/* MailAI — Postal Tool */
/* Direction: compact, monochrome, tool-like. Borders-only depth. */
/* Accent: slate-blue (postal ink). Dark-mode native. */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --ink: #6b7fa3;
  --ink-bright: #8fa4c8;
  --ink-dim: #4e6080;
  --ink-ghost: rgba(107, 127, 163, 0.12);

  --stamp-red: #c9514b;
  --stamp-red-ghost: rgba(201, 81, 75, 0.14);
  --sort-grey: #6b7280;
  --sort-grey-ghost: rgba(107, 114, 128, 0.14);
  --archive-mute: #8b8fa3;
  --okay-green: #4b9e6b;
  --okay-green-ghost: rgba(75, 158, 107, 0.14);
  --warn-amber: #c89b4e;

  --bg: #0e1117;
  --bg-raised: #151921;
  --bg-input: #0b0e13;

  --fg: #c9ced6;
  --fg-secondary: #8b919e;
  --fg-muted: #5c6370;
  --fg-faint: #3b4252;

  --border: rgba(139, 145, 158, 0.10);
  --border-strong: rgba(139, 145, 158, 0.18);
  --border-subtle: rgba(139, 145, 158, 0.06);

  --radius: 6px;
  --radius-sm: 4px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'SF Mono', 'Cascadia Code', 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;

  --ease: cubic-bezier(0.2, 0, 0, 1);
  --speed: 120ms;
}

@media (prefers-color-scheme: light) {
  :root {
    --ink: #4e6080;
    --ink-bright: #3a5070;
    --ink-dim: #6b7fa3;
    --ink-ghost: rgba(78, 96, 128, 0.08);

    --stamp-red-ghost: rgba(201, 81, 75, 0.08);
    --sort-grey-ghost: rgba(107, 114, 128, 0.08);
    --okay-green-ghost: rgba(75, 158, 107, 0.08);

    --bg: #f6f7f9;
    --bg-raised: #ffffff;
    --bg-input: #eef0f3;

    --fg: #1a1d24;
    --fg-secondary: #5c6370;
    --fg-muted: #8b919e;
    --fg-faint: #c4c8d0;

    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.14);
    --border-subtle: rgba(0, 0, 0, 0.04);
  }
}

/* Reset + Base */
html { font-size: 14px; -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--fg);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: var(--ink-bright); text-decoration: none; }
a:hover { color: var(--fg); }

/* Shell */
.shell {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Nav — top bar, hairline bottom */
.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-inner {
  max-width: 640px;
  margin: 0 auto;
  padding: 0 16px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  font-size: 0.93rem;
  color: var(--fg);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand svg { color: var(--ink); }

.nav-links {
  display: flex;
  gap: 2px;
  list-style: none;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--fg-muted);
  font-size: 0.8rem;
  font-weight: 500;
  transition: color var(--speed) var(--ease), background var(--speed) var(--ease);
}

.nav-links a:hover { color: var(--fg-secondary); background: var(--ink-ghost); }
.nav-links a[aria-current="page"] { color: var(--ink-bright); background: var(--ink-ghost); }
.nav-links .logout:hover { color: var(--stamp-red); background: var(--stamp-red-ghost); }

/* Page title */
.page-title {
  padding: 24px 0 16px;
}

.page-title h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--fg);
  line-height: 1.2;
}

.page-title p {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: 2px;
}

/* Section label */
.label {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  padding: 12px 0 8px;
}

/* Email row — the sorted-mail signature */
.row {
  display: block;
  border-bottom: 1px solid var(--border-subtle);
  padding: 12px 0;
  transition: background var(--speed) var(--ease);
}

/* Left sorting tab — color strip via border-left */
.row--alert {
  border-left: 3px solid var(--stamp-red);
  padding-left: 12px;
  background: var(--stamp-red-ghost);
}

.row--delete {
  opacity: 0.4;
}

.row--archive {
  border-left: 3px solid var(--fg-faint);
  padding-left: 12px;
}

.row-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.row-subject {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--fg);
  line-height: 1.35;
  flex: 1;
  min-width: 0;
}

.row-badges {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  padding-top: 1px;
}

.pill {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 1px 6px;
  border-radius: 3px;
  line-height: 1.6;
}

.pill--alert { background: var(--stamp-red); color: #fff; }
.pill--delete { background: var(--fg-faint); color: var(--fg-secondary); }
.pill--archive { background: var(--sort-grey-ghost); color: var(--fg-muted); }
.pill--summarize { background: var(--ink-ghost); color: var(--ink-bright); }
.pill--urgent { background: var(--stamp-red); color: #fff; }
.pill--high { background: var(--warn-amber); color: #1a1d24; }
.pill--low { background: transparent; color: var(--fg-faint); border: 1px solid var(--border); }

.row-meta {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--fg-muted);
  margin-top: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.row-meta .sep { color: var(--fg-faint); }

.row-summary {
  font-size: 0.8rem;
  color: var(--fg-secondary);
  line-height: 1.5;
  margin-top: 6px;
}

.row-reason {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--fg-faint);
  margin-top: 4px;
  font-style: italic;
}

/* Digest — top summary */
.digest {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--fg);
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-raised);
  margin-bottom: 20px;
  line-height: 1.45;
}

/* Digest paragraphs — living summary */
.digest-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 20px;
}

.digest-p {
  border: 1px solid var(--border);
  border-left: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--bg-raised);
}

.digest-p-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.digest-p-cat {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-bright);
}

.digest-p-text {
  font-size: 0.8rem;
  color: var(--fg-secondary);
  line-height: 1.5;
}

.digest-p-dismiss {
  background: none;
  border: none;
  color: var(--fg-faint);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  transition: all var(--speed) var(--ease);
}

