:root {
  color-scheme: dark;
  --bg: #0a0a0b;
  --panel: #111113;
  --panel-raised: #161618;
  --text: #ededee;
  --muted: #8b8b93;
  --faint: #55555e;
  --line: #252529;
  --line-strong: #34343a;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-soft: rgba(129, 140, 248, .11);
  --danger: #f87171;
  --success: #34d399;
  --shadow: 0 18px 60px rgba(0, 0, 0, .24);
  --font-body: 'Hanken Grotesk', system-ui, sans-serif;
  --font-display: 'Instrument Serif', Georgia, serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
  --sidebar-width: 264px;
}

[data-theme='light'] {
  color-scheme: light;
  --bg: #f4f3f0;
  --panel: #fbfaf8;
  --panel-raised: #ffffff;
  --text: #202023;
  --muted: #6f6f75;
  --faint: #a5a3a0;
  --line: #dfddd8;
  --line-strong: #c9c6c0;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, .08);
  --danger: #dc2626;
  --success: #059669;
  --shadow: 0 18px 60px rgba(54, 50, 43, .10);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

a {
  color: inherit;
}

::selection {
  background: var(--accent);
  color: #0a0a0b;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.hidden {
  display: none !important;
}

.brand,
.login-brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -.035em;
  text-decoration: none;
}

.brand-mark {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.eyebrow,
.breadcrumb,
.environment,
.nav-group,
.login-foot,
.header-status,
.content-rule,
.nav-index {
  font-family: var(--font-mono);
  letter-spacing: .075em;
  text-transform: uppercase;
}

/* Login is deliberately quiet: credentials remain the only focal point. */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px;
}

.login-frame {
  width: min(100%, 960px);
  position: relative;
  padding: 26px;
  border: 1px solid var(--line);
}

.login-frame::before,
.login-frame::after {
  content: '';
  position: absolute;
  background: var(--accent);
}

.login-frame::before {
  width: 24px;
  height: 1px;
  left: -1px;
  top: -1px;
}

.login-frame::after {
  width: 1px;
  height: 24px;
  left: -1px;
  top: -1px;
}

.login-brand {
  position: absolute;
  top: 25px;
  left: 26px;
}

.login-card {
  width: min(100%, 430px);
  margin: 58px auto 48px;
  padding: 48px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.login-card .eyebrow {
  margin: 0 0 28px;
  color: var(--accent);
  font-size: 10px;
}

.login-card h1 {
  margin: 0;
  font-family: var(--font-body);
  font-size: clamp(42px, 7vw, 64px);
  line-height: .9;
  letter-spacing: -.065em;
  font-weight: 600;
}

.login-card h1 em {
  color: var(--muted);
  font-family: var(--font-display);
  font-weight: 400;
  letter-spacing: -.02em;
}

.login-note {
  max-width: 310px;
  margin: 27px 0 31px;
  color: var(--muted);
}

.login-form {
  display: grid;
}

.login-form label {
  margin: 15px 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.login-form input {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 0;
}

.login-form input:focus {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
}

.form-error {
  min-height: 21px;
  margin: 9px 0 5px;
  color: var(--danger);
  font-size: 12px;
}

.button {
  min-height: 46px;
  border: 1px solid transparent;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 600;
}

.button-primary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--accent);
  color: #0a0a0b;
}

.button-primary:hover {
  background: var(--accent-hover);
}

.button:disabled {
  cursor: wait;
  opacity: .55;
}

.login-foot {
  margin: 0;
  color: var(--faint);
  font-size: 9px;
}

/* App shell */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  z-index: 30;
  top: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.environment {
  color: var(--faint);
  font-size: 8px;
}

