:root {
  --bg: #f5f7f1;
  --surface: #ffffff;
  --surface-2: #ebf0e6;
  --text: #232a22;
  --muted: #667262;
  --line: #dfe6d9;
  --primary: #5c7a60;
  --primary-ink: #ffffff;
  --primary-soft: #e4ece1;
  --green: #1f7a4d;
  --green-soft: #def3e7;
  --red: #b3261e;
  --red-soft: #fbe3e1;
  --amber: #8a5a00;
  --amber-soft: #fdf0cf;
  --blue: #1f5fa8;
  --blue-soft: #e0ecfa;
  --gray-soft: #e9ece5;
  --shadow: 0 1px 2px rgba(35, 50, 35, 0.08), 0 2px 8px rgba(35, 50, 35, 0.05);
  --radius: 14px;
  --nav-h: 62px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141914;
    --surface: #1d241d;
    --surface-2: #283128;
    --text: #eef3ea;
    --muted: #a5b2a1;
    --line: #2f3a2f;
    --primary: #a4c0a2;
    --primary-ink: #14200f;
    --primary-soft: #263226;
    --green: #76d3a0;
    --green-soft: #16372a;
    --red: #ff8f87;
    --red-soft: #451d1a;
    --amber: #f2c25b;
    --amber-soft: #3f3114;
    --blue: #8ab9f0;
    --blue-soft: #16304d;
    --gray-soft: #2c342b;
    --shadow: none;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh;
  overscroll-behavior-y: contain;
}
body.lock { overflow: hidden; }
h1, h2, h3, p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); }
[hidden] { display: none !important; }
b { font-weight: 650; }

/* ---------- layout ---------- */
header.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 54px;
  padding: 8px 14px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  background: var(--primary);
  color: var(--primary-ink);
}
header.top h1 { flex: 1; font-size: 18px; font-weight: 650; letter-spacing: 0.1px; }
.net { font-size: 11px; padding: 3px 8px; border-radius: 99px; background: rgba(255, 255, 255, 0.2); }
.net.off { background: #ffd9a8; color: #5a3500; font-weight: 650; }
.main { padding: 14px 14px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 720px; margin: 0 auto; }
.loading-line { height: 3px; margin: -14px -14px 12px; background: linear-gradient(90deg, transparent, var(--primary), transparent); background-size: 200% 100%; animation: slide 1.1s linear infinite; }
@keyframes slide { to { background-position: -200% 0; } }

nav.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 25;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  height: calc(var(--nav-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none; color: var(--muted); font-size: 11px; padding: 0; }
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--primary); font-weight: 650; }
.tab.active svg { stroke-width: 2.2; }

.fab {
  position: fixed;
  right: 16px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  z-index: 24;
  width: 56px; height: 56px;
  border-radius: 18px;
  border: 0;
  background: var(--primary);
  color: var(--primary-ink);
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(60, 90, 64, 0.40);
}

/* ---------- login / setup ---------- */
.center-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 26px 22px; box-shadow: var(--shadow); display: grid; gap: 12px; text-align: center; }
.login-card .fld { text-align: left; }
.login-card h1 { font-size: 22px; }
.hero { color: var(--primary); display: grid; place-items: center; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--primary); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- text helpers ---------- */
.muted { color: var(--muted); }
.tiny { font-size: 12px; margin: 2px 2px 8px; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.sub b { color: var(--text); }
.hint { font-size: 12px; opacity: 0.85; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.pre { white-space: pre-wrap; text-align: right; font-weight: 500; }
.sec { font-size: 14px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.5px; margin: 20px 2px 8px; }
.sec-row { display: flex; align-items: center; justify-content: space-between; margin: 16px 0 8px; }
.sec-row h3 { font-size: 15px; }
.empty { text-align: center; padding: 38px 18px; color: var(--muted); }
.empty p { font-size: 15px; }
.empty small { display: block; margin-top: 6px; }

/* ---------- cards ---------- */
.card { display: block; width: 100%; text-align: left; border: 0; background: var(--surface); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; box-shadow: var(--shadow); color: var(--text); }
button.card:active { background: var(--surface-2); }
.card .row, .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.card.list { padding: 4px 14px; }
.li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li.total { border-top: 2px solid var(--line); }
.card.need.short { border-left: 4px solid var(--red); }
.card.note { box-shadow: none; background: var(--surface-2); }
.fld input[readonly] { background: var(--surface-2); font-weight: 650; }
.calc small { color: var(--muted); }
.card.profit { padding: 14px; }
.card.profit .row b { font-size: 19px; }
.card.profit small { display: block; margin-top: 2px; font-size: 12px; }
button.plain { display: block; width: 100%; background: none; border: 0; padding: 0; text-align: left; color: inherit; }
.big { font-size: 22px; font-weight: 700; }
.big small { font-size: 13px; font-weight: 500; color: var(--muted); }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.stat { background: var(--surface); border-radius: var(--radius); padding: 11px 13px; box-shadow: var(--shadow); }
.stat small { display: block; color: var(--muted); font-size: 12px; }
.stat b { display: block; font-size: 24px; line-height: 1.2; margin-top: 2px; }
.stat b.sm { font-size: 17px; margin-top: 5px; }
.stat.warn { background: var(--red-soft); }
.stat.warn b { color: var(--red); }

.badge { display: inline-block; font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--gray-soft); color: var(--muted); white-space: nowrap; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.gray { background: var(--gray-soft); color: var(--muted); }

.alert { padding: 10px 12px; border-radius: 10px; margin-bottom: 12px; font-size: 14px; text-align: left; }
.alert.err { background: var(--red-soft); color: var(--red); }
.alert.warn { background: var(--amber-soft); color: var(--amber); }

/* ---------- chips, filters, search ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--surface); border-radius: 99px; padding: 6px 12px; font-size: 13.5px; color: var(--text); }
.chip i { font-style: normal; color: var(--muted); margin-left: 3px; font-size: 12px; }
.chip.on { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 650; }
.chip.on i { color: inherit; opacity: 0.85; }
.row-split { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.row-split .chips { flex: 1; min-width: 0; }
.search, .filter-row input, .fld input, .fld select, .fld textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 44px;
  outline: none;
}
.search { margin: 2px 0 12px; }
.search:focus, .fld input:focus, .fld select:focus, .fld textarea:focus, .filter-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.filter-row { margin-bottom: 8px; }
.filter-row label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 2px 4px; }
.inline { display: flex; gap: 8px; align-items: center; }
.inline input { flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  text-decoration: none;
  text-align: center;
}
.btn:active { filter: brightness(0.95); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--red); border-color: var(--red-soft); background: var(--red-soft); }
.btn.link { border-color: transparent; background: none; color: var(--primary); min-height: 38px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 13.5px; border-radius: 10px; }
.btn.block { display: flex; width: 100%; margin-top: 8px; }
.btn[disabled] { opacity: 0.6; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-row .btn { flex: 1 1 auto; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 12px; background: none; display: grid; place-items: center; color: var(--muted); padding: 0; }
.icon-btn.light { color: var(--primary-ink); }
.icon-btn:active { background: var(--surface-2); }

/* ---------- menu ---------- */
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; text-align: left; border: 0; background: var(--surface); padding: 13px 14px; margin-bottom: 10px; border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); }
.menu-item .mi-ic { width: 40px; height: 40px; border-radius: 12px; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; flex: none; }
.menu-item .mi-tx { flex: 1; display: grid; }
.menu-item small { color: var(--muted); }
.menu-item > svg { color: var(--muted); }

