/* Пульт агентов: продуктовый регистр, тёмная приборная панель.
   Палитра от собственного знака (два ползунка): графит + индикаторный зелёный.
   Без градиентов, статусы дублируются текстом, контраст ≥ 4.5. */

:root {
  --bg: #14161c;             /* = theme-color и background_color манифеста, байт в байт */
  --surface: oklch(0.225 0.012 265);
  --surface-2: oklch(0.26 0.014 265);
  --border: oklch(0.32 0.015 265);
  --border-hi: oklch(0.42 0.02 265);
  --text: oklch(0.93 0.005 260);
  --muted: oklch(0.72 0.012 260);
  --accent: oklch(0.78 0.13 165);        /* индикатор «подписка / ок» */
  --accent-ink: oklch(0.25 0.05 165);
  --chan-api: oklch(0.76 0.1 250);       /* индикатор «API» */
  --warn: oklch(0.8 0.11 85);            /* «ожидает применения» */
  --err: oklch(0.72 0.17 25);
  --dock-h: 58px;
  --dock-pad-b: max(calc(env(safe-area-inset-bottom) - 14px), 10px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { height: 100%; overscroll-behavior-y: contain; }
body {
  height: 100%; margin: 0; overflow: hidden; overscroll-behavior-y: none;
  background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

#shell {
  position: fixed; inset: 0; height: 100%;
  display: flex; flex-direction: column;
  will-change: transform;
}

/* ── Шапка ── */
#topbar { flex: 0 0 auto; padding-top: env(safe-area-inset-top); background: var(--bg); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; max-width: 1280px; margin: 0 auto; width: 100%; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 650; font-size: 17px; letter-spacing: 0.1px; }
.top-summary { font-size: 13px; color: var(--warn); }

/* ── Каркас: контент + боковая панель ── */
#layout { flex: 1 1 auto; min-height: 0; display: flex; max-width: 1280px; margin: 0 auto; width: 100%; }
#sidenav { display: none; }
#main {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch; padding: 16px 16px calc(var(--dock-h) + var(--dock-pad-b) + 76px);
  outline: none;
}
.view[hidden] { display: none; }
body.unauthed #dock, body.unauthed #sidenav { display: none; }

/* ── Нижняя навигация (телефон) ── */
#dock {
  flex: 0 0 auto; position: relative; z-index: 35;
  display: flex; justify-content: space-around;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 6px 8px var(--dock-pad-b);
}
.nav-item {
  min-height: 44px; min-width: 72px; padding: 4px 10px;
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; border-radius: 10px;
  color: var(--muted); font: inherit; font-size: 12px; cursor: pointer;
  touch-action: manipulation;
}
.nav-item .nav-ico { font-size: 18px; line-height: 1; }
.nav-item.is-active { color: var(--accent); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Вход ── */
.login-card { max-width: 380px; margin: 10vh auto 0; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 22px; }
.login-card h1 { margin: 0 0 10px; font-size: 20px; }
.login-msg { min-height: 1.4em; font-size: 14px; color: var(--muted); }
.login-msg.err { color: var(--err); }

/* ── Кнопки ── */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 10px;
  border: 1px solid var(--border-hi); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: 15px; cursor: pointer; touch-action: manipulation;
}
.btn:disabled { opacity: 0.45; cursor: default; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }
.btn-wide { width: 100%; margin-bottom: 10px; text-align: left; padding: 0 16px; }
.btn-danger-text { color: var(--err); }

/* ── Группы и карточки агентов ── */
.group-title { margin: 18px 2px 8px; font-size: 12.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.group-title:first-child { margin-top: 2px; }

.agent {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 12px 14px; margin-bottom: 10px;
}
.agent.is-missing { opacity: 0.75; }
.agent-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.agent-name { font-weight: 650; font-size: 16px; }
.agent-role { color: var(--muted); font-size: 13px; }
.agent-badges { margin-left: auto; display: inline-flex; gap: 6px; }

.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--border-hi); color: var(--muted); white-space: nowrap; }
.badge-new { color: var(--accent); border-color: var(--accent); }
.badge-missing { color: var(--err); border-color: var(--err); }
.badge-pending { color: var(--warn); border-color: var(--warn); }
.badge-ok { color: var(--accent); border-color: var(--border); }
.badge-err { color: var(--err); border-color: var(--err); }

.agent-controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.select-wrap { position: relative; flex: 1 1 130px; min-width: 120px; }
.select-wrap select {
  width: 100%; min-height: 44px; padding: 0 30px 0 12px; appearance: none;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-hi); border-radius: 10px; font: inherit; font-size: 14.5px;
}
.select-wrap::after { content: '▾'; position: absolute; right: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--muted); font-size: 12px; }
.select-wrap select:disabled { opacity: 0.5; }
.select-wrap select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.chan { display: inline-flex; border: 1px solid var(--border-hi); border-radius: 10px; overflow: hidden; flex: 0 0 auto; }
.chan button {
  min-height: 44px; padding: 0 14px; border: none; background: none; color: var(--muted);
  font: inherit; font-size: 14px; cursor: pointer; touch-action: manipulation;
}
.chan button + button { border-left: 1px solid var(--border-hi); }
.chan button.is-on { background: var(--surface-2); color: var(--text); font-weight: 650; }
.chan button.is-on[data-chan='subscription'] { color: var(--accent); }
.chan button.is-on[data-chan='api'] { color: var(--chan-api); }
.chan button:disabled { cursor: default; opacity: 0.55; }
.chan-locked { font-size: 13px; color: var(--muted); }

