/* Кабинет — светлая деловая тема (мобайл-first). Тёплые нейтрали, спокойный синий. */
:root {
  --bg:        #F6F6F4;          /* тёплый off-white фон */
  --surface:   #FFFFFF;
  --surface-2: #FBFBFA;
  --ink:       #1A1B1E;          /* графит, не чёрный */
  --ink-2:     #5C6168;          /* вторичный текст */
  --ink-3:     #8A9099;          /* подписи */
  --line:      rgba(20, 22, 26, 0.10);
  --line-2:    rgba(20, 22, 26, 0.06);

  --accent:     #2563EB;         /* спокойный синий */
  --accent-ink: #1D4ED8;
  --accent-bg:  #EAF0FE;
  --ok:         #059669;         /* прибыль/успех */
  --ok-bg:      #E7F5EF;
  --warn:       #D97706;         /* близко к бюджету */
  --warn-bg:    #FCF1E2;
  --bad:        #DC2626;         /* перерасход/убыток */
  --bad-bg:     #FCEAEA;
  --info-bg:    #EEF2F6;

  /* категории разбивки */
  --cat-1: #2563EB; --cat-2: #0EA5E9; --cat-3: #059669; --cat-4: #D97706; --cat-5: #8B5CF6;

  --r-s: 10px; --r-m: 14px; --r-l: 20px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;
  --shadow-1: 0 1px 2px rgba(20,22,26,0.05);
  --shadow-2: 0 8px 24px -10px rgba(20,22,26,0.18);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --topbar-h: 54px; --tabbar-h: 62px;
  --maxw: 640px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }  /* иначе display из .lightbox/.topbar__back перебивает атрибут */
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 16px; color: var(--ink); }
.ic { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- каркас ---------- */
.app { max-width: var(--maxw); margin: 0 auto; min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--sp-2);
  height: var(--topbar-h); padding: 0 var(--sp-4);
  background: rgba(246,246,244,0.86); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line-2);
}
.topbar__back { display: grid; place-items: center; width: 36px; height: 36px; margin-left: -6px; border-radius: 50%; color: var(--ink); }
.topbar__back:active { background: var(--info-bg); }
.topbar__name { font-weight: 700; font-size: 17px; letter-spacing: -0.01em; }
.topbar__sub { font-size: 12px; color: var(--ink-3); margin-top: -1px; }

.screens { position: relative; padding-bottom: calc(var(--tabbar-h) + 80px); }
.screen { display: none; padding: var(--sp-4); }
.screen[data-screen="chat"] { padding: 0; }
.app[data-screen="portfolio"] .screen[data-screen="portfolio"],
.app[data-screen="object"]    .screen[data-screen="object"],
.app[data-screen="chat"]      .screen[data-screen="chat"] { display: block; }

/* таб-бар и FAB прячем в детали/чате где не нужно */
.app[data-screen="object"] .tabbar,
.app[data-screen="chat"] .fab,
.app[data-screen="object"] .fab { display: none; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  max-width: var(--maxw); margin: 0 auto;
  display: grid; grid-template-columns: 1fr 1fr;
  height: var(--tabbar-h); padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,0.92); backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.tabbar__btn { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--ink-3); font-size: 11px; font-weight: 600; }
.tabbar__btn.is-active { color: var(--accent); }
.tabbar__btn .ic { width: 22px; height: 22px; }

.fab {
  position: fixed; z-index: 21; right: max(16px, calc((100vw - var(--maxw))/2 + 16px));
  bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom));
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  box-shadow: 0 10px 24px -6px rgba(37,99,235,0.5);
}
.fab .ic { width: 26px; height: 26px; stroke-width: 2.4; }
.fab:active { transform: scale(0.94); }

/* ---------- общие элементы ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); box-shadow: var(--shadow-1); }
.section-title { font-size: 13px; font-weight: 700; color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.04em; margin: var(--sp-5) var(--sp-1) var(--sp-2); }
.muted { color: var(--ink-3); }
.empty { text-align: center; color: var(--ink-3); padding: 48px 24px; }
.empty__big { font-size: 15px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
.row { display: flex; align-items: center; gap: var(--sp-3); }
.row--between { justify-content: space-between; }
.spacer { flex: 1; }
.reveal { opacity: 1; }
.reveal.is-pending { opacity: 0; transform: translateY(8px); }

.chip { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--info-bg); color: var(--ink-2); }
.chip--ok { background: var(--ok-bg); color: var(--ok); }
.chip--warn { background: var(--warn-bg); color: var(--warn); }
.chip--bad { background: var(--bad-bg); color: var(--bad); }
.chip--accent { background: var(--accent-bg); color: var(--accent-ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 600; font-size: 14px; padding: 11px 16px; border-radius: var(--r-s); background: var(--info-bg); color: var(--ink); transition: transform .08s; }
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--accent); color: #fff; }
.btn--ghost { background: transparent; border: 1px solid var(--line); }
.btn--danger { background: var(--bad-bg); color: var(--bad); }
.btn--full { width: 100%; }
.btn--sm { padding: 7px 12px; font-size: 13px; }
.btn .ic { width: 17px; height: 17px; }
.iconbtn { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 8px; color: var(--ink-2); }
.iconbtn:active { background: var(--info-bg); }
.iconbtn--danger { color: var(--bad); }

/* ---------- портфель ---------- */
.portfolio__head { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); }
.stat { flex: 1; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-m); padding: var(--sp-3) var(--sp-4); }
.stat__num { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; }
.stat__lbl { font-size: 12px; color: var(--ink-3); }

