/* ── Design Tokens ──────────────────────────────────────────────── */
:root {
  /* Typography */
  --font-system: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
                 "Segoe UI", system-ui, sans-serif;
  --font-mono:   ui-monospace, "SF Mono", Menlo, "Cascadia Code", monospace;

  /* Type scale */
  --text-xs:   11px;
  --text-sm:   13px;
  --text-base: 15px;
  --text-lg:   17px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;

  /* Spacing (8px grid) */
  --space-1:  4px;
  --space-2:  8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Border radius */
  --radius-sm:   6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-full: 9999px;

  /* Light mode colours */
  --bg-primary:     #ffffff;
  --bg-secondary:   #f5f5f7;
  --bg-tertiary:    #e8e8ed;
  --bg-quaternary:  #d1d1d6;

  /* Accent */
  --accent:          #007aff;
  --accent-hover:    #0062cc;
  --accent-light:    rgba(0, 122, 255, 0.12);

  /* Semantic */
  --success:         #34c759;
  --success-light:   rgba(52, 199, 89, 0.12);
  --warning:         #ff9f0a;
  --warning-light:   rgba(255, 159, 10, 0.12);
  --danger:          #ff3b30;
  --danger-light:    rgba(255, 59, 48, 0.12);
  --danger-hover:    #d70015;

  /* Text */
  --text-primary:   rgba(0, 0, 0, 0.85);
  --text-secondary: rgba(0, 0, 0, 0.55);
  --text-tertiary:  rgba(0, 0, 0, 0.30);
  --text-on-accent: #ffffff;

  /* Borders */
  --border:         rgba(0, 0, 0, 0.10);
  --border-strong:  rgba(0, 0, 0, 0.20);

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(0,0,0,.04);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 6px rgba(0,0,0,.04), 0 10px 15px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 25px rgba(0,0,0,.06), 0 20px 40px rgba(0,0,0,.08);

  /* Animation */
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:    cubic-bezier(0.16, 1, 0.3, 1);
  --duration-fast: 120ms;
  --duration-base: 200ms;
}

/* ── Dark Mode ───────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary:     #1c1c1e;
    --bg-secondary:   #2c2c2e;
    --bg-tertiary:    #3a3a3c;
    --bg-quaternary:  #48484a;

    --accent:         #0a84ff;
    --accent-hover:   #409cff;

    --text-primary:   rgba(255, 255, 255, 0.88);
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-tertiary:  rgba(255, 255, 255, 0.25);

    --border:         rgba(255, 255, 255, 0.10);
    --border-strong:  rgba(255, 255, 255, 0.20);

    --shadow-sm: 0 1px 3px rgba(0,0,0,.25), 0 1px 2px rgba(0,0,0,.30);
    --shadow-md: 0 4px 6px rgba(0,0,0,.20), 0 10px 15px rgba(0,0,0,.30);
  }
}

/* ── Reset ───────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  font-family: var(--font-system);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--bg-secondary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code, pre {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

/* ── App Shell ───────────────────────────────────────────────────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.main-content {
  flex: 1;
  overflow-y: auto;
  /* 64px Topbar-Höhe + 32px Luft = 96px oben. Page-Header + Action-Tabs
     beginnen damit klar abgesetzt von der Topbar. */
  padding: 96px var(--space-8) var(--space-8);
  background: var(--bg-secondary);
}

/* Wenn ein Topbar-Logo (fixed oben rechts, max 180×48 px) konfiguriert
   ist, müssen alle rechtsseitigen Action-Bereiche im Page-Header Platz
   für das Logo machen — sonst verschwinden Buttons wie „+ Neue X",
   „CSV Import" etc. unter dem Logo. 216px = 180 Logo-Breite + 16 rechte
   Marge + 20 Sicherheits-Padding. Mehrere Selektoren + !important weil
   viele Templates inline-styles benutzen. */
.main-content.has-topbar-logo .page-header,
.main-content.has-topbar-logo .action-bar,
.main-content.has-topbar-logo > .nav-tabs:first-of-type + .page-header,
.main-content.has-topbar-logo > .order-tabs:first-of-type + .page-header,
.main-content.has-topbar-logo > div:first-of-type[style*="display:flex"],
.main-content.has-topbar-logo > div:first-of-type[style*="display: flex"] {
  padding-right: 216px !important;
}

