* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
}

#map {
  width: 100%;
  height: 100%;
  background-color: var(--map-background);
}

.track.occupied {
  stroke: var(--track-occupied);
}
.track.reserved {
  stroke: var(--track-reserved);
}
.track {
  stroke: var(--track-free);
}

.train-name,
.station-name {
  font-family: var(--ui-font);
  font-weight: bold;
  font-size: 15px;
}
.station-name .track-number,
.train-name .car-number {
  display: inline-block;
  width: 1.4em;
  text-align: center;
  border-radius: 0.7em;
  background-color: #444;
  color: white;
}

.station-icon .fill {
  fill: var(--station-color);
}
.station-icon .outline {
  fill: var(--station-outline);
}

.portal-icon .fill {
  fill: var(--portal-color);
}
.portal-icon .outline {
  fill: var(--portal-outline);
}

.signal-icon.green .light {
  fill: var(--signal-green);
}
.signal-icon.yellow .light {
  fill: var(--signal-yellow);
}
.signal-icon.red .light {
  fill: var(--signal-red);
}
.signal-icon .frame {
  fill: var(--signal-outline);
}

.train {
  stroke: var(--train-color);
}
.train.lead-car {
  stroke: var(--lead-car-color);
}
.head-icon path {
  fill: var(--lead-car-color);
}

.coords-control {
  font-family: var(--ui-font);
  font-size: 16px;
  font-weight: 500;

  background-color: white;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.65);
  border-radius: 4px;
  padding: 2px 4px;
}

.coords-control .icon {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 24px;
  margin-right: 4px;
  transform: translate(2px, 2px);
}

.coords-control .center-x,
.coords-control .center-z,
.coords-control .cursor-x,
.coords-control .cursor-z {
  display: inline-block;
  padding: 0 5px;
}

.leaflet-control-ctm:not(.leaflet-control-expanded) .leaflet-control-body,
.leaflet-control-layers:not(.leaflet-control-layers-expanded) .leaflet-control-layers-list {
  display: none;
}
.leaflet-control-toggle,
.leaflet-control-layers-toggle {
  display: block;
  width: 36px;
  height: 36px;
  background-position: 50% 50%;
  background-size: 32px 32px;
}
.leaflet-control-ctm {
  margin-top: 8px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.4);
  background: #fff;
  border-radius: 5px;
}
.leaflet-control-expanded,
.leaflet-control-layers-expanded {
  padding: 6px;
}

.leaflet-control-layers-separator {
  margin-top: 5px;
  margin-bottom: 5px;
}
.leaflet-control-layers-toggle {
  background-image: url(../icons/layers.svg);
}
.leaflet-control-ctm label,
.leaflet-control-layers label {
  font-family: var(--ui-font);
  font-size: 14px;
}
.leaflet-control-layers input[type="radio"],
.leaflet-control-layers input[type="checkbox"] {
  display: none;
}
.leaflet-control-layers input[type="radio"] + span,
.leaflet-control-layers input[type="checkbox"] + span {
  display: inline-block;
  width: 100%;
  border-radius: 2px;
  padding: 0 5px;
  margin-top: 2px;
}
.leaflet-control-layers-overlays label input + span {
  border-radius: 0;
}
.leaflet-control-layers-overlays label:first-child input + span {
  border-top-left-radius: 2px;
  border-top-right-radius: 2px;
}
.leaflet-control-layers-overlays label:last-child input + span {
  border-bottom-left-radius: 2px;
  border-bottom-right-radius: 2px;
}
.leaflet-control-layers input[type="radio"] + span:hover,
.leaflet-control-layers input[type="checkbox"] + span:hover {
  cursor: pointer;
  background-color: #ccc;
}
.leaflet-control-layers input[type="radio"]:checked + span,
.leaflet-control-layers input[type="checkbox"]:checked + span {
  background-color: #888;
  color: white;
  font-weight: bold;
}

.leaflet-control-train-list-toggle {
  background-image: url(../icons/trains.svg);
}
.leaflet-control-station-list-toggle {
  background-image: url(../icons/stations.svg);
}

.leaflet-control-scrollbar {
  overflow-y: scroll;
  overflow-x: hidden;
  padding-right: 5px;
}

.leaflet-right .leaflet-control {
  float: right;
}
.ctm-station-list .station,
.ctm-train-list .train {
  font-family: var(--ui-font);
  font-size: 14px;
  display: block;
  border-radius: 2px;
  padding: 0 5px;
  margin-top: 2px;
}
.ctm-station-list .station:hover,
.ctm-train-list .train:hover {
  cursor: pointer;
  background-color: #ccc;
}

.leaflet-top {
  top: 12px;
}
.leaflet-bottom {
  bottom: 12px;
}
.leaflet-left {
  left: 12px;
}
.leaflet-right {
  right: 12px;
}

/* ---- Selected train route ---------------------------------------------- */

.route-leg {
  stroke: var(--route-color);
  stroke-width: 6;
  stroke-opacity: 0.9;
  stroke-linecap: round;
  fill: none;
}

/* A dark casing around the route line. The highlight colour alone only reaches
   ~2.5:1 against the default grey map background, short of the 3:1 WCAG asks
   for graphical objects; the outline keeps it legible on any backdrop. Applied
   to the pane rather than each path so it costs one filter, not one per leg. */
.leaflet-routes-pane {
  filter: drop-shadow(0 0 2px rgba(0, 0, 0, 0.9));
}

