    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
      background: #1a1a2e;
      color: #e0e0e0;
      display: flex;
      flex-direction: column;
      height: 100dvh;
      overflow: hidden;
    }

    /* ── Bars ── */
    .bar {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 6px 10px;
      background: #16213e;
      border-bottom: 1px solid #0f3460;
      flex-shrink: 0;
      flex-wrap: wrap;
    }
    .bar.seg-section {
      flex-direction: column;
      align-items: stretch;
      gap: 4px;
    }
    .seg-section-header {
      display: flex;
      align-items: center;
      gap: 6px;
    }

    /* ── Collapsible panel ── */
    #panel {
      overflow: hidden;
      max-height: 800px;
      transition: max-height 0.22s ease-out;
      flex-shrink: 0;
    }
    #panel.collapsed {
      max-height: 0;
    }

    /* ── Panel header (always visible) ── */
    #panel-header {
      display: flex;
      align-items: center;
      gap: 8px;
      padding: 5px 10px;
      background: #16213e;
      border-bottom: 1px solid #0f3460;
      flex-shrink: 0;
    }

    h1 {
      font-size: 1rem;
      font-weight: 700;
      letter-spacing: 0.05em;
      color: #e94560;
      white-space: nowrap;
    }

    /* ── Inputs ── */
    .text-input {
      padding: 5px 6px;
      border-radius: 4px;
      border: 1px solid #0f3460;
      background: #1a1a2e;
      color: #e0e0e0;
      font-size: 0.88rem;
    }
    .text-input::placeholder { color: #555; }
    .text-input[type=number] { text-align: center; }

    #elr-view { width: 80px; text-transform: uppercase; }
    #elr-view::placeholder { text-transform: none; }

    .seg-elr  { width: 62px; text-transform: uppercase; }
    .seg-elr::placeholder { text-transform: none; }
    .seg-m    { width: 44px; }
    .seg-ch   { width: 38px; }

    /* ── Buttons ── */
    .btn {
      padding: 5px 10px;
      border-radius: 4px;
      border: none;
      font-size: 0.85rem;
      cursor: pointer;
      white-space: nowrap;
    }
    .btn:disabled { opacity: 0.45; cursor: not-allowed; }

    .btn-primary   { background: #e94560; color: #fff; }
    .btn-primary:hover:not(:disabled) { background: #c73652; }

    .btn-secondary { background: transparent; border: 1px solid #444; color: #aaa; }
    .btn-secondary:hover:not(:disabled) { border-color: #e94560; color: #e94560; }

    .btn-apply { background: #0f3460; color: #64b5f6; border: 1px solid #1a5276; }
    .btn-apply:hover:not(:disabled) { background: #1a5276; }

    .btn-add {
      padding: 3px 8px;
      font-size: 0.8rem;
      background: transparent;
      border: 1px solid #444;
      color: #888;
    }
    .btn-add:hover { border-color: #64b5f6; color: #64b5f6; }

    .btn-rem {
      padding: 3px 7px;
      font-size: 0.85rem;
      background: transparent;
      border: 1px solid #333;
      color: #666;
    }
    .btn-rem:hover { border-color: #ef5350; color: #ef5350; }

    /* Panel toggle button */
    #toggle-panel-btn {
      padding: 4px 8px;
      font-size: 0.75rem;
      min-width: 28px;
    }

    /* ── Row labels ── */
    .row-label {
      font-size: 0.75rem;
      font-weight: 600;
      letter-spacing: 0.04em;
      white-space: nowrap;
      min-width: 26px;
    }
    .row-label.swl { color: #ff9800; }
    .row-label.ws  { color: #aed581; }

    .sep { color: #555; font-size: 0.8rem; padding: 0 1px; }
    .lbl { font-size: 0.78rem; color: #888; }

    /* ── Toggle ── */
    .toggle-label {
      display: flex; align-items: center; gap: 5px;
      font-size: 0.8rem; color: #aaa; cursor: pointer; user-select: none;
    }
    .toggle-label input { cursor: pointer; accent-color: #64b5f6; }

    /* ── Status ── */
    #status {
      font-size: 0.78rem;
      color: #aaa;
      margin-left: auto;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      max-width: 220px;
    }
    #status.error { color: #ef5350; }
    #status.ok    { color: #4caf50; }
    #status.info  { color: #64b5f6; }

    /* ── Segment list ── */
    .seg-list {
      display: flex;
      flex-direction: column;
      gap: 4px;
      width: 100%;
    }
    .seg-row {
      display: flex;
      align-items: center;
      gap: 3px;
      flex-wrap: nowrap;
    }

    /* ── Location tooltip ── */
    .loc-tooltip {
      background: rgba(22,33,62,0.93) !important;
      border: 1px solid #4fc3f7 !important;
      border-radius: 4px !important;
      color: #e0e0e0 !important;
      font-size: 0.8rem !important;
      padding: 4px 8px !important;
      white-space: nowrap;
      box-shadow: none !important;
    }
    .loc-tooltip::before { border-right-color: #4fc3f7 !important; }
    .loc-sub { font-size: 0.72rem; color: #90caf9; }

    /* ── Track popup (click/tap on line) ── */
    .track-popup .leaflet-popup-content-wrapper {
      background: rgba(22,33,62,0.96);
      border: 1px solid #4fc3f7;
      border-radius: 5px;
      color: #e0e0e0;
      font-size: 0.82rem;
      line-height: 1.5;
      box-shadow: 0 3px 10px rgba(0,0,0,0.5);
      padding: 0;
    }
    .track-popup .leaflet-popup-content {
      margin: 8px 12px;
    }
    .track-popup .leaflet-popup-tip-container .leaflet-popup-tip {
      background: rgba(22,33,62,0.96);
    }
    .track-popup .leaflet-popup-close-button {
      color: #90caf9 !important;
      font-size: 16px !important;
      padding: 4px 6px !important;
    }
    .popup-elr   { font-weight: 700; color: #fff; font-size: 0.9rem; }
    .popup-mch   { color: #4fc3f7; font-weight: 600; }
    .popup-track { color: #aaa; font-size: 0.75rem; }
    .popup-owner { color: #ffcc80; font-size: 0.72rem; }
    .popup-toggle {
      display: inline-block;
      margin-top: 5px;
      padding: 4px 10px;
      font-size: 0.78rem;
      border-radius: 3px;
      cursor: pointer;
      background: #0d2137;
      color: #64b5f6;
      border: 1px solid #1a5276;
    }
    .popup-toggle:hover { background: #1a5276; }
    .popup-toggle.is-open { color: #81c784; border-color: #2e7d32; }
    .popup-toggle.is-open:hover { background: #1b5e20; }

    /* ── Milepost icon ── */
    .mp-face {
      background: #f7c800;
      border: 2px solid #111;
      border-radius: 3px;
      width: 26px;
      display: flex;
      flex-direction: column;
      align-items: center;
      padding: 2px 2px 3px;
      gap: 2px;
      box-shadow: 1px 2px 5px rgba(0,0,0,0.65);
      cursor: default;
    }
    .mp-num {
      font-size: 10px;
      font-weight: 900;
      color: #111;
      line-height: 1;
      font-family: Arial, sans-serif;
      letter-spacing: -0.5px;
    }
    .mp-qs {
      display: flex;
      gap: 3px;
      min-height: 7px;
      align-items: flex-end;
    }
    .mp-q {
      display: block;
      width: 2px;
      height: 7px;
      background: #111;
      border-radius: 1px;
    }
    /* tooltip for milepost hover */
    .mp-tip {
      background: rgba(22,33,62,0.92) !important;
      border: 1px solid #f7c800 !important;
      color: #f7c800 !important;
      font-size: 0.72rem !important;
      font-weight: 600 !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 2px 6px !important;
    }

    /* ── Location markers ── */
    .loc-icon {
      display: flex;
      align-items: center;
      justify-content: center;
      border: 2px solid #111;
      border-radius: 50%;
      box-shadow: 1px 2px 5px rgba(0,0,0,0.65);
      font-size: 9px;
      font-weight: 900;
      font-family: Arial, sans-serif;
      color: #111;
      cursor: default;
      line-height: 1;
    }
    .loc-station  { background: #fff176; width: 20px; height: 20px; }
    .loc-junction { background: #b0bec5; width: 14px; height: 14px; border-width: 1.5px; }
    .loc-freight  { background: #a5d6a7; width: 14px; height: 14px; border-width: 1.5px; }
    .loc-tip {
      background: rgba(22,33,62,0.92) !important;
      border: 1px solid #ccc !important;
      color: #e0e0e0 !important;
      font-size: 0.72rem !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 2px 6px !important;
    }

    /* ── Switch labels ── */
    .switch-icon {
      display: flex;
      align-items: center;
      justify-content: center;
      background: #ffeb3b;
      border: 1.5px solid #111;
      border-radius: 2px;
      box-shadow: 1px 1px 3px rgba(0,0,0,0.5);
      font-size: 8px;
      font-weight: 800;
      font-family: monospace;
      color: #111;
      cursor: default;
      line-height: 1;
      white-space: nowrap;
      padding: 1px 3px;
      transform: rotate(-15deg);
    }
    .switch-tip {
      background: rgba(22,33,62,0.92) !important;
      border: 1px solid #ffeb3b !important;
      color: #ffeb3b !important;
      font-size: 0.7rem !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 2px 6px !important;
    }

    /* ── Signal labels ── */
    .sig-marker {
      display: flex;
      flex-direction: column;
      align-items: center;
      gap: 2px;
    }
    .sig-head {
      width: 10px;
      height: 18px;
      background: #111;
      border: 1px solid #444;
      border-radius: 2px;
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      padding: 2px 0;
    }
    .sig-lens {
      width: 4px;
      height: 4px;
      border-radius: 50%;
      background: #333;
      margin: 0 auto;
    }
    /* 4-aspect */
    .sig-head-4 { height: 24px; }
    /* Semaphore */
    .sig-sem {
      width: 14px;
      height: 4px;
      background: #e53935;
      border: 1px solid #111;
      transform-origin: left center;
      transform: rotate(-45deg);
      margin-left: 6px;
    }
    /* Ground Position */
    .sig-gpl {
      width: 8px;
      height: 8px;
      background: #111;
      border: 1px solid #666;
      border-radius: 50%;
    }
    /* Stop Board */
    .sig-stop {
      width: 10px;
      height: 10px;
      background: #e53935;
      border: 1.5px solid #fff;
      transform: rotate(45deg);
    }
    .sig-id {
      background: rgba(0,0,0,0.7);
      color: #fff;
      font-size: 8px;
      font-family: monospace;
      padding: 0 2px;
      border-radius: 2px;
      white-space: nowrap;
    }
    .sig-tip {
      background: rgba(22,33,62,0.95) !important;
      border: 1px solid #90caf9 !important;
      color: #fff !important;
      font-size: 0.75rem !important;
      border-radius: 4px !important;
    }
    .sig-tip b { color: #90caf9; }

    /* ── Locate button active state ── */
    .btn-locate-active {
      background: #0d47a1 !important;
      border-color: #4fc3f7 !important;
      color: #4fc3f7 !important;
    }

    /* ── Overview network tooltip ── */
    .ov-tip {
      background: rgba(22,33,62,0.92) !important;
      border: 1px solid #546e7a !important;
      color: #b0bec5 !important;
      font-size: 0.72rem !important;
      font-weight: 700 !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 2px 6px !important;
    }

    /* ── Layer toggle buttons ── */
    .btn-layer {
      padding: 4px 10px;
      border-radius: 4px;
      font-size: 0.82rem;
      cursor: pointer;
      white-space: nowrap;
      border: 1px solid #444;
      background: transparent;
      color: #888;
      transition: background 0.15s, color 0.15s, border-color 0.15s;
    }
    .btn-layer:hover { border-color: #aaa; color: #ccc; }

    .btn-layer-history        { border-color: #7a5c38; color: #a07840; }
    .btn-layer-history:hover  { background: rgba(160,120,64,0.12); color: #c9a96e; border-color: #c9a96e; }
    .btn-layer-history.active { background: rgba(160,120,64,0.22); color: #d4a853; border-color: #d4a853; }

    .btn-layer-tfl        { border-color: #003688; color: #0098D4; }
    .btn-layer-tfl:hover  { background: rgba(0,152,212,0.12); border-color: #0098D4; color: #4fc3f7; }
    .btn-layer-tfl.active { background: rgba(0,152,212,0.22); color: #4fc3f7; border-color: #4fc3f7; }

    .btn-layer-sat        { border-color: #2e7d32; color: #66bb6a; }
    .btn-layer-sat:hover  { background: rgba(76,175,80,0.12); color: #81c784; border-color: #81c784; }
    .btn-layer-sat.active { background: rgba(76,175,80,0.22); color: #a5d6a7; border-color: #a5d6a7; }

    /* ── History tooltip ── */
    .hist-tip {
      background: rgba(28,18,8,0.93) !important;
      border: 1px solid #8B6914 !important;
      color: #d4a853 !important;
      font-size: 0.72rem !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 2px 6px !important;
    }

    /* ── TfL tooltip ── */
    .tfl-tip {
      background: rgba(10,16,40,0.96) !important;
      border: 1px solid #0098D4 !important;
      color: #e0e0e0 !important;
      font-size: 0.76rem !important;
      white-space: nowrap;
      box-shadow: none !important;
      border-radius: 3px !important;
      padding: 3px 8px !important;
      line-height: 1.5 !important;
    }

    /* ── Safety banner ── */
    #safety-banner {
      background: #7f3000;
      border-bottom: 1px solid #bf4800;
      padding: 4px 10px;
      font-size: 0.72rem;
      color: #ffcc80;
      text-align: center;
      flex-shrink: 0;
      letter-spacing: 0.01em;
    }
    #safety-banner strong { color: #ffab40; }

    /* ── Disclaimer modal ── */
    #disclaimer-overlay {
      position: fixed;
      inset: 0;
      background: rgba(0,0,0,0.82);
      display: flex;
      align-items: center;
      justify-content: center;
      z-index: 9999;
      padding: 20px;
    }
    #disclaimer-overlay.hidden { display: none; }
    #disclaimer-box {
      background: #16213e;
      border: 2px solid #bf4800;
      border-radius: 8px;
      padding: 24px 20px 20px;
      max-width: 480px;
      width: 100%;
    }
    #disclaimer-box h2 {
      color: #ffab40;
      font-size: 1rem;
      margin-bottom: 14px;
      display: flex;
      align-items: center;
      gap: 8px;
    }
    #disclaimer-box p {
      font-size: 0.875rem;
      line-height: 1.6;
      color: #ccc;
      margin-bottom: 12px;
    }
    #disclaimer-box p strong { color: #ffcc80; }
    #disclaimer-box p:last-of-type { margin-bottom: 20px; }
    #disclaimer-accept {
      width: 100%;
      padding: 10px;
      background: #bf4800;
      color: #fff;
      border: none;
      border-radius: 4px;
      font-size: 0.9rem;
      font-weight: 600;
      cursor: pointer;
    }
    #disclaimer-accept:hover { background: #e65100; }

    /* ── Map ── */
    #map { flex: 1; width: 100%; }

    /* ── Legend ── */
    .legend {
      background: rgba(22,33,62,0.93);
      border: 1px solid #0f3460;
      border-radius: 4px;
      padding: 7px 11px;
      font-size: 0.73rem;
      line-height: 1.9;
      color: #ddd;
    }
    .li { display: flex; align-items: center; gap: 6px; }
    .sw { display: inline-block; width: 22px; height: 3px; border-radius: 2px; }
    .sw.thick { height: 5px; }

    /* ── Unit toggle ── */
    .unit-toggle {
      display: flex;
      background: #16213e;
      border: 1px solid #0f3460;
      border-radius: 4px;
      overflow: hidden;
      cursor: pointer;
      user-select: none;
      font-size: 0.65rem;
      font-weight: 600;
      height: 24px;
      align-items: center;
      margin-left: 4px;
    }
    .unit-toggle span {
      padding: 0 6px;
      height: 100%;
      display: flex;
      align-items: center;
      color: #777;
    }
    .unit-toggle span.active {
      background: #4fc3f7;
      color: #1a1a2e;
    }

    /* ── Embed mode ── */
    body.is-embedded #safety-banner,
    body.is-embedded #panel-header,
    body.is-embedded #panel,
    body.is-embedded #disclaimer-overlay,
    body.is-embedded .legend {
      display: none !important;
    }
    body.is-embedded #map {
      height: 100vh;
    }
.panel-tabs { display: flex; background: #16213e; border-bottom: 1px solid #0f3460; padding: 0 10px; flex-shrink: 0;}
.tab-btn { background: none; border: none; color: #888; padding: 10px 15px; cursor: pointer; font-size: 0.9rem; font-weight: 600; border-bottom: 2px solid transparent; }
.tab-btn:hover { color: #ccc; }
.tab-btn.active { color: #4fc3f7; border-bottom-color: #4fc3f7; }
.tab-content { display: none; padding-top: 10px; overflow-y: auto; }
.tab-content.active { display: block; }
.ann-line-tip { background: none !important; border: none !important; box-shadow: none !important; color: #ffeb3b !important; font-weight: bold; text-shadow: -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000, 1px 1px 0 #000; }
.ann-line-tip-dyn { background: none !important; border: none !important; box-shadow: none !important; margin: 0; padding: 0; }
