/* Blackpool Information — Shared Styles
   Light/Dark theme, layout, grids, components, tables, accessibility.
   --------------------------------------------------------------- */

/* CSS Reset (condensed) */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html:focus-within { scroll-behavior: smooth; }
body { min-height: 100vh; text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
img, picture, video, canvas, svg { display: block; max-width: 100%; }
input, button, textarea, select { font: inherit; }
a { color: inherit; }
button { cursor: pointer; }

/* Theme variables */
:root {
  --bg: #ffffff;
  --text: #111827;        /* gray-900 */
  --muted: #6b7280;       /* gray-500 */
  --card: #f9fafb;        /* gray-50 */
  --border: #e5e7eb;      /* gray-200 */
  --link: #0ea5e9;        /* sky-500 */
  --accent: #0ea5e9;      /* sky-500 */
  --accent-contrast: #ffffff;
  --shadow: 0 1px 2px rgba(0,0,0,0.06), 0 2px 8px rgba(0,0,0,0.04);

  --radius: 12px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --font-ui: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;

  --container: 1120px;
}

:root[data-theme="dark"] {
  --bg: #0b1220;          /* deep blue-gray */
  --text: #e5e7eb;        /* gray-200 */
  --muted: #a1a1aa;       /* zinc-400 */
  --card: #0f172a;        /* slate-900 */
  --border: #1f2937;      /* gray-800 */
  --link: #38bdf8;        /* sky-400 */
  --accent: #38bdf8;      /* sky-400 */
  --accent-contrast: #06121a;
  --shadow: 0 1px 2px rgba(0,0,0,0.4), 0 8px 24px rgba(0,0,0,0.35);
}

/* Base typography */
html, body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  line-height: 1.55;
  font-size: 16px;
}
h1, h2, h3 {
  line-height: 1.25;
  letter-spacing: -0.01em;
}
h1 { font-size: clamp(2rem, 4vw, 2.75rem); margin-bottom: var(--space-4); }
h2 { font-size: clamp(1.5rem, 2.5vw, 2rem); margin-bottom: var(--space-4); }
h3 { font-size: 1.125rem; margin-bottom: var(--space-3); }
p { margin-bottom: var(--space-4); color: var(--text); }
p.lead { font-size: 1.125rem; color: var(--muted); }
small, .small { font-size: 0.875rem; color: var(--muted); }
code, pre { font-family: var(--font-mono); background: rgba(127,127,127,0.1); padding: 0.1em 0.3em; border-radius: 6px; }

/* Links */
a { color: var(--link); text-decoration: none; }
a:hover, a:focus-visible { text-decoration: underline; }

/* Containers and layout */
.wrap { max-width: var(--container); margin-inline: auto; padding-inline: var(--space-4); }
.grid { display: grid; gap: var(--space-6); }
.grid-2 { grid-template-columns: 1fr; }
.grid-3 { grid-template-columns: 1fr; }
.gap-xl { gap: var(--space-8); }

@media (min-width: 760px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 980px) {
  .grid-3 { grid-template-columns: repeat(3, 1fr); }
}

/* Header */
.site-header {
  position: sticky; top: 0; z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}
.header-inner {
  display: flex; align-items: center; gap: var(--space-4);
  padding: var(--space-3) 0;
}
.brand { display: inline-flex; align-items: center; gap: var(--space-3); color: var(--text); text-decoration: none; }
.brand-mark {
  display: inline-grid; place-items: center; width: 34px; height: 34px;
  background: var(--accent); color: var(--accent-contrast); font-weight: 800; border-radius: 8px;
  box-shadow: 0 2px 10px rgba(14,165,233,0.3);
}
.brand-text { font-weight: 700; letter-spacing: 0.2px; }