.digest-p-dismiss:hover {
  color: var(--fg-secondary);
  background: var(--ink-ghost);
}

/* Poll group — batch header */
.poll-group {
  margin-bottom: 16px;
}

.poll-group:last-child { margin-bottom: 0; }

.poll-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 2px;
}

.poll-label {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--fg-secondary);
  letter-spacing: 0.02em;
}

.poll-summary {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--fg-muted);
}

/* Audit line — single compact row per email */
.audit {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 3px 0;
  font-size: 0.75rem;
  line-height: 1.35;
  border-bottom: 1px solid var(--border-subtle);
}

.audit:last-child { border-bottom: none; }

.audit-action {
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink);
  flex-shrink: 0;
  width: 62px;
}

.audit--alert .audit-action { color: var(--stamp-red); }
.audit--delete .audit-action { color: var(--fg-faint); }
.audit--archive .audit-action { color: var(--sort-grey); }
.audit--delete { opacity: 0.5; }

.audit-subject {
  color: var(--fg);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.audit-sender {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--fg-muted);
  flex-shrink: 0;
  white-space: nowrap;
  display: none;
}

@media (min-width: 480px) {
  .audit-sender { display: block; }
}

/* Empty state */
.empty {
  text-align: center;
  padding: 48px 16px;
}

.empty svg { color: var(--fg-faint); margin-bottom: 12px; }

.empty h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--fg-secondary);
  margin-bottom: 4px;
}

.empty p {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-bottom: 12px;
}

.empty a { color: var(--ink-bright); font-weight: 500; font-size: 0.8rem; }

/* Auth pages (login, approve) */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.auth-box {
  width: 100%;
  max-width: 360px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  background: var(--bg-raised);
}

.auth-heading {
  text-align: center;
  margin-bottom: 24px;
}

.auth-heading h1 {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-top: 8px;
  color: var(--fg);
}

.auth-heading p {
  font-size: 0.8rem;
  color: var(--fg-muted);
  margin-top: 4px;
}

/* Forms */
label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--fg-muted);
  margin-bottom: 4px;
}

input[type="email"],
input[type="text"],
input[type="password"],
input[type="number"],
textarea {
  width: 100%;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--fg);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--speed) var(--ease);
  margin-bottom: 12px;
}

input:focus, textarea:focus {
  border-color: var(--ink);
}

textarea {
  resize: vertical;
  min-height: 72px;
  font-size: 0.8rem;
  line-height: 1.5;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-raised);
  color: var(--fg-secondary);
  cursor: pointer;
  transition: all var(--speed) var(--ease);
}

.btn:hover { border-color: var(--border-strong); color: var(--fg); }

.btn-ink {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.btn-ink:hover {
  background: var(--ink-dim);
  border-color: var(--ink-dim);
  color: #fff;
}

.btn-block { width: 100%; }

.btn-sm {
  font-size: 0.7rem;
  padding: 4px 10px;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--fg-muted);
}

.btn-ghost:hover {
  border-color: var(--stamp-red);
  color: var(--stamp-red);
  background: var(--stamp-red-ghost);
}

/* Toasts */
.toast {
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border: 1px solid var(--border);
}

.toast--error {
  background: var(--stamp-red-ghost);
  color: var(--stamp-red);
  border-color: var(--stamp-red);
}

.toast--success {
  background: var(--okay-green-ghost);
  color: var(--okay-green);
  border-color: var(--okay-green);
}

/* Account card (settings) */
.acct {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 8px;
  background: var(--bg-raised);
}

.acct-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.acct-email {
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--fg);
  display: flex;
  align-items: center;
  gap: 6px;
}

.acct-tag {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 500;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--ink-ghost);
  color: var(--ink-bright);
}

.acct-detail {
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--fg-muted);
  margin-top: 2px;
}

.acct-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.acct-rules {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.acct-rules summary {
  font-family: var(--mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
  list-style: none;
}

.acct-rules summary::-webkit-details-marker { display: none; }
.acct-rules summary::before { content: "\25b8 "; font-size: 0.65rem; }
.acct-rules details[open] summary::before { content: "\25be "; }

.acct-rules form { margin-top: 8px; }

/* Connect buttons */
.connect-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.connect-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--fg-secondary);
  background: var(--bg-raised);
  transition: all var(--speed) var(--ease);
}

.connect-btn:hover {
  border-color: var(--ink);
  color: var(--ink-bright);
}

/* IMAP form */
.imap-section { margin-top: 16px; }

.imap-section summary {
  font-family: var(--mono);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--fg-muted);
  cursor: pointer;
}

.imap-section form {
  margin-top: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--bg-raised);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 100px;
  gap: 12px;
}

/* Divider */
.divider {
  border: none;
  border-top: 1px solid var(--border-subtle);
  margin: 16px 0;
}

/* Admin stats */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  background: var(--bg-raised);
}

.stat-num {
  font-family: var(--mono);
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--ink-bright);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin-top: 2px;
}

/* Data table (admin) */
.dtable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-raised);
}

.dtable th {
  text-align: left;
  padding: 8px 12px;
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--fg-faint);
  border-bottom: 1px solid var(--border);
}

.dtable td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--fg-secondary);
}

.dtable tr:last-child td { border-bottom: none; }
.dtable td strong { color: var(--fg); font-weight: 600; }

/* Responsive */
@media (max-width: 480px) {
  html { font-size: 13px; }
  .topbar-inner { padding: 0 12px; }
  .shell { padding: 0 12px; }
  .nav-links a span { display: none; }
  .row-head { flex-direction: column; gap: 4px; }
  .row-badges { align-self: flex-start; }
  .acct-head { flex-direction: column; gap: 6px; }
  .acct-actions { align-self: flex-end; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 4px; }
}
