/* Кабинет: рабочий инструмент, а не витрина.
 *
 * Отличие от публичной страницы намеренное — здесь плотнее сетка, спокойнее
 * фон и никакой анимации ради анимации. Цифры набраны табличными знаками
 * и выравниваются по правому краю: колонку сумм читают сверху вниз,
 * сравнивая порядок величин, а не по одной.
 */

:root {
  --ground: #F4F7FA;
  --ground-deep: #E9EFF5;
  --surface: #FFFFFF;
  --line: #DDE6EF;
  --line-strong: #C3D0DE;
  --ink: #0F1B26;
  --ink-soft: #33475B;
  --muted: #62768A;
  --brand: #0B5D66;
  --brand-bright: #0E7C87;
  --brand-soft: #E3F1F2;
  --amber: #B4650B;
  --amber-soft: #FBF1E3;
  --critical: #A32D22;
  --critical-soft: #FBEBE9;
  --high: #B4650B;
  --medium: #5A6B7E;
  --positive: #146B4E;
  --positive-soft: #E6F3EE;
  --shadow-sm: 0 1px 2px rgba(15, 27, 38, 0.06), 0 2px 6px rgba(15, 27, 38, 0.04);
  --shadow-md: 0 2px 4px rgba(15, 27, 38, 0.06), 0 8px 24px rgba(15, 27, 38, 0.08);
  --radius: 12px;
  --radius-sm: 8px;

  /* Роли текста, а не набор размеров. Шаг между соседними ролями заметен
   * глазом: 11.5 → 13 → 15 → 19 → 28. Между текстом и заголовком панели
   * получается 1,27, между панелью и заголовком страницы — 1,47. Раньше
   * заголовок панели был крупнее текста на 13 %, и разделы читались как
   * сплошное полотно: глаз не находил, где начинается новое.
   *
   * Микророли (подписи, шапки таблиц, ярлыки) различаются не только
   * размером — регистром, насыщенностью и цветом, поэтому шаг между ними
   * меньше и этого достаточно.
   */
  --text-micro: 11.5px;
  --text-meta: 13px;
  --text-body: 15px;
  --text-section: 19px;
  --text-display: 28px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --ground: #0A1219;
    --ground-deep: #060C11;
    --surface: #121C25;
    --line: #22323F;
    --line-strong: #33475B;
    --ink: #E9F0F6;
    --ink-soft: #B9C9D8;
    --muted: #8598AB;
    --brand: #43B0BA;
    --brand-bright: #57C7D1;
    --brand-soft: #102C31;
    --amber: #E0A05A;
    --amber-soft: #2C2115;
    --critical: #E8837A;
    --critical-soft: #2C1614;
    --high: #E0A05A;
    --medium: #9BAEC1;
    --positive: #5CC49B;
    --positive-soft: #10261F;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 2px 6px rgba(0, 0, 0, 0.45), 0 10px 30px rgba(0, 0, 0, 0.35);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font: var(--text-body)/1.55 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.num {
  font-variant-numeric: tabular-nums;
}

.hidden {
  display: none !important;
}

/* --- Вход -------------------------------------------------------------- */

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 500px at 15% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent 60%),
    radial-gradient(700px 500px at 100% 110%, color-mix(in srgb, var(--amber) 12%, transparent), transparent 60%),
    var(--ground);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 30px;
}

.login-card .brand {
  display: flex;
  align-items: center;
  gap: 11px;
  font-weight: 650;
  /* Логотип — знак, а не текстовая роль: он набран рядом со значком 32 px
   * и выровнен по нему, поэтому размер задан в паре со значком. */
  font-size: 18px;
  letter-spacing: -0.02em;
  text-decoration: none;
  color: inherit;
}

.brand-mark {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(150deg, var(--brand-bright), var(--brand));
  display: grid;
  place-items: center;
  flex: none;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.25);
}

.brand-mark svg {
  width: 18px;
  height: 18px;
}

.login-card h1 {
  font-size: var(--text-section);
  margin: 24px 0 6px;
  letter-spacing: -0.02em;
}

.login-card .sub {
  color: var(--muted);
  font-size: var(--text-body);
  margin: 0 0 4px;
}

.field {
  display: grid;
  gap: 6px;
  margin-top: 16px;
}

.field label {
  font-size: var(--text-meta);
  color: var(--muted);
  font-weight: 540;
}

input,
select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--ground);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 570;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn-primary {
  background: linear-gradient(160deg, var(--brand-bright), var(--brand));
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  filter: brightness(1.07);
}

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--line-strong);
}

.btn-ghost:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.btn[disabled] {
  opacity: 0.55;
  cursor: wait;
}

.btn-block {
  width: 100%;
  margin-top: 22px;
  padding: 12px;
}

.msg {
  margin-top: 14px;
  font-size: var(--text-body);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  display: none;
}

.msg.err {
  display: block;
  background: var(--critical-soft);
  color: var(--critical);
  border: 1px solid color-mix(in srgb, var(--critical) 25%, transparent);
}

.login-foot {
  margin-top: 20px;
  font-size: var(--text-meta);
  color: var(--muted);
  text-align: center;
}