.site-nav ul { display: flex; gap: var(--space-4); list-style: none; padding: 0; }
.site-nav a {
  display: inline-block; padding: var(--space-2) var(--space-3); border-radius: 8px; color: var(--text);
}
.site-nav .active a, .site-nav a[aria-current="page"] {
  background: rgba(14,165,233,0.12);
  color: var(--link);
  text-decoration: none;
}

/* Theme toggle */
.theme-toggle {
  margin-left: auto; border: 1px solid var(--border); background: var(--card);
  color: var(--text); border-radius: 999px; padding: 6px 10px; display: inline-flex; align-items: center; gap: 6px;
}
.theme-toggle .sun { display: inline; }
.theme-toggle .moon { display: none; }
:root[data-theme="dark"] .theme-toggle .sun { display: none; }
:root[data-theme="dark"] .theme-toggle .moon { display: inline; }

/* Skip link */
.skip-link {
  position: absolute; top: -40px; left: 0; background: var(--accent); color: var(--accent-contrast);
  padding: 8px 12px; z-index: 1000; border-radius: 0 0 8px 8px;
}
.skip-link:focus { top: 0; }

/* Hero */
.hero {
  padding: var(--space-12) 0 var(--space-10);
  background: linear-gradient(180deg, rgba(14,165,233,0.10), transparent 60%);
}
.hero-sub { padding: var(--space-8) 0 var(--space-8); }
.hero-cta { display: flex; gap: var(--space-3); margin-top: var(--space-3); flex-wrap: wrap; }

.hero-facts {
  margin-top: var(--space-6);
  display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: var(--space-3);
}
@media (min-width: 760px) {
  .hero-facts { grid-template-columns: repeat(4, minmax(0,1fr)); }
}
.fact { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space-3); }
.fact-label { display: block; color: var(--muted); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; }
.fact-value { font-weight: 700; }

/* Cards */
.cards { align-items: stretch; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: var(--space-5); box-shadow: var(--shadow);
}
.card-link { display: block; color: inherit; text-decoration: none; transition: transform .15s ease, box-shadow .15s ease; }
.card-link:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,0.08); text-decoration: none; }
.pill {
  display: inline-block; margin-top: var(--space-2); padding: 4px 10px; border-radius: 999px;
  background: rgba(14,165,233,0.12); color: var(--link); font-size: 0.85rem;
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  padding: 10px 14px; border-radius: 10px; text-decoration: none;
}
.btn.primary {
  background: var(--accent); color: var(--accent-contrast); border-color: transparent;
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[disabled] {
  opacity: 0.6; cursor: not-allowed; pointer-events: none;
}

/* Subnav pills */
.subnav { margin: var(--space-6) auto; }
.pillnav { list-style: none; display: flex; flex-wrap: wrap; gap: var(--space-3); padding: 0; }
.pillnav a {
  display: inline-block; padding: 8px 12px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  text-decoration: none;
}
.pillnav a:hover { border-color: var(--link); }

/* Lists */
.keylist, .checklist, .timeline { list-style: none; padding: 0; }
.keylist li { margin-bottom: 8px; }
.checklist li { margin: 6px 0; padding-left: 26px; position: relative; }
.checklist li::before {
  content: "✓"; position: absolute; left: 0; top: 0; color: var(--link); font-weight: 700;
}
.timeline li { margin: 10px 0; }
.timeline li span { display: inline-block; min-width: 80px; font-weight: 700; color: var(--muted); }

/* Tables */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow); }
.table { width: 100%; border-collapse: collapse; min-width: 680px; }
.table th, .table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table thead th { position: sticky; top: 0; background: var(--card); text-align: left; font-weight: 700; }
.table tbody tr:hover { background: rgba(14,165,233,0.06); }

/* Toolbar (improved for filter + buttons) */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  justify-content: space-between;
  margin: var(--space-4) 0;
}
#tram-filter {
  flex: 1 1 260px;
  width: 100%;
  max-width: 360px;
  padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
}

