/*  Mail Processor — design system
    A cohesive dark interface optimised for ops dashboards. Inter for type,
    a 60-color scale built around three accents (blue / violet / teal),
    glassmorphism cards on a subtle gradient field, and motion-safe
    transitions for the few things that actually move (sidebar, toasts).
*/

/* ── Dark theme (default) ──────────────────────────────────────────────── */

:root,
:root[data-theme="dark"] {
  --c-bg-0:    #07090d;
  --c-bg-1:    #0d111a;
  --c-bg-2:    #131826;
  --c-surface: rgba(22, 28, 42, 0.65);
  --c-surface-strong: rgba(28, 35, 52, 0.85);
  --c-input-bg: rgba(7, 9, 13, 0.6);
  --c-border:  rgba(120, 140, 180, 0.12);
  --c-border-strong: rgba(120, 140, 180, 0.22);
  --c-text:    #e8ecf6;
  --c-text-dim:#9aa3b8;
  --c-text-faint: #6b748b;

  --c-accent:        #6c8cff;
  --c-accent-strong: #8b9dff;
  --c-violet:        #a06cff;
  --c-teal:          #2bd4c0;
  --c-success:       #34d399;
  --c-warning:       #fbbf24;
  --c-danger:        #f87171;

  --grad-brand: linear-gradient(135deg, #6c8cff 0%, #a06cff 60%, #2bd4c0 100%);
  --grad-bg:    radial-gradient(1200px 600px at 10% -10%, rgba(108,140,255,.18), transparent 60%),
                radial-gradient(1000px 600px at 110% 10%, rgba(160,108,255,.14), transparent 55%),
                radial-gradient(800px 800px at 50% 110%, rgba(43,212,192,.10), transparent 60%);

  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow-md: 0 8px 24px rgba(0,0,0,.45), 0 2px 4px rgba(0,0,0,.3);
  --shadow-lg: 0 24px 60px rgba(0,0,0,.55), 0 4px 8px rgba(0,0,0,.35);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 28px;

  color-scheme: dark;
}

/* ── Light theme ────────────────────────────────────────────────────────── */

:root[data-theme="light"] {
  --c-bg-0:    #f6f7fb;
  --c-bg-1:    #eef0f7;
  --c-bg-2:    #e6e9f3;
  --c-surface: rgba(255, 255, 255, 0.85);
  --c-surface-strong: rgba(255, 255, 255, 0.96);
  --c-input-bg: #ffffff;
  --c-border:  rgba(15, 23, 42, 0.08);
  --c-border-strong: rgba(15, 23, 42, 0.18);
  --c-text:    #0f172a;
  --c-text-dim:#475569;
  --c-text-faint: #94a3b8;

  --grad-bg:    radial-gradient(1200px 600px at 10% -10%, rgba(108,140,255,.10), transparent 60%),
                radial-gradient(1000px 600px at 110% 10%, rgba(160,108,255,.07), transparent 55%),
                radial-gradient(800px 800px at 50% 110%, rgba(43,212,192,.06), transparent 60%);

  --shadow-sm: 0 1px 2px rgba(15,23,42,.06);
  --shadow-md: 0 8px 24px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.04);
  --shadow-lg: 0 24px 60px rgba(15,23,42,.12), 0 4px 8px rgba(15,23,42,.06);

  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  background: var(--c-bg-0);
  background-image: var(--grad-bg);
  background-attachment: fixed;
  color: var(--c-text);
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-feature-settings: 'cv02','cv03','cv04','cv11';
  font-size: 14px;
  line-height: 1.5;
  margin: 0;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--c-accent-strong); text-decoration: none; }
a:hover { color: var(--c-text); }
hr { border: 0; border-top: 1px solid var(--c-border); margin: 1rem 0; }

