:root {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --gruen: #22c55e;
  --gruen-bg: #14532d;
  --gelb: #eab308;
  --gelb-bg: #713f12;
  --rot: #ef4444;
  --rot-bg: #7f1d1d;
}

* { box-sizing: border-box; }

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

header {
  padding: 1.25rem 1.5rem 1rem;
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

h1 {
  margin: 0 0 0.5rem;
  font-size: 1.5rem;
}

.header-row h1 {
  margin: 0;
}

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

.dashboard-logo {
  display: block;
  width: 10rem;
  max-height: 3.2rem;
  object-fit: contain;
  background: #fff;
  border-radius: 7px;
  box-shadow: 0 5px 18px rgba(0, 0, 0, 0.22);
}

.btn-logout {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
}

.btn-logout:hover {
  color: var(--text);
  border-color: var(--accent);
}

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

.filterbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.7rem;
  align-items: end;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.feld {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.feld label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.feld input {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  width: 9rem;
  font-size: 0.9rem;
}

.feld-button {
  margin-left: auto;
}

.feld-basiswert {
  position: relative;
}

.feld-basiswert details {
  position: relative;
}

.feld-basiswert summary {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
  width: 9rem;
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.feld-basiswert summary::-webkit-details-marker {
  display: none;
}

.feld-basiswert summary::after {
  content: "▾";
  float: right;
  color: var(--text-muted);
}

.feld-basiswert details[open] summary {
  border-color: var(--accent);
}

/* Wichtig: `display` NUR im offenen Zustand setzen - `<details>` blendet nicht
   geöffneten Inhalt sonst über eine UA-Regel aus (`details:not([open]) > *`), die ein
   unbedingtes `display` hier überschreiben und den nativen Auf/Zu-Mechanismus
   dadurch komplett aushebeln würde (live beobachtet: Panel blieb dann unsichtbar). */
details[open] > .basiswert-filter-panel {
  display: flex;
}

.basiswert-filter-panel {
  position: absolute;
  top: calc(100% + 0.3rem);
  left: 0;
  z-index: 20;
  width: 16rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  padding: 0.6rem;
  flex-direction: column;
  gap: 0.5rem;
}

.basiswert-filter-panel input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.4rem 0.55rem;
  font-size: 0.85rem;
  width: 100%;
}

.basiswert-filter-alle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.basiswert-filter-liste {
  display: flex;
  flex-direction: column;
  max-height: 14rem;
  overflow-y: auto;
}

.basiswert-filter-liste label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  padding: 0.25rem 0.2rem;
  border-radius: 4px;
  cursor: pointer;
}

.basiswert-filter-liste label:hover {
  background: rgba(255, 255, 255, 0.05);
}

.basiswert-filter-liste .basiswert-filter-keine-treffer {
  color: var(--text-muted);
  font-size: 0.82rem;
  padding: 0.3rem 0.2rem;
}

.feld-button button,
#btn-refresh-tracked {
  border-radius: 6px;
  padding: 0.6rem 1.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.feld-button button:disabled,
#btn-refresh-tracked:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Primär: rein clientseitige Filterung, instantan - kräftig hervorgehoben. */
#btn-suche-tabelle {
  background: var(--accent);
  color: #0b1220;
  border: none;
}

#btn-suche-tabelle:hover:not(:disabled) {
  filter: brightness(1.1);
}

/* Sekundär: löst einen echten, minutenlangen onvista-Abgleich aus - bewusst
   zurückhaltender/umrandet, damit die beiden Buttons nicht wie gleichwertige
   Alternativen wirken. */
#btn-tabelle-aktualisieren,
#btn-refresh-tracked {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}

#btn-tabelle-aktualisieren:hover:not(:disabled),
#btn-refresh-tracked:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 20% 20%, rgba(56, 189, 248, 0.18), transparent 30rem),
    radial-gradient(circle at 80% 80%, rgba(34, 197, 94, 0.12), transparent 26rem),
    var(--bg);
}

.login-shell {
  width: min(100%, 30rem);
  padding: 1.5rem;
}

.login-card {
  background: rgba(30, 41, 59, 0.92);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 2rem;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
}

.login-logo {
  display: block;
  width: min(100%, 24rem);
  margin: 0 auto 1.4rem;
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.24);
}

.login-kicker {
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  margin: 0 0 0.4rem;
  text-transform: uppercase;
}

.login-text {
  color: var(--text-muted);
  margin: 0.5rem 0 1.5rem;
}

.login-form {
  display: grid;
  gap: 0.7rem;
}

.login-form label {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.login-form input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 1rem;
  padding: 0.75rem 0.85rem;
}

.login-form input:focus {
  border-color: var(--accent);
  outline: none;
}

.login-form button {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #0b1220;
  cursor: pointer;
  font-weight: 700;
  margin-top: 0.4rem;
  padding: 0.75rem 1rem;
}

.login-form button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.login-error {
  background: var(--rot-bg);
  border: 1px solid var(--rot);
  border-radius: 8px;
  color: #fecaca;
  font-size: 0.9rem;
  margin: 1rem 0 0;
  padding: 0.75rem;
}

.fortschritt {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1.25rem;
}

.fortschritt-text {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.fortschritt-balken {
  background: var(--bg);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.fortschritt-fill {
  background: var(--accent);
  height: 100%;
  width: 0%;
  transition: width 0.3s ease;
}

.fortschritt-hinweis {
  margin: 0.5rem 0 0;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.fehler {
  background: var(--rot-bg);
  border: 1px solid var(--rot);
  color: #fecaca;
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

.ergebnis-summary {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.cache-modus {
  color: var(--accent);
  font-size: 0.75rem;
  margin: 0 0 0.35rem;
}

.ergebnis-kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.monitoring-aktionen {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}

.tracking-cell {
  text-align: center;
  width: 2.5rem;
  padding-inline: 0.35rem !important;
}

.tracking-head {
  min-width: 2.5rem;
}

.tracking-checkbox {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
  cursor: pointer;
}

.tabelle-wrapper {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.79rem;
}

thead th {
  text-align: left;
  background: var(--bg-card);
  padding: 0.48rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}

th.num, td.num {
  text-align: right;
}

th.sortierbar {
  cursor: pointer;
  user-select: none;
}

th.sortierbar:hover {
  color: var(--accent);
}

th.sortierbar .sort-pfeil {
  display: inline-block;
  width: 0.9em;
  color: var(--accent);
  font-size: 0.75em;
}

tbody td {
  padding: 0.42rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

td.leer {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

a.link-onvista {
  color: var(--accent);
  text-decoration: none;
}

a.link-onvista:hover {
  text-decoration: underline;
}

@media (max-width: 640px) {
  header {
    padding-inline: 1rem;
  }

  .header-row {
    align-items: flex-start;
  }

  .header-row h1 {
    font-size: 1.2rem;
    padding-top: 0.35rem;
  }

  .header-actions {
    flex-direction: column;
    align-items: flex-end;
    gap: 0.45rem;
  }

  .dashboard-logo {
    width: 7.5rem;
  }

  .login-card {
    padding: 1.4rem;
  }
}

.app-footer {
  padding: 1.5rem;
  text-align: center;
}

.app-footer #app-footer-copyright {
  font-size: 0.75rem;
  color: var(--text-muted);
  cursor: default;
  user-select: none;
}
