/* ============================================================
   Панель расчёта ТКП на БИС — ООО «ГИС» / ЭКОВЭЛЛ
   Дизайн 1:1 с panel.giskns.ru, акцент — тёмно-зелёный
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  --primary: 152 62% 23%;        /* классический тёмно-зелёный (~#146a3a) */
  --primary-foreground: 0 0% 100%;
  --primary-hover: 152 62% 19%;
  --background: 210 20% 98%;
  --foreground: 215 28% 13%;
  --card: 0 0% 100%;
  --card-foreground: 215 28% 13%;
  --muted: 210 20% 94%;
  --muted-foreground: 215 15% 42%;
  --border: 214 18% 87%;
  --destructive: 4 76% 44%;
  --destructive-foreground: 0 0% 100%;
  --warning: 38 92% 42%;
  --warning-bg: 45 93% 94%;
  --success: 152 55% 30%;
  --success-bg: 150 45% 94%;
  --info-bg: 152 30% 95%;
  --radius: 0.375rem;

  --font-sans: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Consolas, monospace;
}

[data-theme='dark'] {
  --background: 215 28% 9%;
  --foreground: 210 20% 92%;
  --card: 215 25% 12%;
  --card-foreground: 210 20% 92%;
  --muted: 215 20% 16%;
  --muted-foreground: 215 12% 62%;
  --border: 215 15% 22%;
  --primary: 152 55% 38%;
  --primary-hover: 152 55% 44%;
  --warning-bg: 38 40% 16%;
  --success-bg: 150 30% 14%;
  --info-bg: 152 20% 13%;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

.mono { font-family: var(--font-mono); }

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: 13px;
  color: hsl(var(--foreground));
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 7px 10px;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid hsl(var(--primary) / 0.4);
  outline-offset: 0;
  border-color: hsl(var(--primary));
}
input:disabled { opacity: 0.55; cursor: not-allowed; }

label {
  display: block;
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  margin-bottom: 4px;
  font-weight: 500;
}

/* ---------- Layout shell ---------- */
.shell {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  border-bottom: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  position: sticky;
  top: 0;
  z-index: 40;
}
.app-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.app-logo {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.app-title-block .app-title {
  font-size: 15px;
  font-weight: 600;
  color: hsl(var(--foreground));
}
.app-title-block .app-subtitle {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
}
.app-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}
.badge-blockers {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: hsl(var(--destructive));
  color: hsl(var(--destructive-foreground));
  font-size: 12px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: var(--radius);
}
.badge-blockers.ok {
  background: hsl(var(--success));
}
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid hsl(var(--border));
  background: hsl(var(--card));
  color: hsl(var(--foreground));
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.btn:hover { background: hsl(var(--muted)); }
.btn-primary {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}
.btn-primary:hover { background: hsl(var(--primary-hover)); }
.btn-ghost {
  border-color: transparent;
  background: transparent;
}
.btn-ghost:hover { background: hsl(var(--muted)); }
.icon-btn {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  color: hsl(var(--muted-foreground));
}
.icon-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

/* ---------- Metrics strip ---------- */
.metrics-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0;
  background: hsl(var(--info-bg));
  border-bottom: 1px solid hsl(var(--border));
}
.metric {
  padding: 12px 20px;
  border-right: 1px solid hsl(var(--border));
}
.metric:last-child { border-right: none; }
.metric-label {
  font-size: 10.5px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
}
.metric-value {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 600;
  color: hsl(var(--foreground));
  margin-top: 2px;
}
.metric-value .unit {
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  font-weight: 400;
  margin-left: 3px;
}

/* ---------- Toolbar (versions) ---------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 20px 0 12px;
}
.toolbar .field { min-width: 200px; flex: 1; }
.toolbar-note {
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 10px;
}
.toolbar-actions {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-left: auto;
  font-size: 12.5px;
}
.link-action {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: hsl(var(--primary));
  font-weight: 500;
  font-size: 12.5px;
}
.link-action:hover { text-decoration: underline; }

/* ---------- Section cards ---------- */
.section-card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.section-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}
.section-header .num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: hsl(var(--card) / 0.6);
  border: 1px solid currentColor;
  border-radius: 4px;
  padding: 1px 6px;
}
.section-header .title {
  font-size: 14px;
  font-weight: 600;
}
.section-header .hint {
  font-size: 11.5px;
  opacity: 0.75;
  font-weight: 400;
}
.section-header .chev { margin-left: auto; opacity: 0.7; transition: transform 0.15s; }
.section-header.collapsed .chev { transform: rotate(-90deg); }

