/* app.css — оформление веб-панели. Сначала телефон (вкладки внизу), на широком экране — боковая колонка. */

:root {
  --text-xs: clamp(0.75rem, 0.72rem + 0.15vw, 0.8125rem);
  --text-sm: clamp(0.875rem, 0.85rem + 0.15vw, 0.9375rem);
  --text-base: 1rem;
  --text-lg: clamp(1.125rem, 1.05rem + 0.3vw, 1.25rem);
  --text-xl: clamp(1.375rem, 1.2rem + 0.8vw, 1.75rem);

  --space-1: 0.25rem; --space-2: 0.5rem; --space-3: 0.75rem; --space-4: 1rem;
  --space-5: 1.25rem; --space-6: 1.5rem; --space-8: 2rem; --space-10: 2.5rem; --space-12: 3rem;

  --radius: 14px; --radius-sm: 10px;

  /* тёплый нейтральный фон, акцент — тёмная ягода (родственно WB, но спокойнее) */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f1efea;
  --border: #e3e0d9;
  --text: #1d1b20;
  --muted: #6d6a72;
  --faint: #a9a6ad;
  --primary: #8a1d5a;
  --primary-hover: #6f1448;
  --primary-soft: #f4e3ec;
  --ok: #1f7a4d;
  --ok-soft: #e1f1e8;
  --warn: #9a5a07;
  --warn-soft: #fbefd9;
  --danger: #b3261e;
  --danger-soft: #fae3e1;
  --shadow: 0 1px 2px rgb(30 20 40 / 6%), 0 4px 16px rgb(30 20 40 / 5%);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --tabbar-h: 64px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16151a; --surface: #201e25; --surface-2: #2a2730; --border: #36323d;
    --text: #efedf2; --muted: #a29fa9; --faint: #6c6973;
    --primary: #e07bb0; --primary-hover: #eb98c3; --primary-soft: #3a2330;
    --ok: #5cc28d; --ok-soft: #1d3328; --warn: #e0a54a; --warn-soft: #3a2e1a;
    --danger: #f08a82; --danger-soft: #3d2220;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: var(--text-base); line-height: 1.45;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: var(--text-xl); }
h2 { font-size: var(--text-lg); font-weight: 650; }
code { font-family: var(--mono); font-size: 0.9em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: var(--text-sm); }
.strong { font-weight: 600; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.error { color: var(--danger); min-height: 1.4em; margin: 0; font-size: var(--text-sm); }

/* ---------- Кнопки и поля ---------- */
button, input, select, textarea { font: inherit; color: inherit; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 var(--space-4); border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); font-size: var(--text-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn:hover { border-color: var(--faint); }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #1a0f15; } }
.btn-stop { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); padding: 0 var(--space-2); }
.btn-ghost:hover { background: var(--primary-soft); border-color: transparent; }
.btn-danger-ghost { background: transparent; border-color: var(--danger-soft); color: var(--danger); }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.loading { position: relative; color: transparent !important; }
.btn.loading::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--muted); border-top-color: transparent; animation: spin .7s linear infinite;
}
.btn-primary.loading::after { border-color: #fff; border-top-color: transparent; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface); cursor: pointer;
}
.icon-btn:active { transform: scale(.96); }
.chip {
  min-height: 36px; padding: 0 var(--space-3); border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); font-size: var(--text-sm); cursor: pointer;
}
.chip:active { background: var(--surface-2); }
.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.field { display: grid; gap: var(--space-1); font-size: var(--text-sm); color: var(--muted); }
.field > span { font-weight: 500; }
/* 16px в полях: иначе iPhone приближает страницу при вводе */
input[type="text"], input[type="password"], input[type="url"], input[type="number"], input[type="date"], input[type="search"], input[type="tel"], select, textarea {
  width: 100%; min-height: 44px; padding: var(--space-2) var(--space-3); font-size: 16px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  -webkit-appearance: none; appearance: none;
}
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 32px; }
textarea { font-family: var(--mono); font-size: 14px; resize: vertical; line-height: 1.5; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--primary); outline-offset: 2px;
}
.inline-form { display: flex; gap: var(--space-2); }
.inline-form > input, .inline-form > select { flex: 1; min-width: 0; }
.grid2 { display: grid; gap: var(--space-3); grid-template-columns: 1fr; }
@media (min-width: 560px) { .grid2 { grid-template-columns: 1fr 1fr; } }