/* Callouts */
.callout {
  border: 1px solid var(--border); border-left: 6px solid var(--accent);
  padding: var(--space-5); border-radius: var(--radius); background: var(--card); box-shadow: var(--shadow);
}

/* Footer */
.site-footer {
  margin-top: var(--space-12); padding: var(--space-8) 0;
  border-top: 1px solid var(--border); background: linear-gradient(180deg, transparent, rgba(14,165,233,0.08));
}
.footer-inner { display: grid; gap: var(--space-6); }
@media (min-width: 760px) { .footer-inner { grid-template-columns: 2fr 1fr 2fr; } }
.foot-links { list-style: none; padding: 0; display: grid; gap: 8px; }
.foot-links a { color: var(--text); text-decoration: none; }
.foot-links a:hover { color: var(--link); }

/* Utility */
.prose p + h3 { margin-top: var(--space-4); }
.note { color: var(--muted); }
.sr-only {
  position: absolute !important; height: 1px; width: 1px; overflow: hidden;
  clip: rect(1px,1px,1px,1px); white-space: nowrap;
}

/* Focus */
:focus-visible {
  outline: 3px solid rgba(14,165,233,0.5);
  outline-offset: 2px;
}

/* Contribution UI (community edits) */
.pill.mini {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(14,165,233,0.12);
  color: var(--link);
  margin-left: 6px;
}
.contrib-btn {
  display: inline-block;
  border: 1px dashed var(--border);
  background: transparent;
  color: var(--link);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.8rem;
}
.contrib-btn:hover {
  text-decoration: none;
  border-color: var(--link);
}

.contrib-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: grid;
  place-items: center;
  z-index: 1000;
}
.contrib-dialog {
  background: var(--bg);
  color: var(--text);
  width: min(520px, 94vw);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.contrib-row {
  margin-bottom: 10px;
  display: grid;
  gap: 6px;
}
.contrib-row label {
  font-size: 0.9rem;
  color: var(--muted);
}
.contrib-row input {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  padding: 8px 10px;
  border-radius: 8px;
}
.contrib-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 12px;
}
/* Modal close button */
.contrib-dialog { position: relative; }
.contrib-close {
  position: absolute;
  top: 8px; right: 10px;
  line-height: 1;
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: 22px;
  padding: 2px 6px;
  border-radius: 6px;
}
.contrib-close:hover { color: var(--text); background: rgba(0,0,0,0.05); }
:root[data-theme="dark"] .contrib-close:hover { background: rgba(255,255,255,0.06); }

.contrib-modal[hidden] { display: none !important; }


/* Clamp long contribution text in table cells to 3 lines, with a More/Less toggle */
.cell-text {
  white-space: normal;
}

.clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3; /* show 3 lines */
  overflow: hidden;
}

.cell-toggle {
  border: 0;
  background: none;
  color: var(--link);
  font-size: 0.85rem;
  padding: 0 4px;
  margin-left: 4px;
}
.cell-toggle:hover { text-decoration: underline; }

/* Tram map container */
#tram-map {
  height: 480px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

/* =========================
   Buses table layout + Notes clamp (ADDED)
   ========================= */
#buses-table .table { table-layout: fixed; width: 100%; }
#buses-table .table th, #buses-table .table td { padding: 8px 10px; vertical-align: top; word-break: break-word; }

#buses-table .col-fleetno { width: 90px; }
#buses-table .col-reg     { width: 120px; }
#buses-table .col-chassis { width: 170px; }
#buses-table .col-body    { width: 170px; }
#buses-table .col-dates   { width: 180px; }
#buses-table .col-depots  { width: 180px; }
#buses-table .col-livery  { width: 140px; }
#buses-table .col-status  { width: 160px; }
#buses-table .col-notes   { width: auto; max-width: 28vw; }

