/*
 * UNICORN Orchestra — совет AI-директоров (пилот).
 * Без фреймворка и внешних ресурсов (прокси edge разрешает только ресурсы того же источника).
 */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e3e7ef;
  --text: #141b2d;
  --muted: #667085;
  --faint: #98a2b3;
  --accent: #5146e5;
  --accent-soft: #eeedff;
  --sidebar: #0e1424;
  --sidebar-text: #c5cbe0;
  --critical: #d92d20;
  --critical-soft: #fef3f2;
  --warning: #dc6803;
  --warning-soft: #fffaeb;
  --info: #1570ef;
  --info-soft: #eff8ff;
  --ok: #079455;
  --ok-soft: #ecfdf3;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);

  color: var(--text);
  background: var(--bg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

a {
  color: var(--accent);
}

h1,
h2,
h3,
h4 {
  margin: 0;
  line-height: 1.25;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 13px;
}

.tiny {
  font-size: 12px;
}

/* ---------------------------------------------------------------- разметка */

.shell {
  display: grid;
  grid-template-columns: 250px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 18px;
  height: 100vh;
  padding: 20px 14px;
  background: var(--sidebar);
  color: var(--sidebar-text);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px;
  color: #fff;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, #6d5efc, #3b2fd0);
  font-weight: 800;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-text small {
  color: #8d95b3;
  font-size: 11px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 9px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
}

.nav-link:hover {
  background: rgb(255 255 255 / 6%);
  color: #fff;
}

.nav-link.active {
  background: rgb(109 94 252 / 22%);
  color: #fff;
}

.nav-icon {
  width: 18px;
  text-align: center;
  opacity: 0.8;
}

.nav-badge {
  margin-left: auto;
  min-width: 22px;
  padding: 0 7px;
  border-radius: 20px;
  background: var(--critical);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
}

.sidebar-foot {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: auto;
  padding: 0 10px;
  font-size: 12px;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: #8d95b3;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.health {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.health .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.health--ok .dot {
  background: #32d583;
}

.health--degraded .dot {
  background: #fdb022;
}

.health--down .dot {
  background: #f97066;
}

.view {
  min-width: 0;
  padding: 28px 32px 60px;
  outline: none;
}

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

.page-head h1 {
  font-size: 26px;
}

.page-head p {
  margin: 6px 0 0;
  max-width: 760px;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.grid-kpi {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.grid-cards {
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
}

.two-columns {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.spread {
  justify-content: space-between;
}

/* ---------------------------------------------------------------- карточки */

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

.card h2 {
  font-size: 17px;
}

.card h3 {
  font-size: 15px;
}

.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 12px;
}

.card--accent {
  border-color: #c7c2ff;
  background: linear-gradient(180deg, #fbfaff, #fff 40%);
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.kpi-label {
  color: var(--muted);
  font-size: 13px;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.kpi-value.bad {
  color: var(--critical);
}

.kpi-value.warn {
  color: var(--warning);
}

.kpi-value.good {
  color: var(--ok);
}

.kpi-source {
  color: var(--faint);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

/* ---------------------------------------------------------------- счётчики и метки */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge--ok {
  background: var(--ok-soft);
  border-color: #abefc6;
  color: var(--ok);
}

.badge--critical {
  background: var(--critical-soft);
  border-color: #fecdca;
  color: var(--critical);
}

.badge--warning {
  background: var(--warning-soft);
  border-color: #fedf89;
  color: var(--warning);
}

.badge--info {
  background: var(--info-soft);
  border-color: #b2ddff;
  color: var(--info);
}

.badge--accent {
  background: var(--accent-soft);
  border-color: #d9d6fe;
  color: var(--accent);
}

.chip {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.dot-sev {
  flex: none;
  width: 9px;
  height: 9px;
  margin-top: 6px;
  border-radius: 50%;
  background: var(--info);
}

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

.dot-sev.warning {
  background: var(--warning);
}

/* ---------------------------------------------------------------- списки */

.signal-list,
.plain-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.signal {
  display: flex;
  gap: 10px;
}

.signal strong {
  display: block;
  font-size: 14px;
}

.signal span {
  color: var(--muted);
  font-size: 13px;
}

.bullets {
  margin: 6px 0 0;
  padding-left: 20px;
}

.bullets li + li {
  margin-top: 4px;
}

.facts {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.facts td {
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
  vertical-align: top;
}

.facts td:nth-child(2) {
  padding-left: 12px;
  font-weight: 600;
  white-space: nowrap;
  text-align: right;
}

.source {
  color: var(--faint);
  font-family: ui-monospace, "SFMono-Regular", Consolas, monospace;
  font-size: 11px;
}

/* ---------------------------------------------------------------- таблицы */

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

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.data th {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

table.data td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data tr.bad td {
  background: var(--critical-soft);
}

.num {
  text-align: right;
  white-space: nowrap;
}

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

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

.button:disabled {
  cursor: default;
  opacity: 0.55;
}

.button--primary {
  background: var(--accent);
  color: #fff;
}

.button--primary:hover:not(:disabled) {
  background: #4338ca;
}

.button--ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.button--ok {
  background: var(--ok);
  color: #fff;
}

.button--danger {
  background: var(--surface);
  border-color: #fecdca;
  color: var(--critical);
}

.button--small {
  padding: 6px 12px;
  font-size: 13px;
}

textarea,
input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

select {
  width: auto;
}

textarea {
  resize: vertical;
}

textarea:focus,
input:focus,
select:focus {
  border-color: var(--accent);
  outline: 3px solid rgb(81 70 229 / 15%);
}

.ask textarea {
  min-height: 84px;
  font-size: 16px;
}

.decision input[type="text"] {
  flex: 1;
  width: auto;
  min-width: 200px;
}

label.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- запуск совета */

.question {
  margin: 0;
  padding: 12px 16px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--accent-soft);
  font-size: 17px;
  font-weight: 600;
}

.stepper {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.step {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--faint);
  font-size: 13px;
}

.step strong {
  font-size: 14px;
}

.step.done {
  border-color: #abefc6;
  background: var(--ok-soft);
  color: var(--ok);
}

.step.active {
  border-color: #c7c2ff;
  background: var(--accent-soft);
  color: var(--accent);
}

.step.failed {
  border-color: #fecdca;
  background: var(--critical-soft);
  color: var(--critical);
}

.director {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.director.pending {
  opacity: 0.8;
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.meter {
  height: 6px;
  border-radius: 6px;
  background: var(--surface-2);
  overflow: hidden;
}

.meter > span {
  display: block;
  height: 100%;
  border-radius: 6px;
  background: var(--accent);
}

details {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

details summary {
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

details[open] summary {
  margin-bottom: 8px;
}

.summary-text {
  margin: 0;
  font-size: 16px;
  white-space: pre-wrap;
}

.checks {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px;
}

.check-counter {
  padding: 12px;
  border-radius: 10px;
  background: var(--surface-2);
}

.check-counter strong {
  display: block;
  font-size: 22px;
}

.check-counter.good strong {
  color: var(--ok);
}

.check-counter.bad strong {
  color: var(--critical);
}

.quote {
  margin: 0;
  padding: 10px 14px;
  border-left: 3px solid var(--border);
  background: var(--surface-2);
  border-radius: 6px;
  font-style: italic;
}

.outcome {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  font-size: 13px;
}

.empty {
  padding: 30px;
  color: var(--muted);
  text-align: center;
}

.error-box {
  padding: 12px 14px;
  border: 1px solid #fecdca;
  border-radius: 10px;
  background: var(--critical-soft);
  color: var(--critical);
}

.history-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
}

.history-item:hover,
.history-item.active {
  background: var(--accent-soft);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 16px;
}

.tab {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.tab.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: 10px;
  background: var(--sidebar);
  color: #fff;
  box-shadow: 0 10px 30px rgb(0 0 0 / 25%);
}

.toast.error {
  background: var(--critical);
}

/* ---------------------------------------------------------------- маленькие экраны */

@media (max-width: 1100px) {
  .two-columns {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    padding: 12px;
  }

  .nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .sidebar-foot {
    flex-direction: row;
    flex-wrap: wrap;
    gap: 12px;
  }

  .view {
    padding: 20px 16px 40px;
  }

  .stepper {
    grid-template-columns: repeat(2, 1fr);
  }
}
