/* ============================================================
   Stock Count App - CSS
   Dark sidebar, clean white content layout
   ============================================================ */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: rgba(99, 102, 241, 0.1);
    --success: #10b981;
    --success-dark: #059669;
    --warning: #f59e0b;
    --warning-dark: #d97706;
    --danger: #ef4444;
    --danger-dark: #dc2626;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.05), 0 2px 4px rgba(0,0,0,0.04);
    --radius: 10px;
    --radius-sm: 6px;
    --nav-width: 250px;
    --top-bar-height: 0px;

    /* Sidebar palette */
    --sidebar-bg: #1e293b;
    --sidebar-header-bg: #0f172a;
    --sidebar-text: #94a3b8;
    --sidebar-text-hover: #e2e8f0;
    --sidebar-active-bg: rgba(99, 102, 241, 0.15);
    --sidebar-active-text: #818cf8;
    --sidebar-section: #475569;
    --sidebar-border: #334155;
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

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

/* ===== Utility ===== */
.hidden { display: none !important; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.text-muted { color: var(--text-muted); font-size: 0.875rem; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-center { text-align: center; }

/* ===== Screens ===== */
.screen { display: none; }
.screen.active { display: flex; }

/* ===== Login ===== */
#screen-login {
    min-height: 100vh;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--sidebar-bg);
}

.login-container {
    width: 100%;
    max-width: 400px;
    background: var(--card-bg);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 25px 50px rgba(0,0,0,0.25);
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.025em;
}

.login-header p {
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

input, select, textarea {
    width: 100%;
    padding: 0.625rem 0.875rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    transition: all 0.15s;
    background: #fff;
    color: var(--text);
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

input::placeholder, textarea::placeholder {
    color: #94a3b8;
}

.input-lg {
    padding: 0.875rem 1rem;
    font-size: 1.125rem;
    font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    gap: 0.5rem;
    white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background: var(--primary);
    color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-dark); }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover { background: var(--warning-dark); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-muted);
}
.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.btn-block { width: 100%; }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.875rem 1.25rem; font-size: 1rem; min-height: 48px; }

.btn-icon {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    color: var(--text);
}

/* ===== Top Bar (mobile only) ===== */
.top-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--card-bg);
    color: var(--text);
    display: flex;
    align-items: center;
    padding: 0 1rem;
    z-index: 100;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    gap: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.top-bar h2 {
    flex: 1;
    font-size: 1rem;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.top-bar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-name {
    font-size: 0.8125rem;
    color: var(--text-muted);
    display: none;
}

#btn-logout {
    color: var(--text-muted);
    border-color: var(--border);
}

#btn-logout:hover {
    color: var(--danger);
    border-color: var(--danger);
}

/* ===== Side Nav ===== */
.nav-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    backdrop-filter: blur(2px);
}

.side-nav {
    position: fixed;
    top: 0;
    left: -280px;
    width: var(--nav-width);
    height: 100%;
    background: var(--sidebar-bg);
    z-index: 300;
    transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.side-nav.open { left: 0; }

.nav-header {
    padding: 1.5rem 1.25rem;
    background: var(--sidebar-header-bg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.nav-header h3 {
    font-size: 1.125rem;
    font-weight: 700;
    color: #f1f5f9;
    letter-spacing: -0.025em;
}

.nav-header .badge {
    font-size: 0.6875rem;
    padding: 0.2rem 0.5rem;
}

.nav-links {
    list-style: none;
    padding: 0.75rem 0;
    flex: 1;
}

.nav-section-label {
    padding: 1.25rem 1.25rem 0.5rem;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--sidebar-section);
}

.nav-links li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1.25rem;
    color: var(--sidebar-text);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.875rem;
    border-radius: 0;
    margin: 1px 0;
    transition: all 0.15s;
    border-left: 3px solid transparent;
}

.nav-links li a .nav-icon {
    font-size: 1.125rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.nav-links li a:hover {
    background: rgba(255,255,255,0.05);
    color: var(--sidebar-text-hover);
}

.nav-links li a.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    border-left-color: var(--primary);
}

/* ===== Main Content ===== */
.main-content {
    margin-top: 56px;
    padding: 1.5rem;
    min-height: calc(100vh - 56px);
}

.view { display: none; }
.view.active { display: block; }

/* ===== Cards ===== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.card + .card {
    margin-top: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.card-header h3, .card-header h4 {
    flex: 1;
    min-width: 0;
    font-weight: 600;
    letter-spacing: -0.015em;
}

/* ===== Badge ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 99px;
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: capitalize;
    letter-spacing: 0.015em;
}

.badge-lg {
    font-size: 0.8125rem;
    padding: 0.375rem 0.875rem;
}

.badge-pending { background: #fef3c7; color: #92400e; }
.badge-assigned { background: #dbeafe; color: #1e40af; }
.badge-in_progress { background: #e0e7ff; color: #4338ca; }
.badge-review { background: #fce7f3; color: #9d174d; }
.badge-recount { background: #fee2e2; color: #991b1b; }
.badge-completed { background: #d1fae5; color: #065f46; }

.badge-admin { background: #f3e8ff; color: #7c3aed; }
.badge-supervisor { background: #dbeafe; color: #2563eb; }
.badge-counter { background: #d1fae5; color: #059669; }

/* ===== Tables ===== */
.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    background: #f8fafc;
    position: sticky;
    top: 0;
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: #f8fafc;
}

