:root {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --text: #202436;
  --muted: #647084;
  --border: #d9deea;
  --primary: #1f5fbf;
  --primary-dark: #164991;
  --danger: #c53737;
  --grid: #e8ebf2;
  --axis: #738095;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 28px;
  background: linear-gradient(135deg, #183e77, #1f5fbf);
  color: #fff;
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 24px;
}

.app-header p {
  margin: 0;
  opacity: 0.88;
}

.header-actions {
  display: flex;
  align-items: center;
}

main {
  padding: 20px 28px 32px;
}

.panel, .diagram-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(20, 35, 70, 0.07);
}

.panel {
  padding: 18px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  color: var(--muted);
}

input, select, button {
  font: inherit;
}

input, select {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 10px;
  background: #fff;
  color: var(--text);
}

button {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--primary);
  color: #fff;
  cursor: pointer;
  font-weight: 650;
}

button:hover { background: var(--primary-dark); }
button:disabled {
  background: #aab2c3;
  cursor: not-allowed;
}

button.secondary {
  background: #eef2f8;
  color: #24415f;
  border: 1px solid #cfdaea;
}

button.secondary:hover {
  background: #dfe8f5;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.status {
  margin-top: 12px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.status.error { color: var(--danger); font-weight: 650; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin: 16px 0;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.stat-card strong {
  font-size: 22px;
}

.diagram-wrap {
  overflow: hidden;
}

.diagram-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}

#diagramTitle {
  font-weight: 700;
}

.legend {
  display: flex;
  gap: 14px;
  color: var(--muted);
  font-size: 13px;
}

.line-sample {
  display: inline-block;
  width: 28px;
  height: 3px;
  background: #2c5aa0;
  vertical-align: middle;
  margin-right: 4px;
}

.dot-sample {
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #fff;
  border: 2px solid #2c5aa0;
  border-radius: 50%;
  vertical-align: middle;
  margin-right: 4px;
}

.diagram-scroll {
  width: 100%;
  height: 68vh;
  min-height: 520px;
  overflow: auto;
  background: #fff;
}

#diagramSvg {
  min-width: 100%;
  min-height: 100%;
  display: block;
}

.axis-text {
  fill: #3f4c5f;
  font-size: 12px;
}

.time-text {
  fill: #647084;
  font-size: 11px;
}

.grid-line {
  stroke: var(--grid);
  stroke-width: 1;
}

.axis-line {
  stroke: var(--axis);
  stroke-width: 1.2;
}

.trip-line {
  fill: none;
  stroke: #2c5aa0;
  stroke-width: 1.7;
  opacity: 0.76;
}

.trip-line:hover {
  stroke-width: 3;
  opacity: 1;
}

.stop-dot {
  fill: #fff;
  stroke: #2c5aa0;
  stroke-width: 1.8;
}

.stop-dot.missing-warning {
  stroke: var(--danger);
}

.trip-label {
  font-size: 10px;
  fill: #2b3f63;
  pointer-events: none;
}

.tooltip {
  position: fixed;
  z-index: 10;
  max-width: 380px;
  background: #18202f;
  color: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,.24);
  font-size: 12px;
  line-height: 1.5;
  pointer-events: none;
  white-space: pre-line;
}

.details-panel {
  margin-top: 16px;
}

.details-panel h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.table-wrap {
  overflow: auto;
  max-height: 360px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
}

th, td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  background: #f3f6fb;
  z-index: 1;
}

td.warning {
  color: var(--danger);
  font-weight: 650;
}

dialog {
  border: 0;
  border-radius: 16px;
  max-width: 720px;
  padding: 22px;
  box-shadow: 0 16px 48px rgba(0,0,0,.28);
}

dialog::backdrop {
  background: rgba(10,20,40,.42);
}

@media (max-width: 980px) {
  .controls-grid {
    grid-template-columns: repeat(2, minmax(140px, 1fr));
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .app-header {
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  main { padding: 14px; }
  .controls-grid, .stats-grid {
    grid-template-columns: 1fr;
  }
  .diagram-toolbar {
    flex-direction: column;
    align-items: flex-start;
  }
}
