/* ==========================================================================
   Inventory Dashboard - styles.css
   Desktop-first (optimised for 1280px+), degrades gracefully to tablet.
   Palette: deep navy + teal accents, monospace data, Georgia headings.
   ========================================================================== */

:root {
    --bg:        #0b1220;
    --bg-side:   #08101d;
    --card:      #111b2e;
    --card-2:    #15213a;
    --line:      #1f2d47;
    --text:      #e6edf7;
    --muted:     #8a9bb8;
    --teal:      #2dd4bf;
    --teal-dim:  rgba(45, 212, 191, .14);
    --warn:      #f5b942;
    --warn-dim:  rgba(245, 185, 66, .14);
    --danger:    #f0616d;
    --danger-dim:rgba(240, 97, 109, .14);
    --ok:        #34d399;
    --ok-dim:    rgba(52, 211, 153, .12);
    --radius:    14px;
    --mono:      ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
    --serif:     Georgia, "Times New Roman", serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.93rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1, h2 { font-family: var(--serif); font-weight: 600; margin: 0; letter-spacing: .2px; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.15rem; }
.muted { color: var(--muted); }
.mono  { font-family: var(--mono); }
[hidden] { display: none !important; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }

.sidebar {
    position: sticky; top: 0; height: 100vh;
    display: flex; flex-direction: column;
    padding: 28px 18px 20px;
    background: var(--bg-side);
    border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-mark {
    display: grid; place-items: center; width: 40px; height: 40px;
    border-radius: 11px; background: var(--teal-dim); color: var(--teal);
    font-family: var(--serif); font-weight: 700; letter-spacing: 1px;
    border: 1px solid rgba(45, 212, 191, .35);
}
.brand strong { display: block; font-family: var(--serif); font-size: 1.05rem; }
.brand div span { display: block; color: var(--muted); font-size: .78rem; }

nav { display: flex; flex-direction: column; gap: 4px; }
.nav-title { margin: 22px 10px 6px; color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: 1.6px; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 12px; border-radius: 10px;
    color: var(--muted); transition: background .15s, color .15s;
}
.nav-link:hover  { background: var(--card); color: var(--text); }
.nav-link.active { background: var(--teal-dim); color: var(--teal); }
.ico { width: 18px; height: 18px; flex: none; }
.badge {
    margin-left: auto; min-width: 22px; padding: 1px 7px; text-align: center;
    border-radius: 99px; background: var(--danger); color: #fff; font-size: .72rem; font-weight: 700;
}
.sidebar-foot {
    margin-top: auto; display: flex; align-items: center; gap: 10px;
    padding: 12px; border-radius: 10px; background: var(--card);
    color: var(--muted); font-size: .8rem;
}
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 rgba(52, 211, 153, .6); animation: pulse 2.4s infinite; }
.live-dot.off { background: var(--danger); animation: none; }
@keyframes pulse { 70% { box-shadow: 0 0 0 8px rgba(52, 211, 153, 0); } 100% { box-shadow: 0 0 0 0 rgba(52, 211, 153, 0); } }

/* ---------- Main ---------- */
.main { padding: 32px 40px 48px; max-width: 1800px; width: 100%; }
.topbar { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 26px; }
.topbar p { margin: 4px 0 0; font-size: .82rem; }
.actions { display: flex; gap: 10px; }

.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 15px; border-radius: 10px;
    border: 1px solid var(--line); background: var(--card); color: var(--text);
    font: inherit; font-size: .85rem; cursor: pointer;
    transition: border-color .15s, background .15s;
}
.btn:hover { border-color: var(--teal); }
.btn-primary { background: var(--teal); color: #04211d; border-color: var(--teal); font-weight: 700; }
.btn-primary:hover { background: #5eead4; }
.btn-ghost { background: transparent; }

.banner { padding: 13px 18px; border-radius: 12px; margin-bottom: 22px; font-size: .86rem; }
.banner-error { background: var(--danger-dim); border: 1px solid rgba(240, 97, 109, .4); color: #ffc9ce; }
.banner-info  { background: var(--teal-dim);   border: 1px solid rgba(45, 212, 191, .35); color: #b4f5ec; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px 16px; flex-wrap: wrap; }
.link { color: var(--teal); font-size: .82rem; }
.link:hover { text-decoration: underline; }

/* ---------- Metrics ---------- */
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; margin-bottom: 26px; }
.metric { padding: 24px 26px; position: relative; overflow: hidden; }
.metric::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--teal); }
.metric-warn::before { background: var(--warn); }
.metric-label { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: 1.4px; }
.metric-value { font-family: var(--serif); font-size: 2.7rem; line-height: 1.15; margin: 8px 0 4px; }
.metric-warn .metric-value { color: var(--warn); }
.metric-sub { color: var(--muted); font-size: .82rem; }

/* ---------- Content grid ---------- */
.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 22px; align-items: start; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input[type="search"], .filters select {
    padding: 9px 12px; border-radius: 10px; border: 1px solid var(--line);
    background: var(--bg); color: var(--text); font: inherit; font-size: .85rem;
}
.filters input[type="search"] { width: 230px; }
.filters input:focus, .filters select:focus { outline: none; border-color: var(--teal); }

.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
    text-align: left; padding: 11px 18px; white-space: nowrap;
    color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1.2px;
    border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--card-2);
}
.data-table th a:hover { color: var(--teal); }
.data-table td { padding: 14px 18px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr:hover { background: rgba(255, 255, 255, .025); }
.data-table tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; }
.data-table td:nth-child(7), .data-table td:nth-child(8) { white-space: nowrap; }
.data-table th.num { text-align: right; }
.sku { color: var(--teal); white-space: nowrap; font-size: .85rem; }
.name { min-width: 220px; }
.sub { display: block; color: var(--muted); font-size: .76rem; }
.unit { color: var(--muted); font-size: .78rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 0 !important; list-style: none; }

