/* HNPOS — Westall Point of Sale
   One stylesheet, no CDN. School devices have blocked external CSS before. */

:root {
    --bg:        #f1f5f9;
    --panel:     #ffffff;
    --ink:       #0f172a;
    --ink-soft:  #475569;
    --muted:     #94a3b8;
    --line:      #e2e8f0;
    --brand:     #4f46e5;
    --brand-ink: #ffffff;
    --ok:        #059669;
    --ok-bg:     #ecfdf5;
    --warn:      #b45309;
    --warn-bg:   #fffbeb;
    --danger:    #dc2626;
    --danger-bg: #fef2f2;
    --sidebar:   #0f172a;
    --radius:    12px;
    --shadow:    0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
    --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

/* Must come before any component rule that sets display.
   Without !important, a rule like `.t-row { display: flex }` beats the browser's
   `[hidden] { display: none }`, and every panel we toggle with el.hidden stays
   stubbornly on screen. */
[hidden] { display: none !important; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
}

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

.icon { flex: 0 0 auto; vertical-align: -3px; }

/* ------------------------------------------------------------------ shell */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 232px;
    flex: 0 0 232px;
    background: var(--sidebar);
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    padding: 18px 12px;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; }
.brand-mark {
    width: 32px; height: 32px; border-radius: 9px;
    background: var(--brand); color: #fff;
    display: grid; place-items: center;
    font-weight: 700; font-size: 13px; letter-spacing: .5px;
}
.brand-name { color: #f8fafc; font-weight: 600; font-size: 15px; }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.nav-link {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px;
    border-radius: 9px;
    color: #cbd5e1;
    font-size: 14px;
    font-weight: 500;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; }

.sidebar-foot { margin-top: auto; padding-top: 16px; border-top: 1px solid rgba(255,255,255,.1); }
.who { padding: 4px 12px 10px; }
.who-name { color: #f1f5f9; font-size: 14px; font-weight: 600; }
.who-role { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }

.main { flex: 1 1 auto; padding: 28px 32px 60px; max-width: 1180px; }
.main.wide { max-width: none; padding: 0; }

.menu-toggle {
    display: none;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 9px; font-size: 18px; padding: 6px 12px; cursor: pointer;
    margin-bottom: 14px;
}

/* --------------------------------------------------------------- headings */

h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.3px; }
h2 { font-size: 18px; margin: 28px 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; flex-wrap: wrap; margin-bottom: 22px;
}
.page-head .sub { color: var(--ink-soft); font-size: 14px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ----------------------------------------------------------------- panels */

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    margin-bottom: 18px;
}
.card.tight { padding: 14px 16px; }
.card-head { display:flex; align-items:center; justify-content:space-between; gap:12px; margin-bottom:14px; }

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

.stat { background: var(--panel); border:1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .label { color: var(--ink-soft); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -.5px; margin-top: 4px; }
.stat .value.ok { color: var(--ok); }
.stat .value.bad { color: var(--danger); }

/* --------------------------------------------------------------- controls */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    background: var(--brand); color: var(--brand-ink);
    border: 1px solid transparent; border-radius: 9px;
    padding: 9px 16px;
    font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; text-decoration: none;
    transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; filter: none; }
.btn.ghost   { background: var(--panel); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger  { background: var(--danger); }
.btn.ok      { background: var(--ok); }
.btn.big     { padding: 14px 22px; font-size: 16px; border-radius: 11px; }
.btn.block   { width: 100%; }
.btn.sm      { padding: 6px 11px; font-size: 13px; }

.field { margin-bottom: 14px; }
.field label { display:block; font-size: 13px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
.field .hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=number], input[type=email], input[type=password],
input[type=search], input[type=date], select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #fff;
    font: inherit;
    color: var(--ink);
}
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px rgba(79,70,229,.14);
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
textarea { min-height: 80px; resize: vertical; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1 1 180px; }
.row > .shrink { flex: 0 0 auto; }

/* ----------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--line); }
th { background: #f8fafc; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--ink-soft); font-weight: 650; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-soft); }

/* ------------------------------------------------------------------ chips */

.tag {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; background: #f1f5f9; color: var(--ink-soft);
}
.tag.ok     { background: var(--ok-bg);     color: var(--ok); }
.tag.warn   { background: var(--warn-bg);   color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }

