/* СтройАгент — мобильный интерфейс в первую очередь */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --text: #17212e;
  --muted: #5f6b7a;
  --border: #e1e6ee;
  --primary: #1f4e8c;
  --primary-ink: #ffffff;
  --accent: #ee7d1e;
  --accent-ink: #ffffff;
  --ok: #1f7a3a;
  --ok-bg: #dcf2e3;
  --warn: #8a5a00;
  --warn-bg: #fff1cc;
  --bad: #b3261e;
  --bad-bg: #fbe0de;
  --info: #1f4e8c;
  --info-bg: #e3edfb;
  --run: #6a3fb5;
  --run-bg: #ece4fb;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 14px;
  --nav-h: 64px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1420;
    --surface: #152033;
    --surface-2: #1a273d;
    --text: #e7ecf3;
    --muted: #9aa8bb;
    --border: #26354f;
    --primary: #7fb2ff;
    --primary-ink: #0d1420;
    --accent: #ff9a45;
    --accent-ink: #1b1204;
    --ok: #7fd89a;
    --ok-bg: #16351f;
    --warn: #ffd27a;
    --warn-bg: #3a2c0a;
    --bad: #ff9b93;
    --bad-bg: #3d1614;
    --info: #9cc3ff;
    --info-bg: #16284a;
    --run: #c9a8ff;
    --run-bg: #2b1d49;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  padding-bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: .2rem 0 .8rem; line-height: 1.2; }
h2 { font-size: 1.15rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
.icon { width: 22px; height: 22px; flex: none; }
.icon-sm { width: 18px; height: 18px; flex: none; vertical-align: -3px; }

/* каркас */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--primary); color: var(--primary-ink);
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; display: flex; align-items: center; gap: 10px;
}
.topbar a:not(.chip) { color: var(--primary-ink); }
.topbar .brand { font-weight: 700; letter-spacing: .2px; display: flex; gap: 8px; align-items: center; }
.topbar .spacer { flex: 1; }
.topbar .back { display: inline-flex; align-items: center; }
main { max-width: 1100px; margin: 0 auto; padding: 14px 16px 24px; }
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: var(--surface);
  border-top: 1px solid var(--border); display: flex; justify-content: space-around; align-items: stretch;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: var(--muted); font-size: .72rem; text-decoration: none; position: relative;
}
.bottomnav a.active { color: var(--primary); font-weight: 600; }
.bottomnav a.fab .fab-circle {
  width: 48px; height: 48px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: flex; align-items: center; justify-content: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(238,125,30,.4);
}
.badge {
  position: absolute; top: 6px; left: 55%; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--bad); color: #fff; font-size: .7rem; line-height: 18px; text-align: center; font-weight: 700;
}
.sidebar { display: none; }
@media (min-width: 900px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .layout { display: grid; grid-template-columns: 232px 1fr; min-height: calc(100vh - 52px); }
  .sidebar {
    display: flex; flex-direction: column; gap: 2px; padding: 16px 10px; border-right: 1px solid var(--border);
    background: var(--surface); position: sticky; top: 52px; height: calc(100vh - 52px);
  }
  .sidebar a {
    display: flex; gap: 10px; align-items: center; padding: 10px 12px; border-radius: 10px; color: var(--text);
    text-decoration: none; position: relative;
  }
  .sidebar a.active, .sidebar a:hover { background: var(--info-bg); color: var(--primary); }
  .sidebar .badge { position: static; margin-left: auto; }
  .sidebar .cta { background: var(--accent); color: var(--accent-ink); font-weight: 600; margin: 6px 0 10px; }
  .sidebar .cta:hover { background: var(--accent); color: var(--accent-ink); filter: brightness(1.05); }
  main { padding: 22px 28px 40px; }
}

/* элементы */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; margin: 10px 0; }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { text-decoration: none; border-color: var(--primary); }
.grid { display: grid; gap: 10px; }
@media (min-width: 640px) { .grid-2 { grid-template-columns: 1fr 1fr; } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.grid-4 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr; }
@media (min-width: 640px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } }
.row { display: flex; gap: 10px; align-items: center; }
.row-wrap { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.between { justify-content: space-between; }
.stack > * + * { margin-top: 8px; }
.tile { display: flex; flex-direction: column; gap: 6px; padding: 14px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none; min-height: 104px; }
.tile:hover { border-color: var(--primary); text-decoration: none; }
.tile .t-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--info-bg); color: var(--primary); }
.tile.accent .t-icon { background: var(--accent); color: var(--accent-ink); }
.tile b { font-size: .98rem; }
.tile small { line-height: 1.3; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); border-radius: 12px; padding: 11px 16px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 44px;
}
.btn:hover { text-decoration: none; filter: brightness(.98); }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-accent { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn-danger { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.btn-ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; min-height: 34px; font-size: .88rem; border-radius: 10px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.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-info { background: var(--info-bg); color: var(--info); }
.chip-run { background: var(--run-bg); color: var(--run); }
.chip-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.sev-high { background: var(--bad-bg); color: var(--bad); }
.sev-mid { background: var(--warn-bg); color: var(--warn); }
.sev-low { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

.alert { border-radius: 12px; padding: 12px 14px; margin: 10px 0; border: 1px solid transparent; }
.alert-info { background: var(--info-bg); color: var(--info); }
.alert-ok, .alert-success { background: var(--ok-bg); color: var(--ok); }
.alert-warn, .alert-warning { background: var(--warn-bg); color: var(--warn); }
.alert-bad, .alert-error { background: var(--bad-bg); color: var(--bad); }

label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type=text], input[type=password], input[type=date], input[type=number], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 11px 12px; min-height: 44px;
}
textarea { min-height: 150px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); margin: 6px 0; font-weight: 400; cursor: pointer; }
.check input { width: 20px; height: 20px; margin-top: 2px; flex: none; }
.hint { font-size: .86rem; color: var(--muted); margin-top: 4px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin: 8px 0 4px; scrollbar-width: none; }
.tabs a { padding: 8px 14px; border-radius: 999px; background: var(--surface); border: 1px solid var(--border); color: var(--text); white-space: nowrap; text-decoration: none; font-weight: 600; font-size: .92rem; }
.tabs a.active { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }

.list { list-style: none; margin: 0; padding: 0; }
.list li { padding: 10px 0; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.item-title { font-weight: 600; }
.meta { font-size: .84rem; color: var(--muted); }
.meta.check-note, .check-note { color: var(--bad); }
.doc { display: flex; gap: 10px; align-items: center; }
.doc .ext { font-size: .7rem; font-weight: 800; text-transform: uppercase; width: 42px; height: 42px; border-radius: 10px; display: flex; align-items: center; justify-content: center; background: var(--info-bg); color: var(--primary); flex: none; }
.doc .ext.xlsx, .doc .ext.xlsm { background: var(--ok-bg); color: var(--ok); }
.doc .ext.pdf { background: var(--bad-bg); color: var(--bad); }
.doc .ext.docx, .doc .ext.doc { background: var(--info-bg); color: var(--info); }
.doc .ext.img { background: var(--warn-bg); color: var(--warn); }
.doc .body { flex: 1; min-width: 0; }
.doc .body a { word-break: break-word; }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 76px; height: 76px; object-fit: cover; border-radius: 10px; border: 1px solid var(--border); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
table.t { border-collapse: collapse; width: 100%; font-size: .9rem; }
table.t th, table.t td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.t th { background: var(--surface-2); font-size: .8rem; color: var(--muted); font-weight: 700; position: sticky; top: 0; }
table.t td.num, table.t th.num { text-align: right; white-space: nowrap; }
.finding { border-left: 4px solid var(--border); padding: 10px 12px; margin: 8px 0; background: var(--surface); border-radius: 10px; border-top: 1px solid var(--border); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.finding.sev-high { border-left-color: var(--bad); background: var(--surface); color: var(--text); }
.finding.sev-mid { border-left-color: var(--accent); background: var(--surface); color: var(--text); }
.finding.sev-low { border-left-color: var(--muted); background: var(--surface); color: var(--text); }
.finding .f-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }
.stat { text-align: center; padding: 12px 8px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); }
.stat b { display: block; font-size: 1.5rem; }
.headline { font-size: 1.02rem; font-weight: 600; }
.quote { border-left: 3px solid var(--border); padding-left: 10px; color: var(--muted); font-style: italic; margin: 6px 0; }
.chat { display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--primary); color: var(--primary-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-form { position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 6px); background: var(--bg); padding: 8px 0; }
@media (min-width: 900px) { .chat-form { bottom: 0; } }
.chat-form textarea { min-height: 52px; height: 52px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-flex; }
.progress-card { display: flex; gap: 14px; align-items: center; }
.pulse { width: 14px; height: 14px; border-radius: 50%; background: var(--run); animation: pulse 1.2s ease-in-out infinite; flex: none; }
@keyframes pulse { 0%,100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1.1); } }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }
.login-wrap { max-width: 400px; margin: 8vh auto 0; padding: 0 16px; }
.logo-big { width: 64px; height: 64px; border-radius: 16px; background: var(--primary); color: var(--primary-ink); display: flex; align-items: center; justify-content: center; margin: 0 auto 12px; }
details summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
.kpi { font-size: 1.3rem; font-weight: 700; }
.hide-mobile { display: none; }
@media (min-width: 900px) { .hide-mobile { display: initial; } .hide-desktop { display: none; } }

/* подсказка «установить как приложение» */
.install { display: flex; align-items: center; gap: 10px; background: var(--info-bg); color: var(--info); border-radius: 12px; padding: 10px 12px; margin: 10px 0; }
.install[hidden], .install [hidden] { display: none !important; }
.install-text { flex: 1; min-width: 0; font-size: .92rem; line-height: 1.4; }
.install-text b { display: block; }
.install-close { background: none; border: 0; color: inherit; font-size: 1.5rem; line-height: 1; padding: 4px 6px; cursor: pointer; }

/* счёт на оплату: таблица банковских реквизитов и печать без меню */
.invoice .inv-bank { width: 100%; border-collapse: collapse; font-size: .9rem; }
.invoice .inv-bank td { border: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }
@media print {
  /* на бумаге всегда тёмный текст на белом, даже если на телефоне тёмная тема */
  :root { --bg: #fff; --surface: #fff; --surface-2: #fff; --text: #000; --muted: #333; --border: #777; color-scheme: light; }
  body { background: #fff; color: #000; padding-bottom: 0; }
  .topbar, .sidebar, .bottomnav, .no-print, .alert { display: none !important; }
  .layout { display: block !important; }
  main { padding: 0 !important; }
  .card { box-shadow: none !important; border: none !important; }
}
