/* KD Stores -- mobile-first, no build step. */
:root {
    --navy: #0d2941;
    --navy-2: #163a5c;
    --bg: #f3f5f8;
    --card: #ffffff;
    --text: #17202b;
    --muted: #5c6b7a;
    --line: #dde3ea;
    --ok: #1a7f37;
    --ok-bg: #e3f4e8;
    --warn: #9a6200;
    --warn-bg: #fff3d6;
    --bad: #b42318;
    --bad-bg: #fde7e5;
    --none: #5c6b7a;
    --none-bg: #eceff3;
    --accent: #0b63c5;
    --radius: 12px;
    --tabbar-h: 60px;
    color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
    padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}
a { color: var(--accent); }
h1 { font-size: 1.35rem; margin: 0 0 12px; }
h2 { font-size: 1.1rem; margin: 24px 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; letter-spacing: .02em; }
.right { text-align: right; }
.hidden { display: none !important; }

/* ---- top bar & tab bar ---- */
.topbar {
    position: sticky; top: 0; z-index: 20;
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; background: var(--navy); color: #fff;
}
.topbar img { width: 28px; height: 28px; border-radius: 6px; }
.topbar .brand { font-weight: 700; color: #fff; text-decoration: none; flex: 1; }
.topbar details { position: relative; }
.topbar summary { list-style: none; cursor: pointer; font-size: .9rem; opacity: .9; padding: 6px 0; }
.topbar summary::-webkit-details-marker { display: none; }
.topbar .menu {
    position: absolute; right: 0; top: 36px; min-width: 200px;
    background: #fff; color: var(--text); border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0,0,0,.18); padding: 6px; z-index: 30;
}
.topbar .menu a, .topbar .menu button {
    display: block; width: 100%; text-align: left; padding: 10px 12px;
    background: none; border: 0; font: inherit; color: inherit; text-decoration: none; border-radius: 8px;
}
.topbar .menu a:hover, .topbar .menu button:hover { background: var(--bg); }

.tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff; border-top: 1px solid var(--line);
}
.tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    font-size: .75rem; color: var(--muted); text-decoration: none; gap: 2px;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a.active { color: var(--navy); font-weight: 700; }

.container { max-width: 760px; margin: 0 auto; padding: 16px; }

/* ---- flash & errors ---- */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; }
.flash.ok { background: var(--ok-bg); color: var(--ok); }
.flash.bad { background: var(--bad-bg); color: var(--bad); }
.flash ul { margin: 4px 0 0; padding-left: 18px; }
.field-error { color: var(--bad); font-size: .875rem; margin-top: 4px; }

/* ---- buttons ---- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 44px; padding: 0 16px; border-radius: 10px;
    border: 1px solid var(--line); background: #fff; color: var(--text);
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

.fab {
    position: fixed; right: 16px; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px); z-index: 15;
    min-height: 52px; padding: 0 20px; border-radius: 26px;
    box-shadow: 0 6px 18px rgba(13,41,65,.35);
}

/* ---- pills & dots ---- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.reorder { background: var(--warn-bg); color: var(--warn); }
.pill.out { background: var(--bad-bg); color: var(--bad); }
.pill.none { background: var(--none-bg); color: var(--none); }
.pill.store { background: var(--ok-bg); color: var(--ok); }
.pill.issued { background: #e2ecfb; color: #1d4f91; }
.pill.faulty { background: var(--bad-bg); color: var(--bad); }
.dot {
    display: inline-block; width: 14px; height: 14px; border-radius: 50%;
    border: 1px solid rgba(0,0,0,.25); vertical-align: -2px; flex: none;
}

/* ---- alerts strip ---- */
.alerts { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; border-radius: 10px; margin-bottom: 14px; background: var(--bad-bg); }
.alerts strong { color: var(--bad); margin-right: 4px; }
.alerts a { text-decoration: none; }

