/* Route Builder — Dark theme, matching Lushka family */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #0d1117;
  --bg-panel: #161b22;
  --bg-input: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text-dim: #8b949e;
  --text-bright: #f0f6fc;
  --accent: #58a6ff;
  --accent-dim: #1f6feb;
  --danger: #f85149;
  --success: #3fb950;
  --radius: 6px;
  --panel-width: 320px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
}

/* Header */
#header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  height: 48px;
  z-index: 100;
}

#header h1 {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-bright);
  white-space: nowrap;
}

#search-wrap {
  position: relative;
  flex: 1;
  max-width: 300px;
}

#search-input {
  width: 100%;
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

#search-input:focus {
  border-color: var(--accent);
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
  display: none;
  z-index: 200;
}

#search-results.active { display: block; }

.search-item {
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.search-item:hover {
  background: var(--bg-input);
  color: var(--text-bright);
}

#view-toggle {
  display: flex;
  gap: 2px;
  margin-left: auto;
}

#view-toggle button {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
}

#view-toggle button:first-child {
  border-radius: var(--radius) 0 0 var(--radius);
}

#view-toggle button:not(:first-child):not(:last-child) {
  border-radius: 0;
}

#view-toggle button:last-child {
  border-radius: 0 var(--radius) var(--radius) 0;
}

#view-toggle button.active {
  background: var(--accent-dim);
  color: var(--text-bright);
  border-color: var(--accent);
}

/* Main layout */
#main {
  display: flex;
  height: calc(100vh - 48px);
}

/* Side panel */
#panel {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#panel section {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
}

#panel h2 {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* TOC Panel */
.toc-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0;
  cursor: pointer;
  user-select: none;
}

.toc-item:hover { color: var(--text-bright); }

.toc-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.toc-check {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.toc-name {
  font-size: 0.85rem;
  flex: 1;
}

.toc-count {
  font-size: 0.75rem;
  color: var(--text-dim);
}

.toc-solo {
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}

.toc-solo:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Stats */
.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
  font-size: 0.85rem;
}

.stat-label { color: var(--text-dim); }
.stat-val { color: var(--text-bright); font-weight: 600; }

#hub-list {
  margin-top: 0.4rem;
  font-size: 0.8rem;
}

.hub-item {
  display: flex;
  justify-content: space-between;
  padding: 0.15rem 0;
  color: var(--text-dim);
}

.hub-item .hub-name { color: var(--text); }

/* Detail panel */
.hidden { display: none !important; }

#detail-name {
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

#detail-pronunciation {
  font-size: 0.9rem;
  color: var(--accent);
  font-style: italic;
  margin-bottom: 0.3rem;
}

#detail-tocs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-bottom: 0.4rem;
}

.detail-toc-badge {
  padding: 0.15rem 0.5rem;
  border-radius: 3px;
  font-size: 0.75rem;
  color: #fff;
  font-weight: 600;
}

#detail-connections {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}

#detail-fun-fact {
  font-size: 0.8rem;
  color: var(--text);
  font-style: italic;
}

#detail-close {
  margin-top: 0.5rem;
  padding: 0.3rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.8rem;
}

#detail-close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Journey Planner */
.journey-inputs {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  position: relative;
}

.journey-inputs input {
  padding: 0.35rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}

.journey-inputs input:focus {
  border-color: var(--accent);
}

.journey-results {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 150px;
  overflow-y: auto;
  display: none;
  z-index: 50;
}

.journey-results.active { display: block; }

#journey-go {
  padding: 0.4rem;
  border: none;
  border-radius: var(--radius);
  background: var(--accent-dim);
  color: var(--text-bright);
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 600;
}

#journey-go:hover { background: var(--accent); }

#journey-result {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.journey-stop {
  padding: 0.2rem 0;
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.journey-stop .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.journey-interchange {
  color: var(--accent);
  font-weight: 600;
  font-size: 0.75rem;
  padding: 0.1rem 0 0.1rem 1.2rem;
}

/* What If */
.whatif-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
  margin-bottom: 0.4rem;
}

#whatif-select {
  width: 100%;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.85rem;
}

#whatif-result {
  margin-top: 0.5rem;
  font-size: 0.8rem;
}

.whatif-stat {
  display: flex;
  justify-content: space-between;
  padding: 0.2rem 0;
}

.whatif-isolated {
  color: var(--danger);
  margin-top: 0.3rem;
}

/* Canvas */
#canvas-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#network-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#network-canvas.grabbing { cursor: grabbing; }

#tooltip {
  position: absolute;
  padding: 0.4rem 0.7rem;
  background: rgba(22, 27, 34, 0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.8rem;
  color: var(--text-bright);
  pointer-events: none;
  white-space: nowrap;
  z-index: 50;
}

/* Station Bubble — glass-morphic overlay */
.station-bubble {
  position: absolute;
  width: 320px;
  max-height: 420px;
  overflow-y: auto;
  padding: 1rem 1.1rem;
  background: rgba(22, 27, 34, 0.88);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255,255,255,0.05) inset;
  z-index: 100;
  pointer-events: auto;
  transform-origin: left center;
}

.sb-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.4rem;
}

.sb-name {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-bright);
  margin: 0;
  line-height: 1.3;
}

