:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --text: #1b2333;
  --muted: #5f6b80;
  --line: #dde3ed;
  --primary: #1f3864;
  --primary-ink: #ffffff;
  --accent: #f59e0b;
  --accent-ink: #2b1a00;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --over: #b91c1c;
  --over-bg: #fee2e2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 14px rgba(20, 30, 50, .06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #182033;
    --surface-2: #212b42;
    --text: #e8edf7;
    --muted: #9aa7bf;
    --line: #2a3550;
    --primary: #2b4a86;
    --ok: #4ade80;
    --ok-bg: #12351f;
    --warn: #fbbf24;
    --warn-bg: #3a2a0a;
    --over: #f87171;
    --over-bg: #3d1616;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  padding-bottom: 96px;
}
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }

/* ---------- горна лента и навигация ---------- */
.top {
  background: var(--primary);
  color: var(--primary-ink);
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.logo { display: inline-flex; }
.tag {
  font-size: 10px; letter-spacing: .08em; background: var(--accent); color: var(--accent-ink);
  padding: 2px 7px; border-radius: 999px; font-weight: 700;
}
#nav { display: flex; gap: 4px; }
#nav a {
  display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px;
  color: rgba(255, 255, 255, .75); font-size: 15px;
}
#nav a.active { background: rgba(255, 255, 255, .16); color: #fff; }
#nav a:hover { color: #fff; }

@media (max-width: 719px) {
  #nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    background: var(--surface); border-top: 1px solid var(--line);
    justify-content: space-around; gap: 0; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  }
  #nav a {
    flex-direction: column; gap: 2px; font-size: 12px; color: var(--muted); padding: 6px 14px; flex: 1;
  }
  #nav a.active { background: transparent; color: var(--primary); font-weight: 700; }
  @media (prefers-color-scheme: dark) { #nav a.active { color: #9db8ec; } }
  .fab { bottom: 84px !important; }
}

main { max-width: 980px; margin: 0 auto; padding: 16px; }

/* ---------- общи компоненти ---------- */
.page-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.page-title h1 { font-size: 22px; }
.sub { color: var(--muted); font-size: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; border: 1px solid var(--line);
}
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.kpi .v { font-size: 20px; font-weight: 700; margin-top: 2px; }
.kpi .l { font-size: 13px; color: var(--muted); }
.kpi.bad .v { color: var(--over); }
.kpi.good .v { color: var(--ok); }

.banner {
  border-radius: var(--radius); padding: 14px 16px; font-weight: 700; margin-bottom: 14px;
  display: flex; gap: 10px; align-items: center; font-size: 16px;
}
.banner.over { background: var(--over-bg); color: var(--over); border: 1px solid var(--over); }
.banner.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.banner.ok { background: var(--ok-bg); color: var(--ok); border: 1px solid var(--ok); }

