:root {
  --bg: #f6f7f9; --card: #fff; --text: #1c2430; --muted: #6b7686; --line: #e3e7ed;
  --accent: #2563eb; --accent-d: #1d4ed8; --ok: #16a34a; --warn: #d97706; --err: #dc2626;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171c; --card: #1c2027; --text: #e7eaf0; --muted: #95a0b0; --line: #2c333d; --accent: #4f8bff; --accent-d: #6b9cff; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
header { background: var(--card); border-bottom: 1px solid var(--line); }
nav { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 52px; }
nav .brand { font-weight: 700; color: var(--text); margin-right: 12px; }
nav a.item { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
nav a.item:hover, nav a.item.on { color: var(--text); background: var(--bg); text-decoration: none; }
nav .sp { flex: 1; }
nav form { margin: 0; }
.badge-n { background: var(--err); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; margin-left: 2px; }
main { max-width: 1200px; margin: 24px auto; padding: 0 16px 48px; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 24px 0 10px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.row h1 { margin: 0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.btn, button { font: inherit; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: 7px 14px; border-radius: 8px; display: inline-block; }
.btn:hover, button:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover, button.primary:hover { background: var(--accent-d); }
button.link { border: 0; background: none; color: var(--muted); padding: 6px 10px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 720px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 15px; margin: 10px 0; }
.check input { width: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 500; font-size: 12px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }
.tag { display: inline-block; font-size: 12px; padding: 1px 9px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); white-space: nowrap; }
.s-new { color: var(--accent); border-color: var(--accent); }
.s-in_progress { color: var(--warn); border-color: var(--warn); }
.s-waiting_user { color: #7c3aed; border-color: #7c3aed; }
.s-resolved, .s-closed { color: var(--ok); border-color: var(--ok); }
.u-3 { color: var(--warn); border-color: var(--warn); }
.u-4 { color: var(--err); border-color: var(--err); font-weight: 600; }
.overdue { color: var(--err); font-weight: 600; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 14px; border-radius: 8px; color: var(--muted); }
.tabs a.on { background: var(--card); border: 1px solid var(--line); color: var(--text); }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid var(--ok); color: var(--ok); background: var(--card); }
.flash.err { border-color: var(--err); color: var(--err); }
.ann { border-left: 4px solid var(--warn); }
.ann.unplanned { border-left-color: var(--err); }
.ann h3 { margin: 0 0 4px; font-size: 15px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0 6px 18px; position: relative; font-size: 13px; color: var(--muted); }
.timeline li::before { content: ""; position: absolute; left: 3px; top: 13px; width: 7px; height: 7px; border-radius: 50%; background: var(--line); }
.timeline li.transfer::before, .timeline li.return::before { background: var(--warn); }
.timeline li.comment { color: var(--text); font-size: 15px; padding: 10px 14px; margin: 6px 0 6px 18px; background: var(--bg); border-radius: 10px; }
.timeline li.comment::before { display: none; }
.timeline li.comment.internal { background: color-mix(in srgb, var(--warn) 10%, var(--bg)); }
.timeline .who { font-weight: 600; }
.kv { display: grid; grid-template-columns: 150px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.bar { background: var(--accent); height: 8px; border-radius: 4px; }
.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi div { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; }
.kpi b { display: block; font-size: 24px; } .kpi span { color: var(--muted); font-size: 13px; }
.center { max-width: 420px; margin: 8vh auto; }
.days { display: flex; align-items: flex-end; gap: 3px; height: 80px; }
.days i { flex: 1; background: var(--accent); border-radius: 2px 2px 0 0; min-height: 2px; opacity: .85; }

/* ---------- десктоп: скрыть мобильную панель ---------- */
.tabbar { display: none; }
.menu-list a { display: flex; justify-content: space-between; align-items: center; padding: 14px 4px; color: var(--text); border-bottom: 1px solid var(--line); }
.menu-list a:last-child { border-bottom: 0; }
.menu-list { padding-top: 4px; padding-bottom: 4px; }
.acard { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.acard .grid-cat { display: grid; grid-template-columns: 2fr 90px 130px 130px auto auto; gap: 10px; align-items: end; }
.acard .grid-cat label { margin: 0 0 3px; }
.acard .grid-dep { display: grid; grid-template-columns: 1fr auto auto auto; gap: 10px; align-items: center; }
.acard .check { margin: 0; }

/* ---------- мобильная версия ---------- */
@media (max-width: 720px) {
  body { font-size: 16px; }
  body.with-tabbar { padding-bottom: calc(66px + env(safe-area-inset-bottom)); }
  nav { min-height: 46px; padding: 0 12px; }
  nav .desk { display: none !important; }
  nav .brand { font-size: 16px; }
  main { margin: 14px auto; padding: 0 12px 24px; }
  h1 { font-size: 20px; }
  .row { margin-bottom: 12px; }
  .card { padding: 14px; border-radius: 12px; }

  /* поля ≥16px, чтобы iOS не увеличивал страницу при фокусе; крупные зоны нажатия */
  input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=search], select, textarea {
    font-size: 16px; padding: 11px 12px; }
  .btn, button { min-height: 44px; padding: 10px 16px; }
  button.link { min-height: 0; }
  input[type=checkbox], input[type=radio] { width: 20px; height: 20px; }
  input[type=file] { width: 100%; font-size: 14px; }
  .actions { gap: 8px; }
  .actions > .btn, .actions > button, .actions > form { flex: 1 1 auto; }
  .actions form button { width: 100%; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dt { margin-top: 10px; font-size: 12px; }
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 -12px 12px; padding: 0 12px; scrollbar-width: none; }
  .tabs a { white-space: nowrap; }
  .tabs form { display: none; }

  /* таблицы → карточки */
  .card:has(> table.rt) { background: none; border: 0; padding: 0; overflow: visible !important; }
  table.rt, table.rt tbody { display: block; }
  table.rt thead { display: none; }
  table.rt tr { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 10px; }
  table.rt td { display: block; border: 0; padding: 2px 0; }
  table.rt td[data-l]::before { content: attr(data-l) ": "; color: var(--muted); font-size: 12px; }
  table.rt td.main { font-size: 16px; font-weight: 500; }
  table.rt td.num { display: inline-block; margin-right: 8px; }
  table.rt td.hide-m { display: none; }

  .acard .grid-cat, .acard .grid-dep { grid-template-columns: 1fr 1fr; }
  .acard .grid-cat > div:first-of-type, .acard .grid-dep > input[type=text] { grid-column: 1 / -1; }
  .acard .grid-dep > .muted { grid-column: 1 / -1; }
  .kpi { grid-template-columns: 1fr 1fr; }
  .kpi b { font-size: 20px; }
  .flash { font-size: 15px; }

  /* нижняя панель */
  .tabbar { position: fixed; z-index: 20; left: 0; right: 0; bottom: 0; display: flex; background: var(--card);
    border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 7px 2px 6px;
    font-size: 11px; color: var(--muted); text-decoration: none; min-width: 0; }
  .tabbar a i { font-style: normal; font-size: 20px; line-height: 1.2; position: relative; }
  .tabbar a.on { color: var(--accent); font-weight: 600; }
  .tabbar a.plus i { background: var(--accent); color: #fff; width: 38px; height: 28px; border-radius: 14px; font-size: 22px; line-height: 28px; text-align: center; }
  .tabbar .badge-n { position: absolute; top: -3px; right: -10px; font-size: 10px; }
}
@media (min-width: 721px) { nav .bell { display: inline-block; } }
@media (display-mode: standalone) { header { padding-top: env(safe-area-inset-top); } }

/* ---------- v3: доступность, просрочки, справка ---------- */
nav .uname { font-weight: 600; color: var(--text); white-space: nowrap; max-width: 230px; overflow: hidden; text-overflow: ellipsis; }
button.avail { border-radius: 14px; padding: 3px 12px; font-size: 13px; color: var(--ok); border-color: var(--ok); background: transparent; }
button.avail.off { color: var(--muted); border-color: var(--line); background: var(--bg); }
tr.row-late { background: color-mix(in srgb, var(--err) 7%, transparent); }
td.due { white-space: nowrap; font-size: 13px; }
td.due.overdue { color: var(--err); font-weight: 600; }
.help details { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 0 16px; margin-bottom: 10px; }
.help summary { cursor: pointer; padding: 13px 0; font-weight: 600; }
.help details[open] summary { border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.help details > :last-child { margin-bottom: 14px; }
.help code { background: var(--bg); padding: 1px 6px; border-radius: 5px; }
@media (max-width: 720px) {
  nav .uname { max-width: 150px; font-size: 14px; padding: 6px 4px; }
  td.due { white-space: normal; }
  .acard .grid-cat { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 721px) and (max-width: 1100px) {
  nav { gap: 0; }
  nav a.item { padding: 6px 7px; font-size: 14px; }
  nav .uname { max-width: 160px; }
  button.avail { padding: 3px 9px; font-size: 12px; }
}

/* ---------- v4: общая кнопка сохранения, уведомления ---------- */
h3.sub { font-size: 15px; margin: 22px 0 6px; }
.savebar { position: sticky; bottom: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; margin-top: 14px;
  box-shadow: 0 -4px 14px rgba(0, 0, 0, .06); }
.nrow { align-items: flex-start; margin: 8px 0; }
.nrow input { margin-top: 3px; }
.check.del { color: var(--muted); font-size: 14px; }
html { scroll-behavior: smooth; scroll-padding-top: 12px; }
@media (max-width: 720px) {
  .savebar { bottom: calc(60px + env(safe-area-inset-bottom)); }
}

/* ---------- v4: графики (палитра dataviz: слоты 1–2 + порядковая шкала одного оттенка) ---------- */
:root {
  --s1: #2a78d6; --s2: #eb6834;
  --o1: #86b6ef; --o2: #3987e5; --o3: #1c5cab; --o4: #0d366b;   /* ordinal: больше = темнее */
}
@media (prefers-color-scheme: dark) {
  :root { --s1: #3987e5; --s2: #d95926;
    --o1: #184f95; --o2: #256abf; --o3: #3987e5; --o4: #6da7ec; }  /* на тёмном фоне больше = ярче */
}
.viz-svg { width: 100%; height: auto; display: block; overflow: visible; }
.viz-svg .grid { stroke: var(--line); stroke-width: 1; }
.viz-svg .axis { fill: var(--muted); font-size: 11px; }
.viz-svg .endlbl { fill: var(--text); font-size: 12px; }
.viz-svg .ln { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.viz-svg .ln.s1, .viz-svg .dot.s1 { stroke: var(--s1); } .viz-svg .ln.s2, .viz-svg .dot.s2 { stroke: var(--s2); }
.viz-svg .dot { stroke-width: 2; }
.viz-svg .dot.s1 { fill: var(--s1); stroke: var(--card); } .viz-svg .dot.s2 { fill: var(--s2); stroke: var(--card); }
.viz-svg .xh { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 3 3; pointer-events: none; }
.viz-svg .hit { fill: transparent; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin: 8px 0 2px; font-size: 13px; color: var(--text); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.sw.s1, .stack i.s1 { background: var(--s1); } .sw.s2 { background: var(--s2); }
.sw.o1, .stack i.o1 { background: var(--o1); } .sw.o2, .stack i.o2 { background: var(--o2); }
.sw.o3, .stack i.o3 { background: var(--o3); } .sw.o4, .stack i.o4 { background: var(--o4); }
.stack { display: flex; gap: 2px; height: 22px; margin-top: 4px; }
.stack i { border-radius: 4px; min-width: 4px; }
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hb { display: grid; grid-template-columns: minmax(110px, 44%) 1fr 34px; align-items: center; gap: 10px; color: var(--text); font-size: 14px; padding: 2px 0; border-radius: 6px; }
a.hb:hover { background: color-mix(in srgb, var(--s1) 8%, transparent); text-decoration: none; }
.hb-l { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hb-t { height: 10px; }
.hb-t i { display: block; height: 100%; background: var(--s1); border-radius: 0 4px 4px 0; }
.hb b { text-align: right; font-variant-numeric: tabular-nums; }
.cols { display: flex; align-items: flex-end; gap: 10px; height: 170px; padding-top: 6px; }
.col { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; font-size: 12px; }
.col i { width: 100%; max-width: 54px; background: var(--s1); border-radius: 4px 4px 0 0; min-height: 2px; display: block; }
.col span { color: var(--muted); text-align: center; line-height: 1.2; }
.col b { font-variant-numeric: tabular-nums; }
.col:hover i, .hb:hover .hb-t i { filter: brightness(1.12); }
.hm-wrap { overflow-x: auto; }
.hm { display: grid; grid-template-columns: 26px repeat(24, minmax(14px, 1fr)); gap: 2px; min-width: 520px; align-items: center; }
.hm em { font-style: normal; font-size: 10px; color: var(--muted); text-align: left; }
.hm .d { font-size: 11px; color: var(--muted); }
.hm i { height: 20px; border-radius: 3px; background: color-mix(in srgb, var(--s1) calc(var(--v) * 100%), transparent); }
.hm i.z { background: color-mix(in srgb, var(--muted) 12%, transparent); }
.meter { margin-bottom: 14px; }
.meter-h { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 4px; }
.meter-t { height: 10px; background: color-mix(in srgb, var(--s1) 16%, transparent); border-radius: 5px; overflow: hidden; }
.meter-t i { display: block; height: 100%; background: var(--s1); border-radius: 5px; }
.viz-tip { position: fixed; z-index: 100; pointer-events: none; background: var(--text); color: var(--card); padding: 6px 10px;
  border-radius: 8px; font-size: 12px; line-height: 1.45; white-space: pre-line; box-shadow: 0 4px 14px rgba(0,0,0,.25); max-width: 260px; }
.kpi a.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; color: var(--text); }
.kpi a.tile:hover { border-color: var(--accent); text-decoration: none; }
.kpi a.tile span, .kpi div span { color: var(--muted); font-size: 13px; }
.kpi a.tile b { display: block; font-size: 24px; }
.kpi a.tile.bad b { color: var(--err); }
.kpi a.tile .go { float: right; color: var(--muted); font-size: 13px; }
.card h3.ch { margin: 0 0 8px; font-size: 15px; }
.card p.sub { margin: -4px 0 8px; color: var(--muted); font-size: 13px; }
details.tbl summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-top: 10px; }
details.tbl table { font-size: 13px; margin-top: 6px; }
@media (max-width: 720px) {
  .hb { grid-template-columns: minmax(80px, 38%) 1fr 34px; }
  .cols { gap: 6px; }
}

/* ---------- v5: кликабельные строки, каналы уведомлений в профиле ---------- */
[hidden] { display: none !important; }
tr.clk { cursor: pointer; }
.chans { margin-top: 4px; }
.chan { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.chan:last-child { border-bottom: 0; }
.chan .cn { flex: 1 1 110px; min-width: 0; }
.chan form { margin: 0; }
.chan button { max-width: 100%; }
@media (max-width: 720px) {
  .chan > button:not(.link) { flex: 1 1 100%; }   /* кнопка на всю ширину под названием, не выходит за экран */
}
