/* Design tokens.
   Page/surfaces: soft green (per user request). Brand accent (logo, buttons,
   links, ИТОГО rows) stays the orange sampled from the КООЦ logo - green
   background + orange accent, not a single "orange-gray" scheme anymore.
   Chart DATA colors stay on the `dataviz` skill's validated categorical/
   status palette unchanged - brand and data-encoding are separate parameters
   by design (see palette.md "Plugging in a design system"): re-tinting the
   chrome/background never touches the CVD-validated series/status hues used
   for actual figures. */
:root {
  color-scheme: light;

  /* soft green surfaces */
  --page:           #e9f3e5;
  --surface-1:      #fbfdf9;
  --surface-2:      #eff6ea;
  --text-primary:   #17210f;
  --text-secondary: #57654c;
  --text-muted:     #869178;
  --grid:           #dbe7d2;
  --axis:           #bdd0b0;
  --border:         rgba(23,33,15,0.09);

  /* brand accent - exact colors sampled from the КООЦ logo (logo.png):
     orange #f4801d, gray #6c6d71 - used for chrome (logo, buttons, links,
     card accents, ИТОГО rows) - never for chart data series */
  --brand:          #f4801d;
  --brand-strong:   #cb630a;
  --brand-soft:     rgba(244,128,29,0.12);
  --brand-soft-2:   rgba(244,128,29,0.24);
  --brand-gray:     #6c6d71;

  /* dataviz skill's validated reference palette (unchanged) - see charts_svg.py */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  --status-good:     #0ca30c;
  --status-warning:  #fab219;
  --status-serious:  #ec835a;
  --status-critical: #d03b3b;

  --font: system-ui, -apple-system, "Segoe UI", sans-serif;

  --shadow-card: 0 1px 2px rgba(32,24,17,0.05), 0 12px 32px -12px rgba(32,24,17,0.12);
  --shadow-card-hover: 0 2px 4px rgba(32,24,17,0.06), 0 20px 44px -14px rgba(32,24,17,0.16);
  --shadow-pop: 0 12px 40px rgba(32,24,17,0.16);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page:           #101a0c;
    --surface-1:      #182513;
    --surface-2:      #1d2c17;
    --text-primary:   #f1f7ec;
    --text-secondary: #bcccad;
    --text-muted:     #8ea07d;
    --grid:           #2c3d24;
    --axis:           #3c5031;
    --border:         rgba(241,247,236,0.10);

    --brand:          #f69a4c;
    --brand-strong:   #f8b378;
    --brand-soft:     rgba(246,154,76,0.18);
    --brand-soft-2:   rgba(246,154,76,0.30);
    --brand-gray:     #9a9ba0;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 12px 32px -12px rgba(0,0,0,0.5);
    --shadow-card-hover: 0 2px 4px rgba(0,0,0,0.35), 0 20px 44px -14px rgba(0,0,0,0.6);
    --shadow-pop: 0 12px 40px rgba(0,0,0,0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page:           #101a0c;
  --surface-1:      #182513;
  --surface-2:      #1d2c17;
  --text-primary:   #f1f7ec;
  --text-secondary: #bcccad;
  --text-muted:     #8ea07d;
  --grid:           #2c3d24;
  --axis:           #3c5031;
  --border:         rgba(241,247,236,0.10);

  --brand:          #f69a4c;
  --brand-strong:   #f8b378;
  --brand-soft:     rgba(246,154,76,0.18);
  --brand-soft-2:   rgba(246,154,76,0.30);
  --brand-gray:     #9a9ba0;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --shadow-card: 0 1px 2px rgba(0,0,0,0.3), 0 12px 32px -12px rgba(0,0,0,0.5);
  --shadow-card-hover: 0 2px 4px rgba(0,0,0,0.35), 0 20px 44px -14px rgba(0,0,0,0.6);
  --shadow-pop: 0 12px 40px rgba(0,0,0,0.5);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: var(--font);
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}
/* soft radial warmth behind the page - subtle, not decorative noise */
body {
  background:
    radial-gradient(1100px 520px at 12% -10%, var(--brand-soft), transparent 60%),
    var(--page);
  min-height: 100vh;
}

/* ---------- Login page ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 48px 40px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: var(--shadow-pop);
}
.login-logo {
  margin: 0 auto 16px;
  width: 104px; height: 104px;
  display: flex; align-items: center; justify-content: center;
}
.login-logo img { width: 100%; height: 100%; object-fit: contain; }
.login-card h1 { font-size: 18px; margin: 0 0 6px; line-height: 1.4; font-weight: 650; letter-spacing: -0.01em; }
.login-sub { color: var(--text-secondary); font-size: 13px; margin: 0 0 28px; }
.login-card label { display: block; text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 8px; }
.login-card input {
  width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); font-size: 14px; margin-bottom: 20px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.login-card button {
  width: 100%; padding: 13px; border-radius: 12px; border: none;
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  color: #fff; font-size: 14px; font-weight: 650; cursor: pointer;
  box-shadow: 0 6px 16px -4px var(--brand-soft-2);
  transition: transform 0.15s, box-shadow 0.15s;
}
.login-card button:hover { transform: translateY(-1px); box-shadow: 0 10px 22px -4px var(--brand-soft-2); }
.login-card button:active { transform: translateY(0); }
.login-error {
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  color: var(--status-critical); border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 18px;
}

/* ---------- Dashboard layout ---------- */
.page { max-width: 1180px; margin: 0 auto; padding: 32px 24px 72px; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; margin-bottom: 28px; flex-wrap: wrap;
}
.header-title { display: flex; align-items: center; gap: 14px; }
.header-logo {
  width: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px;
  flex-shrink: 0;
}
.header-logo img { width: 64px; height: 64px; object-fit: contain; }
.header-logo-caption {
  font-size: 9px; font-weight: 650; letter-spacing: 0.02em; text-transform: uppercase;
  color: var(--text-muted); text-align: center; line-height: 1.25;
}

.page-header-home {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
}
.page-header-home .header-title { grid-column: 2; justify-self: center; }
.page-header-home .header-controls { grid-column: 3; justify-self: end; }
.page-header-home .header-logo {
  flex-direction: row; width: auto; gap: 16px;
}
.page-header-home .header-logo-caption {
  font-size: 22px; font-weight: 700; text-transform: none; letter-spacing: -0.01em;
  color: var(--text-primary); text-align: left; line-height: 1.3; max-width: none;
}
.header-title h1 { font-size: 19px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.header-sub { font-size: 12.5px; color: var(--text-muted); margin: 3px 0 0; }
.header-controls { display: flex; align-items: center; gap: 18px; }
.year-form select {
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-card);
}

.period-picker { position: relative; }
.period-picker summary {
  list-style: none; cursor: pointer; user-select: none;
  padding: 8px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-1); color: var(--text-primary); font-size: 13px; font-weight: 650;
  box-shadow: var(--shadow-card);
  display: flex; align-items: center; gap: 6px;
}
.period-picker summary::-webkit-details-marker { display: none; }
.period-picker summary::after { content: "▾"; font-size: 10px; color: var(--text-muted); }
.period-picker[open] summary { border-color: var(--brand-soft-2); }
.period-panel {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 20;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px;
  padding: 16px; width: 320px;
  box-shadow: var(--shadow-pop);
}
.period-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 14px; }
.period-quick-btn {
  display: block; text-align: center; padding: 7px 4px; border-radius: 8px;
  font-size: 12px; font-weight: 600; color: var(--text-secondary); text-decoration: none;
  background: var(--surface-2); transition: background 0.12s, color 0.12s;
}
.period-quick-btn:first-child { grid-column: 1 / -1; }
.period-quick-btn:hover { background: var(--brand-soft); color: var(--brand-strong); }
.period-quick-btn.active { background: var(--brand); color: #fff; }

.period-range-form {
  border-top: 1px solid var(--border); padding-top: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.period-range-form label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; color: var(--text-secondary); font-weight: 600; gap: 10px;
}
.period-range-form select {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); font-size: 12.5px; flex: 1;
}
.thresholds-panel { width: 260px; }
.period-range-form input[type="number"] {
  padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-primary); font-size: 12.5px;
  width: 64px; text-align: right;
}
.thresholds-hint { font-size: 11px; color: var(--text-muted); line-height: 1.4; margin: 2px 0 4px; }

