:root {
  --bg: #f6f5f2; --panel: #fff; --side: #ebe9e3; --line: #e2dfd7; --line-strong: #cfcbc0;
  --text: #1f1e1b; --muted: #6f6c64; --faint: #9a968c;
  --accent: #1d5c55; --accent-soft: #dcebe8; --on-accent: #fff; --danger: #b23a2b; --ok: #2f8a4b;
  --input: #fff; --shadow: rgba(0,0,0,.18); --overlay: rgba(30,28,24,.38); --toast: #2a2925;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --st: env(safe-area-inset-top); --sb: env(safe-area-inset-bottom);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d1e; --panel: #24272a; --side: #2e3236; --line: #34383c; --line-strong: #464b50;
    --text: #e9e7e2; --muted: #a29f97; --faint: #77746d;
    --accent: #3f9a8f; --accent-soft: #23423e; --input: #2b2f33; --shadow: rgba(0,0,0,.5); --overlay: rgba(0,0,0,.55); --toast: #3a3d40;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); font-size: 16px; color: var(--text); background: var(--bg); overscroll-behavior-y: none; }
button { font: inherit; color: inherit; }
input, textarea, select { font: inherit; color: var(--text); }
.hidden { display: none !important; }
svg { display: block; }

/* ---------- экраны ---------- */
#app { min-height: 100%; }
.screen { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.bar { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 6px; padding: calc(8px + var(--st)) 8px 8px; background: var(--bg); border-bottom: 1px solid var(--line); min-height: 56px; }
.bar h1 { flex: 1; min-width: 0; margin: 0 6px; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .sub { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar .ttl { flex: 1; min-width: 0; margin: 0 4px; }
.bar .ttl h1 { margin: 0; }
.ib { width: 42px; height: 42px; flex: none; border: 0; background: none; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: var(--accent); padding: 0; position: relative; }
.ib:active { background: var(--side); }
.ib svg { width: 24px; height: 24px; }
.ib .dot { position: absolute; top: 7px; right: 7px; width: 9px; height: 9px; border-radius: 50%; background: #e0342f; border: 2px solid var(--bg); }
.net { font-size: 12px; text-align: center; padding: 4px; background: #c9861a; color: #fff; }
.content { flex: 1; padding: 12px 12px calc(96px + var(--sb)); }

/* ---------- вход ---------- */
.login { flex: 1; display: flex; flex-direction: column; justify-content: center; padding: calc(24px + var(--st)) 24px calc(24px + var(--sb)); max-width: 420px; width: 100%; margin: 0 auto; }
.login img { width: 76px; height: 76px; margin: 0 auto 14px; display: block; }
.login h2 { text-align: center; margin: 0 0 4px; font-size: 24px; }
.login p { text-align: center; color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 2px 5px; }
.field input, .field textarea { width: 100%; padding: 12px 13px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--input); outline: none; font-size: 16px; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-strong); background: var(--panel); border-radius: 11px; padding: 12px 16px; font-weight: 600; font-size: 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .55; }
.err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 2px 10px; text-align: center; }

/* ---------- список объектов ---------- */
.search { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 11px; background: var(--input); outline: none; margin-bottom: 10px; font-size: 16px; }
.cards { display: flex; flex-direction: column; gap: 8px; }
.card { display: flex; align-items: center; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 13px 14px; text-decoration: none; color: inherit; }
.card:active { background: var(--side); }
.card .c-main { flex: 1; min-width: 0; }
.card .c-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .c-sub { font-size: 13px; color: var(--muted); margin-top: 3px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.card .c-sum { font-weight: 650; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tag { font-size: 11px; padding: 1px 7px; border-radius: 9px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.tag.pend { background: #f6ead2; color: #8a6416; }
.unread { width: 9px; height: 9px; border-radius: 50%; background: #e0342f; flex: none; }
.empty { text-align: center; color: var(--faint); padding: 50px 20px; line-height: 1.5; }
.fab { position: fixed; right: 18px; bottom: calc(20px + var(--sb)); width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--accent); color: var(--on-accent); box-shadow: 0 6px 18px var(--shadow); display: flex; align-items: center; justify-content: center; z-index: 6; }
.fab svg { width: 28px; height: 28px; }

/* ---------- смета ---------- */
.sec { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; overflow: hidden; }
.sec-h { display: flex; justify-content: space-between; align-items: baseline; padding: 12px 14px 10px; font-weight: 650; border-bottom: 1px solid var(--line); }
.sec-h b { font-variant-numeric: tabular-nums; }
.row { display: flex; align-items: center; gap: 8px; padding: 11px 10px 11px 14px; border-bottom: 1px solid var(--line); }
.row:last-of-type { border-bottom: 0; }
.row .r-main { flex: 1; min-width: 0; }
.row .r-name { font-size: 15px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row .r-sub { font-size: 13px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }
.row .r-sub b { color: var(--text); font-weight: 600; }
.row.flash { animation: flash 1.2s; }
@keyframes flash { 0%, 40% { background: var(--accent-soft); } }
.step { display: flex; align-items: center; border: 1px solid var(--line-strong); border-radius: 10px; overflow: hidden; flex: none; }
.step button { width: 36px; height: 36px; border: 0; background: var(--input); font-size: 20px; color: var(--accent); padding: 0; }
.step button:active { background: var(--side); }
.step span { min-width: 34px; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 15px; padding: 0 2px; }
.add-row { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; border-top: 1px solid var(--line); background: none; color: var(--accent); font-weight: 600; padding: 13px 14px; text-align: left; }
.add-row svg { width: 20px; height: 20px; }
.sec-empty { color: var(--faint); padding: 12px 14px; font-size: 14px; }
.total { position: fixed; left: 0; right: 0; bottom: 0; z-index: 6; display: flex; align-items: center; justify-content: space-between; padding: 12px 18px calc(12px + var(--sb)); background: var(--panel); border-top: 1px solid var(--line); box-shadow: 0 -4px 14px rgba(0,0,0,.05); }
.total span { color: var(--muted); font-size: 14px; }
.total b { font-size: 22px; font-variant-numeric: tabular-nums; }
.ro-note { background: var(--accent-soft); color: var(--accent); border-radius: 11px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px; }
.state { font-size: 12px; color: var(--muted); margin: 0 4px 10px; }

/* ---------- нижние листы ---------- */
.sheet { position: fixed; inset: 0; z-index: 20; display: flex; align-items: flex-end; }
.sheet-back { position: absolute; inset: 0; background: var(--overlay); animation: fade .15s; }
.sheet-box { position: relative; width: 100%; max-height: 88vh; max-height: 88dvh; overflow-y: auto; background: var(--bg); border-radius: 18px 18px 0 0; padding: 8px 16px calc(16px + var(--sb)); animation: up .2s ease-out; }
.sheet-box::before { content: ''; display: block; width: 40px; height: 5px; border-radius: 3px; background: var(--line-strong); margin: 0 auto 12px; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
.sheet h3 { margin: 0 0 14px; font-size: 18px; }
.two { display: flex; gap: 10px; } .two .field { flex: 1; }
.btns { display: flex; gap: 10px; margin-top: 6px; } .btns .btn { flex: 1; }
.pick { list-style: none; margin: 0 0 8px; padding: 0; }
.pick li { display: flex; align-items: center; gap: 10px; padding: 12px 4px; border-bottom: 1px solid var(--line); }
.pick li:active { background: var(--side); }
.pick .p-name { flex: 1; min-width: 0; font-size: 15px; line-height: 1.3; }
.pick .p-price { color: var(--muted); font-size: 14px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pick li.free .p-name { color: var(--accent); font-weight: 600; }
.menu { list-style: none; margin: 0; padding: 0; }
.menu li { padding: 14px 4px; border-bottom: 1px solid var(--line); font-size: 16px; }
.menu li.danger { color: var(--danger); }
.menu li:last-child { border-bottom: 0; }
.muted { color: var(--muted); font-size: 14px; }

/* ---------- чат ---------- */
.chat { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.chat-list { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 8px; -webkit-overflow-scrolling: touch; }
.msg { max-width: 84%; align-self: flex-start; }
.msg.mine { align-self: flex-end; }
.msg-h { font-size: 11.5px; color: var(--muted); margin: 0 6px 2px; }
.msg.mine .msg-h { text-align: right; }
.msg-t { background: var(--panel); border: 1px solid var(--line); padding: 8px 11px; border-radius: 14px 14px 14px 4px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.38; user-select: text; }
.msg.mine .msg-t { background: var(--accent); border-color: var(--accent); color: var(--on-accent); border-radius: 14px 14px 4px 14px; }
.msg-img { width: 230px; max-width: 100%; border-radius: 14px; background: var(--side); overflow: hidden; }
.msg-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg-img + .msg-t { margin-top: 4px; }
.msg-v { display: flex; align-items: center; gap: 9px; background: var(--panel); border: 1px solid var(--line); padding: 6px 12px 6px 6px; border-radius: 22px; min-width: 200px; }
.msg.mine .msg-v { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.vplay { width: 34px; height: 34px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; font-size: 12px; flex: none; padding: 0; }
.msg.mine .vplay { background: #fff; color: var(--accent); }
.vbar { flex: 1; height: 4px; border-radius: 2px; background: rgba(127,127,127,.3); overflow: hidden; }
.vfill { display: block; height: 100%; width: 0; background: currentColor; opacity: .8; }
.vtime { font-size: 12px; font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; }
.msg-c { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); padding: 8px 12px; border-radius: 14px; font-size: 14px; }
.msg-c svg { width: 17px; height: 17px; color: var(--accent); flex: none; }
.msg-c.missed svg { color: #e0342f; }
.chat-in { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--sb)); border-top: 1px solid var(--line); background: var(--bg); }
.chat-in textarea { flex: 1; resize: none; max-height: 120px; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 20px; background: var(--input); outline: none; font-size: 16px; line-height: 1.3; }
.chat-in .ib { width: 42px; height: 42px; }
.send { width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; flex: none; padding: 0; }
.send svg { width: 20px; height: 20px; }
.rec { display: flex; align-items: center; gap: 10px; padding: 12px 12px calc(12px + var(--sb)); border-top: 1px solid var(--line); background: var(--bg); }
.rec-dot { width: 11px; height: 11px; border-radius: 50%; background: #e0342f; animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec b { font-variant-numeric: tabular-nums; }
.rec .grow { flex: 1; color: var(--muted); font-size: 14px; }
.lightbox { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.lightbox img { max-width: 100vw; max-height: 100vh; }

.toast { position: fixed; left: 50%; bottom: calc(92px + var(--sb)); transform: translateX(-50%); z-index: 70; max-width: calc(100vw - 32px); background: var(--toast); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 20px var(--shadow); text-align: center; }
.toast.bad { background: var(--danger); }

/* ---------- звонок ---------- */
.call { position: fixed; inset: 0; z-index: 50; background: #101315; color: #fff; overflow: hidden; }
.call #callRemote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #101315; }
.call.no-rv #callRemote { opacity: 0; }
.call-avatar { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.call.no-rv .call-avatar { display: flex; }
.call-avatar span, .in-ava span { width: 120px; height: 120px; border-radius: 50%; background: #1d5c55; display: flex; align-items: center; justify-content: center; font-size: 50px; font-weight: 600; text-transform: uppercase; }
.call #callLocal { position: absolute; right: 14px; top: calc(80px + var(--st)); width: 104px; aspect-ratio: 3/4; object-fit: cover; border-radius: 12px; background: #22282b; box-shadow: 0 6px 20px rgba(0,0,0,.4); }
.call.mirror #callLocal { transform: scaleX(-1); }
.call.no-lv #callLocal { display: none; }
.call-info { position: absolute; top: calc(18px + var(--st)); left: 0; right: 0; text-align: center; text-shadow: 0 1px 6px rgba(0,0,0,.7); pointer-events: none; }
#callPeer { font-size: 19px; font-weight: 600; }
#callStatus { font-size: 14px; opacity: .85; margin-top: 3px; font-variant-numeric: tabular-nums; }
.call-bar { position: absolute; left: 0; right: 0; bottom: calc(26px + var(--sb)); display: flex; justify-content: center; gap: 18px; }
.cbtn { width: 60px; height: 60px; border-radius: 50%; border: 0; background: rgba(255,255,255,.18); color: #fff; display: flex; align-items: center; justify-content: center; padding: 0; }
.cbtn svg { width: 27px; height: 27px; }
.slash { display: none; }
.cbtn.off { background: #fff; color: #101315; }
.cbtn.off .slash { display: inline; }
.cbtn.hang { background: #e0342f; }
.cbtn.hang svg { width: 32px; height: 32px; }
.cbtn.ok { background: #2fa84f; }
.cbtn:disabled { opacity: .35; }
.incoming { position: fixed; left: 10px; right: 10px; top: calc(10px + var(--st)); z-index: 55; background: #1b2023; color: #fff; border-radius: 20px; padding: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px; box-shadow: 0 14px 44px rgba(0,0,0,.4); animation: up .2s ease-out; }
.in-ava span { width: 50px; height: 50px; font-size: 22px; animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(47,168,79,.6); } 70% { box-shadow: 0 0 0 14px rgba(47,168,79,0); } 100% { box-shadow: 0 0 0 0 rgba(47,168,79,0); } }
.in-text { flex: 1; min-width: 0; }
#inName { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#inSub { font-size: 13px; opacity: .7; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.in-btns { display: flex; gap: 10px; width: 100%; justify-content: space-around; }
.in-btns .cbtn { width: 56px; height: 56px; }

@media (min-width: 700px) {
  .content, .bar > .wrap { max-width: 720px; margin: 0 auto; width: 100%; }
  .sheet { align-items: center; justify-content: center; }
  .sheet-box { max-width: 520px; border-radius: 18px; }
  .incoming { left: 50%; right: auto; width: 420px; transform: translateX(-50%); }
}
.gap { margin-top: 16px; }
