/* ticket-radar — интерфейс. Без сборки: переменные для тем, системный шрифт, адаптив до ширины телефона.
   Модули static/css склеиваются по порядку имён в один app.css (web/assets.go): каскад — как в
   одном файле, новое правило — в модуль своей темы, переопределение — в модуле после него. */

:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #f0efec;
  --surface-3: #e7e6e2;
  --border: #e2e1dc;
  --border-strong: #cfcdc6;
  --text: #17171a;
  --muted: #6b6a66;
  /* Акцент подобран под AA: кнопка и ссылка держат контраст 4.5 на своём фоне. */
  --accent: #1f66bd;
  --accent-hover: #18559f;
  --accent-soft: #e6f0fb;
  --accent-ink: #ffffff;
  --ok: #197a47;
  --ok-soft: #e3f4ea;
  --warn: #9a6100;
  --warn-soft: #fbf0d9;
  --err: #c0362c;
  --err-soft: #fbe6e3;
  --shadow: 0 1px 2px rgba(20, 20, 18, .05), 0 2px 8px rgba(20, 20, 18, .04);
  --toast-shadow: 0 8px 24px rgba(0, 0, 0, .14), 0 2px 6px rgba(0, 0, 0, .08);
  --radius: 12px;
  --radius-sm: 8px;
  --pill: 999px; /* пилюля: скругление «до конца» у чипов и бейджей */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #121212;
    --surface: #1b1b1a;
    --surface-2: #232322;
    --surface-3: #2d2d2b;
    --border: #2f2f2d;
    --border-strong: #42423f;
    --text: #f0efec;
    --muted: #a3a29b;
    --accent: #3987e5;
    --accent-hover: #5b9de9;
    --accent-soft: #1a2c44;
    --accent-ink: #0d1a2b; /* белый на #3987e5 даёт 3.6, этот — 4.8 */
    --ok: #4cc283;
    --ok-soft: #173325;
    --warn: #e2a63b;
    --warn-soft: #3a2c12;
    --err: #ef7469;
    --err-soft: #3d1c19;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    --toast-shadow: 0 8px 28px rgba(0, 0, 0, .55), 0 2px 6px rgba(0, 0, 0, .4);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { overflow-wrap: anywhere; line-height: 1.25; margin: 0 0 .5em; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Каркас ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 12px;
  height: 56px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; flex: none; align-items: center; gap: 8px; color: var(--text); font-weight: 700; font-size: 1.1rem; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.logo { width: 22px; height: 22px; }
.spacer { flex: 1; }
.user-name { min-width: 0; color: var(--muted); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
form.inline { display: inline; margin: 0; }

.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: calc(100vh - 56px); }
.sidenav {
  position: sticky; top: 56px; align-self: start; height: calc(100vh - 56px);
  display: flex; flex-direction: column; gap: 2px; padding: 16px 10px;
  border-right: 1px solid var(--border); background: var(--surface); overflow-y: auto;
}
.navlink {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border-radius: var(--radius-sm); color: var(--text); font-weight: 500;
}
.navlink:hover { background: var(--surface-2); text-decoration: none; }
.navlink.active { background: var(--accent-soft); color: var(--accent); }
.main { padding: 24px 28px 64px; max-width: 1280px; width: 100%; }

/* ---------- Шапки и карточки ---------- */
.page-head { margin-bottom: 20px; }
.page-head p { max-width: 70ch; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 20px; min-width: 0;
}
.card.narrow { max-width: 560px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 20px; align-items: start; margin-bottom: 20px; }
.cols > .card { margin-bottom: 0; }

/* ---------- Кнопки и формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 550; cursor: pointer; text-decoration: none;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--err); border-color: var(--err); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: .88rem; }
.btn.big { min-height: 48px; padding: 10px 22px; font-size: 1.05rem; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.btn-row form { margin: 0; }

label { display: block; font-weight: 550; font-size: .92rem; }
label > input, label > select, label > textarea { display: block; margin-top: 5px; }
label .muted { font-weight: 400; }
input, select, textarea {
  font: inherit; font-weight: 400; color: var(--text);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 7px 10px; min-height: 36px; width: 100%; min-width: 0;
}
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); margin: 0; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 14px; }
.stack > form { margin: 0; }
.danger-zone { margin-top: 18px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }

/* ---------- Сообщения ---------- */
/* Тосты — итог действия поверх страницы, ничего не сдвигают: справа сверху под шапкой, на телефоне —
   во всю ширину. z-index 25: над полосой разделов (20), под шапкой (30). Пустая стопка нулевой
   высоты и пропускает клики. */
