@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,700;1,400&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg:           #1a1208;
  --bg-raised:    #22190a;
  --bg-card:      #2a1e0a;
  --bg-hover:     #30240d;
  --text:         #f5f0e8;
  --text-muted:   #8a7455;
  --accent:       #c8840a;
  --accent-hover: #e09a12;
  --accent-dim:   #7a5006;
  --border:       #3a2a10;
  --danger:       #c84a2a;
  --danger-hover: #e05535;
  --success:      #5a9a3a;
}

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

html, body {
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 14px;
  line-height: 1.55;
}

h1, h2, h3 {
  font-family: 'Playfair Display', serif;
  color: var(--accent);
  line-height: 1.2;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

/* ── Nav ───────────────────────────────────────────────── */
nav {
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  height: 42px;
  padding: 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  position: sticky;
  top: 0;
  z-index: 100;
}

.nav-brand {
  font-family: 'Playfair Display', serif;
  font-size: 1.1rem;
  color: var(--accent);
  font-weight: 700;
  white-space: nowrap;
}

.nav-brand span { font-style: italic; }

.nav-links {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  margin-left: auto;
}

.nav-links a {
  color: var(--text-muted);
  font-size: 0.78rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

nav .nav-cog {
  margin-left: auto;
  font-size: 1.4rem;
  color: var(--text-muted);
  text-decoration: none;
  line-height: 1;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--text);
  text-decoration: none;
}

.nav-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.nav-name {
  cursor: pointer;
}

.nav-name:hover { color: var(--text); }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
  font-family: 'DM Mono', monospace;
  font-size: 0.8rem;
  background: transparent;
  color: var(--text-muted);
  transition: color 0.12s, border-color 0.12s, background 0.12s;
  white-space: nowrap;
}

.btn:hover { color: var(--text); border-color: var(--accent-dim); }

.btn-primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
  font-weight: 500;
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: var(--bg);
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-sm { padding: 0.22rem 0.55rem; font-size: 0.72rem; }

.btn-danger { color: var(--danger); border-color: transparent; }
.btn-danger:hover { color: var(--danger-hover); border-color: var(--danger); }

/* ── Forms ─────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
textarea,
select {
  background: var(--bg-raised);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.48rem 0.75rem;
  font-family: 'DM Mono', monospace;
  font-size: 0.875rem;
  width: 100%;
  outline: none;
  transition: border-color 0.12s;
}

input[type="text"]:focus,
textarea:focus,
select:focus { border-color: var(--accent-dim); }

textarea { resize: vertical; min-height: 70px; }

select { cursor: pointer; }
select option { background: var(--bg-card); }

label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.3rem;
}

.form-group { margin-bottom: 0.9rem; }
.settings-section { background: var(--card); border: 1px solid var(--border); border-radius: 6px; padding: 1.25rem; margin-bottom: 1.5rem; max-width: 600px; }
.settings-section h2 { margin: 0 0 0.5rem; font-size: 1rem; color: var(--accent); }

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

/* ── Page ──────────────────────────────────────────────── */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1rem;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.page-header h1 { font-size: 1.5rem; }

.page-header-actions {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.count-badge {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.1rem 0.6rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ── Tables ────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; }

th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  text-align: left;
  white-space: nowrap;
}

td {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:hover td { background: var(--bg-raised); }

.td-name { font-weight: 500; position: -webkit-sticky; position: sticky; left: 0; z-index: 1; background: var(--bg); }
tr:hover .td-name { background: var(--bg-raised); }
.td-muted { color: var(--text-muted); font-size: 0.82rem; }
.td-actions { white-space: nowrap; }

/* ── Notes inline edit ─────────────────────────────────── */
.notes-display { color: var(--text-muted); font-size: 0.82rem; font-style: italic; }
.notes-display:empty::after { content: "—"; }

.notes-edit-wrap { display: none; }
.notes-edit-wrap textarea { min-height: 48px; font-size: 0.82rem; }

/* ── Modals ────────────────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  z-index: 500;
  align-items: center;
  justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 1.5rem;
  max-width: 580px;
  width: 92%;
  max-height: 82vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.modal-header h2 { font-size: 1.2rem; }

.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.1rem 0.3rem;
}

.modal-close:hover { color: var(--text); }

/* ── Login ─────────────────────────────────────────────── */
.login-page {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
}

.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2.75rem 2.25rem;
  width: 360px;
  text-align: center;
}

