:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --text: #182033;
  --muted: #667085;
  --border: #e3e6ec;
  --brand: #1f2a44;
  --brand-text: #ffffff;
  --accent: #e8930c;
  --accent-soft: #fdf1dc;
  --ok: #12805c;
  --ok-soft: #dcf3ea;
  --warn: #b25e09;
  --warn-soft: #fdeccf;
  --bad: #c0362c;
  --bad-soft: #fbe2df;
  --info: #2457c5;
  --info-soft: #e1eafc;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 12px;
  --tabbar-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #182030;
    --surface-2: #1e2738;
    --text: #e8ecf3;
    --muted: #98a2b3;
    --border: #2a3448;
    --brand: #141b2b;
    --accent: #f2a43a;
    --accent-soft: #3a2d17;
    --ok: #4cc79a;
    --ok-soft: #173329;
    --warn: #f0b155;
    --warn-soft: #3a2c14;
    --bad: #f07a70;
    --bad-soft: #3c1f1d;
    --info: #7ea6f5;
    --info-soft: #1c2a47;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--info); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.splash { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon.sm { width: 16px; height: 16px; }

/* ---------- layout ---------- */
.shell { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  min-height: 56px; padding: 8px 16px; padding-top: calc(8px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-text);
}
.topbar h1 { font-size: 18px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .iconbtn { color: var(--brand-text); }
.topbar .btn.primary { background: var(--accent); color: #1b1203; }
main.view {
  max-width: 960px; margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
}
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--surface); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: var(--tabbar-h); color: var(--muted); font-size: 11px; font-weight: 500;
}
.tabbar a.active { color: var(--accent); }
.tabbar .brand-side { display: none; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 232px 1fr; }
  .tabbar {
    position: sticky; top: 0; height: 100vh; flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--border); padding: 0 12px 12px;
  }
  .tabbar .brand-side {
    display: flex; align-items: center; gap: 10px; height: 56px; padding: 0 8px; margin: 0 -12px 12px;
    background: var(--brand); color: #fff; font-weight: 700; font-size: 16px; padding-left: 20px;
  }
  .tabbar .brand-side img { width: 28px; height: 28px; border-radius: 6px; }
  .tabbar a {
    flex: none; flex-direction: row; justify-content: flex-start; gap: 12px;
    height: 42px; padding: 0 12px; border-radius: 8px; font-size: 14px;
  }
  .tabbar a.active { background: var(--accent-soft); }
  main.view { padding: 24px 32px 48px; }
  .main-col { min-width: 0; }
}

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: transparent; color: #1b1203; }
.btn.danger { color: var(--bad); }
.btn.block { width: 100%; min-height: 46px; }
.btn.sm { min-height: 32px; padding: 0 10px; font-size: 13px; border-radius: 8px; }
.iconbtn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.iconbtn:hover { background: rgba(127, 127, 127, .12); }
input, select, textarea {
  width: 100%; font: inherit; font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; min-height: 44px;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--text); font-weight: 500; }
