:root {
  --bg: #0b1020;
  --bg-2: #0e1530;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-strong: rgba(255, 255, 255, 0.1);
  --border: rgba(255, 255, 255, 0.12);
  --text: #eaf0ff;
  --muted: #9fb0d6;
  --accent: #5b8cff;
  --accent-2: #8a5bff;
  --green: #2fe39b;
  --red: #ff5d73;
  --amber: #ffb454;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Vazirmatn", system-ui, sans-serif;
  min-height: 100vh;
}

body {
  position: relative;
  overflow-x: hidden;
  padding-bottom: 60px;
}

.aurora {
  position: fixed;
  inset: -20% -10% auto -10%;
  height: 70vh;
  background:
    radial-gradient(40% 60% at 20% 20%, rgba(91, 140, 255, 0.35), transparent 60%),
    radial-gradient(45% 55% at 80% 10%, rgba(138, 91, 255, 0.32), transparent 60%),
    radial-gradient(40% 50% at 60% 60%, rgba(47, 227, 155, 0.18), transparent 60%);
  filter: blur(20px);
  z-index: -1;
  animation: floaty 16s ease-in-out infinite alternate;
}
@keyframes floaty {
  to { transform: translateY(30px) scale(1.05); }
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 22px clamp(16px, 4vw, 48px);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo {
  font-size: 30px;
  width: 56px; height: 56px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.brand h1 { margin: 0; font-size: 24px; font-weight: 800; letter-spacing: .3px; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.next-check {
  display: flex; align-items: center; gap: 8px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px; font-size: 13px; color: var(--muted);
}
.next-check .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 10px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse { 50% { opacity: .35; } }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--panel-strong);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 12px;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform .12s ease, background .2s ease, box-shadow .2s;
}
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.14); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; box-shadow: var(--shadow); }
.btn.ghost { background: transparent; }
.btn.tiny { padding: 6px 12px; font-size: 12px; }

/* ---------- layout ---------- */
.layout {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 20px;
  padding: 0 clamp(16px, 4vw, 48px);
}
@media (max-width: 880px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 14px; font-size: 17px; }

.add-form { display: flex; gap: 10px; flex-wrap: wrap; }
.flight-input { flex: 1 1 180px; }
.date-input {
  flex: 0 0 150px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 13px 12px;
  font-family: inherit;
  font-size: 14px;
  outline: none;
}
.date-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.25); }
.add-form .btn.primary { flex: 0 0 auto; }
.flight-input {
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  padding: 13px 16px;
  font-family: inherit;
  font-size: 16px;
  letter-spacing: 1px;
  outline: none;
  transition: border .2s, box-shadow .2s;
}
.flight-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,140,255,.25); }
.flight-input::placeholder { color: var(--muted); letter-spacing: 0; }

.hint { color: var(--muted); font-size: 12.5px; line-height: 1.9; margin: 14px 0 0; }
.hint code, .demo-banner code { background: rgba(0,0,0,.35); padding: 1px 6px; border-radius: 6px; direction: ltr; display: inline-block; }

.form-msg { min-height: 18px; margin-top: 10px; font-size: 13px; }
.form-msg.error { color: var(--red); }
.form-msg.ok { color: var(--green); }

.stats { display: flex; gap: 12px; margin-top: 18px; }
.stat {
  flex: 1; text-align: center;
  background: rgba(0,0,0,.2); border: 1px solid var(--border);
  border-radius: 14px; padding: 12px 8px;
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--muted);
}
.stat-num { font-size: 24px; font-weight: 800; color: var(--text); }
.stat-num.delay { color: var(--amber); }

/* ---------- alerts ---------- */
.alerts-head { display: flex; justify-content: space-between; align-items: center; }
.alerts-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 320px; overflow-y: auto; }
.alerts-list li {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 11px 12px; border-radius: 12px; margin-bottom: 8px;
  background: rgba(0,0,0,.2); border: 1px solid var(--border);
  font-size: 13px; line-height: 1.6;
}
.alerts-list li.empty { justify-content: center; color: var(--muted); background: transparent; border-style: dashed; }
.alert-ico { font-size: 16px; line-height: 1.4; }
.alert-body { flex: 1; }
.alert-time { color: var(--muted); font-size: 11px; margin-top: 2px; }
.alert-delay  { border-color: rgba(255,93,115,.4); }
.alert-early  { border-color: rgba(47,227,155,.4); }
.alert-arrived{ border-color: rgba(91,140,255,.45); }
.alert-departed{ border-color: rgba(255,180,84,.4); }
.alert-warn   { border-color: rgba(255,180,84,.5); }