.login-logo {
  font-family: 'Playfair Display', serif;
  font-size: 2.4rem;
  color: var(--accent);
  margin-bottom: 0.2rem;
}

.login-logo span { font-style: italic; }

.login-sub {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 2rem;
  letter-spacing: 0.04em;
}

.login-box input {
  text-align: center;
  letter-spacing: 0.15em;
  font-size: 1rem;
}

.login-box .btn-primary {
  width: 100%;
  justify-content: center;
  padding: 0.6rem;
  font-size: 0.88rem;
  margin-top: 0.5rem;
}

/* ── Error / Info banners ──────────────────────────────── */
.error-msg {
  background: rgba(200, 74, 42, 0.12);
  border: 1px solid var(--danger);
  color: #e07050;
  padding: 0.55rem 0.85rem;
  border-radius: 3px;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.info-msg {
  background: rgba(200, 132, 10, 0.1);
  border: 1px solid var(--accent-dim);
  color: var(--accent);
  padding: 0.55rem 0.85rem;
  border-radius: 3px;
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

/* ── Add-pub search bar ────────────────────────────────── */
.search-add-row {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  align-items: flex-end;
}

.search-add-row .pac-wrap {
  flex: 1;
  position: relative;
}

/* Override Google autocomplete dropdown */

.pac-container {
  background: var(--bg-card) !important;
  border: 1px solid var(--border) !important;
  border-radius: 3px;
  font-family: 'DM Mono', monospace !important;
  font-size: 0.85rem !important;
  margin-top: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important;
}

.pac-item {
  color: var(--text-muted) !important;
  border-top: 1px solid var(--border) !important;
  padding: 0.4rem 0.75rem !important;
  cursor: pointer;
}

.pac-item:hover, .pac-item-selected {
  background: var(--bg-hover) !important;
}

.pac-item-query { color: var(--text) !important; }
.pac-matched { color: var(--accent) !important; }
.pac-icon { display: none !important; }

/* ── Client-side filter ────────────────────────────────── */
.filter-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 0.75rem;
}

.filter-input {
  max-width: 280px;
}

.filter-row-inline td { padding: 2px 4px; }
.filter-row-inline td:first-child { position: -webkit-sticky; position: sticky; left: 0; z-index: 1; background: var(--bg); }
#pub-table thead th:first-child { position: -webkit-sticky; position: sticky; left: 0; z-index: 1; background: var(--bg); }
.col-filter { width: 100%; font-size: 0.78rem; padding: 0.2rem 0.4rem; }
#pub-table tbody tr { height: 2.4rem; }
#pub-table tbody td { white-space: nowrap; }
#pub-table tbody .td-name { overflow: hidden; text-overflow: ellipsis; max-width: 200px; }
.td-truncate { overflow: hidden; text-overflow: ellipsis; max-width: 220px; color: var(--text-muted); font-size: 0.82rem; }
#pub-table tbody .td-actions { white-space: nowrap; width: 1%; }

/* ── Nights list ───────────────────────────────────────── */
.nights-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

.night-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  transition: border-color 0.12s;
}

.night-card:hover { border-color: var(--accent-dim); }

.night-card-title {
  font-family: 'Playfair Display', serif;
  font-size: 1.15rem;
  color: var(--accent);
}

.night-card-desc { color: var(--text-muted); font-size: 0.82rem; }

.night-card-meta {
  color: var(--text-muted);
  font-size: 0.72rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.night-card-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
}

