/* Цвета и чернила. Светлая и тёмная темы выбираются по настройке системы. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f1f0ec;
  --surface-3: #e7e6e0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --ink-3: #6d6b66;
  --muted: #898781;
  --line: #e1e0d9;
  --line-strong: #c3c2b7;
  --accent: #256abf;
  --accent-soft: #e4effc;
  --on-accent: #ffffff;
  --bar: #2a78d6;
  --good: #0ca30c;
  --warning: #fab219;
  --serious: #ec835a;
  --critical: #d03b3b;
  --critical-soft: #fbecec;
  --critical-line: #f0c4c4;
  --warning-soft: #fdf4dd;
  --warning-line: #f1dca4;
  --bubble-in: #ffffff;
  --bubble-out: #dfecfc;
  --shadow: 0 1px 2px rgba(11, 11, 11, .06), 0 8px 24px rgba(11, 11, 11, .12);
  --focus: #256abf;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #232322;
    --surface-3: #2f2f2d;
    --ink: #f0efec;
    --ink-2: #c3c2b7;
    --ink-3: #a09e96;
    --muted: #898781;
    --line: #2c2c2a;
    --line-strong: #454541;
    --accent: #2a78d6;
    --accent-soft: #14263c;
    --on-accent: #ffffff;
    --bar: #3987e5;
    --critical-soft: #2e1717;
    --critical-line: #5a2626;
    --warning-soft: #2b2410;
    --warning-line: #57471a;
    --bubble-in: #232322;
    --bubble-out: #183152;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 8px 24px rgba(0, 0, 0, .55);
    --focus: #6da7ec;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- значки и тона состояния */
.icon { width: 14px; height: 14px; flex: none; color: var(--muted); }
.icon .icon-cut { stroke: var(--surface); }
.tone-critical { color: var(--critical); }
.tone-warning { color: var(--warning); }
.tone-good { color: var(--good); }
.tone-neutral { color: var(--muted); }
.tone-strong { color: var(--ink-2); }

/* ---------- каркас */
.app { display: flex; flex-direction: column; height: 100vh; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 18px;
  height: 52px; padding: 0 16px; flex: none;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 8px; white-space: nowrap; }
.brand strong { font-size: 16px; font-weight: 700; letter-spacing: .04em; }
.brand span { color: var(--ink-2); font-size: 13px; }
.tabs { display: flex; gap: 2px; }
.tab {
  border: 0; background: none; cursor: pointer;
  padding: 7px 12px; border-radius: 8px; color: var(--ink-2); font-weight: 500;
}
.tab:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-current="page"] { background: var(--surface-3); color: var(--ink); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 14px; min-width: 0; }
.conn { display: flex; align-items: center; gap: 6px; min-width: 0; color: var(--ink-2); font-size: 13px; }
.conn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me { display: flex; align-items: center; gap: 8px; white-space: nowrap; color: var(--ink-2); font-size: 13px; }
.me select { max-width: 190px; }
.me.attention select { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.user { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 13px; }
.user-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.topbar.signed-out .tabs, .topbar.signed-out .topbar-right { display: none; }
.demo-banner {
  flex: none; padding: 6px 16px; font-size: 13px; text-align: center;
  background: var(--warning-soft); border-bottom: 1px solid var(--warning-line);
}
.notice {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 8px 16px; background: var(--critical-soft); border-bottom: 1px solid var(--critical-line);
}
.main { flex: 1; min-height: 0; display: flex; min-width: 0; }
.boot { margin: auto; color: var(--ink-2); }

/* ---------- поля и кнопки */
input[type="search"], input[type="text"], input[type="email"], input[type="number"], input[type="time"], input[type="date"], select, textarea {
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 8px;
  padding: 5px 9px; min-height: 32px;
}
textarea { width: 100%; resize: vertical; min-height: 84px; line-height: 1.4; }
select { padding-right: 6px; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 5px 12px; border-radius: 8px; cursor: pointer;
  border: 1px solid var(--line-strong); background: var(--surface); font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.quiet { border-color: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--surface-2); color: var(--ink); }
.btn[aria-pressed="true"] { background: var(--surface-3); border-color: var(--ink-3); }
.btn:disabled { opacity: .5; cursor: default; filter: none; }
a.btn { text-decoration: none; color: inherit; }
a.btn.primary { color: var(--on-accent); }
.btn.wide { width: 100%; min-height: 40px; }
.field-label { color: var(--ink-3); font-size: 12.5px; font-weight: 500; }
.muted { color: var(--ink-3); }

/* ---------- метки */
.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  padding: 1px 8px 1px 6px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink-2); font-size: 12px; line-height: 18px;
}
.chip .icon { width: 12px; height: 12px; }
.chip.critical { background: var(--critical-soft); border-color: var(--critical-line); color: var(--ink); }
.chip.quiet { padding-left: 8px; background: var(--surface-2); border-color: transparent; }