#buses-table .note-wrap { display: block; }
#buses-table .note-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  overflow: hidden;
  white-space: normal;
}
#buses-table .note-wrap.expanded .note-text {
  -webkit-line-clamp: unset;
  display: block;
}
#buses-table .note-toggle {
  display: inline-block;
  margin-top: 4px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--link);
  font-size: 0.86rem;
  cursor: pointer;
}
#buses-table .note-toggle:hover { text-decoration: underline; }

#buses-table .table td > p,
#buses-table .table td > div,
#buses-table .table td > ul,
#buses-table .table td > ol { margin: 0; padding: 0; }

@media (min-width: 1200px) {
  #buses-table .col-notes { max-width: 34vw; }
}

/* Buses table: enable both-axis scroll and make Notes sensible */

/* Make the injected table container scroll both ways without changing your base styles */
#buses-table {
  /* This is the div the JS fills; give it a viewport-based height so vertical scroll can show */
  max-width: 100%;
  height: 70vh;             /* adjust to taste (e.g., 65–80vh) */
  overflow: auto;           /* both horizontal and vertical scrollbars as needed */
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
}

/* Ensure the table can grow wider than the container, triggering horizontal scroll */
#buses-table .table {
  table-layout: fixed;      /* keep columns stable */
  width: 100%;              /* fill available width */
  min-width: 1100px;        /* enough to avoid squish; tweak if you prefer */
}

/* Keep cells compact and readable without altering your base table styles */
#buses-table .table th,
#buses-table .table td {
  padding: 8px 10px;
  vertical-align: top;
  word-break: break-word;
}

/* Give Notes a sensible base width so it’s not tiny (but allow it to flex if space exists) */
#buses-table .col-notes {
  width: 36ch;              /* about 36 characters visible */
  max-width: 44ch;          /* cap on huge screens; adjust to taste */
}

/* Clamp/expand behavior for Notes (if you’re using the toggle) */
#buses-table .note-wrap { display: block; }
#buses-table .note-text {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;    /* show first 3 lines */
  overflow: hidden;
  white-space: normal;
}
#buses-table .note-wrap.expanded .note-text {
  -webkit-line-clamp: unset;
  display: block;
}
#buses-table .note-toggle {
  display: inline-block;
  margin-top: 4px;
  padding: 0;
  background: none;
  border: 0;
  color: var(--link);
  font-size: 0.86rem;
  cursor: pointer;
}
#buses-table .note-toggle:hover { text-decoration: underline; }

/* Neutralize margins inside cells to avoid tall, uneven rows */
#buses-table .table td > p,
#buses-table .table td > div,
#buses-table .table td > ul,
#buses-table .table td > ol {
  margin: 0;
  padding: 0;
}

/* Slightly widen the Livery/Branding column to avoid wrapping the final 'g' */
#buses-table .col-livery {
  min-width: 20ch;   /* was likely narrower; bump to ~20 characters */
  width: 20ch;
}
.pagination {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  justify-content: center;
  margin: 1rem 0;
}

.page-btn {
  padding: 0.5rem 0.75rem;
  border: 1px solid #ddd;
  background: white;
  cursor: pointer;
  border-radius: 4px;
}

.page-btn:hover:not(:disabled) {
  background: #f0f0f0;
}

.page-btn.active {
  background: #007bff;
  color: white;
  border-color: #007bff;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-ellipsis {
  padding: 0 0.5rem;
}

#buses-results-info {
  text-align: center;
  margin: 1rem 0;
  font-weight: 500;
}

/* Tram map legend (external) */
#tram-map-legend {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 1rem;
  margin-top: 1rem;
}

#tram-map-legend h3 {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
}

.tram-legend-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.5rem;
}

.tram-legend-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.tram-legend-list input[type="checkbox"] {
  flex-shrink: 0;
  cursor: pointer;
}

.tram-legend-list label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.legend-color {
  display: inline-block;
  width: 20px;
  height: 3px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* Dark mode support */
body.dark-mode #tram-map-legend {
  background: #1e293b;
  border-color: #334155;
  color: #e2e8f0;
}

