/* ============================================================
   SMTP Control Panel — design system, v2
   Direction: clean, light-first "premium SaaS product" — soft
   rounded cards, gentle elevation, warm restrained accent.
   Self-hosted General Sans (UI) + JetBrains Mono (technical
   identifiers only: hosts, ports, IDs). No framework.
   ============================================================ */

@font-face {
  font-family: "General Sans";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/static/fonts/GeneralSans-Regular.woff2") format("woff2");
}
@font-face {
  font-family: "General Sans";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/GeneralSans-Medium.woff2") format("woff2");
}
@font-face {
  font-family: "General Sans";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/GeneralSans-SemiBold.woff2") format("woff2");
}
@font-face {
  font-family: "General Sans";
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url("/static/fonts/GeneralSans-Bold.woff2") format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url("/static/fonts/JetBrainsMono-Medium.ttf") format("truetype");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url("/static/fonts/JetBrainsMono-SemiBold.ttf") format("truetype");
}

:root {
  /* spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  /* type scale */
  --text-xs: 0.75rem;
  --text-sm: 0.8375rem;
  --text-base: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.875rem;

  --font: "General Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgba(20, 20, 25, 0.04);
  --shadow-sm: 0 1px 2px rgba(20, 20, 25, 0.04), 0 4px 12px rgba(20, 20, 25, 0.04);
  --shadow-md: 0 2px 4px rgba(20, 20, 25, 0.04), 0 12px 32px rgba(20, 20, 25, 0.08);

  --transition-fast: 140ms cubic-bezier(0.4, 0, 0.2, 1);

  /* ---- light theme (identity default) ---- */
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f4f3ef;
  --border: #eae8e2;
  --border-strong: #ddd9d0;
  --text: #191a1d;
  --text-muted: #6b6d74;
  --text-faint: #a2a3a8;

  --accent: #ee7c33;
  --accent-hover: #d96a24;
  --accent-contrast: #ffffff;
  --accent-tint: #fdece0;
  --accent-tint-text: #a5541c;

  --success: #1c9a5b;
  --success-bg: #e5f6ec;
  --danger: #e0453f;
  --danger-bg: #fce9e8;
  --warning: #c1791a;
  --warning-bg: #fbf0dd;
}

:root[data-theme="dark"] {
  --bg: #16171a;
  --surface: #1e2024;
  --surface-2: #26282d;
  --border: #313339;
  --border-strong: #40424a;
  --text: #f1f1f2;
  --text-muted: #9a9ca3;
  --text-faint: #616369;

  --accent: #ff9752;
  --accent-hover: #ffaa70;
  --accent-contrast: #16171a;
  --accent-tint: #3a2a1c;
  --accent-tint-text: #ffb37e;

  --success: #3ecb84;
  --success-bg: #17301f;
  --danger: #ff6b64;
  --danger-bg: #34191a;
  --warning: #f0a941;
  --warning-bg: #332512;

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25), 0 4px 14px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 4px rgba(0, 0, 0, 0.3), 0 16px 40px rgba(0, 0, 0, 0.4);
}

/* Light is the fixed default regardless of OS preference — dark only
   applies when explicitly chosen via the theme toggle (data-theme="dark"),
   set in style.css's :root[data-theme="dark"] block above. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-base);
  font-weight: 500;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

a { color: var(--accent); text-decoration: none; font-weight: 600; }
a:hover { color: var(--accent-hover); }

code, .mono { font-family: var(--font-mono); font-weight: 500; font-size: 0.88em; }

strong { font-weight: 700; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.005em; margin: 0; }

::selection { background: var(--accent-tint); color: var(--accent-tint-text); }

/* ---------- layout ---------- */

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  font-size: var(--text-lg);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  letter-spacing: -0.01em;
  padding: 0 var(--space-2);
}

