:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e3e0d9;
  --text: #1c1a17;
  --muted: #6d675e;
  --accent: #c2410c;
  --accent-soft: #fff1e9;
  --start: #c2410c;
  --end: #1d4ed8;
  --good: #15803d;
  --new: #b45309;
  --shadow: 0 1px 2px rgba(28, 26, 23, .06), 0 8px 24px rgba(28, 26, 23, .06);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14130f;
    --surface: #1e1c18;
    --surface-2: #262320;
    --border: #37332c;
    --text: #f0ece5;
    --muted: #a09a8f;
    --accent: #fb923c;
    --accent-soft: #2e1c10;
    --start: #fb923c;
    --end: #60a5fa;
    --good: #4ade80;
    --new: #fbbf24;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.01em; }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ── top bar ─────────────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { font-size: 30px; line-height: 1; }
.brand h1 { font-size: 19px; }
.tagline { margin: 1px 0 0; font-size: 12.5px; color: var(--muted); }

.topbar-right { display: flex; align-items: center; gap: 20px; }

.stats { display: flex; gap: 20px; margin: 0; }
.stats div { text-align: right; }
.stats dt { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.stats dd { margin: 0; font-size: 17px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stats dd.is-new { color: var(--new); }

/* ── filters ─────────────────────────────────────────────────────────── */

.filters {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  padding: 10px 20px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 130px; }
.field-narrow { min-width: 78px; }
.field label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
}

select, input[type="date"], input[type="number"], input[type="text"] {
  font: inherit;
  font-size: 13.5px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  min-height: 33px;
}

select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.field-checks { gap: 6px; justify-content: center; min-width: auto; }
.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
  font-weight: 400;
}
.check input { accent-color: var(--accent); }

.btn {
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; }
.btn-block { width: 100%; margin-top: 8px; padding: 11px; }

/* ── layout ──────────────────────────────────────────────────────────── */

.layout { flex: 1; display: grid; grid-template-columns: minmax(380px, 42%) 1fr; min-height: 0; }

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--border);
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px 10px;
  gap: 12px;
}
.list-head h2 { font-size: 14px; color: var(--muted); font-weight: 600; }
.sort { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sort select { font-size: 12.5px; padding: 4px 6px; min-height: 28px; }

.list { flex: 1; overflow-y: auto; padding: 0 14px 24px; }

/* ── offer cards ─────────────────────────────────────────────────────── */

.month-label {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px 4px 6px;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  background: linear-gradient(var(--bg) 70%, transparent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: border-color .12s, transform .12s;
}
.card:hover { border-color: var(--accent); transform: translateY(-1px); }
.card.is-active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.card-top { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.route { font-weight: 650; font-size: 15px; }
.route .arrow { color: var(--muted); margin: 0 5px; font-weight: 400; }
.price { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

.card-dates {
  margin-top: 4px;
  font-size: 13.5px;
  font-variant-numeric: tabular-nums;
}

.card-meta {
  margin-top: 7px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.chip {
  font-size: 11.5px;
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  white-space: nowrap;
}
.chip-new { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-flex { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip-vehicle { color: var(--text); }

.empty {
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}

/* ── map ─────────────────────────────────────────────────────────────── */

.map-pane { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--surface-2); }

.map-legend {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 500;
  display: flex;
  gap: 14px;
  align-items: center;
  padding: 7px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12px;
  box-shadow: var(--shadow);
}
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.dot-start { background: var(--start); }
.dot-end { background: var(--end); }
.legend-hint { color: var(--muted); border-left: 1px solid var(--border); padding-left: 14px; }

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-popup-content b { font-size: 14px; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-2); }

/* Dark mode: tone the tiles down rather than ship a second tile source. */
@media (prefers-color-scheme: dark) {
  .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
}

/* ── modals ──────────────────────────────────────────────────────────── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(20, 19, 15, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }

.modal {
  position: relative;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 24px;
  width: 100%;
  max-width: 460px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal-wide { max-width: 620px; }

.modal-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal h2 { font-size: 18px; margin-bottom: 6px; }
.modal .field { margin-top: 14px; min-width: 0; }
.modal .field input { width: 100%; }

.alert-criteria {
  margin-top: 14px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.criteria-summary { margin: 0 0 6px; font-weight: 600; font-size: 13.5px; }
.preview-line { margin: 14px 0 0; font-size: 13px; color: var(--muted); }

/* ── offer detail ────────────────────────────────────────────────────── */

.detail-header { margin-bottom: 4px; padding-right: 30px; }
.detail-header h2 { font-size: 21px; }
.detail-sub { color: var(--muted); font-size: 13.5px; margin-top: 3px; }

.detail-price {
  display: inline-block;
  margin-top: 12px;
  padding: 6px 12px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  font-weight: 700;
  font-size: 15px;
}

.gallery { display: flex; gap: 8px; overflow-x: auto; margin: 16px 0; padding-bottom: 4px; }
.gallery img {
  height: 140px;
  width: auto;
  border-radius: 10px;
  object-fit: cover;
  flex: none;
  background: var(--surface-2);
}

.legs { display: grid; gap: 12px; margin-top: 16px; }
.leg {
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 10px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
}
.leg-icon { font-size: 17px; line-height: 1.3; }
.leg h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.leg .leg-place { font-weight: 650; margin-top: 2px; }
.leg .leg-line { font-size: 13px; color: var(--muted); margin-top: 2px; }
.leg a { color: var(--accent); }

.vehicle-table { width: 100%; border-collapse: collapse; margin-top: 16px; font-size: 13.5px; }
.vehicle-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.vehicle-table td { padding: 8px; border-bottom: 1px solid var(--border); }
.vehicle-table tr:last-child td { border-bottom: none; }
.tag-out { color: var(--muted); font-size: 12px; }

.detail-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.detail-actions .btn { flex: 1; text-align: center; text-decoration: none; min-width: 150px; }

.telegram-box {
  margin-top: 16px;
  padding: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  text-align: center;
}
.telegram-box a {
  display: inline-block;
  margin-top: 10px;
  padding: 11px 20px;
  background: #229ED9;
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 650;
}
.telegram-box code {
  display: block;
  margin-top: 10px;
  font-size: 11.5px;
  color: var(--muted);
  word-break: break-all;
}

/* ── mobile ──────────────────────────────────────────────────────────── */

.mobile-toggle { display: none; }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .list-pane { border-right: none; }
  .map-pane { display: none; }
  body.view-map .list-pane { display: none; }
  body.view-map .map-pane { display: block; }

  .topbar { padding: 10px 14px; }
  .topbar-right { width: 100%; justify-content: space-between; }
  .stats { gap: 14px; }
  .filters { padding: 10px 14px; }

  .mobile-toggle {
    display: flex;
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 900;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }
  .mobile-toggle button {
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    padding: 9px 22px;
    border: none;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
  }
  .mobile-toggle button.active { background: var(--accent); color: #fff; }
  .list { padding-bottom: 70px; }
}
