/* MediStore - professional POS theme.
 * Clean light theme, teal accent (#0f766e), slate neutrals.
 * System font stack only - no web fonts, works fully offline.
 */
* { box-sizing: border-box; }

:root {
    --accent: #0f766e;
    --accent-dark: #115e59;
    --accent-soft: #f0fdfa;
    /* Derived theme shades. When a custom theme color is chosen,
     * assets/theme.js overrides all of these inline on <html>.
     * With no custom theme these defaults give the teal look. */
    --accent-strong: var(--accent);
    --accent-text: var(--accent-dark);
    --accent-tint: #99f6e4;
    --accent-nav: #ccfbf1;
    --accent-foot: #5eead4;
    --ink: #1f2937;
    --muted: #64748b;
    --border: #dbe2ea;
    --bg: #f1f5f9;
    --card: #ffffff;
    --danger: #b91c1c;
    --danger-soft: #fef2f2;
    --warn: #92400e;
    --warn-soft: #fffbeb;
    --ok: #15803d;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

body {
    margin: 0;
    font-family: "Segoe UI", Arial, Helvetica, sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
}

.layout { display: flex; min-height: 100vh; padding-left: 72px; }

/* ---------- sidebar ----------
 * Desktop shows a compact 72px icon rail. Hovering it expands a
 * full menu that floats over the page, so the content never jumps
 * around. Clicking the rail also expands it (see the fold logic in
 * app.js: the menu folds by itself as soon as the pointer moves
 * right into the main content). Keyboard focus expands it too,
 * through the same .expanded class - plain :focus-within is NOT
 * used here, because a clicked nav button keeping focus would
 * hold the menu open after the pointer leaves. The menu scrolls
 * silently on short screens - no scrollbar is ever shown. */
.sidebar {
    width: 72px;
    flex-shrink: 0;
    background: var(--accent-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 60;
    overflow: hidden;
    transition: width 0.18s ease, box-shadow 0.18s ease;
}

.sidebar:hover,
.sidebar.expanded {
    width: 248px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
}

.brand { padding: 18px 0 10px; text-align: center; white-space: nowrap; cursor: pointer; }
.brand h1 { margin: 0; font-size: 22px; letter-spacing: 0.3px; display: none; }
.brand .tagline { font-size: 12px; color: var(--accent-tint); margin-top: 2px; display: none; }

/* Compact cross mark shown while the rail is collapsed. */
.brand::before {
    content: "+";
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 24px;
    font-weight: 700;
    line-height: 1;
}

.sidebar:hover .brand,
.sidebar.expanded .brand { padding: 20px 18px 12px; text-align: left; }
.sidebar:hover .brand h1,
.sidebar.expanded .brand h1,
.sidebar:hover .brand .tagline,
.sidebar.expanded .brand .tagline { display: block; }
.sidebar:hover .brand::before,
.sidebar.expanded .brand::before { display: none; }

/* The menu scrolls when it is taller than the viewport (short
 * screens, zoomed text) but the scrollbar stays invisible.
 * flex:1 + min-height:0 lets it shrink inside the 100vh sidebar
 * instead of pushing the footer off. */
.sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.sidebar nav::-webkit-scrollbar { width: 0; height: 0; display: none; }

.sidebar nav button {
    background: none;
    border: none;
    color: var(--accent-nav);
    text-align: left;
    padding: 11px;
    font-size: 14px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    width: 100%;
    white-space: nowrap;
}

.sidebar nav button svg {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sidebar nav button span { display: none; overflow: hidden; text-overflow: ellipsis; }

.sidebar nav button:hover { background: rgba(255, 255, 255, 0.1); }

.sidebar nav button.active {
    background: #fff;
    color: var(--accent-dark);
    font-weight: 700;
}

.sidebar:hover nav button,
.sidebar.expanded nav button { justify-content: flex-start; padding: 11px 12px; }
.sidebar:hover nav button span,
.sidebar.expanded nav button span { display: inline; }

.sidebar .foot {
    margin-top: auto;
    padding: 14px 18px;
    font-size: 11px;
    color: var(--accent-foot);
    display: none;
    white-space: nowrap;
}
.sidebar:hover .foot,
.sidebar.expanded .foot { display: block; }

/* ---------- main + top bar ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar h2 { margin: 0; font-size: 18px; }
.topbar .date { color: var(--muted); font-size: 13px; }
.topbar .spacer { flex: 1; }

/* Hamburger button - only visible on small screens where the sidebar
 * lives in an off-canvas drawer opened from the top bar. */
.menu-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--ink);
    cursor: pointer;
    flex-shrink: 0;
}

/* Dimmed backdrop shown behind the mobile drawer. */
.sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(15, 23, 42, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    z-index: 55;
}
html.mobile-nav-open .sidebar-backdrop { opacity: 1; visibility: visible; }

.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 13px;
    font-weight: 600;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 12px;
}

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); }
.dot.online { background: #16a34a; }
.sync-meta { font-size: 12px; color: var(--muted); }

main { padding: 20px 24px 48px; max-width: 1120px; width: 100%; margin: 0 auto; }

.view { display: none; }
.view.active { display: block; }
.view > h2 { margin: 0 0 16px; font-size: 20px; }

/* ---------- cards, stats ---------- */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 16px;
}

