:root{
  --blue:#0b4f8a;
  --blue2:#0e67b3;
  --grey:#2f3a45;
  --grey2:#475564;
  --bg:#0f1318;
  --panel:#121a22;
  --panel2:#0f1620;
  --border:rgba(255,255,255,.08);
  --text:#e9eef5;
  --muted:rgba(233,238,245,.72);
  --muted2:rgba(233,238,245,.55);
  --ok:#3ddc97;
  --warn:#ffcc66;
  --bad:#ff6b6b;
  --shadow: 0 8px 24px rgba(0,0,0,.35);
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Apple Color Emoji","Segoe UI Emoji";
  background: radial-gradient(1200px 600px at 10% -10%, rgba(14,103,179,.45), transparent 55%),
              radial-gradient(900px 500px at 110% 10%, rgba(11,79,138,.35), transparent 60%),
              var(--bg);
  color:var(--text);
}

.topbar{
  height:58px;
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding:0 14px;
  border-bottom:1px solid var(--border);
  background:linear-gradient(180deg, rgba(18,26,34,.94), rgba(18,26,34,.70));
  position:sticky;
  top:0;
  z-index:10;
}

.brand{display:flex; align-items:center; gap:10px}
.dot{
  width:14px; height:14px; border-radius:50%;
  background:linear-gradient(180deg,var(--blue2),var(--blue));
  box-shadow: 0 0 0 3px rgba(14,103,179,.18);
}
.brand-title{font-weight:800; letter-spacing:.2px}
.brand-sub{font-size:12px; color:var(--muted2)}

.topbar-right{display:flex; gap:10px; align-items:center}

.pill{
  font-size:12px;
  padding:6px 10px;
  border-radius:999px;
  background:rgba(255,255,255,.06);
  border:1px solid var(--border);
  color:var(--muted);
}

.btn{
  border:1px solid var(--border);
  background:rgba(255,255,255,.06);
  color:var(--text);
  padding:8px 12px;
  border-radius:12px;
  cursor:pointer;
  transition: transform .05s ease, background .15s ease;
}
.btn:hover{background:rgba(255,255,255,.09)}
.btn:active{transform:scale(.98)}
.btn-ghost{background:transparent}

.layout{
  display:grid;
  grid-template-columns: 360px 1fr;
  height: calc(100vh - 58px);
}

.sidebar{
  border-right:1px solid var(--border);
  background:linear-gradient(180deg, rgba(18,26,34,.70), rgba(18,26,34,.35));
  padding:12px;
  overflow:auto;
}

.panel{
  background:linear-gradient(180deg, rgba(18,26,34,.92), rgba(18,26,34,.72));
  border:1px solid var(--border);
  border-radius:18px;
  box-shadow: var(--shadow);
  padding:12px;
  margin-bottom:12px;
}
.panel-title{font-weight:800; font-size:14px}
.panel-sub{font-size:12px; color:var(--muted2); margin-top:4px}

.service-controls{display:flex; gap:8px; margin-top:10px}
.input{
  flex:1;
  border:1px solid var(--border);
  background:rgba(0,0,0,.20);
  color:var(--text);
  padding:9px 10px;
  border-radius:12px;
  outline:none;
}
.input::placeholder{color:rgba(233,238,245,.45)}
.input:focus{border-color: rgba(14,103,179,.55); box-shadow: 0 0 0 3px rgba(14,103,179,.18)}

.list{margin-top:10px; display:flex; flex-direction:column; gap:8px}
.row{
  display:flex;
  justify-content:space-between;
  gap:10px;
  padding:10px 10px;
  border-radius:14px;
  border:1px solid var(--border);
  background:rgba(255,255,255,.04);
  cursor:pointer;
}
.row:hover{background:rgba(255,255,255,.07)}
.row.active{
  background:rgba(14,103,179,.16);
  border-color: rgba(14,103,179,.45);
}
.row .left{display:flex; flex-direction:column}
.row .t{font-weight:800; font-size:13px; letter-spacing:.2px}
.row .s{font-size:12px; color:var(--muted2)}
.row .right{text-align:right}
.badge{
  font-size:11px;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:rgba(255,255,255,.05);
  color:var(--muted);
  display:inline-block;
}

.map-wrap{position:relative}
#map{height:100%; width:100%}

