/* ---------- Design-Tokens ---------- */
:root {
  --color-bg: #f6efe1;
  --color-bg-alt: #efe4cd;
  --color-surface: #fffbf3;
  --color-text: #362a1e;
  --color-text-muted: #6d5c48;
  --color-border: #ddc9a3;
  --color-border-strong: #c2a877;

  --color-gold: #b3872f;
  --color-gold-dark: #8a6423;
  --color-gold-bg: #f1e0b8;

  --color-wine: #7c2e3b;
  --color-wine-dark: #5c2029;
  --color-wine-bg: #f0dadd;

  --color-blue: #2c4a63;
  --color-blue-dark: #1d3547;
  --color-blue-bg: #d9e2e8;

  --color-success: #3f6b3f;
  --color-success-bg: #e2ecdd;
  --color-danger: #a33d3d;
  --color-danger-bg: #f5dfdc;

  --font-heading: Georgia, 'Iowan Old Style', 'Palatino Linotype', Palatino, 'Times New Roman', serif;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-soft: 0 2px 10px rgba(54, 42, 30, 0.14);
  --shadow-lift: 0 6px 20px rgba(54, 42, 30, 0.22);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  line-height: 1.5;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1, h2, h3 { font-family: var(--font-heading); font-weight: 600; margin: 0 0 0.5em; color: var(--color-text); }
h1 { font-size: 1.6rem; letter-spacing: 0.02em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 0.75em; }
a { color: var(--color-blue-dark); }
button, input, select { font-family: inherit; font-size: inherit; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}

/* ---------- Klaviatur-Trennlinie ---------- */
.piano-strip {
  display: block;
  width: 100%;
  height: 34px;
}
.piano-strip .key-white { fill: var(--color-surface); }
.piano-strip .key-line { stroke: var(--color-border-strong); stroke-width: 1; }
.piano-strip .key-black { fill: var(--color-text); }
header .piano-strip { height: 40px; }

/* ---------- Header / Footer ---------- */
.site-header {
  background: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-border);
}
.site-header__bar {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.1rem 1.25rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.site-header__title {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.site-header__title h1 { margin: 0; }
.site-header__title span {
  font-size: 0.82rem;
  color: var(--color-text-muted);
}
.site-header__user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.92rem;
}
.site-header__user .badge-master {
  background: var(--color-gold);
  color: #fff;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.site-footer {
  margin-top: auto;
  background: var(--color-bg-alt);
  border-top: 1px solid var(--color-border);
}
.site-footer__text {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.75rem 1.25rem 1.25rem;
  color: var(--color-text-muted);
  font-size: 0.82rem;
  text-align: center;
}

main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.hidden { display: none !important; }

/* ---------- Buttons & Formulare ---------- */
button {
  cursor: pointer;
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.9rem;
  transition: background 0.15s ease, transform 0.05s ease;
}
button:hover { background: var(--color-bg-alt); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--color-gold);
  border-color: var(--color-gold-dark);
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover { background: var(--color-gold-dark); }

.btn-danger {
  background: var(--color-danger-bg);
  border-color: var(--color-danger);
  color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger); color: #fff; }

.btn-link {
  border: none;
  background: none;
  text-decoration: underline;
  padding: 0.2rem 0.3rem;
  color: var(--color-blue-dark);
}
.btn-link:hover { background: none; color: var(--color-wine-dark); }

.btn-small { padding: 0.3rem 0.6rem; font-size: 0.82rem; }

label {
  display: block;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}
input[type="text"], input[type="password"], input[type="date"], input[type="time"], input[type="number"], select {
  width: 100%;
  min-width: 0;
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  color: var(--color-text);
}
input:focus, select:focus, button:focus {
  outline: 2px solid var(--color-blue);
  outline-offset: 1px;
}
.field { margin-bottom: 0.9rem; min-width: 0; }
.field-row { display: flex; gap: 0.75rem; min-width: 0; }
.field-row .field { flex: 1; min-width: 0; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.9rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; color: var(--color-text); }

/* ---------- Karten / Panels ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 1.1rem 1.25rem;
  margin-bottom: 1.5rem;
}

/* ---------- Login ---------- */
.login-wrap {
  max-width: 420px;
  margin: 2rem auto;
  position: relative;
}
.login-organ {
  position: absolute;
  top: -3.2rem;
  left: 50%;
  transform: translateX(-50%);
  width: 220px;
  height: 70px;
  opacity: 0.55;
}
.login-tabs {
  display: flex;
  gap: 0.4rem;
  margin-bottom: 1rem;
}
.login-tabs button {
  flex: 1;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  border-bottom: none;
  background: var(--color-bg-alt);
}
.login-tabs button.active {
  background: var(--color-surface);
  font-weight: 600;
  border-bottom: 2px solid var(--color-surface);
  margin-bottom: -1px;
}
.login-panel { display: none; }
.login-panel.active { display: block; }
.form-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
  margin-bottom: 0.8rem;
}
.form-success {
  background: var(--color-success-bg);
  color: var(--color-success);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.7rem;
  font-size: 0.88rem;
  margin-bottom: 0.8rem;
}
.hint { font-size: 0.8rem; color: var(--color-text-muted); margin-top: 0.4rem; }