.sidebar-nav {
  flex: 1;
  padding: 17px 13px;
  overflow: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.nav-section+.nav-section {
  margin-top: 22px;
}

.nav-group {
  margin: 0 9px 7px;
  color: var(--faint);
  font-size: 9px;
  font-weight: 500;
}

.nav-link {
  position: relative;
  display: grid;
  grid-template-columns: 27px 1fr 16px;
  align-items: center;
  min-height: 38px;
  padding: 0 9px;
  color: var(--muted);
  text-decoration: none;
  border-left: 1px solid transparent;
}

.nav-index {
  color: var(--faint);
  font-size: 8px;
}

.nav-arrow {
  opacity: 0;
  color: var(--accent);
  transform: translate(-3px, 3px);
}

.nav-link:hover {
  color: var(--text);
  background: var(--accent-soft);
}

.nav-link.active {
  color: var(--text);
  background: var(--accent-soft);
  border-left-color: var(--accent);
}

.nav-link.active .nav-index {
  color: var(--accent);
}

.nav-link.active .nav-arrow {
  opacity: 1;
  transform: translate(0, 0);
}

.sidebar-foot {
  min-height: 64px;
  padding: 0 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.status-dot {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 5px;
  border-radius: 50%;
  background: var(--success);
}

.text-button {
  padding: 4px 0;
  border: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.text-button:hover {
  color: var(--text);
}

.main-content {
  min-width: 0;
  padding: 0 clamp(24px, 4.5vw, 72px) 48px;
}

.content-header {
  min-height: 132px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.title-block {
  min-width: 0;
}

.breadcrumb {
  margin: 0 0 7px;
  color: var(--faint);
  font-size: 9px;
}

.breadcrumb span {
  color: var(--accent);
  padding: 0 4px;
}

.content-header h1 {
  margin: 0;
  font-size: clamp(32px, 4vw, 48px);
  line-height: 1;
  font-weight: 600;
  letter-spacing: -.055em;
}

.header-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 15px;
}

.header-status {
  color: var(--muted);
  font-size: 8px;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: inline-grid;
  place-items: center;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  cursor: pointer;
}

.icon-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-raised);
}

.menu-toggle {
  display: none;
}

.menu-toggle span {
  display: block;
  width: 14px;
  height: 1px;
  background: currentColor;
}

.menu-toggle span+span {
  margin-top: 5px;
  width: 9px;
  justify-self: start;
  margin-left: 11px;
}

.content-rule {
  height: 27px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  color: var(--faint);
  font-size: 8px;
  padding-top: 7px;
}

.page-outlet {
  min-height: 360px;
  animation: page-enter 120ms ease-out both;
}

/* Shared routed states. Future page tasks can replace these without changing shell geometry. */
.page-state {
  min-height: 340px;
  display: grid;
  align-content: center;
  justify-items: start;
  position: relative;
  padding: clamp(28px, 5vw, 64px);
  background: var(--panel);
  border: 1px solid var(--line);
}

.page-state::before {
  content: '○';
  position: absolute;
  right: clamp(24px, 6vw, 76px);
  top: 50%;
  color: var(--line-strong);
  font: 100px/1 var(--font-display);
  transform: translateY(-50%);
}

.page-state .state-code {
  margin: 0 0 28px;
  color: var(--accent);
  font: 9px/1 var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.page-state h2 {
  position: relative;
  margin: 0 0 10px;
  max-width: 560px;
  font-family: var(--font-display);
  font-size: clamp(34px, 5vw, 56px);
  font-weight: 400;
  line-height: .96;
}

.page-state p {
  position: relative;
  max-width: 500px;
  margin: 0;
  color: var(--muted);
}

.page-state button {
  position: relative;
  min-height: 40px;
  margin-top: 20px;
  padding: 8px 14px;
  color: #0a0a0b;
  background: var(--accent);
  border: 0;
  font-weight: 600;
  cursor: pointer;
}

.page-state--loading {
  min-height: 340px;
  align-content: end;
}

.page-state--loading::after {
  content: '';
  position: absolute;
  left: clamp(28px, 5vw, 64px);
  top: clamp(28px, 5vw, 64px);
  width: min(62%, 520px);
  height: 82px;
  border-top: 12px solid var(--line-strong);
  border-bottom: 42px solid var(--line);
  opacity: .55;
}

.page-skeleton {
  min-height: 340px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.page-skeleton::before,
.page-skeleton::after {
  content: '';
  background: var(--panel);
}

.toast-region {
  position: fixed;
  z-index: 80;
  right: 20px;
  bottom: 20px;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 40px));
}

#modalHost {
  position: relative;
  z-index: 90;
}

.drawer-backdrop {
  display: none;
}

