:root {
  --fg: #1a1a1a;
  --muted: #666;
  --bg: #fff;
  --accent: #1f4d2e;      /* dunkelgrün, deutlich vom Flixbus-Grün abgesetzt */
  --accent-dark: #143019;
  --accent-soft: #e6efe9;
  --border: #ddd;
  --error: #c33;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
  line-height: 1.4;
}

header {
  background: var(--accent);
  color: white;
  padding: 1rem 0;
}

header .header-inner {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

header .header-icon {
  flex-shrink: 0;
  font-size: 2.5rem;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
}

header h1 { margin: 0; font-size: 1.4rem; }
header .subtitle { margin: 0.25rem 0 0; opacity: 0.85; font-size: 0.9rem; }
header .brand-tag {
  margin: 0.25rem 0 0;
  opacity: 0.65;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

main {
  padding: 1.5rem;
  max-width: 1200px;
  margin: 0 auto;
}

form {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  margin-bottom: 2rem;
}

.form-section {
  border: 1px solid var(--border);
  border-radius: 6px;
  min-width: 0;
}

.form-section > summary {
  cursor: pointer;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  font-weight: 600;
  color: var(--accent);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-section > summary::-webkit-details-marker { display: none; }

.form-section > summary::before {
  content: "▸";
  color: var(--accent-dark);
  transition: transform 0.15s;
}

.form-section[open] > summary::before { transform: rotate(90deg); }

.form-section .section-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0 1rem 0.85rem;
}

label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 0.9rem;
}

label.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
}

.hint {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: normal;
  line-height: 1.3;
  margin-top: 0.1rem;
}

.dist {
  color: var(--muted);
  font-size: 0.8em;
  font-weight: normal;
}

details.result-group {
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0.5rem 0;
}
details.result-group > summary {
  cursor: pointer;
  padding: 0.5rem 0.75rem;
  background: var(--accent-soft);
  font-weight: 600;
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-radius: 6px;
}
details.result-group[open] > summary {
  border-radius: 6px 6px 0 0;
  border-bottom: 1px solid var(--border);
}
details.result-group > summary::before {
  content: "▸";
  margin-right: 0.5rem;
  transition: transform 0.15s;
  color: var(--accent-dark);
}
details.result-group[open] > summary::before {
  transform: rotate(90deg);
}
details.result-group > summary::-webkit-details-marker { display: none; }
details.result-group .group-label { flex: 1; }
details.result-group .group-count {
  color: var(--muted);
  font-size: 0.85em;
  font-weight: normal;
}
details.result-group > table.results {
  margin: 0;
}

table.results tr.row-main.can-expand { cursor: pointer; }
table.results tr.row-main.can-expand:hover { background: var(--accent-soft); }
table.results td.caret-cell { width: 1.2em; text-align: center; color: var(--accent-dark); }
table.results td.caret-cell .caret {
  display: inline-block;
  transition: transform 0.15s;
}
table.results tr.row-main.expanded td.caret-cell .caret {
  transform: rotate(90deg);
}

table.results tr.row-departure > td {
  background: #fafafa;
  font-size: 0.82rem;
  color: var(--muted);
  padding-top: 0.25rem;
  padding-bottom: 0.25rem;
  border-bottom: 1px solid #eee;
}
table.results tr.row-departure.synthetic > td { font-style: italic; }
table.results tr.row-departure td.departure-time {
  color: var(--fg);
  padding-left: 1.5rem;
}

input[type="text"], input[type="number"], input[type="date"], input[type="time"], select {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  width: 100%;
  font-family: inherit;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath fill='none' stroke='%23666' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round' d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 5px center;
  background-size: 0.8rem;
}

.input-unit {
  position: relative;
  display: block;
}

.input-unit input {
  padding-right: 2.2rem;
  appearance: textfield;
  -moz-appearance: textfield;
}

.input-unit input::-webkit-outer-spin-button,
.input-unit input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.input-unit .unit {
  position: absolute;
  right: 0.6rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.9rem;
  pointer-events: none;
}

input[type="checkbox"] { margin: 0; }

.weekdays {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.field-row {
  display: flex;
  gap: 0.75rem;
}

.field-row > label { flex: 1; min-width: 0; }

#stops-section { grid-column: 1 / -1; }

.stops-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
}

.stop-cell {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.6rem;
}

.stop-cell .remove-stop {
  order: -1;
  align-self: flex-end;
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 0.1rem 0.3rem;
  font-size: 0.8rem;
  font-weight: normal;
}

.stop-cell .remove-stop:hover { color: var(--error); }

.add-stop {
  background: transparent;
  color: var(--accent);
  border: 1px dashed var(--border);
  border-radius: 6px;
  font-size: 0.95rem;
}