/* ---------- board ---------- */
.board-wrap { padding: 0 clamp(16px, 4vw, 48px); margin-top: 28px; }
.board-title { font-size: 18px; margin: 0 0 16px; }
.board-title.muted { color: var(--muted); }
.board {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 18px;
  align-items: stretch;
}
.board-empty {
  grid-column: 1 / -1;
  text-align: center; color: var(--muted);
  padding: 50px 20px;
  border: 1px dashed var(--border); border-radius: var(--radius);
}
.board-empty .big { font-size: 40px; display: block; margin-bottom: 10px; }

/* ---------- flight card ---------- */
.card {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  backdrop-filter: blur(14px);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card.card-enter { animation: rise .35s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
.card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.card.state-airborne::before { background: linear-gradient(90deg, var(--green), var(--accent)); }
.card.state-arrived::before  { background: linear-gradient(90deg, var(--accent-2), var(--accent)); }
.card.state-error::before, .card.state-notfound::before { background: linear-gradient(90deg, var(--red), var(--amber)); }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  min-height: 58px;
}
.card-head-main { flex: 1; min-width: 0; }
.card-head-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.flight-no { font-size: 22px; font-weight: 800; letter-spacing: 1px; direction: ltr; line-height: 1.2; }
.airline {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 4px;
  line-height: 1.45;
  min-height: 2.9em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.remove-btn {
  background: rgba(255,93,115,.12); border: 1px solid rgba(255,93,115,.3);
  color: var(--red); width: 30px; height: 30px; border-radius: 9px;
  cursor: pointer; font-size: 15px; line-height: 1; flex-shrink: 0;
  transition: background .2s;
}
.remove-btn:hover { background: rgba(255,93,115,.25); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
  line-height: 1.2;
  min-height: 30px;
}
.badge.scheduled { background: rgba(91,140,255,.18); color: #aac3ff; }
.badge.airborne  { background: rgba(47,227,155,.16); color: #87ffd2; }
.badge.departed  { background: rgba(255,180,84,.16); color: #ffd29a; }
.badge.arrived   { background: rgba(138,91,255,.18); color: #cdb6ff; }
.badge.error, .badge.notfound, .badge.canceled { background: rgba(255,93,115,.16); color: #ffb0bb; }
.badge.estimated { background: rgba(255,180,84,.16); color: #ffd29a; }

.card-note {
  min-height: 54px;
  margin: 8px 0 2px;
  display: flex;
  align-items: stretch;
}
.card-note:empty {
  visibility: hidden;
}

.estimate-note {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,180,84,.1);
  border: 1px solid rgba(255,180,84,.28);
  color: #ffd29a;
  font-size: 11.5px;
  line-height: 1.65;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.route {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 6px;
  min-height: 64px;
}
.endpoint { flex: 1; text-align: center; min-width: 0; }
.endpoint .iata { font-size: 26px; font-weight: 800; direction: ltr; line-height: 1.1; }
.endpoint .city {
  color: var(--muted);
  font-size: 12px;
  margin-top: 4px;
  min-height: 32px;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.path { flex: 1.2; display: flex; align-items: center; color: var(--accent); min-width: 48px; }
.path .line { flex: 1; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent); }
.path .plane { font-size: 18px; transform: scaleX(-1); flex-shrink: 0; }

.times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
}
.time-box {
  background: rgba(0,0,0,.22);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 11px 12px;
  min-height: 88px;
  display: flex;
  flex-direction: column;
}
.time-box .label { font-size: 11px; color: var(--muted); min-height: 16px; }
.time-box .clock { font-size: 21px; font-weight: 800; margin-top: 4px; direction: ltr; line-height: 1.1; }
.time-box .sched {
  font-size: 11px;
  color: var(--muted);
  margin-top: auto;
  padding-top: 4px;
  min-height: 16px;
  direction: ltr;
}
.time-box .sched.is-empty { visibility: hidden; }
.time-box .clock.changed { color: var(--amber); }

.delay-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 12.5px;
  font-weight: 700;
  width: 100%;
  min-height: 44px;
  text-align: center;
}
.delay-chip .delay-text { line-height: 1.35; }
.delay-chip.ontime { background: rgba(47,227,155,.14); color: #87ffd2; }
.delay-chip.delay  { background: rgba(255,93,115,.14); color: #ffb0bb; }
.delay-chip.early  { background: rgba(47,227,155,.14); color: #87ffd2; }
.delay-chip.unknown{ background: rgba(255,255,255,.06); color: var(--muted); }

.card-avg {
  margin-top: 12px;
  flex: 1 1 auto;
  min-height: 132px;
}
.avg-panel {
  height: 100%;
  min-height: 132px;
  padding: 12px;
  border-radius: 12px;
  background: rgba(91, 140, 255, 0.08);
  border: 1px dashed rgba(91, 140, 255, 0.35);
  display: flex;
  flex-direction: column;
}
.avg-panel-placeholder {
  visibility: hidden;
  border-color: transparent;
  background: transparent;
}
.avg-title {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 8px;
  min-height: 32px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.avg-times {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  flex: 1;
}
.avg-box {
  background: rgba(0,0,0,.22);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-height: 78px;
  display: flex;
  flex-direction: column;
}
.avg-box .label {
  font-size: 10.5px;
  color: var(--muted);
  min-height: 28px;
  line-height: 1.35;
}
.avg-box .clock {
  font-size: 18px;
  font-weight: 800;
  margin-top: 4px;
  direction: ltr;
  color: #aac3ff;
  line-height: 1.1;
}
.avg-box .sched {
  font-size: 10.5px;
  color: var(--muted);
  margin-top: auto;
  padding-top: 4px;
  min-height: 16px;
  line-height: 1.35;
}

.fr24-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 11px;
  direction: ltr;
  display: inline-block;
  white-space: nowrap;
}
.fr24-link:hover { text-decoration: underline; }

.card-foot {
  margin-top: 12px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 8px;
  min-height: 34px;
}
.card-foot-left { flex: 1; min-width: 0; line-height: 1.4; }
.card-foot-right { flex-shrink: 0; text-align: left; }
.card-foot .err { color: var(--red); flex: 1; line-height: 1.4; }

.history .card { opacity: .85; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed; bottom: 20px; left: 20px; z-index: 50;
  display: flex; flex-direction: column; gap: 10px; max-width: 360px;
}
.toast {
  background: var(--bg-2); border: 1px solid var(--border);
  border-right: 4px solid var(--accent);
  border-radius: 12px; padding: 13px 16px; box-shadow: var(--shadow);
  font-size: 13.5px; line-height: 1.6; animation: slideIn .3s ease;
}
.toast.delay { border-right-color: var(--red); }
.toast.early { border-right-color: var(--green); }
.toast.arrived { border-right-color: var(--accent-2); }
.toast.departed { border-right-color: var(--amber); }
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } }

.demo-banner {
  margin: 4px clamp(16px, 4vw, 48px) 0;
  background: rgba(255,180,84,.12); border: 1px solid rgba(255,180,84,.35);
  color: #ffd29a; padding: 11px 16px; border-radius: 12px; font-size: 13px; line-height: 1.8;
}
.hidden { display: none; }

.footer { text-align: center; color: var(--muted); font-size: 12px; margin-top: 36px; }

/* ---------- live map ---------- */
.map-wrap { margin-bottom: 8px; }
.map-head { margin-bottom: 12px; }
.map-hint { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.live-map {
  height: 380px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  box-shadow: var(--shadow);
  background: #0a1228;
}
.map-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
.map-link-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  text-decoration: none;
  min-width: 160px;
  transition: background .2s, transform .12s;
}
.map-link-card:hover { background: rgba(255,255,255,.1); transform: translateY(-1px); }
.map-link-no { font-weight: 800; direction: ltr; }
.map-link-route { font-size: 12px; color: var(--muted); direction: ltr; }
.map-link-cta { font-size: 11px; color: var(--accent); margin-top: 4px; }

.plane-marker { background: transparent; border: none; }
.plane-icon {
  display: block;
  font-size: 22px;
  filter: drop-shadow(0 2px 4px rgba(0,0,0,.6));
  transform: scaleX(-1);
}
.leaflet-popup-content { font-family: "Vazirmatn", sans-serif; font-size: 13px; line-height: 1.7; }
.leaflet-popup-content a { color: var(--accent); }