.login-foot a {
  color: var(--brand);
}

/* --- Каркас кабинета --------------------------------------------------- */

.app-top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}

.app-top-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 22px;
  height: 60px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.org-picker {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.org-picker select {
  width: auto;
  min-width: 210px;
  padding: 7px 11px;
  font-size: var(--text-body);
}

.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 26px 22px 64px;
}

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-head h1 {
  font-size: var(--text-display);
  letter-spacing: -0.025em;
  margin: 0;
}

.page-head .sub {
  color: var(--muted);
  font-size: var(--text-body);
  margin-top: 4px;
}

.period {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.period .field {
  margin: 0;
}

.period input {
  width: auto;
  padding: 8px 11px;
  font-size: var(--text-body);
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
  overflow-x: auto;
}

.tab {
  padding: 10px 16px;
  border: 0;
  background: none;
  font: inherit;
  font-weight: 545;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}

.tab:hover {
  color: var(--ink);
}

.tab.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

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

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow-sm);
}

.tile .cap {
  font-size: var(--text-meta);
  color: var(--muted);
}

.tile .val {
  font-size: var(--text-display);
  font-weight: 650;
  letter-spacing: -0.025em;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.tile .val.pos {
  color: var(--positive);
}

.tile .val.neg {
  color: var(--critical);
}

.tile .hint {
  font-size: var(--text-meta);
  color: var(--muted);
  margin-top: 4px;
}

/* Здоровье учёта — крупный круговой индикатор. */

.health {
  display: flex;
  align-items: center;
  gap: 20px;
  grid-column: span 2;
}

@media (max-width: 720px) {
  .health {
    grid-column: span 1;
  }
}

.gauge {
  --value: 0;
  position: relative;
  width: 82px;
  height: 82px;
  flex: none;
  border-radius: 50%;
  background: conic-gradient(var(--gauge-color, var(--brand)) calc(var(--value) * 1%), var(--ground-deep) 0);
  display: grid;
  place-items: center;
  transition: background 0.6s ease;
}

.gauge::after {
  content: '';
  position: absolute;
  inset: 9px;
  border-radius: 50%;
  background: var(--surface);
}

.gauge span {
  position: relative;
  z-index: 1;
  /* Балл внутри круга 82 px: крупнее текста, но мельче заголовка страницы —
   * иначе он спорит с ним за внимание, стоя в плитке показателей. */
  font-size: 22px;
  font-weight: 660;
  font-variant-numeric: tabular-nums;
}

/* --- Таблицы отчётов --------------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  margin-bottom: 20px;
}

.panel-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.panel-head h2 {
  font-size: var(--text-section);
  margin: 0;
  letter-spacing: -0.015em;
}

.panel-head .note {
  font-size: var(--text-meta);
  color: var(--muted);
}

.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-body);
}

th,
td {
  padding: 10px 20px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  font-size: var(--text-micro);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--ground-deep);
  position: sticky;
  top: 0;
}

td.amount,
th.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

tr:last-child td {
  border-bottom: 0;
}

tr.subtotal td {
  font-weight: 620;
  background: color-mix(in srgb, var(--brand-soft) 55%, transparent);
}

tr.grand td {
  font-weight: 680;
  background: var(--brand-soft);
  border-top: 2px solid color-mix(in srgb, var(--brand) 35%, transparent);
}

td .indent {
  padding-left: 14px;
  color: var(--ink-soft);
}

.amount.neg {
  color: var(--critical);
}

.amount.pos {
  color: var(--positive);
}

/* --- Находки ----------------------------------------------------------- */

.finding {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: start;
}

.finding:last-child {
  border-bottom: 0;
}

.sev {
  font-size: var(--text-micro);
  font-weight: 640;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
}

.sev.critical {
  background: var(--critical-soft);
  color: var(--critical);
}

.sev.high {
  background: var(--amber-soft);
  color: var(--high);
}

.sev.medium {
  background: var(--ground-deep);
  color: var(--medium);
}

.sev.low {
  background: var(--ground-deep);
  color: var(--muted);
}

.finding .title {
  font-weight: 570;
}

.finding .desc {
  color: var(--ink-soft);
  font-size: var(--text-body);
  margin-top: 3px;
}

.finding .impact {
  font-variant-numeric: tabular-nums;
  font-weight: 570;
  color: var(--critical);
  white-space: nowrap;
}

/* --- Служебное --------------------------------------------------------- */

.warn {
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  background: var(--amber-soft);
  border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  color: var(--ink-soft);
  font-size: var(--text-body);
  margin-bottom: 18px;
}

.warn strong {
  color: var(--amber);
}

.empty {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: var(--text-body);
}

.loading {
  padding: 34px 20px;
  text-align: center;
  color: var(--muted);
  font-size: var(--text-body);
}

.loading::after {
  content: '';
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-left: 9px;
  vertical-align: -2px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .loading::after {
    animation-duration: 2s;
  }
}

/* --- Мини-аудит -------------------------------------------------------- */

.mini-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px;
  margin-bottom: 18px;
}