@keyframes page-enter {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 840px) {
  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    left: 0;
    width: min(86vw, var(--sidebar-width));
    transform: translateX(-102%);
    box-shadow: var(--shadow);
  }

  .sidebar.drawer-open {
    transform: translateX(0);
  }

  .drawer-backdrop {
    position: fixed;
    z-index: 25;
    inset: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(0, 0, 0, .56);
    opacity: 0;
    pointer-events: none;
    display: block;
  }

  .drawer-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
  }

  body.drawer-active {
    overflow: hidden;
  }

  .main-content {
    padding-inline: 20px;
  }

  .content-header {
    min-height: 104px;
  }

  .menu-toggle {
    display: inline-grid;
  }

  .header-status {
    display: none;
  }

  .page-state::before {
    display: none;
  }
}

@media (max-width: 520px) {
  .login-page {
    padding: 14px;
  }

  .login-frame {
    padding: 18px;
  }

  .login-brand {
    top: 18px;
    left: 18px;
  }

  .login-card {
    margin: 48px 0 36px;
    padding: 34px 24px;
  }

  .main-content {
    padding-inline: 15px;
  }

  .content-header {
    gap: 12px;
  }

  .content-header h1 {
    font-size: 30px;
  }

  .theme-toggle {
    width: 36px;
    height: 36px;
  }

  .page-state {
    min-height: 300px;
    padding: 28px 22px;
  }

  .page-skeleton {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: no-preference) {

  .nav-link,
  .nav-arrow,
  .icon-button,
  .button,
  .sidebar,
  .drawer-backdrop {
    transition: opacity 120ms ease, transform 120ms ease;
  }
}

@media (prefers-reduced-motion: reduce) {

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* Operational pages */
.overview-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 1px;
  margin-bottom: 18px;
  background: var(--line);
  border: 1px solid var(--line);
}

.metric-card {
  min-height: 156px;
  padding: 22px;
  background: var(--panel);
}

.metric-card__label {
  margin: 0 0 24px;
  color: var(--muted);
  font: 9px/1 var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: clamp(25px, 3vw, 38px);
  line-height: 1;
  letter-spacing: -.045em;
}

.metric-card p:last-child {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.page-panel {
  background: var(--panel);
  border: 1px solid var(--line);
}

.page-panel__head {
  min-height: 88px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 19px 22px;
  border-bottom: 1px solid var(--line);
}

.page-panel__head .eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 8px;
}

.page-panel__head h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.035em;
}

.button-secondary {
  color: var(--text);
  background: transparent;
  border-color: var(--line-strong);
}

.button-danger {
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}

.source-list {
  display: grid;
}

.source-list>div {
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-top: 1px solid var(--line);
}

.source-list>div:first-child {
  border-top: 0;
}

.source-list span {
  color: var(--muted);
}

.muted-copy {
  padding: 22px;
  margin: 0;
  color: var(--muted);
}

.search-field {
  display: grid;
  grid-template-columns: auto minmax(180px, 420px);
  align-items: center;
  justify-content: end;
  gap: 12px;
  min-height: 66px;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
}

.search-field input,
.modal-field__control {
  width: 100%;
  min-height: 40px;
  padding: 8px 11px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: 0;
}

.table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}

.data-table th {
  padding: 10px 14px;
  color: var(--faint);
  background: var(--bg);
  font: 8px/1 var(--font-mono);
  letter-spacing: .07em;
  text-transform: uppercase;
  white-space: nowrap;
}

.data-table td {
  padding: 14px;
  border-top: 1px solid var(--line);
  vertical-align: top;
}

/* Pinned last column: wide tables scroll inside .table-wrap, so the
   actions (Скрыть и т.д.) would slide out of view — keep them visible. */
.data-table th:last-child,
.data-table td:last-child {
  position: sticky;
  right: 0;
  z-index: 1;
  background: var(--panel);
  box-shadow: -1px 0 0 var(--line);
}

.data-table thead th:last-child {
  background: var(--bg);
}

.models-table .model-detail-row>td {
  position: static;
  box-shadow: none;
}

.models-table .model-row:hover>td:last-child {
  background: color-mix(in srgb, var(--accent-soft) 46%, var(--panel));
}

.models-table .model-row.is-expanded>td:last-child {
  background: color-mix(in srgb, var(--accent) 11%, var(--panel));
}