.obj-card { padding: var(--sp-4); margin-bottom: var(--sp-3); display: block; width: 100%; text-align: left; }
.obj-card__top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.obj-card__name { font-size: 16px; font-weight: 700; letter-spacing: -0.01em; }
.obj-card__money { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-top: var(--sp-3); }
.obj-card__money small { font-size: 12px; font-weight: 600; color: var(--ink-3); display: block; letter-spacing: 0; }
.obj-card__foot { display: flex; align-items: center; gap: var(--sp-3); margin-top: var(--sp-3); }

.ring { --val: 0; --col: var(--accent); width: 46px; height: 46px; flex: none; position: relative; }
.ring svg { transform: rotate(-90deg); }
.ring__bg { stroke: var(--line); }
.ring__fg { stroke: var(--col); transition: stroke-dasharray .5s ease; }
.ring__txt { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 700; }

/* ---------- объект (детали) ---------- */
.obj-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-3); }
.obj-head__name { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.subtabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: var(--sp-2); margin: 0 calc(-1 * var(--sp-4)) var(--sp-3); padding-left: var(--sp-4); padding-right: var(--sp-4); scrollbar-width: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtab { flex: none; padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); background: var(--surface); border: 1px solid var(--line); }
.subtab.is-active { background: var(--ink); color: #fff; border-color: var(--ink); }

.kpi { padding: var(--sp-4); margin-bottom: var(--sp-3); }
.kpi__main { display: flex; align-items: center; gap: var(--sp-4); }
.kpi__big { font-size: 28px; font-weight: 800; letter-spacing: -0.02em; }
.kpi__lbl { font-size: 12px; color: var(--ink-3); }
.ring--lg { width: 74px; height: 74px; }
.ring--lg .ring__txt { font-size: 15px; }

.bars { margin-top: var(--sp-3); display: flex; flex-direction: column; gap: var(--sp-2); }
.bar__row { display: flex; align-items: center; gap: var(--sp-3); font-size: 13px; }
.bar__name { width: 84px; flex: none; color: var(--ink-2); }
.bar__track { flex: 1; height: 8px; background: var(--line-2); border-radius: 999px; overflow: hidden; }
.bar__fill { height: 100%; border-radius: 999px; }
.bar__val { width: 92px; flex: none; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.kv { display: flex; justify-content: space-between; padding: 11px 0; border-bottom: 1px solid var(--line-2); font-size: 14px; }
.kv:last-child { border-bottom: none; }
.kv__k { color: var(--ink-2); }
.kv__v { font-weight: 600; font-variant-numeric: tabular-nums; }
.kv__v--ok { color: var(--ok); } .kv__v--bad { color: var(--bad); }
.padded { padding: var(--sp-2) var(--sp-4); }

.list-item { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-2); }
.list-item:last-child { border-bottom: none; }
.list-item__body { flex: 1; min-width: 0; }
.list-item__title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item__sub { font-size: 12px; color: var(--ink-3); }
.list-item__amt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.stage { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--line-2); }
.stage:last-child { border-bottom: none; }
.stage__dot { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.stage__dot--pending { background: var(--info-bg); color: var(--ink-3); }
.stage__dot--in_progress { background: var(--accent-bg); color: var(--accent); }
.stage__dot--done { background: var(--ok-bg); color: var(--ok); }
.stage__dot .ic { width: 15px; height: 15px; }
.stage__name { flex: 1; font-weight: 600; font-size: 14px; }
.stage__flag { font-size: 11px; color: var(--warn); }

/* галерея */
.gallery-group { margin-bottom: var(--sp-4); }
.gallery-group__head { display: flex; justify-content: space-between; align-items: center; margin: 0 var(--sp-1) var(--sp-2); }
.gallery-group__name { font-weight: 600; font-size: 14px; }
.thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: var(--r-s); overflow: hidden; background: var(--info-bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb__del { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; background: rgba(0,0,0,0.5); color: #fff; display: grid; place-items: center; }
.thumb__del .ic { width: 15px; height: 15px; }

/* ---------- чат ---------- */
.chat-log { padding: var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); min-height: calc(100dvh - var(--topbar-h) - 70px - var(--tabbar-h)); }
.msg { max-width: 84%; padding: 10px 14px; border-radius: 16px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; }
.msg--user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg--bot { align-self: flex-start; background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 5px; }
.msg--typing { color: var(--ink-3); font-style: italic; }
.chat-hint { text-align: center; color: var(--ink-3); font-size: 13px; padding: 24px; }
.chat-bar {
  position: fixed; left: 0; right: 0; z-index: 19;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));  /* над таб-баром, не под ним */
  max-width: var(--maxw); margin: 0 auto;
  display: flex; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4);
  background: rgba(255,255,255,0.97); backdrop-filter: blur(12px); border-top: 1px solid var(--line);
}
.chat-input { flex: 1; padding: 11px 16px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface-2); outline: none; resize: none; font-family: inherit; line-height: 1.4; max-height: 120px; overflow-y: auto; caret-color: var(--accent); }
.chat-input:focus { border-color: var(--accent); background: var(--surface); }
.chat-attach { width: 40px; height: 40px; flex: none; align-self: flex-end; border-radius: 50%; color: var(--ink-3); display: grid; place-items: center; }
.chat-attach:active { background: var(--info-bg); }
.chat-send { width: 44px; height: 44px; flex: none; align-self: flex-end; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; }
.proposal { align-self: flex-start; max-width: 92%; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; border-bottom-left-radius: 5px; padding: 12px 14px; }
.proposal__preview { font-size: 14px; line-height: 1.5; white-space: pre-wrap; margin-bottom: 10px; }
.proposal__actions { display: flex; gap: 8px; }
.proposal__actions .btn { flex: 1; }
.proposal.is-resolved { opacity: 0.6; }
.proposal.is-resolved .proposal__actions { display: none; }
.chat-send:active { transform: scale(0.94); }

