/* Пульт флота — мини-приложение Telegram. Цвета — из темы Telegram (--tg-theme-*), запасные — ниже.
   Акцент — чернила; цвет только у статусов, проблем и минуса (brain/process/design-dna.md).
   Мелкий текст — --muted (смесь текста и фона ≥ 4.5:1), не hint_color Telegram (#999 на белом — 2.8:1). */

:root {
  --fb-page: #f2f2f0;
  --fb-surface: #ffffff;
  --fb-ink: #0b0b0c;
  --fb-line: rgba(11, 11, 12, .09);
  --fb-muted: #5c5c61;
  --fb-bar: #8e8e93;
  --fb-hatch: rgba(11, 11, 12, .2);

  --ok: #1f9d55;
  --warn: #c07a06;
  --warn-ink: #855300;
  --warn-soft: rgba(192, 122, 6, .13);
  --bad: #d33a2c;
  --bad-ink: #b02a22;
  --bad-soft: rgba(211, 58, 44, .12);
  --urgent: #b42318;

  --page: var(--tg-theme-secondary-bg-color, var(--fb-page));
  --surface: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, var(--fb-surface)));
  --ink: var(--tg-theme-text-color, var(--fb-ink));
  --line: var(--tg-theme-section-separator-color, var(--fb-line));
  --muted: var(--fb-muted);
  --bar: var(--fb-bar);
  --hatch: var(--fb-hatch);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, "Roboto Mono", monospace;
  --r: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-scheme="light"]) {
    --fb-page: #0b0b0c;
    --fb-surface: #18181a;
    --fb-ink: #ececec;
    --fb-line: rgba(255, 255, 255, .09);
    --fb-muted: #a6a6ab;
    --fb-bar: #77777c;
    --fb-hatch: rgba(255, 255, 255, .22);
    --ok: #35c06d;
    --warn: #e2a43b;
    --warn-ink: #f2b955;
    --warn-soft: rgba(226, 164, 59, .16);
    --bad: #f2564b;
    --bad-ink: #ff7a70;
    --bad-soft: rgba(242, 86, 75, .17);
    --urgent: #b3261e;
    color-scheme: dark;
  }
}

:root[data-scheme="dark"] {
  --fb-page: #0b0b0c;
  --fb-surface: #18181a;
  --fb-ink: #ececec;
  --fb-line: rgba(255, 255, 255, .09);
  --fb-muted: #a6a6ab;
  --fb-bar: #77777c;
  --fb-hatch: rgba(255, 255, 255, .22);
  --ok: #35c06d;
  --warn: #e2a43b;
  --warn-ink: #f2b955;
  --warn-soft: rgba(226, 164, 59, .16);
  --bad: #f2564b;
  --bad-ink: #ff7a70;
  --bad-soft: rgba(242, 86, 75, .17);
  --urgent: #b3261e;
  color-scheme: dark;
}

/* в теме Telegram серые — из её текста и фона, чтобы контраст держался на любой теме */
@supports (color: color-mix(in srgb, red 50%, blue)) {
  :root, :root[data-scheme] {
    --muted: color-mix(in srgb, var(--ink) 66%, var(--surface));
    --bar: color-mix(in srgb, var(--ink) 45%, var(--surface));
    --hatch: color-mix(in srgb, var(--ink) 24%, transparent);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--ink);
  font: 15px/1.35 var(--font);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:focus-visible, a:focus-visible, .charts:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }
[hidden] { display: none !important; }
.neg { color: var(--bad-ink); }

/* верхняя строка: одна строка постоянной высоты — её содержимое не сдвигает карточки */
.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 4px;
  height: 56px;
  padding: 0 6px 0 12px;
  background: var(--page);
}
.bar.has-back { padding-left: 4px; }
.bar-status {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  /* лента шире экрана уходит в тень справа — видно, что она листается */
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
}
.bar-status::-webkit-scrollbar { display: none; }
.icon-btn {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--ink);
}
.icon-btn[aria-pressed="true"] { background: var(--surface); }
.icon-btn:active { transform: scale(.94); }
.jb {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 44px;
  padding: 0 12px 0 10px;
  border-radius: 12px;
  background: var(--surface);
  font-size: 14px;
  white-space: nowrap;
}

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 12px 28px; }

/* метки: цвет — по серьёзности проблемы */
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip {
  flex: none;
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  background: var(--bad-soft);
  color: var(--bad-ink);
}
.chip i { font-style: normal; font-weight: 400; font-variant-numeric: tabular-nums; }
.chip.warn { background: var(--warn-soft); color: var(--warn-ink); }
.chip.urgent { background: var(--urgent); color: #fff; }
.chip.demo { background: var(--ink); color: var(--surface); letter-spacing: .02em; }

/* статус: точка; пауза и стоп дня — значок; неизвестно или снимок устарел — серый */
.st { flex: none; width: 10px; height: 10px; display: grid; place-items: center; color: var(--muted); }
.st svg { display: block; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--bar); }
.st-ok .dot { background: var(--ok); }
.st-warn .dot { background: var(--warn); }
.st-bad .dot { background: var(--bad); }
.st-warn { color: var(--warn); }
.st-bad { color: var(--bad); }