label.check input { width: 22px; height: 22px; min-height: 0; margin: 0; accent-color: var(--accent); }
.form-grid { display: grid; gap: 12px; }
@media (min-width: 640px) { .form-grid.two { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.search { position: relative; flex: 1; min-width: 180px; }
.search input { padding-left: 38px; }
.search .icon { position: absolute; left: 11px; top: 12px; color: var(--muted); }

.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }
@media (prefers-color-scheme: dark) { .chip.active { background: var(--accent); color: #1b1203; border-color: var(--accent); } }

.segmented { display: flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented button {
  flex: 1; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px;
  font: inherit; font-weight: 600; font-size: 14px; color: var(--muted); cursor: pointer;
}
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- cards ---------- */
.card {
  display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); color: inherit;
}
a.card:active { transform: scale(.995); }
.list { display: grid; gap: 10px; }
@media (min-width: 900px) { .list.cols { grid-template-columns: 1fr 1fr; } }
.section-title { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 20px 0 10px; }
.section-title:first-child { margin-top: 0; }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

.pill {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 650; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent-soft); color: var(--warn); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
@media (min-width: 700px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat .l { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat.bad .v { color: var(--bad); }

.obj-card .title { font-weight: 650; font-size: 16px; }
.obj-card .addr { display: flex; gap: 6px; color: var(--muted); font-size: 13px; margin-top: 4px; }
.obj-card .meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.progress { margin-top: 10px; display: grid; gap: 6px; }
.progress .p-row { display: grid; grid-template-columns: 96px 1fr 44px; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--border); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.bar.done > i { background: var(--ok); }

/* ---------- object page ---------- */
.obj-head .addr { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin-top: 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.tabs-sticky { position: sticky; top: calc(56px + env(safe-area-inset-top)); z-index: 10; background: var(--bg); padding: 10px 0; margin: 6px 0 4px; }
@media (min-width: 900px) { .tabs-sticky { top: 56px; } }

.stage { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.stage:last-child { border-bottom: 0; }
.stage-dot {
  flex: none; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--border);
  display: grid; place-items: center; background: var(--surface); color: transparent; cursor: default; padding: 0;
}
.stage-dot.can { cursor: pointer; }
.stage-dot.progress { border-color: var(--accent); background: var(--accent-soft); color: var(--warn); }
.stage-dot.done { border-color: var(--ok); background: var(--ok); color: #fff; }
.stage-name { font-weight: 550; }
.stage.done .stage-name { color: var(--muted); }
.card.flush { padding: 0; overflow: hidden; }
.card-head { display: flex; align-items: center; justify-content: space-between; padding: 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); }

.report .r-head { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; }
.report .r-text { margin-top: 8px; white-space: pre-wrap; overflow-wrap: anywhere; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; margin-top: 10px; }
.media-grid .thumb { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); border: 0; padding: 0; cursor: zoom-in; }
.media-grid .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-grid .thumb .x {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%;
  background: rgba(0,0,0,.6); color: #fff; border: 0; display: grid; place-items: center; cursor: pointer;
}
.media-grid .thumb .tag { position: absolute; left: 4px; bottom: 4px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 6px; }
.videos { display: grid; gap: 8px; margin-top: 10px; }
.videos video { width: 100%; max-height: 420px; border-radius: 10px; background: #000; }

.pay { display: flex; align-items: center; gap: 10px; }
.pay .amount { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.toggle-paid { min-width: 112px; }

.person .contacts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* ---------- upload ---------- */
.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pick label.btn { color: var(--text); font-size: 14px; }
.pick input[type=file] { display: none; }
.progressbar { height: 10px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--border); }
.progressbar > i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }

/* ---------- dialog ---------- */
dialog {
  width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); padding: 0;
  border: 0; border-radius: 16px; background: var(--surface); color: var(--text);
  box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
dialog::backdrop { background: rgba(10, 15, 25, .55); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
dialog .d-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
dialog .d-body { padding: 16px; overflow-y: auto; }
dialog .d-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); }
.form-error { color: var(--bad); font-size: 14px; margin-top: 10px; }

.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.92); display: grid; place-items: center; }
.lightbox img { max-width: 100vw; max-height: 100vh; object-fit: contain; }
.lightbox .lb-btn {
  position: absolute; width: 48px; height: 48px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15);
  color: #fff; display: grid; place-items: center; cursor: pointer;
}
.lightbox .lb-close { top: calc(12px + env(safe-area-inset-top)); right: 12px; }
.lightbox .lb-prev { left: 12px; top: 50%; transform: translateY(-50%); }
.lightbox .lb-next { right: 12px; top: 50%; transform: translateY(-50%); }
.lightbox .lb-count { position: absolute; bottom: calc(16px + env(safe-area-inset-bottom)); color: #fff; font-size: 14px; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px);
  background: #182033; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; z-index: 200;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--bad); }

/* ---------- works (v2) ---------- */
.big-action { min-height: 56px; font-size: 17px; border-radius: 14px; }
.big-action .icon { width: 22px; height: 22px; }
a.btn { text-decoration: none; }
.card-link { display: block; color: inherit; }
.work-card { border-left: 5px solid var(--accent); }
.work-card.lift { border-left-color: var(--info); }
.work-card .title { font-weight: 700; font-size: 17px; margin-top: 8px; }
.work-card .addr { display: flex; gap: 6px; align-items: flex-start; color: var(--muted); font-size: 14px; margin-top: 4px; }
.work-card .addr a { overflow-wrap: anywhere; }
.facts { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 14px; }
.facts span { display: inline-flex; align-items: center; gap: 5px; }
.facts .icon { color: var(--muted); }
.part-badge {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 6px;
  font-weight: 800; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; flex: none;
}
.part-badge.shaft { background: var(--accent-soft); color: var(--warn); }
.part-badge.lift { background: var(--info-soft); color: var(--info); }
.money-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; margin-top: 10px; font-size: 14px; color: var(--muted); }
.money-line b { color: var(--text); font-variant-numeric: tabular-nums; }
.pay-sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.pay-sum > div { background: var(--surface-2); border-radius: 10px; padding: 10px; min-width: 0; }
.pay-sum span { display: block; font-size: 12px; color: var(--muted); font-weight: 600; }
.pay-sum b { display: block; font-size: 16px; margin-top: 2px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.pay-sum b.warn { color: var(--warn); }
.pay-sum b.ok { color: var(--ok); }
.pay-list { margin-top: 12px; border-top: 1px solid var(--border); }
.pay-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.pay-row b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stats.two { grid-template-columns: 1fr 1fr; }
.chips.wrap { flex-wrap: wrap; overflow: visible; }
.field-label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.segmented.radio label { flex: 1; display: block; margin: 0; cursor: pointer; position: relative; }
.segmented.radio input {
  position: absolute; left: 0; top: 0; width: 1px; height: 1px; min-height: 0;
  padding: 0; margin: 0; border: 0; opacity: 0; pointer-events: none;
}
.segmented.radio span {
  display: block; text-align: center; padding: 10px; border-radius: 8px;
  font-size: 15px; font-weight: 700; color: var(--muted);
}
.segmented.radio input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented.radio input:focus-visible + span { outline: 2px solid var(--accent); }
.pick .full { grid-column: 1 / -1; }
.cred { display: grid; gap: 10px; }
.cred > div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.cred b { overflow-wrap: anywhere; text-align: right; }
.cred .pin { font-size: 22px; letter-spacing: .15em; font-variant-numeric: tabular-nums; }

/* ---------- objects & lifts (v3) ---------- */
a.stat { color: inherit; }
.obj-card .title { font-weight: 700; font-size: 17px; }
.obj-card .addr, .card > .addr { display: flex; gap: 6px; align-items: flex-start; color: var(--muted); font-size: 14px; margin-top: 4px; }
.text-warn { color: var(--warn); font-weight: 600; }
.block-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 14px;
}
.lift-row {
  display: flex; align-items: center; gap: 10px; padding: 12px; color: inherit;
  border-bottom: 1px solid var(--border);
}
.lift-row:last-child { border-bottom: 0; }
.lift-row > .icon:first-child { color: var(--info); width: 26px; height: 26px; }
.lift-row > .icon:last-child { color: var(--muted); }
.lift-row.stopped { background: var(--bad-soft); }
.lift-row.stopped > .icon:first-child { color: var(--bad); }
.card > .lift-row { margin: -14px -14px 0; border-bottom: 0; border-radius: var(--radius) var(--radius) 0 0; }
.month-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.card.flush .month-row { padding: 10px 12px; }
.month-row.hidden { display: none; }
.month-row .m { flex: 1 1 110px; font-weight: 600; font-size: 14px; }
.months { margin-top: 10px; border-top: 1px solid var(--border); }
.pay-toggle, .doc-toggle {
  display: inline-flex; align-items: center; gap: 6px; min-height: 38px; padding: 4px 12px;
  border-radius: 10px; border: 1px dashed var(--warn); background: var(--warn-soft); color: var(--warn);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer; font-variant-numeric: tabular-nums;
}
.pay-toggle span { font-weight: 500; font-size: 12px; opacity: .85; }
.pay-toggle.on, .doc-toggle.on { border: 1px solid var(--ok); background: var(--ok-soft); color: var(--ok); }
.doc-toggle { min-height: 44px; padding: 6px 16px; font-size: 15px; }
.doc-toggle:disabled { cursor: default; }
.btn.danger-outline { border-color: var(--bad); color: var(--bad); background: var(--surface); }
.btn.danger-fill { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ok-fill { background: var(--ok); border-color: var(--ok); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.ok-fill, .btn.danger-fill { color: #0f1420; } }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--brand); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px 22px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.login-card .logo { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-card .logo img { width: 48px; height: 48px; border-radius: 12px; }
.login-card .logo b { font-size: 20px; display: block; }
