:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1a1d23;
  --muted: #6b7280;
  --border: #e3e5e9;
  --primary: #3b5bfd;
  --primary-text: #ffffff;
  --danger: #d64545;
  --success: #1c8a4b;
  --success-bg: #e8f7ee;
  --error-bg: #fdecec;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(20, 20, 30, 0.06), 0 8px 24px rgba(20, 20, 30, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --text: #eceef1;
    --muted: #9aa0ab;
    --border: #2c3037;
    --primary: #5b7bff;
    --primary-text: #ffffff;
    --danger: #f0716a;
    --success: #4fd489;
    --success-bg: #123322;
    --error-bg: #3a1c1c;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }

a { color: var(--primary); }

.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

/* --- Zentrierte Seiten (Login etc.) --- */
.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-narrow {
  width: 100%;
  max-width: 380px;
}

/* --- Formulare --- */
.stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 12px;
}

label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 10px;
}
.stack label:first-child { margin-top: 0; }

input[type="text"],
input[type="password"],
input[type="number"],
select {
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 100%;
  min-height: 44px;
}
input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  min-height: 44px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  margin-top: 14px;
}
.btn:hover { border-color: var(--primary); }
.btn-primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
.btn-ghost { background: transparent; margin-top: 0; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-small { min-height: 36px; padding: 6px 12px; font-size: 0.85rem; margin-top: 0; }

.error {
  background: var(--error-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}
.success {
  background: var(--success-bg);
  color: var(--success);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.9rem;
}

/* --- Topbar --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.admin-page, .table-page {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px 16px 60px;
}

/* --- Tabelle --- */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}

.t-row {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.t-row:last-child { border-bottom: none; }

.t-head {
  background: var(--bg);
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  position: sticky;
  top: 0;
}

.t-cell {
  flex: 0 0 var(--w, 160px);
  width: var(--w, 160px);
  padding: 0;
  display: flex;
  align-items: center;
  border-right: 1px solid var(--border);
}
.t-head .t-cell { padding: 12px; }
.t-cell:last-child { border-right: none; }

.cell-input {
  border: none;
  background: transparent;
  width: 100%;
  height: 100%;
  padding: 12px;
  min-height: 46px;
  border-radius: 0;
}
.cell-input:focus {
  outline: none;
  box-shadow: inset 0 0 0 2px var(--primary);
  background: var(--surface);
}
.cell-input.saved { background: var(--success-bg); transition: background 0.6s ease; }

.row-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.t-select-cell {
  flex: 0 0 44px;
  width: 44px;
  justify-content: center;
}
.t-select-cell input[type="checkbox"] {
  width: 18px;
  height: 18px;
}
.t-row.row-selected { background: color-mix(in srgb, var(--primary) 8%, transparent); }

@media (max-width: 640px) {
  .t-select-cell {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 12px;
  }
  .t-select-cell::before { content: 'Auswahl'; }
}

.save-indicator {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
}
.save-indicator.show { opacity: 1; }

/* Mobil: Tabelle wird zu einer Liste von Karten */
@media (max-width: 640px) {
  .table-wrap { border: none; background: transparent; overflow: visible; }
  .t-head { display: none; }
  .t-row {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 12px;
  }
  .t-cell {
    width: 100%;
    flex: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 4px 12px;
  }
  .t-cell:last-child { border-bottom: none; }
  .t-cell::before {
    content: attr(data-label);
    flex: 0 0 40%;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
  }
  .cell-input { padding: 12px 0; }
}

/* --- Admin: Spaltenliste --- */
.columns-list { display: flex; flex-direction: column; gap: 8px; }
.column-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.column-row input[type="text"] { flex: 1 1 auto; }

/* --- Listen (Tabellenuebersicht) --- */
.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  box-shadow: var(--shadow);
}
.list-item .chevron { color: var(--muted); }

.link-row { margin-bottom: 12px; }
.link-row input { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; }

/* --- Startseite --- */
.landing { width: 100%; max-width: 720px; }
.landing-title { text-align: center; font-size: 1.8rem; margin-bottom: 6px; }
.landing-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}
.landing-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 18px;
  text-decoration: none;
  color: var(--text);
  min-height: 96px;
  justify-content: center;
  text-align: center;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.landing-card:hover { border-color: var(--primary); transform: translateY(-2px); }
.landing-card strong { font-size: 1.05rem; }