.section-header.tone-blue    { background: hsl(var(--info-bg)); color: hsl(var(--primary)); }
.section-header.tone-green   { background: hsl(var(--success-bg)); color: hsl(var(--success)); }
.section-header.tone-yellow  { background: hsl(var(--warning-bg)); color: hsl(var(--warning)); }
.section-header.tone-neutral { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

.section-body {
  padding: 18px 16px 20px;
}
.section-body.collapsed { display: none; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 860px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.field-group {
  background: hsl(var(--muted) / 0.5);
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  padding: 14px;
}
.field-group-title {
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: hsl(var(--muted-foreground));
  margin-bottom: 12px;
}
.field { margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field-row { display: flex; gap: 10px; align-items: end; }
.field-row .field { flex: 1; margin-bottom: 0; }

.unit-suffix {
  font-size: 11px;
  color: hsl(var(--muted-foreground));
  margin-left: 6px;
}

/* segmented control */
.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.segmented button {
  padding: 6px 12px;
  font-size: 12.5px;
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
  background: hsl(var(--card));
  color: hsl(var(--foreground));
}
.segmented button.active {
  background: hsl(var(--primary));
  border-color: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
}

/* checkbox row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: hsl(var(--info-bg));
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 13px;
}
.checkbox-row input[type="checkbox"] { width: auto; }

/* formula display */
.formula-line {
  font-family: var(--font-mono);
  font-size: 12px;
  color: hsl(var(--muted-foreground));
  background: hsl(var(--muted) / 0.6);
  border-radius: var(--radius);
  padding: 8px 10px;
  margin-top: 8px;
}
.formula-line b { color: hsl(var(--foreground)); font-weight: 600; }

.result-box {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: hsl(var(--info-bg));
  border: 1px solid hsl(var(--border));
}
.result-box .label { font-size: 11.5px; color: hsl(var(--muted-foreground)); text-transform: uppercase; letter-spacing: 0.02em; font-weight: 600; }
.result-box .value { font-family: var(--font-mono); font-size: 19px; font-weight: 700; margin-top: 2px; }

/* alerts */
.alert {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 12.5px;
  margin-top: 10px;
  border: 1px solid transparent;
}
.alert-error { background: hsl(var(--destructive) / 0.1); border-color: hsl(var(--destructive) / 0.35); color: hsl(var(--destructive)); }
[data-theme='dark'] .alert-error { color: #f28b8b; }
.alert-warning { background: hsl(var(--warning-bg)); border-color: hsl(var(--warning) / 0.35); color: hsl(var(--warning)); }
.alert-success { background: hsl(var(--success-bg)); border-color: hsl(var(--success) / 0.3); color: hsl(var(--success)); }
.alert-icon { flex-shrink: 0; margin-top: 1px; }

/* table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: hsl(var(--muted-foreground));
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid hsl(var(--border));
}
.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid hsl(var(--border));
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tfoot td {
  font-weight: 700;
  border-top: 1px solid hsl(var(--border));
  border-bottom: none;
}
.data-table .num-cell { font-family: var(--font-mono); text-align: right; }
.data-table input {
  width: 64px;
  padding: 4px 6px;
  text-align: right;
  font-family: var(--font-mono);
}

.small-note {
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  margin-top: 6px;
}

.divider { height: 1px; background: hsl(var(--border)); margin: 16px 0; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.pill-green { background: hsl(var(--success-bg)); color: hsl(var(--success)); }
.pill-red { background: hsl(var(--destructive)/0.12); color: hsl(var(--destructive)); }
.pill-amber { background: hsl(var(--warning-bg)); color: hsl(var(--warning)); }

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid hsl(var(--border));
  margin-bottom: 16px;
}
.tab-btn {
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: hsl(var(--muted-foreground));
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active {
  color: hsl(var(--primary));
  border-bottom-color: hsl(var(--primary));
  font-weight: 600;
}

.two-col-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 860px) {
  .two-col-summary { grid-template-columns: 1fr; }
}

.kv-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 0;
  border-bottom: 1px dashed hsl(var(--border));
  font-size: 13px;
}
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: hsl(var(--muted-foreground)); }
.kv-row .v { font-family: var(--font-mono); font-weight: 600; }

.footer-note {
  text-align: center;
  font-size: 11.5px;
  color: hsl(var(--muted-foreground));
  padding: 24px 0 8px;
}

/* scroll to top of sticky header offset */
[id] { scroll-margin-top: 80px; }

.info-icon {
  display: inline-flex;
  width: 13px;
  height: 13px;
  color: hsl(var(--muted-foreground));
  vertical-align: -1px;
  margin-left: 3px;
}

/* ── Шапка на телефоне ───────────────────────────────────────────────────────
   На узком экране длинное название рвалось на четыре строки, а бейдж и кнопки
   сжимались в неразборчивый столбик. Ставим два ряда: бренд сверху, действия
   под ним, и запрещаем разрыв внутри заголовка. */
@media (max-width: 640px) {
  .app-header {
    flex-wrap: wrap;
    gap: 10px 12px;
    padding: 12px 14px;
  }
  .app-header-left {
    flex: 1 1 100%;
    min-width: 0;
    gap: 10px;
  }
  .app-title-block { min-width: 0; }
  .app-title-block .app-title {
    font-size: 14.5px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .app-title-block .app-subtitle {
    font-size: 10.5px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .app-header-right {
    flex: 1 1 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 8px;
  }
  .badge-blockers { white-space: nowrap; }
  .app-header-right .btn { white-space: nowrap; }
}

/* На телефоне заголовок раздела и пояснение к нему не влезают в одну строку —
   пояснение уходит под заголовок, номер и стрелка остаются на месте. */
@media (max-width: 640px) {
  .section-header {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 11px 14px;
  }
  .section-header .num { margin-top: 1px; }
  /* Порядком добиваемся строки «номер — заголовок — стрелка», пояснение под ней. */
  .section-header .num   { order: 0; }
  .section-header .title { order: 1; flex: 1 1 auto; min-width: 0; }
  .section-header .chev  { order: 2; margin-left: auto; align-self: center; }
  .section-header .hint  { order: 3; flex: 1 1 100%; }
}