.seg { display: flex; padding: 3px; gap: 3px; background: var(--surface-2); border-radius: var(--radius-sm); }
.seg-btn {
  flex: 1; min-height: 38px; border: 0; border-radius: 8px; background: transparent; color: var(--muted);
  font-size: var(--text-sm); font-weight: 600; cursor: pointer; padding: 0 var(--space-2);
}
.seg-btn[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.switch { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }
.toggle { position: relative; display: inline-block; width: 52px; height: 32px; flex: none; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.toggle-ui { position: absolute; inset: 0; border-radius: 999px; background: var(--border); transition: background .2s; }
.toggle-ui::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgb(0 0 0 / 25%); transition: transform .2s; }
.toggle input:checked + .toggle-ui { background: var(--primary); }
.toggle input:checked + .toggle-ui::after { transform: translateX(20px); }
.toggle input:focus-visible + .toggle-ui { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---------- Вход ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: var(--space-6) var(--space-4); }
.login-card {
  width: min(400px, 100%); display: grid; gap: var(--space-4); padding: var(--space-8) var(--space-6);
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow);
}
.login-card p { margin: 0; }
.brand { display: inline-flex; align-items: center; gap: var(--space-2); font-weight: 700; letter-spacing: -0.01em; }
.brand-mark { width: 22px; height: 22px; border-radius: 7px; background: var(--primary); position: relative; }
.brand-mark::after { content: ""; position: absolute; left: 8px; top: 4px; width: 6px; height: 11px; border: solid #fff; border-width: 0 2.5px 2.5px 0; transform: rotate(40deg); }

/* ---------- Каркас ---------- */
.app { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: calc(env(safe-area-inset-top) + var(--space-3)) var(--space-4) var(--space-3);
  background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: var(--text-xs); font-weight: 600; background: var(--surface-2); color: var(--muted); }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }
.pill.on { background: var(--ok-soft); color: var(--ok); }
.pill.busy::before { animation: pulse 1.2s ease-in-out infinite; }
.pill.manual { background: var(--warn-soft); color: var(--warn); }
@keyframes pulse { 50% { opacity: .3; } }

.main { padding: var(--space-4) var(--space-4) calc(var(--tabbar-h) + env(safe-area-inset-bottom) + var(--space-8)); max-width: 820px; margin: 0 auto; }
.view { display: grid; gap: var(--space-4); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); -webkit-backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--border);
}
.tab {
  display: grid; justify-items: center; gap: 2px; padding: 6px 0; border: 0; background: transparent; color: var(--muted);
  font-size: 11px; font-weight: 600; border-radius: 10px; cursor: pointer; min-height: 50px;
}
.tab svg { width: 24px; height: 24px; stroke-width: 1.8; }
.tab[aria-current="page"] { color: var(--primary); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; }
  .tabs {
    position: sticky; top: 64px; align-self: start; grid-template-columns: 1fr; gap: 2px; padding: var(--space-4) var(--space-3);
    background: transparent; border: 0; backdrop-filter: none; -webkit-backdrop-filter: none;
  }
  .tab { display: flex; justify-content: flex-start; gap: var(--space-3); font-size: var(--text-sm); padding: 0 var(--space-3); min-height: 44px; }
  .tab svg { width: 20px; height: 20px; }
  .tab[aria-current="page"] { background: var(--primary-soft); }
  .main { padding: var(--space-6) var(--space-8) var(--space-12); margin: 0; }
}

