:root {
  --brand: #9331B8; --brand-d: #6A1F88; --brand-l: #F4EAF9; --brand-xl: #FAF5FC;
  --ink: #1F1626; --muted: #6E6478; --line: #E8E0EE; --bg: #F6F3F8; --card: #FFFFFF;
  --good: #1E8E5A; --good-l: #E5F6EE; --bad: #C62E3A; --bad-l: #FDECEE; --warn: #B86E00; --warn-l: #FFF4E0;
  --r: 14px; --shadow: 0 1px 2px rgba(60, 20, 80, .06), 0 4px 14px rgba(60, 20, 80, .06);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #B65ADB; --brand-d: #D9A6EE; --brand-l: #2E1F38; --brand-xl: #241A2C;
    --ink: #F3EDF7; --muted: #A99DB3; --line: #382C42; --bg: #17111C; --card: #211A28;
    --good: #4CC98D; --good-l: #183126; --bad: #FF6B76; --bad-l: #3A1B20; --warn: #F2B045; --warn-l: #382A12;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0; } h2 { font-size: 1.2rem; margin: 0; } h3 { font-size: 1rem; margin: 18px 0 8px; } h4 { margin: 14px 0 6px; }
.card h3:first-child { margin-top: 0; }
.muted { color: var(--muted); } .small, small { font-size: .82rem; } .neg { color: var(--bad); } .warn { color: var(--warn); }
.splash { display: grid; place-items: center; height: 100vh; } .splash img { width: 60%; max-width: 280px; }

.top { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 14px 8px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; color: var(--ink); min-width: 0; }
.brand img { height: 34px; width: auto; } .brand b { display: block; color: var(--brand); letter-spacing: .02em; font-size: .98rem; }
.brand small { color: var(--muted); display: block; margin-top: -2px; }
.sync-pill { border: 0; border-radius: 99px; padding: 6px 10px; font-size: .75rem; font-weight: 600; background: var(--good-l); color: var(--good); white-space: nowrap; max-width: 55vw; overflow: hidden; text-overflow: ellipsis; }
.sync-pill.off { background: var(--warn-l); color: var(--warn); } .sync-pill.run { background: var(--brand-l); color: var(--brand); }

main { padding: 14px 16px calc(90px + env(safe-area-inset-bottom)); max-width: 760px; margin: 0 auto; }
.bottom { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 10px; color: var(--muted); font-size: .72rem; font-weight: 600; }
.bottom a.on { color: var(--brand); } .bottom .ic { font-size: 1.25rem; position: relative; }
.bottom .dot { position: absolute; top: -4px; right: -12px; background: var(--bad); color: #fff; font-style: normal; font-size: .65rem; border-radius: 99px; padding: 1px 5px; }

.page-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; }
.page-head .back { font-size: 1.8rem; line-height: 1; padding: 0 6px 4px 0; }
.live-dot { margin-left: auto; color: var(--good); font-size: .8rem; font-weight: 700; animation: pulse 2s infinite; }
@keyframes pulse { 50% { opacity: .45; } }

.card { background: var(--card); border-radius: var(--r); padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.eyebrow { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.row-between { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.right { text-align: right; } .big { font-size: 1.6rem; font-weight: 800; }
.count { background: var(--bad); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: .75rem; vertical-align: middle; }

.contract-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.contract-body { display: flex; align-items: center; gap: 16px; margin: 12px 0; }
.ring { flex: none; } .ring-bg { fill: none; stroke: var(--brand-l); stroke-width: 12; }
.ring-fg { fill: none; stroke: var(--brand); stroke-width: 12; stroke-linecap: round; transition: stroke-dashoffset .6s; }
.ring-pct { font-size: 22px; font-weight: 800; fill: var(--ink); } .ring-sub { font-size: 10px; fill: var(--muted); }
.kpis { display: grid; gap: 10px; flex: 1; min-width: 0; } .kpis small, .meta-grid small, .money small { display: block; color: var(--muted); }
.kpis b { font-size: 1.15rem; }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; border-top: 1px solid var(--line); padding-top: 12px; }
.card > .meta-grid:first-child, h3 + .meta-grid { border-top: 0; padding-top: 0; }
.money { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; }
.money b { font-size: 1.15rem; } .money em { display: block; font-style: normal; font-size: .75rem; color: var(--muted); }
.chip { border-radius: 99px; padding: 4px 10px; font-size: .78rem; font-weight: 700; white-space: nowrap; }
.chip.good { background: var(--good-l); color: var(--good); } .chip.bad { background: var(--bad-l); color: var(--bad); }

.chart { width: 100%; height: auto; } .chart .bar { fill: var(--brand); opacity: .55; } .chart .bar.ok { opacity: 1; }
.chart .axis { font-size: 9px; fill: var(--muted); } .chart .target { stroke: var(--good); stroke-dasharray: 4 3; }

.alerts .alert { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-radius: 10px; margin-top: 8px; background: var(--brand-xl); border-left: 4px solid var(--brand); font-size: .9rem; }
.alert.a-arrears, .alert.a-incident, .alert.a-deposit_overdue, .alert.a-silent { background: var(--bad-l); border-color: var(--bad); }
.alert.a-deposit { background: var(--good-l); border-color: var(--good); } .alert.a-license { background: var(--warn-l); border-color: var(--warn); }
.alert-actions { display: flex; gap: 10px; align-items: center; font-size: 1.1rem; }
.link { background: none; border: 0; color: var(--brand); font-weight: 700; cursor: pointer; padding: 4px; font-size: .85rem; }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.action { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 12px; display: flex; flex-direction: column; gap: 6px; color: var(--ink); font-weight: 600; box-shadow: var(--shadow); min-height: 96px; }
.action .ai { font-size: 1.6rem; } .action:active { background: var(--brand-l); }
.warn-card { border-color: var(--bad); }

.tabs { display: flex; gap: 6px; overflow-x: auto; margin: 0 -16px 12px; padding: 2px 16px; scrollbar-width: none; }
.tabs a { flex: none; padding: 8px 14px; border-radius: 99px; background: var(--card); border: 1px solid var(--line); color: var(--muted); font-weight: 600; font-size: .85rem; }
.tabs a.on { background: var(--brand); border-color: var(--brand); color: #fff; }

.list { background: var(--card); border-radius: var(--r); border: 1px solid var(--line); overflow: hidden; margin-bottom: 14px; box-shadow: var(--shadow); }
.item { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 13px 14px; border-bottom: 1px solid var(--line); color: var(--ink); }
.item:last-child { border-bottom: 0; } .item-main { min-width: 0; flex: 1; }
.item-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .item-sub { color: var(--muted); font-size: .82rem; }
.item-amt { font-weight: 700; white-space: nowrap; } .item.void { opacity: .5; text-decoration: line-through; }
.card .list { box-shadow: none; margin: 8px 0; }
.badge { display: inline-block; border-radius: 6px; padding: 1px 6px; font-size: .72rem; font-weight: 700; background: var(--brand-l); color: var(--brand-d); text-decoration: none; }
.s-pending, .s-quote_pending, .s-open { background: var(--warn-l); color: var(--warn); }
.s-verified, .s-approved, .s-done, .s-active, .s-closed { background: var(--good-l); color: var(--good); }
.s-rejected, .s-void, .s-terminated { background: var(--bad-l); color: var(--bad); }
.empty { text-align: center; padding: 24px 0; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 12px; padding: 12px 16px; font: inherit; font-weight: 700; cursor: pointer; min-height: 46px; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; } .btn.danger { color: var(--bad); border-color: var(--bad-l); }
.btn.block { display: flex; width: 100%; margin-bottom: 14px; } .btn.sm { min-height: 34px; padding: 6px 10px; font-size: .82rem; }
.btn:disabled { opacity: .5; } .btn:active { transform: scale(.98); }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; } .btn-row .btn { flex: 1; }
.btn-col { display: grid; gap: 10px; }
.btn-row.sticky { position: sticky; bottom: calc(66px + env(safe-area-inset-bottom)); background: var(--card); padding: 10px 0 2px; margin-top: 16px; }

.form .field { display: block; margin-bottom: 14px; } .field > span { display: block; font-size: .85rem; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
input, select, textarea { width: 100%; font: inherit; color: var(--ink); background: var(--brand-xl); border: 1.5px solid var(--line); border-radius: 10px; padding: 12px; min-height: 46px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); background: var(--card); }
.check { display: flex; align-items: center; gap: 10px; padding: 8px 0; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); flex: none; }
.info { background: var(--brand-l); color: var(--brand-d); border-radius: 10px; padding: 10px 12px; margin: 0 0 14px; font-size: .9rem; }
.info.bad { background: var(--bad-l); color: var(--bad); }
.card .info:last-child { margin-bottom: 0; margin-top: 12px; }

.photo-field { margin-bottom: 14px; } .photo-label { font-size: .85rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.photo-box { display: grid; place-items: center; border: 2px dashed var(--line); border-radius: 12px; min-height: 120px; background: var(--brand-xl); cursor: pointer; overflow: hidden; }
.photo-box img { width: 100%; max-height: 240px; object-fit: cover; display: block; } .photo-box .plus { font-size: 2rem; opacity: .6; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; }
.photo-field.small .photo-box { min-height: 96px; } .photo-field.small .photo-box img { height: 96px; }
.detail .drow { display: flex; justify-content: space-between; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.drow .dlabel { color: var(--muted); font-size: .88rem; flex: none; max-width: 45%; } .drow .dval { text-align: right; font-weight: 600; word-break: break-word; }
.detail-photo { width: 100%; max-width: 420px; border-radius: 10px; display: block; margin: 6px 0 0 auto; background: var(--brand-l); min-height: 40px; }
.photo-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); gap: 8px; } .photo-row figure { margin: 0; } .photo-row figcaption { font-size: .72rem; color: var(--muted); text-align: center; }
.diff { background: var(--brand-xl); border-radius: 10px; padding: 10px 12px; margin: 8px 0; } .diff .drow { border-color: var(--line); }

.seg { display: flex; background: var(--brand-l); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; padding: 10px; border-radius: 9px; font: inherit; font-weight: 700; color: var(--brand-d); cursor: pointer; }
.seg button.on { background: var(--card); color: var(--brand); box-shadow: var(--shadow); }

.join { max-width: 440px; margin: 0 auto; padding: calc(env(safe-area-inset-top) + 24px) 16px 40px; display: grid; gap: 16px; }
.join-logo { width: 72%; max-width: 280px; margin: 0 auto; display: block; }
.invite { margin-top: 14px; text-align: center; } .linkbox { display: block; word-break: break-all; background: var(--brand-xl); padding: 10px; border-radius: 10px; font-size: .8rem; text-align: left; }
.code { font-size: 2.6rem; font-weight: 800; letter-spacing: .12em; color: var(--brand); font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); opacity: 0; transition: .25s; background: var(--ink); color: var(--card); padding: 12px 16px; border-radius: 12px; z-index: 50; max-width: 90vw; font-weight: 600; font-size: .9rem; }
.toast.show { opacity: 1; transform: translate(-50%, 0); } .toast.bad { background: var(--bad); color: #fff; }
[hidden] { display: none !important; }
