:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #121826;
  --muted: #667085;
  --line: #e4e8f0;
  --brand: #1d4ed8;
  --brand-soft: #e6edff;
  --brand-ink: #ffffff;
  --red: #d92d20;
  --red-soft: #fdecea;
  --amber: #b54708;
  --amber-soft: #fef3e2;
  --green: #067647;
  --green-soft: #e3f7ec;
  --wa: #1fa855;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --sheet-shadow: 0 -10px 40px rgba(16, 24, 40, .18);
  --r: 16px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020;
    --card: #151b2e;
    --text: #eef1f8;
    --muted: #98a2b8;
    --line: #262e46;
    --brand: #5b8cff;
    --brand-soft: #1b2a55;
    --brand-ink: #0b1020;
    --red: #ff6b5e;
    --red-soft: #3a1714;
    --amber: #ffb347;
    --amber-soft: #3a2711;
    --green: #4ade80;
    --green-soft: #12301f;
    --shadow: none;
    --sheet-shadow: 0 -10px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
  min-height: 100dvh;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
input, select, textarea {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 14px; width: 100%; outline: none; font-size: 16px;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); }

.wrap { max-width: 720px; margin: 0 auto; padding: 0 16px calc(110px + var(--safe-b)); }

/* Header */
.top {
  position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px);
  padding: calc(10px + var(--safe-t)) 0 10px;
}
.top-row { display: flex; align-items: center; gap: 10px; }
.top h1 { font-size: 26px; line-height: 1.15; margin: 0; letter-spacing: -.02em; flex: 1; }
.top .sub { color: var(--muted); font-size: 13px; }
.sync { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); display: inline-block; }
.dot.off { background: var(--amber); }
.dot.busy { background: var(--brand); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }

.search { position: relative; margin-top: 10px; }
.search input { padding-left: 40px; border-radius: 14px; background: var(--card); }
.search .ico { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); opacity: .5; pointer-events: none; }

/* Summary */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 6px 0 14px; }
.stat {
  background: var(--card); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow);
  text-align: left; display: block; width: 100%;
}
.stat b { display: block; font-size: 24px; line-height: 1.1; }
.stat span { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; color: var(--muted); }
.stat.red b { color: var(--red); } .stat.amber b { color: var(--amber); } .stat.blue b { color: var(--brand); }

/* Sections */
.sec-h {
  display: flex; align-items: center; gap: 8px; margin: 18px 4px 8px;
  font-weight: 700; font-size: 15px;
}
.sec-h .hi { color: var(--muted); font-weight: 500; font-size: 13px; }
.sec-h .count { margin-left: auto; color: var(--muted); font-weight: 500; font-size: 13px; }
.sec-h button.link { margin-left: auto; }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }

/* Rows */
.row {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; min-height: 60px;
  border-bottom: 1px solid var(--line); width: 100%; text-align: left; position: relative;
}
.row:last-child { border-bottom: 0; }
.row .em { font-size: 26px; width: 34px; text-align: center; flex: none; }
.row .main { flex: 1; min-width: 0; }
.row .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .name small { font-weight: 400; color: var(--muted); margin-left: 6px; font-size: 13px; }
.row .meta { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar { height: 4px; border-radius: 4px; background: var(--line); margin-top: 7px; overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--green); }
.bar.soon i { background: var(--amber); } .bar.over i { background: var(--red); }

.pill {
  flex: none; font-size: 12.5px; font-weight: 700; padding: 5px 10px; border-radius: 999px;
  background: var(--green-soft); color: var(--green); white-space: nowrap;
}
.pill.soon { background: var(--amber-soft); color: var(--amber); }
.pill.over, .pill.out, .pill.today { background: var(--red-soft); color: var(--red); }
.pill.none { background: var(--line); color: var(--muted); }
.pill.list { background: var(--brand-soft); color: var(--brand); }

.qbtn {
  flex: none; font-size: 13.5px; font-weight: 700; padding: 9px 12px; border-radius: 12px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap;
}
.qbtn.green { background: var(--green-soft); color: var(--green); }