.pill {
  display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.over { background: var(--over-bg); color: var(--over); }

/* ---------- карта на обект ---------- */
.obj-card { display: block; transition: transform .12s ease, box-shadow .12s ease; }
.obj-card:hover { transform: translateY(-2px); }
.obj-card.over { border-left: 6px solid var(--over); }
.obj-card.warn { border-left: 6px solid var(--warn); }
.obj-card.ok { border-left: 6px solid var(--ok); }
.obj-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.obj-head h3 { font-size: 17px; }
.obj-nums { display: flex; justify-content: space-between; align-items: baseline; margin: 12px 0 6px; }
.obj-nums b { font-size: 20px; }
.bar { position: relative; height: 12px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar > i { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 999px; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: #f59e0b; }
.bar.over > i { background: var(--over); }
.bar .mark { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--text); opacity: .35; }
.bar-caption { display: flex; justify-content: space-between; font-size: 13px; margin-top: 6px; color: var(--muted); }
.bar-caption .over { color: var(--over); font-weight: 700; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip { font-size: 12.5px; background: var(--surface-2); padding: 4px 10px; border-radius: 999px; color: var(--muted); }
.chip b { color: var(--text); }

/* ---------- страница на обект ---------- */
.back { display: inline-flex; gap: 4px; align-items: center; color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.status-select {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 6px 10px; font-size: 14px;
}
.section { margin-top: 22px; }
.section h2 { font-size: 17px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.list { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row .main { flex: 1; min-width: 0; }
.row .t { font-weight: 600; overflow-wrap: anywhere; }
.row .d { font-size: 13px; color: var(--muted); }
.row .amt { font-weight: 700; white-space: nowrap; }
.empty { padding: 18px; color: var(--muted); text-align: center; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 9px 14px;
  cursor: pointer; font-weight: 600; min-height: 42px;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn.primary:hover { filter: brightness(1.1); }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn.danger { color: var(--over); }
.icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 20px; line-height: 1;
  padding: 6px 8px; border-radius: 8px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--over); }
.linklike { border: 0; background: none; color: var(--primary); font-weight: 600; cursor: pointer; padding: 0; }
@media (prefers-color-scheme: dark) { .linklike { color: #9db8ec; } }

.fab {
  position: fixed; right: 18px; bottom: 22px; z-index: 40; display: flex; align-items: center; gap: 8px;
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 999px; padding: 14px 20px;
  font-weight: 800; font-size: 16px; box-shadow: 0 6px 18px rgba(0, 0, 0, .28); cursor: pointer;
}
.fab:active { transform: scale(.97); }

/* ---------- работници ---------- */
.month-nav { display: flex; align-items: center; gap: 10px; }
.month-nav b { min-width: 130px; text-align: center; }
.worker-card .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.worker-card .head h3 { font-size: 17px; }
.mini { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px 14px; margin-top: 12px; font-size: 14px; }
.mini div span { display: block; color: var(--muted); font-size: 12.5px; }
.mini div b { font-size: 16px; }
.due { color: var(--over); }

/* ---------- диалог и форми ---------- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 24px);
  background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0, 0, 0, .4);
}
dialog::backdrop { background: rgba(10, 15, 30, .55); }
@media (max-width: 719px) {
  dialog { margin: auto auto 0; width: 100vw; border-radius: 18px 18px 0 0; max-height: 92vh; }
}
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; }
.dlg-head h2 { font-size: 19px; }
.dlg-body { padding: 8px 18px 4px; overflow-y: auto; max-height: calc(92vh - 150px); display: grid; gap: 12px; }
.dlg-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 14px 18px 18px; }
.dlg-foot .btn { flex: 0 0 auto; }
label.f { display: grid; gap: 4px; font-size: 14px; font-weight: 600; }
label.f input, label.f select, .field input {
  border: 1px solid var(--line); background: var(--surface); border-radius: 10px; padding: 11px 12px; min-height: 46px;
  font-weight: 400; width: 100%;
}
label.f select { background: var(--surface); }
input:focus, select:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 1px;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.lbl { font-size: 14px; font-weight: 600; display: block; margin-bottom: 6px; }
.wrow {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 12px; margin-bottom: 8px; cursor: pointer; background: var(--surface);
}
.wrow:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, var(--surface)); }
.wrow input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--primary); flex: none; }
.wrow .wname { flex: 1; font-weight: 600; }
.wrow .wname small { display: block; font-weight: 400; color: var(--muted); }
.wrow select { border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; background: var(--surface); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.seg label { text-align: center; padding: 12px 8px; cursor: pointer; font-weight: 600; background: var(--surface); border-left: 1px solid var(--line); }
.seg label:first-child { border-left: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--primary); color: var(--primary-ink); }
.seg label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: -3px; }
.preview { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; display: flex; justify-content: space-between; font-size: 15px; }
.err { color: var(--over); font-weight: 600; margin: 0; min-height: 0; }
.err:empty { display: none; }
.hidden { display: none !important; }
.big-actions { display: grid; gap: 10px; }
.big-actions button {
  display: flex; align-items: center; gap: 14px; text-align: left; padding: 16px; border-radius: 14px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 700; font-size: 17px;
}
.big-actions button:hover { background: var(--surface-2); }
.big-actions .ic { font-size: 26px; }
.big-actions small { display: block; font-weight: 400; color: var(--muted); font-size: 13.5px; }

#toast {
  position: fixed; left: 50%; bottom: 92px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #1b2333; color: #fff; padding: 11px 18px; border-radius: 999px; z-index: 100; pointer-events: none;
  transition: opacity .2s, transform .2s; font-weight: 600; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.more-list { display: grid; gap: 10px; }
.more-list .btn { text-align: left; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; }
.note { font-size: 13.5px; color: var(--muted); }
.field { display: grid; gap: 4px; }