/* ---------- Карточки ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-4); box-shadow: var(--shadow); }
.stack { display: grid; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: var(--space-2); }
.count { color: var(--muted); font-weight: 500; font-size: var(--text-sm); margin-left: 4px; }

.status-card { display: grid; gap: var(--space-3); }
.status-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.status-title { font-size: var(--text-lg); font-weight: 700; }
.warn { padding: var(--space-3); border-radius: var(--radius-sm); background: var(--warn-soft); color: var(--warn); font-size: var(--text-sm); }

.list { display: grid; gap: var(--space-3); }
.sup { display: grid; gap: var(--space-2); }
.sup-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); }
.sup-name { font-weight: 650; font-size: var(--text-base); overflow-wrap: anywhere; }
.sup-num { color: var(--faint); font-weight: 600; margin-right: 6px; }
.badge { flex: none; padding: 3px 9px; border-radius: 999px; font-size: var(--text-xs); font-weight: 650; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.badge.active { background: var(--ok-soft); color: var(--ok); }
.badge.verify, .badge.check { background: var(--warn-soft); color: var(--warn); }
.badge.expired { background: var(--danger-soft); color: var(--danger); }
.facts { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-4); font-size: var(--text-sm); }
.facts b { font-weight: 600; }
.last { font-size: var(--text-sm); color: var(--muted); background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-2) var(--space-3); overflow-wrap: anywhere; }
.last time { color: var(--faint); margin-right: 6px; font-variant-numeric: tabular-nums; }
.sup-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.sup-actions .btn { min-height: 38px; padding: 0 var(--space-3); }
.empty { text-align: center; padding: var(--space-8) var(--space-4); color: var(--muted); display: grid; gap: var(--space-3); justify-items: center; }
.empty svg { width: 36px; height: 36px; color: var(--faint); }

.fold summary { cursor: pointer; font-weight: 650; font-size: var(--text-lg); list-style: none; display: flex; align-items: center; justify-content: space-between; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; margin-right: 4px; }
.fold[open] summary::after { transform: rotate(-135deg); }
.fold[open] summary { margin-bottom: var(--space-3); }
.hist { display: grid; gap: var(--space-2); font-size: var(--text-sm); }
.hist div { display: flex; justify-content: space-between; gap: var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--border); }
.hist div:last-child { border: 0; }

.skeleton { height: 140px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sk 1.2s linear infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ---------- Экран ---------- */
.screen-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-2); }
.screen-tools .seg { min-width: 200px; }
.icon-row { display: flex; gap: var(--space-1); }
.screen-scroll { overflow: auto; border-radius: var(--radius); -webkit-overflow-scrolling: touch; }
.screen-wrap.zoom { width: 220%; }
.zoom-btn { font-weight: 700; font-size: var(--text-sm); }
.zoom-btn[aria-pressed="true"] { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-soft); }
.screen-wrap { position: relative; aspect-ratio: 1366 / 900; border-radius: var(--radius); overflow: hidden; background: var(--surface-2); border: 1px solid var(--border); touch-action: manipulation; }
.screen-wrap img { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.screen-msg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: var(--text-sm); padding: var(--space-4); text-align: center; }
.tap-dot { position: absolute; width: 26px; height: 26px; margin: -13px 0 0 -13px; border-radius: 50%; border: 3px solid var(--primary); background: color-mix(in srgb, var(--primary) 25%, transparent); pointer-events: none; animation: tap .6s ease-out forwards; }
@keyframes tap { from { transform: scale(.4); opacity: 1; } to { transform: scale(1.4); opacity: 0; } }
.screen-meta { display: flex; justify-content: space-between; align-items: center; gap: var(--space-3); flex-wrap: wrap; }
.login-wb { border-color: var(--primary); display: grid; gap: var(--space-3); }

