/* ── GTFS Editor ─────────────────────────────────────────────── */
:root {
  --gtfs-toolbar-height: 44px;
  --gtfs-sidebar-width: 260px;
  --gtfs-detail-width: 380px;
  --gtfs-search-max: 320px;
  --gtfs-row-height: 34px;
}

/* ── Panel base ──────────────────────────────────────────────── */
.gtfs-panel {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 2px;
  min-height: 300px;
}

/* ── Layout: sidebar + content ───────────────────────────────── */
.gtfs-layout {
  display: flex;
  gap: 0;
  height: calc(100vh - 240px);
  min-height: 400px;
  overflow: hidden;
}

.gtfs-sidebar {
  width: var(--gtfs-sidebar-width);
  max-width: 40vw;
  border-right: 1px solid var(--color-border);
  background: var(--color-field);
  overflow-y: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.gtfs-sidebar-header {
  padding: 0.6rem 0.8rem;
  font-family: var(--font-display);
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}

.gtfs-sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  font-size: 0.84rem;
  border-left: 3px solid transparent;
  transition: background 120ms ease, border-color 120ms ease;
}

.gtfs-sidebar-item:hover {
  background: var(--color-accent-soft);
}

.gtfs-sidebar-item.active {
  background: var(--color-accent-soft);
  border-left-color: var(--color-accent);
  font-weight: 600;
}

.gtfs-sidebar-item .item-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gtfs-sidebar-item .item-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
  flex-shrink: 0;
}

.gtfs-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Toolbar ─────────────────────────────────────────────────── */
.gtfs-toolbar {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-field);
  min-height: var(--gtfs-toolbar-height);
  flex-wrap: wrap;
}

.gtfs-toolbar .form-control {
  width: auto;
  min-width: 140px;
  padding: 0.35rem 0.5rem;
  font-size: 0.85rem;
}

.gtfs-search {
  flex: 1;
  min-width: 180px;
  max-width: var(--gtfs-search-max);
}

.gtfs-toolbar-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gtfs-toolbar-right {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  margin-left: auto;
}

/* ── Table ───────────────────────────────────────────────────── */
.gtfs-table-wrapper {
  flex: 1;
  overflow: auto;
  position: relative;
}

.gtfs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.84rem;
  table-layout: auto;
}

.gtfs-table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.gtfs-table th {
  padding: 0.35rem 0.5rem;
  text-align: left;
  background: var(--color-field);
  color: var(--color-text-muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  border-bottom: 2px solid var(--color-border);
  white-space: nowrap;
  user-select: none;
}

.gtfs-table th.sortable {
  cursor: pointer;
}

.gtfs-table th.sortable:hover {
  color: var(--color-foreground);
}

.gtfs-table th.sortable::after {
  content: "";
  margin-left: 3px;
  font-size: 0.65rem;
}

.gtfs-table th.sortable.asc::after {
  content: "▴";
}

.gtfs-table th.sortable.desc::after {
  content: "▾";
}

.gtfs-table td {
  padding: 0.28rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  line-height: var(--gtfs-row-height);
  white-space: nowrap;
  vertical-align: middle;
}

.gtfs-table tbody tr {
  transition: background 100ms ease;
}

.gtfs-table tbody tr:hover {
  background: var(--color-accent-soft);
}

.gtfs-table tbody tr.selected {
  background: var(--color-accent-soft);
  outline: 1px solid var(--color-accent);
  outline-offset: -1px;
}

/* Editable cells */
.gtfs-table .editable {
  cursor: text;
  border-bottom: 1px dashed transparent;
  transition: border-color 100ms ease;
  position: relative;
}

.gtfs-table .editable:hover {
  background: var(--color-accent-soft);
  border-bottom-color: var(--color-text-muted);
}

.gtfs-table .editable.active-editing {
  padding: 0.15rem 0.2rem;
  background: var(--color-surface-raised);
  border-bottom-color: var(--color-accent);
}

.gtfs-table .editable input,
.gtfs-table .editable select {
  background: var(--color-surface);
  border: 1px solid var(--color-accent);
  padding: 0.15rem 0.35rem;
  font-family: var(--font-body);
  font-size: 0.84rem;
  width: 100%;
  box-sizing: border-box;
  outline: none;
}

/* Cell states */
.gtfs-table td.cell-modified {
  font-weight: 600;
  position: relative;
}

.gtfs-table td.cell-modified::after {
  content: "";
  position: absolute;
  top: 2px;
  right: 2px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-accent);
}