/* карточки */
.list { display: grid; gap: 8px; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 700px) {
  .list { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
}
.card { position: relative; background: var(--surface); border-radius: var(--r); }
.card.flash { box-shadow: 0 0 0 2px var(--ink); }
.card-open {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px 12px 12px;
  border-radius: var(--r);
}
.row1 { display: flex; flex-wrap: wrap; align-items: center; column-gap: 8px; row-gap: 2px; min-height: 24px; padding-right: 52px; }
.title { flex: 1 1 auto; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.pnl { flex: none; margin-left: auto; font-size: 17px; font-weight: 500; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.pnl.none { color: var(--muted); }
.row2 {
  display: block;
  margin: 2px 52px 0 18px;
  font-size: 14px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.row2 .ink { color: var(--ink); }
.row2 .w { color: var(--warn-ink); }
.row2 .why { color: var(--bad-ink); }
.card .chips { margin: 10px 0 0 18px; }

/* полоса 24 часов: ордера по часам */
.strip { display: flex; height: 20px; margin: 10px 0 0 18px; }
.strip i { flex: 1; display: flex; align-items: flex-end; justify-content: center; }
.strip i.x { background: var(--bad-soft); }
.strip i.nd { background: repeating-linear-gradient(135deg, var(--hatch) 0 1px, transparent 1px 4px); }
.strip b { display: block; width: 64%; background: var(--bar); border-radius: 1.5px 1.5px 0 0; }
.strip b.z { height: 2px; border-radius: 0; }
.strip i.part b { opacity: .45; }
.is-stop .strip b, .is-daystop .strip b { opacity: .5; }

.act {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--page);
  color: var(--ink);
}
.act:active { transform: scale(.94); }
.act[aria-disabled="true"] { cursor: default; background: transparent; }
.act[aria-disabled="true"]:active { transform: none; }
.act .dim { display: grid; opacity: .35; }
.spin { animation: spin .8s linear infinite; transform-origin: 50% 50%; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } }

.go-wrap:empty { display: none; }
.go-wrap { padding: 0 14px 12px 30px; }
.go {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--page);
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
}

/* пустые состояния */
.empty { margin: 0; padding: 28px 12px; text-align: center; font-size: 14px; color: var(--muted); }
.retry {
  min-height: 44px;
  margin-left: 8px;
  padding: 0 16px;
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 500;
}
.surface .retry { background: var(--page); }

/* деталь юнита */
.surface { background: var(--surface); border-radius: var(--r); }
.unit-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; max-width: 880px; margin: 0 auto; }
.head { position: relative; }
.head .info { padding: 14px 14px 14px 12px; }
.head .row1 { min-height: 28px; }
.head .title { font-size: 20px; letter-spacing: -.01em; }
.uid { display: block; margin: 0 52px 0 18px; font: 13px/1.4 var(--mono); color: var(--muted); }
.head .row2 { margin-top: 6px; }
.head .chips { margin: 10px 0 0 18px; }
.head .act { top: 10px; right: 10px; }

.chart-card { padding: 10px 14px 12px; }
.chart-card .chart-top { margin-bottom: 10px; }
.chart-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.seg { display: inline-flex; padding: 2px; border-radius: 12px; background: var(--page); }
.seg button {
  min-width: 56px;
  min-height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  font-size: 14px;
  color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); font-weight: 500; }
.rd { flex: 1; min-width: 0; height: 44px; display: flex; flex-direction: column; justify-content: flex-end; align-items: stretch; font-variant-numeric: tabular-nums; }
.rd > * { min-width: 0; }
.ro { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ro.m { font-size: 13px; line-height: 18px; color: var(--muted); }
.hp { height: 38px; margin-top: 6px; font-size: 14px; line-height: 19px; color: var(--bad-ink); overflow: hidden;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.wsum { font-size: 17px; line-height: 24px; font-weight: 500; }
.chart-l .hv { color: var(--ink); font-weight: 500; }

.charts { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; outline: none; }
.chart { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.chart:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.chart-l { display: flex; justify-content: space-between; min-height: 18px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.chart svg { display: block; width: 100%; overflow: hidden; }
.chart .p { fill: var(--ink); opacity: .82; }
.chart .n { fill: var(--bad); }
.chart .q { fill: var(--bar); }
.chart .q.z { opacity: .8; }
.chart .part { opacity: .4; }
.chart .zl { stroke: var(--line); }
.chart .dl { stroke: var(--line); stroke-dasharray: 2 3; }
.chart .bb { fill: var(--bad-soft); }
.chart .ht { fill: var(--hatch); }
.chart .cur { fill: var(--ink); opacity: .09; }
.axis { position: relative; height: 20px; margin-top: 4px; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }
.axis span { position: absolute; top: 2px; padding-left: 3px; white-space: nowrap; }

.events { padding: 2px 14px; }
.ev { display: flex; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); font-size: 14px; }
.ev:first-child { border-top: 0; }
.ev time { flex: none; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 88px; }

/* вкладка «по дням» */
.days-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; max-width: 560px; margin: 0 auto; }
.total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 14px 16px; }
.total .range { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.total .sum { font-size: 28px; font-weight: 500; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.days { padding: 0 16px; }
.day {
  display: grid;
  grid-template-columns: 46px 26px 1fr 104px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border-top: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.day:first-child { border-top: 0; }
.day .wd { font-size: 14px; color: var(--muted); }
.day .v { text-align: right; font-weight: 500; }
.dbar { position: relative; height: 14px; }
.dbar::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px; background: var(--line); }
.dbar i { position: absolute; top: 3px; height: 8px; border-radius: 2px; }
.dbar .p { left: 50%; background: var(--ink); opacity: .82; }
.dbar .n { right: 50%; background: var(--bad); }

.gate { margin: 30vh 16px 0; text-align: center; font-size: 15px; color: var(--ink); }

@media (min-width: 700px) {
  .wrap { padding: 0 20px 32px; }
  .bar {
    padding-left: max(20px, calc((100% - 1120px) / 2 + 20px));
    padding-right: max(10px, calc((100% - 1120px) / 2 + 10px));
  }
  .bar.has-back { padding-left: max(8px, calc((100% - 1120px) / 2 + 8px)); }
}