.period-apply {
  padding: 9px; border-radius: 8px; border: none; margin-top: 2px;
  background: linear-gradient(180deg, var(--brand), var(--brand-strong));
  color: #fff; font-size: 12.5px; font-weight: 650; cursor: pointer;
}
.period-apply:hover { filter: brightness(1.05); }

.logout-link {
  color: var(--text-secondary); font-size: 13px; text-decoration: none; font-weight: 600;
  padding: 8px 14px; border-radius: 10px; transition: background 0.15s, color 0.15s;
}
.logout-link:hover { color: var(--brand-strong); background: var(--brand-soft); }

.warning-banner {
  background: color-mix(in srgb, var(--status-warning) 12%, var(--surface-1));
  border: 1px solid color-mix(in srgb, var(--status-warning) 35%, transparent);
  border-radius: 16px; padding: 16px 20px; margin-bottom: 24px; font-size: 13px;
  box-shadow: var(--shadow-card);
}
.warning-banner ul { margin: 8px 0 0; padding-left: 20px; }
.warning-banner li { margin-bottom: 3px; }

/* Данные будут потеряны при следующем деплое - это тревожнее, чем
   needs_review, поэтому красный, а не жёлтый. */
.storage-warning {
  background: color-mix(in srgb, var(--status-critical) 12%, var(--surface-1));
  border-color: color-mix(in srgb, var(--status-critical) 45%, transparent);
}
.storage-warning p { margin: 6px 0 0; }