/* ── Night edit split ──────────────────────────────────── */
.night-layout {
  display: grid;
  grid-template-columns: 370px 1fr;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.night-left {
  overflow-y: auto;
  border-right: 1px solid var(--border);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.night-right {
  position: relative;
  overflow: hidden;
}

#night-map, #view-map {
  width: 100%;
  height: 100%;
}

.map-overlay-btns {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 10;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.map-overlay-dist {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.45rem 0.75rem;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  font-size: 0.85rem;
  color: var(--text-muted);
}
.map-overlay-dist input {
  width: 52px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--text);
  font-family: 'DM Mono', monospace;
  font-size: 0.85rem;
  padding: 0.15rem 0.35rem;
  text-align: center;
}

.map-overlay-btns .btn {
  background: var(--bg-card);
  color: var(--text);
  border-color: var(--border);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  min-width: 130px;
  justify-content: center;
  font-size: 0.9rem;
  padding: 0.55rem 1rem;
}

/* ── Autosave ──────────────────────────────────────────── */
.autosave {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-height: 1em;
  text-align: right;
}

.autosave.saving { color: var(--accent); }
.autosave.saved  { color: var(--success); }
.autosave.error  { color: var(--danger); }

/* ── Tube selectors ────────────────────────────────────── */
.tube-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
}

/* ── Stops list ────────────────────────────────────────── */
.stops-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.4rem;
}

.stops-header h3 {
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}

.stops-list { list-style: none; min-height: 40px; }

.stop-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.5rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 0.35rem;
  background: var(--bg-raised);
  cursor: grab;
  user-select: none;
}

.stop-item.dragging { opacity: 0.45; cursor: grabbing; }
.stop-item.drag-over { border-color: var(--accent); background: var(--bg-hover); }