/* ---------- bottom sheet / модалки ---------- */
.sheet-backdrop { position: fixed; inset: 0; z-index: 40; background: rgba(20,22,26,0.4); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: var(--maxw); max-height: 92dvh; overflow-y: auto; background: var(--surface); border-radius: var(--r-l) var(--r-l) 0 0; padding: var(--sp-5) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom)); }
.sheet__grip { width: 36px; height: 4px; border-radius: 999px; background: var(--line); margin: 0 auto var(--sp-4); }
.sheet__title { font-size: 18px; font-weight: 800; margin-bottom: var(--sp-4); }
.field { margin-bottom: var(--sp-4); }
.field__label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.field__input, .field__select { width: 100%; padding: 12px 14px; border-radius: var(--r-s); border: 1px solid var(--line); background: var(--surface-2); outline: none; }
.field__input:focus, .field__select:focus { border-color: var(--accent); background: var(--surface); }
.field__hint { font-size: 12px; color: var(--ink-3); margin-top: 5px; }
.field-row { display: flex; gap: var(--sp-3); }
.field-row > * { flex: 1; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg__opt { padding: 9px 14px; border-radius: 999px; border: 1px solid var(--line); font-size: 13px; font-weight: 600; color: var(--ink-2); background: var(--surface-2); }
.seg__opt.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }
.sheet__actions { display: flex; gap: var(--sp-3); margin-top: var(--sp-5); }
.sheet__actions .btn { flex: 1; }
.preview-box { background: var(--info-bg); border-radius: var(--r-m); padding: var(--sp-4); margin-bottom: var(--sp-4); }

/* ---------- прочее ---------- */
.toast { position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + 24px); translate: -50% 0; transform: translateY(20px); z-index: 60; max-width: 88%; background: var(--ink); color: #fff; font-size: 13px; font-weight: 500; padding: 11px 18px; border-radius: 999px; box-shadow: var(--shadow-2); opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; }
.toast.is-show { opacity: 1; transform: translateY(0); }
.toast--bad { background: var(--bad); }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,0.92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: var(--r-s); }
.skeleton { background: linear-gradient(90deg, var(--line-2), var(--info-bg), var(--line-2)); background-size: 200% 100%; border-radius: var(--r-m); animation: sk 1.3s infinite; }
@keyframes sk { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.sk-card { height: 116px; margin-bottom: var(--sp-3); }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
  .reveal.is-pending { opacity: 1; transform: none; }
}
