:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --success: #16a34a;
    --success-hover: #15803d;
    --success-light: #dcfce7;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --danger-light: #fee2e2;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --orange: #ea580c;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ===== LOGIN ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #6366f1 50%, #818cf8 100%);
    padding: 20px;
}

.login-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    animation: slideUp 0.4s ease;
}

.login-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    margin-bottom: 4px;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 28px;
}

.login-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.login-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.15);
}

.login-btn {
    width: 100%;
    margin-top: 16px;
    padding: 12px;
    font-size: 1rem;
}

/* ===== HEADER ===== */
.app-header {
    background: linear-gradient(135deg, var(--primary), #6366f1);
    color: white;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
    height: 56px;
}

.app-header h1 { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.3px; white-space: nowrap; }

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.header-user-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.header-role-badge {
    font-size: 0.65rem;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.btn-logout {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

.nav-tabs { display: flex; gap: 2px; height: 100%; }

.nav-tabs button {
    background: transparent;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 0 16px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
    border-bottom: 3px solid transparent;
    height: 100%;
    display: flex;
    align-items: center;
    position: relative;
}

.nav-tabs button:hover { color: white; background: rgba(255,255,255,0.1); }

.nav-tabs button.active {
    color: white;
    border-bottom-color: white;
    background: rgba(255,255,255,0.1);
}

.nav-badge {
    background: var(--danger);
    color: white;
    font-size: 0.65rem;
    padding: 1px 5px;
    border-radius: 10px;
    margin-left: 6px;
    font-weight: 700;
    min-width: 18px;
    text-align: center;
}

/* ===== LAYOUT ===== */
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ===== CARDS ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 24px;
    margin-bottom: 16px;
    transition: box-shadow 0.2s;
}

.card:hover { box-shadow: var(--shadow-md); }
.card-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 16px; }

/* ===== DASHBOARD ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.stat-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    flex-shrink: 0;
}

.stat-icon.blue { background: var(--primary-light); color: var(--primary); }
.stat-icon.green { background: var(--success-light); color: var(--success); }
.stat-icon.red { background: var(--danger-light); color: var(--danger); }
.stat-icon.orange { background: var(--warning-light); color: var(--orange); }

.stat-info { flex: 1; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

/* ===== CHART ===== */
.chart-container { position: relative; padding: 12px 0; }

.chart-bars {
    display: flex;
    align-items: flex-end;
    gap: 3px;
    height: 120px;
    padding-top: 8px;
}

.chart-bar-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    min-width: 0;
}

.chart-bar-pair { display: flex; gap: 1px; align-items: flex-end; height: 100px; width: 100%; }

.chart-bar {
    flex: 1;
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: height 0.3s ease;
}

.chart-bar.in { background: var(--success); }
.chart-bar.out { background: var(--danger); opacity: 0.7; }