/* Row states */
.gtfs-table tr.row-deleted td {
  opacity: 0.45;
  text-decoration: line-through;
}

.gtfs-table tr.row-added td {
  background: color-mix(in srgb, var(--color-river) 6%, transparent);
}

.gtfs-table tr.row-modified td {
  background: var(--color-accent-soft);
}

/* Actions cell */
.gtfs-table .actions {
  display: flex;
  gap: 0.2rem;
}

.gtfs-table .actions .btn {
  font-size: 0.78rem;
  padding: 0.18rem 0.55rem;
}

/* ── Detail panel (inspector) ────────────────────────────────── */
.gtfs-detail-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 20, 16, 0.25);
  z-index: 898;
  animation: fadeIn 120ms ease;
}

.gtfs-detail-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: var(--gtfs-detail-width);
  max-width: 95vw;
  height: 100vh;
  background: var(--color-surface-raised);
  border-left: 1px solid var(--color-border-strong);
  z-index: 899;
  display: flex;
  flex-direction: column;
  animation: slideInRight 150ms ease;
}

.gtfs-detail-header {
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--color-border-strong);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(90deg, var(--color-accent) 0 3px, transparent 3px);
  padding-left: calc(0.9rem + 3px);
  min-height: 44px;
}

.gtfs-detail-header h3 {
  margin: 0;
  font-size: 1rem;
  font-family: var(--font-display);
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.gtfs-detail-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--color-foreground);
  opacity: 0.5;
  padding: 0.2rem 0.4rem;
  border-radius: 2px;
  transition: opacity 100ms ease;
}

.gtfs-detail-close:hover {
  opacity: 1;
  background: var(--color-accent-soft);
}

.gtfs-detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 0.8rem 0.9rem;
}

.gtfs-detail-footer {
  padding: 0.6rem 0.9rem;
  border-top: 1px solid var(--color-border);
  display: flex;
  gap: 0.4rem;
  justify-content: flex-end;
}

.gtfs-detail-field {
  margin-bottom: 0.7rem;
}

.gtfs-detail-field label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.15rem;
}

.gtfs-detail-field .field-value {
  font-size: 0.9rem;
}

.gtfs-detail-field .field-original {
  font-size: 0.76rem;
  color: var(--color-text-muted);
  text-decoration: line-through;
  margin-top: 0.1rem;
  word-break: break-all;
}

/* ── Color swatch ────────────────────────────────────────────── */
.gtfs-color-swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 2px;
  border: 1px solid var(--color-border-strong);
  vertical-align: middle;
  margin-right: 5px;
  flex-shrink: 0;
}

/* ── Badges ──────────────────────────────────────────────────── */
.gtfs-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 2px;
  white-space: nowrap;
  letter-spacing: 0.03em;
}

.gtfs-badge.modified {
  background: var(--color-accent-soft);
  color: #b45309;
  border: 1px solid var(--color-accent-line);
}

.gtfs-badge.new {
  background: color-mix(in srgb, var(--color-river) 12%, transparent);
  color: var(--color-river);
  border: 1px solid var(--color-river);
}

.gtfs-badge.deleted {
  background: color-mix(in srgb, var(--danger-color) 8%, transparent);
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
}

