/* The app's own layout: the shell, the top bar, the list, the empty state, the detail and editor pages, the floating button, the settings sheet. */

/* The shell is as tall as the VISIBLE area (--app-h) and starts where it starts (--app-top). js/viewport.js writes both from innerHeight and
   visualViewport, not from Telegram's --tg-viewport-height: on iOS the keyboard shrinks the window or overlays it, and this follows either. */
#app { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100%); display: flex; flex-direction: column; background: var(--bg); }
#view { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* A screen arriving. animation-fill-mode is "backwards" on purpose: a finished animation of transform kept by "forwards"/"both" would stay the containing
   block of position: fixed children (the floating button, verified in Chrome and WebKit). The root screen holds the fixed button, so it only fades. */
.screen.push { animation: push var(--d3) var(--ease) backwards; }
.screen.fade { animation: fade var(--d2) var(--ease) backwards; }
@keyframes push { from { opacity: 0; transform: translateX(28px); } }
@keyframes fade { from { opacity: 0; } }

.bar { flex: none; display: flex; align-items: center; gap: var(--s2); min-height: calc(var(--bar-h) + var(--sat)); background: var(--bg); border-bottom: 1px solid var(--line);
  padding: var(--sat) calc(var(--sar) + var(--s3)) 0 calc(var(--sal) + var(--s4)); }
.bar.has-back { padding-left: calc(var(--sal) + var(--s2)); }
.bar h1 { flex: 1; min-width: 0; font-size: var(--t-title); font-weight: 700; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip { display: inline-flex; align-items: center; gap: var(--s2); max-width: 55%; min-height: 44px; padding: 0 var(--s3) 0 var(--s1); border-radius: var(--r-pill); }
.user-chip span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--t-sm); font-weight: 600; }
.avatar { width: 32px; height: 32px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); font-size: var(--t-sm); font-weight: 700; }
@media (hover: hover) { .user-chip:hover { background: var(--surface-2); } }

.scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.page { width: 100%; max-width: var(--column); margin: 0 auto; display: grid; gap: var(--s4); align-content: start;
  padding: var(--s4) calc(var(--sar) + var(--s4)) calc(var(--fab) + var(--s7) + var(--sab)) calc(var(--sal) + var(--s4)); }

/* ---- home: the list and its states (loading, error, empty, loaded) */
.list-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 40px; }
.list-head h2 { font-size: var(--t-sm); font-weight: 600; color: var(--muted); }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 64px; padding: var(--s3) var(--s4); text-align: left; border-radius: var(--r-l);
  background: var(--surface); border: 1px solid var(--line); transition: transform var(--d1) var(--ease), background var(--d1); }
.row:active { transform: scale(.99); }
.row-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.row-text { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; font-weight: 500; }
.row-meta { font-size: var(--t-meta); color: var(--muted); }
.row > svg { color: var(--muted); }
@media (hover: hover) { .row:hover { background: var(--surface-2); } }
.skel-row { height: 64px; }
.empty, .notice { display: grid; justify-items: center; gap: var(--s3); text-align: center; padding: var(--s8) var(--s4); }
.empty .mark { --size: 88px; border-radius: 28px; }
.empty h2, .notice h2 { font-size: var(--t-title); line-height: 1.25; }
.empty p, .notice p { color: var(--muted); max-width: 340px; overflow-wrap: anywhere; }
.build { text-align: center; font-size: var(--t-cap); color: var(--muted); }
.build code { font-family: var(--mono); }
.fab { position: fixed; z-index: 5; bottom: calc(var(--kb, 0px) + var(--sab) + var(--s4)); right: max(calc(var(--sar) + var(--s4)), calc((100vw - var(--column)) / 2 + var(--s4)));
  min-height: var(--fab); padding: 0 var(--s6) 0 var(--s5); border-radius: var(--r-pill); box-shadow: var(--shadow); }

html[data-kb] .fab, html[data-kb] .build { display: none; }      /* data-kb is set while a keyboard is up (viewport.js): with it there is room only for the field and its buttons */

/* ---- detail and editor */
.note { padding: var(--s5); border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); font-size: 18px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { font-size: var(--t-sm); color: var(--muted); }

/* ---- settings sheet */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 2px; padding: 2px; border-radius: var(--r-m); background: var(--surface-2); }
.seg button { min-height: 40px; border-radius: 10px; font-size: var(--t-sm); font-weight: 600; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.kv { display: grid; gap: var(--s2); margin: 0; font-size: var(--t-sm); }
.kv > div { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s4); }
.kv dt { color: var(--muted); flex: none; }
.kv dd { margin: 0; min-width: 0; text-align: right; overflow-wrap: anywhere; }
.section-label { font-size: var(--t-meta); font-weight: 600; color: var(--muted); }

