:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #15201b;
  --muted: #5f6e67;
  --line: #dde4e0;
  --brand: #0e6b50;
  --brand-ink: #ffffff;
  --brand-soft: #dff1e9;
  --red: #c62828;
  --red-soft: #fde7e7;
  --amber: #b26a00;
  --amber-soft: #fff1d6;
  --blue: #1e5fbf;
  --blue-soft: #e3edfc;
  --green: #1b7f3b;
  --green-soft: #e1f4e6;
  --gray: #7b8781;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 4px 14px rgba(0, 0, 0, 0.06);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e7eeea; --muted: #9aaaa2; --line: #2b3632;
    --brand: #38b48a; --brand-ink: #062419; --brand-soft: #173a2e; --red: #ff6b6b; --red-soft: #3a1c1c;
    --amber: #f0b44c; --amber-soft: #3a2c12; --blue: #7aa7ff; --blue-soft: #1a2944; --green: #5bd08a; --green-soft: #173222;
    --gray: #8c9993; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1412; --surface: #171e1b; --surface-2: #1f2824; --text: #e7eeea; --muted: #9aaaa2; --line: #2b3632;
  --brand: #38b48a; --brand-ink: #062419; --brand-soft: #173a2e; --red: #ff6b6b; --red-soft: #3a1c1c;
  --amber: #f0b44c; --amber-soft: #3a2c12; --blue: #7aa7ff; --blue-soft: #1a2944; --green: #5bd08a; --green-soft: #173222;
  --gray: #8c9993; --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--brand); }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* ---------- layout */
#app { min-height: 100%; }
.topbar {
  position: sticky; top: 0; z-index: 500; display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .title { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-weight: 800; font-size: 10.5px; letter-spacing: -.02em; flex: none; }
.page { padding: 16px; max-width: 1200px; margin: 0 auto; }
.sales .page { padding-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom)); max-width: 760px; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 600; height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom); display: flex; background: var(--surface); border-top: 1px solid var(--line);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  text-decoration: none; color: var(--muted); font-size: 12px; position: relative;
}
.bottomnav a svg { width: 24px; height: 24px; }
.bottomnav a span { font-size: 11px; }
.bottomnav a.on { color: var(--brand); font-weight: 600; }
.badge { position: absolute; top: 8px; left: calc(50% + 6px); background: var(--red); color: #fff; border-radius: 10px;
  font-size: 11px; min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; }

.tabs { display: flex; gap: 4px; overflow-x: auto; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 51px; z-index: 499; scrollbar-width: none; }
.tabs a { padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); white-space: nowrap; font-weight: 500; }
.tabs a.on { background: var(--brand-soft); color: var(--brand); }

/* ---------- components */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow); }
.card + .card, .stack > * + * { margin-top: 12px; }
.grid > .card + .card, .split > .card + .card, .grid > * + *, .split > * + * { margin-top: 0; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.grid { display: grid; gap: 12px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 860px) { .g4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .g3.keep { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.split { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 16px; align-items: start; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 0 16px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600;
  text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; border-radius: 10px; font-size: 13px; }
.btn.block { width: 100%; }
.btn.lg { min-height: 54px; font-size: 16px; }
.btn svg { width: 18px; height: 18px; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.red { background: var(--red-soft); color: var(--red); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.blue { background: var(--blue-soft); color: var(--blue); }
.chip.brand { background: var(--brand-soft); color: var(--brand); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

.kpi { padding: 12px 14px; }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi .value { font-size: 24px; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.bar { height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 6px; }
.bar.red > i { background: var(--red); } .bar.amber > i { background: var(--amber); }

label.f { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 10px 0 4px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: 2px solid var(--brand); outline-offset: 0; border-color: transparent; }
.seg { display: flex; background: var(--surface-2); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; min-height: 40px; border-radius: 10px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.item { display: flex; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); align-items: center; cursor: pointer; }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.seqno { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; font-size: 13px;
  background: var(--surface-2); color: var(--muted); }
.seqno.must { background: var(--red); color: #fff; }
.seqno.done { background: var(--green); color: #fff; }
.seqno.prospect { background: var(--blue); color: #fff; }
.item .name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

table.t { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.t th, .t td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.t th { font-size: 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: 0.02em; background: var(--surface-2); position: sticky; top: 0; }
.t td.r, .t th.r { text-align: right; }
.t tr.click { cursor: pointer; } .t tr.click:hover td { background: var(--surface-2); }
.tablewrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }

.map { height: 360px; border-radius: var(--radius); border: 1px solid var(--line); overflow: hidden; z-index: 1; }
.map.tall { height: calc(100vh - 190px); min-height: 420px; }
.sales .map.tall { height: calc(100vh - var(--nav-h) - 150px); }
.leaflet-container { font: inherit; background: var(--surface-2); }
.pin { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); display: grid; place-items: center;
  color: #fff; font-size: 11px; font-weight: 700; }

.banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius); }
.banner.red { background: var(--red-soft); color: var(--red); }
.banner.amber { background: var(--amber-soft); color: var(--amber); }
.banner.blue { background: var(--blue-soft); color: var(--blue); }
.banner.green { background: var(--green-soft); color: var(--green); }
.banner b { color: inherit; }

/* sheet / modal */
.sheet-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 900; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 760px; max-height: 94vh; overflow: auto; border-radius: 18px 18px 0 0;
  padding: 0 0 calc(16px + env(safe-area-inset-bottom)); animation: up .18s ease-out; }
@media (min-width: 900px) { .sheet-bg { align-items: center; } .sheet { border-radius: 18px; max-height: 88vh; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet-head { position: sticky; top: 0; z-index: 2; background: var(--surface); border-bottom: 1px solid var(--line); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px; }
.sheet-body { padding: 16px; }
.x { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--surface-2); cursor: pointer; font-size: 20px; line-height: 1; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + 20px); z-index: 1000; background: #111; color: #fff;
  padding: 10px 16px; border-radius: 12px; max-width: 90vw; box-shadow: var(--shadow); font-weight: 500; }
.toast.err { background: var(--red); }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 24px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
.section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin: 18px 0 8px; }
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; }