.flash {
    padding: 11px 15px; border-radius: 10px; margin-bottom: 16px;
    font-size: 14px; font-weight: 500; border: 1px solid transparent;
}
.flash-success { background: var(--ok-bg);     color: var(--ok);     border-color: #a7f3d0; }
.flash-error   { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }
.flash-warning { background: var(--warn-bg);   color: var(--warn);   border-color: #fde68a; }

/* ------------------------------------------------------------------ modal */

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(15,23,42,.55);
    display: grid; place-items: center; z-index: 200; padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: var(--panel); border-radius: 14px; padding: 24px;
    max-width: 420px; width: 100%; box-shadow: 0 20px 60px rgba(15,23,42,.3);
}
.modal h3 { font-size: 17px; margin: 0 0 8px; }
.modal p  { margin: 0 0 20px; color: var(--ink-soft); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.toast-host { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); z-index: 300; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
    background: var(--sidebar); color: #fff; padding: 11px 18px; border-radius: 999px;
    font-size: 14px; font-weight: 500; box-shadow: 0 8px 28px rgba(15,23,42,.3);
    animation: toastIn .18s ease;
}
.toast.bad { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* =================================================================== TILL */

.till {
    display: grid;
    grid-template-columns: minmax(0,1fr) 420px;
    height: 100vh;
    background: var(--bg);
}

.till-left  { display: flex; flex-direction: column; min-width: 0; padding: 16px 18px; overflow: hidden; }
.till-right { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }

.till-topbar { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.till-topbar .home { color: var(--ink-soft); display: inline-flex; align-items: center; }

.scan-box { position: relative; flex: 1 1 auto; }
.scan-box .icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.scan-box input {
    padding: 13px 14px 13px 42px; font-size: 16px; border-radius: 11px;
    background: var(--panel);
}

.results { flex: 1 1 auto; overflow-y: auto; padding-bottom: 20px; }

.prod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(158px, 1fr)); gap: 12px; }
.prod-tile {
    background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
    padding: 12px; text-align: left; cursor: pointer; font: inherit; color: inherit;
    display: flex; flex-direction: column; gap: 4px; min-height: 96px;
    transition: border-color .12s, transform .06s;
}
.prod-tile:hover  { border-color: var(--brand); }
.prod-tile:active { transform: scale(.985); }
.prod-tile:disabled { opacity: .45; cursor: not-allowed; }
.prod-tile.sold-out .t-img { opacity: .38; }
.prod-tile.sold-out .t-name { color: var(--ink-soft); }
.prod-tile .t-name { font-weight: 600; font-size: 14px; line-height: 1.3; }
.prod-tile .t-var  { font-size: 12px; color: var(--ink-soft); }
.prod-tile .t-foot { margin-top: auto; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.prod-tile .t-price{ font-weight: 700; font-size: 15px; }
.prod-tile .t-stock{ font-size: 11px; color: var(--muted); }
.prod-tile .t-stock.low { color: var(--warn); font-weight: 600; }
.prod-tile .t-stock.out { color: var(--danger); font-weight: 600; }

.cat-bar { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 12px; }
.cat-chip {
    border: 1px solid var(--line); background: var(--panel); color: var(--ink-soft);
    border-radius: 999px; padding: 7px 15px; font: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; white-space: nowrap;
}
.cat-chip.active { background: var(--sidebar); color: #fff; border-color: var(--sidebar); }

/* cart */
.cart-head { padding: 16px 18px 12px; border-bottom: 1px solid var(--line); display:flex; justify-content:space-between; align-items:center; }
.cart-lines { flex: 1 1 auto; overflow-y: auto; padding: 8px 10px; }
.cart-empty { padding: 60px 20px; text-align: center; color: var(--muted); }

.line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 11px 8px; border-bottom: 1px solid var(--line); }
.line:last-child { border-bottom: none; }
.line-name  { font-weight: 600; font-size: 14px; }
.line-var   { font-size: 12px; color: var(--ink-soft); }
.line-total { font-weight: 650; font-variant-numeric: tabular-nums; align-self: center; }
.line-ctl   { grid-column: 1 / -1; display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.qty {
    width: 30px; height: 30px; border-radius: 8px; border: 1px solid var(--line);
    background: #f8fafc; font: inherit; font-size: 16px; cursor: pointer; line-height: 1;
}
.qty:hover { background: #eef2ff; border-color: var(--brand); }
.qty-val { min-width: 30px; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; }
.line-unit { font-size: 12px; color: var(--muted); margin-left: auto; }
.line-del { border: none; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 6px; }
.line-del:hover { color: var(--danger); background: var(--danger-bg); }

.cart-foot { border-top: 1px solid var(--line); padding: 14px 18px 18px; }
.totals { margin-bottom: 14px; }
.totals .t-row { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; color: var(--ink-soft); }
.totals .t-row.grand { font-size: 22px; font-weight: 700; color: var(--ink); padding-top: 10px; margin-top: 6px; border-top: 1px solid var(--line); }
.pay-buttons { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* cash + card panes */
.pane { padding: 18px; }
.tender-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; margin: 14px 0; }
.tender-grid button {
    padding: 14px 6px; border: 1px solid var(--line); background: var(--panel);
    border-radius: 10px; font: inherit; font-weight: 650; cursor: pointer;
}
.tender-grid button:hover { border-color: var(--brand); background: #eef2ff; }
.change-box { background: var(--ok-bg); color: var(--ok); border-radius: 10px; padding: 14px; text-align: center; margin: 12px 0; }
.change-box .amt { font-size: 30px; font-weight: 700; letter-spacing: -.5px; }

.qr-wrap { text-align: center; padding: 10px 0; }
.qr-wrap img, .qr-wrap canvas, .qr-wrap svg { width: 210px; height: 210px; background:#fff; border:1px solid var(--line); border-radius: 10px; padding: 8px; }
.code-big { font-size: 30px; font-weight: 700; letter-spacing: 5px; text-align: center; font-family: ui-monospace, Menlo, Consolas, monospace; margin: 10px 0; }

.waiting { display: flex; align-items: center; gap: 10px; justify-content: center; color: var(--ink-soft); font-size: 14px; padding: 10px; }
.spinner {
    width: 18px; height: 18px; border: 2px solid var(--line);
    border-top-color: var(--brand); border-radius: 50%;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- receipt */

.receipt {
    max-width: 340px; margin: 0 auto; background: #fff; padding: 22px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px;
    border: 1px solid var(--line); border-radius: 10px;
}
.receipt .r-center { text-align: center; }
.receipt hr { border: none; border-top: 1px dashed #cbd5e1; margin: 10px 0; }
.receipt table { font-size: 13px; }
.receipt th, .receipt td { padding: 2px 0; border: none; background: none; text-transform: none; letter-spacing: 0; font-size: 13px; color: inherit; }

/* --------------------------------------------------------------- phone UI */

.phone-page { max-width: 460px; margin: 0 auto; padding: 22px 18px 60px; }
.phone-amount { font-size: 44px; font-weight: 700; text-align: center; letter-spacing: -1px; margin: 6px 0 2px; }

/* ------------------------------------------------------------ responsive */

@media print {
    .sidebar, .menu-toggle, .no-print, .btn { display: none !important; }
    .main { padding: 0; max-width: none; }
    .receipt { border: none; }
}

@media (max-width: 1100px) {
    .till { grid-template-columns: minmax(0,1fr) 360px; }
}

@media (max-width: 860px) {
    .shell { flex-direction: column; }
    .sidebar {
        position: fixed; left: 0; top: 0; bottom: 0; z-index: 150;
        transform: translateX(-100%); transition: transform .2s ease;
    }
    .sidebar.open { transform: none; }
    .menu-toggle { display: inline-block; }
    .main { padding: 18px 16px 50px; }
    .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
    .till { grid-template-columns: 1fr; height: auto; }
    .till-right { border-left: none; border-top: 1px solid var(--line); }
}

/* ================================================================ PHOTOS */

.photo-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }

.photo-box {
    position: relative;
    width: 150px; height: 150px; flex: 0 0 150px;
    border: 2px dashed var(--line); border-radius: 12px;
    background: #f8fafc; cursor: pointer;
    display: grid; place-items: center; overflow: hidden;
    transition: border-color .12s, background .12s;
}
.photo-box:hover, .photo-box:focus-visible { border-color: var(--brand); background: #eef2ff; outline: none; }
.photo-box.drag { border-color: var(--brand); background: #e0e7ff; }
.photo-box img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.photo-empty {
    display: flex; flex-direction: column; align-items: center; gap: 6px;
    color: var(--muted); font-size: 13px; font-weight: 500; pointer-events: none;
}
.photo-busy {
    position: absolute; inset: 0; background: rgba(255,255,255,.8);
    display: grid; place-items: center;
}

.variant-photo {
    width: 42px; height: 42px; padding: 0; overflow: hidden;
    border: 1px solid var(--line); border-radius: 8px; background: #f8fafc;
    cursor: pointer; display: grid; place-items: center;
}
.variant-photo:hover { border-color: var(--brand); }
.variant-photo.has-own { border-color: var(--brand); }
.variant-photo img { width: 100%; height: 100%; object-fit: cover; }
.variant-photo-plus { color: var(--muted); font-size: 18px; line-height: 1; }

.list-thumb {
    width: 40px; height: 40px; border-radius: 8px; object-fit: cover;
    border: 1px solid var(--line); background: #fff; flex: 0 0 40px;
}
.list-thumb.placeholder { display: grid; place-items: center; color: var(--muted); }
.with-thumb { display: flex; align-items: center; gap: 11px; }

/* till tiles get a picture so search results are recognisable at a glance */
.prod-tile { padding: 0; overflow: hidden; min-height: 0; }
.prod-tile .t-img {
    width: 100%; aspect-ratio: 4 / 3; background: #f1f5f9;
    display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--line);
}
.prod-tile .t-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.prod-tile .t-img .t-noimg { color: #cbd5e1; }
.prod-tile .t-body { padding: 10px 11px 11px; display: flex; flex-direction: column; gap: 3px; flex: 1; }
.prod-tile .t-foot { margin-top: 6px; }

.line-img {
    width: 38px; height: 38px; border-radius: 7px; object-fit: cover;
    border: 1px solid var(--line); background: #fff; flex: 0 0 38px;
}
.line { grid-template-columns: auto 1fr auto; }
.line .line-img { grid-row: span 1; }

@media (max-width: 860px) {
    .photo-box { width: 120px; height: 120px; flex-basis: 120px; }
}