.bar { height: 4px; margin: 7px 0 0 auto; width: 90px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.row-low .bar i { background: var(--warn); }
.row-out .bar i { background: var(--danger); }

.pill { display: inline-block; padding: 3px 11px; border-radius: 99px; font-size: .74rem; font-weight: 600; white-space: nowrap; }
.pill-ok  { background: var(--ok-dim);     color: var(--ok); }
.pill-low { background: var(--warn-dim);   color: var(--warn); }
.pill-out { background: var(--danger-dim); color: var(--danger); }

/* ---------- Scans ---------- */
.scan-list { list-style: none; margin: 0; padding: 0 12px 14px; }
.scan { display: flex; align-items: center; gap: 12px; padding: 12px; border-radius: 10px; }
.scan:hover { background: rgba(255, 255, 255, .025); }
.scan-main { flex: 1; min-width: 0; }
.scan-main strong { display: block; font-weight: 600; font-size: .86rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scan time { font-size: .74rem; white-space: nowrap; }
.tag { padding: 3px 9px; border-radius: 7px; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .8px; background: var(--card-2); color: var(--muted); min-width: 52px; text-align: center; }
.tag-in     { background: var(--ok-dim);     color: var(--ok); }
.tag-out    { background: var(--danger-dim); color: var(--danger); }
.tag-count  { background: var(--teal-dim);   color: var(--teal); }
.tag-adjust { background: var(--warn-dim);   color: var(--warn); }
.scan-list-full { padding: 0 16px 20px; }

/* ---------- Narrower desktops / tablets ---------- */
/* Side panel only sits beside the table on wide screens (>= 1700px); otherwise it stacks below. */
@media (max-width: 1699px) {
    .content-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1360px) {
    .main { padding: 28px 28px 40px; }
}
@media (max-width: 960px) {
    .app { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; align-items: center; padding: 12px 16px; overflow-x: auto; gap: 8px; }
    .brand { padding: 0 12px 0 0; }
    .brand div, .nav-title, .sidebar-foot { display: none; }
    nav { flex-direction: row; }
    .nav-link { white-space: nowrap; }
    .metrics { grid-template-columns: 1fr; }
    .topbar { flex-direction: column; align-items: flex-start; }
}

/* ==========================================================================
   PRINT VIEW  (index.php?view=print)  - light, ink-friendly, paginated
   ========================================================================== */
body.print-view { background: #eef1f5; color: #111; font-family: var(--mono); }
.print-toolbar { display: flex; justify-content: space-between; max-width: 1100px; margin: 20px auto 0; padding: 0 20px; }
.print-toolbar .btn { background: #fff; color: #111; border-color: #cfd6e0; }
.print-toolbar .btn-primary { background: #0f766e; border-color: #0f766e; color: #fff; }

.sheet { max-width: 1100px; margin: 18px auto 40px; padding: 36px 40px; background: #fff; box-shadow: 0 2px 18px rgba(0, 0, 0, .08); }
.sheet-head { display: flex; justify-content: space-between; gap: 24px; border-bottom: 2px solid #111; padding-bottom: 14px; margin-bottom: 18px; }
.sheet-head h1 { font-size: 1.6rem; color: #111; }
.sheet-head p { margin: 4px 0 0; color: #444; font-size: .85rem; }
.sheet-meta { text-align: right; font-size: .8rem; color: #444; }

.sheet-table { width: 100%; border-collapse: collapse; font-size: .82rem; }
.sheet-table th { text-align: left; padding: 8px 10px; background: #f0f2f5; border: 1px solid #b8c0cc; font-size: .72rem; text-transform: uppercase; letter-spacing: .6px; }
.sheet-table td { padding: 8px 10px; border: 1px solid #ccd2db; }
.sheet-table th.num, .sheet-table td.num { text-align: right; }
.sheet-table tr { break-inside: avoid; }
.sheet-table thead { display: table-header-group; }   /* repeat header on every printed page */
.sheet-table .row-low td:nth-child(6), .sheet-table .row-out td:nth-child(6) { font-weight: 700; }
.sheet-table .row-out td:nth-child(6) { text-decoration: underline; }
.count-col { width: 110px; }
.sheet .empty { color: #666; }
.sheet-foot { display: flex; justify-content: space-between; gap: 20px; margin-top: 36px; font-size: .8rem; color: #333; }
.sheet .banner-error { background: #fdecee; color: #7a1620; border-color: #f0a3ab; }

@page { size: letter landscape; margin: 12mm; }
@media print {
    body, body.print-view { background: #fff !important; color: #000 !important; }
    .no-print, .sidebar, .actions, .filters { display: none !important; }
    .sheet { box-shadow: none; margin: 0; padding: 0; max-width: none; }

    /* If someone prints the dashboard itself instead of the print view */
    .app { display: block; }
    .main { padding: 0; max-width: none; }
    .card { background: #fff; border-color: #bbb; }
    .metric-value, .data-table td, .data-table th, h1, h2 { color: #000 !important; }
    .data-table th { background: #eee; }
    .scans-card { display: none; }
    .content-grid { display: block; }
    .metrics { gap: 12px; }
}


/* ==========================================================================
   SCANNER  (scan.php) - mobile-first, big tap targets
   ========================================================================== */
body.scanner { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
body.scanner code { background: var(--card-2); padding: 1px 6px; border-radius: 6px; color: var(--teal); }

.s-top {
    position: sticky; top: 0; z-index: 5;
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top));
    background: rgba(8, 16, 29, .94); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
}
.s-brand { display: flex; align-items: center; gap: 12px; }
.s-brand .brand-mark { width: 38px; height: 38px; }
.s-brand div strong { display: block; font-family: var(--serif); font-size: 1.02rem; line-height: 1.2; }
.s-brand div span   { display: block; color: var(--muted); font-size: .78rem; }
.s-top-actions { display: flex; align-items: center; gap: 4px; }
.s-top-actions form { margin: 0; }
.s-link { padding: 10px 12px; color: var(--teal); font-size: .85rem; border-radius: 8px; }
.s-linkbtn { background: none; border: 0; font: inherit; font-size: .85rem; cursor: pointer; }

.s-wrap { width: 100%; max-width: 560px; margin: 0 auto; padding: 18px 16px 40px; display: grid; gap: 16px; }
.s-wrap > .s-brand { margin-top: 10px; }
.s-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 14px; }
.s-card h1 { font-size: 1.35rem; }

.s-reader { width: 100%; aspect-ratio: 1 / 1; max-height: 62vh; border-radius: 12px; overflow: hidden; background: #050a14; border: 1px dashed var(--line); }
.s-reader video { object-fit: cover; }
.s-msg { margin: 0; font-size: .85rem; text-align: center; min-height: 1.3em; }
.s-msg.bad { color: var(--danger); }
.s-prefixes { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.s-prefixes span { padding: 4px 10px; border-radius: 99px; background: var(--card-2); color: var(--muted); font-size: .72rem; }

.s-label { color: var(--muted); font-size: .74rem; text-transform: uppercase; letter-spacing: 1.2px; }
.s-input {
    width: 100%; min-height: 52px; padding: 12px 14px;
    border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text);
    font: inherit; font-size: 1.05rem;
}
.s-input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-dim); }
.s-row { display: flex; gap: 10px; }
.s-row .s-btn { flex: none; }

.s-btn {
    display: flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 52px; padding: 12px 18px; width: 100%;
    border-radius: 12px; border: 1px solid var(--line); background: var(--card-2); color: var(--text);
    font: inherit; font-size: 1rem; font-weight: 600; cursor: pointer; touch-action: manipulation;
}
.s-btn:active { transform: scale(.98); }
.s-btn:disabled { opacity: .55; }
.s-btn-primary { background: var(--teal); border-color: var(--teal); color: #04211d; }
.s-btn-ghost { background: transparent; color: var(--muted); }

.s-item-head { display: flex; align-items: center; justify-content: space-between; }
.s-chip { display: inline-block; padding: 4px 10px; border-radius: 7px; background: var(--teal-dim); color: var(--teal); font-size: .68rem; font-weight: 700; letter-spacing: 1.2px; }
.s-item-name { line-height: 1.25; overflow-wrap: anywhere; }
.s-item-sub { margin: 0; font-size: .82rem; }
.s-qty-now { font-family: var(--serif); font-size: 3rem; line-height: 1; }
.s-qty-now .unit { font-family: var(--mono); font-size: 1rem; }

.s-seg { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.s-seg-2 { grid-template-columns: repeat(2, 1fr); margin-top: 2px; }
.s-seg button {
    min-height: 60px; padding: 8px 4px; border-radius: 12px; border: 1px solid var(--line);
    background: var(--bg); color: var(--muted); font: inherit; font-size: .98rem; font-weight: 700;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; cursor: pointer; touch-action: manipulation;
}
.s-seg button small { font-size: .62rem; font-weight: 400; }
.s-seg button.on { background: var(--teal-dim); border-color: var(--teal); color: var(--teal); }
.s-seg-2 button { min-height: 48px; }

.s-stepper { display: grid; grid-template-columns: 64px 1fr 64px; gap: 10px; }
.s-stepper .s-btn { padding: 0; font-size: 1.6rem; }
.s-qty-input { text-align: center; font-size: 1.6rem; font-weight: 700; min-height: 60px; }
.s-preview { margin: 0; min-height: 1.4em; text-align: center; color: var(--teal); font-size: .92rem; }
.s-preview.bad { color: var(--danger); }

.s-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.s-li {
    width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    min-height: 60px; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--line);
    background: var(--bg); color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.s-li-main { min-width: 0; }
.s-li-main strong { display: block; font-size: .95rem; overflow-wrap: anywhere; }
.s-li-main small { color: var(--muted); font-size: .72rem; }
.s-li-qty { white-space: nowrap; font-weight: 700; color: var(--ok); }
.s-li-qty.low { color: var(--warn); }
.s-li-qty.out { color: var(--danger); }

.s-toast {
    position: fixed; left: 16px; right: 16px; bottom: max(20px, env(safe-area-inset-bottom));
    max-width: 528px; margin: 0 auto; padding: 14px 18px; border-radius: 12px; z-index: 20;
    background: var(--teal); color: #04211d; font-weight: 700; text-align: center; box-shadow: 0 8px 30px rgba(0, 0, 0, .45);
}
.s-toast.bad { background: var(--danger); color: #fff; }

@media (min-width: 700px) { .s-wrap { padding-top: 32px; } }
#viewScan, #viewItem { display: grid; gap: 16px; }
.s-chip { justify-self: start; }
