:root {
  color-scheme: light;
  --bg: #f2f4f7;
  --surface: #ffffff;
  --surface-soft: #f6f7f9;
  --border: #e1e5eb;
  --border-soft: #edf0f4;
  --control-border: #c9d0db;
  --text: #161b26;
  --text-2: #2c3442;
  --muted: #5a6372;
  --primary: #1e5eff;
  --primary-dark: #1647cc;
  --primary-soft: #e8eeff;
  --primary-text: #1a47c2;
  --ok-bg: #e4f4ea;
  --ok: #12693f;
  --warn-bg: #fff1d6;
  --warn: #8a4b00;
  --bad-bg: #fce8e6;
  --bad: #a3211a;
  --danger: #b42318;
  --radius-card: 16px;
  --radius-control: 10px;
  --ease: cubic-bezier(.22, .8, .36, 1);
  font-family: system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button:focus-visible, input:focus-visible, textarea:focus-visible, .file-btn:focus-within {
  outline: 3px solid rgba(30, 94, 255, .28);
  outline-offset: 2px;
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }
h3 { font-size: 16px; }
p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.icon { width: 16px; height: 16px; flex: 0 0 auto; }

/* Каркас: кабинеты слева, всё остальное — одной лентой справа */
.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 16px 16px 40px;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: flex-start;
}
.content { flex: 999 1 640px; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 20px 24px; }
.loading-card { text-align: center; color: var(--muted); padding: 36px; }
.card-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px 16px; }

