:root {
  --bg: #121316; --panel: #1a1c20; --card: #212429; --card-2: #1c1e22; --line: #33363c; --line-2: #45484f;
  --text: #ECEAE4; --muted: #9C9A93; --faint: #6f6d68;
  --gold: #F2B51D; --gold-soft: #3a2f12; --gold-text: #F5C84C; --on-gold: #1b1405;
  --ok: #53A86D; --ok-soft: #15281c; --ok-text: #74C98E;
  --bad: #E5675C; --bad-soft: #3a1c1a; --bad-text: #F08A80;
  --head: 'Oswald', 'Barlow Condensed', 'Arial Narrow', sans-serif;
  --body: 'Inter', 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --h-btn: 44px; --r: 10px;
  color-scheme: dark;
}
@media (min-width: 900px) { :root { --h-btn: 40px; } }

* { box-sizing: border-box; }
html { scrollbar-gutter: stable; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text); font-family: var(--body);
  font-size: 16px; line-height: 1.5;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.wrap { max-width: 860px; margin: 0 auto; padding: 0 16px 120px; }
.ico { width: 18px; height: 18px; flex: none; display: inline-block; vertical-align: middle; }
.hidden { display: none !important; }

/* Header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 0 14px; border-bottom: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: flex-start; min-width: 0; }
.logo { width: 28px; height: 28px; border: 4px solid var(--gold); border-radius: 3px; flex: none; margin-top: 6px; position: relative; }
.logo::after { content: ''; position: absolute; inset: 4px; background: var(--gold); }
.brand h1 { font-family: var(--head); font-weight: 600; font-size: 32px; letter-spacing: .04em; margin: 0; line-height: 1.1; }
.brand .tag { font-family: var(--head); font-size: 15px; letter-spacing: .06em; color: var(--muted); margin: 2px 0 0; }
.brand .sub { font-size: 14px; color: var(--muted); margin: 2px 0 0; }
.actions { display: flex; gap: 8px; flex: none; }
@media (max-width: 600px) {
  .top { flex-direction: column; }
  .brand .sub { display: none; }
  .actions { width: 100%; }
  .actions .btn { flex: 1; }
}

/* Buttons */
.btn {
  height: var(--h-btn); padding: 0 14px; border-radius: var(--r); border: 1px solid var(--line-2);
  background: var(--card); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap; font-size: 15px; font-weight: 500; transition: background .15s, border-color .15s;
}
.btn:hover { border-color: var(--muted); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }
.btn.gold:hover { background: #ffc531; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad-text); border-color: #5a2a26; }
.btn[aria-busy="true"] { pointer-events: none; opacity: .85; }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn.sm { height: 36px; padding: 0 12px; font-size: 14px; }
.spin { width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; flex: none; }

/* Module tabs */
.modtabs { display: flex; gap: 6px; padding: 12px 0; }
.modtab { height: 40px; padding: 0 14px; border-radius: var(--r); border: 1px solid transparent; background: transparent; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; font-weight: 500; }
.modtab[aria-selected="true"] { color: var(--text); background: var(--card); border-color: var(--line); }

/* Toolbar + picker */
.toolbar { display: flex; gap: 8px; align-items: stretch; position: relative; }
.picker { flex: 1; min-width: 0; position: relative; }
.picker-btn {
  width: 100%; height: var(--h-btn); border-radius: var(--r); border: 1px solid var(--line-2); background: var(--card);
  display: flex; align-items: center; gap: 8px; padding: 0 12px; text-align: left;
}
.picker-btn .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.toolbar .btn { flex: none; width: 128px; }
.menu {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30; background: var(--panel);
  border: 1px solid var(--line-2); border-radius: var(--r); max-height: min(55vh, 420px); overflow: auto; overscroll-behavior: contain;
}
.menu button { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: transparent; }
.menu button:last-child { border-bottom: 0; }
.menu button:hover, .menu button[aria-selected="true"] { background: var(--card); }
.menu .m1 { font-weight: 500; display: flex; justify-content: space-between; gap: 8px; }
.menu .m2 { font-size: 13px; color: var(--muted); }
.menu .empty { padding: 14px; color: var(--muted); font-size: 14px; }

/* Summary card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; margin-top: 12px; }
.eyebrow { font-family: var(--head); font-size: 14px; letter-spacing: .06em; color: var(--muted); }
.lname { font-family: var(--head); font-size: 26px; font-weight: 600; letter-spacing: .02em; line-height: 1.2; margin-top: 2px; }
.meta { font-size: 14px; color: var(--muted); }
.bar { height: 10px; border-radius: 5px; background: #2c2f35; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--gold); border-radius: 5px; transition: width .3s ease-out; }
.bar.done > i { background: var(--ok); }
.prog { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.prog .bar { flex: 1; }
.prog .num { font-size: 15px; font-weight: 500; white-space: nowrap; font-variant-numeric: tabular-nums; }
.units { margin-top: 10px; display: grid; gap: 6px; }
.unit { display: grid; grid-template-columns: minmax(52px, auto) minmax(76px, auto) 1fr 18px; align-items: center; gap: 8px; font-size: 14px; }
.unit .u { color: var(--muted); }
.unit .v { font-variant-numeric: tabular-nums; }
.unit .bar { height: 6px; }
.unit .ok { color: var(--ok-text); }
.more-units { background: none; border: 0; color: var(--gold-text); font-size: 14px; padding: 4px 0; }
.sync { font-size: 13px; margin-top: 10px; display: flex; align-items: center; gap: 6px; color: var(--muted); }
.sync.ok { color: var(--ok-text); }
.sync.warn { color: var(--gold-text); }
.sync.bad { color: var(--bad-text); }
.sync button { background: none; border: 0; color: inherit; text-decoration: underline; padding: 0; }

/* Filter tabs */
.ftabs { display: flex; gap: 8px; margin: 16px 0 4px; }
.ftab { height: 40px; padding: 0 16px; border-radius: 20px; border: 1px solid var(--line-2); background: var(--card); color: var(--muted); font-weight: 500; }
.ftab { white-space: nowrap; }
@media (max-width: 480px) { .ftab { flex: 1; padding: 0 6px; font-size: 14.5px; } }
.ftab[aria-selected="true"] { background: var(--gold); border-color: var(--gold); color: var(--on-gold); }

/* Item rows */
.rows { margin-top: 8px; }
.row {
  position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto 112px; align-items: center; gap: 12px;
  background: var(--card-2); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: 12px;
  padding: 14px 14px 14px 14px; margin-top: 10px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
}
.row.s-done { border-left-color: var(--ok); }
.row.s-more { border-left-color: var(--gold); }
.row.s-less { border-left-color: var(--bad); }
.nm { font-size: 18px; font-weight: 500; line-height: 1.3; word-break: break-word; }
.nm .tap { cursor: pointer; }
.row.s-done .nm .tap { text-decoration: line-through; color: var(--faint); }
.sub { font-size: 14px; margin-top: 2px; color: var(--muted); }
.sub.more { color: var(--gold-text); } .sub.less { color: var(--bad-text); }
.prev { font-size: 13px; color: var(--faint); margin-top: 2px; }
.delta { display: inline-block; font-size: 13px; font-weight: 600; padding: 1px 7px; border-radius: 6px; margin-right: 6px; vertical-align: 2px; }
.delta.anim { animation: pop .35s ease-out; }
.delta.up { background: var(--gold-soft); color: var(--gold-text); }
.delta.dn { background: var(--bad-soft); color: var(--bad-text); }
.qty { text-align: right; }
.qty .n { font-family: var(--head); font-size: 30px; font-weight: 600; line-height: 1; font-variant-numeric: tabular-nums; }
.qty .u { font-size: 14px; color: var(--muted); }
.mark { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stamp {
  font-family: var(--head); font-size: 15px; font-weight: 600; letter-spacing: .06em; color: var(--ok-text);
  border: 2px solid var(--ok); border-radius: 7px; padding: 3px 9px; transform: rotate(-4deg); white-space: nowrap;
}
.stamp.hit { animation: stamp .22s ease-out; }
.who { font-size: 12px; color: var(--muted); white-space: nowrap; }
.row.flash { animation: flash .9s ease-out; }
.row .note { position: absolute; right: 12px; top: -10px; font-size: 12px; color: var(--gold-text); background: var(--bg); padding: 0 6px; animation: fade 2.4s forwards; pointer-events: none; }
@media (max-width: 480px) {
  .row { grid-template-columns: minmax(0, 1fr) auto 84px; gap: 8px; padding: 12px; }
  .nm { font-size: 17px; }
  .qty .n { font-size: 26px; }
  .stamp { font-size: 12.5px; padding: 2px 6px; letter-spacing: .03em; }
  .who { font-size: 11.5px; }
}

/* Detail panel */
.detail { background: var(--panel); border: 1px solid var(--line); border-top: 0; border-radius: 0 0 12px 12px; margin: -8px 0 0; padding: 16px 14px 12px; }
.detail h3 { font-size: 14px; color: var(--muted); font-weight: 500; margin: 0 0 8px; }
.drow { display: grid; grid-template-columns: minmax(0, 1fr) 90px 110px auto auto; column-gap: 8px; row-gap: 4px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); }
.drow:first-of-type { border-top: 0; }
.drow .btn { height: var(--h-btn); }
.drow .src { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
.drow .err { grid-column: 1 / -1; margin: 0; }
.drow .err:empty { display: none; }
@media (max-width: 560px) {
  .drow { grid-template-columns: 1fr 1fr auto auto; }
  .drow .f-nm { grid-column: 1 / -1; }
}
.inp { height: var(--h-btn); border-radius: 8px; border: 1px solid var(--line-2); background: var(--bg); padding: 0 10px; width: 100%; font-size: 16px; }
.inp:focus { border-color: var(--gold); outline: none; }
.err { color: var(--bad-text); font-size: 13px; margin-top: 4px; }

/* Add form */
.addbox { margin-top: 16px; }
.addform { display: grid; grid-template-columns: minmax(0, 1fr) 100px 110px auto; gap: 8px; margin-top: 8px; align-items: center; }
@media (max-width: 560px) { .addform { grid-template-columns: 1fr 1fr; } .addform .f-name { grid-column: 1 / -1; } .addform .f-btn { grid-column: 1 / -1; } }

/* Suggestions */
.ac { position: relative; min-width: 0; }
.acmenu {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 40; background: var(--panel);
  border: 1px solid var(--line-2); border-radius: 10px; max-height: 320px; overflow-y: auto; overscroll-behavior: contain;
}
.acmenu.up { top: auto; bottom: calc(100% + 4px); }
.acmenu.unit { right: auto; min-width: 100%; width: max-content; max-width: 220px; }
.aci {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%; min-height: 44px;
  padding: 8px 12px; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left;
}
.aci:last-child { border-bottom: 0; }
.aci:hover, .aci[aria-selected="true"] { background: var(--card); }
.aci .n { font-size: 15px; }
.aci .m { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* Empty & skeleton & notes */
.empty-state { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty-state h2 { font-family: var(--head); color: var(--text); font-size: 22px; letter-spacing: .03em; margin: 0 0 6px; }
.sk { height: 72px; border-radius: 12px; margin-top: 10px; background: linear-gradient(90deg, #1d1f23 0%, #2a2c31 50%, #1d1f23 100%); background-size: 200% 100%; animation: shim 1.2s linear infinite; }
.sk.sm { height: 120px; }
.wait { font-size: 14px; color: var(--muted); margin-top: 10px; display: flex; gap: 8px; align-items: center; }
.wait.warn { color: var(--gold-text); }
.placeholder { border: 1px dashed var(--line-2); border-radius: 12px; padding: 32px 16px; text-align: center; color: var(--muted); margin-top: 12px; }

/* Toast, banner, modal */
.toasts { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(520px, calc(100vw - 24px)); }
.toast { background: #2a2d33; border: 1px solid var(--line-2); border-radius: 10px; padding: 10px 12px; display: flex; align-items: center; gap: 10px; font-size: 15px; animation: rise .2s ease-out; }
.toast .t { flex: 1; }
.toast button { background: none; border: 0; color: var(--gold-text); font-weight: 600; padding: 6px; }
.toast.bad { border-color: #5a2a26; }
.banner { position: sticky; top: 0; z-index: 50; background: var(--gold); color: var(--on-gold); padding: 10px 16px; display: flex; justify-content: center; gap: 12px; align-items: center; font-weight: 500; }
.banner button { background: var(--on-gold); color: var(--gold); border: 0; border-radius: 8px; padding: 6px 12px; font-weight: 600; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 70; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px; width: min(520px, 100%); max-height: 90vh; overflow: auto; padding: 18px; }
.modal h2 { font-family: var(--head); letter-spacing: .04em; margin: 0 0 12px; font-size: 22px; }
.modal h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); font-weight: 500; }
.modal .row2 { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; margin-top: 16px; }
.kv { font-size: 14px; color: var(--muted); }

/* Login */
.login { max-width: 400px; margin: 8vh auto 0; }
.login label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
.login .btn { width: 100%; margin-top: 18px; }

@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { 0% { transform: scale(.5); opacity: 0; } 60% { transform: scale(1.15); opacity: 1; } 100% { transform: scale(1); } }
@keyframes stamp { from { transform: scale(1.4) rotate(0deg); opacity: 0; } to { transform: scale(1) rotate(-4deg); opacity: 1; } }
@keyframes flash { 0%, 30% { border-color: var(--gold); background: #2b2618; } 100% { background: var(--card-2); } }
@keyframes fade { 0%, 75% { opacity: 1; } 100% { opacity: 0; } }
@keyframes shim { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition: none !important; }
  .spin { animation: none; border-right-color: currentColor; opacity: .6; }
}