/* Models table: pin expander + model name on the left as well — the row
   reads "name … actions" no matter the scroll position. border-collapse:
   separate avoids the sticky-cell rendering artifacts of collapsed borders. */
.models-table {
  border-collapse: separate;
  border-spacing: 0;
}

.models-table th:first-child,
.models-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--panel);
}

.models-table th:nth-child(2),
.models-table td:nth-child(2) {
  position: sticky;
  left: 42px;
  z-index: 1;
  background: var(--panel);
  box-shadow: 1px 0 0 var(--line);
}

.models-table thead th:first-child,
.models-table thead th:nth-child(2) {
  background: var(--bg);
}

.models-table .model-row:hover>td:first-child,
.models-table .model-row:hover>td:nth-child(2) {
  background: color-mix(in srgb, var(--accent-soft) 46%, var(--panel));
}

.models-table .model-row.is-expanded>td:first-child,
.models-table .model-row.is-expanded>td:nth-child(2) {
  background: color-mix(in srgb, var(--accent) 11%, var(--panel));
}



.data-table td strong,
.data-table td small {
  display: block;
}

.data-table td small {
  margin-top: 4px;
  color: var(--muted);
}

.data-table--keys {
  min-width: 1040px;
}

.mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 10px;
}

.status-pill.is-success {
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 40%, var(--line));
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  min-width: 240px;
}

.row-actions button {
  min-height: 29px;
  padding: 4px 7px;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 10px;
}

.row-actions button:hover {
  color: var(--text);
  border-color: var(--accent);
}

.row-actions button:disabled {
  cursor: wait;
  opacity: .42;
}

.row-actions .danger-link {
  color: var(--danger);
}

.inline-empty {
  min-height: 220px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 5px;
  color: var(--muted);
}

.inline-empty strong {
  color: var(--text);
  font-size: 18px;
}

.page-feedback {
  min-height: 42px;
  margin: 0;
  padding: 11px 22px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.page-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  padding: 22px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.page-heading h2 {
  margin: 4px 0;
  font-size: 26px;
  letter-spacing: -.04em;
}

.page-heading p {
  margin: 0;
  color: var(--muted);
}

.page-heading .eyebrow {
  color: var(--accent);
  font: 8px/1 var(--font-mono);
  letter-spacing: .08em;
  text-transform: uppercase;
}

/* auto-fit collapses unused tracks — no empty "ghost" cells when metric count ≠ 4 */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1px;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--line);
}

.metric-grid article {
  min-height: 88px;
  padding: 16px;
  background: var(--panel);
}

.metric-grid span,
.metric-grid strong {
  display: block;
}

.metric-grid span {
  color: var(--faint);
  font: 8px/1 var(--font-mono);
  text-transform: uppercase;
}

.metric-grid strong {
  margin-top: 12px;
  font-size: 23px;
}

.metric-grid .metric-hint {
  margin: 10px 0 0;
  color: var(--muted, var(--faint));
  font: 11px/1.35 var(--font-mono);
}

.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.page-toolbar .search-field {
  flex: 1;
  justify-content: start;
  border: 0;
}

.page-toolbar .page-feedback {
  flex: 1;
  border: 0;
  text-align: right;
}

.data-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-top: 0;
  background: var(--panel);
}

.plans-table {
  min-width: 900px;
}

.models-summary {
  color: var(--muted);
  font-size: 10px;
}

.modal-field__help {
  color: var(--faint);
  font-size: 10px;
}

.subtabs {
  display: flex;
  gap: 20px;
  margin-top: 14px;
  padding: 0 22px;
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.subtabs a,
.subtabs button {
  padding: 15px 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
  text-decoration: none;
  cursor: pointer;
}

.subtabs a:hover,
.subtabs a.active,
.subtabs button:hover,
.subtabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 14px;
}

.setting-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-top: 1px solid var(--line);
}

.setting-row strong,
.setting-row small {
  display: block;
}

.setting-row small {
  color: var(--muted);
}

.provider-workspace {
  display: grid;
  grid-template-columns: minmax(330px, .9fr) minmax(420px, 1.1fr);
  gap: 14px;
  margin-top: 14px;
  max-width: 100%;
}

.provider-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  align-content: start;
}

