/* =========================================================
   V1 Inventory — single stylesheet. Light + dark themes.
   Includes mobile sidebar drawer (≤900px).
   ========================================================= */

:root {
    --bg:        #f8fafc;
    --bg-2:      #ffffff;
    --fg:        #0f172a;
    --fg-2:      #475569;
    --muted:     #94a3b8;
    --border:    #e2e8f0;
    --brand:     #2f55ff;
    --brand-2:   #1e40cf;
    --danger:    #dc2626;
    --ok:        #059669;
    --warn:      #d97706;
    --radius:    10px;
    --shadow:    0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
    --font-sans: 'Inter', 'Noto Sans Ethiopic', -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
    --bg:        #0b1220;
    --bg-2:      #111a2e;
    --fg:        #e6edf7;
    --fg-2:      #b6c2d4;
    --muted:     #6d7c93;
    --border:    #1e293b;
    --brand:     #587dff;
    --brand-2:   #7a97ff;
    --danger:    #f87171;
    --ok:        #34d399;
    --warn:      #fbbf24;
    --shadow:    0 1px 2px rgba(0, 0, 0, 0.4), 0 1px 3px rgba(0, 0, 0, 0.3);
}

*, *::before, *::after { box-sizing: border-box; }

html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    color: var(--fg);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }

/* ── Layout ────────────────────────────────────────────── */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 15px;
}

.sidebar-nav {
    flex: 1;
    padding: 8px;
    overflow-y: auto;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    color: var(--fg-2);
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
}
.nav-link:hover { background: rgba(47, 85, 255, 0.08); color: var(--fg); text-decoration: none; }
.nav-link.active { background: rgba(47, 85, 255, 0.14); color: var(--brand); }
.nav-ico { width: 18px; text-align: center; }

.main { display: flex; flex-direction: column; flex: 1; min-width: 0; }

.topbar {
    height: 56px;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 20px;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-title { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.user-chip { display: flex; align-items: center; gap: 8px; padding-left: 8px; border-left: 1px solid var(--border); }
.avatar {
    width: 28px; height: 28px; border-radius: 50%;
    background: var(--brand); color: #fff;
    display: inline-flex; align-items: center; justify-content: center;
    font-weight: 600; font-size: 12px;
}
.user-name { font-size: 13px; color: var(--fg-2); }

.content { padding: 20px; flex: 1; }

/* ── Cards, tables ─────────────────────────────────────── */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow);
}

.grid { display: grid; gap: 12px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 900px) {
    .grid-3, .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 600px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.kpi { padding: 14px; }
.kpi-label { font-size: 11px; text-transform: uppercase; color: var(--muted); letter-spacing: 0.4px; }
.kpi-value { font-size: 22px; font-weight: 700; margin-top: 2px; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data thead th {
    background: rgba(148, 163, 184, 0.12);
    color: var(--fg-2);
    font-weight: 600;
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.data tbody tr:hover { background: rgba(148, 163, 184, 0.06); }

/* ── Forms & buttons ──────────────────────────────────── */
label { display: block; margin-bottom: 4px; font-size: 12px; color: var(--fg-2); font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], input[type="search"],
select, textarea {
    width: 100%;
    padding: 8px 10px;
    font-family: inherit;
    font-size: 13px;
    color: var(--fg);
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    outline: none;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(47, 85, 255, 0.15);
}

.form-row { margin-bottom: 12px; }

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, box-shadow 0.15s;
}
.btn-primary   { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-2); text-decoration: none; }
.btn-secondary { background: var(--bg-2); color: var(--fg); border-color: var(--border); }
.btn-secondary:hover { background: rgba(148, 163, 184, 0.1); }
.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); }
.btn-ghost     { background: transparent; color: var(--fg-2); padding: 4px 8px; }
.btn-ghost:hover { background: rgba(148, 163, 184, 0.15); }
.btn-sm { padding: 4px 8px; font-size: 12px; }

