/*
 * Прогулка — the design system every page shares.
 *
 * A light "city field guide": a white page, near-white blocks separated by soft warm
 * rules, near-black ink and one terracotta accent kept for the route and the main
 * action, so on a projector the eye lands on what matters. Spectral (serif) for names
 * and headings, Golos Text for the interface, JetBrains Mono for numbers, times and
 * tool calls. Token names are the ones the first UI used (--route, --paper, --rule,
 * ...), so planner styles written against them keep working and simply turn lighter.
 *
 * Tokens (custom properties on :root)
 *   colour  --bg --card --paper --paper-deep --rule --rule-strong
 *           --ink --ink-soft --muted --faint
 *           --route --route-deep --route-tint --route-wash
 *           --green(-tint) --amber(-tint) --red(-tint)
 *   type    --serif --sans --mono
 *   shape   --radius-sm --radius --radius-lg --shadow-sm --shadow --shadow-lg
 *   layout  --topbar-h --page-max
 *
 * Components (class -> markup)
 *   body.is-app            viewport-high app: #topbar row + one row that fills the rest
 *   .container .page .page-head      centred column, page padding, title row
 *   .topbar ...            built by js/nav.js into <header id="topbar">
 *   .display .title .subtitle .eyebrow .lead .muted .num            typography
 *   .btn + .btn-primary | .btn-ghost | .btn-danger, .btn-sm | .btn-lg, .btn-block,
 *        .is-busy (striped "working" state)
 *   .field > label + .input | .textarea, .field-hint, .field-error (input[aria-invalid])
 *   .card [.card-pad]  white block;  .panel  tinted block
 *   .chips > .chip      static pill: .is-strong .is-interest .is-must .is-avoid
 *        button.chip[aria-pressed=false|mixed|true]  toggle; "mixed" = interested, "true"
 *        = strongly; .chip-dots shows the level; [data-tone=avoid] for "do not suggest";
 *        .chip-x  remove button inside a pill
 *   .segmented > label > input[type=radio] + span                 segmented control
 *   label.toggle > input[type=checkbox][role=switch] + .toggle-track + text   switch
 *   input[type=range].slider, style="--fill: 40%"                 slider
 *   .alert [.is-error | .is-ok | .is-info]                         inline message
 *   .toasts > .toast, dialog.dialog      built by js/ui.js toast() / confirmDialog()
 *   .empty > h2 + p       empty state with the dotted-route sketch
 *   .table-wrap > table.table (td.num right-aligned mono)
 *   .tag .count .skeleton .sr-only
 *   @keyframes rise pop pulse stripes shimmer; all motion is off under prefers-reduced-motion
 */

:root {
  --bg: #ffffff;
  --card: #ffffff;
  --paper: #faf9f6;
  --paper-deep: #f2f0eb;
  --rule: #eae6de;
  --rule-strong: #d8d2c6;

  --ink: #1c1f1d;
  --ink-soft: #3b403d;
  --muted: #686b66;
  --faint: #9a9c96;

  --route: #c8412a;
  --route-deep: #a9351d;
  --route-tint: #fbe6de;
  --route-wash: #fdf5f1;

  --green: #2c6e49;
  --green-tint: #e4f2e8;
  --amber: #855600;
  --amber-tint: #fcf1d6;
  --red: #b42318;
  --red-tint: #fdeae7;

  --serif: "Spectral", "PT Serif", Georgia, serif;
  --sans: "Golos Text", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgb(28 31 29 / 0.05);
  --shadow: 0 1px 2px rgb(28 31 29 / 0.04), 0 10px 28px -16px rgb(28 31 29 / 0.22);
  --shadow-lg: 0 2px 6px rgb(28 31 29 / 0.05), 0 28px 64px -28px rgb(28 31 29 / 0.32);

  --topbar-h: 64px;
  --page-max: 1180px;
}

/* projectors and big monitors: everything grows a little, nothing important under 14px */
@media (min-width: 1700px) {
  html { font-size: 17px; }
}

/* ---------- reset ---------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font: 400 1rem/1.55 var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

body.is-app {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

h1, h2, h3, h4, p, figure, blockquote, dl, dd { margin: 0; }
ul[class], ol[class] { margin: 0; padding: 0; list-style: none; }
img, svg { display: block; max-width: 100%; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; }

a { color: var(--route-deep); text-underline-offset: 3px; }

:focus-visible { outline: 3px solid var(--route); outline-offset: 2px; }
::selection { background: var(--route-tint); }

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- layout ---------- */