/* ---------- страница «Диалоги» */
.dialogs {
  flex: 1; min-width: 0; min-height: 0; display: grid;
  grid-template-columns: 236px minmax(320px, 400px) minmax(0, 1fr);
}
.lists { overflow-y: auto; padding: 8px 8px 16px; border-right: 1px solid var(--line); background: var(--page); }
.lists-title {
  padding: 12px 10px 4px; color: var(--ink-3);
  font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase;
}
.list-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 8px; background: none; cursor: pointer; text-align: left;
}
.list-item:hover { background: var(--surface-2); }
.list-item[aria-current="true"] { background: var(--accent-soft); font-weight: 600; }
.list-item .label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .count { min-width: 20px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
.list-item .count.hot { color: var(--ink); font-weight: 650; }
.list-item .count.zero { color: var(--muted); font-weight: 400; }
.count-overdue {
  display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 500;
  font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.count-overdue .icon { width: 12px; height: 12px; }

.contacts { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--surface); border-right: 1px solid var(--line); }
.contacts-head { flex: none; padding: 14px 14px 10px; border-bottom: 1px solid var(--line); }
.contacts-head h1 { display: flex; align-items: baseline; gap: 8px; font-size: 17px; font-weight: 650; }
.contacts-head h1 .n { color: var(--ink-3); font-size: 14px; font-weight: 400; font-variant-numeric: tabular-nums; }
.contacts-head .hint { margin: 2px 0 10px; color: var(--ink-2); font-size: 13px; }
.filters { display: flex; gap: 8px; }
.filters input { flex: 1 1 0; min-width: 0; }
.filters select { flex: 0 1 172px; min-width: 0; }
.contacts-list { flex: 1; min-height: 0; overflow-y: auto; }
.contacts-foot { flex: none; padding: 8px 14px; border-top: 1px solid var(--line); color: var(--ink-2); font-size: 12.5px; }
.empty { padding: 28px 18px; color: var(--ink-2); text-align: center; }

.row {
  display: block; width: 100%; text-align: left; cursor: pointer;
  padding: 10px 14px 10px 11px; background: none; border: 0;
  border-bottom: 1px solid var(--line); border-left: 3px solid transparent;
}
.row:hover { background: var(--surface-2); }
.row.overdue { border-left-color: var(--critical); }
.row.selected { background: var(--accent-soft); border-left-color: var(--accent); }
.row.selected.overdue { border-left-color: var(--critical); }
.row-top { display: flex; align-items: baseline; gap: 10px; }
.row-name { flex: 1; min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-time { flex: none; color: var(--ink-2); font-size: 12.5px; white-space: nowrap; }
.row-snippet {
  margin-top: 2px; color: var(--ink-2); font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.row-snippet .who { color: var(--ink-3); }
.row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.row-manager { margin-left: auto; color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
.row-manager.none { font-style: italic; }

/* ---------- диалог */
.detail { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--page); }
.detail-empty { margin: auto; max-width: 340px; padding: 24px; text-align: center; color: var(--ink-2); }
.detail-empty .big { font-size: 16px; font-weight: 600; color: var(--ink); margin-bottom: 6px; }
.detail-head {
  flex: none; display: flex; flex-direction: column; gap: 8px;
  padding: 12px 18px 12px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.detail-top { display: flex; align-items: center; gap: 10px; min-width: 0; }
.detail-title { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 10px; min-width: 0; }
.detail-title h2 { font-size: 18px; font-weight: 650; overflow-wrap: anywhere; }
.detail-title .uname, .detail-title .channel { color: var(--ink-2); font-size: 13px; }
.detail-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.detail-row .since { color: var(--ink-2); font-size: 13px; }
.back { display: none; }
.banner {
  flex: none; margin: 10px 18px 0; padding: 9px 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
  display: flex; gap: 10px; align-items: flex-start;
}
.banner .icon { width: 16px; height: 16px; margin-top: 2px; }
.banner strong { display: block; }
.banner p { color: var(--ink-2); font-size: 13px; }
.banner.stop { background: var(--critical-soft); border-color: var(--critical-line); }
.banner.attention { background: var(--warning-soft); border-color: var(--warning-line); }
.note-line {
  flex: none; margin: 10px 18px 0; padding: 8px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  display: flex; gap: 10px; align-items: baseline;
}
.note-line .note-text { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 4.4em; overflow-y: auto; }
.actions {
  flex: none; display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  padding: 10px 18px; margin-top: 10px;
  background: var(--surface); border-top: 1px solid var(--line); border-bottom: 1px solid var(--line);
}
.conversation { flex: 1; min-height: 120px; overflow-y: auto; padding: 8px 18px 16px; display: flex; flex-direction: column; }
.day { align-self: center; margin: 12px 0 6px; padding: 1px 10px; color: var(--ink-3); font-size: 12px; }
.msg {
  max-width: min(78%, 620px); margin: 2px 0; padding: 7px 11px 5px; border-radius: 13px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.in { align-self: flex-start; background: var(--bubble-in); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border: 1px solid transparent; border-bottom-right-radius: 4px; }
.msg .kind { display: block; color: var(--ink-2); font-size: 12.5px; font-weight: 600; }
.msg .meta { display: block; margin-top: 1px; color: var(--ink-3); font-size: 11.5px; text-align: right; }
.msg.deleted { color: var(--ink-3); font-style: italic; }
.extra { flex: none; max-height: 46%; overflow-y: auto; background: var(--surface); border-top: 1px solid var(--line); }
.extra summary { padding: 10px 18px; cursor: pointer; font-weight: 500; }
.extra-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; padding: 2px 18px 16px; }
.note-box { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
.history { list-style: none; margin: 6px 0 0; padding: 0; }
.history li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.history li:last-child { border-bottom: 0; }
.history-text { display: block; }
.history-meta { display: block; color: var(--ink-3); font-size: 12.5px; }

/* ---------- страницы «Сводка» и «Настройки» */
.page { flex: 1; min-width: 0; overflow-y: auto; padding: 22px 28px 48px; }
.page-inner { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.page-head h1 { font-size: 20px; font-weight: 650; }
.page-head p { margin-top: 2px; color: var(--ink-2); }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.tile { padding: 14px 16px 15px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.tile .label { display: flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; }
.tile .value { margin-top: 6px; font-size: 34px; font-weight: 600; line-height: 1.15; }
.tile .sub { margin-top: 4px; color: var(--ink-3); font-size: 12.5px; }
.card { padding: 16px 18px 18px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.card h2 { font-size: 15px; font-weight: 650; }
.card .card-sub { margin: 2px 0 12px; color: var(--ink-2); font-size: 13px; }
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th, table.grid td {
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap;
}
table.grid th { color: var(--ink-2); font-size: 12.5px; font-weight: 500; vertical-align: bottom; white-space: normal; }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid tbody tr:hover td, table.grid tbody tr:hover th { background: var(--surface-2); }
table.grid tbody th { color: var(--ink); font-size: 14px; font-weight: 500; white-space: nowrap; }
table.grid tfoot td, table.grid tfoot th { border-bottom: 0; border-top: 1px solid var(--line-strong); font-weight: 650; color: var(--ink); font-size: 14px; }
.cell-link {
  border: 0; background: none; cursor: pointer; padding: 2px 6px; margin: -2px -6px; border-radius: 6px;
  font-variant-numeric: tabular-nums; text-decoration: underline; text-decoration-color: var(--line-strong); text-underline-offset: 3px;
}
.cell-link:hover { background: var(--surface-3); text-decoration-color: var(--ink-2); }
.zero { color: var(--muted); }
.with-icon { display: inline-flex; align-items: center; gap: 5px; }
table.bars td.bar-cell { width: 62%; text-align: left; }
table.bars tbody th { font-weight: 400; }
table.bars tbody tr { cursor: pointer; }
.bar-line { display: flex; align-items: center; gap: 8px; }
.bar { flex: none; height: 8px; min-width: 2px; background: var(--bar); border-radius: 0 4px 4px 0; }
.bar.none { background: none; min-width: 0; }
.bar-value { font-variant-numeric: tabular-nums; color: var(--ink); }
.status-name { display: inline-flex; align-items: center; gap: 8px; }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px 16px; align-items: center; max-width: 640px; }
.form-grid .unit { display: inline-flex; align-items: center; gap: 8px; }
.form-grid input[type="number"] { width: 88px; }
.form-grid select { justify-self: start; min-width: 96px; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.day-toggle { display: inline-flex; align-items: center; gap: 5px; padding: 4px 9px; border: 1px solid var(--line-strong); border-radius: 8px; cursor: pointer; }
.manager-list { display: flex; flex-direction: column; gap: 8px; max-width: 640px; }
.manager-row { display: flex; align-items: center; gap: 8px; }
.manager-row input { flex: 1; min-width: 0; }
.manager-row.off input { color: var(--ink-3); }
.form-actions { display: flex; align-items: center; gap: 12px; margin-top: 14px; }

/* ---------- люди и доступ */
.people { display: flex; flex-direction: column; }
.person { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-top: 1px solid var(--line); }
.people .person:first-child { border-top: 0; padding-top: 0; }
.person-main, .person-access { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.person-main input[type="text"] { flex: 1 1 200px; min-width: 0; max-width: 320px; }
.person-main input[type="email"], .person-access input[type="email"] { flex: 1 1 220px; min-width: 0; max-width: 320px; }
.person-access { color: var(--ink-2); font-size: 13px; }
.person-email { font-weight: 500; color: var(--ink); overflow-wrap: anywhere; }
.person.off .person-main input, .person.off .person-email { color: var(--ink-3); }
.person.add { gap: 6px; }

/* ---------- вход */
.auth-page { flex: 1; min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card {
  width: min(420px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 26px 26px 24px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.auth-card h1 { font-size: 20px; font-weight: 650; }
.auth-card p { color: var(--ink-2); }
.auth-card .brand span { display: inline; }
.auth-dev { display: flex; flex-direction: column; gap: 8px; }
.auth-warning { padding: 10px 12px; border: 1px solid var(--warning-line); border-radius: 8px; background: var(--warning-soft); color: var(--ink); }

/* ---------- окна и подсказки */
.backdrop {
  position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  padding: 20px; background: rgba(11, 11, 11, .38);
}
.modal {
  width: min(440px, 100%); max-height: 100%; overflow-y: auto; padding: 18px 20px 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
}
.modal h2 { font-size: 16px; font-weight: 650; margin-bottom: 8px; }
.modal p { color: var(--ink-2); }
.modal .modal-field { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.modal .quick { display: flex; flex-wrap: wrap; gap: 6px; }
.modal .check { display: flex; align-items: center; gap: 8px; margin-top: 12px; cursor: pointer; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.toast {
  position: fixed; left: 50%; top: 62px; transform: translateX(-50%); z-index: 30;
  max-width: min(520px, calc(100% - 32px)); padding: 9px 16px; border-radius: 10px;
  background: var(--ink); color: var(--surface); box-shadow: var(--shadow); text-align: center;
}

/* ---------- узкие окна */
@media (max-width: 1179px) {
  .dialogs { grid-template-columns: 236px minmax(0, 1fr); }
  .dialogs .detail { display: none; }
  .dialogs.open .contacts { display: none; }
  .dialogs.open .detail { display: flex; }
  .back { display: inline-flex; }
  .brand span { display: none; }
  .extra-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1400px) {
  .extra-body { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1000px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .page { padding: 18px 16px 40px; }
  .topbar { gap: 10px; }
  .me span { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .row, .list-item, .btn, .tab { transition: background-color .12s ease; }
}
