/* ── Variablen ─────────────────────────────────────────────────────────────── */
:root {
  --bg:         #0d0f14;
  --bg-card:    #141720;
  --bg-input:   #1e2130;
  --bg-hover:   #1e2230;
  --border:     #2a2d3a;
  --accent:     #e8a020;
  --accent-dim: rgba(232,160,32,.15);
  --accent-glow:rgba(232,160,32,.08);
  --text:       #dde1eb;
  --text-dim:   #7a8099;
  --text-muted: #4a5066;
  --danger:     #c0392b;
  --danger-dim: rgba(192,57,43,.15);
  --success:    #27ae60;
  --radius:     8px;
  --radius-lg:  12px;
  --shadow:     0 2px 12px rgba(0,0,0,.4);
}

/* ── Reset & Base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  min-height: 100vh;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }

/* ── Header ────────────────────────────────────────────────────────────────── */
.header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(8px);
}
.header-inner {
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 32px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: -.02em;
  text-decoration: none;
  flex-shrink: 0;
}
.logo svg { display: block; }
.logo:hover { text-decoration: none; opacity: .9; }
nav { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 14px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: .9rem;
  transition: color .15s, background .15s;
  text-decoration: none;
}
.nav-link:hover { color: var(--text); background: var(--bg-hover); text-decoration: none; }
.nav-link.active { color: var(--accent); background: var(--accent-dim); }

/* ── Layout ────────────────────────────────────────────────────────────────── */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px; }
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}
.page-title { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }

/* ── Kacheln ───────────────────────────────────────────────────────────────── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 16px; margin-bottom: 28px; }
.tile {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  position: relative;
  overflow: hidden;
}
.tile::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; height: 2px;
  background: var(--accent);
  opacity: .6;
}
.tile-label { font-size: .78rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.tile-value { font-size: 2rem; font-weight: 700; color: var(--accent); line-height: 1; }
.tile-sub { font-size: .82rem; color: var(--text-dim); margin-top: 6px; }

/* ── Karte ─────────────────────────────────────────────────────────────────── */
.map-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 28px;
}
.map-wrap h2 {
  padding: 16px 20px 0;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
}
#map { height: 380px; }

/* ── Cards (Letzte Fahrten) ────────────────────────────────────────────────── */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
  transition: border-color .15s;
}
.card:hover { border-color: var(--accent); }
.card-meta { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.card-date { font-size: .82rem; color: var(--text-dim); }
.card-badge {
  font-size: .72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
}
.card-route { font-size: 1.05rem; font-weight: 600; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }
.card-route .arrow { color: var(--text-muted); }
.card-details { display: flex; gap: 16px; font-size: .83rem; color: var(--text-dim); }
.card-detail-item { display: flex; gap: 4px; }
.card-detail-item strong { color: var(--text); }

/* ── Tabelle ───────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); }
th {
  padding: 12px 16px;
  text-align: left;
  font-size: .78rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}
td { padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: .88rem; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }
.td-mono { font-family: monospace; font-size: .85rem; }
.td-muted { color: var(--text-dim); }
.td-accent { color: var(--accent); font-weight: 600; }
.verspaetung { color: #e67e22; }
.verspaetung-null { color: var(--text-muted); }

/* ── Aktionsleiste ─────────────────────────────────────────────────────────── */
.action-bar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.spacer { flex: 1; }
.selection-info { font-size: .85rem; color: var(--text-dim); }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: .88rem;
  font-weight: 500;
  transition: opacity .15s, background .15s, border-color .15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; opacity: .88; }