.provider-card {
  display: grid;
  gap: 9px;
  min-height: 118px;
  padding: 14px;
  color: var(--muted);
  background: var(--panel);
  border: 1px solid var(--line);
  text-align: left;
  cursor: pointer;
}

.provider-card:hover,
.provider-card.selected {
  color: var(--text);
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.provider-card__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
}

.provider-card[draggable='true'] {
  cursor: grab;
}

.provider-card.is-dragging {
  opacity: .48;
  cursor: grabbing;
}

.provider-card__indicators {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.provider-card__drag {
  color: var(--faint);
  font: 14px/1 var(--font-mono);
  letter-spacing: -2px;
  user-select: none;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--faint);
}

.health-dot.is-ok {
  background: var(--success);
}

.health-dot.is-bad {
  background: var(--danger);
}

.provider-detail {
  min-height: 480px;
  padding: 20px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.provider-detail>header {
  display: flex;
  align-items: start;
  justify-content: space-between;
}

.provider-detail h3 {
  margin: 4px 0 0;
  font-size: 24px;
}

.detail-tabs {
  display: flex;
  gap: 14px;
  margin: 18px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.detail-tabs button {
  padding: 9px 0;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
}

.detail-tabs button.active {
  color: var(--text);
  border-color: var(--accent);
}

.provider-model-list {
  max-height: 380px;
  overflow: auto;
  border: 1px solid var(--line);
}

.provider-model-list>div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.provider-model-list>div:first-child {
  border-top: 0;
}

.provider-model-list span {
  color: var(--muted);
}

.provider-health {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
}

.provider-health>div {
  padding: 15px;
  background: var(--bg);
}

.provider-health span,
.provider-health strong {
  display: block;
}

.provider-health span {
  color: var(--faint);
  font-size: 9px;
}

.provider-health strong {
  margin-top: 8px;
}

.provider-settings dl {
  display: grid;
  gap: 1px;
  background: var(--line);
}

.provider-settings dl div {
  display: flex;
  justify-content: space-between;
  padding: 12px;
  background: var(--bg);
}

.provider-settings dd {
  margin: 0;
}

.system-health,
.incidents-panel,
.analytics-page .page-panel {
  margin-top: 14px;
}

.provider-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}

.provider-chip {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 5px 9px;
  padding: 14px;
  border-right: 1px solid var(--line);
  border-top: 1px solid var(--line);
  color: var(--text);
  text-decoration: none;
}

.provider-chip span {
  grid-column: 2;
  color: var(--muted);
  font-size: 10px;
}

.incident-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.incident-filters select,
.incident-filters input {
  min-height: 38px;
  padding: 7px 9px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line-strong);
}

.analytics-bars {
  padding: 18px;
}

.analytics-bars>div {
  display: grid;
  grid-template-columns: 90px 1fr 70px;
  align-items: center;
  gap: 10px;
  margin: 8px 0;
}

.analytics-bars i {
  height: 8px;
  width: var(--value);
  max-width: 100%;
  background: var(--accent);
}

.analytics-bars strong {
  text-align: right;
}

@media (max-width: 760px) {
  .page-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .page-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .page-toolbar .page-feedback {
    text-align: left;
  }

  .subtabs {
    overflow-x: auto;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }

  .setting-row {
    grid-template-columns: 1fr auto;
  }

  .setting-row .row-actions {
    grid-column: 1 / -1;
  }

  .provider-workspace {
    grid-template-columns: 1fr;
  }

  .provider-card-grid {
    grid-template-columns: 1fr;
  }
}

/* Models / pricing: dense operational ledger with provider-level drill-down. */
.models-panel {
  overflow: hidden;
}

.models-toolbar {
  display: grid;
  grid-template-columns: minmax(230px, 1.35fr) minmax(160px, .65fr) minmax(190px, .75fr) auto;
  gap: 10px;
  padding: 16px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 86%, var(--bg));
}

.models-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 10px;
}

.models-toolbar input,
.models-toolbar select,
.model-editor input,
.model-editor select {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  color: var(--text);
  background: var(--bg);
}

.models-toolbar input:focus,
.models-toolbar select:focus,
.model-editor input:focus,
.model-editor select:focus {
  border-color: var(--accent);
  outline: 1px solid var(--accent);
}