.gtfs-badge.warning {
  background: color-mix(in srgb, #d97706 8%, transparent);
  color: #d97706;
  border: 1px solid #d97706;
}

.gtfs-badge.hidden {
  background: var(--color-muted);
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.gtfs-badge.clean {
  background: color-mix(in srgb, var(--color-river) 6%, transparent);
  color: var(--color-river);
  border: 1px solid var(--color-river);
}

/* ── Shapes map ──────────────────────────────────────────────── */
.gtfs-shapes-layout {
  display: flex;
  height: calc(100vh - 260px);
  min-height: 400px;
}

.gtfs-shapes-sidebar {
  width: 280px;
  max-width: 35vw;
  overflow-y: auto;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  flex-shrink: 0;
}

.gtfs-shapes-map-wrap {
  flex: 1;
  position: relative;
  min-width: 0;
}

.gtfs-shapes-map {
  width: 100%;
  height: 100%;
  border: none;
}

.gtfs-shapes-map .leaflet-container {
  height: 100%;
  background: var(--color-field);
}

/* Floating map tools */
.gtfs-map-tools {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  border-radius: 2px;
  padding: 2px;
  box-shadow: 2px 2px 0 var(--color-accent-soft);
}

.gtfs-map-tools button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 2px;
  color: var(--color-foreground);
  font-size: 1rem;
  transition: background 80ms ease;
}

.gtfs-map-tools button:hover {
  background: var(--color-accent-soft);
}

.gtfs-map-tools button:disabled {
  opacity: 0.3;
  cursor: default;
}

.gtfs-map-coords {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 1000;
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border-strong);
  padding: 2px 8px;
  font-size: 0.75rem;
  font-family: monospace;
  border-radius: 2px;
}

/* ── Validation ──────────────────────────────────────────────── */
.gtfs-validation-summary {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
  flex-wrap: wrap;
}

.gtfs-validation-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.3rem 0.75rem;
  border: 1px solid;
  border-radius: 2px;
  font-size: 0.82rem;
  font-weight: 700;
}

.gtfs-validation-badge.errors {
  border-color: var(--danger-color);
  color: var(--danger-color);
  background: color-mix(in srgb, var(--danger-color) 5%, transparent);
}

.gtfs-validation-badge.warnings {
  border-color: #d97706;
  color: #d97706;
  background: color-mix(in srgb, #d97706 5%, transparent);
}

.gtfs-validation-badge.passed {
  border-color: var(--color-river);
  color: var(--color-river);
  background: color-mix(in srgb, var(--color-river) 5%, transparent);
}

.gtfs-validation-item {
  padding: 0.4rem 0.6rem;
  border-left: 3px solid var(--color-border);
  margin-bottom: 0.3rem;
  background: var(--color-field);
  font-size: 0.84rem;
  border-radius: 0 2px 2px 0;
  cursor: default;
  transition: background 100ms ease;
}

.gtfs-validation-item.error {
  border-left-color: var(--danger-color);
}

.gtfs-validation-item.warning {
  border-left-color: #d97706;
}

.gtfs-validation-item.clickable {
  cursor: pointer;
}

.gtfs-validation-item.clickable:hover {
  background: var(--color-surface);
}

/* ── Diff & Publish ──────────────────────────────────────────── */
.gtfs-diff-section {
  margin-bottom: 1.2rem;
}

.gtfs-diff-section h4 {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.gtfs-diff-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 2px;
  white-space: nowrap;
}

.gtfs-diff-badge.added {
  background: color-mix(in srgb, var(--color-river) 12%, transparent);
  color: var(--color-river);
  border: 1px solid var(--color-river);
}

.gtfs-diff-badge.modified {
  background: var(--color-accent-soft);
  color: #b45309;
  border: 1px solid var(--color-accent-line);
}

.gtfs-diff-badge.removed {
  background: color-mix(in srgb, var(--danger-color) 8%, transparent);
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
}

/* Publish pipeline stepper */
.gtfs-pipeline {
  display: flex;
  align-items: center;
  gap: 0;
  margin-bottom: 1rem;
  padding: 0.6rem 0.8rem;
  background: var(--color-field);
  border: 1px solid var(--color-border);
  border-radius: 2px;
  overflow-x: auto;
}

.gtfs-pipeline-step {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--color-text-muted);
  white-space: nowrap;
}

.gtfs-pipeline-step .step-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  font-weight: 800;
  border: 1px solid var(--color-border);
  background: var(--color-surface);
}

.gtfs-pipeline-step.active {
  color: var(--color-foreground);
}

.gtfs-pipeline-step.active .step-num {
  background: var(--color-accent);
  border-color: var(--color-accent);
  color: #23211e;
}

.gtfs-pipeline-step.done {
  color: var(--color-river);
}

.gtfs-pipeline-step.done .step-num {
  background: var(--color-river);
  border-color: var(--color-river);
  color: #fff;
}

