@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,300&display=swap');

/* ============================================================
   Dashboard CSS — Kova dark design system
   ============================================================ */

:root {
  --bg:           oklch(11% 0.022 280);
  --bg-1:         oklch(14.5% 0.028 280);
  --bg-2:         oklch(19% 0.034 278);
  --bg-sidebar:   oklch(9%  0.018 282);
  --bdr:          oklch(27% 0.042 278);
  --bdr-hi:       oklch(36% 0.055 278);
  --tx:           oklch(96% 0.008 282);
  --tx2:          oklch(65% 0.058 278);
  --tx3:          oklch(44% 0.055 278);
  /* Accent is the one tenant-themed token: applyTenantBrand() overwrites --acc
     with the tenant's primary_color at boot, and every shade below is mixed
     from it. Before this, the dashboard was hard-coded indigo for everybody —
     a cookery school signed in to what was visibly somebody else's product.
     Kept as a default so the page is never unstyled while /api/tenant is in
     flight, or if it fails. */
  --acc:          oklch(67% 0.22 288);
  --acc-lo:       color-mix(in oklab, var(--acc) 72%, white);
  --acc-hi:       color-mix(in oklab, var(--acc) 80%, black);
  --acc-tint:     color-mix(in oklab, var(--acc) 22%, var(--bg));
  --amber:        oklch(80% 0.17 65);
  --amber-tint:   oklch(19% 0.06 65);
  --green:        oklch(70% 0.17 150);
  --green-tint:   oklch(18% 0.07 150);
  --red:          oklch(63% 0.20 22);
  --red-tint:     oklch(18% 0.07 22);
  --f-d:          'Space Grotesk', system-ui, sans-serif;
  --f-b:          'DM Sans', system-ui, sans-serif;
  --radius:       0.5rem;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
  font-family: var(--f-b);
  background: var(--bg);
  color: var(--tx);
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bdr-hi); border-radius: 3px; }

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

.sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  color: var(--tx);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 100;
  border-right: 1px solid var(--bdr);
}

.sidebar__logo {
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid var(--bdr);
  font-family: var(--f-d);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--tx);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .55rem;
}

.sidebar__logo span { color: var(--acc); }

.sidebar__nav { flex: 1; padding: .75rem 0; overflow-y: auto; }

.sidebar__link {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: .55rem 1.4rem;
  color: var(--tx3);
  text-decoration: none;
  font-size: .85rem;
  transition: color .12s, background .12s;
  border-left: 2px solid transparent;
}

.sidebar__link:hover { color: var(--tx2); background: oklch(100% 0 0 / 0.03); }
.sidebar__link.active { color: var(--tx); background: var(--acc-tint); border-left-color: var(--acc); }
.sidebar__link-icon { font-size: 1rem; width: 1.1rem; text-align: center; flex-shrink: 0; }
.sidebar__footer { padding: .875rem 1.4rem; border-top: 1px solid var(--bdr); }
.sidebar__user { font-size: .76rem; color: var(--tx3); margin-bottom: .4rem; }
.sidebar__logout { color: var(--tx3); font-size: .78rem; cursor: pointer; background: none; border: none; padding: 0; text-decoration: underline; font-family: var(--f-b); }
.sidebar__logout:hover { color: var(--tx2); }

.main {
  margin-left: 240px;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: var(--bg);
}

.topbar {
  background: oklch(11% 0.022 280 / 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--bdr);
  padding: 0 2rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar__title {
  font-family: var(--f-d);
  font-size: .95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.topbar__actions { display: flex; gap: .75rem; }

.content { padding: 2rem; flex: 1; }

/* ── Cards ── */
.dc {
  background: var(--bg-1);
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
}

.dc__header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--bdr);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.dc__title {
  font-family: var(--f-d);
  font-size: .88rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.dc__body { padding: 1.5rem; }

/* ── Stat Cards ── */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--bg-1);
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.stat__label {
  font-family: var(--f-d);
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--tx3);
  margin-bottom: .4rem;
}

.stat__value {
  font-family: var(--f-d);
  font-size: 1.9rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--tx);
}

/* ── Table ── */
.dt { width: 100%; border-collapse: collapse; font-size: .85rem; }

.dt thead th {
  padding: .55rem 1rem;
  text-align: left;
  font-family: var(--f-d);
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--tx3);
  border-bottom: 1px solid var(--bdr);
  background: var(--bg-2);
}

thead th:first-child { border-radius: 6px 0 0 6px; }
thead th:last-child  { border-radius: 0 6px 6px 0; }

