/* Дашборд страховой — те же токены "Ember", что в дизайн-прототипе
   (design/watch-insurance-prototype.html) и iOS-приложении.
   Manrope — весь интерфейс; Bricolage Grotesque — только цифры (в нём нет
   кириллицы, смешивать на одной строке нельзя). */

@font-face { font-family: "Manrope"; font-weight: 400; font-display: swap; src: url("fonts/Manrope-Regular.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-weight: 600; font-display: swap; src: url("fonts/Manrope-SemiBold.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-weight: 700; font-display: swap; src: url("fonts/Manrope-Bold.ttf") format("truetype"); }
@font-face { font-family: "Manrope"; font-weight: 800; font-display: swap; src: url("fonts/Manrope-ExtraBold.ttf") format("truetype"); }
@font-face { font-family: "Bricolage Grotesque"; font-weight: 700; font-display: swap; src: url("fonts/BricolageGrotesque-Bold.ttf") format("truetype"); }

:root {
  color-scheme: light dark;
  --bg: #FBF7F5;
  --surface: #FFFFFF;
  --surface-2: #F5EBE7;
  --ink: #201411;
  --muted: #7A6B66;
  --line: #EEE1DB;
  --accent: #FF5A36;
  --accent-ink: #FFFFFF;
  --ok: #1E9E5C;
  --attn: #B9780A;
  --wash: rgba(255, 90, 54, .10);
  --shadow: 0 8px 24px rgba(32, 20, 17, .10);
  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Bricolage Grotesque", "Manrope", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B0E12;
    --surface: #161B21;
    --surface-2: #1E252D;
    --ink: #EDF0F3;
    --muted: #8B94A0;
    --line: #2A323C;
    --accent: #FF7A54;
    --accent-ink: #2A0D04;
    --ok: #35D08A;
    --attn: #FFC24D;
    --wash: rgba(255, 122, 84, .12);
    --shadow: 0 8px 24px rgba(0, 0, 0, .45);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
}
h1, h2, p { margin: 0; }
a { color: inherit; }
[hidden] { display: none !important; }

/* --- шапка -------------------------------------------------------------- */

.dash-nav { background: var(--surface); border-bottom: 1px solid var(--line); }
.dash-nav-inner, .dash-tabs, .dash-main { max-width: 1040px; margin: 0 auto; padding-left: 24px; padding-right: 24px; }
.dash-nav-inner { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-top: 14px; padding-bottom: 10px; }
.dash-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: .95rem; min-width: 0; }
.dash-brand span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mark { width: 22px; height: 22px; border-radius: 6px; background: var(--accent); flex: none; display: inline-block; }
.dash-account { display: flex; align-items: center; gap: 14px; font-size: .85rem; color: var(--muted); flex: none; }
.dash-account form { margin: 0; }
.link-button { background: none; border: 0; padding: 4px 0; font: inherit; font-weight: 600; color: var(--ink); cursor: pointer; }
.link-button:hover { color: var(--accent); }

.dash-tabs { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.dash-tabs > a {
  padding: 10px 12px 11px; font-size: .88rem; font-weight: 600; color: var(--muted); text-decoration: none;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.dash-tabs > a:hover { color: var(--ink); }
.dash-tabs > a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); }

.group-switch { margin-left: auto; position: relative; font-size: .85rem; }
.group-switch summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 8px 4px; list-style: none; }
.group-switch summary::after { content: " ▾"; }
.group-switch ul {
  position: absolute; right: 0; top: 100%; z-index: 10; min-width: 200px; margin: 4px 0 0; padding: 6px;
  list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow);
}
.group-switch li a { display: block; padding: 8px 10px; border-radius: 8px; text-decoration: none; }
.group-switch li a:hover { background: var(--surface-2); }
.group-switch li a[aria-current="true"] { font-weight: 700; }

/* --- основной блок ------------------------------------------------------ */

.dash-main { padding-top: 24px; padding-bottom: 40px; display: flex; flex-direction: column; gap: 16px; }
.dash-title-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.dash-title-row h1 { font-size: 1.5rem; font-weight: 800; }
.dash-title-row .range { font-size: .88rem; color: var(--muted); }

