/* ==========================================================================
   THAILAND ROUTE INTELLIGENCE — Dark Navigation / Digital Command Center
   ========================================================================== */
:root {
  --bg: #080B14;
  --panel: #111525;
  --panel-2: #141A2D;
  --navy: #17213A;
  --navy-2: #1E2A48;
  --line: rgba(164, 92, 255, 0.16);
  --line-2: rgba(255, 255, 255, 0.07);
  --purple: #A45CFF;
  --purple-2: #C9A2FF;
  --gold: #F2C94C;
  --green: #35D6A0;
  --red: #EF526F;
  --text: #E8ECF7;
  --muted: #8C96B3;
  --radius: 14px;
  --sidebar-w: 384px;
  --font: 'Prompt', 'Anuphan', 'Sukhumvit Set', 'Noto Sans Thai', system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); background: var(--bg); color: var(--text);
  font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
a { color: var(--purple-2); }
code, kbd { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: rgba(255,255,255,.06); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

#app { display: flex; height: 100vh; height: 100dvh; }

/* ============================== Sidebar ============================== */
#sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w); height: 100%;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #0E1222 0%, var(--panel) 100%);
  border-right: 1px solid var(--line);
  box-shadow: 8px 0 40px rgba(0,0,0,.45);
  position: relative; z-index: 1000;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 18px 18px 10px; }
