/* FlyCal — 2026 design system. Theme-aware (light/dark), no external assets. */

/* ---------- Design tokens ---------- */
:root, :root[data-theme="light"] {
  --bg: #f4f7fc;
  --bg-2: #eaf0f9;
  --aurora-1: rgba(100, 116, 139, .08);
  --aurora-2: rgba(13, 148, 136, .05);
  --surface: #ffffff;
  --surface-2: #f6f9fd;
  --line: #e6ebf3;
  --line-strong: #d3dbe8;
  --ink: #0e1726;
  --ink-2: #33415a;
  --muted: #6b7a92;
  --brand: #4f46e5;
  --brand-2: #0d9488;
  --brand-ink: #4338ca;
  --primary: #16202e;
  --on-primary: #ffffff;
  --accent-soft: #e7eefe;
  --danger: #e5484d;
  --danger-bg: #fdecec;
  --danger-line: #f3c9cb;
  --ok: #0a8f84;
  --ok-bg: #e2f7f4;
  --warn: #b3803a;
  --pin: #a9791a;
  --pin-bg: #fbecc4;
  --pin-card: linear-gradient(0deg, #fffdf5, #fff);
  --pin-line: #f2d488;
  --chip-bg: #eef2f9;
  --chip-ink: #40506a;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 14px 30px -12px rgba(16, 24, 40, .14);
  --shadow-lg: 0 2px 6px rgba(16, 24, 40, .06), 0 22px 44px -16px rgba(16, 24, 40, .22);
  --radius: 16px;
  --radius-sm: 10px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #090d15;
    --bg-2: #0c1220;
    --aurora-1: rgba(148, 163, 184, .10);
    --aurora-2: rgba(45, 212, 191, .06);
    --surface: #121a28;
    --surface-2: #0f1622;
    --line: #212b3d;
    --line-strong: #2c3850;
    --ink: #e7edf7;
    --ink-2: #b7c2d6;
    --muted: #8593aa;
    --brand: #818cf8;
    --brand-2: #2dd4bf;
    --brand-ink: #a5b4fc;
    --primary: #e7edf7;
    --on-primary: #0b1220;
    --accent-soft: #1b2540;
    --danger: #ff6b6f;
    --danger-bg: rgba(229, 72, 77, .14);
    --danger-line: rgba(229, 72, 77, .38);
    --ok: #34d3c2;
    --ok-bg: rgba(52, 211, 194, .13);
    --warn: #e0b878;
    --pin: #e8c877;
    --pin-bg: rgba(232, 200, 119, .16);
    --pin-card: linear-gradient(0deg, rgba(232, 200, 119, .05), var(--surface));
    --pin-line: rgba(232, 200, 119, .4);
    --chip-bg: #1a2231;
    --chip-ink: #b7c2d6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -14px rgba(0, 0, 0, .6);
    --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 26px 50px -16px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  --bg: #090d15;
  --bg-2: #0c1220;
  --aurora-1: rgba(148, 163, 184, .10);
  --aurora-2: rgba(45, 212, 191, .06);
  --surface: #121a28;
  --surface-2: #0f1622;
  --line: #212b3d;
  --line-strong: #2c3850;
  --ink: #e7edf7;
  --ink-2: #b7c2d6;
  --muted: #8593aa;
  --brand: #818cf8;
  --brand-2: #2dd4bf;
  --brand-ink: #a5b4fc;
  --primary: #e7edf7;
  --on-primary: #0b1220;
  --accent-soft: #1b2540;
  --danger: #ff6b6f;
  --danger-bg: rgba(229, 72, 77, .14);
  --danger-line: rgba(229, 72, 77, .38);
  --ok: #34d3c2;
  --ok-bg: rgba(52, 211, 194, .13);
  --warn: #e0b878;
  --pin: #e8c877;
  --pin-bg: rgba(232, 200, 119, .16);
  --pin-card: linear-gradient(0deg, rgba(232, 200, 119, .05), var(--surface));
  --pin-line: rgba(232, 200, 119, .4);
  --chip-bg: #1a2231;
  --chip-ink: #b7c2d6;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 18px 40px -14px rgba(0, 0, 0, .6);
  --shadow-lg: 0 2px 6px rgba(0, 0, 0, .5), 0 26px 50px -16px rgba(0, 0, 0, .7);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }

html { color-scheme: light dark; }

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(60vw 42vh at 12% -12%, var(--aurora-1), transparent 60%),
    radial-gradient(52vw 40vh at 104% -4%, var(--aurora-2), transparent 55%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.num, .eur, .rub, .t, .dur, .leg-times, .grid .num { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px clamp(16px, 4vw, 30px);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(14px) saturate(1.5);
  -webkit-backdrop-filter: blur(14px) saturate(1.5);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  font-weight: 750; font-size: 20px; letter-spacing: -.02em;
  color: var(--ink); text-decoration: none; display: flex; align-items: center; gap: 9px;
}
.brand-mark {
  display: grid; place-items: center; width: 30px; height: 30px; border-radius: 9px;
  background: var(--primary); color: var(--on-primary); font-size: 15px; transform: rotate(-6deg);
  box-shadow: var(--shadow-sm);
}
.nav { display: flex; align-items: center; gap: 4px; }
.nav a {
  padding: 8px 13px; border-radius: 10px; text-decoration: none;
  color: var(--muted); font-weight: 550; font-size: 14.5px; transition: .15s;
}
.nav a:hover { color: var(--ink); background: color-mix(in srgb, var(--ink) 6%, transparent); }
.nav a.active { color: var(--brand-ink); background: var(--accent-soft); }
.theme-btn {
  width: 36px; height: 34px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 15px; line-height: 1;
  display: inline-grid; place-items: center; transition: .15s; margin-left: 4px;
}
.theme-btn:hover { border-color: var(--line-strong); transform: translateY(-1px); }

/* Euro rate badge, shown in the header on every page */
a.rate-badge {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 7px 12px; margin-right: 6px; border-radius: 20px;
  border: 1px solid var(--line); background: var(--chip-bg);
  color: var(--ink); font-size: 13.5px; font-weight: 650; text-decoration: none;
  transition: .15s;
}
a.rate-badge:hover { border-color: var(--line-strong); background: var(--surface-2); color: var(--ink); }
.rate-badge-ic { color: var(--muted); font-weight: 600; }
.rate-badge-val { font-variant-numeric: tabular-nums; }
.rate-badge-cur { color: var(--muted); font-weight: 600; }

.container { max-width: 1000px; margin: 0 auto; padding: clamp(22px, 4vw, 38px) clamp(16px, 4vw, 24px) 72px; }

/* ---------- Headings ---------- */
.page-head { margin-bottom: 22px; }
.page-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
h1 { font-size: clamp(24px, 3.4vw, 30px); letter-spacing: -.025em; margin: 0 0 5px; font-weight: 760; }
.muted { color: var(--muted); }
.page-head p { margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; cursor: pointer;
  border: 1px solid transparent; border-radius: 11px;
  padding: 10px 18px; font-size: 14.5px; font-weight: 650;
  text-decoration: none; white-space: nowrap; color: var(--ink);
  transition: transform .12s ease, filter .15s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(0); }
.btn-sm { padding: 7px 13px; font-size: 14px; border-radius: 10px; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: var(--shadow-lg); }
.btn-primary:active { transform: translateY(0); }
.btn-ghost { background: var(--surface-2); color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--line-strong); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: var(--danger-line); margin-left: auto; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-danger-solid { background: var(--surface); color: var(--danger); border-color: var(--danger-line); }
.btn-danger-solid:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.head-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.head-actions form { margin: 0; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
input, select {
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  min-width: 150px; transition: border-color .15s, box-shadow .15s;
}
input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
::placeholder { color: var(--muted); }

/* ---------- Search card (legacy) ---------- */
.search-card {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 22px;
}
.search-card .swap { color: var(--muted); font-size: 20px; padding-bottom: 8px; }
.result-count { font-size: 14px; }

/* ---------- Filters ---------- */
.filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
  margin: 14px 0 4px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 13px; box-shadow: var(--shadow-sm);
}
.filters .field input, .filters .field select { min-width: 130px; padding: 8px 11px; }
.filters .field input[name="maxStops"] { min-width: 90px; }
.filters .result-count { margin-left: auto; align-self: center; }

/* ---------- Controls (segmented + sort) ---------- */
.controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 20px 0 8px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 4px; gap: 2px; }
.seg a { padding: 7px 15px; border-radius: 9px; text-decoration: none; color: var(--muted); font-weight: 600; font-size: 14px; transition: .15s; }
.seg a:hover { color: var(--ink); }
.seg a.on { background: var(--surface); color: var(--brand-ink); box-shadow: var(--shadow-sm); }
.sort { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.sort label { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ---------- Groups ---------- */
.group { margin-top: 28px; }
.group-head { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.group-head h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; font-weight: 700; }
.group-count { font-size: 12px; font-weight: 700; color: var(--muted); background: var(--chip-bg); border-radius: 20px; padding: 2px 9px; }

/* ---------- Itinerary cards ---------- */
.cards { display: flex; flex-direction: column; gap: 13px; }
.itin {
  display: flex; align-items: stretch; justify-content: space-between; gap: 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 22px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.itin:hover { border-color: var(--line-strong); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.itin.is-pinned { border-color: var(--pin-line); background: var(--pin-card); }
.itin-main { flex: 1; min-width: 0; }
.itin-route { display: flex; align-items: center; gap: 9px; margin-bottom: 14px; flex-wrap: wrap; }
.route { font-size: 16.5px; font-weight: 720; letter-spacing: -.01em; }
.tag { font-size: 11.5px; font-weight: 650; color: var(--muted); background: var(--chip-bg); padding: 3px 9px; border-radius: 20px; }
.tag-direct { color: var(--ok); background: var(--ok-bg); }
.tag-pin { color: var(--pin); background: var(--pin-bg); }

.itin-times { display: flex; align-items: center; gap: 18px; }
.tpoint { display: flex; flex-direction: column; }
.tpoint .t { font-weight: 650; font-size: 15px; }
.tpoint .c { color: var(--muted); font-size: 13px; }
.tline { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 5px; min-width: 120px; }
.tline .dur { font-size: 12.5px; color: var(--muted); font-weight: 650; }
.tline .bar { width: 100%; height: 2px; background: var(--line-strong); border-radius: 2px; position: relative; }
.tline .bar::after { content: "✈"; position: absolute; right: -3px; top: -9px; font-size: 12px; color: var(--brand); }
.tline .lay { font-size: 11.5px; color: var(--warn); }

.itin-airlines { margin-top: 14px; display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 11.5px; font-weight: 600; color: var(--chip-ink); background: var(--chip-bg); border: 1px solid var(--line); padding: 3px 10px; border-radius: 8px; }

.itin-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 12px; padding-left: 20px; border-left: 1px solid var(--line); min-width: 132px; }
.itin-price { display: flex; flex-direction: column; align-items: flex-end; }
.itin-price .eur, .rt-side .eur {
  font-size: 22px; font-weight: 820; letter-spacing: -.02em; color: var(--ink);
}
.itin-price .rub, .rt-side .rub { font-size: 13.5px; }

.itin-actions { display: flex; gap: 6px; }
.act {
  cursor: pointer; border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  width: 34px; height: 32px; border-radius: 9px; font-size: 15px; line-height: 1; transition: .14s;
}
.act:hover { border-color: var(--line-strong); background: var(--surface-2); color: var(--ink); transform: translateY(-1px); }
.act-del:hover { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }
.act-fav.on { color: var(--danger); border-color: var(--danger-line); background: var(--danger-bg); }
.act-fav:hover { color: var(--danger); border-color: var(--danger-line); }

.empty { padding: 44px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--line-strong); border-radius: var(--radius); }

/* ---------- Round trips ---------- */
.rt {
  display: flex; align-items: stretch; justify-content: space-between; gap: 20px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px 20px;
  transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}
.rt:hover { border-color: var(--line-strong); transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.rt.is-pinned { border-color: var(--pin-line); background: var(--pin-card); }
.rt-legs { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 12px; }
.rt-leg { display: flex; gap: 12px; }
.leg-dir { flex: 0 0 62px; font-size: 11.5px; font-weight: 700; color: #fff; background: var(--brand); border-radius: 8px; height: 22px; display: inline-flex; align-items: center; justify-content: center; margin-top: 2px; }
.rt-leg:nth-child(2) .leg-dir { background: var(--brand-2); color: #04222a; }
.leg-body { min-width: 0; }
.leg-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.leg-top .route { font-size: 15px; font-weight: 700; }
.leg-times { font-size: 14px; color: var(--ink-2); margin-top: 2px; }
.leg-times .arrow { color: var(--muted); }
.leg-air { margin-top: 6px; display: flex; gap: 5px; flex-wrap: wrap; }
.rt-side { display: flex; flex-direction: column; align-items: flex-end; justify-content: space-between; gap: 10px; padding-left: 20px; border-left: 1px solid var(--line); min-width: 152px; }
.rt-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 13px; color: var(--muted); }
.rt-meta b { color: var(--ink); }

/* ---------- Notices ---------- */
.notice { padding: 12px 16px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; border: 1px solid transparent; }
.notice-ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
.notice-bad { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-line); }
.small { font-size: 13px; margin-top: 8px; }
.hint { color: var(--ok); font-size: 13px; }

/* ---------- Flights table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: 14px; }
.grid th { text-align: left; padding: 13px 16px; color: var(--muted); font-weight: 650; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; border-bottom: 1px solid var(--line); background: var(--surface-2); position: sticky; top: 0; }
.grid td { padding: 12px 16px; border-bottom: 1px solid color-mix(in srgb, var(--line) 60%, transparent); }
.grid tr:last-child td { border-bottom: none; }
.grid tbody tr { transition: background .12s; }
.grid tbody tr:hover { background: var(--surface-2); }
.grid .num { text-align: right; }
.grid .nowrap { white-space: nowrap; }
.dir { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 6px; }
.dir-there { color: var(--brand-ink); background: var(--accent-soft); }
.dir-back { color: var(--ok); background: var(--ok-bg); }

.actions { white-space: nowrap; }
.inline { display: inline; margin: 0; }
.rowbtn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 28px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); text-decoration: none; font-size: 14px; cursor: pointer; transition: .14s; }
.rowbtn:hover { border-color: var(--line-strong); background: var(--surface-2); color: var(--ink); }
.rowbtn-del:hover { border-color: var(--danger-line); background: var(--danger-bg); color: var(--danger); }

/* ---------- Forms ---------- */
.form-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 26px; max-width: 660px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-card .field input, .form-card .field select { width: 100%; min-width: 0; }
.block { border: 1px solid var(--line); border-radius: 13px; padding: 16px 18px 18px; margin: 18px 0; background: var(--surface-2); }
.block legend { font-weight: 700; font-size: 13.5px; color: var(--brand-ink); padding: 0 8px; }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 8px; flex-wrap: wrap; }

/* ---------- Footer ---------- */
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 26px; border-top: 1px solid var(--line); }

/* Floating "scroll to top" button, bottom-right on every page */
.to-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 15;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-size: 19px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  opacity: 0; visibility: hidden; transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease, box-shadow .15s ease, border-color .15s ease;
}
.to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.to-top:hover { border-color: var(--line-strong); box-shadow: var(--shadow-lg); }

/* ---------- Responsive ---------- */
@media (max-width: 680px) {
  .form-grid { grid-template-columns: 1fr; }
  .itin, .rt { flex-direction: column; }
  .itin-side, .rt-side { flex-direction: row; align-items: center; border-left: none; border-top: 1px solid var(--line); padding-left: 0; padding-top: 14px; width: 100%; justify-content: space-between; }
  .itin-times { flex-wrap: wrap; }
  .controls .sort { margin-left: 0; }
  .nav a { padding: 8px 10px; }
}

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