/* Интерфейс SBL Терминала. Всё внутри одного экрана: шапка, терминал,
   поле следующей задачи. Верстка рассчитана и на MacBook, и на iPhone —
   отсюда safe-area, крупные цели нажатия и панель клавиш. */

* { box-sizing: border-box; }

/* Атрибут hidden обязан прятать, что бы ни задавали классы. Правило браузера
   [hidden]{display:none} слабее любого нашего display: из-за этого кнопка
   «Проверить» показывалась на устройстве, которое не подписано, и проверка
   уходила на чужой телефон. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overscroll-behavior: none;
  /* Ни одна страница не должна ездить вбок — на телефоне это главное. */
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }

.ico { flex: none; vertical-align: -.2em; }

/* ---------- каркас страницы терминала ---------- */
.shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  min-height: 46px;
  max-width: 100%;
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -.01em;
  color: var(--ink);
  padding-right: 4px;
  flex: none;
}
.brand .ico { color: var(--accent); }

.tabstrip {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  flex: 1;
  min-width: 0;
}
.tabstrip::-webkit-scrollbar { display: none; }

.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
  text-decoration: none;
  max-width: 190px;
}
.tab:hover { background: var(--surface-2); }
.tab.on {
  background: var(--bg);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 500;
}
.tab .name { overflow: hidden; text-overflow: ellipsis; }
.tab .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex: none;
}
.tab .dot.dead { background: transparent; border: 1.5px solid var(--ink-faint); }
.tab .dot.running { background: var(--accent); }
/* Точки «ждёт ответа» и «готово» — ярче текстовых цветов и с лёгким свечением,
   чтобы состояние вкладки было видно с первого взгляда. */
.tab .dot.waiting { background: var(--dot-warn, var(--warn)); box-shadow: 0 0 6px var(--dot-warn, var(--warn)); }
.tab .dot.done { background: var(--dot-good, var(--good)); box-shadow: 0 0 6px var(--dot-good, var(--good)); }
.tab .ico { color: var(--ink-faint); margin-left: 2px; }

@media (prefers-reduced-motion: no-preference) {
  .tab .dot.running { animation: pulse 1.7s ease-in-out infinite; }
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 45%, transparent); }
  50%      { box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* Чип состояния меняет цвет вместе со смыслом. */
.chip.is-running { border-color: var(--accent); color: var(--accent); }
.chip.is-waiting { border-color: var(--warn); color: var(--warn); }
.chip.is-done { border-color: var(--good); color: var(--good); }

/* Строка-кнопка в шторках. */
.row.act {
  background: none;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  width: 100%;
  font: inherit;
  color: inherit;
  padding: 12px 2px;
}
.row.act:hover { background: var(--surface-2); }

.spacer { flex: 1; }

.chip {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 12px;
  white-space: nowrap;
}
.chip.hidden { display: none; }

.iconbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 7px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink-soft);
  text-decoration: none;
  flex: none;
}
.iconbtn:hover { background: var(--surface-2); color: var(--ink); }
.topaction {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 12px;
  white-space: nowrap;
  flex: none;
}
.topaction:hover { background: var(--surface-2); color: var(--ink); }
.topaction .ico { color: var(--accent); }
.iconbtn:focus-visible, .tab:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- терминал ---------- */
.termwrap {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  background: var(--term-bg);
  padding: 6px 4px 0 8px;
  position: relative;
}
#term { width: 100%; height: 100%; }
/* Режим листания одним пальцем: палец принадлежит терминалу, а не браузеру —
   иначе страница «потягивается» и обновляется вместо прокрутки. */
#term.scrolling { touch-action: none; }

.status-line {
  position: absolute;
  left: 50%;
  top: 10px;
  transform: translateX(-50%);
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 12px;
  box-shadow: var(--shadow);
  opacity: 0;
  transition: opacity .2s ease;
  pointer-events: none;
  z-index: 5;
}
.status-line.show { opacity: 1; }

/* ---------- нижняя панель ---------- */
/* Строку ввода отсюда убрали (решение владельца 08.09): место занимал
   терминал, а команда нужна редко — она открывается кнопкой в шапке.
   Панель осталась ради клавиш телефона, на большом экране её нет. */
.bottom {
  max-width: 100%;
  overflow: hidden;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  display: none;
  flex-direction: column;
  gap: 6px;
}