.dt tbody td {
  padding: .825rem 1rem;
  border-bottom: 1px solid oklch(27% 0.042 278 / 0.5);
  vertical-align: middle;
}

.dt tbody tr:last-child td { border-bottom: none; }
.dt tbody tr:hover td { background: oklch(100% 0 0 / 0.025); }
.dt-link { color: var(--acc-lo); text-decoration: none; font-weight: 600; }
.dt-link:hover { text-decoration: underline; color: var(--acc); }

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: .18rem .6rem;
  border-radius: 99px;
  font-family: var(--f-d);
  font-size: .7rem;
  font-weight: 600;
  letter-spacing: .04em;
  white-space: nowrap;
}

.badge--published { background: var(--green-tint); color: var(--green); }
.badge--draft     { background: var(--bg-2); color: var(--tx3); border: 1px solid var(--bdr); }
.badge--paid      { background: var(--green-tint); color: var(--green); }
.badge--pending   { background: var(--amber-tint); color: var(--amber); }
.badge--refunded  { background: var(--red-tint); color: var(--red); }
.badge--expired   { background: var(--bg-2); color: var(--tx3); border: 1px solid var(--bdr); }
.badge--active    { background: var(--green-tint); color: var(--green); }
.badge--inactive  { background: var(--bg-2); color: var(--tx3); border: 1px solid var(--bdr); }
.badge--failed    { background: var(--red-tint); color: var(--red); }
.badge--cancelled { background: var(--red-tint); color: var(--red); }
.badge--free      { background: var(--acc-tint); color: var(--acc); }

/* ── Forms ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-group { margin-bottom: 1.25rem; }

.form-label {
  display: block;
  font-family: var(--f-d);
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--tx3);
  margin-bottom: .4rem;
}

.form-label span { font-weight: 400; color: var(--tx3); font-size: .76rem; text-transform: none; letter-spacing: 0; }

.form-input, .form-select, .form-textarea, .form-color {
  width: 100%;
  padding: .55rem .875rem;
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  font-family: var(--f-b);
  font-size: .875rem;
  background: var(--bg);
  color: var(--tx);
  transition: border-color .12s, box-shadow .12s;
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--tx3); }

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--acc);
  box-shadow: 0 0 0 3px oklch(67% 0.22 288 / 0.18);
}

.form-textarea { resize: vertical; min-height: 100px; }
.form-color { padding: .3rem; height: 42px; cursor: pointer; background: var(--bg-1); }
.form-hint { font-size: .78rem; color: var(--tx3); margin-top: .3rem; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-family: var(--f-d);
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .12s, color .12s, opacity .12s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn--primary { background: var(--acc); color: var(--bg); border-color: var(--acc); }
.btn--primary:hover:not(:disabled) { background: var(--acc-hi); color: #fff; }

.btn--secondary { background: var(--bg-2); color: var(--tx2); border-color: var(--bdr); }
.btn--secondary:hover:not(:disabled) { background: var(--bg-1); border-color: var(--bdr-hi); color: var(--tx); }

.btn--danger { background: var(--red-tint); color: var(--red); border-color: oklch(30% 0.10 22 / 0.5); }
.btn--danger:hover:not(:disabled) { background: oklch(22% 0.08 22 / 0.6); }

.btn--sm { padding: .32rem .65rem; font-size: .76rem; }
.btn--full { width: 100%; }

/* ── Alerts ── */
.alert { padding: .7rem 1rem; border-radius: var(--radius); font-size: .85rem; margin-bottom: 1rem; }
.alert--success { background: var(--green-tint); color: var(--green); border: 1px solid oklch(30% 0.10 150 / 0.5); }
.alert--error   { background: var(--red-tint);   color: var(--red);   border: 1px solid oklch(30% 0.10 22 / 0.5); }
.alert--info    { background: var(--acc-tint);   color: var(--acc-lo); border: 1px solid oklch(30% 0.12 288 / 0.5); }

/* ── Ticket type row ── */
.tt-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: .75rem;
  align-items: center;
  padding: .75rem;
  background: var(--bg-2);
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  margin-bottom: .5rem;
}

/* ── Colour swatch preview ── */
.colour-row { display: flex; align-items: center; gap: .75rem; }
.colour-preview { width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--bdr); flex-shrink: 0; }