/* Attention cards */
.alert-card .row { align-items: flex-start; flex-wrap: wrap; }
.alert-actions { display: flex; gap: 8px; width: 100%; padding-left: 46px; margin-top: 2px; flex-wrap: wrap; }
.alert-actions .qbtn { padding: 8px 11px; }

/* Buttons */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 52px; border-radius: 14px; font-weight: 700; padding: 0 16px; width: 100%;
  background: var(--brand); color: #fff; font-size: 16.5px;
}
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.ghost { background: var(--card); color: var(--text); border: 1.5px solid var(--line); }
.btn.red { background: var(--red-soft); color: var(--red); }
.btn.green { background: var(--green-soft); color: var(--green); }
.btn.wa { background: var(--wa); color: #fff; }
.btn:active, .qbtn:active, .chip:active, .row:active, .stat:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; }
.link { color: var(--brand); font-weight: 600; font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }

/* Chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -16px; padding: 2px 16px; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chip {
  padding: 10px 14px; border-radius: 999px; background: var(--card); border: 1.5px solid var(--line);
  font-weight: 600; font-size: 14.5px; white-space: nowrap; flex: none;
}
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.chip.sm { padding: 6px 11px; font-size: 13px; }
.chip small { opacity: .7; font-weight: 500; }

/* Catalog tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.tile {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 14px; padding: 10px 6px 8px;
  text-align: center; position: relative; min-height: 92px;
}
.tile .e { font-size: 28px; display: block; }
.tile .n { font-weight: 600; font-size: 13px; line-height: 1.2; display: block; margin-top: 4px; }
.tile .h { font-size: 11.5px; color: var(--muted); display: block; }
.tile.have { opacity: .55; }
.tile.have::after, .tile.sel::after {
  content: '✓'; position: absolute; top: 6px; right: 8px; font-size: 13px; font-weight: 800; color: var(--green);
}
.tile.sel { border-color: var(--brand); background: var(--brand-soft); }
.tile.sel::after { color: var(--brand); }

/* Tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(16px); -webkit-backdrop-filter: saturate(1.4) blur(16px);
  border-top: 1px solid var(--line); padding-bottom: var(--safe-b);
}
.tabs-in { max-width: 720px; margin: 0 auto; display: grid; grid-template-columns: 1fr 1fr 84px 1fr 1fr; align-items: center; }
.tab { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; font-weight: 600; color: var(--muted); position: relative; }
.tab .ti { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .75; }
.tab.on { color: var(--brand); }
.tab.on .ti { filter: none; opacity: 1; }
.tab .badge {
  position: absolute; top: 3px; left: calc(50% + 6px); background: var(--red); color: #fff;
  font-size: 11px; font-weight: 800; min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  display: flex; align-items: center; justify-content: center;
}
.fab {
  justify-self: center; width: 60px; height: 60px; border-radius: 20px; background: var(--brand); color: #fff;
  font-size: 32px; font-weight: 300; margin-top: -26px; box-shadow: 0 8px 20px color-mix(in srgb, var(--brand) 45%, transparent);
  display: flex; align-items: center; justify-content: center;
}

/* Sheet */
.backdrop { position: fixed; inset: 0; background: rgba(8, 12, 24, .45); z-index: 20; animation: fade .18s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21; background: var(--bg);
  border-radius: 22px 22px 0 0; box-shadow: var(--sheet-shadow);
  max-height: 92dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 8px 16px calc(20px + var(--safe-b)); animation: up .24s cubic-bezier(.2, .9, .3, 1);
  max-width: 720px; margin: 0 auto;
}
.sheet.full { height: 92dvh; }
@media (min-width: 760px) {
  .sheet { bottom: auto; top: 50%; transform: translateY(-50%); border-radius: 22px; max-height: 86dvh; width: 620px; animation: pop .2s ease; }
  .sheet.full { height: 86dvh; }
}
.grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 10px; }
.sheet-h { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.sheet-h .em { font-size: 38px; }
.sheet-h h2 { margin: 0; font-size: 22px; line-height: 1.2; }
.sheet-h .hi { color: var(--muted); font-size: 14px; }
.sheet-h .x { margin-left: auto; width: 34px; height: 34px; border-radius: 50%; background: var(--card); font-size: 18px; color: var(--muted); flex: none; }
.lbl { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin: 18px 2px 8px; }
.status-box { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.status-box .big { font-size: 18px; font-weight: 700; }
.status-box .small { color: var(--muted); font-size: 13.5px; margin-top: 2px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card); border: 1.5px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { padding: 10px 6px; border-radius: 9px; font-weight: 600; font-size: 14px; }
.seg button.on { background: var(--brand); color: #fff; }
.hint { font-size: 13px; color: var(--muted); margin: 6px 2px 0; }

@keyframes up { from { transform: translateY(100%); } }
@keyframes pop { from { opacity: 0; transform: translateY(-46%); } }
@keyframes fade { from { opacity: 0; } }

/* List screen */
.check {
  width: 28px; height: 28px; border-radius: 8px; border: 2px solid var(--line); flex: none;
  display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; font-size: 16px;
}
.check.on { background: var(--green); border-color: var(--green); }
.row.got .name { text-decoration: line-through; color: var(--muted); }
.src { flex: none; font-size: 12.5px; font-weight: 700; padding: 6px 10px; border-radius: 10px; border: 1.5px dashed var(--line); color: var(--muted); }
.src.CSD { border: 0; background: #e7f0e2; color: #3f6212; }
.src.Online { border: 0; background: #e8edff; color: #3538cd; }
.src.Supermarket { border: 0; background: #fdeeda; color: #b54708; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .src.CSD { background: #22331a; color: #a3e635; }
  :root:not([data-theme="light"]) .src.Online { background: #1f2552; color: #a4b4ff; }
  :root:not([data-theme="light"]) .src.Supermarket { background: #3a2711; color: #ffb347; }
}
.qty { font-size: 13px; color: var(--text); font-weight: 600; }
.x-btn { width: 32px; height: 32px; border-radius: 50%; color: var(--muted); font-size: 18px; flex: none; }
.sharebar {
  position: fixed; left: 0; right: 0; bottom: calc(64px + var(--safe-b)); z-index: 9; padding: 10px 16px;
  pointer-events: none;
}
.sharebar .in { max-width: 688px; margin: 0 auto; display: flex; gap: 8px; pointer-events: auto; }
.sharebar .btn { box-shadow: 0 6px 18px rgba(16, 24, 40, .18); }
.sharebar .btn.icon { width: 56px; flex: none; padding: 0; }

.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .big { font-size: 48px; }
.empty h3 { color: var(--text); margin: 10px 0 6px; }

/* Onboarding */
.hero { text-align: center; padding: calc(40px + var(--safe-t)) 8px 10px; }
.hero .logo { width: 88px; height: 88px; border-radius: 24px; box-shadow: 0 10px 30px rgba(29, 78, 216, .3); }
.hero h1 { font-size: 30px; margin: 16px 0 6px; letter-spacing: -.02em; }
.hero p { color: var(--muted); margin: 0 auto 26px; max-width: 360px; }
.codebox {
  font: 700 26px/1.2 ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .08em; text-align: center;
  background: var(--card); border: 2px dashed var(--brand); border-radius: 14px; padding: 14px; color: var(--brand);
  user-select: all; -webkit-user-select: all;
}
.code-input { text-transform: uppercase; font: 700 22px ui-monospace, "SF Mono", Menlo, monospace; letter-spacing: .1em; text-align: center; }

#toast {
  position: fixed; left: 50%; top: calc(12px + var(--safe-t)); transform: translateX(-50%) translateY(-20px);
  background: #121826; color: #fff; padding: 12px 16px; border-radius: 14px; font-weight: 600; font-size: 14.5px;
  opacity: 0; pointer-events: none; transition: .2s; z-index: 50; display: flex; gap: 14px; align-items: center;
  max-width: calc(100% - 32px); box-shadow: 0 10px 30px rgba(0, 0, 0, .25);
}
#toast.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
#toast button { color: #8fb0ff; font-weight: 800; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) #toast { background: #2b3552; border: 1px solid #3d4a70; } }

.settings .row { min-height: 54px; }
.settings .row .val { color: var(--muted); font-size: 14px; }
.kbd-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 18px; }

@media (min-width: 760px) {
  .top h1 { font-size: 30px; }
  .wrap { padding-left: 24px; padding-right: 24px; }
}
