:root {
  --bg: #061015;
  --panel: #0b1920;
  --panel-2: #10242c;
  --panel-3: #07161c;
  --line: #1d3b46;
  --line-soft: rgba(29, 59, 70, .68);
  --text: #e8f4f7;
  --muted: #86a5af;
  --cyan: #48d7e8;
  --green: #62e39b;
  --amber: #ffc568;
  --red: #ff7881;
  --shadow: 0 18px 48px rgba(0, 0, 0, .28);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: dark; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 15% -10%, rgba(72, 215, 232, .13), transparent 32%),
    radial-gradient(circle at 100% 0%, rgba(98, 227, 155, .07), transparent 28%),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.app-shell { max-width: 1760px; margin: 0 auto; padding: 18px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 14px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-weight: 900;
  letter-spacing: -.08em;
  color: var(--cyan);
  border: 1px solid rgba(72, 215, 232, .45);
  background: linear-gradient(145deg, rgba(72, 215, 232, .23), rgba(72, 215, 232, .04));
  box-shadow: inset 0 0 22px rgba(72, 215, 232, .08);
}
.brand h1 { margin: 0; font-size: 19px; }
.brand p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }

.badge {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(16, 36, 44, .72);
  font-size: 11px;
  white-space: nowrap;
}
.badge-ok { color: var(--green); border-color: rgba(98, 227, 155, .35); }
.badge-warn { color: var(--amber); border-color: rgba(255, 197, 104, .35); }
.badge-error { color: var(--red); border-color: rgba(255, 120, 129, .35); }

.tabs {
  display: flex;
  gap: 7px;
  overflow-x: auto;
  padding: 7px;
  margin-bottom: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(9, 24, 30, .78);
}
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 750;
  white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active {
  color: var(--cyan);
  border-color: rgba(72, 215, 232, .28);
  background: rgba(72, 215, 232, .08);
}
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

.planner-grid {
  display: grid;
  grid-template-columns: minmax(310px, 370px) minmax(480px, 1fr) minmax(310px, 390px);
  gap: 14px;
}
.content-grid { display: grid; gap: 14px; }
.content-grid-2 { grid-template-columns: minmax(360px, .9fr) minmax(360px, 1.1fr); }

.panel {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(180deg, rgba(16, 36, 44, .96), rgba(9, 25, 32, .97));
  box-shadow: var(--shadow);
}
.panel-heading {
  min-height: 67px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
}
.panel-heading h2 { margin: 3px 0 0; font-size: 16px; }
.eyebrow { color: var(--cyan); font-size: 10px; font-weight: 850; letter-spacing: .13em; }
.panel-content { padding: 14px; }
.form-stack { display: grid; gap: 15px; }
.form-section { display: grid; gap: 10px; }
.form-section + .form-section { padding-top: 14px; border-top: 1px solid var(--line-soft); }
.form-section h3, .dispatch-content h3 {
  margin: 0;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .1em;
}

.field-grid { display: grid; gap: 10px; }
.field-grid-2 { grid-template-columns: 1fr 1fr; }
.field { display: grid; gap: 5px; color: var(--muted); font-size: 11px; }
.field input, .field select, .field textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 11px;
  border: 1px solid var(--line);
  border-radius: 11px;
  outline: none;
  resize: vertical;
  color: var(--text);
  background: var(--panel-3);
  transition: border-color .2s, box-shadow .2s;
}
.field textarea { line-height: 1.45; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(72, 215, 232, .1);
}
.field input[type="range"] { padding: 0; accent-color: var(--cyan); }
.range-label { display: flex; align-items: center; justify-content: space-between; }
.range-label strong { color: var(--text); }
.upload-field input { padding: 10px; border-style: dashed; }