/* ── Preset cards (theme preset grid) ── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: .75rem;
}

.preset-card {
  display: flex;
  flex-direction: column;
  gap: .45rem;
  align-items: flex-start;
  text-align: left;
  padding: .85rem;
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  background: var(--bg-1);
  cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}

.preset-card:hover {
  border-color: var(--bdr-hi);
  transform: translateY(-1px);
}

.preset-card.active {
  border-color: var(--acc);
  box-shadow: 0 0 0 3px oklch(67% 0.22 288 / 0.18);
}

.preset-card__swatches { display: inline-flex; gap: .3rem; }

.preset-card__swatches i {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid oklch(0% 0 0 / 0.2);
}

.preset-card__name { font-family: var(--f-d); font-size: .85rem; font-weight: 600; }
.preset-card__meta { font-size: .76rem; color: var(--tx3); }

/* ── Live preview (iframe) ── */
.live-preview {
  margin-top: .5rem;
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  background: var(--bg-1);
  padding: .8rem;
}

.live-preview__toolbar {
  display: flex;
  gap: .5rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: .7rem;
}

.live-preview__stage {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-2);
  height: 620px;
}

.live-preview__frame { width: 100%; height: 100%; border: 0; }

.live-preview[data-device="tablet"] .live-preview__stage { max-width: 820px; }
.live-preview[data-device="mobile"] .live-preview__stage { max-width: 420px; height: 720px; }

/* ── Theme mini-preview (simulates customer-facing UI) ── */
.theme-preview {
  --tp-primary: #22362b;
  --tp-accent:  #b3905d;
  --tp-text:    #1f1a17;
  --tp-bg:      #fcf7ef;
  --tp-font:    'DM Sans', system-ui, sans-serif;
  margin-top: .5rem;
  border: 1px solid var(--bdr);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--tp-bg);
  box-shadow: 0 10px 26px oklch(0% 0 0 / 0.3);
  font-family: var(--tp-font);
  color: var(--tp-text);
}

.theme-preview__header {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .9rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,.1);
  background: rgba(255,255,255,.8);
  backdrop-filter: blur(8px);
}

.theme-preview__logo {
  width: 18px; height: 18px;
  border-radius: 999px;
  background: var(--tp-primary);
}

.theme-preview__title {
  font-size: .82rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: #64748b;
}