/* ---------- Dashboard ---------- */
.notification-card {
  border-left: 4px solid var(--color-gold);
  background: var(--color-gold-bg);
}
.notification-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.5rem 0;
  border-bottom: 1px dashed var(--color-border-strong);
}
.notification-item:last-child { border-bottom: none; }
.notification-item p { margin: 0; font-size: 0.92rem; }

.upcoming-list { list-style: none; margin: 0; padding: 0; }
.upcoming-list li {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 0.92rem;
}
.upcoming-list li:last-child { border-bottom: none; }
.instrument-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.upcoming-list .when { color: var(--color-text-muted); font-size: 0.85rem; }
.empty-state { color: var(--color-text-muted); font-style: italic; font-size: 0.92rem; }

.credential-setup summary { cursor: pointer; font-weight: 600; color: var(--color-blue-dark); }

/* ---------- Instrument-Tabs & Kalender-Steuerung ---------- */
.instrument-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.instrument-tab {
  border-radius: 999px;
  padding: 0.45rem 1.1rem;
  font-weight: 600;
  border: 2px solid var(--color-border-strong);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.instrument-tab[data-active="true"][data-instrument="orgel"] { background: var(--color-gold); border-color: var(--color-gold-dark); color: #fff; }
.instrument-tab[data-active="true"][data-instrument="cembalo"] { background: var(--color-wine); border-color: var(--color-wine-dark); color: #fff; }
.instrument-tab[data-active="true"][data-instrument="fluegel"] { background: var(--color-blue); border-color: var(--color-blue-dark); color: #fff; }

.week-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
  flex-wrap: wrap;
}
.week-nav__range { font-weight: 600; font-family: var(--font-heading); font-size: 1.05rem; }
.week-nav__buttons { display: flex; gap: 0.4rem; }

/* ---------- Kalender-Raster ---------- */
.calendar-scroll { overflow-x: auto; border-radius: var(--radius); }
.calendar-grid {
  display: grid;
  grid-template-columns: 54px repeat(7, minmax(96px, 1fr));
  grid-template-rows: auto;
  grid-auto-rows: 20px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  min-width: 760px;
  position: relative;
}
.cal-head {
  grid-row: 1;
  position: sticky;
  top: 0;
  background: var(--color-bg-alt);
  border-bottom: 1px solid var(--color-border-strong);
  padding: 0.5rem 0.3rem;
  text-align: center;
  font-size: 0.82rem;
  z-index: 3;
}
.cal-head.is-today { background: var(--color-gold-bg); }
.cal-head strong { display: block; font-family: var(--font-heading); font-size: 0.95rem; }
.cal-time-col {
  grid-column: 1;
  border-right: 1px solid var(--color-border);
  font-size: 0.72rem;
  color: var(--color-text-muted);
  text-align: right;
  padding-right: 0.35rem;
  position: relative;
  top: -0.5em;
}
.cal-time-corner { grid-row: 1; grid-column: 1; background: var(--color-bg-alt); border-bottom: 1px solid var(--color-border-strong); z-index: 3; }

.cal-slot {
  border-top: 1px solid var(--color-border-strong);
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
}
.cal-slot.is-today-col { background: #fffdf6; }
.cal-slot:hover { background: var(--color-gold-bg); cursor: pointer; }
.cal-slot.is-past { background: repeating-linear-gradient(135deg, var(--color-bg-alt), var(--color-bg-alt) 6px, var(--color-bg) 6px, var(--color-bg) 12px); cursor: not-allowed; }
.cal-slot.is-past:hover { background: repeating-linear-gradient(135deg, var(--color-bg-alt), var(--color-bg-alt) 6px, var(--color-bg) 6px, var(--color-bg) 12px); }

.cal-block {
  margin: 1px 3px;
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.4rem;
  font-size: 0.76rem;
  line-height: 1.25;
  color: #fff;
  overflow: hidden;
  min-width: 0;
  white-space: nowrap;
  text-overflow: ellipsis;
  box-shadow: var(--shadow-soft);
  z-index: 2;
  border: 1px solid rgba(0,0,0,0.12);
  text-align: left;
}
.cal-block:hover { filter: brightness(1.08); }
.cal-block strong { display: block; font-size: 0.8rem; }
.cal-block[data-instrument="orgel"] { background: var(--color-gold); }
.cal-block[data-instrument="cembalo"] { background: var(--color-wine); }
.cal-block[data-instrument="fluegel"] { background: var(--color-blue); }
.cal-block.is-own { outline: 2px solid var(--color-text); outline-offset: -2px; }
.cal-block.is-override::after { content: "♛"; float: right; opacity: 0.85; }

.upcoming-list li.upcoming-clickable { cursor: pointer; border-radius: var(--radius-sm); }
.upcoming-list li.upcoming-clickable:hover { background: var(--color-bg-alt); }

@keyframes pop-highlight {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(179, 135, 47, 0); }
  30% { transform: scale(1.08); box-shadow: 0 0 0 10px rgba(179, 135, 47, 0.3); }
  60% { transform: scale(1); box-shadow: 0 0 0 0 rgba(179, 135, 47, 0); }
}
.cal-block.pop-highlight {
  animation: pop-highlight 0.6s ease-out 2;
  z-index: 5;
}

.legend { display: flex; gap: 1.25rem; flex-wrap: wrap; margin-top: 0.8rem; font-size: 0.8rem; color: var(--color-text-muted); }
.legend span { display: inline-flex; align-items: center; gap: 0.35rem; }
.legend .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.legend .swatch.own { outline: 2px solid var(--color-text); outline-offset: -2px; background: var(--color-border-strong); }

/* ---------- Modal (dialog) ---------- */
dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(480px, 92vw);
  box-shadow: var(--shadow-lift);
  background: var(--color-surface);
}
dialog::backdrop { background: rgba(54, 42, 30, 0.45); }
.dialog-inner { padding: 1.4rem 1.5rem; }
.dialog-inner h2 { margin-bottom: 0.9rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.2rem; flex-wrap: wrap; }
.dialog-actions .spacer { flex: 1; }
.result-list { list-style: none; margin: 0.6rem 0 0; padding: 0; font-size: 0.88rem; }
.result-list li { padding: 0.3rem 0.4rem; border-radius: var(--radius-sm); margin-bottom: 0.3rem; }
.result-list li.ok { background: var(--color-success-bg); color: var(--color-success); }
.result-list li.fail { background: var(--color-danger-bg); color: var(--color-danger); }

/* ---------- Master-Panel ---------- */
.table-scroll { overflow-x: auto; }
.master-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.master-table th, .master-table td { text-align: left; padding: 0.45rem 0.5rem; border-bottom: 1px solid var(--color-border); }
.master-table th { color: var(--color-text-muted); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }
.token-cell { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

.new-user-details { margin-top: 1.2rem; padding-top: 0.9rem; border-top: 1px dashed var(--color-border-strong); }
.new-user-details summary { cursor: pointer; font-size: 0.8rem; color: var(--color-text-muted); }
.new-user-details summary:hover { color: var(--color-blue-dark); }
.new-user-form { display: flex; gap: 0.6rem; align-items: flex-end; flex-wrap: wrap; margin-top: 0.8rem; }
.new-user-form .field { flex: 1; min-width: 200px; margin-bottom: 0; }
.new-token-callout {
  background: var(--color-success-bg);
  border: 1px solid var(--color-success);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.9rem;
  margin-top: 0.8rem;
  font-size: 0.9rem;
}
.new-token-callout .token-cell { font-size: 1rem; font-weight: 600; }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-text);
  color: #fff;
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lift);
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }

@media (max-width: 640px) {
  .site-header__bar { padding: 0.9rem 1rem 0.7rem; }
  main { padding: 1.1rem 0.75rem 2.5rem; }
  h1 { font-size: 1.3rem; }
  .card { padding: 0.9rem 0.85rem; }

  /* Ganze Woche ohne horizontales Wischen sichtbar - Spalten schrumpfen auf Bildschirmbreite,
     statt eine Mindestbreite zu erzwingen (die war der Grund fuers Wischen-Muessen). */
  .calendar-scroll { overflow-x: visible; }
  .calendar-grid {
    min-width: 0;
    grid-template-columns: 26px repeat(7, minmax(0, 1fr));
  }
  .cal-head { padding: 0.3rem 0.05rem; font-size: 0.64rem; }
  .cal-head strong { font-size: 0.7rem; }
  .cal-time-col { font-size: 0.56rem; padding-right: 0.15rem; }
  .cal-block { padding: 0.15rem 0.25rem; font-size: 0.58rem; }
  .cal-block strong { font-size: 0.6rem; }
  .legend { font-size: 0.72rem; gap: 0.5rem 0.9rem; }

  /* Formularfelder (Reservierungs-Dialog, Zugangsdaten) untereinander statt nebeneinander -
     dadurch muss nichts mehr schrumpfen/ueberlaufen und der Dialog passt immer auf den Bildschirm. */
  .field-row { flex-direction: column; gap: 0; }
  .field-row .field { margin-bottom: 0.9rem; }
}