.container { width: min(100% - 48px, var(--page-max)); margin-inline: auto; }

.page { padding-block: 40px 96px; }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px 24px;
  margin-bottom: 32px;
}
.page-head > div { display: grid; gap: 8px; }

@media (max-width: 640px) {
  .container { width: min(100% - 32px, var(--page-max)); }
  .page { padding-block: 24px 64px; }
}

/* ---------- typography ---------- */

.display {
  font: 500 clamp(2.3rem, 3.8vw, 3.6rem)/1.06 var(--serif);
  letter-spacing: -0.022em;
  text-wrap: balance;
}
.display em { font-style: italic; font-weight: 400; color: var(--route); }

.title {
  font: 600 clamp(1.75rem, 2.6vw, 2.35rem)/1.12 var(--serif);
  letter-spacing: -0.015em;
  text-wrap: balance;
}

.subtitle { font: 600 1.3rem/1.25 var(--serif); letter-spacing: -0.005em; }

.eyebrow {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--route-deep);
}

.lead { font-size: 1.14rem; line-height: 1.6; color: var(--ink-soft); text-wrap: pretty; }
.muted { color: var(--muted); }
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 18px;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  font-size: 0.98rem;
  font-weight: 600;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.btn:hover:not(:disabled) { border-color: var(--ink); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }

.btn-primary { border-color: var(--route); background: var(--route); color: #fff; }
.btn-primary:hover:not(:disabled) { border-color: var(--route-deep); background: var(--route-deep); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-soft); }
.btn-ghost:hover:not(:disabled) { border-color: transparent; background: var(--paper-deep); color: var(--ink); }

.btn-danger { color: var(--red); }
.btn-danger:hover:not(:disabled) { border-color: var(--red); background: var(--red-tint); }

