/* KTC CRM 0.1 — стиль KTC: тёмно-синий каркас, золотые акценты. Без внешних шрифтов и без inline-стилей (CSP). */
:root {
  --midnight: #101E32; --midnight-2: #1B3050; --cloud: #F4F6FA; --white: #fff;
  --gold: #D5A85A; --gold-600: #C4963F; --teal: #197B87; --text: #202B3B; --muted: #566377;
  --line: #E1E7EF; --danger: #B42318; --ok: #137A3B; --wa: #15803D; --warn: #B7791F;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,30,50,.06), 0 10px 28px -18px rgba(16,30,50,.28);
  --font: Inter, Manrope, system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  --side-w: 248px;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--cloud); }
h1, h2, h3, p, dl, dd, ol, ul { margin: 0; padding: 0; }
ol, ul { list-style: none; }
a { color: var(--teal); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { color: #136571; }
:focus-visible { outline: 3px solid rgba(25,123,135,.55); outline-offset: 2px; }
.skip-link { position: fixed; left: 12px; top: -80px; z-index: 100; padding: 10px 14px; border-radius: 10px; background: var(--midnight); color: #fff; }
.skip-link:focus { top: 12px; }
.strong { font-weight: 700; color: var(--midnight); }
.muted { color: var(--muted); }
.wrap { word-break: break-word; }
.h1 { font-size: 1.5rem; line-height: 1.2; font-weight: 800; letter-spacing: -.02em; color: var(--midnight); }
.h2 { font-size: 1.0625rem; font-weight: 800; letter-spacing: -.01em; color: var(--midnight); margin-bottom: 12px; }
.count { font-size: 1rem; font-weight: 600; }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 4px; }

/* ---------- Каркас ---------- */
.shell { display: block; min-height: 100vh; }
.side { display: none; }
.main { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 56px; padding: 0 16px; background: var(--midnight); color: #fff; }
.topbar__brand { color: #fff; font-weight: 800; text-decoration: none; letter-spacing: -.01em; }
.content { padding: 16px 16px 92px; outline: none; max-width: 1280px; }
.tabbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr); background: var(--midnight); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid rgba(255,255,255,.1); }
.tabbar__link { display: flex; align-items: center; justify-content: center; min-height: 56px; padding: 6px 4px; color: rgba(255,255,255,.75); text-decoration: none; font-size: 13px; font-weight: 700; }
.tabbar__link.is-active { color: var(--gold); box-shadow: inset 0 3px 0 var(--gold); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.hide-sm { display: none !important; }

@media (min-width: 1024px) {
  .shell { display: grid; grid-template-columns: var(--side-w) minmax(0, 1fr); }
  .side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 20px 14px; background: var(--midnight); color: #fff; }
  .topbar, .tabbar { display: none; }
  .content { padding: 28px 32px 48px; }
  .hide-sm { display: inline-flex !important; }
  .h1 { font-size: 1.75rem; }
}
.side__brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; text-decoration: none; font-weight: 800; font-size: 1.0625rem; }
.side__nav { display: grid; gap: 4px; }
.side__link { display: block; padding: 11px 12px; border-radius: 10px; color: rgba(255,255,255,.78); text-decoration: none; font-weight: 600; }
.side__link:hover { background: rgba(255,255,255,.07); color: #fff; }
.side__link.is-active { background: rgba(213,168,90,.16); color: var(--gold); }
.side__user { margin-top: auto; padding: 14px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.side__who { font-weight: 700; }
.side__mail { font-size: 12.5px; color: rgba(255,255,255,.6); word-break: break-all; margin-bottom: 8px; }
.side__logout { padding: 8px 0; border: 0; background: none; color: var(--gold); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Кнопки ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; padding: 10px 18px; border: 1px solid transparent; border-radius: 10px; font: inherit; font-weight: 700; text-decoration: none; cursor: pointer; transition: background-color .2s, border-color .2s, color .2s; }
.btn--gold { background: var(--gold); color: var(--midnight); }
.btn--gold:hover { background: var(--gold-600); color: var(--midnight); }
.btn--ghost { background: var(--white); border-color: #CBD5E1; color: var(--midnight); }
.btn--ghost:hover { border-color: var(--teal); color: var(--teal); }
.btn--wa { background: var(--wa); color: #fff; }
.btn--wa:hover { background: #116B33; color: #fff; }
.btn--danger { background: var(--white); border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { min-height: 36px; padding: 6px 12px; font-size: 13.5px; }
.btn--block { width: 100%; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }

/* ---------- Карточки и сетки ---------- */
.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card--flush { padding: 0; overflow: hidden; }
.card--narrow { max-width: 420px; margin: 8vh auto 0; }
.card--wide { max-width: 720px; }
.card--danger { border-color: rgba(180,35,24,.35); }
.grid2 { display: grid; gap: 14px; }
.grid2 > .card { margin-bottom: 0; }
.cols { display: grid; gap: 14px; }
.cols__main > .card:last-child, .cols__side > .card:last-child { margin-bottom: 0; }
.row2 { display: grid; gap: 12px; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; margin-bottom: 14px; } .cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); align-items: start; } .row2 { grid-template-columns: 1fr 1fr; } }

/* На телефоне блоки карточки заявки идут в удобном порядке: клиент, статус, комментарий, детали, история */
@media (max-width: 899px) {
  .cols { display: flex; flex-direction: column; }
  .cols__main, .cols__side { display: contents; }
  .cols .card { margin-bottom: 0; }
  .o1 { order: 1; } .o2 { order: 2; } .o3 { order: 3; } .o4 { order: 4; } .o5 { order: 5; } .o6 { order: 6; } .o7 { order: 7; } .o8 { order: 8; }
}

/* ---------- Показатели ---------- */
.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.kpi { display: flex; flex-direction: column; gap: 2px; padding: 14px; border-radius: var(--radius); background: var(--midnight); color: #fff; text-decoration: none; box-shadow: var(--shadow); }
a.kpi:hover { background: var(--midnight-2); color: #fff; }
.kpi__n { font-size: 1.75rem; font-weight: 800; letter-spacing: -.02em; color: var(--gold); line-height: 1.1; }
.kpi__t { font-size: 13px; color: rgba(255,255,255,.78); }
@media (min-width: 900px) { .kpis { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Графики ---------- */
.chart { width: 100%; min-height: 160px; }
.chart svg { display: block; width: 100%; height: auto; }
.chart__axis { stroke: var(--line); stroke-width: 1; }
.chart__line { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-linejoin: round; stroke-linecap: round; }
.chart__area { fill: rgba(25,123,135,.12); }
.chart__dot { fill: var(--teal); }
.chart__label { fill: var(--muted); font-size: 11px; }
.bars { display: grid; gap: 10px; }
.bar { display: grid; gap: 4px; }
.bar__head { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.bar__name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar__track { height: 10px; border-radius: 999px; background: var(--cloud); overflow: hidden; }
.bar__fill { display: block; height: 100%; width: 0; border-radius: 999px; background: linear-gradient(90deg, var(--teal), var(--gold)); transition: width .5s ease; }

/* ---------- Статусы ---------- */
.chip { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--cloud); color: var(--muted); }
.st-new { background: rgba(213,168,90,.22); color: #7A5718; }
.st-in-progress { background: rgba(25,123,135,.14); color: #136571; }
.st-waiting-client { background: rgba(183,121,31,.16); color: #8A5A0E; }
.st-won { background: rgba(19,122,59,.14); color: var(--ok); }
.st-lost { background: rgba(180,35,24,.12); color: var(--danger); }
.statusgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.statusbtn { min-height: 44px; border: 2px solid transparent; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; background: var(--cloud); color: var(--text); }
.statusbtn.is-current { border-color: var(--midnight); }
.statusbtn:hover { filter: brightness(.97); }

/* ---------- Формы ---------- */
.form { display: grid; gap: 12px; margin-top: 12px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field__label { font-size: 13px; font-weight: 700; color: var(--midnight); }
.input { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #CBD5E1; border-radius: 10px; background: #fff; font: inherit; color: var(--text); }
textarea.input { min-height: 80px; resize: vertical; }
.input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px rgba(25,123,135,.18); }
.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.filters .field--grow { grid-column: 1 / -1; }
.filters__actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (min-width: 900px) { .filters { grid-template-columns: repeat(4, 1fr); } .filters .field--grow { grid-column: span 2; } }

/* ---------- Сообщения ---------- */
.flash { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-weight: 600; border: 1px solid transparent; }
.flash--success { background: rgba(19,122,59,.1); border-color: rgba(19,122,59,.3); color: var(--ok); }
.flash--error { background: rgba(180,35,24,.08); border-color: rgba(180,35,24,.3); color: var(--danger); }

/* ---------- Таблицы (на телефоне превращаются в карточки) ---------- */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; padding: 10px 14px; font-size: 12px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: #FAFBFD; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl__actions { white-space: nowrap; text-align: right; }
.tbl__actions .btn { margin-left: 4px; }
@media (max-width: 899px) {
  .tbl thead { position: absolute; left: -9999px; }
  .tbl, .tbl tbody, .tbl tr { display: block; width: 100%; }
  .tbl tr { padding: 12px 14px; border-bottom: 1px solid var(--line); }
  .tbl td { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; padding: 3px 0; border: 0; text-align: left; }
  .tbl td::before { content: attr(data-label); font-size: 12.5px; font-weight: 700; color: var(--muted); }
  .tbl td.tbl__actions { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 10px; text-align: left; }
  .tbl td.tbl__actions::before { content: none; }
  .tbl td.tbl__actions .btn { margin-left: 0; }
  .col-opt { display: none !important; }
}
.pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin: 14px 0; flex-wrap: wrap; }

/* ---------- Списки, история, описания ---------- */
.recent__item + .recent__item { border-top: 1px solid var(--line); }
.recent__link { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 10px 0; color: inherit; text-decoration: none; }
.recent__link:hover .recent__name { color: var(--teal); }
.recent__name { font-weight: 700; color: var(--midnight); }
.recent__meta { width: 100%; font-size: 13px; color: var(--muted); }
.timeline { display: grid; gap: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline__item { position: relative; padding: 0 0 14px 16px; }
.timeline__item::before { content: ''; position: absolute; left: -7px; top: 5px; width: 12px; height: 12px; border-radius: 50%; background: var(--gold); border: 2px solid var(--white); }
.timeline__head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 2px 10px; font-size: 13.5px; }
.timeline__body { margin-top: 2px; white-space: pre-wrap; word-break: break-word; }
.dl { display: grid; grid-template-columns: minmax(110px, 36%) 1fr; gap: 6px 12px; }
.dl dt { font-size: 13px; font-weight: 700; color: var(--muted); }
.dl dd { min-width: 0; }

/* ---------- Вход и установка ---------- */
.bare__main { padding: 16px; }
.login__brand { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.checks { display: grid; gap: 6px; margin: 10px 0 16px; }
.checks__item { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px 10px; border-radius: 10px; background: var(--cloud); }
.checks__mark { display: inline-flex; align-items: center; justify-content: center; min-width: 28px; height: 22px; padding: 0 6px; border-radius: 999px; font-size: 12px; font-weight: 800; background: var(--warn); color: #fff; }
.checks__item.is-ok .checks__mark { background: var(--ok); }
.checks__item.is-bad .checks__mark { background: var(--danger); }

@media (prefers-reduced-motion: reduce) { .btn, .bar__fill { transition: none; } }

/* Заголовки внутри карточек без полей (таблицы) */
.h2.pad { padding: 16px 16px 8px; margin: 0; }
.muted.pad { padding: 0 16px 16px; }
