:root {
  /* Per-domain branding (plan §12) - overridden by /_brand/theme.css when an admin customises
     a domain; left alone by the dark-mode block below so an explicit branding choice always wins. */
  --brand-primary: #2563eb;
  --brand-bg: #f8fafc;
  --brand-text: #0f172a;

  /* App chrome - independent of branding, switches with the light/dark toggle. */
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --success: #15803d;
  --success-bg: #f0fdf4;
  --warning: #b45309;
  --warning-bg: #fffbeb;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-bg: #0f172a;
    --brand-text: #e2e8f0;
    --surface: #1e293b;
    --surface-2: #162032;
    --border: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --danger: #f87171;
    --danger-bg: #450a0a;
    --success: #4ade80;
    --success-bg: #052e16;
    --warning: #fbbf24;
    --warning-bg: #451a03;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --brand-bg: #0f172a;
  --brand-text: #e2e8f0;
  --surface: #1e293b;
  --surface-2: #162032;
  --border: #334155;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --success: #4ade80;
  --success-bg: #052e16;
  --warning: #fbbf24;
  --warning-bg: #451a03;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
}

html {
  font-size: 14px;
  color-scheme: light dark;
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

body {
  background: var(--brand-bg);
  color: var(--brand-text);
  min-height: 100%;
}

/* --- Component classes - keep markup declarative, keep theming in one place --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: var(--shadow);
}

.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border-radius: 9999px;
  padding: 0.125rem 0.6rem;
  font-size: 0.7rem;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }

.input {
  width: 100%;
  border-radius: 0.5rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.input:focus {
  outline: none;
  border-color: var(--brand-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand-primary) 20%, transparent);
}
.input[type="color"] { height: 2.5rem; padding: 0.25rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  border-radius: 0.5rem;
  padding: 0.5rem 1rem;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
.btn-primary { background: var(--brand-primary); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.btn-link { background: none; border: none; color: var(--text-muted); font-weight: 500; padding: 0; }
.btn-link:hover { color: var(--brand-primary); }

.table-clean { width: 100%; font-size: 0.9rem; border-collapse: collapse; }
.table-clean th {
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
}
.table-clean td {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1rem;
  color: var(--text);
}
.table-clean tr:last-child td { border-bottom: none; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.theme-toggle:hover { color: var(--brand-primary); border-color: var(--brand-primary); }
.theme-toggle .fa-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .fa-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .fa-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .fa-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .fa-moon { display: none; }
}