.btn-sm { min-height: 36px; padding: 0 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.btn-lg { min-height: 54px; padding: 0 26px; border-radius: var(--radius); font-size: 1.06rem; }
.btn-block { width: 100%; }

/* while something runs the button becomes a moving progress bar instead of a dead control */
.btn.is-busy,
.btn.is-busy:disabled {
  opacity: 1;
  cursor: progress;
  background-image: repeating-linear-gradient(-45deg, rgb(255 255 255 / 0.18) 0 10px, transparent 10px 20px);
  background-size: 28px 28px;
  animation: stripes 0.8s linear infinite;
}
.btn:not(.btn-primary).is-busy {
  background-image: repeating-linear-gradient(-45deg, var(--paper-deep) 0 10px, transparent 10px 20px);
}

/* ---------- form fields ---------- */

.field { display: grid; gap: 6px; }
.field > label, .field-label { font-size: 0.92rem; font-weight: 600; color: var(--ink); }
.field-hint { font-size: 0.86rem; color: var(--muted); }
.field-error { font-size: 0.86rem; font-weight: 500; color: var(--red); }
.field-error:empty { display: none; }

.input, .textarea {
  width: 100%;
  min-height: 46px;
  padding: 10px 14px;
  border: 1px solid var(--rule-strong);
  border-radius: 10px;
  background: #fff;
  font-size: 1rem;
  line-height: 1.4;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.textarea { min-height: 7em; resize: vertical; line-height: 1.5; }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input:hover, .textarea:hover { border-color: #c4bdb0; }
.input:focus, .textarea:focus { border-color: var(--ink); outline: none; box-shadow: 0 0 0 4px var(--route-tint); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--red); }
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus { box-shadow: 0 0 0 4px var(--red-tint); }

/* ---------- blocks ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 28px; }
@media (max-width: 640px) {
  .card-pad { padding: 20px; }
}

.panel { padding: 20px 22px; border-radius: var(--radius); background: var(--paper); }

/* ---------- chips ---------- */

.chips { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 11px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--paper-deep);
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--ink-soft);
}
.chip.is-strong { background: var(--ink); color: #fff; }
.chip.is-interest { background: var(--route-tint); color: var(--route-deep); font-weight: 500; }
.chip.is-interest b { font: 600 0.75rem var(--mono); }
.chip.is-must { background: var(--green-tint); color: var(--green); }
.chip.is-avoid { border: 1px dashed var(--rule-strong); background: transparent; color: var(--muted); }

button.chip {
  min-height: 40px;
  padding: 7px 15px;
  border-color: var(--rule-strong);
  background: var(--card);
  font-size: 0.96rem;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
button.chip:hover:not(:disabled) { border-color: var(--ink); color: var(--ink); }
button.chip:active:not(:disabled) { transform: scale(0.97); }
button.chip[aria-pressed="mixed"] { border-color: #eeb8a6; background: var(--route-tint); color: var(--route-deep); }
button.chip[aria-pressed="true"] { border-color: var(--route); background: var(--route); color: #fff; }
button.chip[data-tone="avoid"][aria-pressed="true"] { border-color: var(--ink); background: var(--ink); color: #fff; }

/* two small dots after the label: empty, one filled ("интересно"), both filled ("очень") */
.chip-dots { display: inline-flex; gap: 3px; margin-left: 2px; }
.chip-dots i { width: 7px; height: 7px; border: 1.5px solid currentColor; border-radius: 50%; opacity: 0.35; }
[aria-pressed="mixed"] > .chip-dots i:first-child,
[aria-pressed="true"] > .chip-dots i { background: currentColor; opacity: 1; }

.chip-x {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  margin: 0 -5px 0 2px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1rem;
  line-height: 1;
  color: inherit;
  opacity: 0.6;
}
.chip-x:hover { background: rgb(28 31 29 / 0.1); opacity: 1; }

/* ---------- segmented control ---------- */

.segmented {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--paper-deep);
}
.segmented label { position: relative; display: flex; }
.segmented input { position: absolute; inset: 0; margin: 0; opacity: 0; cursor: pointer; }
.segmented span {
  display: grid;
  gap: 1px;
  padding: 8px 18px;
  border-radius: 9px;
  font-weight: 500;
  line-height: 1.3;
  color: var(--ink-soft);
  text-align: center;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.segmented small { font-size: 0.78rem; font-weight: 400; color: var(--muted); }
.segmented label:hover span { color: var(--ink); }
.segmented input:checked + span { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgb(28 31 29 / 0.12); }
.segmented input:focus-visible + span { outline: 3px solid var(--route); outline-offset: 1px; }

/* ---------- toggle switch ---------- */

.toggle { display: inline-flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 999px;
  background: var(--rule-strong);
  transition: background 0.2s;
}
.toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgb(28 31 29 / 0.3);
  transition: transform 0.2s cubic-bezier(0.3, 1.4, 0.5, 1);
}
.toggle input:checked + .toggle-track { background: var(--route); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--route); outline-offset: 2px; }

/* ---------- slider ---------- */

.slider {
  --fill: 50%;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}
.slider::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--route) var(--fill), var(--paper-deep) var(--fill));
}
.slider::-webkit-slider-thumb {
  width: 24px;
  height: 24px;
  margin-top: -9px;
  border: 2.5px solid var(--route);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgb(28 31 29 / 0.25);
  -webkit-appearance: none;
}
.slider::-moz-range-track { height: 6px; border-radius: 999px; background: var(--paper-deep); }
.slider::-moz-range-progress { height: 6px; border-radius: 999px; background: var(--route); }
.slider::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border: 2.5px solid var(--route);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgb(28 31 29 / 0.25);
}
.slider:focus-visible { outline: none; }
.slider:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 5px var(--route-tint); }
.slider:focus-visible::-moz-range-thumb { box-shadow: 0 0 0 5px var(--route-tint); }
/* "no limit": the slider stays usable but reads as switched off */
.slider.is-off::-webkit-slider-runnable-track { background: var(--paper-deep); }
.slider.is-off::-webkit-slider-thumb { border-color: var(--rule-strong); }
.slider.is-off::-moz-range-progress { background: transparent; }
.slider.is-off::-moz-range-thumb { border-color: var(--rule-strong); }

/* ---------- messages ---------- */

.alert {
  padding: 11px 14px;
  border-left: 3px solid var(--rule-strong);
  border-radius: 0 10px 10px 0;
  background: var(--paper);
  font-size: 0.95rem;
  color: var(--ink-soft);
}
.alert.is-error { border-color: var(--red); background: var(--red-tint); color: var(--red); }
.alert.is-ok { border-color: var(--green); background: var(--green-tint); color: var(--green); }
.alert.is-info { border-color: var(--route); background: var(--route-wash); color: var(--ink-soft); }

