/* ============ Design tokens — Mail Platform ============ */
:root {
  /* Canvas & surfaces */
  --canvas: #f4f5f7;
  --surface-1: #ffffff;
  --surface-2: #fafbfc;
  --surface-3: #eef0f3;
  --surface-inverse: #10182b;

  /* Text */
  --text-1: #131a2a;
  --text-2: #4b5568;
  --text-3: #8b93a5;
  --text-inverse: #f4f6fb;

  /* Borders */
  --border-1: #e2e5ea;
  --border-2: #eceef2;
  --border-focus: #3b5bfd;

  /* Accent */
  --accent: #3b5bfd;
  --accent-hover: #2e4be4;
  --accent-active: #2440ce;
  --accent-soft: #eef1ff;
  --accent-soft-border: #d7defe;
  --accent-text: #2c47e0;

  /* Status */
  --ok: #147d52;
  --ok-soft: #e7f6ee;
  --ok-border: #bfe6d2;
  --warn: #9a6a00;
  --warn-soft: #fdf4dd;
  --warn-border: #f0dfae;
  --danger: #c62f34;
  --danger-soft: #fdeeee;
  --danger-border: #f5cccd;
  --danger-hover: #ab2429;

  /* Type */
  --font-ui: 'Inter', -apple-system, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', Consolas, monospace;

  /* Shape */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Elevation */
  --shadow-1: 0 1px 2px rgba(19, 26, 42, 0.05);
  --shadow-2: 0 2px 8px rgba(19, 26, 42, 0.08);
  --shadow-3: 0 8px 32px rgba(19, 26, 42, 0.16);

  /* Motion */
  --motion-fast: 120ms cubic-bezier(0.2, 0, 0, 1);
  --motion-normal: 180ms cubic-bezier(0.2, 0, 0, 1);

  /* Spacing rhythm: 4px base — use multiples */
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-1);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ============ Primitives ============ */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px; font-weight: 550;
  cursor: pointer; user-select: none;
  transition: background var(--motion-fast), border-color var(--motion-fast),
              color var(--motion-fast), box-shadow var(--motion-fast), transform var(--motion-fast);
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--border-focus); outline-offset: 2px; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 16px; height: 16px; flex: none; }

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

.btn-secondary { background: var(--surface-1); border-color: var(--border-1); color: var(--text-1); box-shadow: var(--shadow-1); }
.btn-secondary:hover { background: var(--surface-2); border-color: #d3d7de; }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text-1); }

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

.btn-sm { height: 28px; padding: 0 10px; font-size: 12.5px; }
.btn-icon { width: 32px; height: 32px; padding: 0; border-radius: var(--radius-sm); }
.btn[disabled] { opacity: 0.55; cursor: default; pointer-events: none; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--text-3); }
.input, .select, .textarea {
  height: 34px; padding: 0 11px;
  background: var(--surface-1);
  border: 1px solid var(--border-1);
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
  width: 100%;
}
.textarea { height: auto; padding: 9px 11px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 91, 253, 0.14);
}
.input.invalid { border-color: var(--danger); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%234b5568' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 32px; }

/* Status pills */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  height: 22px; padding: 0 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid transparent;
}
.pill svg { width: 12px; height: 12px; }
.pill-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok-border); }
.pill-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-border); }
.pill-danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.pill-muted { background: var(--surface-3); color: var(--text-2); border-color: var(--border-1); }
.pill-accent { background: var(--accent-soft); color: var(--accent-text); border-color: var(--accent-soft-border); }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 43, 0.4);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px;
  animation: fadeIn 140ms ease;
  overflow-y: auto;
}
.modal {
  background: var(--surface-1); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  width: 100%; max-width: 480px;
  animation: modalIn 160ms cubic-bezier(0.2, 0, 0, 1);
}
.modal-lg { max-width: 720px; }
.modal header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 0;
}
.modal header h2 { margin: 0; font-size: 16px; font-weight: 650; }
.modal .modal-body { padding: 16px 20px; display: flex; flex-direction: column; gap: 14px; }
.modal footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 4px 20px 18px;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(-8px) scale(0.99); } }

/* Toast */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--surface-inverse); color: var(--text-inverse);
  padding: 10px 16px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-3);
  display: flex; align-items: center; gap: 9px;
  animation: toastIn 200ms cubic-bezier(0.2, 0, 0, 1);
  max-width: min(90vw, 480px);
}
.toast.err { background: #5d1a1c; }
.toast svg { width: 15px; height: 15px; flex: none; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-3); padding: 8px 12px; border-bottom: 1px solid var(--border-1);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border-2); vertical-align: middle; }
.table tbody tr { transition: background var(--motion-fast); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.clickable { cursor: pointer; }

.mono { font-family: var(--font-mono); font-size: 12.5px; }
.muted { color: var(--text-3); }
.spin { animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Scrollbars (WebKit) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #c9cdd6; border-radius: 6px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: #aeb4c0; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }

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