.inline { display: inline-block; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-gray   { background: rgba(148, 163, 184, 0.2); color: var(--fg-2); }
.badge-green  { background: rgba(16, 185, 129, 0.15); color: #047857; }
.badge-red    { background: rgba(239, 68, 68, 0.15); color: #b91c1c; }
.badge-yellow { background: rgba(245, 158, 11, 0.15); color: #92400e; }

.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.alert-success { background: rgba(16, 185, 129, 0.12); color: #047857; border: 1px solid rgba(16, 185, 129, 0.3); }
.alert-error   { background: rgba(239, 68, 68, 0.1); color: #b91c1c; border: 1px solid rgba(239, 68, 68, 0.3); }
.alert-warn    { background: rgba(245, 158, 11, 0.12); color: #92400e; border: 1px solid rgba(245, 158, 11, 0.3); }

/* ── Login ─────────────────────────────────────────────── */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #eef2f8, #dbe4ff);
    padding: 20px;
}
[data-theme="dark"] .login-wrap {
    background: linear-gradient(135deg, #0b1220, #1a2340);
}
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 28px;
    box-shadow: 0 20px 40px rgba(15, 23, 42, 0.15);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p.sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.login-card .btn { width: 100%; justify-content: center; padding: 10px; }
.login-card .footer { margin-top: 16px; display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* ── Utilities ─────────────────────────────────────────── */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.mb-1 { margin-bottom: 4px; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.w-100 { width: 100%; }

/* ── Print (58mm receipts) ─────────────────────────────── */
@media print {
    @page { size: 58mm auto; margin: 0; }
    body * { visibility: hidden; }
    .receipt, .receipt * { visibility: visible; }
    .receipt {
        position: absolute; left: 0; top: 0;
        width: 58mm;
        font-family: 'Courier New', monospace;
        font-size: 10px;
        line-height: 1.2;
        padding: 2mm;
        color: #000;
        background: #fff;
    }
    .receipt .center { text-align: center; }
    .receipt .line { border-top: 1px dashed #000; margin: 2px 0; }
    .receipt .row { display: flex; justify-content: space-between; }
}

/* =========================================================
   MOBILE SIDEBAR DRAWER (Placed at the very bottom so
   nothing else can override it).
   ========================================================= */
.nav-toggle {
    display: none; /* Hidden on desktop */
    background: transparent;
    border: none;
    color: var(--fg-2);
    padding: 6px;
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.nav-toggle:hover { background: rgba(148, 163, 184, 0.15); }
.nav-toggle:active { transform: scale(0.95); }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 40;
    animation: fadeIn 0.18s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@media (max-width: 900px) {
    /* Show hamburger on mobile/tablet */
    .nav-toggle { display: inline-flex !important; }

    /* Sidebar becomes a slide-in drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: 260px;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        box-shadow: 2px 0 16px rgba(0, 0, 0, 0.18);
    }
    .app.sidebar-open .sidebar {
        transform: translateX(0);
    }
    .app.sidebar-open .sidebar-backdrop {
        display: block;
    }

    /* Prevent body scroll behind the open drawer */
    body.sidebar-locked {
        overflow: hidden;
    }

    /* Main area fills the screen */
    .main {
        width: 100%;
    }

    .topbar { padding: 0 12px; gap: 8px; }
    .content { padding: 12px; }
}

/* Theme-aware native controls and POS category labels */
select option, datalist option { color: var(--fg); background: var(--bg-2); }
[data-theme="dark"] select,
[data-theme="dark"] select option,
[data-theme="dark"] .pos-cat-tabs button:not(.active) {
    color: #ffffff;
}
[data-theme="dark"] .pos-cat-tabs button:not(.active) {
    background: var(--bg-2);
}
.purchase-item-search { min-width: 190px; }

/* The hidden attribute always hides, even on elements styled with display */
[hidden] { display: none !important; }
