:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1f4fd1;
  --accent-soft: #e8eefc;
  --in: #15803d;
  --in-soft: #e6f6ec;
  --out: #c2410c;
  --out-soft: #fdeee4;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --input: #f7f8fa;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --r: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --card: #1a1d23; --text: #eef0f3; --muted: #9aa3af; --line: #2a2f37;
    --accent: #6d95ff; --accent-soft: #1d2740; --in: #4ade80; --in-soft: #12291b;
    --out: #fb923c; --out-soft: #32200f; --warn: #fbbf24; --warn-soft: #33290e; --danger: #f87171;
    --input: #22262d; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding-bottom: calc(var(--nav-h) + var(--safe-b) + 16px); }
body.form-mode { padding-bottom: calc(96px + var(--safe-b)); }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[hidden] { display: none !important; }

/* top bar */
.top { position: sticky; top: 0; z-index: 10; background: var(--bg); padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  display: flex; align-items: center; gap: 8px; }
.top h1 { font-size: 22px; margin: 0; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top.small h1 { font-size: 18px; }
.icon-btn { border: 0; background: var(--card); box-shadow: var(--shadow); width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--text); flex: none; cursor: pointer; }
.icon-btn.ghost { background: transparent; box-shadow: none; }
.pdf-btn { border: 0; background: var(--accent-soft); color: var(--accent); height: 42px; padding: 0 14px; border-radius: 12px;
  font-weight: 600; display: inline-flex; align-items: center; gap: 6px; flex: none; cursor: pointer; }
.pdf-btn svg { width: 20px; height: 20px; }

.wrap { padding: 0 16px; max-width: 720px; margin: 0 auto; }
.top > .inner { max-width: 720px; margin: 0 auto; width: 100%; display: flex; align-items: center; gap: 8px; }

/* search */
.search { position: relative; margin: 2px 0 12px; }
.search input { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--card);
  padding: 0 14px 0 44px; font-size: 16px; color: var(--text); outline: none; }
.search input:focus { border-color: var(--accent); }
.search svg { position: absolute; left: 13px; top: 12px; color: var(--muted); }

.meta { color: var(--muted); font-size: 14px; margin: 0 2px 8px; display: flex; justify-content: space-between; }

/* list */
.list { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; padding: 13px 14px; border-top: 1px solid var(--line); color: var(--text); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:active { background: var(--input); }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row .s { color: var(--muted); font-size: 13.5px; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .q { text-align: right; flex: none; }
.row .q b { font-size: 18px; display: block; }
.row .q small { color: var(--muted); font-size: 13px; }
.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--input); color: var(--muted); }
.ic { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex: none; }
.ic.in { background: var(--in-soft); color: var(--in); }
.ic.out { background: var(--out-soft); color: var(--out); }
.ic svg { width: 20px; height: 20px; }
.plus { color: var(--in); } .minus { color: var(--out); }
.group-h { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; margin: 18px 4px 8px; }
.group-h:first-child { margin-top: 4px; }

.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty svg { width: 48px; height: 48px; stroke-width: 1.5; opacity: .5; margin-bottom: 8px; }
.empty b { display: block; color: var(--text); font-size: 17px; margin-bottom: 4px; }