.toasts {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 28px;
  display: grid;
  justify-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100vw - 32px);
  transform: translateX(-50%);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  border-radius: var(--radius);
  background: var(--ink);
  box-shadow: var(--shadow-lg);
  font-weight: 500;
  color: #fff;
  animation: rise 0.25s ease-out both;
  pointer-events: auto;
}
.toast::before { content: "•"; font-size: 1.3em; line-height: 1; color: #f2a28f; }
.toast.is-ok::before { content: "✓"; font-size: 1em; color: #9fd8b4; }
.toast.is-error { background: var(--red); }
.toast.is-error::before { content: "!"; font-size: 1em; color: #fff; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 26px 26px 22px;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--card);
  box-shadow: var(--shadow-lg);
  color: var(--ink);
}
.dialog::backdrop { background: rgb(28 31 29 / 0.32); backdrop-filter: blur(2px); }
.dialog[open] { animation: rise 0.2s ease-out both; }
.dialog h2 { font: 600 1.3rem/1.25 var(--serif); }
.dialog p { margin-top: 8px; color: var(--ink-soft); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- empty state ---------- */

.empty {
  display: grid;
  gap: 10px;
  align-content: center;
  min-height: 100%;
  padding: 24px 8px;
  text-align: center;
  color: var(--muted);
}
.empty::before {
  content: "";
  justify-self: center;
  width: 128px;
  height: 68px;
  margin-bottom: 6px;
  /* a dotted route sketch between two stops: the brand mark, stretched */
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 120 64'%3E%3Cpath d='M10 52 C 40 10, 70 70, 110 14' fill='none' stroke='%23c8412a' stroke-width='3' stroke-linecap='round' stroke-dasharray='0.1 8'/%3E%3Ccircle cx='10' cy='52' r='6' fill='%231c1f1d'/%3E%3Ccircle cx='110' cy='14' r='6' fill='%23c8412a'/%3E%3C/svg%3E") center / contain no-repeat;
}
.empty h2 { font: 600 1.45rem/1.2 var(--serif); color: var(--ink); }
.empty p { max-width: 38ch; justify-self: center; }
.empty .btn { justify-self: center; max-width: 100%; margin-top: 10px; white-space: normal; text-align: center; }

/* ---------- tables ---------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--card); }
.table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.table th {
  padding: 11px 16px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  font-size: 0.76rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-align: left;
  text-transform: uppercase;
  color: var(--muted);
  white-space: nowrap;
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--paper); }
.table .num { text-align: right; white-space: nowrap; }
.table th.num { font-family: inherit; }

/* ---------- small labels and loading ---------- */

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--paper-deep);
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.count {
  display: inline-block;
  padding: 0 7px;
  border-radius: 5px;
  background: var(--ink);
  font: 600 0.78rem/1.6 var(--mono);
  color: #fff;
}

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--paper-deep) 30%, var(--paper) 50%, var(--paper-deep) 70%) 0 0 / 300% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

/* ---------- top bar (markup from js/nav.js) ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: var(--topbar-h); /* holds the space before nav.js fills the bar */
  border-bottom: 1px solid var(--rule);
  background: rgb(255 255 255 / 0.9);
  backdrop-filter: blur(12px) saturate(1.4);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 8px 28px;
  min-height: var(--topbar-h);
  padding: 0 24px;
}

.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; }
.brand-name { font: 600 1.5rem/1 var(--serif); letter-spacing: -0.01em; }
.logo { flex: none; width: 36px; height: 36px; color: var(--route); }
.logo-start { fill: var(--ink); }

.nav { display: flex; gap: 2px; }
.nav a {
  position: relative;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  color: var(--ink-soft);
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover { background: var(--paper-deep); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); }
/* the active section is underlined with a dotted route */
.nav a[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 1px;
  height: 4px;
  background: radial-gradient(circle, var(--route) 1.6px, transparent 2.1px) 0 50% / 8px 4px repeat-x;
}
.nav .nav-new { color: var(--route-deep); }
.nav .nav-new::before { content: "+"; margin-right: 5px; font-weight: 700; }

.topbar-user { display: flex; align-items: center; gap: 10px; margin-left: auto; min-width: 0; }
.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--route-tint);
  font: 600 1rem/1 var(--serif);
  color: var(--route-deep);
}
.user-name { max-width: 18ch; overflow: hidden; font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }

@media (max-width: 860px) {
  .topbar-inner { flex-wrap: wrap; padding: 10px 16px 0; }
  .nav { order: 3; width: calc(100% + 32px); margin: 0 -16px; padding: 0 10px 6px; overflow-x: auto; scrollbar-width: none; }
  .user-name { display: none; }
}

/* ---------- motion ---------- */

@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
@keyframes pop { from { opacity: 0; transform: scale(0.3); } }
@keyframes pulse { 50% { opacity: 0.3; } }
@keyframes stripes { to { background-position: 28px 0; } }
@keyframes shimmer { to { background-position: -150% 0; } }

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