.keys {
  display: none;
  gap: 5px;
  overflow-x: auto;
  scrollbar-width: none;
}
.keys::-webkit-scrollbar { display: none; }
.keys button {
  flex: none;
  min-width: 42px;
  padding: 8px 10px;
  border-radius: 7px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 13px;
}
.keys button.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
/* «⇕ Листать» шире остальных: это подпись, а не одна клавиша. */
#scrollkey { min-width: 92px; }

/* Поле запасной вставки: 16px — меньше iPhone приближает страницу при фокусе. */
.pastein {
  display: block;
  width: 100%;
  margin: 0 0 10px;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
  resize: vertical;
}

.compose { display: flex; gap: 6px; align-items: center; max-width: 100%; }
.sheet .compose { margin-bottom: 10px; }
.sheet .hint { margin: 0 0 16px; font-size: 12px; color: var(--ink-faint); }
.sheet h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.compose input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}
.compose input::placeholder { color: var(--ink-faint); }
.compose button {
  padding: 9px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  white-space: nowrap;
}
.compose button.ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }

/* ---------- всплывающие панели ---------- */
.sheet {
  position: fixed;
  inset: auto 0 0 0;
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow);
  padding: 14px 16px calc(18px + env(safe-area-inset-bottom));
  z-index: 20;
  transform: translateY(101%);
  transition: transform .18s ease;
}
.sheet.open { transform: translateY(0); }
.sheet h2 { margin: 0 0 12px; font-size: 15px; font-weight: 600; }

