/* Пульт владельца — стили. Без внешних шрифтов и CDN: в мобильных «белых списках» они не грузятся. */

:root {
  --bg: #f2f3f5;
  --card: #ffffff;
  --card2: #f5f6f8;
  --text: #14171c;
  --muted: #5d6471;
  --line: #e0e3e8;
  --accent: #2458d6;
  --accent-text: #ffffff;
  --ok: #157a3c;    --ok-bg: #dcf5e4;
  --warn: #975a07;  --warn-bg: #fdf0c9;
  --bad: #b3261e;   --bad-bg: #fde1de;
  --off: #626a77;   --off-bg: #eaecef;
  --busy: #1f4fc2;  --busy-bg: #dde7fd;
  --info: #3d5a80;  --info-bg: #e3ebf5;
  /* Серии графиков: категориальные слоты 1–3, проверены на различимость (в т.ч. дальтонизм) */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a;
  --shadow: 0 1px 2px rgba(15, 20, 30, .06);
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f13;
    --card: #16191f;
    --card2: #1d2129;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --line: #2a2f39;
    --accent: #7ba2ff;
    --accent-text: #0b0d11;
    --ok: #4fd183;    --ok-bg: #11301f;
    --warn: #f2b53c;  --warn-bg: #33270b;
    --bad: #ff7a70;   --bad-bg: #3b1614;
    --off: #9aa2b0;   --off-bg: #232730;
    --busy: #9ab8ff;  --busy-bg: #17233f;
    --info: #9fb6d6;  --info-bg: #1b2433;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  overflow-wrap: anywhere;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 20px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; color: var(--muted); font-weight: 600; margin: 12px 0 6px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 13px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- Шапка и вкладки ---------- */

.head { position: sticky; top: 0; z-index: 20; }
.top {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--card);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.mock-badge {
  font-size: 11px; font-weight: 700; letter-spacing: .02em;
  padding: 2px 6px; border-radius: 6px;
  background: var(--warn-bg); color: var(--warn);
}
.upd { flex: 1; min-width: 0; font-size: 13px; color: var(--muted); text-align: right;
       white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upd.bad { color: var(--bad); font-weight: 600; }
.icon-btn {
  flex: none; width: 44px; height: 44px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--card2);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.icon-btn:disabled { opacity: .5; }
.icon-btn.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .icon-btn.spin { animation: none; } }

.tabs {
  display: flex; gap: 4px;
  padding: 6px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: none; position: relative;
  min-height: 40px; padding: 0 12px;
  border: 0; border-radius: 10px;
  background: transparent; color: var(--muted);
  font-weight: 600; cursor: pointer;
}
.tab[aria-selected="true"] { background: var(--card); color: var(--text); box-shadow: inset 0 0 0 1px var(--line); }
.tab .badge {
  display: inline-block; min-width: 18px; height: 18px; margin-left: 5px; padding: 0 5px;
  border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center;
  background: var(--bad-bg); color: var(--bad);
}
.tab .badge.warn { background: var(--warn-bg); color: var(--warn); }

/* ---------- Содержимое ---------- */

.view { padding: 12px 16px 40px; max-width: 1180px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
@media (min-width: 700px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid > .wide { grid-column: 1 / -1; }
  .tabs { justify-content: flex-start; }
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.card-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 6px; }
.card-h h2 { flex: 1; min-width: 0; }
.card-h .age { font-size: 12px; color: var(--muted); }
.card-h .age.stale { color: var(--warn); font-weight: 600; }
.sub { font-size: 13px; color: var(--muted); margin: -2px 0 6px; }
.err {
  margin: 6px 0; padding: 8px 10px; border-radius: 8px;
  background: var(--bad-bg); color: var(--bad); font-size: 14px;
}
.empty { color: var(--muted); font-size: 14px; }

/* Светофор: всегда цвет + слово */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  background: var(--off-bg); color: var(--off);
}
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex: none; }
.pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.lv-ok   { --c: var(--ok);   --cb: var(--ok-bg); }
.lv-warn { --c: var(--warn); --cb: var(--warn-bg); }
.lv-bad  { --c: var(--bad);  --cb: var(--bad-bg); }
.lv-off  { --c: var(--off);  --cb: var(--off-bg); }
.lv-busy { --c: var(--busy); --cb: var(--busy-bg); }
.lv-info { --c: var(--info); --cb: var(--info-bg); }
.pill[class*="lv-"] { background: var(--cb); color: var(--c); }
.lvw { font-size: 12px; font-weight: 600; color: var(--c, var(--muted)); }

