/* Командный центр. Тёмная тема по умолчанию (макет), светлая - если в Telegram
   colorScheme=light (app.js ставит data-theme). Шрифты - системные, без внешних.
   Цвет домена приходит из app.js как --dom/--dom-tint (CSSOM, только палитра). */
:root, [data-theme="dark"] {
  --bg: #0f1115;
  --bar: #13161c;
  --card: #171a21;
  --line: #222731;
  --line2: #2a2f3a;
  --dash: #343a47;
  --text: #e8eaee;
  --text2: #c9ced8;
  --muted: #8d96a7;
  --faint: #6b7486;
  --accent: #3b6fe0;
  --accent-text: #ffffff;
  --link: #7aa7ff;
  --hover: #1b1f27;
  --sel: #1e2533;
  --chip: #1e222b;
  --pill-on: #e8eaee;
  --pill-on-text: #0f1115;
  --shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  --backdrop: rgba(5, 7, 10, 0.65);
  --ok: #2f9e6a;
  --danger: #ff5c5c;
  --p0: #ff5c5c; --p0-bg: #3a1c1f;
  --p1: #ff8a3d; --p1-bg: #3a2617;
  --p2: #f2c14e; --p2-bg: #352d17;
  --p3: #8d96a7; --p3-bg: #22262e;
  --st-triage: #f2c14e; --st-triage-bg: #352d17;
  --st-new: #c9ced8; --st-new-bg: #262b35;
  --st-progress: #9dbbff; --st-progress-bg: #1e2a44;
  --st-waiting: #d4b2ff; --st-waiting-bg: #2c2240;
  --st-done: #5fe0a5; --st-done-bg: #173326;
  --st-cancelled: #8d96a7; --st-cancelled-bg: #22262e;
  --tag: #9dbbff; --tag-bg: #1e2a44;
  --stat-open: #9dbbff; --stat-closed: #5fe0a5; --stat-urgent: #ff8a3d; --stat-waiting: #d4b2ff;
  --heat0: #222731; --heat1: #1d3b6e; --heat2: #2f5fb3; --heat3: #4c8dff; --heat4: #9dbbff;
  --dom: #8d96a7;
  --dom-tint: #8d96a726;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg: #f5f6f8;
  --bar: #ffffff;
  --card: #ffffff;
  --line: #e3e6eb;
  --line2: #d5d9e0;
  --dash: #c5cad3;
  --text: #14171c;
  --text2: #39404c;
  --muted: #646d7c;
  --faint: #9aa1ad;
  --accent: #2f62d6;
  --link: #2a62d6;
  --hover: #f0f2f5;
  --sel: #e8eefb;
  --chip: #eef0f3;
  --pill-on: #14171c;
  --pill-on-text: #ffffff;
  --shadow: 0 20px 60px rgba(20, 23, 28, 0.18);
  --backdrop: rgba(20, 23, 28, 0.35);
  --ok: #1d8a57;
  --danger: #d93636;
  --p0: #d93636; --p0-bg: #fde8e8;
  --p1: #d9661a; --p1-bg: #fdeedf;
  --p2: #b88a0a; --p2-bg: #fbf3d9;
  --p3: #6b7486; --p3-bg: #eef0f3;
  --st-triage: #9a7300; --st-triage-bg: #fbf3d9;
  --st-new: #39404c; --st-new-bg: #eceef2;
  --st-progress: #2a62d6; --st-progress-bg: #e3ecfd;
  --st-waiting: #7a4fcf; --st-waiting-bg: #efe7fd;
  --st-done: #1d8a57; --st-done-bg: #dff5ea;
  --st-cancelled: #6b7486; --st-cancelled-bg: #eef0f3;
  --tag: #2a62d6; --tag-bg: #e3ecfd;
  --stat-open: #2a62d6; --stat-closed: #1d8a57; --stat-urgent: #d9661a; --stat-waiting: #7a4fcf;
  --heat0: #e3e6eb; --heat1: #c6d8fb; --heat2: #8fb3f5; --heat3: #4c8dff; --heat4: #2a62d6;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; padding: 0; text-align: left; }
button:disabled { cursor: default; opacity: 0.45; }
:focus-visible { outline: 2px solid var(--link); outline-offset: 1px; }
a { color: var(--link); text-decoration: none; }
h1, h2 { margin: 0; }
.ico { flex: none; display: block; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hint { color: var(--muted); padding: 12px 2px; }
.hint-sm { color: var(--muted); font-size: 11px; }
.overdue { color: var(--danger); }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* --- каркас: телефон -------------------------------------------------------- */
.app { min-height: 100vh; }
.side { display: none; }
.main { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 12px 14px 10px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.titles { flex: 1; min-width: 0; }
.crumb { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.heading { font-size: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  width: 32px; height: 32px; flex: none; display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border: 1px solid var(--line2); border-radius: 8px; color: var(--text2);
}
.icon-btn.sm { width: 28px; height: 28px; border-radius: 7px; }
.icon-btn.accent, .btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn {
  height: 32px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line2);
  background: var(--card); color: var(--text); font-weight: 500; text-align: center;
}
.btn.accent { font-weight: 600; }
.wide-btn { width: 100%; }
#add-wide { display: none; }
.search-box {
  display: none; order: 10; flex: 1 0 100%;
  align-items: center; gap: 6px; height: 32px; padding: 0 10px;
  border: 1px solid var(--line2); border-radius: 8px; background: var(--card); color: var(--muted);
}
.top.search-open .search-box { display: flex; }
.search-box input { flex: 1; min-width: 0; background: transparent; border: 0; outline: none; color: var(--text); font-size: 12px; }
.search-ico { display: inline-flex; }
.link-btn { color: var(--link); font-size: 12px; }
.notice { margin: 12px 14px; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.no-auth .tabs, .no-auth .top { display: none; }

.screen {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 14px calc(76px + env(safe-area-inset-bottom, 0px));
}
.with-actions .screen { padding-bottom: calc(132px + env(safe-area-inset-bottom, 0px)); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--bar); border-top: 1px solid var(--line);
  padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px));
}
.tab { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 0;
  font-size: 11px; color: var(--muted); text-align: center; }
.tab.on { color: var(--link); }
.actions {
  position: fixed; left: 0; right: 0; z-index: 5;
  bottom: calc(57px + env(safe-area-inset-bottom, 0px));
  display: flex; gap: 6px; padding: 10px 14px; background: var(--bg); border-top: 1px solid var(--line);
}

/* --- общие блоки ------------------------------------------------------------ */
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.panel.pad { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; overflow: visible; }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel-title { font-weight: 600; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-top: 4px; }
.sec-title { font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.04em; }
.chip {
  flex: none; align-self: flex-start; display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 7px; border-radius: 6px; font-size: 11px; font-weight: 600; white-space: nowrap;
}
.st-triage { color: var(--st-triage); background: var(--st-triage-bg); }
.st-new { color: var(--st-new); background: var(--st-new-bg); }
.st-in_progress { color: var(--st-progress); background: var(--st-progress-bg); }
.st-waiting { color: var(--st-waiting); background: var(--st-waiting-bg); }
.st-done { color: var(--st-done); background: var(--st-done-bg); }
.st-cancelled { color: var(--st-cancelled); background: var(--st-cancelled-bg); }
.p-P0 { color: var(--p0); } .p-P1 { color: var(--p1); } .p-P2 { color: var(--p2); } .p-P3 { color: var(--p3); }
.p-chip { font-size: 12px; padding: 3px 8px 3px 6px; }
.p-chip.p-P0 { background: var(--p0-bg); } .p-chip.p-P1 { background: var(--p1-bg); }
.p-chip.p-P2 { background: var(--p2-bg); } .p-chip.p-P3 { background: var(--p3-bg); }
.dom-chip { font-size: 12px; font-weight: 500; padding: 3px 8px; background: var(--dom-tint); color: var(--text); }
.dom-chip .ico { color: var(--dom); }
.dom-badge {
  width: 28px; height: 28px; flex: none; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--dom-tint); color: var(--dom);
}
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
/* телефон: фильтры в одну строку с прокруткой, чтобы список не прыгал */
.list-screen > .pills { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
.list-screen > .pills::-webkit-scrollbar { display: none; }
.pill {
  height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12px; white-space: nowrap;
  border: 1px solid var(--line2); background: var(--card); color: var(--text2);
}
.pill.on { background: var(--pill-on); border-color: var(--pill-on); color: var(--pill-on-text); }
.pills.sm .pill { height: 24px; padding: 0 9px; font-size: 11px; background: transparent; }
.pills.sm .pill.on { background: var(--pill-on); }
.empty { border: 1px dashed var(--dash); border-radius: 10px; padding: 20px; text-align: center;
  color: var(--muted); font-size: 12px; }
.dot { width: 8px; height: 8px; flex: none; border-radius: 2px; display: inline-block; }
.v-anthropic, .m-opus { background: #d98b5f; }
.m-sonnet { background: #e0b07a; }
.v-openai, .m-gpt { background: #5fe0a5; }
.v-other, .m-other { background: #8d96a7; }

/* --- главная ------------------------------------------------------------------ */
.home { display: flex; flex-direction: column; gap: 12px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile {
  height: 58px; background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.tile-num { font-size: 18px; font-weight: 700; line-height: 1; min-width: 3ch; text-align: center; }
.t-open .ico { color: var(--stat-open); }
.t-closed_7d .ico, .tile.t-closed_7d .tile-num { color: var(--stat-closed); }
.t-urgent .ico, .tile.t-urgent .tile-num { color: var(--stat-urgent); }
.t-waiting .ico { color: var(--stat-waiting); }
.legend { display: flex; gap: 4px 10px; flex-wrap: wrap; font-size: 11px; color: var(--muted); margin-top: -4px; }
.legend-item { display: inline-flex; align-items: center; gap: 3px; }
.home-cols, .home-col { display: flex; flex-direction: column; gap: 12px; }
.dom-row {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  border-bottom: 1px solid var(--line); min-height: 44px;
}
.dom-row:last-child { border-bottom: 0; }
.dom-row.disabled { color: var(--faint); }
.dom-name { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dom-title { font-weight: 500; }
.dom-sub { font-size: 11px; color: var(--muted); }
.dom-open { font-weight: 600; min-width: 2ch; text-align: right; }
.dom-total { font-size: 11px; color: var(--muted); min-width: 3.5ch; }
.top-panel { padding: 4px 0; }
.top-dom { font-size: 11px; color: var(--muted); padding: 6px 12px 2px; text-transform: uppercase; letter-spacing: 0.03em; }
.strip { box-shadow: inset 3px 0 0 var(--dom); }
.mini-row { width: 100%; display: flex; align-items: center; gap: 8px; padding: 7px 12px 7px 14px; }
.mini-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mini-date { font-size: 11px; color: var(--muted); }
.top-empty { font-size: 11px; color: var(--muted); padding: 8px 12px 6px; border-top: 1px solid var(--line); margin-top: 4px; }
.top-panel > .top-empty:first-child { border-top: 0; margin-top: 0; }
.vendor-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.vendor-tile { background: var(--card); border: 1px dashed var(--dash); border-radius: 10px; padding: 8px 10px; min-width: 0; }
.vendor-name { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--text2); }
.vendor-name .dot { width: 7px; height: 7px; }
.vendor-sum { font-size: 16px; font-weight: 700; color: var(--faint); margin-top: 2px; }

/* --- список задач --------------------------------------------------------------- */
.list-screen { display: flex; flex-direction: column; gap: 10px; }
.list-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }
.rows { display: flex; flex-direction: column; gap: 4px; }
/* карточка списка: прямоугольная, без скруглений, полоса домена 3px слева */
.trow {
  width: 100%; display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 10px 9px 13px; background: var(--card); border: 1px solid var(--line); border-radius: 0;
  touch-action: pan-y; transition: transform 0.15s ease;
}
.trow.swiping { transition: none; }
.trow > .ico { margin-top: 1px; }
.tbody-cell { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
.ttitle { font-weight: 500; overflow-wrap: anywhere; }
.closed .ttitle, .closed .cell-title { color: var(--muted); }
.tmeta { display: flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); flex-wrap: wrap; min-width: 0; }
.tsrc { display: inline-flex; align-items: center; gap: 4px; }
.tdom { color: var(--text2); }
.cfg { padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.cfg-head { display: flex; align-items: center; gap: 8px; }
.cfg-title { flex: 1; font-weight: 600; }
.swatches, .icon-choices { display: flex; gap: 6px; flex-wrap: wrap; }
.swatch {
  width: 28px; height: 28px; border-radius: 7px; background: var(--sw, #8d96a7);
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--bg);
}
.swatch.on { border-color: var(--text); }
.icon-choice {
  width: 32px; height: 32px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center;
  background: var(--chip); border: 1px solid var(--line2); color: var(--muted);
}
.icon-choice.on { background: var(--dom-tint); border-color: var(--dom); color: var(--dom); }

/* --- карточка задачи ------------------------------------------------------------ */
.card { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chips .chip { align-self: center; }
.card-title { font-size: 17px; font-weight: 600; line-height: 1.3; overflow-wrap: anywhere; }
.fields-panel { padding: 4px 12px; }
/* две колонки: метка фиксированной ширины + значение; minmax(0, 1fr) - ничего не наезжает */
.fields { display: grid; grid-template-columns: 104px minmax(0, 1fr); font-size: 12px; }
.fields > .f-label, .fields > .f-value { padding: 8px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.fields > :nth-last-child(-n + 2) { border-bottom: 0; }
.f-label { color: var(--muted); }
.f-value { overflow-wrap: anywhere; }
.src-cell { display: flex; flex-direction: column; gap: 2px; align-items: flex-start; }
.due-cell { display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: baseline; }
.ext-link { display: inline-flex; align-items: center; gap: 4px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; }
.tag { padding: 2px 7px; border-radius: 999px; font-size: 11px; background: var(--tag-bg); color: var(--tag); }
.history { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.history li { display: flex; gap: 8px; align-items: flex-start; }
.h-dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--faint); margin-top: 6px; }
.h-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.h-when { color: var(--muted); font-size: 11px; white-space: nowrap; }
.action-row, .actions { display: flex; gap: 6px; }
.act {
  flex: 1; height: 36px; border-radius: 8px; border: 1px solid var(--line2); background: var(--card);
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; font-weight: 500;
}
.act-done { background: var(--ok); border-color: var(--ok); color: #ffffff; font-weight: 600; }
.act.on { opacity: 1; box-shadow: inset 0 0 0 1px var(--text2); }
.act-more-wrap { position: relative; flex: none; }
.act-more { flex: none; width: 36px; }
.act-menu {
  position: absolute; right: 0; bottom: calc(100% + 6px); z-index: 6; min-width: 170px;
  background: var(--card); border: 1px solid var(--line2); border-radius: 8px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; padding: 4px;
}
.menu-item { height: 32px; padding: 0 10px; border-radius: 6px; }
.menu-item:hover { background: var(--hover); }

/* подкатегории (0005): вкладки, метки, строки дашборда. Цвет - --dom подкатегории или домена;
   isolated (своя граница) - замок и подпись "отдельная граница" */
.sub-tabs .sub-pill { display: inline-flex; align-items: center; gap: 5px; }
.sub-pill.on { background: var(--dom-tint); border-color: var(--dom); color: var(--text); }
.pill-count { font-size: 11px; color: var(--muted); }
.pill.on .pill-count { color: inherit; opacity: 0.75; }
.sub-dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--dom); display: inline-block; }
.sub-name, .tsub, .dom-title.isolated { display: inline-flex; align-items: center; gap: 4px; min-width: 0; }
.tsub { color: var(--text2); white-space: nowrap; }
.tsub .ico, .sub-name .ico, .dom-title .ico { color: var(--dom); }
.iso-note { font-size: 11px; color: var(--muted); margin-left: 4px; }
.mini-row .tsub { font-size: 11px; max-width: 40%; overflow: hidden; }
.sub-row { padding-left: 26px; min-height: 38px; }
.sub-row .dom-title { font-size: 12px; }
.sub-chip { background: transparent; border: 1px solid var(--dom); }
.sub-manage { display: flex; flex-direction: column; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; }
.cfg-sub-title { font-size: 12px; font-weight: 600; color: var(--text2); }
.sub-line { display: flex; align-items: center; gap: 8px; min-width: 0; flex-wrap: wrap; }
.sub-form input {
  flex: 1; min-width: 0; height: 30px; padding: 4px 8px; border: 1px solid var(--line2); border-radius: 7px;
  background: var(--bg); color: var(--text); font-size: 12px;
}
.iso-hint { display: flex; align-items: flex-start; gap: 6px; font-size: 11px; color: var(--muted);
  padding: 6px 10px; border: 1px dashed var(--dom); border-radius: 8px; }
.iso-hint .ico { color: var(--dom); margin-top: 2px; }
.sm-btn { height: 30px; padding: 0 10px; font-size: 12px; }

/* формы: метка над полем, поля не шире колонки */
.form { padding: 12px; display: flex; flex-direction: column; gap: 10px; overflow: visible; }
.form-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-field .f-label { font-size: 12px; }
.form-pair, .due-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.due-row { grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); }
.form input, .form select, .form textarea {
  display: block; width: 100%; min-width: 0; max-width: 100%;
  height: 34px; padding: 6px 10px; border: 1px solid var(--line2); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 13px;
}
.form textarea { height: auto; resize: vertical; line-height: 1.35; }
.form input[type="date"], .form input[type="time"] { -webkit-appearance: none; appearance: none; }
.form input::-webkit-date-and-time-value { text-align: left; }
.check { display: flex; align-items: center; gap: 8px; }
.form .check input { width: auto; height: auto; }
.form-buttons { display: flex; gap: 8px; }
.form-buttons .btn { flex: 1; }

/* --- расходы на AI ------------------------------------------------------------ */
.ai, .ai-cols { display: flex; flex-direction: column; gap: 12px; }
.sum-empty { font-size: 16px; font-weight: 700; color: var(--faint); }
.vendor-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.vendor-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.bar-empty { width: 90px; height: 6px; border-radius: 3px; background: var(--line); }
.vendor-sum-sm { width: 50px; text-align: right; color: var(--muted); }
.heat {
  display: grid; grid-template-rows: repeat(7, 11px); grid-auto-flow: column; grid-auto-columns: 11px;
  gap: 3px; overflow: hidden;
}
.cell { width: 11px; height: 11px; border-radius: 2px; background: var(--heat0); display: inline-block; }
.heat-legend .cell { width: 9px; height: 9px; }
.cell.l1 { background: var(--heat1); } .cell.l2 { background: var(--heat2); }
.cell.l3 { background: var(--heat3); } .cell.l4 { background: var(--heat4); }
.heat-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap;
  font-size: 11px; color: var(--muted); }
.heat-legend { display: inline-flex; align-items: center; gap: 3px; }
.model-grid { display: grid; grid-template-columns: minmax(0, 1fr) 62px 62px; padding: 8px 12px;
  border-bottom: 1px solid var(--line); font-size: 12px; }
.model-grid:last-child { border-bottom: 0; }
.model-grid > :not(:first-child) { text-align: right; }
.model-head { font-size: 11px; color: var(--muted); }
.model-name { display: flex; align-items: center; gap: 6px; }
.model-name .dot { width: 7px; height: 7px; }

/* --- модалка ---------------------------------------------------------------- */
.modal { position: fixed; inset: 0; z-index: 10; display: flex; align-items: flex-start; justify-content: center;
  padding: 72px 16px 16px; }
.modal-back { position: absolute; inset: 0; background: var(--backdrop); }
.dialog {
  position: relative; width: min(560px, 100%); max-height: calc(100vh - 96px); overflow-y: auto;
  background: var(--card); border: 1px solid var(--line2); border-radius: 12px; padding: 18px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; outline: none;
}
.dialog .card-title { font-size: 16px; }
.dialog .fields-panel { border: 0; padding: 0; background: transparent; border-radius: 0; }
.dialog .fields { grid-template-columns: 100px minmax(0, 1fr); }
.dialog .action-row .act { height: 32px; }
.dialog .act-menu { bottom: calc(100% + 6px); }
.dialog .form { padding: 0; border: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-title { font-size: 16px; font-weight: 600; }
.in-dialog { position: sticky; bottom: -18px; background: var(--card); padding: 10px 0 0; margin-top: -4px; }
.modal-open { overflow: hidden; }

.toast {
  position: fixed; left: 14px; right: 14px; z-index: 20;
  bottom: calc(68px + env(safe-area-inset-bottom, 0px));
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--text); color: var(--bg); border-radius: 10px; padding: 9px 12px; font-size: 13px;
}
.with-actions .toast { bottom: calc(124px + env(safe-area-inset-bottom, 0px)); }
.toast button { color: var(--bg); font-weight: 600; padding: 4px 8px; }

@media (hover: hover) {
  .dom-row:hover, .mini-row:hover, .trow:hover, .trow-grid:hover:not(.thead), .side-item:hover { background: var(--hover); }
}

/* --- широкое окно: боковое меню, таблица, модалка --------------------------- */
@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 232px minmax(0, 1fr); }
  .side {
    display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0; height: 100vh; overflow-y: auto;
    padding: 16px 12px; background: var(--bar); border-right: 1px solid var(--line);
  }
  .brand { display: flex; align-items: center; gap: 8px; padding: 4px 8px 14px; font-weight: 600; }
  .brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); color: #ffffff;
    display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; }
  .side-group { display: flex; flex-direction: column; gap: 2px; }
  .side-head { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; padding: 14px 8px 4px; }
  .side-item { width: 100%; display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 8px;
    border-radius: 7px; color: var(--text2); }
  .side-item.on { background: var(--sel); color: var(--text); }
  .side-item .dom-ico { color: var(--dom); }
  .side-count { font-size: 11px; color: var(--muted); }
  .side-sub { height: 28px; padding-left: 22px; font-size: 12px; }
  .side-sub .sub-name, .side-sub .grow { display: inline-flex; align-items: center; gap: 4px; }
  .side-soon { display: flex; flex-direction: column; font-size: 12px; color: var(--faint); padding: 0 8px; }
  .side-soon span { padding: 5px 0; }

  .tabs, .actions, #search-toggle, #add, #back { display: none !important; }
  .top { position: static; padding: 18px 22px 0; border-bottom: 0; gap: 12px; flex-wrap: nowrap; }
  .heading { font-size: 18px; }
  .search-box { display: flex; order: 0; flex: none; width: 260px; }
  #add-wide { display: inline-block; }
  .screen, .with-actions .screen { padding: 16px 22px 32px; gap: 16px; }
  .toast, .with-actions .toast { left: auto; right: 22px; bottom: 22px; width: 360px; }

  .tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
  .tile { height: 72px; flex-direction: row; gap: 10px; }
  .tile-num { font-size: 24px; }
  .home-cols { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; align-items: start; }

  .table-panel { overflow: hidden; }
  .table-bar { display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .table-title { font-weight: 600; margin-right: 8px; }
  .table-bar .pill { height: 24px; padding: 0 9px; }
  .table-scroll { overflow-x: auto; }
  .table { min-width: 680px; }
  .trow-grid {
    width: 100%; display: grid; grid-template-columns: 28px minmax(0, 1fr) 150px 120px 56px 84px;
    gap: 10px; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); border-radius: 0;
  }
  .trow-grid.sel { background: var(--sel); }
  .thead { font-size: 11px; color: var(--muted); padding: 7px 12px; }
  .tbody > .trow-grid:last-child { border-bottom: 0; }
  .tbody > .empty { margin: 12px; }
  .cell-title { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
  .tdom-inline { margin-left: 8px; font-size: 11px; color: var(--muted); font-weight: 400; }
  .cell-src { font-size: 12px; color: var(--tag); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cell-who { font-size: 12px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .cell-date { font-size: 12px; color: var(--muted); }
  .trow-grid .chip { justify-self: start; align-self: center; }
  .list-screen .cfg { max-width: 560px; }
  .ai-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
  .ai-cols > :nth-child(2) { grid-row: span 2; }
}