.agent-note { margin-top: 8px; font-size: 13px; color: var(--muted); }
.agent-note.err { color: var(--err); }
.agent-note.warn { color: var(--warn); }
.agent-note.ok { color: var(--accent); }

.btn-check { font-size: 14px; padding: 0 14px; flex: 0 0 auto; }

/* ── Плашка неприменённых изменений ── */
#applybar {
  position: fixed; left: 12px; right: 12px; bottom: calc(var(--dock-h) + var(--dock-pad-b) + 10px);
  z-index: 40; display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--warn); border-radius: 14px;
  padding: 10px 10px 10px 16px; max-width: 640px; margin: 0 auto;
}
#applybar[hidden] { display: none; }
#applybar-text { font-size: 14px; white-space: nowrap; }
.applybar-actions { display: inline-flex; gap: 8px; }
.applybar-actions .btn { padding: 0 12px; font-size: 14px; }

/* ── Журнал ── */
.journal-row { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.journal-meta { color: var(--muted); font-size: 12.5px; margin-bottom: 2px; }
.journal-change { word-break: break-word; }
.journal-result-err { color: var(--err); }

/* ── Настройки ── */
.settings { max-width: 480px; }
.settings-group { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.settings-group h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; }
.small { font-size: 12.5px; }

/* ── Служебное ── */
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty b { color: var(--text); display: block; margin-bottom: 6px; font-size: 16px; }

.skeleton { border-radius: 14px; border: 1px solid var(--border); background: var(--surface); height: 96px; margin-bottom: 10px; position: relative; overflow: hidden; }
.skeleton::after { content: ''; position: absolute; inset: 0; background: var(--surface-2); opacity: 0; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.5; } }

.overlay { position: fixed; inset: 0; z-index: 2000; background: oklch(0.1 0.01 265 / 0.66); display: flex; align-items: flex-end; justify-content: center; }
.overlay[hidden] { display: none; }
.dialog { background: var(--surface); border: 1px solid var(--border-hi); border-radius: 18px 18px 0 0; padding: 22px 20px calc(18px + env(safe-area-inset-bottom)); width: 100%; max-width: 480px; }
.dialog h2 { margin: 0 0 8px; font-size: 17px; }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

#toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--dock-h) + var(--dock-pad-b) + 14px);
  z-index: 2100; background: var(--surface-2); border: 1px solid var(--border-hi);
  color: var(--text); border-radius: 12px; padding: 10px 16px; font-size: 14px; max-width: 86vw;
}

.ptr { position: fixed; top: env(safe-area-inset-top); left: 0; right: 0; height: 0; display: flex; justify-content: center; z-index: 90; pointer-events: none; opacity: 0; will-change: transform, opacity; }
.ptr-ring { display: block; margin-top: 6px; width: 22px; height: 22px; padding: 0; border-radius: 50%; border: 2px solid var(--border-hi); border-top-color: var(--accent); box-sizing: border-box; }
.ptr.spinning .ptr-ring { animation: ptrspin 0.7s linear infinite; }
@keyframes ptrspin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .skeleton::after, .ptr.spinning .ptr-ring { animation: none; }
}

/* ── Десктоп от 1024: боковая панель + таблица ── */
@media (min-width: 1024px) {
  #dock { display: none; }
  #sidenav {
    display: flex; flex-direction: column; gap: 4px;
    flex: 0 0 200px; padding: 20px 12px; border-right: 1px solid var(--border);
  }
  #sidenav .nav-item { flex-direction: row; justify-content: flex-start; gap: 10px; font-size: 14.5px; min-height: 42px; width: 100%; }
  #sidenav .nav-item.is-active { background: var(--surface); color: var(--accent); }
  #main { padding: 20px 28px 24px; }
  body.has-pending #main { padding-bottom: 96px; } /* место под плашку изменений */
  :root { --dock-h: 0px; --dock-pad-b: 0px; }
  #applybar { left: 240px; right: 24px; bottom: 18px; }
  #toast { bottom: 20px; }
  .dialog { border-radius: 18px; margin-bottom: 10vh; align-self: center; }
  .overlay { align-items: center; }

  /* таблица: 12 агентов помещаются на 1440×900 без прокрутки */
  /* колонки: имя, роль, статус, провайдер, модель, канал, проверка (R1, R6) */
  .agent { display: grid; grid-template-columns: minmax(120px, 1.1fr) 95px 150px 135px minmax(140px, 1fr) 165px 100px; gap: 10px; align-items: center; padding: 5px 12px; margin-bottom: 5px; }
  .agent-head { display: contents; }
  .agent-name { font-size: 14px; }
  .agent-role { font-size: 12.5px; }
  .agent-badges { margin-left: 0; justify-content: flex-start; flex-wrap: wrap; }
  .agent-controls { display: contents; }
  .select-wrap select { min-height: 33px; font-size: 13px; }
  .chan button { min-height: 33px; padding: 0 12px; font-size: 13px; }
  .btn-check { min-height: 33px; font-size: 13px; padding: 0 10px; }
  .agent-note { grid-column: 1 / -1; margin-top: 0; font-size: 12px; }
  .group-title { margin: 9px 2px 5px; font-size: 11.5px; }
}