.back-link {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
  text-decoration: none; margin-bottom: 16px; transition: color 0.15s;
}
.back-link:hover { color: var(--brand-strong); }

.kpi-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; margin-bottom: 28px;
}
.kpi-row-2 { grid-template-columns: repeat(2, 1fr); max-width: 620px; }
.kpi-row-1 { grid-template-columns: 1fr; max-width: 320px; }

.agent-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-top: 8px;
}
.agent-card {
  display: block; background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 22px; padding: 26px 26px 22px; text-decoration: none; color: var(--text-primary);
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  position: relative; overflow: hidden;
}
.agent-card::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), transparent);
}
.agent-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-card-hover); }
.agent-card-top { display: flex; align-items: center; gap: 9px; margin-bottom: 6px; }
.agent-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.agent-card h2 { font-size: 16px; margin: 0; font-weight: 650; }
.agent-card-sub { font-size: 12.5px; color: var(--text-muted); margin: 0 0 18px; line-height: 1.45; min-height: 34px; }
.agent-card-value { font-size: 25px; font-weight: 650; letter-spacing: -0.01em; }
.agent-card-meta {
  font-size: 12px; color: var(--text-secondary); margin-top: 6px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.agent-card-spark { margin-top: 14px; }
.agent-card-cta {
  margin-top: 18px; font-size: 12.5px; font-weight: 650; color: var(--brand-strong);
}

@media (max-width: 900px) {
  .agent-grid { grid-template-columns: 1fr; }
}
.kpi-tile {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 20px; padding: 22px 24px;
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
  position: relative;
  overflow: hidden;
}
.kpi-tile::before {
  content: ""; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--brand), transparent);
}
.kpi-tile:hover { transform: translateY(-2px); box-shadow: var(--shadow-card-hover); }
.kpi-label { font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); margin-bottom: 10px; }
.kpi-value { font-size: 26px; font-weight: 650; letter-spacing: -0.01em; }
.kpi-delta { font-size: 12.5px; margin-top: 6px; font-weight: 600; }
.kpi-spark { margin-top: 12px; }

.chart-card {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 22px;
  padding: 28px 28px 26px; margin-bottom: 24px;
  box-shadow: var(--shadow-card);
  transition: box-shadow 0.18s ease;
}
.chart-card:hover { box-shadow: var(--shadow-card-hover); }

.insights-card {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 22px;
  padding: 22px 26px 22px 30px; margin-bottom: 24px; position: relative;
  box-shadow: var(--shadow-card);
}
.insights-card::before {
  content: ""; position: absolute; left: 0; top: 20px; bottom: 20px; width: 4px;
  background: var(--brand); border-radius: 4px;
}
.insights-card h2 { font-size: 15px; margin: 0 0 13px; font-weight: 650; letter-spacing: -0.01em; }
.insights-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.insights-list li { font-size: 14.5px; line-height: 1.55; color: var(--text-primary); }
.insights-list li::before { content: "→ "; color: var(--brand); font-weight: 700; }
.card-header { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; flex-wrap: wrap; }
.card-header h2 { font-size: 17px; margin: 0 0 3px; font-weight: 650; letter-spacing: -0.01em; }
.card-sub { font-size: 12.5px; color: var(--text-muted); margin: 0 0 18px; }
.chart-wrap { width: 100%; overflow-x: auto; margin-bottom: 4px; }
.chart-wrap svg { max-width: 100%; height: auto; display: block; }

