:root {
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
  --color-bg: #f8fafc;
  --color-bg-gradient-end: #f1f5f9;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-border-light: #f1f5f9;
  --color-text: #0f172a;
  --color-text-muted: #64748b;
  --color-text-light: #94a3b8;
  --color-primary: #0f172a;
  --color-primary-hover: #1e293b;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success-bg: #ecfdf5;
  --color-success: #059669;
  --color-warning-bg: #fffbeb;
  --color-warning: #b45309;
  --color-info-bg: #eff6ff;
  --color-info: #2563eb;
  --radius-sm: 0.5rem;
  --radius-md: 0.75rem;
  --radius-lg: 1rem;
  --radius-xl: 1.25rem;
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
}

* { box-sizing: border-box; }

html {
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.5;
}

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: linear-gradient(135deg, var(--color-bg), #fff, var(--color-bg-gradient-end));
}

.auth-page__main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8) var(--space-4);
}

.auth-page__container {
  width: 100%;
  max-width: 28rem;
}

.auth-page__brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: var(--space-8);
}

.auth-page__logo {
  width: 3.5rem;
  height: 3.5rem;
  border-radius: var(--radius-xl);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 700;
  box-shadow: var(--shadow-sm);
  margin-bottom: var(--space-4);
}

.auth-page__secured {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.auth-page__client {
  margin-top: var(--space-2);
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.auth-page__footer {
  border-top: 1px solid var(--color-border);
  background: rgba(255,255,255,0.5);
  padding: var(--space-4);
  text-align: center;
  font-size: 0.75rem;
  color: var(--color-text-light);
}

.auth-page__footer a {
  color: var(--color-text-light);
  text-decoration: none;
}

.auth-page__footer a:hover { color: var(--color-text-muted); }

.card {
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  box-shadow: var(--shadow-sm);
  padding: var(--space-8);
}

.card__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.card__subtitle {
  margin: 0.375rem 0 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.card__body { margin-top: var(--space-6); }

.form { display: flex; flex-direction: column; gap: var(--space-4); }

.label {
  display: block;
  margin-bottom: 0.375rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #334155;
}

.input {
  width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid #cbd5e1;
  background: #fff;
  padding: 0.625rem 0.875rem;
  font-size: 0.875rem;
  color: var(--color-text);
}

.input:focus {
  outline: none;
  border-color: #64748b;
  box-shadow: 0 0 0 1px #64748b;
}

.input--code {
  height: 3.5rem;
  text-align: center;
  font-size: 1.25rem;
  font-weight: 700;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border-radius: var(--radius-md);
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

.btn--primary:hover { background: var(--color-primary-hover); }

.btn--secondary {
  background: #fff;
  color: #334155;
  border: 1px solid #cbd5e1;
}

.btn--secondary:hover { background: #f8fafc; }

.btn--ghost {
  background: transparent;
  color: var(--color-text-muted);
}

.btn--ghost:hover { background: #f1f5f9; }

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

.btn--block { width: 100%; }

.alert {
  border-radius: var(--radius-md);
  padding: var(--space-3);
  font-size: 0.875rem;
}

.alert--error {
  background: #fef2f2;
  color: #b91c1c;
}

.alert--info {
  background: #f8fafc;
  color: var(--color-text-muted);
  font-size: 0.75rem;
}

.alert--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  font-size: 0.75rem;
}

.consent__app {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  border-radius: var(--radius-md);
  background: #f8fafc;
  padding: var(--space-4);
  margin-bottom: var(--space-6);
}

.consent__scopes { list-style: none; padding: 0; margin: 0; }

.consent__scope {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.consent__check {
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 9999px;
  background: var(--color-success-bg);
  color: var(--color-success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  flex-shrink: 0;
}

.consent__actions {
  display: flex;
  gap: var(--space-3);
  margin-top: var(--space-6);
}

.consent__actions .btn { flex: 1; }

/* Admin layout */
.admin-layout {
  display: flex;
  min-height: 100vh;
  background: var(--color-bg);
}

.admin-layout__sidebar {
  width: 15rem;
  border-right: 1px solid var(--color-border);
  background: var(--color-surface);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
}

.admin-layout__brand {
  height: 4rem;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--color-border);
}

.admin-layout__brand-icon {
  width: 2rem;
  height: 2rem;
  border-radius: var(--radius-md);
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.875rem;
}

.admin-layout__nav {
  flex: 1;
  padding: var(--space-3);
  overflow-y: auto;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  border: none;
  background: none;
  border-radius: var(--radius-md);
  padding: var(--space-2) var(--space-3);
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-decoration: none;
  cursor: pointer;
  margin-bottom: 0.25rem;
}

.sidebar-link:hover {
  background: #f1f5f9;
  color: var(--color-text);
}

.sidebar-link--active {
  background: var(--color-primary);
  color: #fff;
}

.sidebar-link--active:hover {
  background: var(--color-primary);
  color: #fff;
}

.admin-layout__content {
  flex: 1;
  margin-left: 15rem;
  display: flex;
  flex-direction: column;
}

.admin-layout__header {
  height: 4rem;
  border-bottom: 1px solid var(--color-border);
  background: rgba(255,255,255,0.8);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-8);
  position: sticky;
  top: 0;
  z-index: 10;
}

.admin-layout__main {
  flex: 1;
  padding: var(--space-8);
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: var(--space-6);
  gap: var(--space-4);
}

.page-header__title {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0;
}

.page-header__subtitle {
  margin: var(--space-1) 0 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

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

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.table th {
  text-align: left;
  padding: 0.75rem 1rem;
  font-weight: 500;
  color: var(--color-text-muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
}

.table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 9999px;
  padding: 0.125rem 0.625rem;
  font-size: 0.75rem;
  font-weight: 500;
}

.badge--green { background: #ecfdf5; color: #047857; }
.badge--red { background: #fef2f2; color: #b91c1c; }
.badge--slate { background: #f1f5f9; color: #475569; }

.setup-wizard {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.setup-wizard__container { width: 100%; max-width: 42rem; }

.setup-wizard__hero { text-align: center; margin-bottom: var(--space-8); }

.mono-box {
  border-radius: var(--radius-md);
  background: #f8fafc;
  padding: var(--space-4);
  font-family: var(--font-mono);
  font-size: 0.75rem;
}

.mono-box__row {
  display: flex;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.admin-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: 0.875rem;
  margin-bottom: var(--space-4);
}

.admin-banner--warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
  border: 1px solid #fcd34d;
}

.admin-banner a {
  color: inherit;
  font-weight: 600;
  white-space: nowrap;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

textarea.input {
  resize: vertical;
  min-height: 2.5rem;
  font-family: inherit;
}

.admin-tab {
  border: none;
  background: none;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.admin-tab:hover { color: var(--color-text); }

.admin-tab--active {
  color: var(--color-text);
  border-bottom-color: var(--color-primary);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
}

.modal__dialog {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 28rem;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  border: 1px solid var(--color-border);
  box-shadow: 0 25px 50px -12px rgb(0 0 0 / 0.25);
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.modal__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.modal__close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--color-text-muted);
  cursor: pointer;
  padding: 0.25rem;
}

.modal__close:hover { color: var(--color-text); }

.modal__body {
  padding: var(--space-6);
}

.modal__footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
}

.email-body { font-family: var(--font-sans); }
.email-header { border-bottom: 1px solid var(--color-border-light); background: #f8fafc; padding: 1.5rem 2rem; }
.email-content { padding: 2rem; }
.email-footer { border-top: 1px solid var(--color-border-light); background: #f8fafc; padding: 1.5rem 2rem; font-size: 0.75rem; color: var(--color-text-light); }
.email-btn { display: inline-block; background: var(--color-primary); color: #fff; padding: 0.75rem 1.5rem; border-radius: var(--radius-md); text-decoration: none; font-size: 0.875rem; font-weight: 500; margin: 1.5rem 0; }

[data-alpine] { display: block; }
[x-cloak] { display: none !important; }

.client-drawer {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}

.client-drawer__backdrop {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: rgb(15 23 42 / 0.4);
}

.client-drawer__panel {
  position: relative;
  z-index: 1;
  width: min(56rem, 100%);
  height: 100%;
  background: var(--color-surface);
  border-left: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 24px rgb(0 0 0 / 0.08);
}

.client-drawer__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.client-drawer__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
}

.client-drawer__subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--color-text-muted);
}

.client-drawer__close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--color-text-muted);
}

.client-drawer__tabs {
  display: flex;
  gap: 0.25rem;
  padding: 0 var(--space-6);
  border-bottom: 1px solid var(--color-border);
}

.client-drawer__tab {
  border: none;
  background: none;
  padding: 0.75rem 1rem;
  font-size: 0.875rem;
  color: var(--color-text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}

.client-drawer__tab--active {
  color: var(--color-text);
  border-bottom-color: var(--color-primary);
  font-weight: 500;
}

.client-drawer__body {
  flex: 1;
  overflow: auto;
  padding: var(--space-6);
}

.client-drawer__footer {
  display: flex;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-6);
  border-top: 1px solid var(--color-border);
}

.client-type-card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
}

.client-type-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
}

.copy-field {
  display: flex;
  gap: var(--space-2);
}

.copy-field__input {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
}

.copy-field__btn {
  flex-shrink: 0;
}

.template-editor {
  display: grid;
  grid-template-columns: 14rem 1fr;
  gap: var(--space-6);
}

.template-editor__nav {
  border-right: 1px solid var(--color-border);
  padding-right: var(--space-4);
  max-height: 32rem;
  overflow: auto;
}

.template-editor__group-block {
  display: contents;
}

.template-editor__section {
  margin: var(--space-4) 0 var(--space-2);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--color-text-light);
}

.template-editor__item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 0.375rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
  color: var(--color-text-muted);
  cursor: pointer;
}

.template-editor__item--active,
.template-editor__item:hover {
  background: var(--color-border-light);
  color: var(--color-text);
}

.template-editor__title {
  margin: 0 0 var(--space-4);
  font-size: 1rem;
}

.template-editor__placeholders {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  align-items: center;
  margin: var(--space-4) 0;
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.template-editor__chip {
  border: 1px solid var(--color-border);
  background: #fff;
  border-radius: 999px;
  padding: 0.125rem 0.5rem;
  font-size: 0.6875rem;
  font-family: var(--font-mono);
  cursor: pointer;
}

.template-editor__actions {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}

.template-editor__preview {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  background: #fff;
  width: 100%;
  min-height: 12rem;
  max-height: 20rem;
}

@media (max-width: 900px) {
  .template-editor { grid-template-columns: 1fr; }
  .template-editor__nav {
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    padding-right: 0;
    padding-bottom: var(--space-4);
    max-height: 12rem;
  }
}

.client-row {
  cursor: pointer;
}

.client-row:hover {
  background: var(--color-border-light);
}