.chart-label {
    font-size: 0.6rem;
    color: var(--text-muted);
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.chart-legend {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: 12px;
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chart-legend span::before {
    content: '';
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 4px;
    vertical-align: middle;
}

.chart-legend .leg-in::before { background: var(--success); }
.chart-legend .leg-out::before { background: var(--danger); opacity: 0.7; }

/* ===== ALERT LIST ===== */
.alert-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.alert-item:last-child { border-bottom: none; }

.alert-item .alert-product { font-weight: 500; font-size: 0.9rem; flex: 1; min-width: 0; }
.alert-item .alert-detail { font-size: 0.8rem; color: var(--text-muted); }

.alert-badge {
    background: var(--danger-light);
    color: var(--danger);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    white-space: nowrap;
}

.alert-badge.warning {
    background: var(--warning-light);
    color: var(--orange);
}

/* ===== SCAN ===== */
.scan-section { max-width: 700px; margin: 0 auto; }

.scan-input-group { display: flex; gap: 8px; margin-bottom: 20px; }

.scan-input-group input {
    flex: 1;
    padding: 14px 16px;
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    font-size: 1.1rem;
    outline: none;
    transition: all 0.2s;
}

.scan-input-group input:focus {
    box-shadow: 0 0 0 4px rgba(79,70,229,0.15);
}

.product-info {
    background: linear-gradient(135deg, #f8fafc, #f1f5f9);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 20px;
    border: 1px solid var(--border);
}

.product-info .product-name { font-size: 1.1rem; font-weight: 600; color: var(--primary); }

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.info-item { display: flex; flex-direction: column; }

.info-item .label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.info-item .value { font-size: 0.95rem; font-weight: 500; }

.stock-current { font-size: 1.5rem; font-weight: 700; color: var(--primary); }

/* Weight */
.weight-section { margin-bottom: 20px; }

.weight-input-row {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.weight-input-row label { font-weight: 500; white-space: nowrap; min-width: 160px; }

.weight-input-row input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    max-width: 200px;
}

.weight-input-row input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

.weight-input-row .unit { color: var(--text-muted); font-size: 0.9rem; }

.calculated-qty {
    background: var(--primary-light);
    border: 2px solid var(--primary);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 600;
    animation: fadeIn 0.3s ease;
}

.calculated-qty span { color: var(--primary); font-size: 1.6rem; }

/* Last operations mini-list */
.last-ops { margin-top: 20px; }
.last-ops h4 { font-size: 0.85rem; color: var(--text-muted); margin-bottom: 8px; }

.last-op-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: #f8fafc;
    border-radius: var(--radius);
    margin-bottom: 4px;
    font-size: 0.8rem;
}

.last-op-item .op-name { font-weight: 500; flex: 1; }
.last-op-item .op-qty { font-weight: 600; margin: 0 8px; }
.last-op-item .op-time { color: var(--text-muted); font-size: 0.75rem; }

/* ===== BUTTONS ===== */
.action-buttons { display: flex; gap: 12px; margin-top: 16px; }

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-add { background: var(--success); color: white; flex: 1; padding: 14px; font-size: 1rem; }
.btn-add:hover:not(:disabled) { background: var(--success-hover); transform: translateY(-1px); }

.btn-subtract { background: var(--danger); color: white; flex: 1; padding: 14px; font-size: 1rem; }
.btn-subtract:hover:not(:disabled) { background: var(--danger-hover); transform: translateY(-1px); }

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #d1d5db; }

.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-xs { padding: 4px 8px; font-size: 0.75rem; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }

.btn-warning { background: var(--warning); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f8fafc; }

/* ===== MESSAGES ===== */
.success-message {
    background: var(--success-light);
    border: 1px solid #86efac;
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    text-align: center;
    color: #166534;
    font-weight: 500;
    animation: slideUp 0.3s ease;
}

.error-message {
    background: var(--danger-light);
    border: 1px solid #fca5a5;
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 16px;
    text-align: center;
    color: #991b1b;
    font-weight: 500;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== TABLE ===== */
.table-container { overflow-x: auto; border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; }

table th, table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

table th {
    background: #f1f5f9;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.5px;
    position: sticky;
    top: 0;
}

table tr:hover { background: #f8fafc; }

/* ===== SEARCH ===== */
.search-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }

.search-bar input, .search-bar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.85rem;
    outline: none;
}

.search-bar input:focus, .search-bar select:focus { border-color: var(--primary); }
.search-bar input { flex: 1; min-width: 180px; }

/* ===== MODAL ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    animation: fadeIn 0.15s ease;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 92%;
    max-width: 700px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 24px;
    animation: slideUp 0.2s ease;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 { font-size: 1.15rem; }

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
    padding: 4px;
}

.modal-close:hover { color: var(--text); }

/* ===== FORMS ===== */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; }
.form-group.full-width { grid-column: 1 / -1; }

.form-group label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.form-group input, .form-group select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

.form-group input:focus, .form-group select:focus { border-color: var(--primary); }

.form-section-title {
    grid-column: 1 / -1;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
    padding-top: 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}

.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 20px; }

/* ===== IMPORT ===== */
.import-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
}

.import-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.import-zone input[type="file"] { display: none; }

/* ===== PAGINATION ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 16px;
}

.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.8rem;
}

.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }
.pagination span { font-size: 0.8rem; color: var(--text-muted); }

/* ===== BADGES ===== */
.stock-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.stock-badge.low { background: var(--danger-light); color: #991b1b; }
.stock-badge.medium { background: var(--warning-light); color: #92400e; }
.stock-badge.ok { background: var(--success-light); color: #166534; }
.stock-badge.info { background: var(--primary-light); color: var(--primary); }

/* ===== ALERT BANNER ===== */
.alert-banner {
    background: linear-gradient(90deg, #fef3c7, #fde68a);
    color: #92400e;
    text-align: center;
    padding: 8px 16px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.alert-banner:hover {
    background: linear-gradient(90deg, #fde68a, #fcd34d);
}

/* ===== ARCHIVED ROWS ===== */
.row-archived {
    opacity: 0.5;
    background: #f8f8f8;
}

.row-archived:hover {
    opacity: 0.7;
}

/* ===== CANCELLED ROWS ===== */
.row-cancelled {
    opacity: 0.45;
    text-decoration: line-through;
    background: #fef2f2;
}

.row-cancelled:hover {
    opacity: 0.65;
}

/* ===== TOGGLE LABEL ===== */
.toggle-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.toggle-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* ===== HISTORY ===== */
.op-add { color: var(--success); font-weight: 600; }
.op-subtract { color: var(--danger); font-weight: 600; }

/* ===== SPINNER ===== */
.spinner {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== TOOLBAR ===== */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
    .app-header { padding: 0 12px; flex-wrap: wrap; height: auto; gap: 0; }
    .app-header h1 { font-size: 1rem; padding: 10px 0; }

    .header-user { padding: 10px 0; }
    .header-user-name { display: none; }

    .nav-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; width: 100%; order: 3; }
    .nav-tabs button { padding: 0 12px; font-size: 0.8rem; white-space: nowrap; }

    .container { padding: 12px; }

    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 12px; gap: 10px; }
    .stat-icon { width: 36px; height: 36px; font-size: 1.1rem; }
    .stat-value { font-size: 1.2rem; }

    .dashboard-grid { grid-template-columns: 1fr; }

    .form-grid { grid-template-columns: 1fr; }
    .action-buttons { flex-direction: column; }

    .weight-input-row { flex-wrap: wrap; }
    .weight-input-row label { min-width: 100%; }
    .weight-input-row input { max-width: 100%; }

    .toolbar { flex-direction: column; align-items: stretch; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
}