.themes { display: flex; gap: 10px; flex-wrap: wrap; }
.theme-card {
  flex: 1 1 140px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  text-align: left;
}
.theme-card.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.theme-card .preview {
  height: 54px;
  padding: 7px 9px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11px;
  line-height: 1.45;
}
.theme-card .cap { padding: 7px 10px; font-size: 13px; border-top: 1px solid var(--line-soft); }
.pv-light  { background: #ffffff; color: #1c2536; }
.pv-light b  { color: #2f6fb0; font-weight: 500; }
.pv-dark   { background: #0c1017; color: #dfe6f0; }
.pv-dark b   { color: #6ba6e2; font-weight: 500; }
.pv-cream  { background: #f7efdc; color: #4a4036; }
.pv-cream b { color: #8a5a14; font-weight: 500; }
.pv-auto   { background: linear-gradient(105deg, #ffffff 0 50%, #0c1017 50% 100%); color: #1c2536; }
.pv-auto b { color: #2f6fb0; font-weight: 500; }

.fontsize { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 14px; color: var(--ink-soft); }
.fontsize button {
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink);
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .28);
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease;
}
.backdrop.open { opacity: 1; pointer-events: auto; }

/* ---------- страницы входа и настроек ---------- */
.page {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 18px calc(40px + env(safe-area-inset-bottom));
}
.page h1 { font-size: 21px; font-weight: 600; margin: 0 0 6px; letter-spacing: -.01em; }
.page .lede { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 14px;
}
.card h2 {
  font-size: 14px;
  font-weight: 600;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .ico { color: var(--accent); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field label { font-size: 13px; color: var(--ink-soft); }
.field input {
  padding: 11px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
}

/* ---------- ползунок громкости сигнала ---------- */
.volume { display: flex; flex-direction: column; gap: 6px; margin-top: 16px; max-width: 360px; }
.volume label { font-size: 13px; color: var(--ink-soft); display: flex; gap: 8px; align-items: baseline; }
.volume label .now { font-size: 12px; color: var(--good); }
.volume input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent; cursor: pointer;
}
.volume input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; border-radius: 2px; background: var(--line);
}
.volume input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: var(--line); }
/* Кружок крупный: по нему попадают пальцем на телефоне. */
.volume input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 20px; height: 20px; margin-top: -8px;
  border-radius: 50%; background: var(--accent); border: none;
}
.volume input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%; background: var(--accent); border: none;
}
.volume input[type="range"]:disabled { opacity: 0.45; cursor: default; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 14px;
  text-decoration: none;
}
.btn.ghost { background: transparent; border-color: var(--line); color: var(--ink-soft); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.compact { padding: 7px 11px; font-size: 12px; white-space: nowrap; }

.msg { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
.msg.error { background: var(--surface-2); border: 1px solid var(--danger); color: var(--danger); }
.msg.warn { background: var(--surface-2); border: 1px solid var(--warn); color: var(--warn); }
.msg.info { background: var(--surface-2); border: 1px solid var(--line); color: var(--ink-soft); }

.rows { display: flex; flex-direction: column; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.row:last-child { border-bottom: none; }
.row .grow { flex: 1; min-width: 0; }
.row .sub { font-size: 12px; color: var(--ink-faint); }
.row .now { font-size: 12px; color: var(--good); }

.histtext {
  margin: 0;
  max-height: 58vh;
  overflow: auto;
  font-size: 12px;
  line-height: 1.45;
  /* Длинные строки переносим, а не режем: скопировать команду целиком важнее
     ровного правого края. */
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  -webkit-user-select: text;
  user-select: text;
}

.log { font-size: 12px; color: var(--ink-soft); max-height: 260px; overflow-y: auto; }
.log div { padding: 3px 0; border-bottom: 1px solid var(--line-soft); }

/* ---------- телефон ---------- */
@media (max-width: 720px) {
  .brand span { display: none; }
  .bottom { display: flex; }
  .keys { display: flex; }
  .tab { max-width: 140px; }
  .termwrap { padding: 4px 2px 0 5px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}


/* ---------- проводник по файлам ---------- */
.crumbs {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  font-size: 13px;
  min-width: 0;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumbs button {
  border: none;
  background: none;
  color: var(--ink-soft);
  padding: 4px 6px;
  border-radius: 5px;
  white-space: nowrap;
  font-family: var(--font-mono, "JetBrains Mono"), monospace;
}
.crumbs button:hover { background: var(--surface-2); color: var(--ink); }
.crumbs button:last-child { color: var(--ink); font-weight: 500; }
.crumbs .sep { color: var(--ink-faint); }

.places {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.places::-webkit-scrollbar { display: none; }
.exchange-help {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 14px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 13px;
}
.exchange-help strong { color: var(--ink); white-space: nowrap; }
.place {
  flex: none;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
}
.place:hover { color: var(--ink); }
.place.accent { border-color: var(--accent); color: var(--accent); }
.place.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* Фильтр списка: поиск, порядок, вид файла и давность. */
.filterbar {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 10px 0;
  background: var(--surface);
}
.search {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 4px 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink-faint);
  cursor: text;
}
.search:focus-within { border-color: var(--accent); }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  padding: 0;
  border: none;
  outline: none;
  background: none;
  color: var(--ink);
  /* 16 px — иначе Safari на iPhone приближает страницу при касании поля. */
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}
.search input::placeholder { color: var(--ink-faint); }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }
.search .clear {
  flex: none;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: none;
  color: var(--ink-faint);
  font-size: 20px;
  line-height: 1;
}
.search .clear:hover { background: var(--surface-2); color: var(--ink); }
.sortsel {
  flex: none;
  height: 36px;
  max-width: 44%;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 14px;
}
.chips {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none;
  padding: 4px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  font-size: 13px;
  white-space: nowrap;
  transition: transform 100ms ease-out;
}
.chip:hover { color: var(--ink); }
.chip:active { transform: scale(0.97); }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chipsep { flex: none; width: 1px; height: 18px; margin: 0 2px; background: var(--line); }
.filegroup {
  padding: 14px 8px 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-faint);
}
.filelist .empty .btn { margin-top: 12px; }
.fileitem .where {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--ink-soft);
}

.filelist { flex: 1; min-height: 0; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 10px 12px; }
.filelist .empty { padding: 28px 8px; text-align: center; color: var(--ink-faint); font-size: 14px; }

.fileitem {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 11px 8px;
  border: none;
  border-bottom: 1px solid var(--line-soft);
  background: none;
  color: var(--ink);
  text-align: left;
  font: inherit;
}
.fileitem:hover { background: var(--surface-2); }
.fileitem.folder { cursor: pointer; }
.fileitem .ico { color: var(--ink-faint); }
.fileitem.folder .ico { color: var(--accent); }
.fileitem .grow { flex: 1; min-width: 0; }
.fileitem .name { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fileitem .meta { font-size: 12px; color: var(--ink-faint); }
.fileitem.denied { color: var(--ink-faint); cursor: not-allowed; }
.fileitem.denied .lock { font-size: 11px; color: var(--warn); white-space: nowrap; }
.fileactions { display: flex; align-items: center; gap: 6px; flex: none; }

.uploadinfo { font-size: 12px; color: var(--ink-soft); padding: 0 2px; }
.uploadinfo.err { color: var(--danger); }

.dropzone {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border: 3px dashed var(--accent);
  color: var(--accent);
  font-size: 16px;
  z-index: 30;
}
.dropzone.on { display: flex; }

.filepreview {
  position: fixed;
  inset: 0;
  z-index: 35;
  background: var(--bg);
  padding: env(safe-area-inset-top) env(safe-area-inset-right)
           env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.filepreview > header {
  min-height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.filepreview > header strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.previewbody { height: calc(100% - 48px); overflow: auto; padding: 14px; }
.previewtext { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
.previewimage { display: block; max-width: 100%; max-height: 100%; margin: 0 auto; object-fit: contain; }
.previewpdf { width: 100%; height: 100%; border: 0; background: white; }

/* ---------- отложенные задачи ---------- */
.chip.queuechip {
  border-color: var(--accent);
  color: var(--accent);
  cursor: pointer;
  margin-left: 0;
}
.chip.queuechip:hover { background: var(--accent-soft); }

.queueitem {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line-soft);
  font-size: 14px;
}
.queueitem:last-child { border-bottom: none; }
.queueitem .grow { flex: 1; min-width: 0; }
.queueitem .text { display: block; word-break: break-word; }
.queueitem .note { font-size: 12px; color: var(--warn); }
.queueitem .num {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--ink-faint);
  padding-top: 2px;
}
.queueitem button {
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink-soft);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 12px;
  flex: none;
}
.queueitem button:hover { color: var(--danger); border-color: var(--danger); }

/* ---------- экран выбора ---------- */
.startpage {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(40px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.starthead { display: flex; align-items: center; gap: 8px; }
.brand.big { font-size: 17px; flex: 1; min-width: 0; }
.brand.big span { display: inline; }
.startpage .lede { color: var(--ink-soft); font-size: 15px; margin: 0; }
.startpage .lede.small { font-size: 12px; color: var(--ink-faint); margin-top: 10px; }
.startpage .label { margin-bottom: 8px; }

.modes { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px; }
.modebtn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  font: inherit;
  min-height: 68px;
}
.modebtn:hover { border-color: var(--accent); }
.modebtn.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.modebtn .ico { color: var(--accent); width: 22px; height: 22px; }
.modebtn b { display: block; font-weight: 600; font-size: 15px; }
.modebtn .sub { display: block; font-size: 12px; color: var(--ink-faint); margin-top: 2px; }
.modebtn.wide { width: 100%; }

.wherebox { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.wherelist { display: flex; flex-wrap: wrap; gap: 8px; }

.opened .rows { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 0 14px; }
.row.tabrow { text-decoration: none; color: inherit; }
.row.tabrow:hover { background: var(--surface-2); }
.row .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.row .dot.running { background: var(--accent); }
.row .dot.waiting { background: var(--dot-warn, var(--warn)); box-shadow: 0 0 6px var(--dot-warn, var(--warn)); }
.row .dot.done { background: var(--dot-good, var(--good)); box-shadow: 0 0 6px var(--dot-good, var(--good)); }
.row .dot.dead { background: transparent; border: 1.5px solid var(--ink-faint); }

.tworow { display: flex; gap: 10px; }
.tworow .field { flex: 1; }
.tworow .field.narrow { flex: 0 0 90px; }

/* ---------- телефон: ничего лишнего в шапке ---------- */
@media (max-width: 600px) {
  .topbar .brand { display: none; }
  #summary { display: none; }
  .tab { max-width: 116px; padding: 6px 9px; }
  .iconbtn { width: 32px; height: 32px; }
  .topaction { height: 32px; padding: 0 8px; }
  .topaction span:last-child { display: none; }
  .exchange-help { align-items: flex-start; flex-direction: column; gap: 2px; }
  .fileactions { gap: 4px; }
  .fileactions .btn { padding: 7px 9px; }
  .modes { grid-template-columns: 1fr; }
  .startpage { padding-left: 12px; padding-right: 12px; }
  /* Поле задачи занимает всю строку, кнопки — вторую: на 390 px иначе не влезает. */
  .compose { flex-wrap: wrap; }
  .compose input { flex: 1 1 100%; }
  .compose button { flex: 1 1 0; }
  .page { padding-left: 12px; padding-right: 12px; }
  .card { padding: 14px; }
  .tworow { flex-wrap: wrap; }
  .tworow .field.narrow { flex: 1 1 100%; }
}

/* Очень узкие экраны (iPhone SE и мельче). */
@media (max-width: 380px) {
  .tab { max-width: 92px; font-size: 12px; }
  .compose button { padding: 9px 10px; font-size: 13px; }
}

/* Вкладки Claude и Codex: значок режима вместо слова (см. _tabname.html). */
.modeico { display: inline-flex; flex: none; vertical-align: -3px; }
.modeico .ico, .tab .modeico .ico { color: inherit; margin-left: 0; }
.tabrow .modeico, .card .row .modeico { margin-right: 6px; }
.tab.on .modeico { color: var(--accent); }