.btn-primary { background: var(--accent); color: #000; }
.btn-secondary { background: var(--bg-input); color: var(--text); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.btn-danger { background: var(--danger-dim); color: #e74c3c; border-color: transparent; }
.btn-sm { padding: 5px 10px; font-size: .8rem; }
.btn:disabled { opacity: .4; cursor: not-allowed; }

/* ── Formular ──────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.form-grid .full { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: .8rem; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .05em; }
.form-group input,
.form-group select,
.form-group textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  transition: border-color .15s;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus { border-color: var(--accent); }
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group select option { background: var(--bg-card); }
.form-divider { grid-column: 1 / -1; border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.form-section-title { grid-column: 1 / -1; font-size: .78rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: .07em; margin-bottom: -8px; }
.form-actions { display: flex; gap: 12px; align-items: center; margin-top: 24px; }

/* ── Betriebsstellen-Eingabe ───────────────────────────────────────────────── */
.bs-input-wrap { position: relative; }
.bs-input-row { display: flex; gap: 8px; }
.bs-input-row input { flex: 1; }
.bs-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  z-index: 200;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.bs-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background .1s;
}
.bs-option:last-child { border-bottom: none; }
.bs-option:hover { background: var(--bg-hover); }
.bs-ds100 { font-family: monospace; font-size: .85rem; color: var(--accent); width: 54px; flex-shrink: 0; }
.bs-name { font-size: .88rem; }
.bs-typ { font-size: .75rem; color: var(--text-muted); margin-left: auto; }
.bs-empty { padding: 12px 14px; font-size: .85rem; color: var(--text-dim); }

/* ── Chips ─────────────────────────────────────────────────────────────────── */
.chips { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 10px;
  font-size: .85rem;
}
.chip-pos { width: 20px; height: 20px; border-radius: 50%; background: var(--accent); color: #000; font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.chip-ds100 { font-family: monospace; color: var(--accent); width: 52px; flex-shrink: 0; }
.chip-name { color: var(--text); flex: 1; }
.chip-rm { margin-left: auto; background: none; border: none; color: var(--text-muted); font-size: 1rem; padding: 0 4px; line-height: 1; transition: color .1s; }
.chip-rm:hover { color: #e74c3c; }

/* ── km-Ergebnis ───────────────────────────────────────────────────────────── */
.km-result {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--accent-glow);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-top: 10px;
  font-size: .9rem;
}
.km-result .km-val { font-size: 1.3rem; font-weight: 700; color: var(--accent); }
.km-result.hidden { display: none; }

/* ── Loader / leere Zustände ───────────────────────────────────────────────── */
.loading { color: var(--text-dim); font-size: .88rem; padding: 40px; text-align: center; }
.empty { color: var(--text-dim); font-size: .9rem; text-align: center; padding: 60px 20px; }
.error-msg { color: #e74c3c; font-size: .85rem; margin-top: 8px; }

/* ── Checkbox ──────────────────────────────────────────────────────────────── */
input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; cursor: pointer; }

/* ── Responsiv ─────────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .full { grid-column: 1; }
  .tiles { grid-template-columns: 1fr 1fr; }
  .page { padding: 16px; }
}

@media (max-width: 768px) {
  /* ── Logbuch: Card-Layout ────────────────────────────────────────────────── */
  .table-wrap { background: transparent; border: none; border-radius: 0; overflow: visible; box-shadow: none; }
  #fahrt-table { display: block; }
  #fahrt-table thead { display: none; }
  #fahrt-table tbody { display: block; }
  #fahrt-table tbody.schicht-tbody.expanded { display: block !important; }

  /* Year / Month / Schicht header rows */
  #fahrt-table tr.year-header-row,
  #fahrt-table tr.month-header-row,
  #fahrt-table tr.schicht-header-row { display: block; }
  #fahrt-table tr.year-header-row > td,
  #fahrt-table tr.month-header-row > td,
  #fahrt-table tr.schicht-header-row > td { display: block; padding: 0; border: none; }

  /* Compact year / month / schicht wrappers */
  .year-header  { padding: 8px 12px 5px; }
  .month-header { padding: 4px 12px 4px; }
  .schicht-header { padding: 7px 12px; }

  /* Individual ride rows → cards */
  #fahrt-table tr.zug-row,
  #fahrt-table tr.leer-row,
  #fahrt-table tr.gast-row,
  #fahrt-table tr.schicht-member {
    display: block;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 3px solid var(--typ-color, var(--accent));
    border-radius: var(--radius);
    margin-bottom: 6px;
    padding: 10px 12px;
  }
  #fahrt-table tr.schicht-member { border-left-color: var(--border); }

  /* All tds inside ride cards: block, compact */
  #fahrt-table tr.zug-row > td,
  #fahrt-table tr.leer-row > td,
  #fahrt-table tr.gast-row > td,
  #fahrt-table tr.schicht-member > td { display: block; padding: 1px 0; border: none; font-size: .85rem; }

  /* Checkbox column: hide */
  #fahrt-table tr.zug-row > td:nth-child(1),
  #fahrt-table tr.leer-row > td:nth-child(1),
  #fahrt-table tr.gast-row > td:nth-child(1),
  #fahrt-table tr.schicht-member > td:nth-child(1) { display: none; }

  /* Datum: small + dim */
  #fahrt-table tr.zug-row > td:nth-child(2),
  #fahrt-table tr.leer-row > td:nth-child(2),
  #fahrt-table tr.gast-row > td:nth-child(2),
  #fahrt-table tr.schicht-member > td:nth-child(2) { font-size: .77rem; color: var(--text-dim); }

  /* Baureihe + Fahrzeug: small */
  #fahrt-table tr.zug-row > td:nth-child(6),
  #fahrt-table tr.leer-row > td:nth-child(6),
  #fahrt-table tr.gast-row > td:nth-child(6),
  #fahrt-table tr.schicht-member > td:nth-child(6),
  #fahrt-table tr.zug-row > td:nth-child(7),
  #fahrt-table tr.leer-row > td:nth-child(7),
  #fahrt-table tr.gast-row > td:nth-child(7),
  #fahrt-table tr.schicht-member > td:nth-child(7) { font-size: .77rem; color: var(--text-dim); }

  /* Notiz: hide */
  #fahrt-table tr.zug-row > td:nth-child(8),
  #fahrt-table tr.leer-row > td:nth-child(8),
  #fahrt-table tr.gast-row > td:nth-child(8),
  #fahrt-table tr.schicht-member > td:nth-child(8) { display: none; }

  /* Actions: right-aligned */
  #fahrt-table tr.zug-row > td:nth-child(9),
  #fahrt-table tr.leer-row > td:nth-child(9),
  #fahrt-table tr.gast-row > td:nth-child(9),
  #fahrt-table tr.schicht-member > td:nth-child(9) { text-align: right; padding-top: 4px; }
  #fahrt-table tr.zug-row > td:nth-child(9) > div,
  #fahrt-table tr.leer-row > td:nth-child(9) > div,
  #fahrt-table tr.gast-row > td:nth-child(9) > div,
  #fahrt-table tr.schicht-member > td:nth-child(9) > div { justify-content: flex-end; }

  /* Reset indentation applied by base CSS */
  .schicht-member td:first-child { padding-left: 0; }
  .einzelfahrt-tbody tr td:first-child { padding-left: 0; }
  .einzelfahrt-tbody tr td { border-bottom: none; }
  .schicht-member td { background: transparent; border-bottom: none; }

  /* Action bar */
  .page { padding: 12px; }
  .action-bar { margin-bottom: 10px; gap: 8px; }
}