.card h2 { margin: 0 0 12px; font-size: 17px; }
.card h3 { margin: 0 0 10px; font-size: 15px; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    border-top: 4px solid var(--accent);
}

.stat .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value.warn { color: var(--danger); }
.stat .value.ok { color: var(--accent-text); }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 8px; border-bottom: 1px solid #e5e7eb; vertical-align: middle; }
th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
td.num, th.num { text-align: right; }
tr.low { background: var(--danger-soft); }
tr.expired { background: var(--danger-soft); }
tr.expiring { background: var(--warn-soft); }

.badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    background: #e0f2fe;
    color: #0369a1;
    white-space: nowrap;
}

.badge.danger { background: #fee2e2; color: var(--danger); }
.badge.warn { background: #fef3c7; color: var(--warn); }
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.sample { background: #ede9fe; color: #6d28d9; }

/* ---------- forms & buttons ---------- */
input, select, textarea {
    font: inherit;
    padding: 9px 11px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    width: 100%;
    background: #fff;
    color: var(--ink);
}

input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
/* A field that failed number validation: red border until the
 * cashier types in it again (see numError in assets/app.js). */
input.field-error, select.field-error, textarea.field-error { border-color: #b91c1c !important; outline: 2px solid rgba(185, 28, 28, .3); }
input[type="checkbox"] { width: auto; }
input[type="file"] { padding: 6px; }

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

label { display: block; font-size: 12px; color: #475569; margin-bottom: 4px; font-weight: 600; }
label.inline { display: flex; align-items: center; gap: 6px; font-weight: 400; }

.btn {
    background: var(--accent-strong);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: var(--accent-dark); }
.btn.secondary { background: #475569; }
.btn.secondary:hover { background: #334155; }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: #991b1b; }
.btn.ghost { background: #e2e8f0; color: var(--ink); }
.btn.ghost:hover { background: #cbd5e1; }
.btn.small { padding: 6px 11px; font-size: 12px; }
.btn.active { background: var(--accent-strong); color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"], .toolbar input[type="text"] { max-width: 320px; }
.toolbar .spacer { flex: 1; }

/* ---------- POS ---------- */
.pos-grid { display: grid; grid-template-columns: 1fr 340px; gap: 16px; align-items: start; }

.search-box { position: relative; }
.search-box input { font-size: 16px; padding: 12px 14px; }

.search-results {
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background: #fff;
    max-height: 260px;
    overflow-y: auto;
    margin-top: 4px;
    box-shadow: var(--shadow);
}

.search-results div {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid #e5e7eb;
}

.search-results div:hover { background: var(--accent-soft); }
.search-results .muted { cursor: default; }

.cart-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid #e5e7eb; }
.cart-row .name { flex: 1; }
.cart-row input { width: 64px; text-align: center; }

.totals { font-size: 15px; margin-top: 12px; }
.totals .row { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { font-size: 20px; font-weight: 700; border-top: 1px solid var(--border); padding-top: 8px; margin-top: 6px; }
.totals .change { color: var(--accent-text); font-weight: 700; }

/* ---------- misc ---------- */
.muted { color: var(--muted); font-size: 13px; }
.hidden { display: none !important; }

#toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--ink);
    color: #fff;
    padding: 11px 20px;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    display: none;
    z-index: 100;
    max-width: 90vw;
    text-align: center;
}

#print-area { display: none; position: relative; }

/* On-screen receipt (inside the receipt modal after a sale): the
 * same 80mm thermal layout as the printed receipt, so the cashier
 * sees exactly what will print. */
.receipt-sheet { width: 280px; max-width: 100%; margin: 0 auto; font-size: 12px; color: #000; }
.receipt-sheet h2 { font-size: 15px; text-align: center; margin: 0 0 4px; }
.receipt-sheet .center { text-align: center; }
.receipt-sheet table { font-size: 12px; }
.receipt-sheet hr { border: none; border-top: 1px dashed #000; }

/* ---------- receipt QR code + paid stamp ---------- */
.receipt-qr { text-align: center; margin: 12px 0 4px; }
.receipt-qr svg { width: 148px; height: 148px; }
.receipt-qr .qr-caption { font-size: 10px; color: #444; margin-top: 2px; }

/* Rubber-stamp watermark across the receipt items: a proper
 * CIRCLE, green PAID when the bill is fully paid, red UNPAID
 * otherwise. It sits in the flow right after the items table, so
 * it never covers the bill number (top), the totals or the QR
 * code (bottom). The items show through the translucent ink, as
 * with a real stamp. The circle is 118px across: "UNPAID" (the
 * longest word) fits at 20px type, and the stamp stays well
 * inside the 280px-wide 80mm receipt. */
.receipt-stamp {
    position: relative;
    width: 118px;
    height: 118px;
    margin: -28px auto 10px;
    transform: rotate(-14deg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 900;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    border: 3px double currentColor;
    border-radius: 50%;
    opacity: 0.55;
    pointer-events: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
}
.receipt-stamp.paid { color: #15803d; }
.receipt-stamp.unpaid { color: #b91c1c; }

@media print {
    body > *:not(#print-area) { display: none !important; }
    #print-area { display: block; width: 280px; margin: 0 auto; font-size: 12px; color: #000; }
    #print-area h2 { font-size: 15px; text-align: center; margin: 0 0 4px; }
    #print-area .center { text-align: center; }
    #print-area table { font-size: 12px; }
    #print-area hr { border: none; border-top: 1px dashed #000; }
    /* The paid stamp must print as a coloured circle, not a
     * colourless box: re-assert the shape and the exact colours
     * (some printers drop colour and borders otherwise). */
    #print-area .receipt-stamp { border-radius: 50%; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    #print-area .receipt-stamp.paid { color: #15803d; }
    #print-area .receipt-stamp.unpaid { color: #b91c1c; }
}

@media (max-width: 900px) {
    .pos-grid { grid-template-columns: 1fr; }
    .layout { flex-direction: column; padding-left: 0; }
    /* Mobile: the sidebar becomes a side drawer opened with the
     * hamburger in the top bar. Closed by default, slides in from
     * the left, no horizontal strip, full labels, own scroll area. */
    .menu-toggle { display: inline-flex; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: min(280px, 84vw);
        height: 100vh;
        transform: translateX(-105%);
        visibility: hidden;
        z-index: 80;
        transition: transform 0.22s ease, visibility 0.22s ease, box-shadow 0.18s ease;
    }
    .sidebar:hover,
    .sidebar:focus-within { width: min(280px, 84vw); }
    html.mobile-nav-open .sidebar { transform: translateX(0); visibility: visible; }
    html.mobile-nav-open .sidebar:hover,
    html.mobile-nav-open .sidebar:focus-within { width: min(280px, 84vw); }
    html.mobile-nav-open .sidebar .brand { padding: 18px 18px 10px; text-align: left; }
    html.mobile-nav-open .sidebar .brand h1,
    html.mobile-nav-open .sidebar .brand .tagline { display: block; }
    html.mobile-nav-open .sidebar .brand::before { display: none; }
    .sidebar nav { overflow-y: auto; overflow-x: hidden; }
    .sidebar nav button { justify-content: flex-start; padding: 12px; white-space: normal; }
    .sidebar nav button span { display: inline; }
    .sidebar .foot { display: block; margin-top: 12px; }
    main { padding: 14px 12px 40px; }
    .topbar { padding: 10px 14px; position: static; }
    html.mobile-nav-open { overflow: hidden; }
}

/* ---------- v2: login, roles, alerts ---------- */
.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: var(--bg);
}

.login-card {
    background: var(--card);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.25);
    padding: 28px;
    width: 100%;
    max-width: 420px;
}

.login-card h2 { margin: 0 0 8px; font-size: 20px; }

.brand-block { text-align: center; margin-bottom: 18px; }
.brand-block h1 { margin: 0; font-size: 28px; color: var(--accent-text); }
.brand-block .tagline { font-size: 13px; color: var(--muted); }

/* "Back to Home" button at the bottom of the sign-in card. */
.login-back {
    display: block;
    width: 100%;
    margin-top: 12px;
    text-align: center;
    text-decoration: none;
}


.alert {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 12px;
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
    margin-top: 10px;
}

.check-grid label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 400;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 8px 10px;
    margin: 0;
    cursor: pointer;
}

@media print {
    #print-area { width: 72mm; }
}

/* ---------- theme color picker (Settings > Appearance) ---------- */
.theme-swatches { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 4px; }
.theme-swatch {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid transparent;
    outline: 2px solid var(--border);
    outline-offset: 2px;
    cursor: pointer;
    padding: 0;
}
.theme-swatch:hover { transform: scale(1.08); }
.theme-swatch.selected { outline-color: var(--accent-strong); border-color: #fff; }
.theme-swatch:focus-visible { outline-color: var(--accent-strong); }

input[type="color"].theme-color-input {
    height: 44px;
    padding: 4px;
    cursor: pointer;
    width: 100%;
}

/* Live preview: a mini sidebar strip + button in the chosen theme. */
.theme-preview {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.theme-preview .tp-bar {
    background: var(--accent-dark);
    color: var(--accent-nav);
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}
.theme-preview .tp-bar .tp-dot {
    width: 14px;
    height: 14px;
    border-radius: 4px;
    background: var(--accent);
    flex-shrink: 0;
}
.theme-preview .tp-body { padding: 10px 12px; background: var(--card); }
.theme-preview .tp-btn {
    display: inline-block;
    background: var(--accent-strong);
    color: #fff;
    font-size: 13px;
    font-weight: 600;
    padding: 7px 14px;
    border-radius: 6px;
}
.theme-preview .tp-link { color: var(--accent-text); font-weight: 700; font-size: 13px; margin-left: 10px; }

/* ---------- offline mode ---------- */
.offline-banner {
    background: var(--warn-soft);
    color: var(--warn);
    border-bottom: 1px solid #fde68a;
    padding: 9px 24px;
    font-size: 13px;
    font-weight: 600;
    text-align: center;
}
/* Simulated offline (the "Go Offline" button) gets its own color
 * so it is never confused with a real network loss. */
.offline-banner.sim { background: #ede9fe; color: #5b21b6; border-bottom: 1px solid #c4b5fd; }
#btn-offline-mode[aria-pressed="true"] { background: var(--accent-dark); color: #fff; }
.sync-pill.sim { background: #ede9fe; border-color: #c4b5fd; }