/* ======================================================================== Perspektiva: the screens of the construction app */

/* ---- top bar: the brand on the main screens (the page title is the big heading under it) */
.bar-brand { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--s2); font-weight: 700; font-size: var(--t-body); color: var(--accent); }
.bar-brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.hero { font-size: 24px; line-height: 1.2; font-weight: 800; letter-spacing: -.01em; text-wrap: balance; }
.hero:focus-visible { outline: none; }

/* ---- layout helpers */
.stack { display: grid; gap: var(--s4); align-content: start; min-width: 0; }
.stack.tight { gap: var(--s2); }
.grow { flex: 1; min-width: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); align-items: start; }
.grid3 { display: grid; grid-template-columns: 1fr 1.6fr .9fr; gap: var(--s3); align-items: start; }
.grid2 > *, .grid3 > * { min-width: 0; }
.cta { display: grid; gap: var(--s2); }
.center { text-align: center; }
.hint { font-size: var(--t-sm); color: var(--muted); }
.hint:empty { display: none; }
.field-row { min-height: 0; }
.hint.bad, .bad { color: var(--danger); }
.good { color: var(--good); }
.field-hint { color: var(--muted); }
.section-title { font-size: var(--t-sm); font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: var(--s2); }
.day { font-size: var(--t-meta); font-weight: 700; color: var(--muted); margin: var(--s2) 0 calc(var(--s2) * -1 + 2px); }
.bullets { margin: 0; padding-left: var(--s5); display: grid; gap: var(--s1); font-size: var(--t-sm); }

/* ---- cards and sections */
.card { display: grid; gap: var(--s3); padding: var(--s4); border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.card.warn { background: var(--danger-soft); border-color: transparent; }
.card-title { font-size: var(--t-body); font-weight: 700; overflow-wrap: anywhere; }

/* ---- the numbers at the top of a screen */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.stat { display: grid; gap: 2px; padding: var(--s3) var(--s4); border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); min-width: 0; }
.stat.wide { grid-column: 1 / -1; }
.stat-label { font-size: var(--t-meta); color: var(--muted); font-weight: 600; }
.stat-value { font-size: 22px; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat.wide .stat-value { font-size: 28px; }
.stat.good .stat-value { color: var(--good); }
.stat.bad .stat-value { color: var(--danger); }

/* ---- lists: a row can carry an amount, a chip, a button */
.row.tall { align-items: flex-start; }
.row.static { cursor: default; }
.row.static:active { transform: none; }
.row-end { display: grid; justify-items: end; gap: 4px; flex: none; }
.row-amount { font-variant-numeric: tabular-nums; white-space: nowrap; font-size: var(--t-sm); }
.row-amount.good { color: var(--good); }
.row-meta.good { color: var(--good); }
.row-meta.bad { color: var(--danger); font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: 2px; }
.chip { display: inline-flex; align-items: center; min-height: 22px; padding: 0 var(--s2); border-radius: var(--r-pill); font-size: var(--t-cap); font-weight: 700; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.good { background: var(--good-soft); color: var(--good); }
.dot { width: 36px; height: 36px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--muted); }
.dot.in { background: var(--good-soft); color: var(--good); }
.dot.out { background: var(--accent-soft); color: var(--accent); }
.banner.action { width: 100%; text-align: left; align-items: center; background: var(--accent-soft); color: var(--text); }
.banner.action svg:first-child { color: var(--accent); }
.banner .btn { flex: none; margin-left: auto; }

/* ---- bottom tab bar */
.tabbar { flex: none; display: grid; grid-template-columns: repeat(5, 1fr); background: var(--surface); border-top: 1px solid var(--line); padding: 0 var(--sar) var(--sab) var(--sal); }
.tab { min-height: var(--tabbar-h); display: grid; gap: 2px; justify-items: center; align-content: center; padding: var(--s2) 0; color: var(--muted); font-size: var(--t-cap); font-weight: 600; min-width: 0; }
.tab span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tab.on { color: var(--accent); }
@media (hover: hover) { .tab:hover { background: var(--surface-2); } }
html[data-kb] .tabbar { display: none; }
.fab-above { bottom: calc(var(--kb, 0px) + var(--sab) + var(--tabbar-h) + var(--s4)); }

/* ---- the bar with the main button of a form */
.foot-bar { flex: none; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) calc(var(--sar) + var(--s4)) calc(var(--s3) + var(--sab)) calc(var(--sal) + var(--s4));
  background: var(--surface); border-top: 1px solid var(--line); }