.gtfs-pipeline-arrow {
  margin: 0 0.4rem;
  color: var(--color-border);
  font-size: 0.7rem;
}

/* ── Calendar grid ───────────────────────────────────────────── */
.gtfs-calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 0.6rem;
}

.gtfs-calendar-card {
  border: 1px solid var(--color-border);
  border-radius: 2px;
  padding: 0.7rem;
  background: var(--color-field);
  max-width: 480px;
}

.gtfs-calendar-card h4 {
  font-family: var(--font-display);
  font-weight: 800;
  margin-bottom: 0.4rem;
  font-size: 0.92rem;
  line-height: 1.3;
}

.gtfs-day-chips {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.gtfs-day-chip {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 2px;
  font-size: 0.74rem;
  font-weight: 700;
  cursor: pointer;
  background: var(--color-surface);
  transition: background 80ms ease, color 80ms ease, border-color 80ms ease;
  user-select: none;
}

.gtfs-day-chip:hover {
  border-color: var(--color-accent);
}

.gtfs-day-chip.active {
  background: var(--color-foreground);
  color: var(--color-background);
  border-color: var(--color-foreground);
}

.gtfs-day-chip:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* ── Sequence (stop-times) ───────────────────────────────────── */
.gtfs-sequence {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--color-border);
  border-radius: 2px;
  overflow: hidden;
}

.gtfs-sequence-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--color-border);
  transition: background 100ms ease, opacity 100ms ease;
}

.gtfs-sequence-item:last-child {
  border-bottom: none;
}

.gtfs-sequence-item:hover {
  background: var(--color-accent-soft);
}

.gtfs-sequence-item.dragging {
  opacity: 0.4;
}

.gtfs-sequence-item.drag-over {
  border-top: 2px solid var(--color-accent);
}

.gtfs-sequence-item .seq-num {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--color-foreground);
  color: var(--color-background);
  flex-shrink: 0;
}

.gtfs-sequence-item .seq-time {
  font-family: var(--font-display);
  font-size: 0.85rem;
  font-weight: 800;
  min-width: 55px;
  color: var(--color-river);
}

.gtfs-sequence-item .seq-name {
  flex: 1;
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gtfs-sequence-item .seq-actions {
  display: flex;
  gap: 0.2rem;
  flex-shrink: 0;
}

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

.gtfs-empty h4 {
  color: var(--color-text-muted);
  font-size: 1rem;
  margin-bottom: 0.3rem;
}

/* ── Keyboard shortcuts hint ──────────────────────────────────── */
.gtfs-shortcut-hint {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  font-size: 0.68rem;
  color: var(--color-text-muted);
}

.gtfs-shortcut-hint kbd {
  padding: 1px 4px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 2px;
  font-family: monospace;
  font-size: 0.7rem;
}

/* ── Animations ──────────────────────────────────────────────── */
@keyframes slideInRight {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Focus & Accessibility ───────────────────────────────────── */
.gtfs-table .editable:focus-visible,
.gtfs-day-chip:focus-visible,
.gtfs-sequence-item:focus-visible,
.gtfs-sidebar-item:focus-visible,
.gtfs-detail-close:focus-visible,
.gtfs-map-tools button:focus-visible,
.gtfs-validation-item.clickable:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -1px;
}

.gtfs-toolbar button:focus-visible,
.gtfs-toolbar input:focus-visible,
.gtfs-toolbar select:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

@media (prefers-reduced-motion: reduce) {
  .gtfs-detail-panel,
  .gtfs-detail-overlay {
    animation: none;
  }
  .gtfs-table tbody tr,
  .gtfs-day-chip,
  .gtfs-sequence-item,
  .gtfs-sidebar-item {
    transition: none;
  }
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .gtfs-layout {
    flex-direction: column;
    height: auto;
  }
  .gtfs-sidebar {
    width: 100%;
    max-width: 100%;
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .gtfs-detail-panel {
    width: 100vw;
    max-width: 100vw;
  }
  .gtfs-shapes-layout {
    flex-direction: column;
    height: auto;
  }
  .gtfs-shapes-sidebar {
    width: 100%;
    max-width: 100%;
    max-height: 30vh;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
}