.brand-logo {
  width: 46px; height: 46px; border-radius: 13px; flex: none;
  background: radial-gradient(circle at 30% 25%, #2A1B4D, #0B0F1E 70%);
  border: 1px solid rgba(164,92,255,.45);
  box-shadow: 0 0 22px rgba(164,92,255,.35), inset 0 0 12px rgba(164,92,255,.25);
  display: grid; place-items: center;
}
.brand-logo svg { width: 26px; height: 26px; filter: drop-shadow(0 0 6px rgba(164,92,255,.8)); }
.brand h1 {
  margin: 0; font-size: 15.5px; font-weight: 700; letter-spacing: .06em;
  background: linear-gradient(90deg, #FFFFFF, var(--purple-2) 60%, var(--gold));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.brand p { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.status-row { display: flex; gap: 6px; padding: 0 18px 12px; border-bottom: 1px solid var(--line-2); }
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted);
  padding: 3px 10px; border-radius: 999px; background: rgba(255,255,255,.04); border: 1px solid var(--line-2);
}
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #5B6584; }
.status-pill[data-state="ok"] i { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-pill[data-state="busy"] i { background: var(--gold); box-shadow: 0 0 8px var(--gold); animation: blink 1s infinite; }
.status-pill[data-state="error"] i { background: var(--red); box-shadow: 0 0 8px var(--red); }
.status-pill[data-state="error"] { color: #FFB3C1; border-color: rgba(239,82,111,.35); }
@keyframes blink { 50% { opacity: .35; } }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 12px 12px 24px; scrollbar-width: thin; scrollbar-color: #2A3456 transparent; }
.sidebar-scroll::-webkit-scrollbar { width: 8px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: #2A3456; border-radius: 8px; }

.card {
  background: linear-gradient(180deg, rgba(23,33,58,.72), rgba(17,21,37,.9));
  border: 1px solid var(--line-2); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 6px 20px rgba(0,0,0,.25), inset 0 1px 0 rgba(255,255,255,.03);
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card h2 { margin: 0; font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.card h2 .num {
  width: 22px; height: 22px; border-radius: 7px; display: grid; place-items: center; font-size: 12px; font-weight: 700;
  background: rgba(164,92,255,.18); color: var(--purple-2); border: 1px solid rgba(164,92,255,.35);
}
h3.sub { font-size: 13px; font-weight: 600; margin: 14px 0 8px; color: #CBD3EA; }

/* segmented */
.seg { display: inline-flex; background: rgba(0,0,0,.25); border: 1px solid var(--line-2); border-radius: 10px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 3px 9px; border-radius: 8px; font-size: 15px; filter: grayscale(.8); opacity: .7; }
.seg button[aria-checked="true"] { background: var(--navy-2); filter: none; opacity: 1; box-shadow: 0 0 0 1px rgba(164,92,255,.45); }

/* buttons */
.btn {
  border: 1px solid var(--line-2); background: rgba(255,255,255,.04); border-radius: 10px;
  padding: 7px 12px; font-size: 13px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .15s, border-color .15s, transform .1s;
}
.btn:hover:not(:disabled) { background: rgba(164,92,255,.12); border-color: rgba(164,92,255,.4); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, #8B3DFF, var(--purple)); border-color: transparent; color: #fff; font-weight: 600; box-shadow: 0 4px 16px rgba(164,92,255,.35); }
.btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, #9A55FF, #B37BFF); }
.btn-danger-ghost:hover:not(:disabled) { background: rgba(239,82,111,.12); border-color: rgba(239,82,111,.45); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-row .btn { flex: 1; }
.btn-row.center { justify-content: center; }
.btn-row.center .btn { flex: none; }
.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.hint { font-size: 12px; color: var(--muted); margin: 10px 0 0; line-height: 1.6; }

/* ---------------- waypoint rows ---------------- */
.wp-list { display: flex; flex-direction: column; gap: 6px; }
.wp-row { display: grid; grid-template-columns: 28px 1fr auto; gap: 8px; align-items: start; position: relative; }
.wp-line { position: absolute; left: 13px; top: 30px; bottom: -12px; width: 2px; background: repeating-linear-gradient(to bottom, rgba(164,92,255,.45) 0 4px, transparent 4px 8px); }
.wp-end .wp-line { display: none; }
.wp-badge {
  width: 28px; height: 28px; margin-top: 5px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 12.5px; color: #0B0F1C; position: relative; z-index: 1;
}
.wp-start .wp-badge { background: var(--green); box-shadow: 0 0 12px rgba(53,214,160,.55); }
.wp-end .wp-badge { background: var(--red); box-shadow: 0 0 12px rgba(239,82,111,.55); color: #fff; }
.wp-via .wp-badge { background: var(--gold); box-shadow: 0 0 12px rgba(242,201,76,.5); }
.wp-input-wrap { position: relative; display: flex; align-items: center; }
.wp-input {
  width: 100%; padding: 9px 58px 9px 12px; border-radius: 10px;
  background: rgba(5,8,16,.65); border: 1px solid var(--line-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
.wp-input::placeholder { color: #66708E; }
.wp-input:focus { border-color: rgba(164,92,255,.6); box-shadow: 0 0 0 3px rgba(164,92,255,.15); }
.wp-input-wrap .wp-btn { position: absolute; }
.wp-input-wrap .wp-clear { right: 4px; }
.wp-input-wrap .wp-locate { right: 30px; }
.wp-btn {
  width: 26px; height: 26px; border-radius: 8px; border: 0; background: transparent; color: var(--muted);
  display: grid; place-items: center; font-size: 14px; line-height: 1;
}
.wp-btn:hover:not(:disabled) { background: rgba(255,255,255,.08); color: #fff; }
.wp-addr { font-size: 11.5px; color: var(--muted); padding: 3px 4px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.wp-order { display: flex; flex-direction: column; margin-top: 2px; }
.wp-order .wp-btn { height: 18px; font-size: 9px; }

/* ---------------- autocomplete ---------------- */
.ac-dropdown {
  position: fixed; z-index: 5000; overflow-y: auto;
  background: #0F1424; border: 1px solid rgba(164,92,255,.35); border-radius: 12px;
  box-shadow: 0 18px 40px rgba(0,0,0,.6), 0 0 0 1px rgba(0,0,0,.4);
}
.ac-item { padding: 9px 12px; cursor: pointer; border-bottom: 1px solid var(--line-2); }
.ac-item:hover, .ac-item.hi { background: rgba(164,92,255,.14); }
.ac-name { font-weight: 500; font-size: 13.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ac-type { font-size: 10.5px; font-weight: 500; color: var(--gold); background: rgba(242,201,76,.1); border: 1px solid rgba(242,201,76,.25); padding: 0 6px; border-radius: 6px; }
.ac-addr { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.ac-state { padding: 12px; color: var(--muted); font-size: 13px; }
.ac-state.err { color: #FFB3C1; }
.ac-foot { padding: 6px 12px; font-size: 11px; color: #6C7695; background: rgba(0,0,0,.2); }

/* ---------------- route cards ---------------- */
.route-list { display: flex; flex-direction: column; gap: 8px; }
.route-card {
  text-align: left; width: 100%; padding: 10px 12px; border-radius: 12px;
  background: rgba(5,8,16,.45); border: 1px solid var(--line-2); transition: all .15s;
}
.route-card:hover { border-color: rgba(164,92,255,.4); }
.route-card.sel { background: linear-gradient(135deg, rgba(164,92,255,.22), rgba(23,33,58,.6)); border-color: rgba(164,92,255,.7); box-shadow: 0 0 18px rgba(164,92,255,.25); }
.rc-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rc-dot { width: 22px; height: 5px; border-radius: 4px; background: #6B7690; }
.route-card.sel .rc-dot { background: var(--purple); box-shadow: 0 0 8px var(--purple); }
.rc-nums { display: flex; gap: 14px; margin-top: 6px; align-items: baseline; }
.rc-dist { font-size: 19px; font-weight: 700; }
.rc-time { font-size: 14px; color: var(--gold); font-weight: 500; }
.rc-via { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 10.5px; padding: 1px 7px; border-radius: 6px; font-weight: 500; }
.tag-green { color: var(--green); background: rgba(53,214,160,.1); border: 1px solid rgba(53,214,160,.3); }
.tag-gold { color: var(--gold); background: rgba(242,201,76,.1); border: 1px solid rgba(242,201,76,.3); }
.note { font-size: 11.5px; color: var(--muted); padding: 2px 4px; }
.empty { color: var(--muted); font-size: 13px; padding: 10px; text-align: center; background: rgba(0,0,0,.15); border-radius: 10px; border: 1px dashed var(--line-2); list-style: none; }
.empty.err { color: #FFB3C1; border-color: rgba(239,82,111,.35); background: rgba(239,82,111,.06); text-align: left; }

/* ---------------- animation ---------------- */
.badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; background: rgba(255,255,255,.06); color: var(--muted); }
.badge[data-state="play"] { background: rgba(53,214,160,.14); color: var(--green); }
.badge[data-state="done"] { background: rgba(242,201,76,.14); color: var(--gold); }
.anim-controls { display: flex; align-items: center; gap: 6px; }
.ctl {
  width: 38px; height: 38px; border-radius: 11px; border: 1px solid var(--line-2); background: rgba(255,255,255,.05);
  display: grid; place-items: center; font-size: 18px; transition: all .15s;
}
.ctl svg { width: 18px; height: 18px; fill: currentColor; }
.ctl:hover:not(:disabled) { background: rgba(164,92,255,.15); border-color: rgba(164,92,255,.45); }
.ctl-main { width: 48px; height: 48px; border-radius: 50%; background: linear-gradient(135deg, #8B3DFF, var(--purple)); border: 0; color: #fff; box-shadow: 0 0 22px rgba(164,92,255,.55); }
.ctl-main svg { width: 22px; height: 22px; }
.ctl-main:hover:not(:disabled) { background: linear-gradient(135deg, #9A55FF, #B37BFF); }
.ctl-sep { flex: 1; }
.speed-val { min-width: 44px; text-align: center; font-weight: 700; color: var(--gold); font-size: 16px; }
.speed-presets { display: flex; gap: 6px; margin-top: 10px; }
.chip { flex: 1; border: 1px solid var(--line-2); background: rgba(255,255,255,.04); border-radius: 8px; padding: 4px 0; font-size: 12.5px; font-weight: 600; }
.chip.on { background: rgba(242,201,76,.15); border-color: rgba(242,201,76,.55); color: var(--gold); }
.timeline { margin-top: 12px; }
.timeline input[type=range] { width: 100%; accent-color: var(--purple); height: 22px; cursor: pointer; }
.timeline input[type=range]:disabled { cursor: not-allowed; opacity: .4; }
.timeline-labels { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--muted); margin-top: -2px; }

.switch { display: flex; align-items: center; gap: 10px; font-size: 13px; margin-top: 8px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .slider { width: 34px; height: 19px; border-radius: 999px; background: #2A3352; position: relative; transition: .2s; flex: none; }
.switch .slider::after { content: ''; position: absolute; left: 2px; top: 2px; width: 15px; height: 15px; border-radius: 50%; background: #9AA3C0; transition: .2s; }
.switch input:checked + .slider { background: rgba(164,92,255,.6); }
.switch input:checked + .slider::after { left: 17px; background: #fff; }

.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 12px; }
.stat { background: rgba(5,8,16,.45); border: 1px solid var(--line-2); border-radius: 10px; padding: 7px 10px; }
.stat label { display: block; font-size: 11px; color: var(--muted); }
.stat b { font-size: 15.5px; font-weight: 600; font-variant-numeric: tabular-nums; }
#s-speed { font-size: 12.5px; }
#s-heading { font-size: 13px; }
.c-purple { color: var(--purple-2); }
.c-gold { color: var(--gold); }
.c-green { color: var(--green); }
.progress-bar { height: 6px; border-radius: 6px; background: rgba(255,255,255,.07); margin-top: 10px; overflow: hidden; }
#progress-fill, #hud-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--purple), var(--purple-2)); box-shadow: 0 0 10px var(--purple); }
.now-road { margin-top: 10px; padding: 8px 10px; border-radius: 10px; background: rgba(164,92,255,.08); border: 1px solid rgba(164,92,255,.22); }
.now-road label { font-size: 11px; color: var(--muted); display: block; }
#s-road { font-weight: 600; font-size: 14px; }

/* ---------------- sequence ---------------- */
.seq-list { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow-y: auto; scrollbar-width: thin; scrollbar-color: #2A3456 transparent; }
.seq-item { display: grid; grid-template-columns: 24px 22px 1fr; gap: 6px; align-items: start; padding: 7px 6px; border-radius: 9px; cursor: pointer; border-left: 2px solid transparent; }
.seq-item:hover { background: rgba(255,255,255,.04); }
.seq-item.now { background: rgba(164,92,255,.14); border-left-color: var(--purple); }
.seq-n { font-size: 11px; color: var(--muted); text-align: right; padding-top: 2px; font-variant-numeric: tabular-nums; }
.seq-ic { color: var(--purple-2); font-size: 15px; text-align: center; line-height: 1.3; }
.seq-pin { width: 12px; height: 12px; border-radius: 50%; margin: 4px auto 0; }
.seq-pin-start { background: var(--green); box-shadow: 0 0 8px var(--green); }
.seq-pin-end { background: var(--red); box-shadow: 0 0 8px var(--red); }
.seq-pin-via { background: var(--gold); box-shadow: 0 0 8px var(--gold); }
.seq-name { font-size: 13px; font-weight: 500; }
.seq-name b { color: var(--gold); font-weight: 600; margin-right: 4px; }
.seq-start .seq-name b { color: var(--green); }
.seq-end .seq-name b { color: var(--red); }
.seq-name .ref { font-size: 10.5px; padding: 0 5px; border-radius: 5px; background: rgba(242,201,76,.12); color: var(--gold); border: 1px solid rgba(242,201,76,.3); margin-left: 4px; }
.seq-meta { font-size: 11.5px; color: var(--muted); }

/* ---------------- manage / saved ---------------- */
.save-row { display: flex; gap: 8px; }
.save-row input { flex: 1; min-width: 0; padding: 8px 12px; border-radius: 10px; background: rgba(5,8,16,.65); border: 1px solid var(--line-2); outline: none; }
.save-row input:focus { border-color: rgba(164,92,255,.6); }
.saved-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.saved-item { display: grid; grid-template-columns: 22px 24px 1fr auto; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; background: rgba(5,8,16,.45); border: 1px solid var(--line-2); }
.saved-vis { position: relative; width: 20px; height: 20px; cursor: pointer; }
.saved-vis input { position: absolute; opacity: 0; inset: 0; cursor: pointer; margin: 0; }
.saved-vis span { position: absolute; inset: 0; border-radius: 6px; border: 1.5px solid #4A5578; }
.saved-vis input:checked + span { background: var(--purple); border-color: var(--purple); }
.saved-vis input:checked + span::after { content: '✓'; position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: #fff; }
.sv-color { width: 24px; height: 24px; border: 0; padding: 0; border-radius: 6px; background: none; cursor: pointer; }
.sv-color::-webkit-color-swatch-wrapper { padding: 0; }
.sv-color::-webkit-color-swatch { border: 1px solid rgba(255,255,255,.3); border-radius: 6px; }
.saved-main { min-width: 0; }
.sv-name { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 6px; padding: 1px 4px; font-weight: 500; font-size: 13px; }
.sv-name:hover { border-color: var(--line-2); }
.sv-name:focus { border-color: rgba(164,92,255,.6); outline: none; background: rgba(0,0,0,.25); }
.saved-meta { font-size: 11px; color: var(--muted); padding-left: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.saved-actions { display: flex; }

.credits { font-size: 11px; color: #67718F; text-align: center; padding: 6px 10px; line-height: 1.7; }
.credits a { color: #8D7CC0; }

/* ============================== Map ============================== */
#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; background: #0A0E1A; }
.leaflet-container { font-family: var(--font); background: #0A0E1A; }
.basemap-light .leaflet-container { background: #E8E4DC; }
.leaflet-control-attribution { background: rgba(8,11,20,.75) !important; color: #9AA3C0 !important; font-size: 10.5px; backdrop-filter: blur(4px); border-radius: 8px 0 0 0; }
.leaflet-control-attribution a { color: #C9A2FF !important; }
.leaflet-control-zoom { border: 0 !important; box-shadow: 0 6px 18px rgba(0,0,0,.45) !important; margin-top: 64px !important; }
.leaflet-control-zoom a { background: rgba(17,21,37,.92) !important; color: #E8ECF7 !important; border-color: rgba(255,255,255,.08) !important; width: 36px !important; height: 36px !important; line-height: 36px !important; }
.leaflet-control-zoom a:hover { background: var(--navy-2) !important; }
.leaflet-control-scale-line { background: rgba(8,11,20,.7); color: #C8CFE4; border-color: #8C96B3; }

/* route glow animation */
.route-flow { animation: flow 1.2s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -15; } }
.route-core { filter: drop-shadow(0 0 4px rgba(164,92,255,.9)); cursor: pointer; }
.route-alt { cursor: pointer; }
.route-hit { cursor: copy; }
path.route-alt:hover { stroke: #9AA3C0; }

/* pins */
.tri-pin-wrap { background: none; border: 0; }
.tri-pin {
  position: absolute; left: 2px; top: 0; width: 30px; height: 30px; border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg); display: grid; place-items: center;
  border: 2.5px solid #fff; box-shadow: 0 4px 12px rgba(0,0,0,.55);
}
.tri-pin span { transform: rotate(45deg); font-weight: 700; font-size: 13px; color: #0B0F1C; }
.tri-pin-start { background: var(--green); box-shadow: 0 0 16px rgba(53,214,160,.75), 0 4px 12px rgba(0,0,0,.5); }
.tri-pin-end { background: var(--red); box-shadow: 0 0 16px rgba(239,82,111,.75), 0 4px 12px rgba(0,0,0,.5); }
.tri-pin-end span { color: #fff; }
.tri-pin-via { background: var(--gold); box-shadow: 0 0 14px rgba(242,201,76,.7), 0 4px 12px rgba(0,0,0,.5); transform: rotate(-45deg) scale(.85); }
.tri-pin-shadow { position: absolute; left: 11px; top: 40px; width: 12px; height: 5px; border-radius: 50%; background: rgba(0,0,0,.45); filter: blur(1px); }
.leaflet-marker-draggable { cursor: grab; }
.leaflet-dragging .leaflet-marker-draggable { cursor: grabbing; }

/* moving arrow */
.tri-arrow-wrap { background: none; border: 0; pointer-events: none; }
.tri-arrow-rot { position: absolute; inset: 0; transform-origin: 50% 50%; will-change: transform; filter: drop-shadow(0 0 7px rgba(164,92,255,.95)) drop-shadow(0 0 2px rgba(255,255,255,.7)); }
.tri-arrow-rot svg { display: block; }
.tri-arrow-pulse { position: absolute; left: 50%; top: 50%; width: 46px; height: 46px; margin: -23px 0 0 -23px; border-radius: 50%; border: 2px solid rgba(164,92,255,.7); animation: pulse 1.8s ease-out infinite; }
@keyframes pulse { from { transform: scale(.6); opacity: .9; } to { transform: scale(1.9); opacity: 0; } }
.tri-arrow-label {
  position: absolute; left: 50%; top: 50px; transform: translateX(-50%); white-space: nowrap;
  font-size: 12px; font-weight: 600; color: #fff; padding: 2px 9px; border-radius: 8px;
  background: rgba(8,11,20,.85); border: 1px solid rgba(164,92,255,.55); box-shadow: 0 4px 12px rgba(0,0,0,.5);
}

/* tooltips & popups */
.tri-tooltip { background: rgba(10,14,26,.95); color: #E8ECF7; border: 1px solid rgba(164,92,255,.45); border-radius: 9px; box-shadow: 0 8px 20px rgba(0,0,0,.5); font-family: var(--font); font-size: 12.5px; padding: 5px 10px; }
.tri-tooltip::before { border-top-color: rgba(164,92,255,.45) !important; }
.leaflet-tooltip-left.tri-tooltip::before, .leaflet-tooltip-right.tri-tooltip::before { border-top-color: transparent !important; }
.tri-popup .leaflet-popup-content-wrapper { background: #0F1424; color: var(--text); border: 1px solid rgba(164,92,255,.45); border-radius: 12px; box-shadow: 0 14px 34px rgba(0,0,0,.6); }
.tri-popup .leaflet-popup-tip { background: #0F1424; }
.tri-popup .leaflet-popup-content { margin: 12px 14px; font-family: var(--font); }
.tri-popup a.leaflet-popup-close-button { color: #9AA3C0; }
.pt-menu { min-width: 200px; display: flex; flex-direction: column; gap: 5px; }
.pt-title { font-weight: 600; font-size: 13px; }
.pt-coord { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.pt-menu button { display: flex; align-items: center; gap: 8px; text-align: left; padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line-2); background: rgba(255,255,255,.04); font-size: 13px; }
.pt-menu button:hover { background: rgba(164,92,255,.15); border-color: rgba(164,92,255,.45); }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.g { background: var(--green); } .dot.y { background: var(--gold); } .dot.r { background: var(--red); }

/* HUD */
.hud {
  position: absolute; z-index: 800; top: 14px; left: 50%; transform: translateX(-50%);
  width: min(560px, calc(100% - 140px)); display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; border-radius: 16px;
  background: rgba(10,14,26,.86); border: 1px solid rgba(164,92,255,.4);
  backdrop-filter: blur(10px); box-shadow: 0 10px 30px rgba(0,0,0,.5), 0 0 24px rgba(164,92,255,.15);
}
.hud-play { width: 40px; height: 40px; border-radius: 50%; border: 0; flex: none; background: linear-gradient(135deg, #8B3DFF, var(--purple)); color: #fff; display: grid; place-items: center; box-shadow: 0 0 16px rgba(164,92,255,.6); }
.hud-play svg { width: 18px; height: 18px; fill: currentColor; }
.hud-body { flex: 1; min-width: 0; }
.hud-road { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-meta { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-meta b { color: var(--green); }
.hud-bar { height: 4px; border-radius: 4px; background: rgba(255,255,255,.08); margin-top: 5px; overflow: hidden; }

/* map tools */
.map-tools { position: absolute; z-index: 900; top: 14px; right: 10px; display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.leaflet-top.leaflet-right { top: 118px; }
.tool-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid rgba(255,255,255,.08); background: rgba(17,21,37,.92); font-size: 16px; box-shadow: 0 6px 18px rgba(0,0,0,.45); display: grid; place-items: center; }
.tool-btn:hover { background: var(--navy-2); }
.basemap-ctl { position: relative; }
.basemap-menu { position: absolute; right: 44px; top: 0; width: 240px; background: #0F1424; border: 1px solid rgba(164,92,255,.4); border-radius: 12px; padding: 6px; box-shadow: 0 14px 34px rgba(0,0,0,.6); }
.bm-title { font-size: 11.5px; color: var(--muted); padding: 4px 8px; }
.bm-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 8px; border-radius: 8px; font-size: 13px; }
.bm-item:hover { background: rgba(255,255,255,.06); }
.bm-item.on { background: rgba(164,92,255,.18); }
.bm-sw { width: 18px; height: 18px; border-radius: 5px; border: 1px solid rgba(255,255,255,.25); flex: none; }
.bm-sw.dark { background: linear-gradient(135deg, #1B1F2E, #3A3F55); }
.bm-sw.light { background: linear-gradient(135deg, #F4EFE6, #B9D3B0); }

/* loading / error overlays */
.spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(164,92,255,.25); border-top-color: var(--purple); animation: spin .8s linear infinite; display: inline-block; vertical-align: -3px; }
.spinner.sm { width: 13px; height: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }
.route-busy, .tile-spinner {
  position: absolute; z-index: 850; left: 50%; bottom: 34px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  display: flex; gap: 10px; align-items: center; padding: 8px 16px; border-radius: 999px;
  background: rgba(10,14,26,.9); border: 1px solid rgba(164,92,255,.45); font-size: 13px; transition: all .2s;
}
.tile-spinner { left: auto; right: 12px; bottom: 40px; transform: translateY(10px); font-size: 11.5px; padding: 5px 12px; }
.route-busy.show, .tile-spinner.show { opacity: 1; transform: translate(-50%, 0); }
.tile-spinner.show { transform: none; }
.map-loading { position: absolute; inset: 0; z-index: 950; display: none; place-items: center; align-content: center; gap: 18px; background: radial-gradient(circle at center, #121A33 0%, var(--bg) 70%); }
.map-loading.show { display: grid; }
.map-loading-text { color: #C9D0E6; font-size: 14px; }
.radar { width: 90px; height: 90px; border-radius: 50%; border: 1px solid rgba(164,92,255,.45); position: relative; overflow: hidden; box-shadow: 0 0 30px rgba(164,92,255,.3), inset 0 0 20px rgba(164,92,255,.2); }
.radar span { position: absolute; inset: 0; background: conic-gradient(from 0deg, rgba(164,92,255,.65), transparent 30%); animation: spin 1.6s linear infinite; border-radius: 50%; }
.map-error { position: absolute; inset: 0; z-index: 960; display: none; place-items: center; background: rgba(8,11,20,.78); backdrop-filter: blur(3px); }
.map-error.show { display: grid; }
.map-error-box { max-width: 420px; text-align: center; padding: 26px; border-radius: 18px; background: #0F1424; border: 1px solid rgba(239,82,111,.45); box-shadow: 0 20px 50px rgba(0,0,0,.6); }
.map-error-icon { font-size: 34px; color: var(--red); }
.map-error-title { font-weight: 600; font-size: 16px; margin: 6px 0; }
.map-error-detail { color: var(--muted); font-size: 13px; }

/* toasts & banners */
.toasts { position: fixed; z-index: 6000; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; font-size: 13px;
  background: rgba(15,20,36,.97); border: 1px solid var(--line-2); box-shadow: 0 12px 30px rgba(0,0,0,.55);
  animation: tin .25s ease-out; border-left: 3px solid var(--purple);
}
.toast.out { opacity: 0; transform: translateX(20px); transition: all .25s; }
@keyframes tin { from { opacity: 0; transform: translateY(10px); } }
.toast-icon { font-weight: 700; }
.toast-success { border-left-color: var(--green); } .toast-success .toast-icon { color: var(--green); }
.toast-warn { border-left-color: var(--gold); } .toast-warn .toast-icon { color: var(--gold); }
.toast-error { border-left-color: var(--red); } .toast-error .toast-icon { color: var(--red); }
.toast-info .toast-icon { color: var(--purple-2); }
.toast-msg { flex: 1; }
.toast-x { border: 0; background: none; color: var(--muted); font-size: 16px; line-height: 1; padding: 0 2px; }
.offline-banner { position: fixed; z-index: 6500; top: 0; left: 0; right: 0; text-align: center; padding: 6px; font-size: 13px; background: var(--red); color: #fff; font-weight: 500; }
.fatal { position: fixed; inset: 0; z-index: 9999; display: grid; place-items: center; background: var(--bg); padding: 20px; }
.fatal-box { max-width: 460px; text-align: center; background: var(--panel); border: 1px solid rgba(239,82,111,.45); border-radius: 18px; padding: 28px; }
.fatal-box h2 { color: var(--red); margin-top: 0; }

/* ============================== Responsive ============================== */
@media (max-width: 1100px) { :root { --sidebar-w: 350px; } }
@media (max-width: 900px) {
  /* มือถือ: แผนที่ด้านบน แผงควบคุมด้านล่าง (เลื่อนได้อิสระ ทั้งสองส่วนมองเห็นพร้อมกัน) */
  #app { flex-direction: column-reverse; }
  #map-wrap { height: 52vh; height: 52dvh; flex: none; z-index: 1; }
  #sidebar { width: 100%; min-width: 0; height: auto; flex: 1; min-height: 0; border-right: 0; border-top: 1px solid var(--line); box-shadow: 0 -10px 30px rgba(0,0,0,.5); z-index: 2; }
  .status-row { padding-bottom: 8px; }
  .brand { padding: 12px 14px 8px; }
  .brand h1 { font-size: 14px; }
  .hud { top: 8px; width: calc(100% - 70px); left: 8px; transform: none; padding: 8px 10px; }
  .hud-play { width: 34px; height: 34px; }
  .map-tools { top: 8px; right: 8px; }
  .leaflet-top.leaflet-right { top: 100px; }
  .leaflet-control-zoom { margin-top: 30px !important; }
  .basemap-menu { width: 210px; }
  .wp-addr { max-width: calc(100vw - 140px); }
  .seq-list { max-height: none; }
  .toasts { left: 16px; right: 16px; max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
  .route-flow, .tri-arrow-pulse, .radar span { animation: none; }
}
