/* ==========================================================================
   APP SHELL
   Layout and components for the top bar, tabs, route generator, auth screen
   and account settings. Loaded after the legacy stylesheets, and uses the
   theme tokens from style.css so light and dark mode both work.

   The Tube identity lives in a few places only: the roundel, real line
   colours and the LondonTube typeface for headings. Everything else is a
   plain, quiet surface so the route and the map carry the page.
   ========================================================================== */

:root {
  --shell-radius: 12px;
  --shell-radius-sm: 8px;
  --shell-shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --shell-topbar-height: 60px;
  --shell-focus: 0 0 0 3px rgba(0, 25, 168, 0.35);
  --roundel-red: #DC241F;
  --roundel-blue: #0019A8;
}

body[data-dark-mode="true"] {
  --text-muted: #9A9990;
  --shell-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shell-focus: 0 0 0 3px rgba(122, 162, 255, 0.5);
}

@media (prefers-color-scheme: dark) {
  body:not([data-dark-mode="false"]) {
    --text-muted: #9A9990;
    --shell-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shell-focus: 0 0 0 3px rgba(122, 162, 255, 0.5);
  }
}

[hidden] {
  display: none !important;
}

body {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

:focus-visible {
  outline: none;
  box-shadow: var(--shell-focus);
}

.skip-link {
  transform: translateY(-150%);
}

.skip-link:focus {
  z-index: 1000;
  transform: none;
}

/* --------------------------------------------------------------------------
   Neutralise legacy decoration
   -------------------------------------------------------------------------- */

.card,
.glass-card,
.platform-panel,
.stat-card,
.results-box,
.historical-intro-card,
.historical-controls-card,
.historical-save-card,
.historical-timeline-container {
  background: var(--surface);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: var(--shell-shadow);
}

.card,
.platform-panel {
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.platform-panel::before,
.platform-panel::after,
.station-sign::before,
.station-sign::after,
.ticket-machine::before,
.departure-board::before {
  content: none;
  display: none;
}

.station-sign {
  background: none;
  color: var(--text-primary);
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0 0 1rem;
  text-align: left;
  text-transform: none;
  letter-spacing: 0;
  font-family: 'LondonTube', 'DM Sans', sans-serif;
  font-weight: 700;
  font-size: 1.35rem;
  line-height: 1.25;
}

h3.station-sign {
  font-size: 1.15rem;
}

.ticket-machine,
.departure-board {
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
  margin: 0;
  overflow: visible;
}

.ticket-machine input,
.ticket-machine select,
.ticket-machine textarea {
  padding: 0.6rem 0.75rem;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 400;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius-sm);
}

.ticket-machine label {
  color: var(--text-primary);
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
}

.intro-header h2,
.historical-intro-card .station-sign {
  color: var(--text-primary);
  text-shadow: none;
  font-size: 1.5rem;
}

.intro-description {
  color: var(--text-secondary);
  opacity: 1;
}

/* --------------------------------------------------------------------------
   Form controls
   -------------------------------------------------------------------------- */

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.6rem 0.75rem;
  font: inherit;
  font-size: 1rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius-sm);
  box-shadow: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--roundel-blue);
  box-shadow: var(--shell-focus);
  outline: none;
}

/* Only flag fields as invalid after the user has interacted with them */
input:user-invalid,
textarea:user-invalid {
  border-color: var(--roundel-red);
}

.control-group {
  margin-bottom: 1rem;
}

.control-group label,
.mode-choice legend {
  padding: 0;
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
  text-transform: none;
  letter-spacing: 0;
}

.control-group small,
.form-help {
  display: block;
  margin-top: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Checkbox rows */
.check-row {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.95rem;
  color: var(--text-primary);
  cursor: pointer;
}

.check-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin: 0.15rem 0 0;
  flex-shrink: 0;
  accent-color: var(--roundel-blue);
}

/* Switches: a checkbox drawn as a toggle, with its label alongside */
.switch-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.6rem 0;
  cursor: pointer;
}

.switch-input {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex-shrink: 0;
  width: 40px;
  height: 24px;
  margin: 0.1rem 0 0;
  border-radius: 999px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.switch-input::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transition: transform 0.15s ease;
}