.stop-num {
  background: var(--accent);
  color: var(--bg);
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.stop-body { flex: 1; min-width: 0; }

.stop-name {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-addr {
  font-size: 0.74rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-leg {
  font-size: 0.7rem;
  color: var(--accent);
  margin-top: 0.1rem;
}

.stop-notes-input {
  margin-top: 0.3rem;
  font-size: 0.78rem;
  padding: 0.25rem 0.45rem;
  min-height: 0;
  resize: none;
}

.stop-actions { display: flex; gap: 0.2rem; flex-shrink: 0; }

/* ── Route summary ─────────────────────────────────────── */
.route-summary {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0.5rem 0.75rem;
  line-height: 1.6;
}

.route-summary strong { color: var(--accent); }

/* ── Night view ────────────────────────────────────────── */
.night-view-layout {
  display: grid;
  grid-template-columns: 1fr 440px;
  height: calc(100vh - 48px);
  overflow: hidden;
}

.night-view-left {
  overflow-y: auto;
  padding: 1.5rem;
}

.night-view-right { position: relative; }

.night-view-title {
  font-size: 1.5rem;
  margin-bottom: 0.1rem;
}

.night-view-meta {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin-bottom: 0.5rem;
}

.route-line {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin: 0.4rem 0;
}

.route-node {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.route-node-icon {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 700;
  flex-shrink: 0;
  margin-top: 2px;
}

.route-node-icon.tube {
  background: var(--bg-raised);
  border: 1px solid var(--accent);
  color: var(--accent);
  font-size: 0.6rem;
}

.route-node-body { flex: 1; padding-bottom: 0.15rem; }
.route-node-name { font-weight: 500; }
.route-node-addr { font-size: 0.78rem; color: var(--text-muted); }
.route-node-notes { font-size: 0.78rem; color: var(--accent); font-style: italic; margin-top: 0.1rem; }
.expand-arrow { font-size: 1em; color: var(--text-muted); margin-left: 0.25rem; display: inline-block; transition: transform 0.15s; }
.expand-arrow.open { transform: rotate(180deg); }

.route-connector {
  margin-left: 14px;
  border-left: 2px dashed var(--border);
  padding: 0.25rem 0 0.25rem 0.75rem;
  font-size: 0.72rem;
  color: var(--text-muted);
  min-height: 24px;
}

.night-view-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
  padding-bottom: 0.5rem;
}

/* ── Visited stop ──────────────────────────────────────── */
.route-node-icon.visited {
  background: #3a6e3a;
  color: #b8f0b8;
}
.route-node-icon.visited::after { content: " ✓"; }

/* ── Nearby stop badge ─────────────────────────────────── */
.stop-nearby .route-node-name { color: var(--accent); }
.stop-dist-badge { font-size: 0.75rem; color: var(--text-muted); font-weight: 400; }

/* ── Leg directions panel ──────────────────────────────── */
.leg-dir-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 0.72rem; cursor: pointer; padding: 0.1rem 0.3rem;
  margin-left: 0.4rem;
}
.leg-dir-btn:hover { color: var(--text); }
.leg-dirs { display: none; padding: 0.3rem 0 0.2rem; }
.leg-dirs.open { display: block; }
.leg-step {
  font-size: 0.75rem; color: var(--text-muted);
  padding: 0.15rem 0; line-height: 1.3;
}
.leg-step-dist { opacity: 0.6; margin-left: 0.25rem; }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; left: 50%; transform: translateX(-50%);
  background: var(--bg-raised); color: var(--text); border: 1px solid var(--border);
  padding: 0.5rem 1rem; border-radius: 8px; font-size: 0.85rem;
  opacity: 0; transition: opacity 0.2s; pointer-events: none; z-index: 9999;
}
.toast.toast-show { opacity: 1; }

/* ── Pub select modal ──────────────────────────────────── */
.pub-select-list {
  list-style: none;
  max-height: 350px;
  overflow-y: auto;
}

.pub-select-item {
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pub-select-item:hover { background: var(--bg-hover); }
.pub-select-item .psi-name { font-weight: 500; }
.pub-select-item .psi-addr { font-size: 0.78rem; color: var(--text-muted); }

/* ── Import modal ──────────────────────────────────────── */
.import-result {
  font-size: 0.82rem;
  padding: 0.5rem 0.75rem;
  border-radius: 3px;
  margin-top: 0.75rem;
}

/* ── Empty state ───────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 3.5rem 1rem;
  color: var(--text-muted);
}

.empty h2 { margin-bottom: 0.4rem; font-size: 1.3rem; }
.empty p { font-size: 0.85rem; }

/* ── Misc utils ────────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.ml-auto { margin-left: auto; }
.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.text-muted { color: var(--text-muted); }
.text-accent { color: var(--accent); }
.text-sm { font-size: 0.82rem; }
.hidden { display: none !important; }

/* ── Mobile tabs ───────────────────────────────────────── */
.mobile-tabs {
  display: none;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
}

.mobile-tab {
  flex: 1;
  padding: 0.65rem;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-family: 'DM Mono', monospace;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  cursor: pointer;
}

.mobile-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 800px) {
  .mobile-tabs { display: flex; }
  .page { padding-left: 0.5rem; padding-right: 0.5rem; }

  .night-layout {
    display: flex;
    flex-direction: column;
    flex: 1;
    height: auto;
    min-height: 0;
    overflow: hidden;
  }

  .night-left {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
  }

  .night-right {
    flex: 1;
    min-height: 0;
  }

  .night-view-layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .night-view-right {
    height: 300px;
    position: relative;
  }

  .night-view-left { padding: 1rem; }

  .tube-row { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .nights-grid { grid-template-columns: 1fr; }
}

/* Mobile night pages: body is the flex container so tabs can never scroll away */
html.night-page, html.night-page body { height: 100%; overflow: hidden; overscroll-behavior: none; }
html.night-page body { display: flex; flex-direction: column; }
html.night-page footer { display: none; }

/* Force dark text in Google Maps InfoWindows (dark theme bleeds in otherwise) */
.gm-style-iw-d, .gm-style-iw-d * { color: #1a1208 !important; }
.gm-style-iw-c { padding: 0 !important; }
.gm-style-iw-d { overflow: auto !important; }
.iw-content { position: relative; background: #fff; color: #1a1208; font-family: 'DM Mono', monospace; font-size: 12px; max-width: 200px; padding: 6px 24px 8px 8px; }
.iw-content * { color: #1a1208 !important; }
.iw-content a { text-decoration: underline; cursor: pointer; }
.iw-close { position: absolute; top: 4px; right: 4px; background: none; border: none; cursor: pointer; font-size: 14px; color: #888 !important; line-height: 1; padding: 2px 4px; }
