/* S-Bahn Schichten – Komponenten-Layer (self-hosted, keine Dritt-Ressourcen).
   Ergaenzt das Tailwind-Utility-Setup um eine konsistente Komponenten-Sprache. */

:root {
  --btn-primary: #2563eb;
  --btn-primary-hover: #1d4ed8;
}

/* ---------- Browser-Oberflaechen: themen statt Defaults ---------- */
::selection { background: #bfdbfe; color: #1e3a8a; }
.dark ::selection { background: #1e40af; color: #e0e7ff; }

:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 4px;
}
.dark :focus-visible { outline-color: #60a5fa; }

html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* Zahlen in Tabellen/Kosten statisch ausrichten */
.tnum { font-variant-numeric: tabular-nums; }

/* ---------- Buttons: eine Form, alle Zustände ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 150ms ease, border-color 150ms ease, color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
  user-select: none;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--btn-primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.25);
}
.btn-primary:hover { background: var(--btn-primary-hover); }
.btn-primary:active { box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.15); }

.btn-secondary {
  background: #fff;
  border-color: #d1d5db;
  color: #374151;
}
.btn-secondary:hover { background: #f3f4f6; border-color: #9ca3af; }
.dark .btn-secondary {
  background: #374151;
  border-color: #4b5563;
  color: #e5e7eb;
}
.dark .btn-secondary:hover { background: #4b5563; border-color: #6b7280; }

.btn-ghost {
  background: transparent;
  color: #4b5563;
}
.btn-ghost:hover { background: rgba(107, 114, 128, 0.12); color: #111827; }
.dark .btn-ghost { color: #9ca3af; }
.dark .btn-ghost:hover { background: rgba(156, 163, 175, 0.14); color: #f3f4f6; }

.btn-danger { background: #dc2626; color: #fff; box-shadow: 0 1px 2px rgba(220, 38, 38, 0.25); }
.btn-danger:hover { background: #b91c1c; }

.btn-success { background: #059669; color: #fff; box-shadow: 0 1px 2px rgba(5, 150, 105, 0.25); }
.btn-success:hover { background: #047857; }

.btn-sm { padding: 0.3125rem 0.75rem; font-size: 0.8125rem; border-radius: 0.375rem; }
.btn-xs { padding: 0.1875rem 0.5rem; font-size: 0.75rem; border-radius: 0.375rem; }

/* Textlink-Button (zeilt sich wie ein Link, funktioniert wie ein Button) */
.btn-link {
  background: transparent;
  border: none;
  padding: 0;
  height: auto;
  color: #2563eb;
  font-weight: 500;
  cursor: pointer;
}
.btn-link:hover { color: #1d4ed8; text-decoration: underline; }
.dark .btn-link { color: #60a5fa; }
.dark .btn-link:hover { color: #93c5fd; }
.btn-link.btn-danger-link { color: #dc2626; }
.btn-link.btn-danger-link:hover { color: #b91c1c; }
.dark .btn-link.btn-danger-link { color: #f87171; }

/* ---------- Karten: eine Kante, ein Schatten ---------- */
.card {
  background: #fff;
  border-radius: 0.75rem;
  border: 1px solid #e5e7eb;
  box-shadow: 0 1px 2px rgba(17, 24, 39, 0.05), 0 1px 3px rgba(17, 24, 39, 0.06);
}
.dark .card {
  background: #1f2937;
  border-color: #374151;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.35);
}

/* Karten-Überschrift: entsprich der bestehenden text-lg/semibold-Stufe */
.card-title {
  font-size: 1.125rem;
  line-height: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: #111827;
}
.dark .card-title { color: #f3f4f6; }

/* Seiten-Überschrift (H1-Ebene): entsprich der bestehenden text-2xl/bold-Stufe */
.page-title {
  font-size: 1.5rem;
  line-height: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #111827;
}
.dark .page-title { color: #f9fafb; }

/* Abschnitts-Überschrift innerhalb von Seiten: text-xl/semibold-Stufe */
.section-title {
  font-size: 1.25rem;
  line-height: 1.75rem;
  font-weight: 600;
  letter-spacing: -0.015em;
  color: #111827;
}
.dark .section-title { color: #f3f4f6; }

/* ---------- Felder: einheitliche Basis fuer alle Roh-Elemente ---------- */
input[type="text"]:not([class*="border"]),
input[type="number"]:not([class*="border"]),
input[type="email"]:not([class*="border"]),
input[type="password"]:not([class*="border"]),
input[type="date"]:not([class*="border"]),
input[type="time"]:not([class*="border"]),
input[type="url"]:not([class*="border"]),
input[type="search"]:not([class*="border"]),
select:not([class*="border"]),
textarea:not([class*="border"]) {
  border: 1px solid #d1d5db;
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  background: #fff;
  color: #111827;
}
.dark input[type="text"]:not([class*="border"]),
.dark input[type="number"]:not([class*="border"]),
.dark input[type="email"]:not([class*="border"]),
.dark input[type="password"]:not([class*="border"]),
.dark input[type="date"]:not([class*="border"]),
.dark input[type="time"]:not([class*="border"]),
.dark input[type="url"]:not([class*="border"]),
.dark input[type="search"]:not([class*="border"]),
.dark select:not([class*="border"]),
.dark textarea:not([class*="border"]) {
  border-color: #4b5563;
  background: #374151;
  color: #e5e7eb;
}

/* Dark-Mode-Farbierung nativer Datums-/Zeit-Picker */
.dark input[type="date"]::-webkit-calendar-picker-indicator,
.dark input[type="time"]::-webkit-calendar-picker-indicator {
  filter: invert(1) opacity(0.65);
}

input::placeholder, textarea::placeholder { color: #9ca3af; }
.dark input::placeholder, .dark textarea::placeholder { color: #6b7280; }

/* Checkboxen/Radios im Akzentton */
input[type="checkbox"], input[type="radio"] { accent-color: #2563eb; }

/* ---------- Scrollbarer Tabellen-Container (mobile) ----------
   Horizontales Scrollen statt Überlauf; Scroll-Schatten/Fade erscheinen
   nur, wenn der Inhalt wirklich überquillt (background-attachment local/scroll). */
.table-scroll {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
  background-color: #fff;
  background-image:
    linear-gradient(90deg, #fff 30%, rgba(255, 255, 255, 0)),
    linear-gradient(90deg, rgba(255, 255, 255, 0), #fff 70%),
    radial-gradient(farthest-side at 0 50%, rgba(17, 24, 39, 0.18), rgba(17, 24, 39, 0)),
    radial-gradient(farthest-side at 100% 50%, rgba(17, 24, 39, 0.18), rgba(17, 24, 39, 0));
  background-repeat: no-repeat;
  background-size: 28px 100%, 28px 100%, 10px 100%, 10px 100%;
  background-position: left, right, left, right;
  background-attachment: local, local, scroll, scroll;
}
.dark .table-scroll {
  background-color: #1f2937;
  background-image:
    linear-gradient(90deg, #1f2937 30%, rgba(31, 41, 55, 0)),
    linear-gradient(90deg, rgba(31, 41, 55, 0), #1f2937 70%),
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0)),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.5), rgba(0, 0, 0, 0));
}
.table-scroll > table { min-width: max(100%, var(--table-min, 40rem)); }
.table-scroll > .table-base th,
.table-scroll > .table-base td { white-space: nowrap; }
.table-scroll:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
  border-radius: 8px;
}
.dark .table-scroll:focus-visible { outline-color: #60a5fa; }

/* ---------- Tabellen: ruhiger Kopf, klare Zeile ---------- */
.table-base { width: 100%; border-collapse: collapse; color: #1f2937; text-align: left; }
.dark .table-base { color: #d1d5db; }
.table-base th {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #6b7280;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #e5e7eb;
}
.dark .table-base th { color: #9ca3af; border-bottom-color: #374151; }
/* Zellfarbe erbt von .table-base, damit text-* Utilities der Zellen gewinnen. */
.table-base td {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  border-bottom: 1px solid #f3f4f6;
}
.dark .table-base td { border-bottom-color: #1f2937; }
.table-base tbody tr:hover td { background: #f9fafb; }
.dark .table-base tbody tr:hover td { background: rgba(55, 65, 81, 0.4); }
.table-base tr:last-child td { border-bottom: none; }

/* ---------- Skeleton-Laden statt Spinner-Text ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: #e5e7eb;
  border-radius: 0.5rem;
}
.dark .skeleton { background: #374151; }
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.5), transparent);
  animation: shimmer 1.4s infinite;
}
.dark .skeleton::after { background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.07), transparent); }
@media (prefers-reduced-motion: reduce) {
  .skeleton::after { animation: none; }
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ---------- Leerer Zustand: erklaert, nicht nur „nichts hier“ ---------- */
.empty-state {
  border: 1px dashed #d1d5db;
  border-radius: 0.75rem;
  padding: 2rem 1.5rem;
  text-align: center;
  color: #6b7280;
}
.dark .empty-state { border-color: #4b5563; color: #9ca3af; }

/* ---------- Status-Badges: eine Semantik, drei Töne ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 600;
  line-height: 1rem;
  padding: 0.125rem 0.5rem;
  border-radius: 9999px;
}
.badge-blue   { background: #dbeafe; color: #1e40af; }
.badge-green  { background: #d1fae5; color: #065f46; }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-red    { background: #fee2e2; color: #991b1b; }
.badge-gray   { background: #f3f4f6; color: #374151; }
.dark .badge-blue  { background: rgba(30, 64, 175, 0.45); color: #bfdbfe; }
.dark .badge-green { background: rgba(6, 95, 70, 0.5);  color: #a7f3d0; }
.dark .badge-amber { background: rgba(146, 64, 14, 0.45); color: #fde68a; }
.dark .badge-red   { background: rgba(153, 27, 27, 0.45); color: #fecaca; }
.dark .badge-gray  { background: rgba(55, 65, 81, 0.7);  color: #d1d5db; }

/* ---------- Tabs: gleicher Reiter ueberall ---------- */
.tab {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  color: #6b7280;
  transition: color 150ms ease, border-color 150ms ease;
}
.tab:hover { color: #374151; }
.dark .tab { color: #9ca3af; }
.dark .tab:hover { color: #d1d5db; }
.tab[aria-selected="true"], .tab.tab-active {
  color: #2563eb;
  border-color: #2563eb;
}
.dark .tab[aria-selected="true"], .dark .tab.tab-active {
  color: #60a5fa;
  border-color: #60a5fa;
}

/* ---------- Sidebar-Links (Nav-Aktivzustand) ---------- */
.nav-link {
  position: relative;
  padding: 0.375rem 0.625rem;
  border-radius: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #4b5563;
  transition: background-color 150ms ease, color 150ms ease;
}
.nav-link:hover { background: #f3f4f6; color: #111827; }
.dark .nav-link { color: #9ca3af; }
.dark .nav-link:hover { background: rgba(107, 114, 128, 0.18); color: #f3f4f6; }
.nav-link.nav-active { color: #2563eb; background: #eff6ff; }
.dark .nav-link.nav-active { color: #93c5fd; background: rgba(30, 58, 138, 0.35); }

/* ---------- Scrollbars (dezente Thematisierung) ---------- */
* { scrollbar-width: thin; scrollbar-color: #d1d5db transparent; }
.dark * { scrollbar-color: #4b5563 transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; background-clip: content-box; }
.dark ::-webkit-scrollbar-thumb { background: #4b5563; background-clip: content-box; }
.dark ::-webkit-scrollbar-thumb:hover { background: #6b7280; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* Rechts-/Infotexte: lesefreundliche Zeilenlaenge */
.ds-content { max-width: 72ch; }
@media (min-width: 768px) { .ds-content { margin-inline: auto; } }

/* Sprungmarke fuer Tastaturnutzer */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 60;
  background: #2563eb;
  color: #fff;
  padding: 0.5rem 1rem;
  border-radius: 0 0 0.5rem 0;
  font-size: 0.875rem;
}
.skip-link:focus { left: 0; }