.switch-input:checked {
  background: var(--roundel-blue);
  border-color: var(--roundel-blue);
}

.switch-input:checked::after {
  transform: translateX(16px);
}

.switch-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.switch-title {
  font-weight: 600;
  color: var(--text-primary);
}

.switch-help {
  font-size: 0.85rem;
  font-weight: 400;
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: auto;
  min-height: 44px;
  margin: 0;
  padding: 0.6rem 1.1rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: 0;
  text-transform: none;
  text-decoration: none;
  color: #fff;
  background: var(--roundel-red);
  border: 1px solid transparent;
  border-radius: var(--shell-radius-sm);
  box-shadow: none;
  cursor: pointer;
  transform: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

/* Mouse clicks shouldn't leave a focus ring; keyboard focus still shows one */
.btn:focus:not(:focus-visible) {
  outline: none;
  box-shadow: none;
}

.btn:hover {
  background: #B71C17;
  box-shadow: none;
  transform: none;
}

.btn-primary {
  color: #fff;
  background: var(--roundel-red);
}

.btn-secondary,
.btn-quiet {
  color: var(--text-primary);
  background: var(--surface);
  border-color: var(--border-color);
}

.btn-secondary:hover,
.btn-quiet:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
}

.btn-quiet {
  border-color: transparent;
  background: transparent;
}

.btn-danger {
  color: #fff;
  background: #B3261E;
}

.btn-danger:hover {
  background: #8C1D18;
}

.btn-small {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  font-size: 0.875rem;
}

.btn-block {
  width: 100%;
}

/* Disabled buttons keep readable text and just fade */
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border-color: var(--border-color);
}

.link-button {
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--roundel-blue);
  background: none;
  border: 0;
  text-decoration: underline;
  cursor: pointer;
}

body[data-dark-mode="true"] .link-button,
body[data-dark-mode="true"] a {
  color: #8FB3FF;
}

@media (prefers-color-scheme: dark) {
  body:not([data-dark-mode="false"]) .link-button,
  body:not([data-dark-mode="false"]) a {
    color: #8FB3FF;
  }
}

/* --------------------------------------------------------------------------
   Top bar
   -------------------------------------------------------------------------- */

header.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 0;
  margin: 0;
  text-align: left;
  color: var(--text-primary);
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  box-shadow: none;
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 1200px;
  min-height: var(--shell-topbar-height);
  margin: 0 auto;
  padding: 0.5rem 1.5rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text-primary);
  text-decoration: none;
  flex-shrink: 0;
}

body[data-dark-mode="true"] .brand {
  color: var(--text-primary);
}