/* ── Layout ─────────────────────────────────────────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 1.25rem 0.75rem;
  background: linear-gradient(180deg, rgba(13,17,26,.92), rgba(7,9,13,.92));
  border-right: 1px solid var(--c-border);
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.75rem 1rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  font-size: 1rem;
  color: var(--c-text);
}
.brand .logo {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--grad-brand);
  display: grid; place-items: center;
  color: white;
  box-shadow: 0 8px 24px rgba(108,140,255,.35);
  flex: 0 0 auto;
}
.brand .theme-toggle {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: transparent;
  border: 1px solid var(--c-border);
  color: var(--c-text-dim);
  display: grid; place-items: center;
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s, transform .15s;
  flex: 0 0 auto;
}
.brand .theme-toggle:hover {
  background: rgba(108,140,255,.10);
  color: var(--c-text);
  border-color: var(--c-border-strong);
}
.brand .theme-toggle:active { transform: scale(0.95); }
.brand .theme-toggle i { width: 16px; height: 16px; }
.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 0.25rem; }
.nav-section { color: var(--c-text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; padding: 0.75rem 0.75rem 0.4rem; }
.nav a {
  display: flex; align-items: center; gap: 0.7rem;
  color: var(--c-text-dim);
  padding: 0.55rem 0.75rem;
  border-radius: var(--r-sm);
  transition: background .15s, color .15s, transform .15s;
}
.nav a:hover { background: rgba(255,255,255,.04); color: var(--c-text); }
.nav a.active {
  background: linear-gradient(135deg, rgba(108,140,255,.18), rgba(160,108,255,.10));
  color: var(--c-text);
  border: 1px solid rgba(108,140,255,.28);
}
.nav a.active::before {
  content: '';
  width: 3px; height: 18px; border-radius: 3px; margin-right: 4px;
  background: var(--grad-brand);
}
.nav .badge { margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 999px; background: rgba(255,255,255,.08); color: var(--c-text-dim); }

.user-card {
  margin-top: auto;
  padding: 0.75rem;
  border-radius: var(--r-md);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  display: flex; align-items: center; gap: 0.6rem;
}
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--grad-brand); display: grid; place-items: center; color: white; font-weight: 600; font-size: 12px; }
.user-card .meta { display: flex; flex-direction: column; line-height: 1.1; }
.user-card .meta .name { font-size: 13px; }
.user-card .meta .role { font-size: 11px; color: var(--c-text-faint); text-transform: capitalize; }
.user-card a { margin-left: auto; color: var(--c-text-dim); }

.main { padding: 1.5rem 2rem 4rem; max-width: 1500px; }
.page-head {
  display: flex; align-items: center; gap: 1rem;
  margin-bottom: 1.25rem;
}
.page-head h1 { font-size: 1.6rem; font-weight: 600; letter-spacing: -0.02em; margin: 0; }
.page-head .subtitle { color: var(--c-text-dim); font-size: 0.9rem; }
.page-head .actions { margin-left: auto; display: flex; gap: 0.5rem; }

/* ── Cards ──────────────────────────────────────────────────────────────── */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  padding: 1.25rem 1.4rem;
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 0.75rem;
}
.card-head h3 { font-size: 0.95rem; font-weight: 600; margin: 0; }
.card-head .hint { color: var(--c-text-faint); font-size: 12px; }
.card.hover:hover { border-color: var(--c-border-strong); transform: translateY(-1px); transition: transform .2s, border-color .2s; }