.sb-close {
  background: none;
  border: none;
  color: var(--text-dim);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0 0.2rem;
  line-height: 1;
  flex-shrink: 0;
  margin-left: 0.5rem;
}
.sb-close:hover { color: var(--text-bright); }

.sb-pronunciation {
  color: var(--accent);
  font-style: italic;
  font-size: 0.9rem;
  margin-bottom: 0.6rem;
  line-height: 1.4;
}

.sb-tocs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.6rem;
}

.sb-toc-badge {
  padding: 0.25rem 0.65rem;
  border-radius: 5px;
  font-size: 0.78rem;
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.sb-connections {
  font-size: 0.82rem;
  color: var(--text-dim);
  margin-bottom: 0.5rem;
  line-height: 1.5;
}

.sb-conn-label {
  color: var(--text);
  font-weight: 600;
}

.sb-fact {
  font-size: 0.88rem;
  color: var(--text);
  padding: 0.6rem 0.8rem;
  background: rgba(88, 166, 255, 0.06);
  border-radius: 10px;
  border-left: 3px solid var(--accent);
  line-height: 1.5;
  margin-top: 0.3rem;
}

/* ---- Journey Builder ---- */

#journey-builder {
  width: var(--panel-width);
  min-width: var(--panel-width);
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#jb-header {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#jb-header h2 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-bright);
  margin: 0;
  flex: 1;
}

#jb-stats {
  font-size: 0.78rem;
  color: var(--text-dim);
  white-space: nowrap;
}

#jb-stats span {
  color: var(--accent);
  font-weight: 700;
}

#jb-reset {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.75rem;
}

#jb-reset:hover {
  border-color: var(--danger);
  color: var(--danger);
}

/* Start picker */
.jb-start-picker {
  padding: 1.5rem 1rem;
  text-align: center;
}

.jb-start-picker p {
  font-size: 0.9rem;
  color: var(--text-dim);
  margin-bottom: 0.8rem;
}

#jb-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-input);
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
}

#jb-search:focus {
  border-color: var(--accent);
}

#jb-search-results {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 240px;
  overflow-y: auto;
  display: none;
  margin-top: 0.3rem;
  text-align: left;
}

#jb-search-results.active { display: block; }

/* Journey track */
#jb-track {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

/* Station ball */
.jb-step {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.jb-ball-row {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  cursor: pointer;
  padding: 0.15rem 0;
}

.jb-ball {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.25);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: #fff;
  animation: jb-ball-enter 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.jb-ball-current {
  animation: jb-pulse 1.8s infinite ease-in-out;
  box-shadow: 0 0 12px rgba(88, 166, 255, 0.5);
}

@keyframes jb-ball-enter {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes jb-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 8px rgba(88, 166, 255, 0.4); }
  50% { transform: scale(1.12); box-shadow: 0 0 18px rgba(88, 166, 255, 0.7); }
}

.jb-ball-name {
  font-size: 0.88rem;
  color: var(--text-bright);
  font-weight: 600;
  line-height: 1.3;
}

.jb-ball-route {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Connection line between balls */
.jb-line {
  width: 4px;
  height: 40px;
  margin-left: 22px;
  border-radius: 2px;
}

/* Choice container */
.jb-choices {
  padding: 0.4rem 0 0.6rem 0;
  margin-left: 56px;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.jb-choice-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.jb-choice-row:hover {
  background: var(--bg-input);
}

.jb-choice-ball {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
  opacity: 0.85;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s;
  animation: jb-choice-enter 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

.jb-choice-row:hover .jb-choice-ball {
  transform: scale(1.08);
  opacity: 1;
}

.jb-choice-ball.jb-visited {
  border-style: dashed;
  opacity: 0.5;
}

@keyframes jb-choice-enter {
  from { transform: scale(0) translateY(8px); opacity: 0; }
  to { transform: scale(1) translateY(0); opacity: 1; }
}

.jb-choice-name {
  font-size: 0.85rem;
  color: var(--text);
  flex: 1;
}

.jb-choice-badge {
  font-size: 0.68rem;
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  color: #fff;
  font-weight: 600;
  white-space: nowrap;
}

/* Fan line connecting choices to track */
.jb-fan-line {
  width: 2px;
  height: 12px;
  margin-left: 22px;
  border-left: 2px dashed var(--border);
}

/* Mobile */
@media (max-width: 768px) {
  #main { flex-direction: column-reverse; }

  #panel {
    width: 100%;
    min-width: 0;
    max-height: 40vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }

  #canvas-wrap {
    height: 60vh;
  }

  :root {
    --panel-width: 100%;
  }

  #search-wrap { max-width: 200px; }

  #journey-builder {
    width: 100%;
    min-width: 0;
    max-height: 45vh;
    border-right: none;
    border-top: 1px solid var(--border);
  }
}

/* iPad / tablet */
@media (min-width: 769px) and (max-width: 1100px) {
  #journey-builder {
    width: 360px;
    min-width: 360px;
  }

  .jb-ball {
    width: 52px;
    height: 52px;
  }

  .jb-line {
    margin-left: 24px;
  }

  .jb-choices {
    margin-left: 60px;
  }
}