.brand-name {
  font-family: 'LondonTube', 'DM Sans', sans-serif;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

/* The roundel is drawn in CSS: a red ring crossed by a blue bar */
.brand-roundel {
  position: relative;
  display: inline-block;
  width: 30px;
  height: 30px;
  border: 5px solid var(--roundel-red);
  border-radius: 50%;
  font-size: 0;
  color: transparent;
  background: transparent;
  box-shadow: none;
}

.brand-roundel::after {
  content: '';
  position: absolute;
  top: 50%;
  left: -9px;
  right: -9px;
  height: 7px;
  transform: translateY(-50%);
  background: var(--roundel-blue);
}

.topbar-link {
  margin-left: auto;
  font-weight: 600;
  color: var(--text-secondary);
  text-decoration: none;
}

.topbar-link:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* City switcher */
.app-topbar .city-switcher {
  margin: 0;
  z-index: 60;
}

.app-topbar .city-current {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 36px;
  padding: 0.3rem 0.7rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  box-shadow: none;
}

.app-topbar .city-current:hover {
  background: var(--bg-tertiary);
}

.app-topbar .city-name {
  display: inline;
}

.app-topbar .city-flag {
  font-size: 1.05rem;
  line-height: 1;
}

.city-arrow {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

/* Runs / Pub crawls segmented control */
.app-topbar .mode-switcher {
  display: inline-flex;
  flex-direction: row;
  align-items: center;
  gap: 2px;
  margin: 0 0 0 auto;
  padding: 3px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  order: 0;
}

.app-topbar .mode-btn {
  min-height: 32px;
  margin: 0;
  padding: 0.3rem 0.9rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  border-radius: 999px;
  box-shadow: none;
  cursor: pointer;
}

.app-topbar .mode-btn.active,
.pub-mode .app-topbar .mode-btn.active {
  color: #fff;
  background: var(--roundel-blue);
  box-shadow: none;
}

.pub-mode .app-topbar .mode-btn.active {
  background: #7A3E12;
}

.account-menu {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 0;
}

.account-name {
  max-width: 16rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.app-topbar #logoutBtn {
  min-height: 36px;
  padding: 0.35rem 0.8rem;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Section tabs
   -------------------------------------------------------------------------- */

.app-tabs {
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
}

.app-tabs-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

.app-tabs .mode-tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  scrollbar-width: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  box-shadow: none;
}

.app-tabs .mode-tabs::-webkit-scrollbar {
  display: none;
}

.app-tabs .nav-tab {
  flex: 0 0 auto;
  width: auto;
  max-width: none;
  position: relative;
  min-height: 48px;
  min-width: 0;
  margin: 0;
  padding: 0.75rem 0.9rem;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  white-space: nowrap;
  color: var(--text-secondary);
  background: none;
  border: 0;
  border-radius: 0;
  box-shadow: none;
  transform: none;
  cursor: pointer;
}

.app-tabs .nav-tab::before {
  content: none;
}

.app-tabs .nav-tab::after {
  content: '';
  position: absolute;
  left: 0.6rem;
  right: 0.6rem;
  bottom: 0;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
}

.app-tabs .nav-tab:hover {
  color: var(--text-primary);
  background: none;
  transform: none;
}

.app-tabs .nav-tab.active {
  color: var(--text-primary);
  background: none;
  box-shadow: none;
}

.app-tabs .nav-tab.active::after {
  background: var(--roundel-red);
}

.pub-mode .app-tabs .nav-tab.active::after {
  background: #B8860B;
}

/* --------------------------------------------------------------------------
   Page
   -------------------------------------------------------------------------- */

.app-main {
  max-width: 1200px;
  padding: 1.25rem 1.5rem 3rem;
}

.app-main:focus {
  outline: none;
  box-shadow: none;
}

.page-title {
  margin: 0 0 1rem;
  font-family: 'LondonTube', 'DM Sans', sans-serif;
  font-size: 1.6rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
  text-align: left;
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.tab-title {
  margin: 0 0 1rem;
  font-size: 1.3rem;
  color: var(--text-primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* --------------------------------------------------------------------------
   Route generator
   -------------------------------------------------------------------------- */

.gen-layout {
  display: grid;
  grid-template-columns: minmax(320px, 400px) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}

.gen-controls {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.gen-card {
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: var(--shell-shadow);
}

.gen-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.gen-field-row .control-group {
  margin-bottom: 0;
}

.distance-reference {
  margin: 0.5rem 0 1rem;
  padding: 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
  background: none;
  border: 0;
}

#distanceReference {
  color: var(--text-secondary);
}

/* Start and finish: a compact segmented choice */
.mode-choice {
  margin: 0 0 0.5rem;
  padding: 0;
  border: 0;
  min-width: 0;
}

.mode-choice-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 4px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius-sm);
}

.mode-choice-option {
  position: relative;
  display: block;
  margin: 0;
  cursor: pointer;
}

.mode-choice-option input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.mode-choice-option span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 0.3rem 0.25rem;
  font-size: 0.85rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.15;
  color: var(--text-secondary);
  border-radius: 6px;
}

.mode-choice-option input:checked + span {
  color: var(--text-primary);
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12);
}

.mode-choice-option input:focus-visible + span {
  box-shadow: var(--shell-focus);
}

.gen-switches {
  margin: 0.5rem 0 1rem;
  border-top: 1px solid var(--border-light);
  padding-top: 0.25rem;
}

.visited-stations-info {
  margin: -0.25rem 0 0.25rem 3.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

#lineFocusOptions {
  margin: 0.25rem 0 0.5rem 3.25rem;
}

.btn-generate:focus-visible {
  box-shadow: var(--shell-focus);
}

.btn-generate {
  width: 100%;
  min-height: 52px;
  font-size: 1.05rem;
}

#loadingMessage {
  margin-top: 0.5rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  text-align: center;
}

