/* ===== CSS Variables / Theme System ===== */
:root,
[data-theme="dark"] {
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-card: #141414;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --accent: #4fc3f7;
    --accent-hover: #39b0e4;
    --border: #2a2a2a;
    --nav-hover: #1e1e1e;
    --nav-active: #1c2a35;
    --success: #4caf50;
    --error: #ef5350;
    --warning: #f59e0b;
    --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
    --bg-primary: #f5f5f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --text-primary: #1a1a1a;
    --text-secondary: #666;
    --accent: #0288d1;
    --accent-hover: #0277bd;
    --border: #e0e0e0;
    --nav-hover: #f0f0f0;
    --nav-active: #e3f2fd;
    --success: #4caf50;
    --error: #ef5350;
    --warning: #f59e0b;
    --shadow: rgba(0, 0, 0, 0.1);
}

/* ===== Reset & Base ===== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: background-color 0.2s, color 0.2s;
}

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    color: var(--accent-hover);
}

/* ===== Layout: Sidebar + Main ===== */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.2rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-logo {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.65rem 1.2rem;
    color: var(--text-secondary);
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.sidebar-nav li a:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
}

.sidebar-nav li a.active {
    background: var(--nav-active);
    color: var(--accent);
    border-left-color: var(--accent);
}

.nav-icon {
    width: 20px;
    height: 20px;
    object-fit: contain;
    flex-shrink: 0;
}

/* Nav badge (pending count) */
.nav-badge {
    margin-left: auto;
    background: #e74c3c;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    line-height: 20px;
    text-align: center;
    border-radius: 10px;
    padding: 0 6px;
    flex-shrink: 0;
}

.logo-icon {
    width: 24px;
    height: 24px;
}

/* Sidebar categories */
.sidebar-cat {
    list-style: none;
}

.sidebar-cat-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1.2rem;
    cursor: pointer;
    user-select: none;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    transition: background 0.15s, color 0.15s;
}

.sidebar-cat-header:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
}

.sidebar-cat-chevron {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    position: relative;
    transition: transform 0.2s;
}

.sidebar-cat-chevron::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 6px;
    height: 6px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: translate(-50%, -65%) rotate(45deg);
    transition: transform 0.2s;
}

.sidebar-cat-header.collapsed .sidebar-cat-chevron::before {
    transform: translate(-50%, -35%) rotate(-45deg);
}

.sidebar-cat-pages {
    list-style: none;
    overflow: hidden;
    max-height: 500px;
    transition: max-height 0.25s ease;
}

.sidebar-cat-pages.hidden {
    max-height: 0;
}

.sidebar-cat-pages .nav-link {
    padding-left: 2rem;
}

/* Sidebar bottom area */
.sidebar-bottom {
    padding: 0.8rem 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-user-info {
    font-size: 0.8rem;
    color: var(--text-secondary);
    padding: 0.2rem 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-auth-btn {
    flex: 1;
    justify-content: center;
    font-size: 0.82rem;
    padding: 0.4rem 0.6rem;
}

.sidebar-bottom-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.15s, color 0.15s;
}

.theme-toggle:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
}

.lang-toggle {
    background: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    transition: background 0.15s, color 0.15s;
}

.lang-toggle:hover {
    background: var(--nav-hover);
    color: var(--text-primary);
}

/* ===== Main Content ===== */
.main {
    margin-left: 240px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.content {
    flex: 1;
    padding: 2rem;
}

.page-title {
    font-size: 1.6rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.page-title .nav-icon {
    width: 28px;
    height: 28px;
}

/* ===== Mobile Topbar ===== */
.topbar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 50px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    align-items: center;
    padding: 0 1rem;
    z-index: 90;
}

.topbar-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-left: 0.5rem;
}

.menu-toggle {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px;
}

.menu-toggle .bar {
    width: 22px;
    height: 2px;
    background: var(--text-primary);
    border-radius: 2px;
    transition: transform 0.25s, opacity 0.25s;
}

.menu-toggle.active .bar:nth-child(1) {
    transform: translateY(6.5px) rotate(45deg);
}

