:root {
  color-scheme: dark;
  --bg: #070b14;
  --bg-elevated: #0b1220;
  --surface: #101a2b;
  --surface-2: #142238;
  --surface-3: #182a44;
  --ink: #f5f7fb;
  --ink-soft: #d7e2f2;
  --muted: #8fa2bb;
  --muted-2: #6f829b;
  --line: #253a56;
  --line-strong: #385578;
  --primary: #4f8cff;
  --primary-dark: #2f6fe8;
  --primary-soft: rgba(79, 140, 255, .13);
  --accent: #ff8a3d;
  --accent-soft: rgba(255, 138, 61, .13);
  --green: #42d6a0;
  --green-bg: rgba(66, 214, 160, .12);
  --amber: #ffd166;
  --amber-bg: rgba(255, 209, 102, .12);
  --red: #ff6b81;
  --red-bg: rgba(255, 107, 129, .13);
  --shadow: 0 18px 44px rgba(0, 0, 0, .28);
  --shadow-hover: 0 20px 48px rgba(24, 92, 190, .25);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-width: 320px; color: var(--ink); background: radial-gradient(circle at 10% -10%, rgba(79, 140, 255, .16), transparent 35%), var(--bg); line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; }
button { min-height: 44px; cursor: pointer; touch-action: manipulation; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid rgba(79, 140, 255, .38); outline-offset: 2px; }