tr.variance { background: #fff7ed; }
tr.variance:hover td { background: #fff7ed; }
tr.variance-high { background: #fef2f2; }
tr.variance-high:hover td { background: #fef2f2; }

/* ===== Stats Grid ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.stat-card .stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-card .stat-label {
    font-size: 0.8125rem;
    color: var(--text-muted);
    font-weight: 500;
}

/* ===== Upload Area ===== */
.upload-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2.5rem;
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    gap: 0.5rem;
    text-align: center;
    background: #f8fafc;
}

.upload-area:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.upload-icon { font-size: 2.5rem; }

/* ===== Filter Bar ===== */
.filter-bar {
    margin-bottom: 1rem;
}

.filter-bar select {
    max-width: 200px;
}

/* ===== Count Card (list item) ===== */
.count-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.15s;
    gap: 0.75rem;
    flex-wrap: wrap;
    background: var(--card-bg);
}

.count-card:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.count-card-main {
    flex: 1;
    min-width: 0;
}

.count-card-ref {
    font-weight: 600;
    font-size: 0.9375rem;
}

.count-card-meta {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ===== Location Grid ===== */
.location-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.location-btn {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--card-bg);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: all 0.15s;
    word-break: break-all;
}

.location-btn:hover { border-color: var(--primary); background: var(--primary-light); }
.location-btn.done {
    border-color: var(--success);
    background: #ecfdf5;
    color: var(--success-dark);
}
.location-btn.active {
    border-color: var(--primary);
    background: #eef2ff;
    color: var(--primary-dark);
}

/* ===== Scanned Value Display ===== */
.scanned-value {
    background: #eef2ff;
    border: 2px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    font-size: 1.25rem;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.75rem;
    color: var(--primary-dark);
}

/* ===== Counting Header ===== */
.counting-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

/* ===== Review checkboxes ===== */
.review-checkbox {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--primary);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 1rem;
    backdrop-filter: blur(4px);
}

.modal-content {
    background: var(--card-bg);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 2rem;
    box-shadow: 0 25px 50px rgba(0,0,0,0.2);
}

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

.modal-header h3 {
    font-weight: 600;
}

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

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 500;
    font-size: 0.875rem;
    z-index: 1000;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
    transition: opacity 0.3s;
    max-width: 90%;
    text-align: center;
}

.toast-success { background: var(--success); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }
.toast-info { background: var(--primary); color: #fff; }

/* ===== Loading ===== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 900;
    backdrop-filter: blur(2px);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

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

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
}

/* ===== Assign dropdown area ===== */
.assign-area {
    display: flex;
    gap: 0.5rem;
    align-items: end;
    flex-wrap: wrap;
}

.assign-area select {
    flex: 1;
    min-width: 150px;
}

/* ===== Variance highlight ===== */
.qty-match { color: var(--success); font-weight: 700; }
.qty-mismatch { color: var(--danger); font-weight: 700; }

/* ===== DESKTOP LAYOUT ===== */
@media (min-width: 768px) {
    /* Sidebar always visible on desktop */
    .side-nav {
        left: 0 !important;
        box-shadow: none;
        border-right: 1px solid var(--sidebar-border);
    }

    .nav-overlay {
        display: none !important;
    }

    #btn-menu {
        display: none;
    }

    .top-bar {
        left: var(--nav-width);
        background: var(--bg);
        border-bottom: 1px solid var(--border);
        box-shadow: none;
        padding: 0 2rem;
        height: 64px;
    }

    .top-bar h2 {
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--text);
    }

    .user-name { display: inline; }

    .main-content {
        margin-left: var(--nav-width);
        margin-top: 64px;
        padding: 0 2rem 2rem;
        max-width: none;
    }
}

@media (max-width: 480px) {
    html { font-size: 15px; }
    .card { padding: 1rem; }
    th, td { padding: 0.5rem 0.75rem; }
}