.menu-toggle.active .bar:nth-child(2) {
    opacity: 0;
}

.menu-toggle.active .bar:nth-child(3) {
    transform: translateY(-6.5px) rotate(-45deg);
}

/* Overlay */
.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 95;
}

.overlay.active {
    display: block;
}

/* ===== Cards ===== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.2rem;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}

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

.btn-primary:hover {
    opacity: 0.85;
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--nav-hover);
}

/* ===== Inputs ===== */
.input {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

.input:focus {
    outline: none;
    border-color: var(--accent);
}

/* ===== Toast Notifications ===== */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    font-size: 0.83rem;
    font-weight: 500;
    transform: translateX(120%);
    transition: transform 0.3s ease;
    max-width: 340px;
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left-color: var(--success);
    background: rgba(34, 197, 94, 0.08);
}

.toast.error {
    border-left-color: var(--error);
    background: rgba(239, 68, 68, 0.08);
}

/* ===== Login Page ===== */
.login-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 100px);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: 2rem;
}

.login-card:hover {
    transform: none;
}

.login-header {
    text-align: center;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.6rem;
}

.login-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.login-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-group .input {
    width: 100%;
    padding: 0.6rem 0.75rem;
}

.login-error {
    color: var(--error);
    font-size: 0.83rem;
    min-height: 1.2em;
}

.remember-group {
    margin-top: -0.25rem;
}

.remember-label {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.88rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.remember-label input[type="checkbox"] {
    width: 1rem;
    height: 1rem;
    accent-color: var(--accent);
    cursor: pointer;
}

.login-btn {
    width: 100%;
    padding: 0.65rem;
    font-size: 0.95rem;
    justify-content: center;
    margin-top: 0.5rem;
}

.theme-toggle-login {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
}

/* ===== Home/Dashboard Page ===== */
.home-page {
    max-width: 1600px;
}

.home-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    grid-auto-rows: 120px;
    gap: 16px;
}

.home-welcome {
    grid-column: 1 / -1;
}

.home-welcome h2 {
    font-size: 1.3rem;
    margin-bottom: 0.6rem;
}

.home-welcome p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

.home-status h3,
.home-quick h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.status-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-indicator {
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
}

.status-indicator.online {
    color: var(--success);
    background: rgba(76, 175, 80, 0.12);
}

.status-indicator.offline {
    color: var(--error);
    background: rgba(239, 83, 80, 0.12);
}

.text-secondary {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .topbar {
        display: flex;
    }

    .main {
        margin-left: 0;
        padding-top: 50px;
    }

    .content {
        padding: 1rem;
    }

    .login-card {
        margin: 1rem;
    }

    .home-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }
}

/* ===== Shared Barcode Scanner Modal ===== */
.bs-modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 3000;
}
.bs-modal.active { display: flex; }
.bs-modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .65);
}
.bs-modal-content {
    position: relative;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.5rem;
    max-width: min(90vw, 500px);
    width: 100%;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    color: var(--text-primary);
}
.bs-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.bs-modal-header h2 {
    margin: 0;
    font-size: 1.1rem;
}
.bs-modal-close {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-main);
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bs-modal-close:hover { background: var(--nav-hover); }
#bs-barcode-reader {
    width: 100%;
    border-radius: 10px;
    overflow: hidden;
}
#bs-barcode-reader video {
    border-radius: 10px;
}
.bs-scanner-hint {
    text-align: center;
    color: var(--text-secondary);
    font-size: .88rem;
    margin: 0;
}
.bs-scanner-fallback {
    text-align: center;
    padding: 1.5rem 1rem;
}
.bs-scanner-fallback p {
    margin: 0 0 1rem;
    color: var(--text-secondary);
    font-size: .92rem;
}

/* Scan button next to inputs */
.bs-scan-btn {
    padding: 0.4rem 0.55rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.05rem;
    line-height: 1;
    flex-shrink: 0;
}
.bs-scan-btn:hover {
    background: var(--nav-hover);
    color: var(--accent);
}