/* Боковая панель */
.sidebar {
  flex: 1 1 220px;
  max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.side-title { padding: 6px 10px 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.side-item {
  text-align: left;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  padding: 10px;
  background: transparent;
  display: flex;
  flex-direction: column;
  gap: 2px;
  cursor: pointer;
  min-height: 56px;
  transition: background .15s var(--ease);
}
.side-item:hover { background: var(--surface-soft); }
.side-item.active { background: #eef3ff; border-color: #c9d7ff; }
.side-item.active .side-name { color: #1a3a8f; }
.side-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.side-sub { font-size: 12px; color: var(--muted); padding-left: 16px; }
.side-meta { margin-top: 10px; padding: 12px 10px 4px; border-top: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.side-meta b { color: var(--text); font-weight: 600; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: 0 0 auto; background: #9aa3b2; }
.dot.ok { background: var(--ok); }
.dot.info { background: var(--primary); }
.dot.bad { background: var(--danger); }

/* Баннеры */
.banners { display: flex; flex-direction: column; gap: 10px; }
.banners:empty { display: none; }
.banner { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; padding: 14px 16px; border-radius: 12px; border: 1px solid; }
.banner .icon { width: 20px; height: 20px; }
.banner-text { flex: 1 1 360px; min-width: 0; }
.banner-title { font-weight: 600; }
.banner-sub { font-size: 13px; }
.banner.bad { background: var(--bad-bg); border-color: #f3b8b2; color: #7a1a14; }
.banner.warn { background: var(--warn-bg); border-color: #f0ce8c; color: #6b3a00; }
.banner.muted { background: #eef0f3; border-color: #d5dbe4; color: var(--text-2); }

/* Кнопки */
.btn {
  height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--control-border);
  background: var(--surface);
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
  transition: background .15s var(--ease), border-color .15s var(--ease);
}
.btn:hover { background: var(--surface-soft); }
.btn-sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.btn-danger:hover { background: #8f1c13; }
.btn-danger-text { border-color: transparent; background: transparent; color: var(--danger); font-weight: 600; }
.btn-danger-text:hover { background: var(--bad-bg); }
.btn:disabled { cursor: not-allowed; opacity: .55; }
.btn-run { height: 44px; padding: 0 20px; border-radius: 12px; font-size: 15px; font-weight: 600; }
.btn-run:disabled { opacity: 1; background: var(--surface); border-color: #d5dbe4; color: #7a8394; }
.btn-run.is-busy:disabled { background: var(--primary-soft); border-color: var(--primary-soft); color: var(--primary-text); cursor: progress; }
.file-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.file-btn { position: relative; }
fieldset:disabled .file-btn { opacity: .55; cursor: not-allowed; }

/* Переключатель */
.switch {
  width: 44px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 999px;
  border: 0;
  padding: 3px;
  background: var(--control-border);
  cursor: pointer;
  display: flex;
  transition: background .15s var(--ease);
}
.switch span { width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(16, 24, 40, .3); transition: transform .18s var(--ease); }
.switch[aria-checked="true"] { background: var(--primary); }
.switch[aria-checked="true"] span { transform: translateX(18px); }
.switch:disabled { opacity: .5; cursor: not-allowed; }

/* Пилюли статусов */
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: #eef0f3; color: #3b4556; }
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.info { background: var(--primary-soft); color: var(--primary-text); }

/* Сводка кабинета */
.hero { display: flex; flex-direction: column; gap: 18px; padding: 22px 24px; }
.hero-head { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.hero-last { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--muted); }
.keys-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 13px; color: var(--text-2); }
.keys-row .sep { color: #9aa3b2; }
.ok-text { color: var(--ok); font-weight: 600; }
.bad-text { color: var(--bad); font-weight: 600; }
.keys-panel.attention { padding: 12px; border-radius: 12px; background: #fff7f6; border: 1px solid #f3b8b2; }
.keys-panel { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; padding-top: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 200px; min-width: 0; }
.field.wide { flex: 2 1 260px; }
.field label { font-size: 13px; font-weight: 600; }
.input { height: 40px; padding: 0 10px; border-radius: 8px; border: 1px solid var(--control-border); background: #fff; width: 100%; }
.input:focus-visible { border-color: var(--primary); }
.run-panel { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-radius: 12px; background: var(--surface-soft); }
.run-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; }
.schedule { display: flex; align-items: center; gap: 10px; }
.run-note { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; color: var(--muted); }
.run-note .icon { margin-top: 1px; }
.run-note.strong { color: var(--text-2); }
.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.metric { padding: 14px 16px; border-radius: 12px; background: var(--surface-soft); display: flex; flex-direction: column; gap: 2px; }
.metric-label { font-size: 13px; color: var(--muted); }
.metric-value { font-size: 28px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.metric-note { font-size: 13px; color: var(--muted); }
.metric-note.ok { color: var(--ok); }
.metric-note.warn { color: var(--warn); }
.metric-note.bad { color: var(--bad); }
.hero-info { padding: 14px 16px; border-radius: 12px; background: var(--surface-soft); color: var(--text-2); display: flex; gap: 10px; align-items: center; }
.hero-error { padding: 14px 16px; border-radius: 12px; background: var(--bad-bg); border: 1px solid #f3b8b2; color: #7a1a14; display: flex; flex-direction: column; gap: 10px; }
.hero-error-head { display: flex; gap: 10px; align-items: flex-start; }
.hero-error-head .icon { width: 20px; height: 20px; }
.hero-error-text { display: flex; flex-direction: column; gap: 2px; }
.hero-error-title { font-weight: 600; }
.hero-error-raw { font-size: 12px; color: #8a3b35; }
.hero-error-raw summary { cursor: pointer; width: fit-content; }
.hero-error-raw code { display: block; margin-top: 6px; padding: 8px 10px; border-radius: 8px; background: rgba(255, 255, 255, .6); font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.spinner { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 50%; border: 2px solid #c9d7ff; border-top-color: var(--primary); animation: spin .9s linear infinite; }
.onboarding { display: flex; flex-wrap: wrap; gap: 24px 40px; }
.onboarding > div { flex: 1 1 300px; display: flex; flex-direction: column; gap: 12px; }
.onboarding ol { margin: 0; padding-left: 20px; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); }
.eyebrow { font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }

/* Шаги обработки */
.settings { padding: 6px 24px; }
.settings .card-head { padding: 14px 0 4px; }
.steps { border: 0; margin: 0; padding: 0; min-width: 0; }
.step { display: flex; flex-direction: column; gap: 12px; padding: 16px 0; }
.step + .step { border-top: 1px solid var(--border-soft); }
.step-head { display: flex; gap: 14px; align-items: flex-start; }
.step-num { flex: 0 0 auto; width: 28px; height: 28px; border-radius: 8px; background: var(--primary-soft); color: var(--primary-text); display: grid; place-items: center; font-weight: 700; }
.step-num.plain { background: #f2f4f7; color: var(--text-2); }
.step-text { flex: 1; min-width: 0; }
.step-text h3 { margin: 2px 0; }
.step-text p { color: var(--muted); }
.step-head .switch { margin-top: 2px; }
.step-body { display: flex; flex-direction: column; gap: 10px; padding-left: 42px; transition: opacity .15s var(--ease); }
.step-body.is-off { opacity: .45; }
.list-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.list-summary { font-weight: 600; flex: 1; }
.list-label { font-size: 13px; color: var(--muted); }
.list-text { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--control-border); font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.thresholds { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.threshold { display: inline-flex; align-items: center; gap: 8px; padding: 4px 10px 4px 8px; border-radius: 10px; border: 1px solid var(--border); background: #f9fafb; }
.threshold input[type="checkbox"] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.num-input { width: 72px; height: 36px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--control-border); text-align: right; font-variant-numeric: tabular-nums; background: #fff; }
.or { font-size: 12px; font-weight: 700; letter-spacing: .06em; color: var(--muted); }
.example { padding: 14px 16px; border-radius: 12px; display: flex; flex-direction: column; gap: 12px; }
.example.info { background: #eef3ff; color: #1a3a8f; }
.example.warn { background: var(--warn-bg); color: var(--warn); }
.example-head { display: flex; gap: 10px; align-items: flex-start; }
.example-head .icon { width: 18px; height: 18px; margin-top: 1px; }
.example-text { display: flex; flex-direction: column; gap: 4px; }
.example-title { font-weight: 600; }
.example-table-wrap { overflow-x: auto; border-radius: 10px; background: #fff; border: 1px solid #d9e2fa; }
.example-table { width: 100%; min-width: 540px; border-collapse: collapse; font-size: 13px; color: var(--text); font-variant-numeric: tabular-nums; }
.example-table th { padding: 8px 12px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border-soft); }
.example-table td { padding: 9px 12px; border-bottom: 1px solid var(--border-soft); }
.example-table tr:last-child td { border-bottom: 0; }
.example-table .why { margin-left: 8px; color: var(--muted); }
.save-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; margin: 0 -24px; padding: 14px 24px; border-top: 1px solid var(--border-soft); }
.save-row.dirty { background: #161b26; color: #fff; border-radius: 0 0 var(--radius-card) var(--radius-card); border-top-color: #161b26; }
.save-row .btn-ghost { background: transparent; border-color: #3a4456; color: #fff; }
.save-actions { display: flex; gap: 8px; }

/* История */
.history-card { display: flex; flex-direction: column; gap: 10px; }
.table-wrap { overflow-x: auto; }
.history { width: 100%; min-width: 860px; border-collapse: collapse; }
.history th { padding: 8px 10px; text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--border); }
.history td { padding: 10px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
.history .cab { font-weight: 600; }
.history .actions-cell { text-align: right; white-space: nowrap; }
.history .actions-cell .btn + .btn { margin-left: 6px; }
.log-cell { padding: 0 10px 12px !important; }
.log-box { border-radius: 10px; overflow: hidden; border: 1px solid #1f2633; }
.log-box pre { margin: 0; padding: 12px 14px; max-height: 50vh; overflow: auto; background: #141a24; color: #d7e0ee; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.log-tools { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 10px; background: #1b2230; }
.log-tools .btn { background: transparent; border-color: #3a4456; color: #d7e0ee; }

/* Уведомление */
.toast { position: fixed; right: 18px; bottom: 18px; max-width: min(420px, calc(100% - 36px)); background: #202a3a; color: #fff; border-radius: 12px; box-shadow: 0 12px 32px rgba(16, 24, 40, .28); padding: 11px 14px; z-index: 20; }
.toast:not(.hidden) { animation: toast-in .28s var(--ease); }

/* Страница ошибки */
.centered-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.error-card { width: min(560px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; text-align: center; }
.error-card h1 { margin-bottom: 8px; }
.error-card p + p { margin-top: 8px; }
.error-icon { margin: 0 auto 15px; display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--bad-bg); color: var(--danger); font-size: 28px; font-weight: 900; }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

@media (max-width: 760px) {
  .layout { padding: 8px 8px 24px; }
  .card, .hero { padding: 16px; }
  .settings { padding: 4px 16px; }
  .save-row { margin: 0 -16px; padding: 12px 16px; }
  .step-body { padding-left: 0; }
}