.shell { width: min(1120px, 100%); margin: 0 auto; padding: 24px 20px 72px; }
.topbar, .section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.topbar { position: relative; margin-bottom: 32px; padding: 28px 30px; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 18px; background: linear-gradient(135deg, rgba(20, 34, 56, .98), rgba(11, 18, 32, .96)); box-shadow: var(--shadow); animation: pageEnter .42s ease both; }
.topbar::before { content: ""; position: absolute; left: -80px; bottom: -120px; width: 260px; height: 260px; border: 1px solid rgba(79, 140, 255, .25); border-radius: 50%; box-shadow: 0 0 0 28px rgba(79, 140, 255, .04), 0 0 0 56px rgba(79, 140, 255, .025); pointer-events: none; }
.topbar::after { content: ""; position: absolute; right: -90px; top: -150px; width: 280px; height: 280px; border-radius: 50%; background: radial-gradient(circle, rgba(255, 138, 61, .16), transparent 66%); pointer-events: none; }
.topbar > * { position: relative; z-index: 1; }
.eyebrow { margin: 0 0 10px; color: var(--primary); font-size: 11px; letter-spacing: .16em; font-weight: 800; }
h1, h2, h3, p { margin-top: 0; }
h1 { max-width: 720px; margin-bottom: 10px; color: #fff; font-size: clamp(32px, 5vw, 52px); line-height: 1.1; letter-spacing: -.045em; }
h2 { margin-bottom: 8px; color: #fff; font-size: clamp(24px, 3vw, 30px); line-height: 1.2; letter-spacing: -.03em; }
h3 { margin-bottom: 5px; color: var(--ink); font-size: 18px; line-height: 1.3; }
.muted { color: var(--muted); line-height: 1.65; }
.header-actions, .form-actions, .card-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.header-actions { position: relative; z-index: 2; }

button { border-radius: 12px; padding: 10px 16px; color: var(--ink); font-weight: 750; transition: background-color .2s ease, border-color .2s ease, box-shadow .2s ease, color .2s ease, transform .2s cubic-bezier(.2, .8, .2, 1); }
button:hover { transform: translateY(-2px); }
button:active { transform: translateY(0) scale(.98); }
button.primary { color: #fff; background: linear-gradient(135deg, var(--primary), #6da3ff); border: 1px solid #79adff; box-shadow: 0 8px 22px rgba(79, 140, 255, .28); }
button.primary:hover { background: linear-gradient(135deg, var(--primary-dark), var(--primary)); box-shadow: 0 12px 28px rgba(79, 140, 255, .4); }
button.secondary { color: var(--ink-soft); background: var(--surface-2); border: 1px solid var(--line-strong); box-shadow: 0 2px 0 rgba(255, 255, 255, .03) inset; }
button.secondary:hover { color: #fff; background: var(--surface-3); border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 140, 255, .1); }
button.danger { color: var(--red); background: var(--red-bg); border: 1px solid rgba(255, 107, 129, .35); }
button.danger:hover { background: rgba(255, 107, 129, .2); border-color: var(--red); }
.badge, .status-pill, .optional { display: inline-flex; align-items: center; border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 750; white-space: nowrap; }
.badge { color: #c6dcff; background: rgba(79, 140, 255, .14); border: 1px solid rgba(79, 140, 255, .36); }
.badge-muted { color: var(--muted); background: rgba(143, 162, 187, .1); border-color: var(--line); }
.badge-success { color: var(--green); background: var(--green-bg); border-color: rgba(66, 214, 160, .38); }

.view { animation: pageEnter .32s ease both; }
.hidden { display: none !important; }
@keyframes pageEnter { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes cardEnter { from { opacity: 0; transform: translateY(12px) scale(.985); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastEnter { from { opacity: 0; transform: translateY(12px) scale(.96); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes alertPulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(255, 107, 129, 0); } 45% { box-shadow: 0 0 0 5px rgba(255, 107, 129, .08); } }

.section-heading { margin-bottom: 18px; }
.section-heading.compact { align-items: center; margin-bottom: 14px; }
.section-heading.compact > div { min-width: 0; }

.plan-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(290px, 1fr)); gap: 16px; }
.card, .plan-card, .empty-state { background: linear-gradient(145deg, rgba(16, 26, 43, .98), rgba(11, 18, 32, .98)); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.plan-card { position: relative; padding: 22px; overflow: hidden; transition: transform .24s cubic-bezier(.2, .8, .2, 1), box-shadow .24s ease, border-color .24s ease; animation: cardEnter .42s ease both; }
.plan-card:nth-child(2) { animation-delay: .06s; }
.plan-card:nth-child(3) { animation-delay: .12s; }
.plan-card:nth-child(4) { animation-delay: .18s; }
.plan-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(var(--primary), var(--accent)); }
.plan-card::after { content: ""; position: absolute; right: -50px; top: -50px; width: 120px; height: 120px; border: 1px solid rgba(79, 140, 255, .14); border-radius: 50%; transition: transform .35s ease, border-color .35s ease; }
.plan-card:hover { transform: translateY(-5px); border-color: #4b6b92; box-shadow: var(--shadow-hover); }
.plan-card:hover::after { transform: scale(1.3); border-color: rgba(255, 138, 61, .32); }
.plan-card h3 { margin-bottom: 10px; }
.plan-card .route { margin-bottom: 14px; color: var(--ink-soft); font-size: 16px; font-weight: 800; }
.plan-meta { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 18px; color: var(--muted); font-size: 13px; }
.card-actions { gap: 8px; }
.empty-state { margin-top: 18px; padding: 72px 20px; text-align: center; border-style: dashed; box-shadow: none; }
.empty-icon { width: 56px; height: 56px; display: grid; place-items: center; margin: 0 auto 14px; color: var(--primary); background: var(--primary-soft); border: 1px solid rgba(79, 140, 255, .35); border-radius: 16px; font-size: 32px; }

.form-card, .config-card { max-width: 820px; padding: 28px; }
.real-route-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.real-route-fields label { margin-bottom: 0; }
label { display: grid; gap: 8px; margin-bottom: 18px; color: var(--ink-soft); font-weight: 750; }
.optional { margin-left: 5px; padding: 3px 7px; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line); font-size: 11px; vertical-align: middle; }
input, select { width: 100%; min-height: 46px; border: 1px solid var(--line-strong); border-radius: 11px; background: #0c1626; padding: 11px 13px; color: var(--ink); outline: none; transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease, transform .2s ease; }
input:hover, select:hover { border-color: #5d83af; background: #0e1b2d; }
input:focus, select:focus { border-color: var(--primary); background: #0e1c31; box-shadow: 0 0 0 4px rgba(79, 140, 255, .13), 0 0 20px rgba(79, 140, 255, .08); transform: translateY(-1px); }
input::placeholder { color: #657994; }
.form-hint { margin-bottom: 24px; padding: 12px 14px; color: var(--ink-soft); background: var(--surface-2); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 11px; font-size: 13px; }
.form-actions { justify-content: flex-end; margin-top: 18px; padding-top: 20px; border-top: 1px solid var(--line); }
.back-link { min-height: 36px; margin-bottom: 12px; padding: 4px 0; color: var(--primary); background: transparent; }
.back-link:hover { color: #94bcff; transform: translateX(-3px); }

.route-controls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.route-controls label { margin: 0; }
.route-strip { display: flex; align-items: center; gap: 0; flex-wrap: wrap; margin-bottom: 22px; padding: 20px 0 26px; border-bottom: 1px solid var(--line); }
.route-node { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 14px; transition: color .22s ease, text-shadow .22s ease; }
.route-node.active { color: var(--primary); font-weight: 800; text-shadow: 0 0 14px rgba(79, 140, 255, .45); }
.route-node::after { content: "→"; padding: 0 10px; color: var(--muted-2); }
.route-node:last-child::after { content: ""; }
.segment-editor { display: grid; gap: 10px; margin-bottom: 16px; }
.segment-row { display: grid; grid-template-columns: 28px minmax(0, 1fr) minmax(260px, 1.5fr) 90px; align-items: center; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: rgba(12, 22, 38, .7); transition: transform .22s ease, border-color .22s ease, background-color .22s ease, box-shadow .22s ease; }
.segment-row:hover { transform: translateX(4px); border-color: #52749e; background: var(--surface-2); box-shadow: -4px 0 0 rgba(79, 140, 255, .24); }
.segment-row label { display: flex; align-items: center; gap: 9px; margin: 0; font-weight: 650; }
.segment-row input[type="number"], .segment-row select { min-height: 40px; padding: 8px 10px; }
.segment-row .checkbox { width: 20px; min-height: 20px; height: 20px; accent-color: var(--primary); }
.segment-row .threshold-label { color: var(--muted); font-size: 13px; }
.segment-threshold-control { display: flex; align-items: center; gap: 8px; min-width: 0; }
.segment-threshold-control select { flex: 1 1 auto; min-width: 0; }
.segment-threshold-control input[type="number"] { flex: 0 0 88px; width: 88px; }
.segment-notify { white-space: nowrap; }

.summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 18px 0; }
.summary-item { padding: 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 13px; box-shadow: var(--shadow); transition: transform .22s ease, border-color .22s ease; }
.summary-item:hover { transform: translateY(-3px); border-color: var(--line-strong); }
.summary-item .label { margin-bottom: 8px; color: var(--muted); font-size: 12px; }
.summary-item .value { color: #fff; font-size: 18px; font-weight: 800; }
/* Detail cards need their own breathing room: the card border should not sit against the data rows. */
#detailView > .card { padding: 22px 24px 24px; }
.detail-segments { display: grid; gap: 10px; padding: 2px 4px 0; }
.detail-row { display: grid; grid-template-columns: minmax(180px, 1.25fr) minmax(105px, .72fr) minmax(105px, .72fr) minmax(125px, .85fr) minmax(160px, 1fr); align-items: center; gap: 14px; padding: 14px 12px; border: 1px solid transparent; border-bottom-color: var(--line); border-radius: 12px; transition: background-color .2s ease, border-color .2s ease, transform .2s ease; }
.detail-row:hover { border-color: var(--line-strong); background: rgba(79, 140, 255, .07); transform: translateX(2px); }
.detail-row:last-child { border-bottom-color: transparent; }
.detail-row .destination { min-width: 0; color: #fff; font-weight: 800; }
.detail-row .destination small { display: block; margin-top: 4px; overflow: hidden; color: var(--muted); font-weight: 500; text-overflow: ellipsis; white-space: nowrap; }
.detail-field { display: grid; align-content: center; gap: 4px; min-width: 0; }
.detail-label { color: var(--muted-2); font-size: 11px; font-weight: 750; letter-spacing: .04em; white-space: nowrap; }
.detail-value { display: block; overflow: hidden; color: var(--ink-soft); font-size: 13px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.count { overflow: hidden; color: #fff; font-size: 20px; font-weight: 800; text-overflow: ellipsis; white-space: nowrap; }
.count.unknown { color: var(--amber); font-size: 15px; }
.status-pill.normal { color: var(--green); background: var(--green-bg); border: 1px solid rgba(66, 214, 160, .3); }
.status-pill.alerting { color: var(--red); background: var(--red-bg); border: 1px solid rgba(255, 107, 129, .4); animation: alertPulse 2.4s ease-in-out infinite; }
.status-pill.unknown { color: var(--amber); background: var(--amber-bg); border: 1px solid rgba(255, 209, 102, .34); }
.event-list { display: grid; gap: 10px; padding: 2px 4px 0; }
.event-item { display: flex; justify-content: space-between; gap: 12px; padding: 14px 12px; border: 1px solid transparent; border-bottom-color: var(--line); border-radius: 12px; transition: background-color .2s ease, border-color .2s ease, transform .2s ease; }
.event-item:hover { border-color: var(--line-strong); background: rgba(79, 140, 255, .07); transform: translateX(2px); }
.event-item:last-child { border-bottom-color: transparent; }
.event-item .event-main { display: grid; gap: 4px; min-width: 0; }
.event-item .event-title { color: var(--ink-soft); font-weight: 700; }
.event-item .event-time { color: var(--muted); font-size: 12px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: min(360px, calc(100vw - 32px)); padding: 14px 16px; color: #fff; background: #172a45; border: 1px solid #46678f; border-radius: 12px; box-shadow: 0 16px 34px rgba(0, 0, 0, .42); animation: toastEnter .28s ease both; }

@media (max-width: 820px) {
  .topbar { padding: 24px; }
  .route-controls, .summary-grid { grid-template-columns: 1fr 1fr; }
  .segment-row { grid-template-columns: 28px minmax(0, 1fr); }
  .segment-threshold-control, .segment-row .segment-notify { grid-column: 2; }
  .detail-row { grid-template-columns: minmax(150px, 1.2fr) repeat(2, minmax(105px, .8fr)); gap: 12px 14px; }
  .detail-row .destination { grid-column: 1; grid-row: 1 / span 2; }
  .detail-row > .detail-field:nth-child(2) { grid-column: 2; grid-row: 1; }
  .detail-row > .detail-field:nth-child(3) { grid-column: 3; grid-row: 1; }
  .detail-row > .detail-field:nth-child(4) { grid-column: 2; grid-row: 2; }
  .detail-row > .detail-field:nth-child(5) { grid-column: 3; grid-row: 2; }
}

@media (max-width: 560px) {
  .shell { padding: 14px 14px 48px; }
  .topbar, .section-heading { flex-direction: column; }
  .topbar { gap: 18px; margin-bottom: 26px; padding: 22px 18px; border-radius: 16px; }
  .topbar .header-actions { width: 100%; justify-content: space-between; }
  .topbar .header-actions button { flex: 1; }
  .topbar .header-actions .badge { font-size: 11px; }
  .section-heading { gap: 12px; }
  .section-heading .header-actions { width: 100%; }
  .section-heading .header-actions button { flex: 1; }
  .form-card, .config-card, #detailView > .card { padding: 20px 16px; }
  .route-controls, .summary-grid, .real-route-fields { grid-template-columns: 1fr; }
  .route-strip { overflow-x: auto; flex-wrap: nowrap; padding-bottom: 20px; scrollbar-width: thin; }
  .route-node { flex: 0 0 auto; }
  .form-actions { justify-content: stretch; }
  .form-actions button { flex: 1; }
  .card-actions button { flex: 1; }
  .detail-row { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .detail-row .destination { grid-column: 1 / -1; grid-row: auto; padding-bottom: 2px; }
  .detail-row > .detail-field:nth-child(n) { grid-column: auto; grid-row: auto; }
  .event-item { align-items: flex-start; flex-direction: column; }
  .toast { right: 16px; bottom: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