/* ---------- Журнал ---------- */
.search { background: var(--surface); }
.live { font-size: var(--text-xs); color: var(--ok); display: inline-flex; align-items: center; gap: 6px; }
.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 2s ease-in-out infinite; }
.live.off { color: var(--faint); }
.live.off::before { animation: none; }
.log { list-style: none; margin: 0; padding: 0; display: grid; gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.log li { background: var(--surface); padding: var(--space-2) var(--space-3); font-size: var(--text-sm); overflow-wrap: anywhere; display: grid; gap: 2px; }
.log time { font-size: var(--text-xs); color: var(--faint); font-variant-numeric: tabular-nums; }
.log li.good { box-shadow: inset 3px 0 0 var(--ok); }
.log li.bad { box-shadow: inset 3px 0 0 var(--danger); }
.log li.fresh { animation: fresh 1.5s ease-out; }
@keyframes fresh { from { background: var(--primary-soft); } }
.notices { display: grid; gap: var(--space-2); margin-top: var(--space-3); }
.notice { display: grid; gap: var(--space-2); font-size: var(--text-sm); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.notice img { width: 100%; border-radius: 8px; border: 1px solid var(--border); }

/* ---------- Кабинеты ---------- */
.cab-list { display: grid; gap: var(--space-2); }
.cab { display: grid; gap: var(--space-2); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.cab-top { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); }
.cab textarea { min-height: 70px; }

/* ---------- Шторка ---------- */
.sheet-back { position: fixed; inset: 0; z-index: 40; background: rgb(15 10 20 / 45%); animation: fade .2s; }
.sheet {
  position: fixed; z-index: 50; left: 0; right: 0; bottom: 0; max-height: 92dvh; display: flex; flex-direction: column;
  background: var(--surface); border-radius: 20px 20px 0 0; box-shadow: 0 -8px 30px rgb(0 0 0 / 18%);
  padding-bottom: env(safe-area-inset-bottom); animation: up .25s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 700px) {
  .sheet { left: 50%; right: auto; bottom: auto; top: 50%; width: min(620px, 92vw); transform: translate(-50%, -50%); border-radius: 20px; max-height: 86dvh; animation: fade .2s; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-4) var(--space-2); }
.sheet-body { overflow: auto; padding: var(--space-2) var(--space-4) var(--space-5); display: grid; gap: var(--space-3); -webkit-overflow-scrolling: touch; }
.sheet-body img { width: 100%; border-radius: var(--radius-sm); border: 1px solid var(--border); }
.out-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: var(--text-sm); background: var(--surface-2); border-radius: var(--radius-sm); padding: var(--space-3); margin: 0; font-family: var(--font); }
.mark-list { display: grid; gap: var(--space-1); }
.mark-list button { text-align: left; min-height: 40px; padding: var(--space-2) var(--space-3); border: 1px solid var(--border); background: var(--surface); border-radius: 8px; font-size: var(--text-sm); cursor: pointer; }
.sheet-actions { display: flex; gap: var(--space-2); justify-content: flex-end; flex-wrap: wrap; }
.menu-list { display: grid; gap: var(--space-2); }
.menu-list .btn { justify-content: flex-start; }
@keyframes up { from { transform: translateY(30px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

/* ---------- Всплывающие сообщения ---------- */
.toasts { position: fixed; z-index: 60; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px); width: min(520px, calc(100vw - 24px)); display: grid; gap: var(--space-2); pointer-events: none; }
.toast { pointer-events: auto; background: var(--text); color: var(--bg); padding: var(--space-3) var(--space-4); border-radius: 12px; box-shadow: 0 8px 24px rgb(0 0 0 / 20%); font-size: var(--text-sm); white-space: pre-wrap; overflow-wrap: anywhere; animation: drop .25s ease-out; cursor: pointer; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.bad { background: var(--danger); color: #fff; }
@keyframes drop { from { transform: translateY(10px); opacity: 0; } }
@media (min-width: 900px) { .toasts { bottom: auto; top: 76px; } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