.add-stop:hover { background: var(--accent-soft); }

section.leg { margin: 1.5rem 0; }
section.leg > h3 { margin: 0 0 0.5rem; }

.actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 1rem;
}

button {
  background: var(--accent);
  color: white;
  border: 0;
  padding: 0.55rem 1.2rem;
  border-radius: 4px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--accent-dark); }

.htmx-indicator {
  display: none;
  color: var(--muted);
  font-style: italic;
}

.loading {
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
  margin: 1.5rem 0;
}

#loading.htmx-request { display: flex; }

.spinner {
  width: 2.5rem;
  height: 2.5rem;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

#results { margin-top: 1rem; }

.results-header h2 { margin: 0 0 0.25rem; }
.meta { color: var(--muted); font-size: 0.9rem; margin: 0.25rem 0 1rem; }
.relax-note {
  background: #fffbe5;
  border: 1px solid #f0d480;
  padding: 0.5rem 0.75rem;
  border-radius: 4px;
  font-size: 0.85rem;
  margin: 0.5rem 0 1rem;
}

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--border);
  border-radius: 6px;
}

.error {
  background: #ffe5e5;
  border: 1px solid #f5a;
  color: var(--error);
  padding: 0.6rem 0.9rem;
  border-radius: 4px;
}

table.results {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
  margin: 0.5rem 0 1.5rem;
}

table.results th, table.results td {
  padding: 0.5rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.results th {
  background: #f6f6f6;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

table.results th[data-sort] {
  cursor: pointer;
  user-select: none;
}
table.results th[data-sort]:hover { color: var(--fg); }
table.results th[data-sort] .arrow { color: var(--accent-dark); }
table.results th[data-dir] { color: var(--fg); }

table.results tr:hover { background: #fafafa; }

a.book-link {
  display: inline-block;
  white-space: nowrap;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.8rem;
  padding: 0.35rem 0.7rem;
  border-radius: 4px;
  text-decoration: none;
}
a.book-link:hover { background: var(--accent-dark); }
table.results.detail td { font-family: ui-monospace, Menlo, monospace; font-size: 0.82rem; }

.day-tabs {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  margin: 0.5rem 0 1rem;
  border-bottom: 1px solid var(--border);
}

.day-nav {
  background: transparent;
  color: var(--muted);
  font-size: 1.2rem;
  padding: 0.2rem 0.6rem;
  border: 0;
  cursor: pointer;
}
.day-nav:hover { color: var(--fg); background: #f0f0f0; }

.tab-strip {
  display: flex;
  gap: 0.3rem;
  overflow-x: auto;
  scroll-behavior: smooth;
  flex: 1;
  scrollbar-width: thin;
}

.day-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.1rem;
  background: #f6f6f6;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  padding: 0.4rem 0.8rem;
  cursor: pointer;
  font-size: 0.82rem;
  white-space: nowrap;
  min-width: 70px;
  position: relative;
  font-weight: 600;
}

.day-tab:hover { background: #ebebeb; color: var(--fg); }

.day-tab.active {
  background: white;
  color: var(--fg);
  border-color: var(--border);
  border-bottom-color: white;
  margin-bottom: -1px;
}

.day-tab.cheapest::before {
  content: "★";
  position: absolute;
  top: 2px;
  right: 4px;
  color: var(--accent-dark);
  font-size: 0.7rem;
}

.day-tab .tab-label { font-size: 0.85rem; }
.day-tab .tab-badge {
  font-size: 0.7rem;
  color: var(--muted);
  background: rgba(0,0,0,0.05);
  border-radius: 8px;
  padding: 0 0.4rem;
}
.day-tab.active .tab-badge { background: var(--accent); color: white; }
.day-tab .tab-price {
  font-size: 0.7rem;
  color: var(--accent-dark);
}

.day-pane { display: none; }
.day-pane.active { display: block; }

/* Breite Ergebnis-Tabellen horizontal scrollbar machen, statt den Viewport zu sprengen */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {
  header { padding: 0.85rem 0; }
  header .header-inner { padding: 0 1rem; }
  header h1 { font-size: 1.15rem; }
  header .subtitle { font-size: 0.82rem; }

  main { padding: 1rem; }

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

  .stops-grid { grid-template-columns: 1fr; }

  .actions button { flex: 1; }

  /* Tabelle über ihre natürliche Breite wachsen lassen und den .table-scroll
     scrollen lassen, statt Spalten unleserlich umzubrechen */
  .table-scroll table.results {
    width: auto;
    min-width: 100%;
  }
  table.results th, table.results td { white-space: nowrap; }

  .day-tab {
    min-width: 60px;
    padding: 0.35rem 0.6rem;
  }
}
