:root {
  --bg: #f5f6f8;
  --bg-elevated: #ffffff;
  --text: #1a1d23;
  --text-muted: #666e7a;
  --border: #e0e3e8;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #b00020;
  --comfort: #e2622f;
  --economy: #e0a934;
  --booking: #2563eb;
  --standby: #9aa2ad;
  --override: #8b5cf6;
  --radius: 0.5rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --bg-elevated: #1e2126;
    --text: #e8eaed;
    --text-muted: #9aa2ad;
    --border: #2c3038;
    --accent: #4d8dff;
    --accent-text: #0a0d12;
    --danger: #ff6b6b;
    --comfort: #f0794a;
    --economy: #f0bc55;
    --booking: #6ea3ff;
    --standby: #5b6270;
    --override: #a78bfa;
  }
}

* { box-sizing: border-box; }

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

.container {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1rem 1rem 3rem;
}

.container-narrow {
  max-width: 26rem;
  margin: 4rem auto;
  padding: 0 1rem;
}

h1 { font-size: 1.5rem; margin: 1rem 0; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 0.75rem; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.topbar nav a {
  color: var(--text-muted);
  text-decoration: none;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius);
  font-size: 0.95rem;
}

.topbar nav a:hover { background: var(--bg); color: var(--text); }

.topbar form.logout { margin: 0; }

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

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 1rem;
}

table { border-collapse: collapse; width: 100%; background: var(--bg-elevated); }
th, td { text-align: left; padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tr:last-child td { border-bottom: none; }

input, select, button {
  font: inherit;
  color: inherit;
}

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  padding: 0.5rem 0.6rem;
  margin-top: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
}

table input[type=number] { width: 5.5rem; }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; }

label { display: block; margin-top: 1rem; font-size: 0.95rem; }

button {
  padding: 0.5rem 1rem;
  margin-top: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  font-weight: 500;
}

button:hover { filter: brightness(1.08); }

button.btn-ghost { background: var(--bg-elevated); color: var(--text); }
button.btn-comfort { background: var(--comfort); color: #fff; }
button.btn-economy { background: var(--economy); color: #1a1d23; }
button.btn-standby { background: var(--standby); color: #fff; }

table button { margin-top: 0; }

.override-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; padding: 0.75rem; }
.override-actions form { margin: 0; }
.override-actions button { margin-top: 0; }

.error, .banner-error { color: var(--danger); }
.notice { color: var(--accent); font-weight: 500; }
.banner {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin: 1rem 0;
  font-size: 0.95rem;
}
.banner-warn { background: color-mix(in srgb, var(--comfort) 15%, var(--bg-elevated)); border: 1px solid var(--comfort); }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--border);
  color: var(--text-muted);
  vertical-align: middle;
  white-space: nowrap;
}

.badge-mode-comfort { background: var(--comfort); color: #fff; }
.badge-mode-economy { background: var(--economy); color: #1a1d23; }
.badge-mode-standby { background: var(--standby); color: #fff; }
.badge-mode-unbekannt { background: var(--border); color: var(--text-muted); }

.badge-source-automatik { background: color-mix(in srgb, var(--accent) 18%, var(--bg-elevated)); color: var(--accent); }
.badge-source-override { background: color-mix(in srgb, var(--override) 20%, var(--bg-elevated)); color: var(--override); }
.badge-source-handbetrieb { background: color-mix(in srgb, var(--danger) 18%, var(--bg-elevated)); color: var(--danger); }
.badge-source-disabled { background: var(--border); color: var(--text-muted); }
.badge-source-unknown { background: var(--border); color: var(--text-muted); }

hr { border: none; border-top: 1px solid var(--border); margin: 2rem 0; }

.legend { display: flex; flex-wrap: wrap; gap: 1rem; margin: 0.5rem 0 1.25rem; font-size: 0.9rem; color: var(--text-muted); }
.legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.swatch { width: 0.85rem; height: 0.85rem; border-radius: 0.2rem; display: inline-block; }
.swatch.comfort { background: var(--comfort); }
.swatch.economy { background: var(--economy); }
.swatch.booking { background: transparent; border: 2px solid var(--booking); }

.room-timeline { overflow-x: auto; }
.timeline-inner { min-width: 46rem; }

.timeline-ruler {
  display: grid;
  grid-template-columns: repeat(14, 1fr);
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}
.ruler-day { padding: 0.15rem 0.3rem; border-left: 1px solid var(--border); }
.ruler-day:first-child { border-left: none; }

.timeline-track {
  position: relative;
  height: 1.6rem;
  background-image: repeating-linear-gradient(
    to right, var(--border) 0, var(--border) 1px,
    transparent 1px, transparent calc(100% / 14)
  );
  border: 1px solid var(--border);
  border-radius: 0.25rem;
  margin-bottom: 0.4rem;
}

.timeline-track .bar {
  position: absolute;
  top: 3px;
  bottom: 3px;
  border-radius: 0.2rem;
  min-width: 2px;
}

.track-bookings .bar { background: transparent; border: 2px solid var(--booking); }
.bar-comfort { background: var(--comfort); }
.bar-economy { background: var(--economy); }

@media (max-width: 40rem) {
  .container { padding: 0.75rem 0.75rem 2rem; }
  .topbar { padding: 0.6rem 0.75rem; }
  th, td { padding: 0.5rem; }

  /* .responsive-table opts a specific table into a card-per-row mobile
     layout instead of the default horizontal-scroll table, so pages like
     Dashboard and Räume never need a sideways swipe to read. Each <td>
     needs a data-label attribute (the value shown via ::before) for its
     row to read as a labeled list rather than bare values. */
  .table-wrap:has(.responsive-table) { padding: 0.5rem; }
  .responsive-table thead { display: none; }
  .responsive-table, .responsive-table tbody, .responsive-table tr, .responsive-table td {
    display: block;
    width: 100%;
    white-space: normal;
  }
  .responsive-table tr {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.6rem;
  }
  .responsive-table tr:last-child { margin-bottom: 0; }
  .responsive-table td { border: none; padding: 0.35rem 0; }
  .responsive-table td[data-label] {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
  }
  .responsive-table td[data-label]::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-muted);
    flex: 0 0 auto;
  }
}