.info-message {
  margin-top: 0.75rem;
  padding: 0.75rem;
  font-size: 0.9rem;
  border-width: 1px;
}

/* Filters panel */
.filters-panel {
  padding: 0;
}

.filters-panel > summary {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  padding: 1rem 1.25rem;
  list-style: none;
  cursor: pointer;
}

.filters-panel > summary::-webkit-details-marker {
  display: none;
}

.filters-panel > summary::after {
  content: '▾';
  margin-left: auto;
  color: var(--text-secondary);
  transition: transform 0.15s ease;
}

.filters-panel[open] > summary::after {
  transform: rotate(180deg);
}

.filters-title {
  font-weight: 700;
  color: var(--text-primary);
}

.filters-summary {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.filter-section {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-light);
}

.filter-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.filter-section h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
}

.selection-summary {
  margin: 0.75rem 0 0;
  padding: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: none;
  border: 0;
}

.selection-summary p {
  margin: 0;
  color: var(--text-secondary);
}

.line-presets,
.area-presets {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
}

.area-presets {
  margin-bottom: 0.75rem;
}

.preset-btn,
.select-all-btn,
.borough-group-action,
.postcode-group-action {
  min-height: 30px;
  padding: 0.2rem 0.65rem;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  cursor: pointer;
}

.preset-btn:hover,
.select-all-btn:hover,
.borough-group-action:hover,
.postcode-group-action:hover {
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border-color: var(--border-color);
}

.select-all-btn.deselect {
  color: var(--text-secondary);
  border-color: var(--border-color);
}

/* Line, zone and area chips. --toggle-color is set per chip by main.js */
.enhanced-line-toggles {
  display: block;
  margin: 0;
}

.enhanced-line-group {
  margin-bottom: 1rem;
}

.enhanced-line-group:last-child {
  margin-bottom: 0;
}

.enhanced-group-header-container,
.enhanced-borough-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  padding: 0;
  border: 0;
}

.enhanced-group-header,
.enhanced-borough-group-title {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.select-all-buttons,
.enhanced-borough-group-actions {
  display: flex;
  gap: 0.35rem;
}

.enhanced-lines-grid,
.enhanced-zones-grid,
.enhanced-borough-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.enhanced-borough-toggles {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.enhanced-borough-group {
  margin: 0;
}

.enhanced-line-button,
.enhanced-zone-button,
.enhanced-borough-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  min-height: 34px;
  width: auto;
  margin: 0;
  padding: 0.25rem 0.7rem 0.25rem 0.5rem;
  font: inherit;
  font-size: 0.85rem;
  text-align: left;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  box-shadow: none;
  transform: none;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.enhanced-line-button:hover,
.enhanced-zone-button:hover,
.enhanced-borough-toggle:hover {
  border-color: var(--text-muted);
  box-shadow: none;
  transform: none;
}

.enhanced-line-button.selected,
.enhanced-zone-button.selected,
.enhanced-borough-toggle.selected {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--toggle-color, var(--roundel-blue)) 12%, var(--surface));
  border-color: var(--toggle-color, var(--roundel-blue));
  box-shadow: none;
  transform: none;
}

.enhanced-line-icon,
.enhanced-borough-indicator {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--toggle-color);
  opacity: 0.35;
}

.enhanced-borough-indicator {
  background-color: var(--toggle-color) !important;
}

.selected > .enhanced-line-icon,
.selected .enhanced-borough-indicator {
  opacity: 1;
}

.enhanced-line-name,
.enhanced-borough-name,
.enhanced-zone-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: inherit;
  line-height: 1.2;
}

.enhanced-zone-circle {
  width: 12px;
  height: 12px;
  margin: 0;
  flex-shrink: 0;
  opacity: 0.35;
}

.enhanced-zone-button.selected .enhanced-zone-circle {
  opacity: 1;
}

.enhanced-zone-number {
  display: none;
}

.enhanced-borough-header {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

.enhanced-borough-type,
.enhanced-borough-stats {
  display: none;
}

/* Output column */
.gen-output {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.gen-map.map-container,
#map.gen-map {
  height: 420px;
  margin: 0;
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: var(--shell-shadow);
  overflow: hidden;
}

.route-empty-state {
  padding: 1rem 1.25rem;
  font-size: 0.95rem;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--shell-radius);
}