.brand-glyph {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--accent-tint);
  color: var(--accent-tint-text);
  border-radius: var(--radius-md);
  flex-shrink: 0;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar-nav a {
  color: var(--text-muted);
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.sidebar-nav a.active {
  background: var(--accent-tint);
  color: var(--accent-tint-text);
}

.main {
  padding: var(--space-6) var(--space-7);
  max-width: 1220px;
  width: 100%;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: var(--space-6);
  gap: var(--space-3);
}

.page-title {
  font-size: var(--text-2xl);
  font-weight: 700;
  margin: 0;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.page-subtitle {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin-top: var(--space-2);
  max-width: 62ch;
  font-weight: 500;
}

/* ---------- components ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: var(--text-sm);
  font-weight: 700;
  color: var(--text);
  margin: 0 0 var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}

.stat-tile .stat-value {
  font-family: var(--font-mono);
  font-size: var(--text-2xl);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.stat-tile .stat-label {
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: var(--space-2);
}

table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }

th {
  text-align: left;
  color: var(--text-faint);
  font-weight: 600;
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: var(--space-2) var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
}

td {
  padding: var(--space-4) var(--space-3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 3px var(--space-3);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 700;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.status-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  margin-right: var(--space-2);
  vertical-align: middle;
}
.status-dot-success { background: var(--success); box-shadow: 0 0 0 3px var(--success-bg); }
.status-dot-danger { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-bg); }

.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-muted { background: var(--surface-2); color: var(--text-muted); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform var(--transition-fast);
}

.btn svg { flex-shrink: 0; }

.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }

.btn-danger { color: var(--danger); border-color: var(--border-strong); background: var(--surface); }
.btn-danger:hover { background: var(--danger-bg); border-color: var(--danger); }

.btn-sm { padding: 5px var(--space-3); font-size: var(--text-xs); border-radius: var(--radius-sm); }

.form-field { margin-bottom: var(--space-4); }
.form-field label {
  display: block;
  font-size: var(--text-xs);
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: var(--font);
  font-weight: 500;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-field input:focus, .form-field select:focus, .form-field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.form-hint { color: var(--text-faint); font-size: var(--text-xs); margin-top: var(--space-2); font-weight: 500; }

.alert {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: 600;
  margin-bottom: var(--space-4);
}

.alert-danger { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }

/* scrollable live-log panel — stays terminal-styled, intentional contrast */
.log-panel {
  background: #191a1d;
  color: #d4d5d8;
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
}

.log-panel .line-pass { color: var(--success); }
.log-panel .line-fail { color: var(--danger); }

/* pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: var(--space-5);
  font-size: var(--text-xs);
  color: var(--text-faint);
  font-weight: 600;
}

.pagination .btn[disabled] { opacity: 0.4; pointer-events: none; }

/* theme toggle */
.theme-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font-size: var(--text-xs);
  font-family: var(--font);
  font-weight: 700;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }

/* login page */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}

.auth-card {
  width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-7) var(--space-6);
  box-shadow: var(--shadow-md);
}

.auth-title {
  font-size: var(--text-xl);
  font-weight: 700;
  margin: 0 0 var(--space-2);
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-faint);
  font-size: var(--text-sm);
  font-weight: 500;
  margin: 0 0 var(--space-6);
}

/* ---------- htmx loading feedback ---------- */

.htmx-indicator { opacity: 0; transition: opacity 200ms ease; }
.htmx-request.htmx-indicator,
.htmx-request .htmx-indicator { opacity: 1; }

.spin-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: currentColor;
}

.spin-icon {
  animation: spin 0.7s linear infinite;
  color: var(--accent);
}

.btn-primary .spin-icon,
.btn-danger .spin-icon { color: inherit; }

@keyframes spin {
  to { transform: rotate(360deg); }
}

@media (prefers-reduced-motion: reduce) {
  .spin-icon { animation: none; }
}

/* dim the tab content area while an htmx request targeting it is in flight */
#tab-content.htmx-request {
  opacity: 0.55;
  transition: opacity 150ms ease;
  pointer-events: none;
}

/* ---------- confirm modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
  animation: modal-fade 140ms ease;
}

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-5);
  width: 100%;
  max-width: 380px;
  animation: modal-pop 160ms cubic-bezier(0.2, 0.7, 0.3, 1);
}

@keyframes modal-pop {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  .modal-backdrop, .modal-card { animation: none; }
}

.modal-title {
  font-size: var(--text-base);
  font-weight: 700;
  margin: 0 0 var(--space-2);
}

.modal-message {
  color: var(--text-muted);
  font-size: var(--text-sm);
  margin: 0 0 var(--space-5);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
}

/* ---------- table search input ---------- */

.table-search {
  width: 100%;
  max-width: 280px;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: var(--text-sm);
  font-family: var(--font);
  font-weight: 500;
  margin-bottom: var(--space-4);
}

.table-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}

/* ---------- bulk action bar ---------- */

.bulk-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--accent-tint);
  color: var(--accent-tint-text);
  margin-bottom: var(--space-4);
  font-size: var(--text-sm);
  font-weight: 600;
}

.bulk-bar[hidden] { display: none; }

.bulk-bar form { display: inline-flex; align-items: center; gap: var(--space-2); }

.col-check { width: 1%; }

@media (max-width: 800px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: var(--space-4); }
}