.drawer{
  position:absolute;
  right:14px;
  top:14px;
  /* Leaflet panes/controls sit on high z-index; keep this UI above the map */
  z-index: 2000;
  width:min(540px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  overflow:auto;
  border-radius:18px;
  border:1px solid var(--border);
  background:linear-gradient(180deg, rgba(18,26,34,.95), rgba(18,26,34,.82));
  box-shadow: var(--shadow);
  display:none;
}
.drawer.open{display:block}

.drawer-head{
  display:flex;
  justify-content:space-between;
  align-items:flex-start;
  padding:12px;
  border-bottom:1px solid var(--border);
}
.drawer-title{font-weight:900; font-size:14px}
.drawer-sub{font-size:12px; color:var(--muted2); margin-top:4px}

.tiles{display:grid; grid-template-columns: 1fr; gap:12px; padding:12px}
.tile{
  border:1px solid var(--border);
  border-radius:16px;
  padding:12px;
  background:rgba(255,255,255,.04);
}
.tile-title{font-weight:900; font-size:13px}
.tile-sub{font-size:12px; color:var(--muted2); margin-top:4px}

.kv{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:10px;
  margin-top:10px;
}
.kv .k{
  font-size:11px;
  color:var(--muted2);
}
.kv .v{
  font-size:13px;
  font-weight:700;
  margin-top:3px;
}

.table-wrap{margin-top:10px; overflow:auto; border-radius:14px; border:1px solid var(--border)}
.table{width:100%; border-collapse:collapse; font-size:12px}
.table th, .table td{padding:8px 10px; border-bottom:1px solid var(--border); white-space:nowrap}
.table th{color:var(--muted2); text-align:left; font-weight:800; background:rgba(0,0,0,.12)}
.table tr:last-child td{border-bottom:none}
.table tr.highlight td{background:rgba(14,103,179,.18)}
.tp{font-weight:900; color:rgba(255,255,255,.85)}



.hint{font-size:12px; color:var(--muted2); margin-top:10px}

/* Leaflet tweaks */
.leaflet-container{background:#0b0f14}
.leaflet-control-attribution{background:rgba(0,0,0,.35); color:rgba(255,255,255,.6); border-radius:10px; padding:2px 8px}

/* TXC progress (kept minimal to avoid layout regressions) */
.progress-block { margin: 10px 0 8px; }
.progress-label { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.progress-bar { height: 10px; border-radius: 999px; background: rgba(255,255,255,0.08); overflow: hidden; border: 1px solid rgba(255,255,255,0.10); }
.progress-fill { height: 100%; width: 0%; background: rgba(59,130,246,0.85); border-radius: 999px; transition: width 180ms ease; }

/* =======================================================================
   TXC Stops table: lock column widths (stop column must NOT expand)
   ======================================================================= */

/* Only affects the TXC table in the drawer */
#txcStopsTable {
  table-layout: fixed !important;
  width: 100% !important;
  max-width: 100% !important;
  min-width: 0 !important;
}

/* Prevent the wrapper from showing a horizontal scrollbar for this table */
#txcStopsTable.table {
  width: 100% !important;
}
.drawer .tile .table-wrap {
  overflow-x: hidden;
}

/* Hard column widths (# | Stop | Due | Actual | TP | Distance) */
#txcStopsTable th:nth-child(1),
#txcStopsTable td:nth-child(1) { width: 40px !important; }

#txcStopsTable th:nth-child(3),
#txcStopsTable td:nth-child(3) { width: 70px !important; }
#txcStopsTable th:nth-child(4),
#txcStopsTable td:nth-child(4) { width: 100px !important; }

#txcStopsTable th:nth-child(5),
#txcStopsTable td:nth-child(5) { width: 98px !important; }

#txcStopsTable th:nth-child(6),
#txcStopsTable td:nth-child(6) { width: 80px !important; }

/* Stop column: fixed width, crop text (no wrapping, no expansion) */
#txcStopsTable th:nth-child(2),
#txcStopsTable td:nth-child(2) {
  width: 220px !important;      /* adjust if you want */
  max-width: 220px !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: clip !important;
}
/* Allow tiles (and their contents) to shrink instead of forcing horizontal growth */
.tiles, .tile, .drawer, .table-wrap {
  min-width: 0;
}

/* TXC table should never force the tile wider */
#txcStopsTable {
  width: 100%;
  table-layout: fixed;
}

/* Don’t allow horizontal scroll / widening inside the TXC tile */
#txcStopsTable.table-wrap,
.tile .table-wrap {
  overflow-x: hidden;
}

/* Hard-cap Stop column so long names can’t expand layout */
#txcStopsTable th:nth-child(2),
#txcStopsTable td:nth-child(2) {
  width: 180px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: clip; /* crop */
}
/* Timing point indicator colour */
.tp {
  color: #F54927; /* Orange */
}
/* --- Sidebar Tabs (Live | History) --- */
.tabs{
  display:flex;
  gap:6px;
  padding:8px;
  margin-bottom:8px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
}
.tab{
  flex:1;
  cursor:pointer;
  padding:8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: rgba(233,238,245,.92);
  font-weight: 800;
  font-size: 12px;
}
.tab:hover{ filter: brightness(1.06); }
.tab.active{
  background: rgba(61,220,151,.18);
  border-color: rgba(61,220,151,.35);
}