.route-empty-state p {
  margin: 0;
}

.enhanced-generation-status .status-card {
  padding: 1rem 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
}

.status-main {
  font-weight: 600;
  color: var(--text-primary);
}

.status-distance,
.status-explanation {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Results */
.gen-output .results-box {
  margin: 0;
  padding: 1.25rem;
  text-align: left;
}

/* Stations as a line diagram: a vertical rule with a stop on each station */
#routeStations {
  position: relative;
  margin: 0 0 1.25rem;
  padding-left: 1.75rem;
}

#routeStations::before {
  content: '';
  position: absolute;
  left: 0.55rem;
  top: 0.9rem;
  bottom: 0.9rem;
  width: 4px;
  border-radius: 2px;
  background: var(--roundel-red);
}

.station-result {
  position: relative;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.25rem 0.75rem;
  padding: 0.45rem 0;
  border: 0;
  text-align: left;
}

.station-result::before {
  content: '';
  position: absolute;
  left: -1.55rem;
  top: 50%;
  width: 14px;
  height: 14px;
  transform: translateY(-50%);
  border-radius: 50%;
  background: var(--surface);
  border: 3px solid var(--roundel-red);
  box-sizing: border-box;
}

.station-result:first-of-type::before,
.station-result:last-of-type::before {
  width: 18px;
  height: 18px;
  left: -1.67rem;
  background: var(--roundel-red);
}

.station-result h2 {
  margin: 0;
  font-family: 'LondonTube', 'DM Sans', sans-serif;
  font-size: 1.2rem;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text-primary);
}

.station-lines {
  display: inline-flex;
  justify-content: flex-start;
  gap: 4px;
}

.station-lines .line-block {
  width: 12px;
  height: 12px;
}

#routeStations .route-arrow {
  display: none;
}

.route-header.loop-route {
  margin: 0 0 0.75rem -1.75rem;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 0;
  border-radius: var(--shell-radius-sm);
}

.route-header.loop-route p {
  margin: 0.15rem 0 0;
  color: var(--text-secondary);
}

.loop-return-indicator {
  margin: 0.25rem 0;
  padding: 0.25rem 0;
  background: none;
  border: 0;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.return-arrow,
.return-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

#routeInfo h3 {
  margin: 0 0 0.5rem;
  font-size: 1rem;
  text-align: left;
  color: var(--text-primary);
}

#routeInfo .stat-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 0.9rem;
}

#routeInfo .stat-label {
  color: var(--text-secondary);
  text-transform: none;
  letter-spacing: 0;
  font-size: 0.9rem;
}

#routeInfo .stat-value {
  font-weight: 600;
  text-align: right;
  color: var(--text-primary);
}

.estimated-times {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.25rem;
  margin: 0.75rem 0 0;
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  background: var(--bg-secondary);
  border-radius: var(--shell-radius-sm);
}

.rail-benchmark-container {
  margin-top: 1rem;
}

/* The rail benchmark injects its own styles (railBenchmark.js); bring the
   card in line with the rest of the result instead of a navy panel */
.gen-output .rail-benchmark-card {
  margin: 0;
  padding: 1rem 1.1rem;
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: none;
}

.gen-output .rail-benchmark-card .benchmark-title {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  color: var(--text-primary);
}

.gen-output .rail-benchmark-card .benchmark-challenge,
.gen-output .rail-benchmark-card .journey-segment,
.gen-output .rail-benchmark-card .journey-leg,
.gen-output .rail-benchmark-card .alt-route {
  color: var(--text-primary);
  background: var(--surface);
  border-color: var(--border-color);
}

.gen-output .rail-benchmark-card .challenge-time {
  color: var(--text-primary);
}

.gen-output .rail-benchmark-card h4,
.gen-output .rail-benchmark-card p,
.gen-output .rail-benchmark-card span {
  color: inherit;
}

.route-export-section {
  margin-top: 1.25rem;
  padding: 1rem 0 0;
  text-align: left;
  background: none;
  border: 0;
  border-top: 1px solid var(--border-light);
  border-radius: 0;
}

