/* ---------- темы ---------- */
:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --fg: #1d232b;
  --muted: #66707c;
  --line: #dde2e7;
  --accent: #2563eb;
  --on: #2e9e4f;
  --maybe: #f0bf2a;
  --maybe-text: #d4a106;
  --off: #e04848;
  --sure: #a61b1b;
  --hand: #111821;
  --hatch: rgba(0, 0, 0, .35);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #12161b;
  --card: #1b2128;
  --fg: #e8ecf0;
  --muted: #96a0ab;
  --line: #2e363f;
  --accent: #6ea0ff;
  --on: #33a957;
  --maybe: #e2b321;
  --maybe-text: #e2b321;
  --off: #df5050;
  --sure: #a8241d;
  --hand: #ffffff;
  --hatch: rgba(0, 0, 0, .45);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12161b;
    --card: #1b2128;
    --fg: #e8ecf0;
    --muted: #96a0ab;
    --line: #2e363f;
    --accent: #6ea0ff;
    --on: #33a957;
    --maybe: #e2b321;
  --maybe-text: #e2b321;
    --off: #df5050;
    --sure: #a8241d;
    --hand: #ffffff;
    --hatch: rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
/* страховка: горизонтальной прокрутки страницы не бывает никогда */
html, body { overflow-x: hidden; }
@supports (overflow-x: clip) { html, body { overflow-x: clip; } }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Ubuntu, Roboto, sans-serif;
  transition: background-color .2s, color .2s;
}
main { max-width: 980px; margin: 0 auto; padding: 14px 16px 40px; }
a { color: var(--accent); }

/* ---------- верхнее меню qHub ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) calc(16px + env(safe-area-inset-right, 0px)) 10px calc(16px + env(safe-area-inset-left, 0px));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; flex: none; }
.logo { width: 22px; height: 22px; border-radius: 6px; background: url(/static/favicon.svg) center/cover; flex: none; }

/* ---------- боковая шторка ---------- */
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 15;
  background: rgba(10, 15, 20, .45);
  opacity: 0; pointer-events: none; transition: opacity .22s;
}
.drawer-backdrop.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 20;
  width: min(300px, 86vw); overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 16px calc(20px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px));
  background: var(--card); border-right: 1px solid var(--line);
  transform: translateX(-100%); visibility: hidden;
  transition: transform .22s ease, visibility 0s .22s;
}
.drawer.open {
  transform: none; visibility: visible; transition: transform .22s ease;
  box-shadow: 0 0 32px rgba(0, 0, 0, .25);
}
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drawer-sec { display: flex; flex-direction: column; gap: 8px; }
.drawer .seg { display: flex; }
.drawer .seg-btn { flex: 1 1 0; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 10px; }
.drawer .seg-btn svg { width: 16px; height: 16px; flex: none; }
.drawer .seg-btn + .seg-btn { border-left: 1px solid var(--line); }
html.drawer-open, html.drawer-open body { overflow: hidden; }
[hidden] { display: none !important; }
.drawer-head .brand, .view-title { flex: 1 1 auto; min-width: 0; }
.view-title { margin: 0; font-size: 1.05rem; }
.head-actions { display: flex; gap: 8px; }
.drawer-view { display: flex; flex-direction: column; gap: 18px; flex: 1 1 auto; }
.account-sec { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--line); }
.account-box { display: flex; flex-direction: column; gap: 8px; }
.hint { margin: 0; color: var(--muted); font-size: .85rem; line-height: 1.4; }
.account-name { color: var(--fg); font-weight: 600; overflow-wrap: anywhere; }
.primary-btn {
  border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 8px;
  font: inherit; font-size: .9rem; font-weight: 600; padding: 9px 12px; cursor: pointer;
}
.primary-btn.ghost { background: transparent; color: var(--accent); }
.primary-btn:disabled { opacity: .6; cursor: default; }
.primary-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.opt-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.opt-table th, .opt-table td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: center; }
.opt-table thead th { color: var(--muted); font-size: .75rem; font-weight: 600; }
.opt-table tbody th { text-align: left; font-weight: 600; }
.opt-table input { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; margin: 0; }
.opt-table input:disabled { cursor: default; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; color: var(--muted); }
.field input {
  font: inherit; font-size: 1rem; color: var(--fg); background: var(--bg);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.auth-error { margin: 0; color: var(--off); font-size: .85rem; min-height: 1em; }
.auth-error:empty { display: none; }
@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer.open, .drawer-backdrop { transition: none; }
}

