/* ============================================================
   DatazymesMail — design system
   Tokens: color (light/dark) · type · space · radius · motion
   ============================================================ */

:root {
  /* Surfaces & text — LIGHT (default) */
  --bg-primary: #f8fafc;
  --bg-secondary: #f1f5f9;
  --surface-card: #ffffff;
  --surface-raised: #ffffff;
  --border-subtle: #e2e8f0;
  --border-strong: #cbd5e1;
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #94a3b8;

  /* Brand + semantic */
  --accent-primary: #4f46e5;
  --accent-hover: #4338ca;
  --accent-contrast: #ffffff;
  --accent-soft: #eef2ff;
  --success: #059669;
  --success-soft: #ecfdf5;
  --warning: #b45309;
  --warning-soft: #fffbeb;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --focus-ring: rgba(79, 70, 229, 0.45);

  /* Type */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;

  /* Space (4/8 scale) */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;

  /* Radius */
  --radius-sm: 8px;
  --radius-lg: 12px;
  --radius-full: 999px;

  /* Elevation — restrained, offset + soft blur */
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);

  /* Motion */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 170ms;

  color-scheme: light;
}

/* DARK — system default (when no explicit choice) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg-primary: #0b0f19;
    --bg-secondary: #0f1623;
    --surface-card: #111827;
    --surface-raised: #161f30;
    --border-subtle: #1e293b;
    --border-strong: #334155;
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;

    --accent-primary: #6366f1;
    --accent-hover: #818cf8;
    --accent-contrast: #0b0f19;
    --accent-soft: #1e1b4b;
    --success: #34d399;
    --success-soft: #052e22;
    --warning: #fbbf24;
    --warning-soft: #2a2008;
    --danger: #fb7185;
    --danger-soft: #3b0a16;
    --focus-ring: rgba(129, 140, 248, 0.5);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
  }
}

/* DARK — explicit choice */
:root[data-theme="dark"] {
  --bg-primary: #0b0f19;
  --bg-secondary: #0f1623;
  --surface-card: #111827;
  --surface-raised: #161f30;
  --border-subtle: #1e293b;
  --border-strong: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-tertiary: #64748b;

  --accent-primary: #6366f1;
  --accent-hover: #818cf8;
  --accent-contrast: #0b0f19;
  --accent-soft: #1e1b4b;
  --success: #34d399;
  --success-soft: #052e22;
  --warning: #fbbf24;
  --warning-soft: #2a2008;
  --danger: #fb7185;
  --danger-soft: #3b0a16;
  --focus-ring: rgba(129, 140, 248, 0.5);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 20px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-primary);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
h1, h2, h3 { letter-spacing: -0.02em; line-height: 1.25; margin: 0; font-weight: 600; text-wrap: balance; }
a { color: var(--accent-primary); text-decoration: none; }
::selection { background: var(--accent-primary); color: var(--accent-contrast); }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-sm); }
:focus:not(:focus-visible) { outline: none; }

/* Scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--radius-full); border: 2px solid var(--bg-primary); }
*::-webkit-scrollbar-track { background: transparent; }

.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-secondary); }
.sub { font-size: var(--text-sm); color: var(--text-secondary); }
[hidden] { display: none !important; }

/* ---------- header ---------- */
.app-header {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: var(--sp-4);
  padding: var(--sp-3) var(--sp-5);
  background: color-mix(in srgb, var(--bg-primary) 86%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-subtle);
}
.brand { display: flex; align-items: center; gap: var(--sp-2); font-weight: 600; letter-spacing: -0.02em; }
.brand svg { width: 24px; height: 24px; color: var(--accent-primary); }
.spacer { flex: 1; }
.header-id { font-size: var(--text-sm); color: var(--text-secondary); }