.button-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.button-grid-2 { grid-template-columns: 1fr 1fr; }
.button {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--text);
  background: #102730;
  font-weight: 800;
}
.button:hover { filter: brightness(1.12); }
.button:disabled { cursor: not-allowed; opacity: .5; filter: none; }
.button-primary {
  border: 0;
  color: #041114;
  background: linear-gradient(135deg, #25b7c8, #3dd69d);
}
.button-accent { color: var(--cyan); border-color: rgba(72, 215, 232, .4); }
.button-small { padding: 7px 10px; font-size: 11px; }
.link-button {
  border: 0;
  background: transparent;
  color: var(--cyan);
  padding: 0;
  font-size: 11px;
}
.icon-button {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-3);
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}
.notice {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid rgba(255, 197, 104, .3);
  border-radius: 11px;
  color: #e8cf9f;
  background: rgba(255, 197, 104, .06);
  font-size: 11px;
  line-height: 1.5;
}
.muted-text { margin: 0; color: var(--muted); font-size: 12px; }

.route-map {
  min-height: 550px;
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(rgba(72, 215, 232, .045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(72, 215, 232, .045) 1px, transparent 1px),
    radial-gradient(circle at 50% 50%, #112a33, #071218 72%);
  background-size: 34px 34px, 34px 34px, auto;
}
.route-map::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(circle at 50% 50%, transparent 44%, rgba(0, 0, 0, .34));
}
#mapSvg { width: 100%; height: 550px; display: block; position: relative; z-index: 1; }
.map-overlay {
  position: absolute;
  top: 14px;
  z-index: 3;
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(5, 17, 22, .86);
  backdrop-filter: blur(10px);
}
.map-overlay span { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .1em; }
.map-overlay strong { font-size: 12px; }
.map-overlay-left { left: 14px; }
.map-overlay-right { right: 14px; text-align: right; }
.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--line); }
.summary-grid article { padding: 13px 14px; border-right: 1px solid var(--line); }
.summary-grid article:last-child { border-right: 0; }
.summary-grid span { display: block; color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .1em; }
.summary-grid strong { display: block; margin-top: 4px; font-size: 18px; }
.route-string-block { border-top: 1px solid var(--line); }
.route-string-title { display: flex; justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 10px; text-transform: uppercase; letter-spacing: .1em; }
.route-string-block code { display: block; color: #d4f0f5; line-height: 1.5; font-size: 12px; word-break: break-word; }

.dispatch-content { display: grid; gap: 15px; }
.dispatch-content section { display: grid; gap: 9px; }
.dispatch-content section + section { padding-top: 14px; border-top: 1px solid var(--line-soft); }
.metrics, .checks { display: grid; gap: 7px; }
.metrics > div, .checks > div {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 10px;
  border: 1px solid rgba(29, 59, 70, .72);
  border-radius: 10px;
  background: rgba(6, 20, 25, .72);
}
.metrics span, .checks span { color: var(--muted); font-size: 11px; }
.metrics strong, .checks strong { font-size: 12px; font-variant-numeric: tabular-nums; }
.metrics .metric-total { border-color: rgba(72, 215, 232, .42); background: rgba(72, 215, 232, .07); }
.metrics .metric-total strong { color: var(--cyan); font-size: 14px; }
.limit-block { display: grid; gap: 5px; }
.limit-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 10px; }
.progress { height: 8px; overflow: hidden; border: 1px solid var(--line); border-radius: 999px; background: #071218; }
.progress > div { width: 0; height: 100%; background: linear-gradient(90deg, var(--green), var(--cyan)); transition: width .3s; }
.progress > div.is-warn { background: linear-gradient(90deg, var(--amber), var(--red)); }
.weather-card {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(7, 22, 28, .7);
}
.weather-card-heading { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 7px; }
.weather-card-heading strong { font-size: 12px; }
.weather-card-heading span { color: var(--muted); font-size: 10px; }
.weather-raw, .weather-taf {
  margin: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 10px;
  line-height: 1.5;
  word-break: break-word;
}
.weather-raw { color: #d4f0f5; }
.weather-taf { margin-top: 6px; color: var(--muted); }

.cost-summary { display: grid; gap: 9px; }
.cost-summary > div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(6, 20, 25, .72);
}
.cost-summary span { color: var(--muted); }
.cost-total { border-color: rgba(72, 215, 232, .4) !important; }
.cost-total strong { color: var(--cyan); }
.cost-profit { border-color: rgba(98, 227, 155, .38) !important; }
.cost-profit strong { color: var(--green); }
.cost-profit.is-negative { border-color: rgba(255, 120, 129, .4) !important; }
.cost-profit.is-negative strong { color: var(--red); }

.airac-stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.airac-stat-grid article {
  padding: 14px 9px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: rgba(6, 20, 25, .72);
}
.airac-stat-grid strong { display: block; font-size: 17px; }
.airac-stat-grid span { display: block; margin-top: 4px; color: var(--muted); font-size: 9px; text-transform: uppercase; }
.airac-log {
  min-height: 120px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  background: var(--panel-3);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
}
.prose { color: #c7dce1; line-height: 1.65; }
.prose p:first-child { margin-top: 0; }
.prose code { color: var(--cyan); }

.empty-state {
  padding: 28px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
}
.saved-plans { display: grid; gap: 9px; }
.saved-plan {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(6, 20, 25, .72);
}
.saved-plan h3 { margin: 0 0 5px; font-size: 14px; }
.saved-plan p { margin: 0; color: var(--muted); font-size: 11px; }
.saved-plan-actions { display: flex; gap: 7px; }

.modal {
  width: min(520px, calc(100% - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: var(--panel);
  box-shadow: var(--shadow);
}
.modal::backdrop { background: rgba(0, 0, 0, .64); backdrop-filter: blur(5px); }
.modal-card { margin: 0; }
.modal-heading { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.modal-heading h2 { margin: 3px 0 0; font-size: 16px; }
.modal-content { padding: 16px; }
.connection-box { padding: 11px; border: 1px solid var(--line); border-radius: 11px; color: var(--muted); background: var(--panel-3); font-size: 12px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 30;
  max-width: min(380px, calc(100% - 40px));
  padding: 12px 14px;
  border: 1px solid rgba(72, 215, 232, .35);
  border-radius: 12px;
  color: var(--text);
  background: #0b1e25;
  box-shadow: var(--shadow);
  transform: translateY(90px);
  opacity: 0;
  transition: .25s;
  font-size: 12px;
  line-height: 1.45;
}
.toast.is-visible { transform: translateY(0); opacity: 1; }

@media (max-width: 1220px) {
  .planner-grid { grid-template-columns: 340px 1fr; }
  .dispatch-panel { grid-column: 1 / -1; }
  .dispatch-content { grid-template-columns: repeat(4, 1fr); align-items: start; }
  .dispatch-content section + section { padding-top: 0; padding-left: 13px; border-top: 0; border-left: 1px solid var(--line-soft); }
}

@media (max-width: 900px) {
  .content-grid-2 { grid-template-columns: 1fr; }
  .dispatch-content { grid-template-columns: 1fr 1fr; }
  .dispatch-content section:nth-child(3) { border-left: 0; padding-left: 0; }
  .dispatch-content section:nth-child(n+3) { padding-top: 13px; border-top: 1px solid var(--line-soft); }
}

@media (max-width: 760px) {
  .app-shell { padding: 10px; }
  .topbar { align-items: flex-start; }
  .top-actions .badge { display: none; }
  .planner-grid { grid-template-columns: 1fr; }
  .dispatch-panel { grid-column: auto; }
  .route-map, #mapSvg { min-height: 390px; height: 390px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-grid article:nth-child(2) { border-right: 0; }
  .summary-grid article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .dispatch-content { grid-template-columns: 1fr; }
  .dispatch-content section + section,
  .dispatch-content section:nth-child(3) {
    padding: 13px 0 0;
    border-left: 0;
    border-top: 1px solid var(--line-soft);
  }
  .airac-stat-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 470px) {
  .field-grid-2, .button-grid, .button-grid-2 { grid-template-columns: 1fr; }
  .brand p { display: none; }
  .saved-plan { grid-template-columns: 1fr; }
  .saved-plan-actions { justify-content: stretch; }
  .saved-plan-actions .button { flex: 1; }
}