.models-toolbar .page-feedback {
  grid-column: 1 / -1;
  min-height: 0;
  padding: 2px 0 0;
  border-top: 0;
  font-size: 12px;
  color: var(--muted);
}

.models-toolbar .page-feedback:not(:empty) {
  padding-top: 8px;
}

.models-reset {
  align-self: end;
  min-height: 40px;
}

.models-segments {
  min-height: 50px;
  display: flex;
  align-items: stretch;
  gap: 0;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
}

.models-segments button {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.models-segments button:hover {
  color: var(--text);
}

.models-segments button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.models-segments button span {
  min-width: 19px;
  padding: 1px 5px;
  color: var(--faint);
  background: var(--bg);
  font: 9px/1.6 var(--font-mono);
  text-align: center;
}

.models-segments p {
  margin: 0 0 0 auto;
  align-self: center;
  color: var(--faint);
  font: 9px/1 var(--font-mono);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.models-table {
  min-width: 1120px;
}

.models-table th:first-child,
.models-table td:first-child {
  width: 42px;
  padding-right: 0;
}

.models-table tbody>.model-row:hover {
  background: color-mix(in srgb, var(--accent-soft) 46%, transparent);
}

.models-table .model-row.is-expanded {
  background: var(--accent-soft);
}

.model-expand {
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font: 15px/1 var(--font-mono);
}

.model-expand:hover,
.model-row.is-expanded .model-expand {
  color: var(--accent-hover);
  border-color: var(--accent);
}

.model-name {
  max-width: 240px;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  font-size: 12px;
}

.model-price {
  white-space: nowrap;
  font: 12px/1 var(--font-mono);
}

.warning-copy {
  color: #fbbf24 !important;
}

.status-pill.is-muted {
  color: var(--faint);
}

.status-pill.is-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 42%, var(--line));
}

.provider-badges {
  max-width: 420px;
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.provider-badge {
  display: inline-grid;
  grid-template-columns: 7px auto;
  align-items: center;
  gap: 3px 6px;
  min-height: 33px;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  color: var(--text);
  background: var(--panel-raised);
  font-size: 10px;
  line-height: 1;
}

.provider-badge i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--faint);
}

.provider-badge small {
  grid-column: 2;
  margin: 0 !important;
  color: var(--faint) !important;
  font: 7px/1 var(--font-mono);
  letter-spacing: .05em;
  text-transform: uppercase;
}

.provider-badge.is-healthy i,
.provider-badge.is-available i {
  background: var(--success);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 14%, transparent);
}

.provider-badge.is-manual-hidden i {
  background: var(--faint);
}

.provider-badge.is-runtime-hidden i {
  background: #fbbf24;
}

.provider-badge.is-unavailable i {
  background: var(--danger);
}

/* Pinned actions: one compact row, never stacked vertically. Buttons keep
   their natural width — a shrinking flex item is what made them overlap. */
.model-actions {
  flex-wrap: nowrap;
  gap: 4px;
  min-width: 0;
}

.model-actions>button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.model-detail-row>td {
  padding: 0 !important;
  background: var(--bg);
  border-top-color: var(--accent) !important;
}

.model-detail {
  padding: 22px;
  border-bottom: 1px solid var(--line-strong);
  box-shadow: inset 3px 0 0 var(--accent);
}

.model-detail__head {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.model-detail__head .eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 8px;
}

.model-detail__head h3 {
  margin: 0;
  font: 21px/1.1 var(--font-mono);
  letter-spacing: -.04em;
}

.model-detail__head>span {
  color: var(--faint);
  font: 9px/1 var(--font-mono);
  text-transform: uppercase;
}

.model-detail__actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.model-detail__actions>span {
  color: var(--faint);
  font: 9px/1 var(--font-mono);
  text-transform: uppercase;
}

.model-provider-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.model-provider-card {
  min-width: 0;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--panel);
}

.model-provider-card>header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.model-provider-card>header>div {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.model-provider-card>header strong {
  overflow-wrap: anywhere;
  font: 11px/1.3 var(--font-mono);
}

.model-provider-card__id {
  flex: none;
  color: var(--faint);
  font: 8px/1 var(--font-mono);
}

.provider-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
  margin: 14px 0;
}