/* ---------- theme segmented control ---------- */
.theme-toggle {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--bg-secondary); border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}
.theme-toggle button {
  display: inline-grid; place-items: center;
  width: 30px; height: 28px; padding: 0;
  background: transparent; border: 0; border-radius: var(--radius-full);
  color: var(--text-tertiary); cursor: pointer;
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.theme-toggle button svg { width: 16px; height: 16px; }
.theme-toggle button:hover { color: var(--text-primary); }
.theme-toggle button[aria-pressed="true"] {
  background: var(--surface-card); color: var(--accent-primary);
  box-shadow: var(--shadow-sm);
}

/* ---------- layout shells ---------- */
.shell { width: 100%; margin: 0 auto; padding: var(--sp-6) var(--sp-6); }
.center-screen { min-height: calc(100vh - 57px); display: grid; place-items: center; padding: var(--sp-4); }

/* Products: list + detail side by side on wide screens, using the full width */
#tab-products { display: grid; grid-template-columns: 1fr; gap: var(--sp-4); align-items: start; }
@media (min-width: 1024px) { #tab-products { grid-template-columns: minmax(300px, 380px) 1fr; } }
/* Grid children get spacing from `gap`; neutralize the stacked-card top margin so both tops align. */
#tab-products > .card { margin-top: 0; }

/* Forms stay at a readable measure even in a full-width card */
.form-narrow { max-width: 560px; }

/* ---------- cards ---------- */
.card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--sp-4); }
.card-title { font-size: var(--text-lg); margin-bottom: var(--sp-1); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.section-label {
  font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text-tertiary); margin: var(--sp-5) 0 var(--sp-3);
}

/* ---------- forms ---------- */
label.field { display: block; margin-bottom: var(--sp-3); font-size: var(--text-sm); color: var(--text-secondary); font-weight: 500; }
label.field > span { display: block; margin-bottom: var(--sp-1); }
input, select {
  width: 100%; font: inherit; font-size: var(--text-base);
  color: var(--text-primary); background: var(--bg-primary);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  padding: 9px var(--sp-3);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
input::placeholder { color: var(--text-tertiary); }
input:focus-visible, select:focus-visible {
  outline: none; border-color: var(--accent-primary);
  box-shadow: 0 0 0 3px var(--focus-ring);
}
.inline-form { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; flex: 1; min-width: 160px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  font: inherit; font-size: var(--text-sm); font-weight: 500; line-height: 1;
  padding: 9px var(--sp-4); border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
    color var(--dur) var(--ease), transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.btn:active { transform: translateY(0.5px); }
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--accent-primary); color: var(--accent-contrast); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: transparent; border-color: var(--border-strong); color: var(--text-primary); }
.btn-ghost:hover { background: var(--bg-secondary); border-color: var(--text-tertiary); }
.btn-danger { background: transparent; border-color: color-mix(in srgb, var(--danger) 40%, transparent); color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); }
.btn-sm { padding: 6px var(--sp-3); font-size: var(--text-xs); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- tabs ---------- */
.tabs { display: inline-flex; gap: var(--sp-1); padding: var(--sp-1); background: var(--bg-secondary);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); margin-bottom: var(--sp-5); }
.tabs button {
  font: inherit; font-size: var(--text-sm); font-weight: 500;
  padding: 6px var(--sp-4); border: 0; border-radius: 6px; cursor: pointer;
  background: transparent; color: var(--text-secondary);
  transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.tabs button:hover { color: var(--text-primary); }
.tabs button.active { background: var(--surface-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ---------- lists ---------- */
.list { list-style: none; padding: 0; margin: 0; }
.list-row {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-3);
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  margin-bottom: var(--sp-2); background: var(--bg-primary);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.list-row.clickable { cursor: pointer; }
.list-row.clickable:hover { border-color: var(--accent-primary); background: var(--accent-soft); }
.list-row.selected { border-color: var(--accent-primary); background: var(--accent-soft); }
.list-row .meta { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.list-row .name { font-weight: 500; }

/* ---------- stats strip ---------- */
.stats {
  display: flex; flex-wrap: wrap; gap: 0;
  border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
  overflow: hidden; margin: var(--sp-1) 0 var(--sp-4);
}
.stat {
  flex: 1; min-width: 120px; padding: var(--sp-3) var(--sp-4);
  display: flex; flex-direction: column; gap: 2px;
  border-right: 1px solid var(--border-subtle); background: var(--bg-primary);
}
.stat:last-child { border-right: 0; }
.stat-value { font-size: var(--text-xl); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.stat-label { font-size: var(--text-xs); color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- badges / pills ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: var(--text-xs); font-weight: 500; padding: 2px 9px; border-radius: var(--radius-full);
  border: 1px solid transparent;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.verified, .pill.sent { color: var(--success); background: var(--success-soft); }
.pill.pending { color: var(--warning); background: var(--warning-soft); }
.pill.failed, .pill.revoked { color: var(--danger); background: var(--danger-soft); }
.pill.queued { color: var(--accent-primary); background: var(--accent-soft); }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border-subtle); border-radius: var(--radius-lg); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data thead th {
  text-align: left; font-weight: 600; font-size: var(--text-xs); letter-spacing: 0.03em;
  text-transform: uppercase; color: var(--text-tertiary);
  padding: var(--sp-3) var(--sp-4); background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle); white-space: nowrap;
}
table.data td { padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border-subtle); vertical-align: top; }
table.data tbody tr:hover { background: var(--bg-secondary); }
table.data .mono { font-variant-numeric: tabular-nums; }

/* DNS records table */
.dns { width: 100%; border-collapse: collapse; margin-top: var(--sp-3); font-size: var(--text-xs); }
.dns th, .dns td { border: 1px solid var(--border-subtle); padding: var(--sp-2) var(--sp-3); text-align: left; }
.dns th { background: var(--bg-secondary); color: var(--text-secondary); font-weight: 600; }

/* ---------- token reveal ---------- */
.token-box {
  display: flex; align-items: center; gap: var(--sp-3); justify-content: space-between;
  background: var(--accent-soft); border: 1px solid color-mix(in srgb, var(--accent-primary) 30%, transparent);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); margin: var(--sp-3) 0;
}
.token-box code { font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-all; }

/* ---------- developer docs ---------- */
.doc-lead { color: var(--text-secondary); margin: 0 0 var(--sp-4); max-width: 68ch; }
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0 0 var(--sp-2); display: grid; gap: var(--sp-3); }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: var(--sp-3); align-items: start; }
.steps li::before {
  counter-increment: step; content: counter(step);
  width: 28px; height: 28px; display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-primary); font-weight: 600; font-size: var(--text-sm);
  border-radius: 50%;
}
.endpoint { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; margin: var(--sp-2) 0 var(--sp-4);
  font-family: var(--font-mono); font-size: var(--text-sm); }