.screen > .foot-bar:has(+ .tabbar) { padding-bottom: var(--s3); }
.foot-bar .btn { flex: 1; }
.foot-sum { display: grid; gap: 0; flex: none; }
.foot-label { font-size: var(--t-cap); color: var(--muted); font-weight: 600; }
.foot-sum strong { font-size: 18px; font-variant-numeric: tabular-nums; }
html[data-kb] .foot-bar { display: none; }

/* ---- the estimate editor */
.phase { gap: var(--s4); }
.phase-head { display: flex; align-items: flex-start; gap: var(--s3); }
.phase-no { width: 32px; height: 32px; flex: none; margin-top: 26px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.field.days { width: 92px; flex: none; }
.field.narrow { min-width: 0; }
.item { display: grid; gap: var(--s3); padding: var(--s3); border-radius: var(--r-m); background: var(--bg); border: 1px solid var(--line); min-width: 0; }
.item-head { display: flex; align-items: flex-start; gap: var(--s2); }
.item-nums { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: var(--s2); }
.item-nums > * { min-width: 0; }
.item-sum { display: flex; justify-content: space-between; align-items: baseline; font-size: var(--t-sm); color: var(--muted); }
.item-total { color: var(--text); font-size: var(--t-body); font-variant-numeric: tabular-nums; }
.phase-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.suggest { display: flex; flex-wrap: wrap; gap: var(--s2); }
.suggest:empty { display: none; }
.chip-btn { min-height: 36px; padding: 0 var(--s3); border-radius: var(--r-pill); background: var(--accent-soft); color: var(--accent); font-size: var(--t-sm); font-weight: 600; }
.totals { display: grid; gap: var(--s2); padding: var(--s4); border-radius: var(--r-l); background: var(--surface); border: 1px solid var(--line); }
.totals > div { display: flex; justify-content: space-between; font-variant-numeric: tabular-nums; }
.totals .total { font-size: 20px; font-weight: 800; padding-top: var(--s2); border-top: 1px solid var(--line); }
.totals .total strong { color: var(--accent); }

/* ---- "ready" screens */
.ready { display: grid; justify-items: center; gap: var(--s2); text-align: center; padding: var(--s4) 0 var(--s2); }
.ready h2 { font-size: var(--t-title); }
.mark.good { background: var(--good-soft); color: var(--good); }
.mark.warn { background: var(--danger-soft); color: var(--danger); }
.actions { display: grid; gap: var(--s2); }
.actions-row { display: flex; flex-wrap: wrap; gap: var(--s2); }
.actions-row .btn { flex: 1 1 auto; }
.kv .strong { font-weight: 800; padding-top: var(--s2); border-top: 1px solid var(--line); font-size: var(--t-body); }
.kv .strong dt { color: var(--text); }

/* ---- the contract */
.plan-sum { padding: var(--s3) var(--s4); border-radius: var(--r-m); font-size: var(--t-sm); font-weight: 600; }
.plan-sum.ok { background: var(--good-soft); color: var(--good); }
.plan-sum.off { background: var(--danger-soft); color: var(--danger); }
.plan-pct { font-size: var(--t-meta); color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 4px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 48px; }
.switch-text { display: grid; gap: 2px; min-width: 0; }
.switch-text small { color: var(--muted); font-size: var(--t-meta); }
.switch { position: relative; width: 52px; height: 32px; flex: none; border-radius: var(--r-pill); background: var(--border); transition: background var(--d2); }
.switch i { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: var(--surface); transition: transform var(--d2) var(--ease); box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.switch[aria-checked="true"] { background: var(--accent); }
.switch[aria-checked="true"] i { transform: translateX(20px); }

/* ---- cash and profile */
.month-nav { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.month-label { text-transform: capitalize; font-size: var(--t-body); }
.fab-above + .tabbar { position: relative; }
.logo-box { display: flex; align-items: center; gap: var(--s4); }
.logo { flex: none; align-self: center; max-width: 140px; max-height: 64px; border-radius: var(--r-s); object-fit: contain; background: var(--surface-2); }
.logo.empty { width: 64px; height: 64px; display: grid; place-items: center; color: var(--muted); }
.foot-links { text-align: center; font-size: var(--t-sm); padding: var(--s2) 0 var(--s4); }
