:root {
  color-scheme: light dark;
  --bg: #f2f5f1;
  --surface: #ffffff;
  --surface-2: #f6f8f5;
  --text: #17211a;
  --muted: #65736a;
  --line: #e1e8e2;
  --primary: #15803d;
  --primary-ink: #ffffff;
  --soft: #e8f5ec;
  --red: #b42318;
  --red-soft: #fef3f2;
  --amber: #b54708;
  --amber-soft: #fffaeb;
  --green: #067647;
  --green-soft: #ecfdf3;
  --blue: #175cd3;
  --blue-soft: #eff4ff;
  --shadow: 0 10px 30px -18px rgba(23, 33, 26, .35);
  --radius: 16px;
  --radius-sm: 11px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c110e;
    --surface: #161d18;
    --surface-2: #111713;
    --text: #e9efea;
    --muted: #97a69d;
    --line: #263029;
    --primary: #4ade80;
    --primary-ink: #052e16;
    --soft: #10281a;
    --red: #f97066;
    --red-soft: #391917;
    --amber: #fdb022;
    --amber-soft: #33250d;
    --green: #75e0a7;
    --green-soft: #0d2a1b;
    --blue: #84adff;
    --blue-soft: #16233c;
    --shadow: 0 10px 30px -18px rgba(0, 0, 0, .75);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
.icon { display: inline-block; vertical-align: -3px; flex: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.muted { color: var(--muted); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-green { color: var(--green); }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.nowrap { white-space: nowrap; }
.hide-mobile { display: none; }
.show-mobile { display: initial; }
.w-full { width: 100%; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-3 { margin-bottom: 12px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.grow { flex: 1; min-width: 0; }
.center { text-align: center; }
.right { text-align: right; }
.divider { height: 1px; background: var(--line); margin: 14px 0; border: 0; }

/* App shell */
.app { min-height: 100vh; }
.main { min-width: 0; }
.page {
  padding: 14px 14px calc(86px + var(--safe-bottom));
  max-width: 1180px;
  margin: 0 auto;
}
.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.page-title { margin: 0; font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.page-actions { display: flex; align-items: center; gap: 6px; flex: none; }
.section-title {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 18px 0 8px; font-size: 13px; font-weight: 650;
}
.section-title .muted { font-weight: 400; font-size: 11px; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand-mobile { display: flex; align-items: center; gap: 7px; font-weight: 650; font-size: 14px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--primary); color: var(--primary-ink);
  display: grid; place-items: center; flex: none;
}
.brand-mark .icon { width: 19px; height: 19px; }
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 6px; margin-left: auto; }
.store-form { margin: 0; }
.store-select {
  height: 34px; max-width: 128px; padding: 0 26px 0 10px;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--text);
  font-size: 12px; font-weight: 550;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 14px, calc(100% - 9px) 14px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.icon-btn {
  width: 34px; height: 34px; display: grid; place-items: center;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text);
}
.icon-btn:hover { text-decoration: none; background: var(--surface-2); }
.icon-btn .icon { width: 18px; height: 18px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--soft); color: var(--primary);
  display: grid; place-items: center; font-size: 12px; font-weight: 650;
  border: 1px solid transparent;
}
a.avatar:hover { text-decoration: none; border-color: var(--primary); }

/* Sidebar (desktop) */
.sidebar { display: none; }
.sidebar-brand {
  display: flex; align-items: center; gap: 9px;
  padding: 4px 8px 16px; font-weight: 650; font-size: 15px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 9px;
  color: var(--muted); font-size: 13px; font-weight: 500;
}
.sidebar-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-link.active { background: var(--soft); color: var(--primary); font-weight: 650; }
.sidebar-link .icon { width: 17px; height: 17px; }
.sidebar-badge {
  margin-left: auto; min-width: 19px; height: 19px; padding: 0 5px;
  border-radius: 999px; background: var(--red-soft); color: var(--red);
  font-size: 10px; font-weight: 650; display: grid; place-items: center;
}
.sidebar-group { margin-top: 14px; padding: 0 10px 5px; font-size: 10px; color: var(--muted); letter-spacing: .06em; }
.sidebar-footer {
  margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 9px;
}
.sidebar-footer .name { font-size: 12px; font-weight: 600; }
.sidebar-footer .role { font-size: 10px; color: var(--muted); }

/* Bottom nav */
.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 6px 4px calc(7px + var(--safe-bottom));
  background: var(--surface);
  border-top: 1px solid var(--line);
  box-shadow: 0 -8px 24px -20px rgba(0, 0, 0, .3);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 3px 0; border-radius: 9px;
  color: var(--muted); font-size: 9px; font-weight: 500;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav .icon { width: 21px; height: 21px; stroke-width: 1.8; }
.bottom-nav .nav-dot {
  position: absolute; transform: translate(13px, -5px);
  width: 6px; height: 6px; border-radius: 50%; background: var(--red);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 14px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
.card-title { margin: 0; font-size: 13px; font-weight: 650; }
.card-body { padding: 12px 14px 14px; }
.card + .card { margin-top: 10px; }
.card-flat { box-shadow: none; }
.hero {
  background: linear-gradient(135deg, var(--primary), color-mix(in srgb, var(--primary) 82%, #000));
  color: var(--primary-ink);
  border-radius: 18px; padding: 16px;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; width: 180px; height: 180px; border-radius: 50%;
  right: -70px; top: -90px; background: rgba(255, 255, 255, .12);
}
.hero-label { font-size: 11px; opacity: .82; }
.hero-value { font-size: 29px; font-weight: 700; letter-spacing: -.03em; margin: 2px 0 8px; font-variant-numeric: tabular-nums; position: relative; z-index: 1; }
.hero-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 11px; opacity: .9; position: relative; z-index: 1; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.stat-grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; padding: 10px 11px; min-width: 0;
}
.stat-label { font-size: 10px; color: var(--muted); display: block; }
.stat-value { font-size: 19px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; display: block; margin-top: 2px; }
.stat-note { font-size: 10px; color: var(--muted); display: block; margin-top: 1px; }
.stat-warn .stat-value { color: var(--amber); }
.stat-bad .stat-value { color: var(--red); }
.stat-good .stat-value { color: var(--green); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); color: var(--text);
  font-size: 14px; font-weight: 600; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }
.btn .icon { width: 17px; height: 17px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-soft { background: var(--soft); border-color: transparent; color: var(--primary); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--red); border-color: var(--red); color: #fff; }
.btn-danger-soft { background: var(--red-soft); border-color: transparent; color: var(--red); }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: 12px; border-radius: 9px; }
.btn-sm .icon { width: 14px; height: 14px; }
.btn-lg { min-height: 50px; font-size: 15px; border-radius: 14px; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* Forms */
.field { margin-bottom: 12px; }
.label { display: block; font-size: 11px; color: var(--muted); margin-bottom: 5px; font-weight: 550; }
.input, .select, .textarea {
  width: 100%; min-height: 44px; padding: 9px 12px;
  border: 1px solid var(--line); border-radius: 11px;
  background: var(--surface); color: var(--text);
  font-size: 16px; outline: none;
}
.textarea { min-height: 82px; resize: vertical; font-size: 14px; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent); }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.input[readonly] { background: var(--surface-2); }
.hint { font-size: 10px; color: var(--muted); margin-top: 4px; }
.error-text { font-size: 11px; color: var(--red); margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
.form-grid.two { grid-template-columns: 1fr 1fr; }
.form-grid.three { grid-template-columns: 1fr 1fr; }
.form-actions { display: flex; gap: 8px; margin-top: 14px; }
.form-actions .btn { flex: 1; }
.check-row { display: flex; align-items: flex-start; gap: 8px; padding: 8px 0; font-size: 12px; }
.check-row input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--primary); }
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; font-size: 12px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track {
  width: 42px; height: 24px; border-radius: 999px; background: var(--line);
  position: relative; transition: background .15s; flex: none;
}
.switch-track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .15s;
}
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { transform: translateX(18px); }

/* Chips and badges */
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  min-height: 30px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface);
  color: var(--muted); font-size: 11px; font-weight: 500; white-space: nowrap;
}
.chip:hover { text-decoration: none; border-color: var(--primary); color: var(--primary); }
.chip.active, .chip[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.chip .count { font-size: 10px; opacity: .8; }
.badge {
  display: inline-flex; align-items: center; gap: 3px;
  height: 21px; padding: 0 7px; border-radius: 6px;
  font-size: 10px; font-weight: 600; white-space: nowrap;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-gray { background: var(--surface-2); color: var(--muted); }
.badge-primary { background: var(--soft); color: var(--primary); }

/* Lists */
.list { display: flex; flex-direction: column; }
.list-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.list-row:last-child { border-bottom: 0; padding-bottom: 0; }
.list-row:first-child { padding-top: 0; }
.list-main { flex: 1; min-width: 0; }
.list-title { font-size: 12px; font-weight: 600; overflow-wrap: anywhere; }
.list-sub { font-size: 10px; color: var(--muted); margin-top: 2px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.list-end { text-align: right; flex: none; }
.list-end .amount { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.list-thumb {
  width: 38px; height: 38px; border-radius: 11px; background: var(--surface-2);
  display: grid; place-items: center; color: var(--muted); flex: none;
}
.list-thumb .icon { width: 18px; height: 18px; }
.list-link { color: inherit; }
.list-link:hover { text-decoration: none; }
.list-link:hover .list-title { color: var(--primary); }
.list-row.warn { background: linear-gradient(90deg, var(--amber-soft), transparent 70%); border-radius: 9px; padding-left: 7px; }
.list-row.danger { background: linear-gradient(90deg, var(--red-soft), transparent 70%); border-radius: 9px; padding-left: 7px; }

/* Tables */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border-radius: 11px; }
.table { width: 100%; border-collapse: collapse; font-size: 12px; }
.table th {
  text-align: left; font-weight: 550; color: var(--muted); font-size: 10px;
  padding: 8px 6px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.table td { padding: 9px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.table .name { font-weight: 550; }
.table .sub { display: block; font-size: 10px; color: var(--muted); font-weight: 400; margin-top: 1px; }

/* Tabs */
.tabs {
  display: flex; gap: 4px; overflow-x: auto; padding: 3px;
  background: var(--surface-2); border-radius: 11px; border: 1px solid var(--line);
}
.tab {
  flex: 1; min-width: max-content; text-align: center;
  padding: 7px 11px; border-radius: 8px;
  color: var(--muted); font-size: 11px; font-weight: 550;
}
.tab:hover { text-decoration: none; color: var(--text); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

/* Empty, flash, progress */
.empty { text-align: center; padding: 30px 14px; color: var(--muted); }
.empty .icon { width: 34px; height: 34px; opacity: .5; margin-bottom: 8px; }
.empty-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.flash {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 12px; border-radius: 11px; margin-bottom: 10px;
  font-size: 12px; border: 1px solid transparent;
}
.flash .icon { width: 16px; height: 16px; margin-top: 1px; }
.flash-success { background: var(--green-soft); color: var(--green); }
.flash-error { background: var(--red-soft); color: var(--red); }
.flash-warning { background: var(--amber-soft); color: var(--amber); }
.flash-info { background: var(--blue-soft); color: var(--blue); }
.progress { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* Quick actions */
.quick-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.quick-btn {
  display: flex; align-items: center; gap: 9px;
  padding: 11px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text); min-height: 64px;
}
.quick-btn:hover { text-decoration: none; border-color: var(--primary); }
.quick-btn.primary { background: var(--soft); border-color: transparent; }
.quick-icon {
  width: 36px; height: 36px; border-radius: 11px;
  background: var(--soft); color: var(--primary);
  display: grid; place-items: center; flex: none;
}
.quick-btn.primary .quick-icon { background: var(--primary); color: var(--primary-ink); }
.quick-icon .icon { width: 19px; height: 19px; }
.quick-title { font-size: 12px; font-weight: 650; display: block; }
.quick-sub { font-size: 9px; color: var(--muted); display: block; margin-top: 1px; }
.quick-bar {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text); font-size: 12px; font-weight: 550;
}
.quick-bar:hover { text-decoration: none; border-color: var(--primary); }
.quick-bar .icon { width: 17px; height: 17px; color: var(--primary); }
.quick-bar .arrow { margin-left: auto; color: var(--muted); }

/* Search */
.search-bar {
  display: flex; align-items: center; gap: 7px;
  height: 42px; padding: 0 12px; border-radius: 12px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px;
}
.search-bar .icon { width: 16px; height: 16px; }
.search-bar input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent;
  font-size: 16px; color: var(--text);
}
.search-bar .btn { margin-right: -7px; }
.search-row { display: flex; gap: 8px; align-items: center; }
.search-row .search-bar { flex: 1; }

/* Document cards */
.doc-card {
  display: block; padding: 12px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line);
  color: var(--text);
}
.doc-card:hover { text-decoration: none; border-color: var(--primary); }
.doc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.doc-no { font-size: 12px; font-weight: 650; font-variant-numeric: tabular-nums; }
.doc-sub { font-size: 10px; color: var(--muted); margin-top: 2px; }
.doc-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 7px; font-size: 10px; color: var(--muted); }
.doc-amount { font-size: 14px; font-weight: 700; color: var(--text); font-variant-numeric: tabular-nums; }
.doc-grid { display: flex; flex-direction: column; gap: 8px; }

/* Line editor */
.line-card { background: var(--surface); border: 1px solid var(--line); border-radius: 13px; padding: 11px; margin-bottom: 8px; }
.line-card.invalid { border-color: var(--red); background: var(--red-soft); }
.line-head { display: flex; align-items: flex-start; gap: 7px; }
.line-name { font-size: 12px; font-weight: 650; flex: 1; min-width: 0; }
.line-fields { display: grid; grid-template-columns: 1.15fr 1fr; gap: 7px; margin-top: 8px; }
.line-extra { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 7px; }
.line-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 7px; font-size: 10px; color: var(--muted); }
.stepper {
  display: flex; align-items: center; gap: 4px;
  min-height: 42px; padding: 3px 5px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
}
.stepper button {
  width: 30px; height: 34px; border: 0; border-radius: 7px;
  background: var(--surface); color: var(--text); display: grid; place-items: center;
}
.stepper input {
  flex: 1; min-width: 0; width: 44px; text-align: center; border: 0; outline: 0;
  background: transparent; font-size: 16px; font-variant-numeric: tabular-nums;
}
.stepper .unit { font-size: 10px; color: var(--muted); padding-right: 4px; white-space: nowrap; }
.line-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.line-actions .btn { min-height: 38px; padding: 0 6px; font-size: 11px; }
.add-product {
  position: relative;
}
.suggestions {
  position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 25;
  background: var(--surface); border: 1px solid var(--line); border-radius: 11px;
  box-shadow: var(--shadow); max-height: 300px; overflow-y: auto;
}
.suggestion {
  display: block; padding: 9px 11px; border-bottom: 1px solid var(--line);
  color: var(--text); font-size: 12px;
}
.suggestion:last-child { border-bottom: 0; }
.suggestion:hover { background: var(--soft); text-decoration: none; }
.suggestion .sub { display: block; font-size: 10px; color: var(--muted); margin-top: 1px; }

/* AI review */
.ai-note {
  display: flex; gap: 8px; padding: 10px 11px; border-radius: 11px;
  background: var(--blue-soft); color: var(--blue); font-size: 11px; line-height: 1.55;
}
.ai-note .icon { width: 16px; height: 16px; margin-top: 1px; }
.ai-block {
  display: flex; gap: 8px; padding: 10px 11px; border-radius: 11px;
  background: var(--red-soft); color: var(--red); font-size: 11px; font-weight: 550;
}
.ai-block .icon { width: 16px; height: 16px; margin-top: 1px; }
.ai-line { border: 1px solid var(--line); background: var(--surface); border-radius: 13px; padding: 10px; margin-bottom: 7px; }
.ai-line.blocked { border-color: var(--red); background: var(--red-soft); }
.ai-line-head { display: flex; align-items: flex-start; gap: 7px; }
.ai-line-head .name { flex: 1; min-width: 0; font-size: 12px; font-weight: 650; }
.ai-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 6px; font-size: 9px; color: var(--muted); }
.ai-meta b { display: block; font-size: 11px; color: var(--text); font-weight: 550; margin-top: 1px; }
.ai-source { font-size: 9px; color: var(--muted); margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.ai-source .icon { width: 12px; height: 12px; }
.ai-photos { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 2px; }
.ai-photo { width: 86px; height: 66px; border-radius: 10px; object-fit: cover; border: 1px solid var(--line); flex: none; }
.ai-photo-placeholder {
  width: 86px; height: 66px; border-radius: 10px; border: 1px dashed var(--line);
  display: grid; place-items: center; color: var(--muted); font-size: 9px; flex: none;
}

/* Scanner */
.scan-box { position: relative; background: #000; border-radius: 14px; overflow: hidden; aspect-ratio: 4 / 3; }
.scan-box video { width: 100%; height: 100%; object-fit: cover; }
.scan-frame { position: absolute; inset: 18% 8%; border: 2px solid rgba(255,255,255,.85); border-radius: 12px; box-shadow: 0 0 0 999px rgba(0,0,0,.28); }
.scan-hint { position: absolute; left: 0; right: 0; bottom: 10px; text-align: center; color: #fff; font-size: 11px; }

/* Misc */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 14px; }
.pagination .btn { min-height: 34px; padding: 0 10px; font-size: 11px; }
.pagination .current { font-size: 11px; color: var(--muted); }
.tag-list { display: flex; gap: 5px; flex-wrap: wrap; }
.mono-id { font-size: 10px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.kv { display: grid; grid-template-columns: 82px 1fr; gap: 7px 10px; font-size: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.summary-bar {
  display: flex; align-items: baseline; justify-content: space-between; gap: 10px;
  padding: 11px 13px; border-radius: 13px; background: var(--surface); border: 1px solid var(--line);
}
.summary-bar .label { margin: 0; }
.summary-bar .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sticky-actions {
  position: sticky; bottom: calc(66px + var(--safe-bottom)); z-index: 20;
  padding: 10px 0 0;
  background: linear-gradient(transparent, var(--bg) 30%);
}
.danger-zone { border-color: var(--red); }
.danger-zone .card-title { color: var(--red); }
.empty-state-icon { width: 42px; height: 42px; border-radius: 13px; background: var(--surface-2); display: grid; place-items: center; margin: 0 auto 9px; color: var(--muted); }
.alert-strip {
  display: flex; align-items: center; gap: 9px; padding: 11px 12px;
  border-radius: 12px; background: var(--red-soft); color: var(--red); font-size: 11px;
}
.alert-strip .icon { width: 17px; height: 17px; }
.alert-strip a { color: inherit; font-weight: 650; }

/* Login */
.public-body { min-height: 100vh; background: var(--bg); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 22px; }
.login-card { width: 100%; max-width: 380px; }
.login-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 22px; }
.login-brand .brand-mark { width: 46px; height: 46px; border-radius: 14px; }
.login-brand .brand-mark .icon { width: 26px; height: 26px; }
.login-brand h1 { margin: 0; font-size: 23px; font-weight: 700; letter-spacing: -.03em; }
.login-brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }
.login-card .card { padding: 18px; }
.login-card .btn { margin-top: 4px; }
.login-foot { text-align: center; font-size: 10px; color: var(--muted); margin-top: 14px; }
.login-feats { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 16px; justify-content: center; }
.login-feats span { font-size: 9px; color: var(--muted); background: var(--surface-2); border-radius: 999px; padding: 4px 8px; }

/* Desktop */
@media (min-width: 980px) {
  .app { display: grid; grid-template-columns: 220px minmax(0, 1fr); }
  .sidebar {
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    padding: 16px 12px;
    background: var(--surface-2); border-right: 1px solid var(--line);
  }
  .main { min-height: 100vh; }
  .topbar { padding: 10px 26px; background: var(--bg); backdrop-filter: none; }
  .brand-mobile { display: none; }
  .topbar-left .page-context { font-size: 12px; color: var(--muted); }
  .page { padding: 18px 26px 40px; }
  .bottom-nav { display: none; }
  .hide-mobile { display: initial; }
  .show-mobile { display: none; }
  .stat-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid.two { grid-template-columns: 1fr 1fr; }
  .form-grid.three { grid-template-columns: repeat(3, 1fr); }
  .quick-grid { grid-template-columns: repeat(4, 1fr); }
  .summary-bar .value { font-size: 24px; }
}
@media (min-width: 760px) and (max-width: 979px) {
  .stat-grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
@media (max-width: 380px) {
  .page { padding-left: 10px; padding-right: 10px; }
  .topbar { padding-left: 10px; padding-right: 10px; }
  .hero-value { font-size: 25px; }
}

@media print {
  .topbar, .bottom-nav, .sidebar, .no-print, .flash, .sticky-actions { display: none !important; }
  .page { padding: 0; max-width: none; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; border-color: #ccc; }
  @page { size: A4; margin: 12mm; }
}

/* Password field with toggle */
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 46px; }
.input-wrap .icon-btn {
  position: absolute; right: 5px; top: 5px; width: 34px; height: 34px;
  border: 0; background: transparent; color: var(--muted);
}

/* Dashboard chart */
.chart-bars { display: flex; align-items: flex-end; gap: 9px; height: 96px; padding-top: 6px; }
.chart-group { flex: 1; display: flex; align-items: flex-end; justify-content: center; gap: 3px; height: 100%; }
.chart-bar { width: 9px; border-radius: 3px 3px 0 0; background: var(--primary); min-height: 2px; }
.chart-bar.out { background: var(--line); }
.chart-labels { display: flex; gap: 9px; margin-top: 4px; }
.chart-labels span { flex: 1; text-align: center; font-size: 9px; color: var(--muted); }
.chart-legend { display: inline-flex; align-items: center; gap: 10px; font-size: 10px; color: var(--muted); }
.chart-legend i { width: 7px; height: 7px; border-radius: 2px; background: var(--primary); display: inline-block; margin-right: 3px; }
.chart-legend .out { background: var(--line); }
.alert-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.alert-card {
  display: block; padding: 10px 11px; border-radius: 13px;
  background: var(--surface); border: 1px solid var(--line); color: var(--text);
}
.alert-card:hover { text-decoration: none; border-color: var(--primary); }
.alert-card .count { font-size: 19px; font-weight: 700; font-variant-numeric: tabular-nums; display: block; }
.alert-card .name { font-size: 10px; color: var(--muted); display: block; margin-top: 1px; }
.alert-card.warn .count { color: var(--amber); }
.alert-card.bad .count { color: var(--red); }
@media (min-width: 760px) { .alert-grid { grid-template-columns: repeat(4, 1fr); } }

/* Product unit rows */
.unit-row {
  display: grid;
  grid-template-columns: 1.3fr .65fr 1.2fr 32px;
  gap: 6px;
  align-items: end;
  padding: 8px 0;
  border-bottom: 1px dashed var(--line);
}
.unit-row:last-child { border-bottom: 0; }
.unit-row .input { min-height: 38px; padding: 7px 9px; font-size: 14px; }
.unit-row .icon-btn { width: 32px; height: 38px; border-radius: 9px; }
.unit-add {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 36px; padding: 0 10px; border-radius: 9px;
  border: 1px dashed var(--line); background: transparent; color: var(--primary);
  font-size: 12px; font-weight: 550;
}

/* Dialogs and scan */
dialog {
  border: 0; padding: 0; background: transparent; width: min(440px, 94vw); max-width: 94vw;
}
dialog::backdrop { background: rgba(0, 0, 0, .55); }
dialog .card { box-shadow: 0 30px 80px -30px rgba(0,0,0,.6); }
.editor-error {
  padding: 9px 11px; border-radius: 10px; background: var(--red-soft);
  color: var(--red); font-size: 11px; font-weight: 550; margin-bottom: 8px;
}

/* Read-only value inside order line */
.ph-input {
  display: flex; align-items: center; min-height: 38px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface-2); font-size: 11px; color: var(--muted);
}

/* AI previews and review */
.preview-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preview-grid img, .preview-grid .ai-photo { width: 92px; height: 92px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.ai-line .field { margin-bottom: 8px; }
.ai-line .line-fields { grid-template-columns: 1fr 1fr; }
.ai-line .line-extra { grid-template-columns: 1fr 1fr 1fr; }
.ai-js-reason { font-size: 10px; color: var(--red); margin-top: 4px; min-height: 14px; }
.ai-line.blocked .ai-js-reason { font-weight: 600; }
.ai-candidates { display: flex; gap: 5px; flex-wrap: wrap; margin-top: 5px; }
.ai-candidates .chip { font-size: 10px; }

/* AI review notes and actions */
.ph-note {
  display: flex; gap: 8px; padding: 10px 11px; border-radius: 11px;
  background: var(--green-soft); color: var(--green); font-size: 11px; line-height: 1.55;
}
.ph-note .icon { width: 16px; height: 16px; margin-top: 1px; }
.ai-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.ai-actions .btn { width: auto; }
@media (max-width: 520px) {
  .ai-line .line-extra { grid-template-columns: 1fr 1fr; }
}

/* Stocktake rows */
.count-row { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.count-row:last-child { border-bottom: 0; }
.count-row b { font-size: 12px; font-weight: 600; }
.diff { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 12px; }
.diff.bad { color: var(--red); }
.diff.ok { color: var(--green); }
.diff.muted { color: var(--muted); font-weight: 500; }
.diff.warn { color: var(--amber); }
.line-batch { display: flex; flex-wrap: wrap; gap: 4px 10px; font-size: 10px; color: var(--muted); }
.line-batch b { color: var(--text); font-weight: 500; }

/* Clear disabled primary actions */
.btn-primary:disabled, .btn-primary.disabled {
  background: var(--surface-2); border-color: transparent; color: var(--muted); opacity: 1;
}
.btn:disabled { cursor: not-allowed; }

.search-row > .btn, .search-row > .icon-btn { flex: none; white-space: nowrap; }

/* Space so sticky form actions never cover the last editable row */
.sticky-spacer { height: 48px; }
@media (min-width: 980px) { .sticky-spacer { height: 24px; } }

/* AI capture mode selector */
.mode-grid { display: grid; gap: 7px; }
.mode-card {
  display: flex; gap: 9px; align-items: flex-start;
  padding: 10px 11px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--surface); cursor: pointer;
}
.mode-card input { margin-top: 3px; accent-color: var(--primary); flex: none; }
.mode-card:has(input:checked) { border-color: var(--primary); background: var(--soft); }
.mode-title { display: block; font-size: 12px; font-weight: 650; }
.mode-sub { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; line-height: 1.5; }