#flash-area {
  position: fixed; inset: 68px 16px auto auto; z-index: 25; width: min(400px, calc(100vw - 32px));
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
body.bare #flash-area { top: 16px; }
.toast {
  position: relative; overflow: hidden; pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px; padding: 12px 40px 12px 14px;
  border: 1px solid; border-radius: var(--radius-sm); color: var(--text); box-shadow: var(--toast-shadow);
  animation: toast-in .18s ease-out;
}
.toast-text { flex: 1; min-width: 0; max-height: 40vh; overflow-y: auto; overflow-wrap: anywhere; line-height: 1.45; }
.toast-close {
  position: absolute; top: 8px; right: 8px; display: flex; align-items: center; justify-content: center; width: 28px; height: 28px;
  background: none; border: 0; border-radius: var(--radius-sm); font-size: 1.25rem; line-height: 1; cursor: pointer; color: var(--muted);
  outline-offset: -2px;
}
.toast-close:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.toast-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.toast-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.toast-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.toast-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } }
.alert {
  display: flex; align-items: flex-start; gap: 10px; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius-sm); margin-bottom: 14px; border: 1px solid;
}
.alert > span { min-width: 0; overflow-wrap: anywhere; }
.alert-ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 35%, transparent); }
.alert-error { background: var(--err-soft); border-color: color-mix(in srgb, var(--err) 35%, transparent); }
.alert-info { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.alert-warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }

/* ---------- Значки и ожидание ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: var(--pill);
  font-size: .76rem; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted);
}
.badge.on { background: var(--ok-soft); color: var(--ok); }
.badge.fail { background: var(--err-soft); color: var(--err); }
.spinner {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid currentColor; border-right-color: transparent; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
/* includeIndicatorStyles выключен (CSP без inline-стилей): индикатор htmx прячем сами. */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: inline-block; }
.waiting { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); }
.login-box { max-width: 380px; margin: 12vh auto 0; padding: 0 16px; }

/* ---------- Подписки ---------- */
.fields-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(150px, 100%), 1fr)); gap: 14px; align-items: end; }
/* Длинные названия городов на телефоне не должны обрезаться: столбиком. */
.route-fields { grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); }
/* Отказ лежит в форме, а страница после него открывается сверху: форма — первой, иначе на телефоне ошибку
   не видно. */
.cols.form-first > .new-sub { order: -1; }
.sub-list { list-style: none; margin: 0; padding: 0; }
.sub-item { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--border); }
.sub-item:first-child { border-top: 0; padding-top: 0; }
.sub-item form { margin: 0; flex: none; }
.sub-main { min-width: 0; overflow-wrap: anywhere; }
.sub-route { font-weight: 600; }
.sub-status { margin-top: 6px; }
.sub-status .badge { white-space: normal; }
.small { font-size: .85rem; }

/* ---------- Адаптив: от 320 px без прокрутки вбок ---------- */
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; } /* иначе короткая страница растягивает строку меню */
  .sidenav {
    position: sticky; top: 56px; z-index: 20; height: auto; flex-direction: row; overflow-x: auto;
    padding: 6px 10px; border-right: 0; border-bottom: 1px solid var(--border); scrollbar-width: none;
  }
  .sidenav::-webkit-scrollbar { display: none; }
  .navlink { flex: none; padding: 6px 10px; font-size: .9rem; }
  .main { padding: 16px 16px 48px; }
  .topbar { gap: 8px; padding: 0 12px; }
  .cols { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.35rem; }
  #flash-area { inset: 64px 8px auto 8px; width: auto; }
}
@media (max-width: 640px) {
  .card { padding: 14px; }
}
/* Поля 16px: иначе iOS увеличивает страницу при фокусе. Кнопки — под палец. */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn.small { min-height: 40px; }
}