/* item page */
.hero { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 16px; }
.hero h2 { margin: 0 0 6px; font-size: 20px; line-height: 1.25; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.chip { font-size: 13px; background: var(--input); color: var(--muted); padding: 3px 9px; border-radius: 99px; }
.bal { display: flex; align-items: baseline; gap: 8px; }
.bal b { font-size: 40px; line-height: 1; letter-spacing: -.02em; }
.bal span { color: var(--muted); font-size: 18px; }
.bal-l { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.btn { border: 0; height: 52px; border-radius: 14px; font-weight: 700; font-size: 16px; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; cursor: pointer; width: 100%; }
.btn svg { width: 20px; height: 20px; }
.btn.in { background: var(--in); color: #fff; }
.btn.out { background: var(--out); color: #fff; }
.btn.primary { background: var(--accent); color: #fff; }
.btn.soft { background: var(--accent-soft); color: var(--accent); }
.btn.plain { background: var(--input); color: var(--text); }
.btn.danger { background: var(--danger); color: #fff; }
.btn:disabled { opacity: .55; }
@media (prefers-color-scheme: dark) { .btn.in, .btn.out { color: #0b0d10; } }
.banner { border-radius: 12px; padding: 12px 14px; font-size: 14.5px; margin-top: 14px; display: flex; gap: 10px; align-items: flex-start; }
.banner svg { width: 20px; height: 20px; flex: none; margin-top: 1px; }
.banner.warn { background: var(--warn-soft); color: var(--warn); }
.banner.info { background: var(--input); color: var(--muted); }
.section-h { display: flex; align-items: center; justify-content: space-between; margin: 22px 4px 8px; }
.section-h h3 { margin: 0; font-size: 17px; }
.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; cursor: pointer; padding: 6px 4px; }
.props { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); display: grid; grid-template-columns: 1fr 1fr; }
.prop { padding: 10px 14px; border-top: 1px solid var(--line); min-width: 0; }
.prop:nth-child(-n+2) { border-top: 0; }
.prop:nth-child(odd) { border-right: 1px solid var(--line); }
.prop .l { font-size: 12.5px; color: var(--muted); }
.prop .v { font-weight: 500; overflow-wrap: anywhere; }
.prop .v.none { color: var(--muted); font-weight: 400; }

/* forms */
.form { display: flex; flex-direction: column; gap: 14px; }
.fcard { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.fcard > .fh { font-weight: 700; font-size: 15px; margin-bottom: -4px; }
.field label { display: block; font-size: 13.5px; color: var(--muted); margin: 0 0 5px 2px; font-weight: 500; }
.field label .req { color: var(--danger); }
.field input, .field select { width: 100%; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: var(--input);
  padding: 0 13px; font-size: 16px; color: var(--text); outline: none; }
.field input:focus { border-color: var(--accent); background: var(--card); }
.field .hint { font-size: 13px; color: var(--muted); margin: 5px 2px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
.qty-box { display: flex; align-items: center; gap: 10px; }
.qty-box input { height: 60px; font-size: 26px; font-weight: 700; text-align: center; }
.qty-box .unit { font-size: 18px; color: var(--muted); min-width: 36px; }
.quick { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.quick button { border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.quick button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.summary { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; border-radius: 12px; background: var(--input); font-size: 15px; }
.summary b { font-size: 18px; }
.item-mini { display: flex; gap: 12px; align-items: center; }
.item-mini .t { font-weight: 700; }
.item-mini .s { color: var(--muted); font-size: 14px; }
details.more { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); }
details.more summary { padding: 14px; font-weight: 700; font-size: 15px; cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; }
details.more summary::-webkit-details-marker { display: none; }
details.more summary small { font-weight: 400; color: var(--muted); }
details.more summary svg { width: 20px; height: 20px; transition: transform .2s; color: var(--muted); }
details.more[open] summary svg { transform: rotate(180deg); }
details.more .fcard { box-shadow: none; padding-top: 0; }
.submit-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--bg); padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); }
.submit-bar .inner { max-width: 720px; margin: 0 auto; }
.err { color: var(--danger); font-size: 14px; min-height: 0; }

/* segmented */
.seg { display: flex; gap: 6px; overflow-x: auto; margin: 2px -16px 12px; padding: 0 16px; scrollbar-width: none; }
.seg::-webkit-scrollbar { display: none; }
.seg button { flex: none; border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 99px; height: 36px; padding: 0 14px; font-size: 14.5px; cursor: pointer; }
.seg button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stats { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; margin-bottom: 14px; }
.stat { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.stat b { font-size: 20px; }

/* bottom nav */
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; height: calc(var(--nav-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr); align-items: center; }
.nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; color: var(--muted); font-size: 11.5px; font-weight: 600; padding: 6px 0; }
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--accent); }
.fab { justify-self: center; width: 56px; height: 56px; border-radius: 18px; border: 0; background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; margin-top: -22px; box-shadow: 0 6px 16px rgba(31,79,209,.35); cursor: pointer; }
.fab svg { width: 28px; height: 28px; stroke-width: 2.4; }

/* bottom sheet / modal */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + var(--safe-b)); animation: up .2s ease-out; max-height: 90vh; overflow: auto; }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 12px; }
.sheet h3 { margin: 0 0 6px; font-size: 19px; }
.sheet p { margin: 0 0 14px; color: var(--muted); }
.sheet .stack { display: flex; flex-direction: column; gap: 10px; }
.op { display: flex; align-items: center; gap: 14px; padding: 12px; border-radius: 14px; background: var(--input); border: 0; width: 100%; text-align: left; cursor: pointer; }
.op .ic { width: 46px; height: 46px; }
.op .ic.new { background: var(--accent-soft); color: var(--accent); }
.op b { display: block; font-size: 16px; }
.op small { color: var(--muted); font-size: 13.5px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 14px); z-index: 60;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-size: 15px; max-width: calc(100% - 32px); box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.toast.err { background: var(--danger); color: #fff; }

/* login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login .box { width: 100%; max-width: 380px; }
.login .logo { width: 64px; height: 64px; border-radius: 18px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; }
.login .logo svg { width: 34px; height: 34px; }
.login h1 { text-align: center; margin: 0 0 4px; font-size: 26px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 24px; }

.user-row .s { white-space: normal; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 60px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (min-width: 720px) { .props { grid-template-columns: 1fr 1fr 1fr; } .prop:nth-child(3) { border-top: 0; } .prop:nth-child(odd) { border-right: 0; } .prop { border-right: 1px solid var(--line); } .prop:nth-child(3n) { border-right: 0; } }