.upload-form { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.upload-form input[type="file"] {
  flex: 1; min-width: 260px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-primary);
  font-size: 13px;
}
.upload-form .period-apply { padding: 10px 22px; margin-top: 0; }
.upload-hint { font-size: 12.5px; color: var(--text-secondary); line-height: 1.55; }
.upload-hint p { margin: 0 0 8px; }
.upload-hint ul { margin: 0 0 12px; padding-left: 20px; }
.upload-result { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 12px; }
.upload-result li {
  padding: 12px 16px; border-radius: 12px; background: var(--surface-2);
  border-left: 3px solid var(--status-good); font-size: 13px;
}
.upload-result li.err { border-left-color: var(--status-critical); }
.upload-message { display: block; margin-top: 4px; white-space: pre-line; color: var(--text-secondary); }

.position-groups { display: flex; flex-direction: column; gap: 8px; }
.position-group {
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2);
  overflow: hidden;
}
.position-group summary {
  list-style: none; cursor: pointer; user-select: none; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.position-group summary::-webkit-details-marker { display: none; }
.position-group-name { font-size: 13.5px; font-weight: 650; }
.position-group-total { font-size: 13px; font-weight: 650; color: var(--text-secondary); white-space: nowrap; }
.position-group .table-wrap { margin-top: 0; border: none; border-top: 1px solid var(--border); border-radius: 0; }
.position-group[open] summary { border-bottom: 1px solid var(--border); }
/* Должности, не попавшие ни в одну категорию персонала: видно, что это
   открытый вопрос, а не обычная строка. */
.position-group-review { border-color: color-mix(in srgb, var(--status-warning) 45%, transparent); }
.position-group-review summary { gap: 8px; }
.position-group-name .pill { margin-left: 8px; font-size: 11px; }
tr.row-review td { background: color-mix(in srgb, var(--status-warning) 8%, transparent); }

.legend-row { display: flex; flex-wrap: wrap; gap: 14px; margin: 14px 0 4px; }
.legend-item { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-secondary); font-weight: 500; }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

.table-wrap { overflow-x: auto; margin-top: 18px; border-radius: 14px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; font-weight: 650; color: var(--text-muted); padding: 12px 16px;
  border-bottom: 1px solid var(--border); white-space: nowrap; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.03em; background: var(--surface-2);
}
td { padding: 11px 16px; border-bottom: 1px solid var(--grid); }
td.num, th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr { transition: background 0.12s; }
tbody tr:hover { background: var(--brand-soft); }
tbody tr:last-child td { border-bottom: none; }
tr.totals-row td {
  font-weight: 700; background: var(--surface-2); border-top: 2px solid var(--brand-soft-2);
  border-bottom: none;
}
tr.totals-row:hover td { background: var(--surface-2); }

.pill {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 700;
  color: #fff; letter-spacing: 0.01em;
}
.status-good { background: var(--status-good); }
.status-warning { background: var(--status-warning); color: #1a1a19; }
.status-serious { background: var(--status-serious); }
.status-critical { background: var(--status-critical); }
.status-neutral { color: var(--text-muted); background: none; }
.kpi-delta.status-good { color: var(--status-good); }
.kpi-delta.status-warning { color: color-mix(in srgb, var(--status-warning) 70%, var(--text-primary)); }
.kpi-delta.status-serious { color: var(--status-serious); }
.kpi-delta.status-critical { color: var(--status-critical); }
.kpi-delta.status-neutral { color: var(--text-muted); }

.empty-state { color: var(--text-muted); font-size: 13px; padding: 32px 0; text-align: center; }

/* chart interactivity affordances */
.chart-dot, .chart-seg, .chart-hbar { cursor: pointer; }
.chart-dot:hover, .chart-seg:hover { opacity: 0.85; }
.chart-hbar:hover { filter: brightness(1.08); }

.chart-tooltip {
  position: fixed; pointer-events: none; z-index: 50;
  background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; font-size: 12.5px; box-shadow: var(--shadow-pop);
  max-width: 220px;
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip .tt-value { font-weight: 700; color: var(--text-primary); }
.chart-tooltip .tt-label { color: var(--text-secondary); margin-top: 2px; }

@media (max-width: 720px) {
  .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .page { padding: 20px 16px 56px; }
  .chart-card { padding: 20px 18px 18px; border-radius: 18px; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header-home { display: flex; }
  .kpi-value { font-size: 21px; }
}