/* ── App-Topbar (fix oben, rechts neben der Sidebar) ─────────────────
   Solider grauer Hintergrund passend zum main-content (var(--bg-secondary)
   = #f5f5f7). Keine Transparenz, kein backdrop-filter — User-Wunsch:
   die Leiste soll überall solid grau sein wie der Hauptframe und das
   Logo (z-index 240) nicht durch ein semi-transparentes Layer
   abgedunkelt werden.
   3-Spalten-Grid: links = Online-Widget (admin-only), Mitte = App-Hook
   (PMS füllt den Hotel-Switcher via partials/top_banner.html), rechts
   = leer (App-Logo lebt fix darüber).
   z-index 220 > Sidebar (100), < Modals (1000), < fixed-Logo (240). */
.app-topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: 64px;
  z-index: 220;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
}
.topbar-left   { justify-self: start;  display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-center { justify-self: center; display: flex; align-items: center; min-width: 0; }
.topbar-right  { justify-self: end;    display: flex; align-items: center; gap: 12px; min-width: 0; }

/* Switcher-Pille (PMS Phase 43.7). Tint kommt aus --hotel-primary, die
   in base.html aus Property.primary_color injected wird. Fallback:
   Theme-Accent (default Blau, Romantik Bronze). color-mix erlaubt
   subtilen Tint ohne preprocessing. */
.topbar-hotel-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  /* Hintergrund erkennbar grau — bg-tertiary statt bg-secondary, weil
     bg-secondary (#f5f5f7) auf dem 78%-weißen Topbar-Glass-Blur fast
     unsichtbar ist. bg-tertiary (#e8e8ed) ist visuell klar grau ohne
     zu dunkel zu werden. Border + Text tragen weiterhin --hotel-primary. */
  color: var(--hotel-primary, var(--accent));
  background: var(--bg-tertiary);
  border: 1px solid color-mix(in srgb, var(--hotel-primary, var(--accent)) 45%, transparent);
  /* Kompakt: ~32 Zeichen-Breite, danach Ellipsis. Synchron mit dem
     Inline-Style-Fallback in PMS top_banner.html. */
  max-width: 32ch;
  width: fit-content;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-hotel-pill select {
  background: transparent;
  border: 0;
  color: inherit;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  padding: 0 20px 0 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 2px center;
  background-size: 12px 12px;
}
.topbar-hotel-pill select option {
  /* Reset, weil OS-Dropdowns die Pill-Tint nicht erben */
  color: var(--text-primary);
  background: var(--bg-primary);
}

@media (prefers-color-scheme: dark) {
  .app-topbar {
    background: var(--bg-secondary);  /* #2c2c2e im Dark-Mode */
  }
}

/* ── Page Header ─────────────────────────────────────────────────── */
.page-header {
  margin-bottom: var(--space-6);
}

.page-header h1 {
  font-size: var(--text-2xl);
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.page-header p {
  margin-top: var(--space-1);
  font-size: var(--text-base);
  color: var(--text-secondary);
}

/* ── Card ────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.card + .card {
  margin-top: var(--space-4);
}

.card-title {
  font-size: var(--text-lg);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  font-family: var(--font-system);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition:
    background var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    opacity var(--duration-fast) var(--ease-out);
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary {
  background: var(--accent);
  color: var(--text-on-accent);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover {
  background: var(--bg-quaternary);
}

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

.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
  border-radius: var(--radius-sm);
}

/* ── Badge ───────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 500;
}
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger  { background: var(--danger-light);  color: var(--danger);  }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-default { background: var(--bg-tertiary);   color: var(--text-secondary); }

/* ── Table ───────────────────────────────────────────────────────── */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  background: var(--bg-primary);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

thead {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }

/* ── Utilities ───────────────────────────────────────────────────── */
.text-secondary { color: var(--text-secondary); }
.text-tertiary  { color: var(--text-tertiary); }
.text-sm        { font-size: var(--text-sm); }
.text-xs        { font-size: var(--text-xs); }
.font-mono      { font-family: var(--font-mono); }

.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-2          { gap: var(--space-2); }
.gap-4          { gap: var(--space-4); }
.mt-4           { margin-top: var(--space-4); }
.mt-6           { margin-top: var(--space-6); }

/* ── Alert / Flash ───────────────────────────────────────────────── */
.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.alert-success { background: var(--success-light); color: var(--success); border: 1px solid rgba(52,199,89,.25); }
.alert-error   { background: var(--danger-light);  color: var(--danger);  border: 1px solid rgba(255,59,48,.25); }
.alert-warning { background: var(--warning-light); color: var(--warning); border: 1px solid rgba(255,159,10,.25);}