/* Плитки сводки */
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.tile {
  display: block; width: 100%; text-align: left; cursor: pointer;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; min-height: 92px; box-shadow: var(--shadow);
  border-left: 4px solid var(--c, var(--line));
}
.tile .t-h { display: flex; justify-content: space-between; align-items: baseline; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.tile .t-n { flex: 1; min-width: 0; }
.tile .t-h .lvw { flex: none; white-space: nowrap; }
.tile .t-v { font-size: 22px; line-height: 1.2; font-weight: 700; margin: 3px 0; font-variant-numeric: tabular-nums; }
.nw { white-space: nowrap; }
@media (max-width: 440px) {
  .tile { padding: 9px 10px; min-height: 0; }
  .tile .t-v { font-size: 18px; }
  .tile .t-s { font-size: 12.5px; }
}
.tile .t-s { font-size: 13px; color: var(--muted); }

/* Метрики с полосой */
.metric { margin: 8px 0; }
.metric .m-top { display: flex; align-items: baseline; gap: 8px; }
.metric .m-l { color: var(--muted); font-size: 13px; min-width: 64px; }
.metric .m-v { font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .m-s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.metric .lvw { margin-left: auto; }
.bar { display: block; height: 7px; margin-top: 4px; border-radius: 4px; background: var(--card2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.bar > i { display: block; height: 100%; width: 0; background: var(--c, var(--accent)); border-radius: 4px; }

/* Ключ-значение */
.kv { display: grid; grid-template-columns: minmax(84px, 38%) minmax(0, 1fr); gap: 3px 10px; margin: 4px 0; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; }
.kv .metric { margin: 0; }
/* Вложенные «подробно» (снимок биллинга: ёмкость → аккаунты → primary) идут на 3–4 уровня:
   колонка подписи с минимумом 84px на каждом уровне выдавливала страницу вбок на 390px.
   Второй уровень — без минимума, третий и глубже — подпись над значением. */
.kv .kv { grid-template-columns: minmax(0, 40%) minmax(0, 1fr); }
.kv .kv .kv { grid-template-columns: minmax(0, 1fr); gap: 0 8px; }
.kv .kv .kv dd { padding-left: 8px; margin-bottom: 2px; }
.kv dt { overflow-wrap: anywhere; }

/* Таблицы: прокрутка только внутри, страница вбок не едет */
.tw { overflow-x: auto; margin: 4px -4px; padding: 0 4px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; overflow-wrap: normal; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl tr.hi td { background: var(--warn-bg); }

/* Строки-карточки для списков с множеством полей */
.rows { margin: 2px 0; }
.row { padding: 8px 0; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row-h b { font-weight: 600; min-width: 0; }
.row-t { margin: 3px 0 0; font-size: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 3px; font-size: 13px; }
.chip i { font-style: normal; color: var(--muted); }

details { margin: 6px 0; }
details > summary {
  cursor: pointer; color: var(--muted); font-size: 13.5px; font-weight: 600;
  min-height: 32px; display: flex; align-items: center; list-style: none;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; margin-right: 6px; transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }

/* Кнопки */
.btn {
  min-height: 44px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--card2); color: var(--text);
  font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn { overflow-wrap: normal; }
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.danger.primary { background: var(--bad); color: #fff; }
.btn.link { background: none; border: 0; color: var(--accent); padding: 0 4px; min-height: 36px; }
.btns { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.btns .btn { flex: 0 1 auto; }
.more-btn { margin-top: 6px; }

/* Карточка агента */
.agent .a-title { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agent .a-title h2 { flex: 1; min-width: 0; }
.agent .a-sub { font-size: 13px; color: var(--muted); margin: 2px 0 6px; }
.agent .kv { grid-template-columns: minmax(84px, 30%) minmax(0, 1fr); }
/* Кнопки агента растягиваются по строке: шесть действий укладываются в две-три строки */
.agent .btns .btn { flex: 1 1 auto; padding: 0 10px; font-size: 14px; }

/* Лента событий */
.ev { display: grid; grid-template-columns: 46px minmax(0, 1fr); gap: 2px 8px; padding: 7px 0; border-top: 1px solid var(--line); }
.ev:first-child { border-top: 0; }
.ev .ev-t { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; padding-top: 2px; }
.ev .ev-h { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 13px; }
.ev .ev-x { font-size: 14px; margin-top: 2px; }
.ev .cnt { font-size: 12px; color: var(--muted); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: 2px 0 8px; }
.filters .btn { min-height: 36px; padding: 0 10px; font-size: 13.5px; }
.filters .btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* Советы */
.recs { list-style: none; margin: 0; padding: 0; }
.recs li { display: flex; gap: 8px; align-items: flex-start; padding: 7px 0; border-top: 1px solid var(--line); }
.recs li:first-child { border-top: 0; }
.recs .pill { margin-top: 1px; }
.recs .rt { flex: 1; min-width: 0; font-size: 14px; }

/* Вход */
.login { min-height: 100vh; min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.login-box { width: 100%; max-width: 380px; padding: 20px; }
.login-box h1 { margin-bottom: 6px; }
.login-box .btn { width: 100%; margin-top: 12px; }
.login-box .msg { min-height: 20px; font-size: 14px; }
.login-box .msg.bad { color: var(--bad); }
.code-in {
  width: 100%; margin-top: 12px; padding: 10px 12px; min-height: 52px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card2);
  font-size: 26px; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums;
}

/* Лист действия (снизу на телефоне, по центру на широком) */
.sheet { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(8, 10, 14, .5); }
.sheet-box {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: var(--card); border-radius: 16px 16px 0 0;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 700px) { .sheet { align-items: center; } .sheet-box { border-radius: 16px; } }
.sheet-h { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.sheet-h h2 { flex: 1; font-size: 17px; }
.field { margin: 10px 0; }
.field label { display: block; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.field .hint { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.field input[type=text], .field input[type=number], .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--card2);
}
.field textarea { min-height: 96px; resize: vertical; }
.field .fixed { font-weight: 600; }
.field.check label { display: flex; gap: 8px; align-items: center; color: var(--text); font-size: 15px; min-height: 44px; }
.field.check input { width: 22px; height: 22px; }
.confirm { margin-top: 10px; padding: 10px 12px; border-radius: 10px; background: var(--warn-bg); color: var(--text); }
.confirm strong { color: var(--warn); }
.res { margin-top: 12px; padding: 10px 12px; border-radius: 10px; }
.res.ok { background: var(--ok-bg); }
.res.bad { background: var(--bad-bg); }
.res .res-h { font-weight: 700; }
.res.ok .res-h { color: var(--ok); }
.res.bad .res-h { color: var(--bad); }
.steps { margin: 6px 0 4px; padding-left: 22px; font-size: 14px; }
.steps li { margin: 3px 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* График за сутки: тонкие линии, сетка приглушена, подсказка по касанию */
.hist-box { position: relative; margin-top: 4px; touch-action: pan-y; }
.hist { display: block; width: 100%; height: 72px; overflow: visible; }
.hist .grid-ln { stroke: var(--line); stroke-width: 1; vector-effect: non-scaling-stroke; }
.hist .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.hist .ln.s1 { stroke: var(--series-1); }
.hist .ln.s2 { stroke: var(--series-2); }
.hist .ln.s3 { stroke: var(--series-3); }
.hist .cross { stroke: var(--muted); stroke-width: 1; vector-effect: non-scaling-stroke; }
.sw { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin-right: 5px; vertical-align: middle; }
.sw.s1 { background: var(--series-1); }
.sw.s2 { background: var(--series-2); }
.sw.s3 { background: var(--series-3); }
.legend { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12.5px; color: var(--text); margin-top: 4px; }
.tip {
  position: absolute; top: -6px; z-index: 2; min-width: 100px; pointer-events: none;
  padding: 5px 8px; border-radius: 8px; font-size: 12px; line-height: 1.35;
  background: var(--card); color: var(--text); border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

/* «подробно» внутри строк — мелко, чтобы не спорить с главным */
.row details { margin: 2px 0 0; }
.row details > summary { min-height: 28px; font-size: 12.5px; }