/* ---------- шапка ---------- */
main > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
main > header h1 { margin: 0; font-size: 1.5rem; }
main > header .sub { margin: 4px 0 16px; color: var(--muted); font-size: .9rem; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); }
.seg-btn {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: .85rem; font-weight: 600; padding: 6px 10px; cursor: pointer;
}
.seg-btn[aria-pressed="true"] { background: var(--accent); color: #fff; }
.icon-btn {
  width: 36px; height: 34px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--card); color: var(--fg); cursor: pointer; display: grid; place-items: center; padding: 0; flex: none;
}
.icon-btn:hover, .seg:hover { border-color: var(--accent); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; } /* .seg обрезает выступающее */
.icon-btn svg { width: 18px; height: 18px; }

/* ---------- выбор ---------- */
.controls { display: flex; flex-wrap: wrap; gap: 12px 28px; margin-bottom: 16px; }
.group { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: .8rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.queues, .days { display: flex; flex-wrap: wrap; gap: 6px; }

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--fg);
  border-radius: 8px;
  padding: 6px 12px;
  font: inherit;
  cursor: pointer;
  min-width: 52px;
}
.btn:hover { border-color: var(--accent); }
.btn[aria-checked="true"], .btn[aria-selected="true"] {
  background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600;
}
.btn .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--off); margin-left: 5px; vertical-align: middle; }
.btn .dot.conflict { background: transparent; box-shadow: inset 0 0 0 1.5px var(--off); width: 8px; height: 8px; }
.btn[aria-checked="true"] .dot.conflict { box-shadow: inset 0 0 0 1.5px #fff; }

/* ---------- статус ---------- */
.status {
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 6px solid var(--muted);
  border-radius: 10px;
  padding: 12px 16px;
  margin-bottom: 18px;
  min-height: 56px;
}
.status.c-green { border-left-color: var(--on); }
.status.c-yellow { border-left-color: var(--maybe); }
.status.c-red { border-left-color: var(--off); }
.status .big { font-size: 1.25rem; font-weight: 650; }
.status .small { color: var(--muted); font-size: .92rem; margin-top: 2px; }
.status .fact-off { color: var(--off); font-weight: 600; }
.status .fact-conflict { color: var(--maybe-text); font-weight: 600; }
.status.error { border-left-color: var(--off); }

/* ---------- циферблаты ---------- */
.dials { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr)); gap: 6px; margin-bottom: 18px; }
.dial {
  margin: 0;
  position: relative;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 10px 14px;
  transition: opacity .3s;
}
.dial-head {
  position: relative; z-index: 1; pointer-events: none; /* поверх SVG, когда он подтянут вверх */
  display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 6px;
  min-height: 6.4rem; padding: 2px 6px 0; /* одинаково у обоих, чтобы циферблаты стояли ровно */
}
.corner { line-height: 1.15; min-width: 0; }
.corner.right { text-align: right; }
.corner > div { width: fit-content; }            /* прямоугольник = текст, для расчёта наложений */
.corner.right > div { margin-left: auto; }
.corner.bottom-left { position: absolute; left: 16px; bottom: 12px; z-index: 1; pointer-events: none; }
/* текущее время чуть крупнее; отступ уменьшен на прирост, чтобы низ цифр
   остался на одной линии с первым временем справа */
.corner.left { padding-top: calc((.78rem + 1.7rem - 2rem) * 1.15); }
.colon { animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .colon { animation: none; } }
.corner .lbl { color: var(--muted); font-size: .78rem; text-transform: lowercase; }
.corner .val { font-size: 1.7rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: .01em; }
.corner .val.is-on { color: var(--on); }
.corner .val.is-off { color: var(--off); }
.corner .val.is-maybe { color: var(--maybe-text); }
.corner .val + .lbl { margin-top: 4px; }
.corner.left .val { font-size: 2rem; }
@media (max-width: 640px) {
  /* в одну колонку: активный циферблат первым */
  .dial.active { order: -1; }
  .dial:not(.active) .dial-head { min-height: 0; }
}
@media (max-width: 420px) {
  .corner .val { font-size: 1.4rem; }
  .corner.left .val { font-size: 1.65rem; }
  .corner.left { padding-top: calc((.78rem + 1.4rem - 1.65rem) * 1.15); }
}
.dial svg { display: block; width: 100%; max-width: 430px; margin: 0 auto; height: auto; }
.dial.dim { opacity: .6; }
.dials.single { grid-template-columns: minmax(min(280px, 100%), 520px); justify-content: center; }
.dials.single #dial-pm { display: none; }
.ring { transition: opacity .3s; }
.ring-dim { opacity: .55; }
.inner-label {
  fill: #fff; font-size: 12px; font-weight: 600; text-anchor: middle; dominant-baseline: central;
  paint-order: stroke; stroke: rgba(0, 0, 0, .45); stroke-width: 2.5px; pointer-events: none;
}
.ring-sep { fill: none; stroke: var(--card); stroke-width: 2.5; }