.method { font-weight: 600; color: var(--success); letter-spacing: 0.04em; }
.codeblock { border: 1px solid var(--border-subtle); border-radius: var(--radius-sm); overflow: hidden; margin-bottom: var(--sp-4); }
.codeblock-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3); background: var(--bg-secondary); border-bottom: 1px solid var(--border-subtle); }
.lang-tabs { display: inline-flex; gap: 2px; }
.lang-tabs button { font: inherit; font-size: var(--text-xs); font-weight: 500; padding: 4px 10px; border: 0;
  border-radius: 6px; background: transparent; color: var(--text-secondary); cursor: pointer; }
.lang-tabs button.active { background: var(--surface-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.codeblock pre { margin: 0; padding: var(--sp-4); overflow-x: auto; background: var(--surface-card);
  font-family: var(--font-mono); font-size: var(--text-sm); line-height: 1.65; color: var(--text-primary);
  white-space: pre; tab-size: 2; }
.resp-code { font-family: var(--font-mono); font-weight: 600; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: var(--sp-7) var(--sp-4); color: var(--text-secondary); }
.empty svg { width: 32px; height: 32px; color: var(--text-tertiary); margin-bottom: var(--sp-3); }
.empty h4 { margin: 0 0 var(--sp-1); color: var(--text-primary); font-size: var(--text-base); }

/* ---------- skeleton ---------- */
.skeleton { border-radius: var(--radius-sm); background: var(--bg-secondary); position: relative; overflow: hidden; }
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--text-tertiary) 14%, transparent), transparent);
  transform: translateX(-100%); animation: shimmer 1.3s var(--ease) infinite;
}
.skeleton-row { height: 46px; margin-bottom: var(--sp-2); }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: var(--sp-5); left: 50%; transform: translateX(-50%) translateY(8px);
  max-width: min(480px, calc(100vw - 32px));
  background: var(--surface-raised); color: var(--text-primary);
  border: 1px solid var(--border-subtle); box-shadow: var(--shadow-md);
  padding: var(--sp-3) var(--sp-4); border-radius: var(--radius-sm); font-size: var(--text-sm);
  opacity: 0; pointer-events: none; transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease);
  z-index: 50;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { border-color: color-mix(in srgb, var(--danger) 45%, var(--border-subtle)); }

.err-text { color: var(--danger); font-size: var(--text-sm); min-height: 18px; margin: var(--sp-2) 0 0; }

/* ---------- responsive ---------- */
@media (max-width: 640px) {
  .shell { padding: var(--sp-5) var(--sp-3); }
  .app-header { padding: var(--sp-3) var(--sp-4); gap: var(--sp-3); }
  .brand span { display: none; }
  .header-id { display: none; }
  .inline-form input, .inline-form select { min-width: 0; }
  .list-row { flex-wrap: wrap; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; }
}