.tab-pane{ display:none; min-height:0; }
.tab-pane.active{ display:block; }

/* Make panes scroll if the sidebar already constrains height */
.sidebar{ min-height:0; }
#livePane, #historyPane{ overflow:auto; }

/* ===============================
   Sidebar tabs (Live / History)
   =============================== */

.tabs {
  display: flex;
  gap: 6px;
  padding: 8px;
  margin-bottom: 8px;
}

.tab {
  flex: 1;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,0.12);
  background: rgba(255,255,255,0.06);
  color: rgba(230,235,245,0.95);
}

.tab.active {
  background: rgba(61,220,151,0.18);
  border-color: rgba(61,220,151,0.35);
}

/* 🔑 THIS IS THE CRITICAL BIT */
.tab-pane {
  display: none;
  min-height: 0;
}

.tab-pane.active {
  display: block;
}
/* --- Sidebar Tabs (Live | History) --- */
.tabs{
  display:flex;
  gap:6px;
  padding:8px;
  margin-bottom:8px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 12px;
}
.tab{
  flex:1;
  cursor:pointer;
  padding:8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(255,255,255,.06);
  color: rgba(233,238,245,.92);
  font-weight: 800;
  font-size: 12px;
}
.tab:hover{ filter: brightness(1.06); }
.tab.active{
  background: rgba(61,220,151,.18);
  border-color: rgba(61,220,151,.35);
}

.tab-pane{ display:none; min-height:0; }
.tab-pane.active{ display:block; }

/* Make panes scroll if the sidebar already constrains height */
.sidebar{ min-height:0; }
#livePane, #historyPane{ overflow:auto; }

/* ---- TXC admin (prevent height jumping; scroll inside tiles) ---- */
.txc-admin .tiles{ overflow:hidden; }
.txc-admin .layout{ height: calc(100vh - 58px); }

/* quick reset animation */
.reset-flash {
  opacity: 0.25;
  transform: translateY(4px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.reset-flash-back {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 180ms ease, transform 180ms ease;
}





/* ===== App Shell: left rail + module panes ===== */
.app-shell{
  display:grid;
  grid-template-columns: 210px 1fr;
  height: calc(100vh - 58px); /* your topbar height */
}

.rail{
  border-right:1px solid var(--border);
  background: linear-gradient(180deg, rgba(18,26,34,.80), rgba(18,26,34,.35));
  padding: 10px;
  overflow:auto;
}

.rail-btn{
  width:100%;
  display:flex;
  align-items:center;
  gap:10px;
  padding:10px 12px;
  border-radius:14px;
  border:1px solid var(--border);
  background: rgba(255,255,255,.04);
  color: var(--text);
  cursor:pointer;
  font-weight:900;
  margin-bottom:8px;
}
.rail-btn:hover{ background: rgba(255,255,255,.07); }
.rail-btn.active{
  background: rgba(14,103,179,.16);
  border-color: rgba(14,103,179,.45);
}
.rail-btn span{ white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }

.main-tabs{ min-width:0; }
.main-pane{ display:none; height:100%; }
.main-pane.active{ display:block; }

/* 3-column per-module layout: (sidebar + content) */
.layout3{
  display:grid;
  grid-template-columns: 360px 1fr;
  height: 100%;
  min-width:0;
}
.layout3 .content{ min-width:0; }


/* Live Map status pill - bottom center overlay */
.map-wrap { position: relative; }

.map-hud{
  position:absolute;
  left:50%;
  bottom:14px;
  transform: translateX(-50%);
  z-index: 2000;          /* above map tiles */
  pointer-events: none;   /* HUD should not block map clicks */
}

.map-hud-pill{
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(15,23,42,.70);
  color: rgba(233,238,245,.95);
  padding: 10px 14px;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: .2px;
  box-shadow: 0 10px 26px rgba(0,0,0,.35);
  backdrop-filter: blur(8px);
  white-space: nowrap;
}


/* Ensure the left rail is always clickable above Leaflet/map overlays */
.rail{
  position: relative;
  z-index: 50000;
}

/* Stop any module content from overlapping the rail */
.main-tabs{
  position: relative;
  z-index: 1;
}

/* Leaflet panes sometimes float high; keep them below rail */
.leaflet-pane,
.leaflet-top,
.leaflet-bottom,
.leaflet-control,
.leaflet-control-container{
  z-index: 1000 !important;
}


/* Hidden panes must NOT capture pointer events */
.main-pane{ display:none; pointer-events:none; }
.main-pane.active{ display:block; pointer-events:auto; }

/* Keep rail above any map panes/overlays */
.rail{ position:relative; z-index:50000; }