.mini-score {
  display: flex;
  align-items: center;
  gap: 20px;
}

.gauge-lg {
  width: 96px;
  height: 96px;
}

.gauge-lg span {
  font-size: var(--text-display);
}

.mini-verdict {
  font-size: var(--text-section);
  font-weight: 660;
  letter-spacing: -0.02em;
}

.mini-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.highlight {
  display: grid;
  grid-template-columns: 30px 1fr;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
  font-size: var(--text-body);
  color: var(--ink-soft);
}

.highlight:last-child {
  border-bottom: 0;
}

.highlight-no {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  display: grid;
  place-items: center;
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 640;
  font-size: var(--text-meta);
}

/* Зона раскрывается по щелчку: девять развёрнутых списков сразу
   невозможно читать, а свёрнутый светофор виден целиком. */
details.zone {
  border-bottom: 1px solid var(--line);
}

details.zone:last-child {
  border-bottom: 0;
}

details.zone summary {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 20px;
  cursor: pointer;
  list-style: none;
}

details.zone summary::-webkit-details-marker {
  display: none;
}

.zone-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.zone-title {
  font-weight: 545;
  flex: 1;
}

.zone-score {
  font-size: var(--text-meta);
  white-space: nowrap;
}

.zone-body {
  padding: 0 20px 16px 42px;
}

.zone-why {
  margin: 0 0 12px;
  font-size: var(--text-meta);
  color: var(--muted);
  max-width: 90ch;
}

.zone-finding {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
  font-size: var(--text-body);
  color: var(--ink-soft);
}

.zone-amount {
  font-weight: 570;
  color: var(--ink);
  white-space: nowrap;
}

.zone-clean {
  font-size: var(--text-body);
  color: var(--positive);
}

.plan-block {
  padding: 14px 20px;
  border-bottom: 1px solid var(--line);
}

.plan-block:last-child {
  border-bottom: 0;
}

.plan-title {
  font-size: var(--text-micro);
  font-weight: 620;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.plan-item {
  padding: 7px 0;
  font-size: var(--text-body);
}

.plan-zone {
  font-size: var(--text-meta);
  color: var(--muted);
}

/* --- Окно поверх страницы --------------------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(9, 16, 22, 0.55);
  backdrop-filter: blur(3px);
}

.modal-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 26px 24px;
}

.modal-card h2 {
  margin: 0;
  font-size: var(--text-section);
  letter-spacing: -0.02em;
}

.modal-hint {
  margin: 8px 0 0;
  font-size: var(--text-body);
  color: var(--muted);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

.field-hint {
  font-size: var(--text-micro);
  color: var(--muted);
}

/* --- Мастер подключения ------------------------------------------------ */

.form-body {
  padding: 20px;
  display: grid;
  gap: 14px;
}

.form-body .field {
  margin-top: 0;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

@media (max-width: 620px) {
  .field-row {
    grid-template-columns: 1fr;
  }
}

.hint-text {
  color: var(--ink-soft);
  font-size: var(--text-body);
  margin: 0;
  max-width: 78ch;
}

.hint-text code {
  font-size: var(--text-meta);
  background: var(--ground-deep);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
  word-break: break-all;
}

.msg.ok {
  display: block;
  background: var(--positive-soft);
  color: var(--positive);
  border: 1px solid color-mix(in srgb, var(--positive) 28%, transparent);
}

.form-body .btn {
  justify-self: start;
}

.tunnel-pick {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
  font-size: var(--text-body);
  color: var(--ink-soft);
}

.tunnel-pick input {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  accent-color: var(--brand);
}

.tunnel-pick small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--text-meta);
}

.tunnel-pick code {
  font-size: var(--text-micro);
  background: var(--ground-deep);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
}

.org-row {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-top: 10px;
  background: var(--ground);
}

.org-pick {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 10px;
  align-items: start;
  cursor: pointer;
}

.org-pick input {
  width: 17px;
  height: 17px;
  margin-top: 3px;
  accent-color: var(--brand);
}

.org-name {
  display: block;
  font-weight: 570;
}

.org-inn {
  display: block;
  font-size: var(--text-meta);
  color: var(--muted);
}

.org-fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 12px;
  padding-left: 30px;
}

.tax-history {
  margin-top: 12px;
  padding-left: 30px;
}

.tax-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: var(--text-meta);
  color: var(--muted);
  font-weight: 540;
  margin-bottom: 8px;
}

.tax-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 150px auto;
  gap: 10px;
  margin-bottom: 8px;
  align-items: center;
}

@media (max-width: 620px) {
  .tax-row {
    grid-template-columns: 1fr;
  }
}

.btn-small {
  padding: 6px 12px;
  font-size: var(--text-meta);
}

.chip.missing {
  background: var(--critical-soft);
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 25%, transparent);
}

.chip.ok {
  background: var(--positive-soft);
  color: var(--positive);
  border-color: color-mix(in srgb, var(--positive) 22%, transparent);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
}

.chip {
  font-size: var(--text-meta);
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--ground-deep);
  color: var(--ink-soft);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
