:root {
  --bg: #f3f1ec;
  --card: #ffffff;
  --card-2: #f8f7f4;
  --ink: #1b1c1f;
  --muted: #6c6f76;
  --line: #e3e0d9;
  --accent: #f02a00;
  --accent-ink: #ffffff;
  --accent-soft: #ffe9e3;
  --ok: #23843f;
  --ok-soft: #e5f4e9;
  --ok-line: #bfe3c9;
  --bad: #d3302f;
  --bad-soft: #fde8e7;
  --warn: #9a6100;
  --warn-soft: #fff3d9;
  --shadow: 0 1px 2px rgba(20, 20, 20, .05), 0 4px 14px rgba(20, 20, 20, .04);
  --radius: 16px;
  --tabbar: 64px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121316; --card: #1c1d21; --card-2: #23252a; --ink: #f1f0ed; --muted: #9b9ea6; --line: #2e3036;
    --accent: #ff4a1f; --accent-soft: #3a1d16; --ok: #4cc16c; --ok-soft: #15301e; --ok-line: #24502f;
    --bad: #ff5a55; --bad-soft: #3a1a1a; --warn: #f0b44a; --warn-soft: #33280f;
    --shadow: none; color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.4 var(--font);
  padding: env(safe-area-inset-top) 0 calc(var(--tabbar) + env(safe-area-inset-bottom) + 16px);
  min-height: 100vh;
}
body.noscroll { overflow: hidden; }
body.bare { padding-bottom: env(safe-area-inset-bottom); }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; }
#app { max-width: 720px; margin: 0 auto; padding: 0 16px; }

/* шапка */
.top { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 18px 0 12px; }
.top h1 { font-size: 32px; line-height: 1.1; letter-spacing: -.02em; font-weight: 750; }
.top .sub { color: var(--muted); font-size: 14px; margin-top: 4px; }
.back { display: inline-flex; align-items: center; gap: 2px; color: var(--accent); font-weight: 550; padding: 14px 0 0; margin-left: -4px; }
.back svg { width: 22px; height: 22px; }
.title-over { color: var(--bad); }

.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 12px; border: 0;
  background: var(--card); box-shadow: var(--shadow); color: var(--ink); flex: none;
}
.icon-btn.accent { background: var(--accent); color: var(--accent-ink); }
.icon-btn svg { width: 22px; height: 22px; }

/* кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px;
  border-radius: 13px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 16px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; border-radius: 10px; }
.btn:disabled { opacity: .55; }
.btn svg { width: 19px; height: 19px; }
.btn-text { background: none; border: 0; padding: 6px 4px; color: var(--accent); font-weight: 600; font-size: 14px; }
.btn-text.danger { color: var(--bad); }
.btn-text.muted { color: var(--muted); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 4px 0 16px; }
.actions .btn { padding: 0 10px; white-space: nowrap; font-size: 15px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* карточки */
.stack { display: grid; gap: 12px; }
.card { display: block; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; border: 1px solid transparent; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 22px 4px 8px; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.empty b { display: block; color: var(--ink); font-size: 18px; margin-bottom: 6px; }

/* список проектов */
.proj-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.proj-name { font-size: 18px; font-weight: 680; line-height: 1.25; }
.proj.over .proj-name { color: var(--bad); }
.proj .meta { margin-top: 3px; }
.bar { height: 8px; background: var(--card-2); border-radius: 99px; overflow: hidden; margin: 14px 0 8px; border: 1px solid var(--line); }
.bar span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.proj.over .bar span { background: var(--bad); }
.proj-nums { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.pending-line { margin-top: 10px; font-size: 13px; color: var(--warn); background: var(--warn-soft); border-radius: 9px; padding: 6px 10px; display: inline-block; }
.badge { flex: none; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }

/* чипы и сегменты */
.chips { display: flex; gap: 8px; margin: 0 0 14px; }
.chip { border: 1px solid var(--line); background: var(--card); padding: 7px 14px; border-radius: 99px; font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; margin-bottom: 14px; }
.seg button, .seg label { border: 0; background: none; padding: 8px 6px; border-radius: 9px; font-size: 14px; font-weight: 600; text-align: center; color: var(--muted); position: relative; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg [aria-selected="true"], .seg label:has(input:checked) { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* сводные цифры */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat { background: var(--card); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 19px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat.ok .v { color: var(--ok); }
.stat.bad { background: var(--bad-soft); }
.stat.bad .v, .stat.bad .k { color: var(--bad); }
.stat.warn .v { color: var(--warn); }

.kv { display: grid; gap: 0; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); flex: none; }
.kv dd { margin: 0; text-align: right; }
.desc { white-space: pre-wrap; margin-top: 10px; }

/* исполнители */
.list { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.li { display: flex; gap: 12px; align-items: center; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .grow { flex: 1; min-width: 0; }
.li .name { font-weight: 600; }
.li .right { text-align: right; flex: none; }

/* платежи */
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.pay { border-color: var(--line); box-shadow: none; }
.pay.paid { background: var(--ok-soft); border-color: var(--ok-line); }
.pay-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tag { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; padding: 3px 8px; border-radius: 7px; background: var(--card-2); color: var(--muted); border: 1px solid var(--line); }
.tag.inv { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.amount { font-size: 19px; font-weight: 750; font-variant-numeric: tabular-nums; }
.pay-purpose { margin: 8px 0 4px; font-weight: 550; overflow-wrap: anywhere; }
.pay-file { display: inline-flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--accent); font-weight: 600; font-size: 14px; max-width: 100%; }
.pay-file span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pay-file svg { width: 17px; height: 17px; flex: none; }
.pay-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--line); flex-wrap: wrap; }
.pay.paid .pay-foot { border-top-color: var(--ok-line); }
.status { font-size: 14px; font-weight: 650; color: var(--muted); }
.status.ok { color: var(--ok); }
.alert { margin-top: 10px; padding: 10px 12px; border-radius: 10px; font-size: 14px; background: var(--warn-soft); color: var(--warn); }
.alert.bad { background: var(--bad-soft); color: var(--bad); }
.check { display: flex; gap: 12px; align-items: flex-start; }
.check input { width: 22px; height: 22px; margin: 2px 0 0; accent-color: var(--accent); flex: none; }

/* сводка */
.sum-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 13px 16px; border-bottom: 1px solid var(--line); }
.sum-row:last-child { border-bottom: 0; }
.sum-row .n { font-weight: 650; }
.sum-row.over .n { color: var(--bad); }
.sum-row .p { text-align: right; font-weight: 700; }
.sum-row.over .p { color: var(--bad); }
.sum-row .b { grid-column: 1 / -1; display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); }
.sum-total { background: var(--card-2); }

/* отчёт */
.report-text { white-space: pre-wrap; font-size: 14px; line-height: 1.45; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 12px; max-height: 320px; overflow: auto; margin: 0; font-family: var(--font); }

/* формы */
.field { display: block; margin-bottom: 14px; }
.label { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 2px 6px; }
.input, .field input:not([type="radio"]):not([type="checkbox"]):not([type="file"]), .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 21px, calc(100% - 15px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 36px; }
.field textarea { resize: vertical; min-height: 84px; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field input[type="date"] { display: block; }
.hint { display: block; font-size: 13px; color: var(--muted); margin: 6px 2px 0; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-pick { display: flex; align-items: center; gap: 12px; border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; background: var(--card); }
.file-pick input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-pick .ico { width: 40px; height: 40px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.file-pick .ico svg { width: 22px; height: 22px; }
.file-pick.has { border-style: solid; border-color: var(--ok-line); background: var(--ok-soft); }
.calc { background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin: -4px 0 14px; font-size: 14px; }
.calc .spread + .spread { margin-top: 4px; }
.calc b { font-variant-numeric: tabular-nums; }
.form-err { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }
.page-form { padding-bottom: 8px; }

/* нижняя панель */
#tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--bg) 88%, transparent); -webkit-backdrop-filter: blur(18px); backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
#tabs[hidden] { display: none; }
#tabs a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; font-weight: 600; color: var(--muted); }
#tabs a svg { width: 25px; height: 25px; }
#tabs a[aria-current="page"] { color: var(--accent); }

/* шторка */
#sheet-root .overlay { position: fixed; inset: 0; background: rgba(0,0,0,.38); opacity: 0; transition: opacity .2s; z-index: 40; }
#sheet-root .sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-height: calc(100% - env(safe-area-inset-top) - 24px);
  display: flex; flex-direction: column; background: var(--bg); border-radius: 20px 20px 0 0; transform: translateY(100%);
  transition: transform .26s cubic-bezier(.2,.8,.2,1); max-width: 720px; margin: 0 auto;
}
#sheet-root.open .overlay { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.sheet-grab { width: 38px; height: 5px; border-radius: 9px; background: var(--line); margin: 8px auto 0; flex: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 16px 10px; flex: none; }
.sheet-head h2 { font-size: 20px; font-weight: 720; }
.sheet-head .icon-btn { width: 34px; height: 34px; border-radius: 99px; box-shadow: none; background: var(--card-2); }
.sheet-head .icon-btn svg { width: 18px; height: 18px; }
.sheet-body { padding: 4px 16px 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; flex: 1; }
.sheet-foot { padding: 10px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); flex: none; display: grid; gap: 8px; }

/* тосты */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar) + env(safe-area-inset-bottom) + 12px); z-index: 60; display: grid; justify-items: center; pointer-events: none; }
#toast .t { max-width: 520px; background: var(--ink); color: var(--bg); padding: 12px 16px; border-radius: 14px; font-size: 15px; font-weight: 550; box-shadow: 0 8px 30px rgba(0,0,0,.2); animation: tin .2s ease-out; }
#toast .t.warn { background: var(--warn); color: #fff; }
#toast .t.bad { background: var(--bad); color: #fff; }
@keyframes tin { from { transform: translateY(10px); opacity: 0; } }

/* вход */
.login { min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom)); display: flex; flex-direction: column; justify-content: center; max-width: 380px; margin: 0 auto; padding: 24px 0; }
.brand { display: grid; gap: 10px; margin-bottom: 32px; }
.brand > span { color: var(--muted); font-size: 15px; }
.logo { display: block; }
.logo img { display: block; height: 30px; width: auto; }
.logo.big img { height: 52px; }
.logo .logo-d { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .logo .logo-l { display: none; } :root:not([data-theme="light"]) .logo .logo-d { display: block; } }
.appbar { padding: 14px 0 0; }
.login h1 { font-size: 26px; margin-bottom: 6px; }
.login p { color: var(--muted); margin: 0 0 20px; }
.names { display: grid; gap: 8px; }
.names button { text-align: left; padding: 15px 16px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-weight: 600; font-size: 17px; display: flex; justify-content: space-between; align-items: center; }
.names button svg { width: 18px; height: 18px; color: var(--muted); }

.skeleton { height: 112px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card) 0%, var(--card-2) 50%, var(--card) 100%); background-size: 200% 100%; animation: sk 1.2s infinite linear; }
@keyframes sk { to { background-position: -200% 0; } }
.chat-row .grow .tiny { word-break: break-all; }
.mt { margin-top: 14px; }
.mb { margin-bottom: 14px; }
.center { text-align: center; }