.stat {
  position: relative; overflow: hidden;
  padding: 1.15rem 1.25rem;
}
.stat .label { color: var(--c-text-faint); font-size: 11px; letter-spacing: .12em; text-transform: uppercase; }
.stat .value { font-size: 1.9rem; font-weight: 600; letter-spacing: -0.02em; margin-top: 6px; }
.stat .delta { font-size: 12px; color: var(--c-text-dim); margin-top: 4px; }
.stat .glyph {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border-radius: 10px;
  background: rgba(108,140,255,.15);
  display: grid; place-items: center;
  color: var(--c-accent-strong);
}
.stat.violet .glyph { background: rgba(160,108,255,.15); color: #c7b1ff; }
.stat.teal   .glyph { background: rgba(43,212,192,.15);  color: #6dead8; }
.stat.warn   .glyph { background: rgba(251,191,36,.15);  color: var(--c-warning); }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  font: inherit; font-weight: 500; font-size: 13px;
  padding: 0.5rem 0.85rem;
  border-radius: var(--r-sm);
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface-strong);
  color: var(--c-text);
  cursor: pointer;
  transition: filter .15s, transform .15s, background .15s, border-color .15s;
}
.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--grad-brand); border: 0; color: #fff; box-shadow: 0 8px 20px rgba(108,140,255,.35); }
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { background: transparent; border: 1px solid var(--c-border); }
.btn-danger { background: linear-gradient(135deg, #f87171, #c2410c); border: 0; color: #fff; }
.btn-success { background: linear-gradient(135deg, #34d399, #059669); border: 0; color: #fff; }
.btn-sm { padding: 0.32rem 0.6rem; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

/* ── Forms ──────────────────────────────────────────────────────────────── */

label { color: var(--c-text-dim); font-size: 12px; margin-bottom: 4px; display: block; }

/* Catch every text-flavoured input — including <input> with no type attr. */
.input,
input,
select,
textarea {
  width: 100%;
  background: var(--c-input-bg);
  color: var(--c-text);
  border: 1px solid var(--c-border-strong);
  border-radius: var(--r-sm);
  padding: 0.55rem 0.75rem;
  font: inherit;
  font-size: 13px;
  transition: border-color .15s, box-shadow .15s;
}

/* Reset for inputs that aren't text fields. */
input[type=checkbox],
input[type=radio],
input[type=submit],
input[type=button],
input[type=reset],
input[type=file],
input[type=color],
input[type=range] {
  width: auto;
  background: transparent;
  border: 0;
  padding: 0;
}

.input:focus, input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--c-accent);
  box-shadow: 0 0 0 3px rgba(108,140,255,.15);
}

input::placeholder, textarea::placeholder {
  color: var(--c-text-faint);
}

/* Make native date/time pickers + dropdown chevrons match the theme. */
input[type=date]::-webkit-calendar-picker-indicator,
input[type=time]::-webkit-calendar-picker-indicator,
input[type=datetime-local]::-webkit-calendar-picker-indicator {
  filter: invert(var(--icon-invert, 0.85));
  cursor: pointer;
}
:root[data-theme="light"] input[type=date]::-webkit-calendar-picker-indicator,
:root[data-theme="light"] input[type=time]::-webkit-calendar-picker-indicator {
  filter: none;
}

/* Selected option in a select stays readable in both themes. */
select option { background: var(--c-bg-1); color: var(--c-text); }
textarea { resize: vertical; min-height: 90px; }
.form-row { display: grid; grid-template-columns: repeat(12, 1fr); gap: 0.75rem; }
.form-row .col-12 { grid-column: span 12; }
.form-row .col-9 { grid-column: span 9; }
.form-row .col-8 { grid-column: span 8; }
.form-row .col-6 { grid-column: span 6; }
.form-row .col-4 { grid-column: span 4; }
.form-row .col-3 { grid-column: span 3; }

.toggle { display: inline-flex; align-items: center; gap: 0.5rem; }
.toggle input[type=checkbox] {
  appearance: none; width: 36px; height: 20px; border-radius: 999px;
  background: rgba(255,255,255,.1); border: 1px solid var(--c-border-strong);
  position: relative; cursor: pointer; transition: background .2s;
}
.toggle input:checked { background: var(--grad-brand); border-color: transparent; }
.toggle input::after {
  content: ''; position: absolute;
  width: 14px; height: 14px; top: 2px; left: 2px;
  background: white; border-radius: 50%; transition: left .2s;
}
.toggle input:checked::after { left: 18px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.table-wrap { overflow-x: auto; border-radius: var(--r-md); border: 1px solid var(--c-border); }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--c-surface); }
table.tbl th {
  text-align: left;
  font-weight: 500;
  color: var(--c-text-faint);
  font-size: 11px;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--c-border);
  background: rgba(255,255,255,.025);
}
table.tbl td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--c-border);
  color: var(--c-text);
}
table.tbl tr:last-child td { border-bottom: 0; }
table.tbl tr:hover td { background: rgba(255,255,255,.025); }
.tdim { color: var(--c-text-dim); }
.tfaint { color: var(--c-text-faint); }
.mono { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ── Badges + status pills ──────────────────────────────────────────────── */

.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(255,255,255,.06);
  color: var(--c-text);
  border: 1px solid var(--c-border);
}
.pill-success { background: rgba(52,211,153,.14); color: #6ee7b7; border-color: rgba(52,211,153,.3); }
.pill-warning { background: rgba(251,191,36,.14); color: #fde68a; border-color: rgba(251,191,36,.3); }
.pill-danger  { background: rgba(248,113,113,.14); color: #fca5a5; border-color: rgba(248,113,113,.3); }
.pill-accent  { background: rgba(108,140,255,.14); color: #a8b9ff; border-color: rgba(108,140,255,.3); }
.pill-violet  { background: rgba(160,108,255,.14); color: #cdaeff; border-color: rgba(160,108,255,.3); }
.pill-teal    { background: rgba(43,212,192,.14);  color: #6dead8; border-color: rgba(43,212,192,.3); }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-up { background: #34d399; box-shadow: 0 0 0 4px rgba(52,211,153,.18); }
.dot-down { background: #f87171; box-shadow: 0 0 0 4px rgba(248,113,113,.18); }

/* ── Alerts ─────────────────────────────────────────────────────────────── */

.alert {
  border-radius: var(--r-md);
  padding: 0.85rem 1rem;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  font-size: 13px;
}
.alert-info { border-color: rgba(108,140,255,.3); background: rgba(108,140,255,.08); }
.alert-warn { border-color: rgba(251,191,36,.3); background: rgba(251,191,36,.08); }
.alert-error { border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.08); }

/* ── Help toggle ────────────────────────────────────────────────────────── */

.help {
  margin: 0.5rem 0 1rem;
}
.help summary {
  list-style: none;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 0.4rem;
  color: var(--c-text-dim);
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.03);
  border: 1px dashed var(--c-border-strong);
  user-select: none;
}
.help summary::-webkit-details-marker { display: none; }
.help[open] summary { background: rgba(108,140,255,.10); color: var(--c-text); border-style: solid; border-color: rgba(108,140,255,.3); }
.help-body {
  margin-top: 0.5rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--c-border);
  background: rgba(255,255,255,.02);
  border-radius: var(--r-md);
  color: var(--c-text-dim);
  font-size: 13px;
  line-height: 1.6;
}
.help-body code { background: rgba(108,140,255,.12); color: #b9c8ff; padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* ── Login ──────────────────────────────────────────────────────────────── */

.auth-shell {
  min-height: 100vh; display: grid; place-items: center;
  background-image: var(--grad-bg);
}
.auth-card {
  width: 100%; max-width: 420px;
  background: var(--c-surface-strong);
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
}
.auth-card h2 { margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.auth-card p.muted { color: var(--c-text-dim); margin: 0 0 1.5rem; }

/* ── Dashboard widgets ──────────────────────────────────────────────────── */

.grid-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }

.bar { height: 8px; border-radius: 4px; background: rgba(255,255,255,.05); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--grad-brand); }

.list-clean { list-style: none; padding: 0; margin: 0; }
.list-clean li { display: flex; gap: 0.6rem; padding: 6px 0; border-bottom: 1px solid var(--c-border); align-items: center; }
.list-clean li:last-child { border-bottom: 0; }

/* ── Tabs ───────────────────────────────────────────────────────────────── */

.tabs {
  display: flex; gap: 4px;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 0;
}
.tabs a {
  padding: 0.6rem 0.9rem;
  color: var(--c-text-dim);
  border-bottom: 2px solid transparent;
  font-size: 13px;
}
.tabs a.active { color: var(--c-text); border-bottom-color: var(--c-accent); }
.tabs a:hover { color: var(--c-text); }

/* ── Misc / utility ─────────────────────────────────────────────────────── */

.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 0.5rem; } .gap-2 { gap: 1rem; } .gap-3 { gap: 1.5rem; }
.grow { flex: 1; }
.between { justify-content: space-between; }
.middle { align-items: center; }
.muted { color: var(--c-text-dim); }
.faint { color: var(--c-text-faint); }
.right { text-align: right; }
.mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.text-xs { font-size: 11px; } .text-sm { font-size: 12px; } .text-lg { font-size: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.w-30ch { max-width: 30ch; } .w-40ch { max-width: 40ch; } .w-20ch { max-width: 20ch; }
.copy { cursor: copy; }
.hidden { display: none !important; }

/* Pagination */
.pagination { display: inline-flex; gap: 4px; margin-top: 1rem; }
.pagination a, .pagination span {
  padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--c-border);
  color: var(--c-text-dim); background: var(--c-surface);
  font-size: 12px;
}
.pagination a:hover { color: var(--c-text); }
.pagination span.current { color: var(--c-text); border-color: var(--c-accent); background: rgba(108,140,255,.1); }

/* HTMX indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-flex; }
.htmx-request.htmx-indicator { display: inline-flex; }

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; transform: translateX(-100%); transition: transform .25s; z-index: 50; width: 248px; }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 1rem; }
}