.provider-facts div {
  min-width: 0;
}

.provider-facts dt {
  color: var(--faint);
  font: 8px/1 var(--font-mono);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.provider-facts dd {
  margin: 5px 0 0;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 10px;
}

.model-editor {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.model-editor label {
  min-width: 0;
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 9px;
}

.model-editor input,
.model-editor select {
  min-height: 36px;
  font-size: 11px;
}

.model-editor input[aria-invalid='true'] {
  border-color: var(--danger);
}

.model-editor__error {
  grid-column: 1 / -1;
  min-height: 16px;
  margin: 0;
  color: var(--danger);
  font-size: 10px;
}

.model-editor__actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  gap: 7px;
}

.model-editor__actions .button {
  min-height: 35px;
  padding-block: 6px;
  font-size: 10px;
}

/* Dependency-free accessible modal system. */
body.modal-active {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, .68);
}

.admin-modal {
  width: min(100%, 640px);
  max-height: min(88dvh, 820px);
  display: flex;
  flex-direction: column;
  color: var(--text);
  background: var(--panel-raised);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow);
}

.admin-modal--danger {
  border-top-color: var(--danger);
}

.admin-modal__header {
  padding: 22px 24px;
  border-bottom: 1px solid var(--line);
}

.admin-modal__title {
  margin: 0;
  font-size: 24px;
  letter-spacing: -.035em;
}

.admin-modal__body {
  padding: 22px 24px;
  overflow: auto;
}

.admin-modal__message {
  margin: 0;
  color: var(--muted);
  white-space: pre-wrap;
}

.admin-modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 15px 24px;
  border-top: 1px solid var(--line);
}

.admin-modal__form {
  display: grid;
  gap: 15px;
}

.admin-modal__form>.admin-modal__footer {
  position: sticky;
  bottom: -22px;
  margin: 5px -24px -22px;
  background: var(--panel-raised);
}

.modal-field {
  display: grid;
  gap: 6px;
}

.modal-field__label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

textarea.modal-field__control {
  resize: vertical;
}

.modal-field__error {
  min-height: 16px;
  color: var(--danger);
  font-size: 11px;
}

.modal-checklist {
  display: grid;
  border: 1px solid var(--line-strong);
  background: var(--bg);
}

.modal-checklist__head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border-bottom: 1px solid var(--line);
}

.modal-checklist__search {
  min-height: 30px;
  padding: 4px 9px;
  font-size: 12px;
}

.modal-checklist__count {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.modal-checklist__list {
  max-height: 240px;
  overflow: auto;
  scrollbar-color: var(--line-strong) transparent;
}

.modal-checklist__item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
}

.modal-checklist__item:hover {
  background: var(--line);
}

.modal-checklist__box {
  flex: 0 0 auto;
  accent-color: var(--accent, #6f9e8f);
}

.modal-checklist__foot {
  display: flex;
  gap: 8px;
  padding: 6px;
  border-top: 1px solid var(--line);
}

.modal-checklist__btn {
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text);
  background: var(--card, transparent);
  border: 1px solid var(--line-strong);
  cursor: pointer;
}