/* ---------- sheet ---------- */
.backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20, 8, 12, 0.5); animation: fade 0.15s ease; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  margin: 0 auto; max-width: 720px;
  max-height: 92vh;
  display: flex; flex-direction: column;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.25);
  animation: up 0.2s ease;
}
@keyframes up { from { transform: translateY(40px); opacity: 0.4; } }
@keyframes fade { from { opacity: 0; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 8px 4px 18px; }
.sheet-head h2 { font-size: 17px; }
.sheet-body { padding: 8px 18px 18px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sheet-foot { padding: 10px 18px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }
.sheet-foot .btn { margin-top: 0; }

.fld { display: block; margin: 10px 0; }
.fld > span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 4px; font-weight: 600; }
.fld small { display: block; font-size: 12px; color: var(--muted); margin: 3px 2px 0; }
.fld textarea { resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid2 .fld { min-width: 0; }

.line-row { display: grid; gap: 6px; align-items: center; margin-bottom: 10px; padding: 8px; background: var(--surface); border-radius: 12px; border: 1px solid var(--line); }
.line-row select, .line-row input { width: 100%; min-height: 42px; border: 1px solid var(--line); background: var(--bg); border-radius: 9px; padding: 8px 10px; min-width: 0; }
.line-row.ord { grid-template-columns: 1fr 1.4fr 40px; }
.line-row.ord select { grid-column: 1 / -1; }
.line-row.comp { grid-template-columns: 1fr 88px 40px; }
.calc { margin: 6px 2px 4px; padding: 10px 12px; background: var(--primary-soft); border-radius: 10px; font-size: 14px; }
.kv { display: flex; justify-content: space-between; gap: 14px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 14px; }
.kv > span { color: var(--muted); }
.kv.col { flex-direction: column; gap: 2px; }
.kv.col .pre { text-align: left; }
.sheet-body > .card.list { margin-top: 12px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + var(--safe-b) + 84px);
  transform: translate(-50%, 20px);
  z-index: 60;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 12px;
  background: #2a1f22; color: #fff;
  font-size: 14px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #b3261e; }

/* ---------- foto & logo ---------- */
.thumb { width: 68px; height: 68px; border-radius: 12px; object-fit: cover; background: var(--surface-2); flex: none; display: block; }
.thumb.sm { width: 40px; height: 40px; border-radius: 10px; }
.thumb.ph { display: grid; place-items: center; color: var(--muted); }
.thumb.ph svg { width: 26px; height: 26px; }
.card.hamp { display: flex; gap: 12px; align-items: flex-start; }
.card.hamp .body { flex: 1; min-width: 0; }
.card.hamp .body .row { align-items: flex-start; }
.li .lhs { display: flex; align-items: center; gap: 10px; min-width: 0; }
.photo-preview { width: 100%; aspect-ratio: 4 / 3; border-radius: 14px; background: var(--surface-2); border: 1px dashed var(--line); display: grid; place-items: center; color: var(--muted); overflow: hidden; font-size: 14px; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; display: block; }
.logo-login { display: block; width: 220px; max-width: 80%; height: auto; margin: 0 auto 4px; background: #fff; border-radius: 16px; padding: 10px 12px; }
.hlogo { height: 40px; width: auto; border-radius: 9px; background: #fff; padding: 3px 6px; flex: none; }
