/* Каркас и компоненты панели. Цвета и шрифты — в themes.css (переменные). */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
svg { width: 22px; height: 22px; fill: currentColor; flex: none; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── Каркас: на телефоне навигация внизу, на ПК — слева ─────────────────── */
.app { min-height: 100vh; }
.main {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px 16px calc(84px + env(safe-area-inset-bottom));
  outline: none;
}
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: var(--nav-bg);
  border-top: 1px solid var(--line);
}
.nav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-width: 56px; padding: 4px 6px; border-radius: 10px;
  color: var(--muted); text-decoration: none; font-size: 11px;
}
.nav a[aria-current="page"] { color: var(--accent); }
.nav-brand, .nav-extra { display: none !important; }

@media (min-width: 900px) {
  /* фон левой колонки — на всю высоту страницы, даже если она длиннее экрана */
  .app { display: grid; grid-template-columns: 220px 1fr;
    background: linear-gradient(to right, var(--nav-bg) 220px, transparent 220px); }
  .nav {
    position: sticky; top: 0; inset: auto; height: 100vh;
    flex-direction: column; justify-content: flex-start; gap: 2px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav-brand { display: block !important; font: 600 20px/1 var(--font-display); padding: 4px 12px 18px; }
  .nav-extra { display: flex !important; }
  .nav-more { display: none !important; }
  .nav a { flex-direction: row; gap: 12px; font-size: 15px; padding: 9px 12px; }
  .nav a[aria-current="page"] { background: var(--surface); }
  .main { padding: 28px 32px 48px; margin: 0; }
}

/* ── Заголовок раздела ─────────────────────────────────────────────────── */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 4px 0 14px; }
.page-head h1 { margin: 0; font: 600 24px/1.2 var(--font-display); }
.loading, .empty { padding: 40px 8px; text-align: center; color: var(--muted); }
.empty p { margin: 0 0 14px; }

/* ── Секции ────────────────────────────────────────────────────────────── */
.section {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 14px;
  border: var(--section-border);
}
.section > h2 { margin: 0 0 10px; font: 600 15px/1.3 var(--font); color: var(--section-title); }
.section > p.hint { margin: -4px 0 12px; }
.hint { color: var(--muted); font-size: 13px; }
.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; margin-bottom: 14px;
  border-radius: var(--radius-lg);
  background: var(--warn-bg); color: var(--warn-text);
}
.banner.bad { background: var(--bad-bg); color: var(--bad-text); }
.banner svg { margin-top: 1px; }