.modal-checklist__btn:hover {
  border-color: var(--accent, #6f9e8f);
}

.modal-field__control[aria-invalid='true'] {
  border-color: var(--danger);
}

.secure-result {
  display: block;
  margin-top: 18px;
  padding: 16px;
  overflow-wrap: anywhere;
  user-select: all;
  color: var(--accent-hover);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  font-family: var(--font-mono);
}

.details-section+.details-section {
  margin-top: 22px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.details-section__title {
  margin: 0 0 12px;
  font-size: 15px;
}

.details-list {
  display: grid;
  grid-template-columns: minmax(110px, .55fr) minmax(0, 1fr);
  gap: 8px 16px;
  margin: 0;
}

.details-list dt {
  color: var(--muted);
}

.details-list dd {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

@media (max-width: 1100px) {
  .overview-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (max-width: 1180px) {
  .models-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .models-reset {
    width: 100%;
  }

  .model-provider-grid {
    grid-template-columns: 1fr;
  }

  /* At 841–1180px the 264px sidebar + paddings leave <750px of content —
     the workspace's minmax(330/420px) tracks would clip the right column. */
  .provider-workspace {
    grid-template-columns: minmax(0, 1fr);
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 700px) {
  .overview-grid {
    grid-template-columns: 1fr 1fr;
  }

  .page-panel__head {
    align-items: flex-start;
  }

  .search-field {
    grid-template-columns: 1fr;
    justify-content: stretch;
  }

  .details-list {
    grid-template-columns: 1fr;
    gap: 2px;
  }

  .details-list dd+dt {
    margin-top: 9px;
  }

  .models-toolbar {
    grid-template-columns: 1fr;
    padding-inline: 15px;
  }

  .models-segments {
    padding-inline: 8px;
    overflow-x: auto;
  }

  .models-segments button {
    flex: none;
    padding-inline: 9px;
  }

  .models-segments p {
    display: none;
  }

  .model-detail {
    padding: 15px;
  }

  .model-detail__head {
    align-items: flex-start;
    flex-direction: column;
  }

  .model-editor {
    grid-template-columns: 1fr;
  }

  .model-editor__error,
  .model-editor__actions {
    grid-column: 1;
  }
}

@media (max-width: 460px) {
  .overview-grid {
    grid-template-columns: 1fr;
  }

  .page-panel__head {
    flex-direction: column;
  }

  .page-panel__head .button {
    width: 100%;
  }

  .modal-backdrop {
    padding: 8px;
  }

  .admin-modal__header,
  .admin-modal__body {
    padding-inline: 18px;
  }

  .admin-modal__footer {
    padding-inline: 18px;
  }
}
/* Compact model field inside the small form: summary + "Изменить" */
.model-field { display: flex; align-items: center; gap: 10px; }
.model-field__summary { flex: 1; font-size: 13px; color: var(--muted); }
.model-field__edit { flex: 0 0 auto; min-height: 34px; padding: 6px 12px; }

/* Large model picker overlay — sits above the form modal (backdrop z=100) */
.model-picker { position: fixed; inset: 0; z-index: 120; display: flex; align-items: center; justify-content: center; background: rgba(0,0,0,.6); }
.model-picker__panel { width: 75vw; height: 75vh; max-width: 1100px; display: grid; grid-template-rows: auto auto 1fr auto; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 12px; overflow: hidden; }
.model-picker__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.model-picker__title { margin: 0; font-size: 16px; font-weight: 600; }
.model-picker__close { border: none; background: none; color: var(--muted); font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.model-picker__close:hover { color: var(--text); background: var(--panel-raised); }
.model-picker__tools { display: flex; align-items: center; gap: 10px; padding: 10px 18px; border-bottom: 1px solid var(--line); }
.model-picker__search { flex: 1; min-height: 32px; padding: 5px 10px; font-size: 13px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; color: var(--text); }
.model-picker__count { flex: 0 0 auto; color: var(--muted); font-size: 12px; white-space: nowrap; }
.model-picker__groups { overflow: auto; padding: 4px 0; scrollbar-color: var(--line-strong) transparent; }
.model-picker__group-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; gap: 8px; padding: 8px 18px; background: var(--panel); border-bottom: 1px solid var(--line); }
.model-picker__group-toggle { display: flex; align-items: center; gap: 8px; flex: 1; border: none; background: none; color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; text-align: left; }
.model-picker__arrow { color: var(--muted); font-size: 11px; width: 12px; }
.model-picker__group-count { color: var(--muted); font-size: 12px; font-weight: 400; }
.model-picker__group-all { flex: 0 0 auto; padding: 3px 10px; font-size: 11px; color: var(--text); background: var(--panel-raised); border: 1px solid var(--line-strong); border-radius: 6px; cursor: pointer; }
.model-picker__group-all:hover { border-color: var(--muted); }
.model-checklist__item { display: flex; align-items: center; gap: 9px; padding: 5px 18px 5px 34px; font-size: 13px; color: var(--text); cursor: pointer; }
.model-checklist__item:hover { background: var(--panel-raised); }
.model-checklist__box { flex: 0 0 auto; accent-color: var(--accent); }
.model-checklist__name { font-family: ui-monospace, monospace; font-size: 12px; }
.model-picker__foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); }
.model-picker__foot .button-primary { margin-left: auto; min-height: 36px; }