.filters { display: flex; gap: 10px; flex-wrap: wrap; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.segmented a {
  padding: 7px 14px; border-radius: 9px; font-size: .85rem; font-weight: 600; color: var(--muted); text-decoration: none;
}
.segmented a:hover { color: var(--ink); }
.segmented a[aria-current="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px 18px; }
.kpi-label { font-size: .82rem; color: var(--muted); margin-bottom: 4px; }
.kpi-value { font-family: var(--font-display); font-size: 2rem; font-weight: 700; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi-value.ok { color: var(--ok); }
.kpi-value.attn { color: var(--attn); }
.kpi-delta { font-size: .8rem; color: var(--muted); margin-top: 4px; }

.chart-card, .score-switch-wrap, .info-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px 20px; }
.ch-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.ch-head h2 { font-size: 1rem; font-weight: 700; }
.ch-head span { font-size: .82rem; color: var(--muted); }

.dash-note { font-size: .8rem; color: var(--muted); line-height: 1.5; }

/* --- график ------------------------------------------------------------- */

.chart { position: relative; padding-left: 34px; padding-right: 8px; }
.chart-plot { position: relative; height: 240px; outline: none; touch-action: pan-y; }
.chart-plot:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: 4px; }
.chart-svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.chart-svg .line { fill: none; stroke: var(--accent); stroke-width: 2px; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.chart-svg .area { fill: var(--wash); stroke: none; }
.grid-line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.y-label {
  position: absolute; left: -34px; width: 28px; text-align: right; transform: translateY(-50%);
  font-size: .72rem; color: var(--muted); font-variant-numeric: tabular-nums;
}
.x-axis { position: relative; height: 22px; }
.x-label { position: absolute; top: 6px; transform: translateX(-50%); font-size: .72rem; color: var(--muted); white-space: nowrap; }
.x-label.start { transform: none; }
.x-label.end { transform: translateX(-100%); }

.end-dot, .hover-dot, .lone-dot {
  position: absolute; width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 0 2px var(--surface); pointer-events: none;
}
.lone-dot { width: 6px; height: 6px; margin: -3px 0 0 -3px; }
.end-label {
  position: absolute; transform: translate(-50%, -100%); margin-top: -9px;
  font-family: var(--font-display); font-weight: 700; font-size: .9rem; color: var(--ink); pointer-events: none;
}
.end-label.at-edge { transform: translate(-100%, -100%); margin-left: -4px; }
.chart-plot.is-hovering .end-label { visibility: hidden; }
.crosshair { position: absolute; top: 0; bottom: 0; width: 0; border-left: 1px solid var(--muted); opacity: .5; pointer-events: none; }
.chart-tooltip {
  position: absolute; top: 0; z-index: 5; min-width: 176px; padding: 10px 12px; pointer-events: none;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); font-size: .8rem;
}
.chart-tooltip .tt-date { font-weight: 700; margin-bottom: 4px; }
.chart-tooltip .tt-row { display: flex; justify-content: space-between; gap: 14px; color: var(--muted); }
.chart-tooltip .tt-row b { color: var(--ink); font-weight: 700; font-variant-numeric: tabular-nums; }

.table-view { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 10px; }
.table-view summary { cursor: pointer; font-size: .85rem; font-weight: 600; color: var(--muted); }
.table-view summary:hover { color: var(--ink); }
.table-scroll { overflow-x: auto; margin-top: 8px; max-height: 360px; overflow-y: auto; }
.table-view table { width: 100%; border-collapse: collapse; font-size: .85rem; font-variant-numeric: tabular-nums; }
.table-view th, .table-view td { padding: 7px 10px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table-view th:first-child { text-align: left; }
.table-view thead th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }
.table-view tbody th { font-weight: 600; }

/* --- пустые состояния --------------------------------------------------- */

.dash-empty {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: .8rem; padding: 48px 24px;
}
.dash-empty .ring {
  width: 56px; height: 56px; border-radius: 50%; border: 2.5px dashed var(--line);
  display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 1.2rem;
}
.dash-empty h2 { font-size: 1.1rem; font-weight: 800; }
.dash-empty p { font-size: .9rem; color: var(--muted); max-width: 420px; }
.dash-empty .prog { font-size: .82rem; font-weight: 600; background: var(--surface-2); padding: .35rem .8rem; border-radius: 100px; }

/* --- типы показателей --------------------------------------------------- */

.score-switch { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.score-opt { flex: 1; min-width: 160px; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; text-decoration: none; }
.score-opt.active { border-color: var(--accent); background: var(--surface-2); }
.score-opt .so-name { font-size: .95rem; font-weight: 700; }
.score-opt .so-tag { font-size: .7rem; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-top: .3rem; }
.score-opt.soon .so-name { opacity: .5; }
.info-card { display: flex; flex-direction: column; gap: 8px; }
.info-card h2 { font-size: 1rem; font-weight: 700; }

/* --- экспорт ------------------------------------------------------------ */

.print-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.pc-head { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 12px; }
.pc-title { font-weight: 800; font-size: 1.05rem; }
.pc-sub { font-size: .85rem; font-weight: 700; margin-bottom: 10px; }
.pc-empty { color: var(--muted); font-size: .9rem; }
.print-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.print-grid p:first-child { font-size: .78rem; color: var(--muted); }
.print-grid p:nth-child(2) { font-family: var(--font-display); font-size: 1.6rem; font-weight: 700; margin-top: .15rem; font-variant-numeric: tabular-nums; }
.print-grid .pg-note { font-size: .75rem; color: var(--muted); }
.print-chart .chart-plot { height: 180px; }
.export-actions { display: flex; gap: 10px; flex-wrap: wrap; }

/* --- кнопки и формы ----------------------------------------------------- */

.btn-primary, .btn-secondary {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
  border-radius: 12px; font: inherit; font-weight: 700; font-size: .95rem; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); color: var(--accent-ink); border: 0; }
.btn-primary:hover { filter: brightness(1.05); }
.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-primary:focus-visible, .btn-secondary:focus-visible, a:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { font-size: 1.35rem; font-weight: 800; margin-top: 8px; }
.login-card .muted { color: var(--muted); font-size: .9rem; }
.login-card label { font-size: .82rem; font-weight: 600; margin-top: 6px; }
.login-card input {
  font: inherit; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-height: 44px;
}
.login-card input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.login-card input[aria-invalid="true"] { border-color: var(--attn); }
.form-error { color: var(--attn); font-size: .85rem; font-weight: 600; }

/* --- телефон ------------------------------------------------------------ */

@media (max-width: 720px) {
  .dash-nav-inner, .dash-tabs, .dash-main { padding-left: 16px; padding-right: 16px; }
  .org-name { display: none; }
  .dash-nav-inner { align-items: flex-start; }
  .dash-brand span:last-child { white-space: normal; }
  .x-label.minor { display: none; }
  .kpi-grid, .print-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-card { padding: 13px 14px; }
  .kpi-value { font-size: 1.6rem; }
  .chart-plot { height: 200px; }
  .dash-tabs > a { padding: 10px 8px 11px; font-size: .84rem; }
  .group-switch { margin-left: 0; }
  .group-switch ul { left: 0; right: auto; }
}

/* --- печать (кнопка "Скачать PDF") -------------------------------------- */

@media print {
  :root {
    --bg: #FFFFFF; --surface: #FFFFFF; --surface-2: #F5EBE7; --ink: #201411; --muted: #6B5D58;
    --line: #E4D6D0; --accent: #FF5A36; --ok: #1E9E5C; --attn: #9A6408; --wash: rgba(255, 90, 54, .10);
    color-scheme: light;
  }
  @page { size: A4; margin: 16mm; }
  body { font-size: 12pt; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .dash-nav, .no-print { display: none !important; }
  .dash-main { max-width: none; padding: 0; }
  .print-card { border: 0; padding: 0; }
  .print-grid { grid-template-columns: repeat(4, 1fr); }
}