/* Fade the rest of the network so the highlighted route stands out. */
body.ctm-route-active .track {
  opacity: 0.3;
}

.train.selected {
  filter: drop-shadow(0 0 4px var(--route-color));
}

.ctm-train-list .train.selected {
  background-color: #888;
  color: white;
  font-weight: bold;
}

/* ---- Timetable control -------------------------------------------------- */

.leaflet-control-timetable-toggle {
  background-image: url(../icons/clock.svg);
}

.ctm-timetable {
  width: 580px;
  max-width: 92vw;
  overflow-y: auto;
  overflow-x: hidden;
}

.ctm-timetable-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.ctm-timetable-title {
  flex: 1;
  font-family: var(--ui-font);
  font-weight: bold;
  font-size: 17px;
}

.ctm-timetable-btn {
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 2px 8px;
  border: 1px solid #bbb;
  background: #f4f4f4;
  border-radius: 3px;
  cursor: pointer;
}
.ctm-timetable-btn:hover {
  background: #e4e4e4;
}
.ctm-timetable-close {
  padding: 2px 6px;
}

.ctm-timetable-search,
.ctm-editor-name,
.ctm-editor-filter {
  display: block;
  width: 100%;
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 3px 6px;
  margin-bottom: 6px;
  border: 1px solid #ccc;
  border-radius: 3px;
}

/* ---- Combined station editor -------------------------------------------- */

.ctm-timetable-editor {
  background: #f0f0f0;
  border-radius: 4px;
  padding: 8px;
  margin-bottom: 8px;
}

.ctm-editor-label {
  font-family: var(--ui-font);
  font-weight: bold;
  font-size: 12px;
  margin-bottom: 6px;
}

.ctm-editor-picker {
  max-height: 160px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 3px;
  padding: 4px;
  margin-bottom: 6px;
}

.ctm-editor-option {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ui-font);
  font-size: 12px;
  padding: 1px 2px;
  cursor: pointer;
}
.ctm-editor-option:hover {
  background: #eee;
}

.ctm-editor-empty {
  font-family: var(--ui-font);
  font-size: 12px;
  color: #777;
  padding: 4px;
}

.ctm-editor-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.ctm-editor-error {
  flex: 1;
  font-family: var(--ui-font);
  font-size: 11px;
  color: #b00020;
}

/* ---- Departure boards --------------------------------------------------- */

.ctm-board {
  background: var(--board-background);
  color: var(--board-text);
  font-family: var(--ui-font);
  border-radius: 6px;
  padding: 10px 14px;
  margin-bottom: 14px;
}

.ctm-board-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 17px;
  font-weight: bold;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding-bottom: 8px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}
.ctm-board-title > span:first-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctm-board-tag {
  flex: none;
  font-size: 9px;
  font-weight: normal;
  letter-spacing: 0.06em;
  color: var(--board-header);
  background: rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 1px 5px;
}

.ctm-board-delete {
  margin-left: auto;
  flex: none;
  background: none;
  border: none;
  color: var(--board-header);
  font-size: 11px;
  padding: 0 2px;
  cursor: pointer;
}
.ctm-board-delete:hover {
  color: var(--board-text);
}

.ctm-board-head,
.ctm-board-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr) minmax(0, 1.2fr) 68px;
  gap: 10px;
  font-size: 14px;
  padding: 4px 0;
}

.ctm-board-head {
  color: var(--board-header);
  font-size: 11px;
  letter-spacing: 0.08em;
  padding-top: 6px;
}

/* Rows are <button> for keyboard access, so undo the UA button styling. */
.ctm-board-row {
  width: 100%;
  font: inherit;
  font-size: 14px;
  color: inherit;
  background: none;
  border: none;
  text-align: left;
  padding: 7px 6px;
  border-radius: 3px;
  cursor: pointer;
}
.ctm-board-row:hover {
  background: rgba(255, 255, 255, 0.08);
}
.ctm-board-row:active {
  background: rgba(255, 255, 255, 0.14);
}
.ctm-board-row > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctm-board-dest {
  font-weight: bold;
}

.ctm-board-time {
  color: var(--board-time);
  font-weight: bold;
  font-size: 15px;
  /* The countdown reflows twice a second; fixed-width digits stop it jittering
     if the configured UI font is proportional. */
  font-variant-numeric: tabular-nums;
}

.ctm-board-none {
  font-size: 13px;
  color: var(--board-header);
  padding: 6px 0;
}

.ctm-board-empty {
  font-family: var(--ui-font);
  font-size: 13px;
  color: #666;
  padding: 10px 4px;
}

/* ---- Focus visibility --------------------------------------------------- */

/* Panel chrome sits on white; the board sits on dark slate. Two focus colours
   so the ring stays visible against both. */
.ctm-timetable-btn:focus-visible,
.ctm-timetable-search:focus-visible,
.ctm-editor-name:focus-visible,
.ctm-editor-filter:focus-visible,
.ctm-editor-option input:focus-visible,
.leaflet-control-toggle:focus-visible,
.leaflet-control-layers-toggle:focus-visible {
  outline: 2px solid #2f6fd0;
  outline-offset: 1px;
}

.ctm-board-row:focus-visible,
.ctm-board-delete:focus-visible {
  outline: 2px solid var(--board-time);
  outline-offset: -1px;
}

.ctm-editor-field-label {
  display: block;
  font-family: var(--ui-font);
  font-size: 11px;
  font-weight: bold;
  margin-bottom: 2px;
}