.route-export-section h3 {
  margin: 0 0 0.25rem;
  font-size: 1rem;
  color: var(--text-primary);
}

.route-export-section > p {
  margin: 0 0 0.75rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.route-options {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.9rem;
}

.export-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.export-buttons .btn {
  width: auto;
  margin: 0;
}

.export-status:empty {
  display: none;
}

.export-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Auth, cities hub and shared route pages
   -------------------------------------------------------------------------- */

.auth-main {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 1rem 4rem;
}

.auth-intro {
  max-width: 28rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

.auth-intro h1,
.page-intro h1 {
  margin: 0 0 0.5rem;
  font-family: 'LondonTube', 'DM Sans', sans-serif;
  font-size: 2rem;
  line-height: 1.15;
  color: var(--text-primary);
  background: none;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.auth-intro p,
.page-intro p {
  margin: 0;
  color: var(--text-secondary);
}

.auth-container {
  width: 100%;
  max-width: 26rem;
  margin: 0;
  padding: 1.75rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: var(--shell-shadow);
}

.auth-container h2 {
  margin: 0 0 1.25rem;
  font-size: 1.35rem;
  color: var(--text-primary);
}

.auth-form {
  padding: 0;
  background: none;
  border: 0;
  box-shadow: none;
}

.auth-form .btn {
  margin-top: 0.5rem;
}

.auth-toggle {
  margin: 1.25rem 0 0;
  text-align: center;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.guest-option {
  margin-top: 1.25rem;
  padding-top: 1.25rem;
  text-align: center;
  border-top: 1px solid var(--border-light);
}

.guest-option small {
  display: block;
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.consent-fieldset {
  margin: 0.5rem 0 1rem;
  padding: 0;
  border: 0;
}

.consent-fieldset legend {
  margin-bottom: 0.5rem;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.consent-checkbox {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--text-primary);
  cursor: pointer;
}

.consent-checkbox input[type="checkbox"] {
  margin-top: 0.1rem;
}

.cities-main,
.shared-route-main {
  padding: 2rem 0 4rem;
}

.page-intro {
  margin-bottom: 2rem;
}

.section-label {
  margin: 0 0 1rem;
  font-size: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

/* --------------------------------------------------------------------------
   Guests
   -------------------------------------------------------------------------- */

.guest-gate {
  padding: 1.5rem;
}

.guest-gate h2 {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
}

.guest-gate p {
  margin: 0 0 1rem;
  color: var(--text-secondary);
}

.guest-gate-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

body.is-guest .tab-content > .guest-gate ~ *,
body.is-guest [data-requires-account] {
  display: none !important;
}

body:not(.is-guest) .guest-gate,
.guest-only {
  display: none;
}

body.is-guest .guest-only {
  display: block;
}

/* --------------------------------------------------------------------------
   Account settings
   -------------------------------------------------------------------------- */

.settings-card {
  padding: 1.25rem 1.5rem;
}

.settings-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1.1rem;
  color: var(--text-primary);
}

.settings-card h4 {
  margin: 1rem 0 0.25rem;
  font-size: 0.95rem;
  color: var(--text-primary);
}

.settings-card p {
  color: var(--text-secondary);
}

.account-info {
  margin: 0;
}

.account-info .info-item {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border-light);
}

.account-info .info-item:last-child {
  border-bottom: 0;
}

.account-info dt {
  color: var(--text-secondary);
}

.account-info dd {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
  text-align: right;
  overflow-wrap: anywhere;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem 1.5rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-row:last-of-type {
  border-bottom: 0;
}

.settings-row h4 {
  margin: 0;
}

.settings-row p {
  margin: 0.15rem 0 0;
  font-size: 0.9rem;
}

.settings-row .check-row {
  flex: 1 1 18rem;
}

.danger-zone h4 {
  color: #B3261E;
}

.current-theme {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1rem 0 0;
  color: var(--text-secondary);
}

.strava-btn {
  color: #fff;
  background: #FC4C02;
}

.strava-btn:hover {
  background: #D94102;
}

.sync-status {
  font-size: 0.9rem;
}

/* --------------------------------------------------------------------------
   Leaderboard and other tabs
   -------------------------------------------------------------------------- */

/* The participation switch had a visible native checkbox beside it */
.toggle-setting input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
}

.toggle-setting input[type="checkbox"]:focus-visible + .toggle-switch-small {
  box-shadow: var(--shell-focus);
}

.coming-soon ul {
  display: inline-block;
  margin: 0 auto;
  padding-left: 1.25rem;
  text-align: left;
  font-style: normal;
}

.coming-soon h4 {
  font-style: normal;
}

.map-controls {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.map-controls label {
  margin: 0;
  font-weight: 600;
}

.map-controls select {
  width: auto;
  min-width: 12rem;
}

.historical-generate-section {
  margin-top: 1rem;
}

/* Status colours need darker text to read on light backgrounds, and lighter
   text on dark ones */
body[data-dark-mode="true"] .warning-text { color: #FFC266; }
body[data-dark-mode="true"] .error-text { color: #FF8A80; }
body[data-dark-mode="true"] .success-text { color: #81C995; }
body[data-dark-mode="true"] .info-text { color: #8AB4F8; }

@media (prefers-color-scheme: dark) {
  body:not([data-dark-mode="false"]) .warning-text { color: #FFC266; }
  body:not([data-dark-mode="false"]) .error-text { color: #FF8A80; }
  body:not([data-dark-mode="false"]) .success-text { color: #81C995; }
  body:not([data-dark-mode="false"]) .info-text { color: #8AB4F8; }
}

/* Modals */
.modal-content {
  background: var(--surface);
  color: var(--text-primary);
  border-radius: var(--shell-radius);
}

/* --------------------------------------------------------------------------
   Small screens
   -------------------------------------------------------------------------- */

@media (max-width: 900px) {
  .gen-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  #map.gen-map {
    height: 320px;
  }
}

@media (max-width: 720px) {
  .topbar-inner {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
  }

  .brand-name {
    font-size: 1.15rem;
  }

  .app-topbar .mode-switcher {
    order: 3;
    flex: 1 1 100%;
    margin: 0;
  }

  .app-topbar .mode-btn {
    flex: 1;
  }

  .account-menu {
    margin-left: auto;
  }

  .account-name {
    display: none;
  }

  .app-tabs-inner {
    padding: 0 0.5rem;
  }

  .app-tabs .nav-tab {
    padding: 0.7rem 0.7rem;
    font-size: 0.9rem;
  }

  .app-main,
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
  }

  .page-title {
    font-size: 1.3rem;
  }

  .auth-main {
    padding-top: 1.5rem;
  }

  .auth-intro h1,
  .page-intro h1 {
    font-size: 1.6rem;
  }

  .auth-container {
    padding: 1.25rem;
  }

  /* Legacy forms used fixed column widths that overflowed narrow screens */
  .controls-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .card,
  .platform-panel {
    padding: 1.1rem;
  }
}

@media (max-width: 380px) {
  .mode-choice-options {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* --------------------------------------------------------------------------
   Consistency fixes for older tabs
   -------------------------------------------------------------------------- */

/* Several tabs coloured their own headings; keep headings neutral */
.tab-content .guest-gate h2,
.tab-content h2,
.tab-content h3.station-sign,
.historical-controls-card h3 {
  color: var(--text-primary);
}

.historical-generate-btn {
  width: 100%;
  justify-content: center;
  min-height: 52px;
  padding: 0.75rem 1.25rem;
  font-size: 1.05rem;
  color: #fff;
  background: var(--roundel-red);
  border-radius: var(--shell-radius-sm);
  box-shadow: none;
}

.historical-generate-btn:not(:disabled):hover {
  background: #B71C17;
  transform: none;
  box-shadow: none;
}

.historical-generate-btn:disabled {
  opacity: 0.5;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}

.historical-generate-btn .btn-icon,
.historical-generate-btn .btn-sub {
  display: none;
}

.historical-generate-btn .btn-text {
  align-items: center;
}

.account-info,
.current-theme {
  padding: 0;
  background: none;
  border: 0;
}

/* Achievements summary: a neutral panel, not white text on navy */
.achievement-stats-header {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
}

.achievement-stats-header .stat-box {
  background: var(--surface);
}

.achievement-stats-header .stat-value,
.achievement-stats-header .stat-label,
#achievements .achievement-stats-header p {
  color: var(--text-primary);
}

/* "Ran it?" panel under a generated route */
.route-log-panel {
  margin-top: 1.25rem;
  padding: 1rem 1.1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
}

.route-log-intro h3 {
  margin: 0;
  font-size: 1rem;
  color: var(--text-primary);
}

.route-log-intro p {
  margin: 0.2rem 0 0.9rem;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.route-log-fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}

.route-log-form .control-group {
  margin-bottom: 0.75rem;
}

.route-log-done {
  margin: 0;
  font-weight: 600;
  color: var(--text-primary);
}

.route-log-panel .guest-only {
  margin: 0;
  font-size: 0.95rem;
  color: var(--text-secondary);
}

@media (max-width: 480px) {
  .route-log-fields {
    grid-template-columns: 1fr 1fr;
  }

  .route-log-fields .control-group:first-child {
    grid-column: 1 / -1;
  }
}

/* --------------------------------------------------------------------------
   Dialogs and notices (modules/dialog.js)
   -------------------------------------------------------------------------- */

.app-dialog {
  width: min(28rem, calc(100vw - 2rem));
  padding: 1.5rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-radius: var(--shell-radius);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
}

.app-dialog::backdrop {
  background: rgba(16, 20, 32, 0.5);
}

.app-dialog-title {
  margin: 0 0 0.5rem;
  font-size: 1.2rem;
}

.app-dialog-message {
  margin: 0 0 1.25rem;
  color: var(--text-secondary);
}

.app-dialog-require {
  display: block;
  margin: 0 0 1.25rem;
  font-size: 0.95rem;
}

.app-dialog-require input {
  margin-top: 0.4rem;
}

.app-dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.app-notices {
  position: fixed;
  left: 50%;
  bottom: 1.25rem;
  z-index: 10001;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(32rem, calc(100vw - 2rem));
  transform: translateX(-50%);
  pointer-events: none;
}

.app-notice {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 0.9rem;
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--roundel-blue);
  border-radius: var(--shell-radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  /* Clicks pass through to the page; only × is interactive */
  pointer-events: none;
  animation: notice-in 0.18s ease-out;
}

.app-notice p {
  flex: 1;
  margin: 0;
  font-size: 0.95rem;
}

.app-notice-success { border-left-color: #1E7B34; }
.app-notice-warning { border-left-color: #C77700; }
.app-notice-error { border-left-color: var(--roundel-red); }

.app-notice-close {
  pointer-events: auto;
  padding: 0 0.25rem;
  font-size: 1.2rem;
  line-height: 1;
  color: var(--text-secondary);
  background: none;
  border: 0;
  cursor: pointer;
}

@keyframes notice-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .app-notice { animation: none; }
}

/* Progress: line and area lists as a compact grid instead of one long column */
.line-progress-list,
.borough-progress-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.5rem;
  align-items: start;
}

.line-progress-item,
.borough-progress-item {
  margin: 0;
  border-radius: var(--shell-radius-sm);
  box-shadow: none;
  transform: none;
}

.line-progress-item:hover,
.borough-progress-item:hover {
  box-shadow: none;
  transform: none;
}

.line-progress-item .line-header,
.borough-progress-item .borough-header {
  padding: 0.6rem 0.75rem;
}

/* Route summary under the station list */
.route-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  margin: 0;
}

.route-summary-stat {
  display: flex;
  flex-direction: column;
  padding: 0.6rem 0.75rem;
  background: var(--bg-secondary);
  border-radius: var(--shell-radius-sm);
}

.route-summary-value {
  font-size: 1.35rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text-primary);
}

.route-summary-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.route-paces {
  margin: 0.5rem 0 0;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Run history cards: theme tokens instead of fixed light greys */
.run-item {
  color: var(--text-primary);
  background: var(--surface);
  border-color: var(--border-color);
}

.run-details .stat,
.strava-match-indicator.unmatched,
.run-notes {
  color: var(--text-primary);
  background: var(--bg-secondary);
  border-color: var(--border-color);
}

.run-details .stat strong,
.run-notes strong {
  color: var(--text-secondary);
}

.app-dialog .app-dialog-title {
  color: var(--text-primary);
}