.theme-preview__chip {
  margin-left: auto;
  font-size: .75rem;
  font-weight: 700;
  border-radius: 999px;
  padding: .2rem .6rem;
  background: color-mix(in srgb, var(--tp-accent) 20%, #fff);
}

.theme-preview__hero {
  padding: 1rem;
  background: linear-gradient(135deg, color-mix(in srgb, var(--tp-primary) 20%, #fff) 0%, color-mix(in srgb, var(--tp-accent) 22%, #fff) 100%);
}

.theme-preview__eyebrow {
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .12em;
  font-weight: 700;
  opacity: .75;
}

.theme-preview__heading {
  margin-top: .3rem;
  font-size: 1rem;
  font-weight: 700;
}

.theme-preview__subtitle {
  margin-top: .4rem;
  font-size: .82rem;
  line-height: 1.5;
  opacity: .78;
}

.theme-preview__cta {
  margin-top: .8rem;
  padding: .55rem .9rem;
  border: 0;
  border-radius: 999px;
  background: var(--tp-primary);
  color: #fff;
  font: inherit;
  font-size: .82rem;
  font-weight: 700;
}

.theme-preview__toolbar {
  display: flex;
  gap: .45rem;
  align-items: center;
  flex-wrap: wrap;
  padding: .75rem 1rem;
  background: rgba(255,255,255,.75);
  border-top: 1px solid rgba(0,0,0,.08);
}

.theme-preview__search-pill,
.theme-preview__category-pill {
  padding: .35rem .6rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  background: #fff;
  border: 1px solid rgba(0,0,0,.1);
}

.theme-preview__search-pill { min-width: 110px; }

.theme-preview__cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .6rem;
  padding: 1rem;
  background: var(--tp-bg);
}

.theme-preview__card {
  height: 70px;
  border-radius: .8rem;
  border: 1px solid rgba(0,0,0,.1);
  background: #fff;
}

/* Device toggle */
.preview-device-toggle { display: flex; gap: .45rem; flex-wrap: wrap; }
.preview-device-toggle .btn.active { background: var(--acc); color: var(--bg); border-color: var(--acc); }

/* Theme preview device modes */
.theme-preview[data-device="tablet"] { max-width: 720px; margin-left: auto; margin-right: auto; }
.theme-preview[data-device="mobile"] { max-width: 380px; margin-left: auto; margin-right: auto; }

/* Theme preview variants */
.theme-preview[data-hero="hero-solid"] .theme-preview__hero {
  background: linear-gradient(135deg, var(--tp-primary) 0%, var(--tp-accent) 100%);
  color: #fff;
}
.theme-preview[data-hero="hero-outline"] .theme-preview__hero {
  background: transparent;
  border-top: 1px solid rgba(0,0,0,.08);
  border-bottom: 1px solid rgba(0,0,0,.08);
}
.theme-preview[data-hero="hero-split"] .theme-preview__hero {
  display: grid;
  grid-template-columns: 1.4fr .6fr;
  align-items: center;
}
.theme-preview[data-hero="hero-minimal"] .theme-preview__hero { background: #fff; }

.theme-preview[data-density="card-airy"] .theme-preview__cards { gap: .9rem; padding: 1.2rem; }
.theme-preview[data-density="card-airy"] .theme-preview__card { height: 88px; }
.theme-preview[data-density="card-compact"] .theme-preview__cards { gap: .45rem; padding: .75rem; }
.theme-preview[data-density="card-compact"] .theme-preview__card { height: 56px; border-radius: .55rem; }

.theme-preview[data-button="button-square"] .theme-preview__cta { border-radius: .5rem; }
.theme-preview[data-button="button-outline"] .theme-preview__cta {
  background: transparent;
  color: var(--tp-primary);
  border: 1px solid var(--tp-primary);
}
.theme-preview[data-button="button-soft"] .theme-preview__cta {
  background: color-mix(in srgb, var(--tp-primary) 14%, #fff);
  color: var(--tp-primary);
}

.theme-preview[data-home="home-list"] .theme-preview__cards { grid-template-columns: 1fr; }
.theme-preview[data-home="home-poster"] .theme-preview__cards { grid-template-columns: 2fr 1fr; }
.theme-preview[data-home="home-poster"] .theme-preview__card:first-child { grid-row: span 2; height: 148px; }
.theme-preview[data-home="home-magazine"] .theme-preview__cards { grid-template-columns: 1.5fr 1fr 1fr; }
.theme-preview[data-home="home-minimal"] .theme-preview__card { border-radius: .35rem; box-shadow: none; }

.theme-preview[data-header="header-centered"] .theme-preview__header { justify-content: center; }
.theme-preview[data-header="header-minimal"] .theme-preview__header { border-bottom-style: dashed; }
.theme-preview[data-header="header-glass"] .theme-preview__header {
  background: rgba(255,255,255,.6);
  backdrop-filter: blur(6px);
}
.theme-preview[data-header="header-split"] .theme-preview__chip { order: -1; margin-left: 0; }

.theme-preview[data-page="page-spacious"] .theme-preview__hero,
.theme-preview[data-page="page-spacious"] .theme-preview__cards { padding-left: 1.25rem; padding-right: 1.25rem; }
.theme-preview[data-page="page-compact"] .theme-preview__hero,
.theme-preview[data-page="page-compact"] .theme-preview__cards { padding: .75rem; }
.theme-preview[data-page="page-framed"] { border-width: 2px; }
.theme-preview[data-page="page-immersive"] .theme-preview__hero {
  background: linear-gradient(130deg, var(--tp-primary) 0%, var(--tp-accent) 100%);
  color: #fff;
}

.theme-preview[data-event="event-story"] .theme-preview__heading { font-style: italic; }
.theme-preview[data-event="event-split"] .theme-preview__cards { grid-template-columns: 1.8fr 1fr; }
.theme-preview[data-event="event-minimal"] .theme-preview__hero { background: #fff; }
.theme-preview[data-event="event-cardstack"] .theme-preview__card { transform: rotate(-1deg); }

/* ── Spinner ── */
.spinner {
  width: 28px; height: 28px;
  border: 2.5px solid var(--bdr);
  border-top-color: var(--acc);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 3rem auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ── */
#toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem;
  background: var(--bg-2); color: var(--tx);
  border: 1px solid var(--bdr-hi);
  padding: .7rem 1.1rem; border-radius: var(--radius);
  font-family: var(--f-d); font-size: .82rem; font-weight: 500;
  box-shadow: 0 4px 16px oklch(0% 0 0 / 0.4);
  opacity: 0; transform: translateY(6px);
  transition: opacity .18s, transform .18s;
  pointer-events: none; z-index: 9999; max-width: 300px;
}

#toast.show { opacity: 1; transform: translateY(0); }
#toast.toast--success { background: var(--green-tint); color: var(--green); border-color: oklch(30% 0.10 150 / 0.5); }
#toast.toast--error   { background: var(--red-tint);   color: var(--red);   border-color: oklch(30% 0.10 22 / 0.5); }

/* ── Responsive ── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .form-row { grid-template-columns: 1fr; }
}