.sector { stroke-width: .8; }
.t-on { fill: var(--on); stroke: var(--on); background: var(--on); }
.t-maybe { fill: var(--maybe); stroke: var(--maybe); background: var(--maybe); }
.t-off { fill: var(--off); stroke: var(--off); background: var(--off); }
.t-sure { fill: var(--sure); stroke: var(--sure); background: var(--sure); }
/* без filter: он выносит сектор в отдельный слой и ломает градиент затемнения поверх */
.sector.t-on:hover { fill: color-mix(in srgb, var(--on) 85%, #fff); }
.sector.t-maybe:hover { fill: color-mix(in srgb, var(--maybe) 85%, #fff); }
.sector.t-off:hover { fill: color-mix(in srgb, var(--off) 85%, #fff); }
.sector.t-sure:hover { fill: color-mix(in srgb, var(--sure) 85%, #fff); }
.sector { cursor: pointer; }
.hatch { pointer-events: none; }
.hour-tick, .rim, .ring-sep, .hand, .hand-outline, .hand-cap, .hour-label { pointer-events: none; }
/* выделенная зона: остальные сектора приглушены, зона обведена */
.has-sel .sector:not(.sel), .has-sel .hatch:not(.sel) { opacity: .3; }
.sel-outline { fill: none; stroke: var(--fg); stroke-width: 2.5; stroke-linejoin: round; pointer-events: none; }
.hatch-line { stroke: var(--hatch); stroke-width: 2.2; }
.hour-tick { stroke: var(--card); stroke-width: 2.5; stroke-linecap: butt; }
.start-shade { fill: #000; pointer-events: none; }
.rim { fill: none; stroke: var(--line); stroke-width: 1.5; }
.hour-label { fill: var(--fg); font-size: 16px; font-weight: 600; text-anchor: middle; dominant-baseline: central; }
.hand { stroke: var(--hand); stroke-width: 3.5; stroke-linecap: round; }
.hand-outline { stroke: var(--card); stroke-width: 7.5; stroke-linecap: round; }
.hand-cap { fill: var(--hand); stroke: var(--card); stroke-width: 2.5; }

/* ---------- легенда и интервалы ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 8px 20px; margin: 18px 0 8px; color: var(--muted); font-size: .9rem; }
.sw { display: inline-block; width: 14px; height: 14px; border-radius: 4px; margin-right: 6px; vertical-align: -2px; flex: none; }
.sw.t-sure { background-image: repeating-linear-gradient(45deg, transparent 0 3px, var(--hatch) 3px 5px); }

.intervals h2 { font-size: 1.05rem; margin: 18px 0 8px; }
.intervals ul { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 6px; }
.intervals li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  display: flex; align-items: center; gap: 8px;
}
.intervals li .time { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
/* описание и длительность переносятся, а не вылезают за карточку на узких экранах */
.intervals li .what { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.intervals li .dur { color: var(--muted); margin-left: auto; font-size: .85rem; text-align: right; flex: none; }
.intervals li { cursor: pointer; }
.intervals li:hover { border-color: var(--accent); }
.intervals li:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.intervals li.now { outline: 2px solid var(--accent); }
.intervals li.sel { border-color: var(--fg); box-shadow: inset 0 0 0 1px var(--fg); background: color-mix(in srgb, var(--accent) 10%, var(--card)); }
@media (max-width: 480px) {
  /* на телефоне описание уходит под время, чтобы длинные слова не рвались и не вылезали */
  .intervals li {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto;
    grid-template-areas: "sw time dur" "sw what dur"; column-gap: 10px; row-gap: 1px; align-items: center;
  }
  .intervals li .sw { grid-area: sw; margin-right: 0; }
  .intervals li .time { grid-area: time; }
  .intervals li .what { grid-area: what; font-size: .9rem; }
  .intervals li .dur { grid-area: dur; }
}

/* ---------- футер ---------- */
.meta { margin-top: 22px; color: var(--muted); font-size: .85rem; display: flex; flex-direction: column; gap: 3px; }
.meta .warn { color: var(--off); }
.meta .fresh { color: var(--accent); font-weight: 600; }
.live { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-right: 5px; vertical-align: 0; }
.live.on { background: var(--on); box-shadow: 0 0 0 3px color-mix(in srgb, var(--on) 25%, transparent); }