/* ── Табло следующей рассылки (главный элемент «Обзора») ────────────────── */
.board { display: grid; gap: 14px; }
.board-status { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 10px; font-weight: 500; }
.board-status .now { flex-basis: 100%; padding-left: 20px; color: var(--muted); font-weight: 400; font-size: 14px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 4px var(--ok-glow); }
.dot.bad { background: var(--bad); box-shadow: 0 0 0 4px var(--bad-glow); }
.dot.idle { background: var(--warn); }
.board-next { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 14px; }
.board-time {
  font: 600 64px/0.95 var(--font-numbers);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--numbers-tracking);
  color: var(--board-time);
}
.board-label { color: var(--muted); }
.board-label b { color: var(--text); font-weight: 500; }
.lamps { display: flex; flex-wrap: wrap; gap: 8px; }
.lamp {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px 5px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--text);
  font-size: 13px; border: 0; cursor: pointer;
}
.lamp i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.lamp.ok i { background: var(--ok); }
.lamp.mod i { background: var(--warn); }
.lamp.err i { background: var(--bad); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.legend .l-ok::before { background: var(--ok); }
.legend .l-mod::before { background: var(--warn); }
.legend .l-err::before { background: var(--bad); }
.legend .l-none::before { background: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: var(--radius-sm); padding: 10px 12px; }
.stat b { display: block; font: 600 28px/1 var(--font-numbers); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }
.stat.bad b { color: var(--bad); }
.stat.warn b { color: var(--warn); }

/* ── Строки списков ────────────────────────────────────────────────────── */
.list { margin: 0 -16px; }
.row {
  display: flex; align-items: center; gap: 12px;
  width: 100%; padding: 11px 16px; text-align: left;
  background: none; border: 0; border-top: 1px solid var(--line);
  cursor: pointer;
}
.list > .row:first-child { border-top: 0; }
.row:active { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.off .row-title { color: var(--muted); }
.row-end { color: var(--muted); font-size: 13px; text-align: right; flex: none; }
.status-icon { width: 20px; height: 20px; flex: none; }
.status-icon.ok { color: var(--ok); }
.status-icon.mod { color: var(--warn); }
.status-icon.err { color: var(--bad); }
.status-icon.none { color: var(--muted); }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 6px;
  background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 500;
  vertical-align: 1px;
}
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.badge.bad { background: var(--bad-bg); color: var(--bad-text); }

.text-preview { white-space: pre-line; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; color: var(--text); font-size: 14px; }
.text-card { padding: 0; border: 0; }
.text-card-head { margin-bottom: 6px; }
.text-bad { color: var(--bad); }
.full-text { white-space: pre-wrap; background: var(--surface-2); border-radius: var(--radius-sm); padding: 12px; font-size: 14px; margin: 0; }

/* ── Кнопки ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 42px; padding: 0 16px; border-radius: var(--radius-sm);
  border: 0; cursor: pointer; font-weight: 500;
  background: var(--surface-2); color: var(--text);
}
.btn.primary { background: var(--accent); color: var(--accent-text); }
.btn.danger { background: none; color: var(--bad); }
.btn.ghost { background: none; color: var(--accent); padding: 0 6px; min-height: 34px; }
a.btn { text-decoration: none; }
.btn.wide { width: 100%; }
.btn[disabled] { opacity: .5; cursor: default; }
.btn svg { width: 18px; height: 18px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .btn { flex: 1 1 200px; white-space: nowrap; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.icon-btn:active { background: var(--surface-2); }

/* ── Поля ──────────────────────────────────────────────────────────────── */
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 13px; color: var(--muted); }
.field .hint { margin-top: -1px; }
.input, select.input, textarea.input {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border-radius: var(--radius-sm); border: 1px solid var(--line);
  background: var(--input-bg); color: var(--text);
}
textarea.input.short { min-height: 72px; }
textarea.input { min-height: 190px; resize: vertical; line-height: 1.45; }
.input:focus { outline: none; border-color: var(--accent); }
.input.invalid { border-color: var(--bad); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.counter { text-align: right; font-size: 12px; color: var(--muted); }

/* переключатель */
.toggle { display: flex; align-items: center; gap: 12px; padding: 9px 0; cursor: pointer; }
.toggle + .toggle { border-top: 1px solid var(--line); }
.toggle .t-text { flex: 1; }
.toggle .t-text small { display: block; color: var(--muted); font-size: 13px; }
.switch { position: relative; width: 44px; height: 26px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch i { position: absolute; inset: 0; border-radius: 999px; background: var(--switch-off); transition: background .15s; }
.switch i::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; box-shadow: 0 1px 2px rgb(0 0 0 / .25); }
.switch input:checked + i { background: var(--accent); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }

/* сегменты и фильтры */
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; margin-bottom: 10px; scrollbar-width: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--line);
  background: none; color: var(--text); font-size: 13px; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.segmented { display: flex; background: var(--surface-2); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.segmented button { flex: 1; border: 0; border-radius: calc(var(--radius-sm) - 2px); padding: 8px 6px; background: none; color: var(--muted); cursor: pointer; font-weight: 500; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgb(0 0 0 / .12); }

/* выбор стиля */
.themes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.theme-card { border: 2px solid var(--line); border-radius: var(--radius-sm); padding: 0; overflow: hidden; background: none; cursor: pointer; text-align: left; }
.theme-card[aria-pressed="true"] { border-color: var(--accent); }
.theme-card .swatch { height: 64px; display: flex; align-items: flex-end; padding: 8px; gap: 6px; }
.theme-card .swatch i { width: 14px; height: 14px; border-radius: 50%; }
.theme-card span { display: block; padding: 8px 10px; font-weight: 500; }

/* ── Журнал ────────────────────────────────────────────────────────────── */
.log { font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; margin: 0 -16px; }
.log-line { display: grid; grid-template-columns: auto 1fr; gap: 0 10px; padding: 6px 16px; border-top: 1px solid var(--line); }
.log-line time { color: var(--muted); white-space: nowrap; }
.log-line div { white-space: pre-wrap; word-break: break-word; }
.log-line.WARNING div { color: var(--warn); }
.log-line.ERROR div { color: var(--bad); }
@media (max-width: 520px) { .log-line { grid-template-columns: 1fr; } }

/* ── Лист (модальное окно снизу; на ПК — по центру) ──────────────────────── */
.sheet-backdrop { position: fixed; inset: 0; z-index: 30; background: rgb(0 0 0 / .45); }
.sheet {
  position: fixed; z-index: 31; left: 0; right: 0; bottom: 0;
  max-height: 92vh; display: flex; flex-direction: column;
  background: var(--bg); border-radius: 16px 16px 0 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 10px 6px 18px; }
.sheet-head h2 { flex: 1; margin: 0; font: 600 18px/1.25 var(--font-display); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { overflow-y: auto; padding: 6px 16px 20px; }
@media (min-width: 900px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: 560px; transform: translate(-50%, -50%); border-radius: 16px; max-height: 86vh; }
}
@media (prefers-reduced-motion: no-preference) {
  .sheet:not([hidden]) { animation: sheet-in .2s ease-out; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
  @media (min-width: 900px) { @keyframes sheet-in { from { transform: translate(-50%, calc(-50% + 16px)); opacity: 0; } } }
}

/* ── Уведомления внутри панели ─────────────────────────────────────────── */
.toasts { position: fixed; z-index: 40; left: 12px; right: 12px; bottom: calc(80px + env(safe-area-inset-bottom)); display: grid; gap: 8px; justify-items: center; pointer-events: none; }
.toast { max-width: 520px; padding: 10px 14px; border-radius: 12px; background: var(--toast-bg); color: var(--toast-text); box-shadow: 0 6px 20px rgb(0 0 0 / .25); font-size: 14px; }
.toast.bad { background: var(--bad); color: #fff; }
@media (min-width: 900px) { .toasts { bottom: 24px; left: 240px; } }

/* ── Мелочи ────────────────────────────────────────────────────────────── */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.more-links .row svg { color: var(--muted); }
.spacer { height: 6px; }

/* ── Проверка групп ────────────────────────────────────────────────────── */
.check-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.check-head .hint { margin-left: auto; }
.check-problems { margin: 0 0 10px; padding-left: 20px; color: var(--text); }
.check-problems li { margin: 2px 0; }
.check-status { min-height: 1.4em; margin: 6px 0 0; }
.toast.warn { background: var(--warn); color: #1a1206; }
.banner a { color: inherit; font-weight: 600; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: -6px 0 10px; }
.toolbar .btn { flex: none; }
/* адрес обрезается многоточием, метка проверки остаётся видна */
.row-title-badge { display: flex; align-items: center; gap: 6px; }
.row-title-badge > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-title-badge .badge { flex: none; }
.kv + .hint, .kv + p { margin-top: 10px; }

/* объявления */
.campaign-picker { margin: -4px 0 14px; }
.campaign-picker .chip { font-weight: 500; }
.lamp-flag {
  font-size: 11px; font-weight: 600; line-height: 1; padding: 2px 5px; border-radius: 5px;
  background: var(--warn-bg); color: var(--warn-text);
}
.row-title-badge { flex-wrap: wrap; }
.pick-list { max-height: 46vh; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); margin-top: 8px; }
.row.pick[aria-pressed="true"] { background: color-mix(in srgb, var(--accent) 14%, transparent); box-shadow: inset 3px 0 0 var(--accent); }
.pick-toolbar { margin: 8px 0 0; }
.row.pick:disabled { cursor: default; opacity: .55; }