/* ---- stock cards ---- */
.cards { display: grid; gap: 12px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.card-head { display: flex; align-items: center; gap: 8px; }
.card-head .name { font-weight: 700; flex: 1; }
.balance { font-size: 2rem; font-weight: 800; line-height: 1.1; margin: 8px 0 4px; }
.balance .unit { font-size: 1rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.meta { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: .85rem; color: var(--muted); margin: 8px 0 12px; }
.meta b { color: var(--text); font-weight: 600; }

/* ---- lists ---- */
.list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.list .row { padding: 12px 14px; border-top: 1px solid var(--line); }
.list .row:first-child { border-top: 0; }
.row-top { display: flex; gap: 8px; align-items: baseline; justify-content: space-between; }
.row.voided .row-body { text-decoration: line-through; color: var(--muted); }
.void-note { color: var(--bad); font-size: .85rem; margin-top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { font: .8rem/1.6 ui-monospace, Menlo, Consolas, monospace; padding: 0 8px; border-radius: 6px; background: var(--none-bg); }
button.chip { border: 1px dashed var(--accent); background: #fff; color: var(--accent); min-height: 34px; cursor: pointer; }

.tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.tile { background: var(--card); border-radius: var(--radius); padding: 12px; text-align: center; text-decoration: none; color: var(--text); border: 2px solid transparent; }
.tile.active { border-color: var(--navy); }
.tile .n { font-size: 1.6rem; font-weight: 800; }
.tile .l { font-size: .8rem; color: var(--muted); }

table.data { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; font-size: .9rem; }
table.data th, table.data td { padding: 10px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { background: #f8fafc; font-size: .8rem; color: var(--muted); border-top: 0; }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---- forms ---- */
.form { background: var(--card); border-radius: var(--radius); padding: 16px; }
.field { margin-bottom: 14px; }
.field > label, .label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
input[type=text], input[type=tel], input[type=password], input[type=number], input[type=date], input[type=search], select, textarea {
    width: 100%; min-height: 46px; padding: 10px 12px;
    font: inherit; color: inherit; background: #fff;
    border: 1px solid #c3ccd6; border-radius: 10px;
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-weight: 600; }
.check input { width: 22px; height: 22px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form > * { flex: 1 1 140px; }
.filters { display: flex; gap: 8px; margin-bottom: 12px; }
.filters > * { flex: 1; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label {
    display: flex; align-items: center; justify-content: center; min-height: 46px;
    border: 1px solid #c3ccd6; border-radius: 10px; font-weight: 600; font-size: .9rem; cursor: pointer; background: #fff;
}
.segmented input:checked + label { background: var(--navy); border-color: var(--navy); color: #fff; }
.segmented input:focus-visible + label { outline: 2px solid var(--accent); }

.serial-tools { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.serial-tools .count { margin-left: auto; font-size: .875rem; color: var(--muted); }

/* ---- scanner overlay ---- */
.scanner {
    position: fixed; inset: 0; z-index: 50; background: #000;
    display: flex; flex-direction: column;
}
.scanner video { flex: 1; width: 100%; object-fit: cover; min-height: 0; }
.scanner .frame {
    position: absolute; left: 8%; right: 8%; top: 30%; height: 28%;
    border: 3px solid rgba(255,255,255,.85); border-radius: 12px; pointer-events: none;
    box-shadow: 0 0 0 9999px rgba(0,0,0,.35);
}
.scanner .bar { display: flex; gap: 8px; align-items: center; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); background: #111; color: #fff; }
.scanner .bar .msg { flex: 1; font-size: .9rem; }

details.inline > summary { cursor: pointer; color: var(--accent); font-size: .875rem; margin-top: 6px; }
details.inline[open] > summary { margin-bottom: 8px; }

.pager { display: flex; justify-content: space-between; margin-top: 14px; }

/* ---- auth ---- */
.auth { max-width: 380px; margin: 8vh auto 0; padding: 0 16px; }
.auth .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.auth .logo img { width: 44px; height: 44px; border-radius: 10px; }
