/* ============================================================
   CSS Custom Properties
   ============================================================ */
:root {
  --font: 'Inter', system-ui, -apple-system, sans-serif;

  --color-bg:             #f1f5f9;
  --color-surface:        #ffffff;
  --color-surface-hover:  #f8fafc;
  --color-border:         #e2e8f0;
  --color-text:           #0f172a;
  --color-text-secondary: #64748b;
  --color-accent:         #3b82f6;
  --color-accent-hover:   #2563eb;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow:    0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);

  --radius-sm: 6px;
  --radius:    10px;

  --sidebar-width: 280px;
  --header-height: 56px;

  --sp-xs: 4px;
  --sp-sm: 8px;
  --sp-md: 16px;
  --sp-lg: 24px;
  --sp-xl: 32px;
}

[data-theme="dark"] {
  --color-bg:             #0d1117;
  --color-surface:        #161b22;
  --color-surface-hover:  #1c2128;
  --color-border:         #30363d;
  --color-text:           #e6edf3;
  --color-text-secondary: #7d8590;
  --color-accent:         #58a6ff;
  --color-accent-hover:   #79b8ff;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.30);
  --shadow:    0 1px 3px rgba(0,0,0,0.40), 0 1px 2px rgba(0,0,0,0.30);
}

/* ============================================================
   Reset & Base
   ============================================================ */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--color-text);
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* ============================================================
   Header
   ============================================================ */
.header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--sp-lg);
  gap: var(--sp-md);
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 10;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.header__logo {
  color: var(--color-accent);
  flex-shrink: 0;
}

.header__title {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--color-text);
}

.header__controls {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

/* ============================================================
   Buttons
   ============================================================ */
.toggle-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-width: 44px;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.toggle-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: var(--color-accent);
}

.toggle-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.icon-btn {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--color-surface-hover);
  color: var(--color-text);
  border-color: var(--color-accent);
}

.icon-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* ============================================================
   Layout
   ============================================================ */
.layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

/* ============================================================
   Sidebar
   ============================================================ */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

/* ============================================================
   Upload Zone
   ============================================================ */
.upload-zone {
  margin: var(--sp-md);
  padding: var(--sp-lg) var(--sp-md);
  border: 2px dashed var(--color-border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--color-text-secondary);
  position: relative;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.upload-zone:hover,
.upload-zone:focus-visible,
.upload-zone--drag-over {
  border-color: var(--color-accent);
  background: rgba(59, 130, 246, 0.06);
  color: var(--color-accent);
  outline: none;
}

[data-theme="dark"] .upload-zone:hover,
[data-theme="dark"] .upload-zone:focus-visible,
[data-theme="dark"] .upload-zone--drag-over {
  background: rgba(88, 166, 255, 0.08);
}

.upload-zone__text {
  font-size: 13px;
  font-weight: 500;
  margin-top: var(--sp-xs);
}

.upload-zone__sub {
  font-size: 12px;
  color: var(--color-text-secondary);
}

.upload-zone #fileInput {
  display: none;
}

.upload-zone--loading {
  pointer-events: none;
  opacity: 0.6;
}

/* ============================================================
   Route List
   ============================================================ */
.sidebar__section {
  padding: 0 var(--sp-md) var(--sp-md);
  flex: 1;
  min-height: 0;
}

.sidebar__section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  padding: var(--sp-xs) 0 var(--sp-sm);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--sp-sm);
}

.badge {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 100px;
  min-width: 22px;
  text-align: center;
}

.route-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.route-list__empty {
  font-size: 13px;
  color: var(--color-text-secondary);
  text-align: center;
  padding: var(--sp-lg) 0;
}

.route-item {
  display: flex;
  flex-direction: column;
  padding: 7px var(--sp-sm);
  border-radius: var(--radius-sm);
  transition: background 0.1s;
}

.route-item:hover {
  background: var(--color-surface-hover);
}

.route-item__header {
  display: flex;
  align-items: center;
  gap: var(--sp-sm);
}

.route-item__checkbox {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  cursor: pointer;
  accent-color: var(--color-accent);
}

.route-item__color {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.route-item__name {
  flex: 1;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.route-item__thumbnail {
  display: block;
  width: 100%;
  margin-top: 6px;
  border-radius: var(--radius-sm);
  background: var(--color-bg);
}

.route-item__offset {
  display: flex;
  align-items: center;
  gap: var(--sp-xs);
  padding-top: 5px;
  padding-left: calc(15px + var(--sp-sm)); /* indent past checkbox */
}

.route-item__offset-label {
  font-size: 11px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.route-item__offset-slider {
  flex: 1;
  min-width: 0;
  accent-color: var(--color-accent);
  cursor: pointer;
}

.route-item__offset-value {
  font-size: 11px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
  min-width: 58px;
  text-align: right;
}

/* ============================================================
   Main / Chart
   ============================================================ */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  padding: var(--sp-lg);
  overflow: hidden;
}

.chart-wrapper {
  flex: 1;
  min-height: 400px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-md);
  color: var(--color-text-secondary);
  text-align: center;
  padding: var(--sp-xl);
  pointer-events: none;
}

.chart-empty p {
  font-size: 14px;
}

.chart-empty.hidden {
  display: none;
}

.chart-canvas-container {
  position: absolute;
  inset: var(--sp-md);
  display: none;
}

.chart-canvas-container.visible {
  display: block;
}

/* ============================================================
   Description Panel
   ============================================================ */
.description-panel {
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: var(--sp-md) var(--sp-lg);
  flex-shrink: 0;
  overflow: hidden;
}

.description-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-sm);
}

.description-panel__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
}

.description-panel__toggle {
  background: none;
  border: none;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 2px 4px;
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s;
  line-height: 0;
}

.description-panel__toggle:hover {
  color: var(--color-text);
}

.description-panel__toggle:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.description-panel__toggle svg {
  transition: transform 0.2s ease;
}

.description-panel--collapsed .description-panel__header {
  margin-bottom: 0;
}

.description-panel--collapsed .description-panel__grid {
  display: none;
}

.description-panel--collapsed .description-panel__toggle svg {
  transform: rotate(180deg);
}

.description-panel__grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: var(--sp-lg);
}

.description-panel__heading {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-secondary);
  margin-bottom: var(--sp-sm);
}

.description-panel__body {
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.7;
}

.description-panel__list {
  font-size: 14px;
  color: var(--color-text);
  line-height: 1.8;
  padding-left: var(--sp-lg);
}

.description-panel__list li {
  margin-bottom: var(--sp-xs);
}

.description-panel__list code {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  padding: 1px 4px;
}

.description-panel__list strong {
  font-weight: 600;
  color: var(--color-text);
}

/* ============================================================
   Mobile
   ============================================================ */
@media (max-width: 640px) {
  .layout {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    max-height: 260px;
  }

  .main {
    padding: var(--sp-sm);
  }

  .header__title {
    display: none;
  }

  .description-panel {
    display: none;
  }
}
