/* ==========================================================================
   Abulu Mail — Design System (Vercel-style, neutral minimal)
   Shared by /, /mail.html, /admin.html, /docs.html
   ========================================================================== */

:root {
  /* Neutral zinc scale */
  --bg: #fafafa;
  --bg-2: #f4f4f5;
  --surface: #ffffff;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --muted: #71717a;
  --muted-2: #a1a1aa;

  /* Accent */
  --accent: #0070f3;
  --accent-strong: #0060d0;
  --accent-soft: #eef5ff;
  --accent-fg: #ffffff;

  /* Semantic */
  --success: #16a34a;
  --success-soft: #ecfdf5;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --info: #0891b2;
  --info-soft: #ecfeff;

  /* Code */
  --code-bg: #f4f4f5;
  --code-text: #27272a;

  /* Radii / shadows */
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="dark"] {
  --bg: #09090b;
  --bg-2: #131316;
  --surface: #101012;
  --border: #26262b;
  --border-strong: #3f3f46;
  --text: #fafafa;
  --muted: #a1a1aa;
  --muted-2: #71717a;

  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --accent-fg: #ffffff;

  --success: #4ade80;
  --success-soft: rgba(22, 163, 74, 0.15);
  --warning: #fbbf24;
  --warning-soft: rgba(217, 119, 6, 0.15);
  --danger: #f87171;
  --danger-soft: rgba(220, 38, 38, 0.15);
  --info: #22d3ee;
  --info-soft: rgba(8, 145, 178, 0.15);

  --code-bg: #18181b;
  --code-text: #e4e4e7;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.6);
}

/* ── Reset ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: none; }
svg { display: block; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; }

/* ── Typography helpers ────────────────────────────────── */
.mono { font-family: var(--mono); font-size: 0.92em; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  background: var(--accent);
  color: var(--accent-fg);
  transition: background 0.15s, border-color 0.15s, color 0.15s, opacity 0.15s;
}
.btn:hover { background: var(--accent-strong); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.btn.ghost {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn.ghost:hover { background: var(--bg-2); border-color: var(--border-strong); }

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

.btn.sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn.block { width: 100%; }
.btn.loading { pointer-events: none; opacity: 0.7; }
.btn.loading::before {
  content: "";
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Forms ─────────────────────────────────────────────── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}
.input, input[type="text"], input[type="email"], input[type="password"], select, textarea {
  width: 100%;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.input:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted-2); }

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

/* ── Badge ─────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.on, .badge.active { background: var(--success-soft); color: var(--success); }
.badge.off { background: var(--bg-2); color: var(--muted); }
.badge.pending { background: var(--warning-soft); color: var(--warning); }
.badge.temp { background: var(--info-soft); color: var(--info); }
.badge.error, .badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.user { background: var(--accent-soft); color: var(--accent); }

/* ── Table ─────────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--bg-2); }

/* ── Empty / loading / error states ────────────────────── */
.empty, .loading, .error-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
  padding: 40px 20px;
  color: var(--muted);
}
.empty .empty-icon {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px;
  background: var(--bg-2);
  color: var(--muted-2);
  margin-bottom: 8px;
}
.empty .empty-icon svg { width: 26px; height: 26px; }
.empty h3 { margin: 4px 0 2px; color: var(--text); font-size: 15px; font-weight: 650; }
.empty p { margin: 0 0 10px; font-size: 13px; max-width: 360px; }
.error-state { color: var(--danger); }

/* Skeleton shimmer */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--bg-2);
  border-radius: var(--radius);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.35), transparent);
  animation: shimmer 1.4s infinite;
}
[data-theme="dark"] .skeleton::after {
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.06), transparent);
}
@keyframes shimmer { 100% { transform: translateX(100%); } }

/* ── Spinner ───────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 15px; height: 15px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Header / nav ──────────────────────────────────────── */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 24px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 17px;
  font-weight: 750;
  letter-spacing: -0.02em;
  color: var(--text);
}
.brand img { width: 26px; height: 26px; object-fit: contain; border-radius: 6px; }
.brand em { font-style: normal; color: var(--accent); }
.nav { display: flex; align-items: center; gap: 4px; }
.nav a, .nav .icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--muted);
  padding: 7px 12px;
  border-radius: var(--radius);
  transition: color 0.15s, background 0.15s;
}
.nav a:hover { color: var(--text); background: var(--bg-2); }
.nav a.cta { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.nav a.cta:hover { background: var(--accent-strong); }
.nav a svg { width: 16px; height: 16px; }
.nav .nlabel { white-space: nowrap; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--text); border-color: var(--border-strong); }
.icon-btn svg { width: 17px; height: 17px; }

/* ── Toast ─────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--radius);
  padding: 11px 16px;
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
[data-theme="dark"] .toast { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.err { background: var(--danger); color: #fff; }
.toast svg { width: 16px; height: 16px; }

/* ── Modal ─────────────────────────────────────────────── */
.modal-bg {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 780px;
  max-width: 100%;
  max-height: 88vh;
  overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0 0 6px; font-size: 16px; }
.modal-meta { font-size: 13px; color: var(--muted); line-height: 1.7; }
.modal-body { padding: 18px 22px; line-height: 1.6; font-size: 14px; }
.modal-close {
  float: right;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-weight: 600;
  font-size: 12.5px;
}
.modal-close:hover { background: var(--bg-2); }

/* ── Layout helpers ────────────────────────────────────── */
.wrap { max-width: 860px; margin: 0 auto; padding: 32px 20px 72px; }
.wrap-lg { max-width: 1080px; }
.grid { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1; min-width: 0; }
hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ── Stat cards (admin overview) ───────────────────────── */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat b { display: block; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat .sub { color: var(--muted-2); font-size: 11.5px; margin-top: 3px; }

/* ── Avatar (message list) ─────────────────────────────── */
.avatar {
  flex: 0 0 38px;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bg-2);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  text-transform: uppercase;
}

/* ── Charts ────────────────────────────────────────────── */
.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.chart-card { padding: 16px 18px; }
.chart-card h4 { margin: 0 0 12px; font-size: 13.5px; font-weight: 650; color: var(--muted); }
.chart-legend { display: flex; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.chart-legend .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.chart-empty { color: var(--muted-2); font-size: 12.5px; text-align: center; padding: 24px 0; }

/* ── Code / pre ────────────────────────────────────────── */
code {
  font-family: var(--mono);
  background: var(--code-bg);
  color: var(--code-text);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.9em;
}
pre {
  background: var(--code-bg);
  color: var(--code-text);
  padding: 14px 16px;
  border-radius: var(--radius);
  overflow: auto;
  font-size: 12.5px;
  line-height: 1.6;
  border: 1px solid var(--border);
}
pre code { background: none; padding: 0; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 760px) {
  .header { padding: 11px 14px; }
  .nav a .nlabel { display: none; }
  .nav a { padding: 8px 10px; }
  .chart-grid { grid-template-columns: 1fr; }
  .wrap { padding: 20px 14px 56px; }
}

/* ── Accessibility ─────────────────────────────────────── */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}
