/* MailFlow design system — custom CSS, no external CDN required for layout & components.
 * Tailwind utilities can be layered on top in views, but the entire UI works without it.
 */

:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-2: #f1f3f9;
  --surface-3: #e9ecf3;
  --border: #e6e8ee;
  --border-strong: #d6dae4;
  --text: #0d1117;
  --muted: #5b6478;
  --muted-2: #8b93a7;
  --brand: #6366f1;
  --brand-2: #8b5cf6;
  --brand-soft: rgba(99, 102, 241, .12);
  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, .14);
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, .14);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .14);
  --info: #0891b2;
  --info-soft: rgba(8, 145, 178, .14);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
  --shadow: 0 4px 14px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .03);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .08), 0 2px 6px rgba(15, 23, 42, .04);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --sidebar-w: 248px;
  --header-h: 60px;
}
html.dark {
  --bg: #0a0d14;
  --surface: #11151f;
  --surface-2: #161b27;
  --surface-3: #1d2230;
  --border: #232a3a;
  --border-strong: #2f3849;
  --text: #e7eaf3;
  --muted: #97a0b6;
  --muted-2: #6c7593;
  --brand-soft: rgba(99, 102, 241, .18);
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 4px 14px rgba(0,0,0,.4), 0 1px 2px rgba(0,0,0,.25);
  --shadow-lg: 0 16px 36px rgba(0,0,0,.55), 0 2px 6px rgba(0,0,0,.35);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
code { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre { font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace; font-size: 12px; }

/* ====== APP SHELL ====== */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: var(--surface); border-right: 1px solid var(--border);
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column;
  z-index: 30;
}
.sidebar-brand {
  padding: 14px 16px; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #6366f1, #d946ef);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 16px;
  box-shadow: 0 4px 14px rgba(99, 102, 241, .35);
}
.sidebar-brand .name { font-weight: 700; letter-spacing: -.01em; }
.sidebar-brand .sub { font-size: 11px; color: var(--muted); }

.nav { padding: 12px 8px; flex: 1; overflow-y: auto; }
.nav-section { padding: 14px 10px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted-2); }
.nav-link {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px; color: var(--muted);
  font-weight: 500; font-size: 13.5px; transition: all .12s ease;
  white-space: nowrap;
}
.nav-link svg { width: 16px; height: 16px; flex-shrink: 0; opacity: .85; }
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-soft); color: var(--brand); }
.nav-link.active svg { color: var(--brand); opacity: 1; }
.nav-link .pill {
  margin-left: auto; font-size: 10.5px; padding: 1px 6px; border-radius: 999px;
  background: var(--surface-3); color: var(--muted);
}
.nav-link.active .pill { background: var(--brand); color: #fff; }

.sidebar-footer { padding: 10px; border-top: 1px solid var(--border); }
.user-card {
  display: flex; align-items: center; gap: 10px; padding: 8px;
  border-radius: 10px; transition: background .12s;
}
.user-card:hover { background: var(--surface-2); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #d946ef);
  color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 12px;
}
.user-meta { flex: 1; min-width: 0; }
.user-meta .n { font-size: 13px; font-weight: 600; line-height: 1.2; }
.user-meta .e { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ====== MAIN ====== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--header-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 24px;
  position: sticky; top: 0; z-index: 20;
  backdrop-filter: saturate(1.4) blur(8px);
}
.topbar h1 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin: 0; }
.topbar .crumbs { color: var(--muted); font-size: 13px; }
.topbar-spacer { flex: 1; }
.search {
  flex: 1; max-width: 480px; position: relative;
}
.search input {
  width: 100%; height: 36px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 0 14px 0 36px; font-size: 13.5px; color: var(--text);
}
.search input:focus { outline: none; border-color: var(--brand); background: var(--surface); }
.search svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; color: var(--muted); }
.search kbd {
  position: absolute; right: 10px; top: 8px;
  font-size: 11px; padding: 1px 6px; border-radius: 6px;
  background: var(--surface-3); color: var(--muted); border: 1px solid var(--border);
  font-family: inherit;
}
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); transition: all .12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }
.icon-btn .dot {
  position: absolute; top: -3px; right: -3px;
  width: 8px; height: 8px; background: var(--danger); border-radius: 50%;
  border: 2px solid var(--surface);
}
.content { padding: 24px; flex: 1; }

/* ====== UI PRIMITIVES ====== */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-padded { padding: 18px; }
.card-h { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.card-h h2 { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }
.card-h .sub { color: var(--muted); font-size: 12px; }
.card-b { padding: 18px; }

.btn, .btn-primary, .btn-ghost, .btn-danger, .btn-soft {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500;
  border: 1px solid transparent; transition: all .12s; line-height: 1; height: 36px;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: #4f46e5; }
.btn-ghost { color: var(--text); border-color: var(--border); background: var(--surface); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-soft { background: var(--brand-soft); color: var(--brand); }
.btn-soft:hover { background: rgba(99, 102, 241, .22); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; height: 30px; }

.input, .select, .textarea {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 9px 12px; font-size: 13.5px; color: var(--text);
  transition: border-color .12s, background .12s; font-family: inherit;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft);
}
.textarea { resize: vertical; min-height: 96px; }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500;
  background: var(--surface-3); color: var(--muted);
}
.badge.dot::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }

table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl thead th {
  text-align: left; padding: 10px 14px; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
table.tbl tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); }
table.tbl tbody tr:hover td { background: var(--surface-2); }
table.tbl tbody tr:last-child td { border-bottom: none; }

.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; position: relative; overflow: hidden;
}
.kpi .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.kpi .value { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin-top: 4px; }
.kpi .delta { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; margin-top: 6px; }
.kpi .delta.up { color: var(--success); }
.kpi .delta.down { color: var(--danger); }
.kpi .icon {
  position: absolute; top: 14px; right: 14px;
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}
.kpi .icon svg { width: 18px; height: 18px; }
.kpi .spark { margin-top: 10px; height: 36px; }

.progress { height: 6px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }
.progress.success > span { background: var(--success); }
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ====== UTILITIES ====== */
.row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.row > * { min-width: 0; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.flex { display: flex; }
.flex-col { display: flex; flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.justify-end { justify-content: flex-end; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-5 { gap: 20px; } .gap-6 { gap: 24px; }
.flex-1 { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.text-xs { font-size: 11.5px; } .text-sm { font-size: 13px; } .text-base { font-size: 14px; }
.text-lg { font-size: 16px; } .text-xl { font-size: 18px; } .text-2xl { font-size: 22px; } .text-3xl { font-size: 28px; }
.font-mono { font-family: 'JetBrains Mono', ui-monospace, monospace; }
.font-medium { font-weight: 500; } .font-semibold { font-weight: 600; } .font-bold { font-weight: 700; }
.text-muted { color: var(--muted); } .text-muted-2 { color: var(--muted-2); }
.text-success { color: var(--success); } .text-danger { color: var(--danger); } .text-warn { color: var(--warn); } .text-info { color: var(--info); }
.text-brand { color: var(--brand); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.uppercase { text-transform: uppercase; letter-spacing: .04em; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full { width: 100%; } .h-full { height: 100%; }
.mb-0{margin-bottom:0}.mb-1{margin-bottom:4px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mb-5{margin-bottom:20px}.mb-6{margin-bottom:24px}
.mt-0{margin-top:0}.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mt-5{margin-top:20px}.mt-6{margin-top:24px}
.mr-1{margin-right:4px}.mr-2{margin-right:8px}.mr-3{margin-right:12px}
.ml-auto { margin-left: auto; }
.p-0{padding:0}.p-2{padding:8px}.p-3{padding:12px}.p-4{padding:16px}.p-5{padding:20px}.p-6{padding:24px}
.px-2{padding-left:8px;padding-right:8px}.px-3{padding-left:12px;padding-right:12px}.px-4{padding-left:16px;padding-right:16px}
.py-1{padding-top:4px;padding-bottom:4px}.py-2{padding-top:8px;padding-bottom:8px}.py-3{padding-top:12px;padding-bottom:12px}.py-4{padding-top:16px;padding-bottom:16px}
.rounded { border-radius: 8px; } .rounded-lg { border-radius: 12px; } .rounded-full { border-radius: 999px; }

.grid { display: grid; gap: 16px; }
.g-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.g-12 { grid-template-columns: 2fr 1fr; }
.g-21 { grid-template-columns: 1fr 2fr; }
@media (max-width: 1100px) { .g-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .g-12, .g-21 { grid-template-columns: 1fr; } .g-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 720px) { .g-2, .g-3, .g-4 { grid-template-columns: 1fr; } }

/* Activity feed */
.feed { padding: 8px 0; }
.feed-item { display: flex; align-items: center; gap: 10px; padding: 8px 18px; font-size: 13px; border-left: 2px solid transparent; }
.feed-item:hover { background: var(--surface-2); }
.feed-item .ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.feed-item .ico svg { width: 14px; height: 14px; }
.feed-item .ico.open { background: var(--success-soft); color: var(--success); }
.feed-item .ico.click { background: var(--info-soft); color: var(--info); }
.feed-item .ico.reply { background: var(--brand-soft); color: var(--brand); }
.feed-item .ico.bounce { background: var(--danger-soft); color: var(--danger); }
.feed-item .meta { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.feed-item .body { flex: 1; min-width: 0; }
.feed-item .time { color: var(--muted-2); font-size: 11px; }

/* Sender health rows */
.sender-row {
  display: grid; grid-template-columns: 1fr auto auto;
  gap: 12px; align-items: center;
  padding: 10px 0; border-bottom: 1px solid var(--border);
}
.sender-row:last-child { border-bottom: 0; }
.sender-row .name { font-weight: 500; font-size: 13px; }
.sender-row .email { color: var(--muted); font-size: 12px; }

/* Toast */
.toast-wrap { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); font-size: 13px; min-width: 240px;
  border-left: 3px solid var(--brand);
  animation: slidein .25s ease;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
.toast.info { border-left-color: var(--info); }
@keyframes slidein { from { transform: translateY(-8px); opacity: 0 } to { transform: none; opacity: 1 } }

/* Donut chart placeholder */
.donut { position: relative; width: 140px; height: 140px; }
.donut svg { transform: rotate(-90deg); }
.donut .label { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; }
.donut .label .v { font-size: 24px; font-weight: 700; }
.donut .label .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }

/* Empty state */
.empty {
  text-align: center; padding: 40px 20px; color: var(--muted);
}
.empty .ico {
  width: 48px; height: 48px; margin: 0 auto 12px;
  border-radius: 12px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand);
}

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(80% 60% at 50% 0%, rgba(99,102,241,.15), transparent 60%), var(--bg);
}
.auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px; max-width: 440px; width: 100%; box-shadow: var(--shadow-lg); }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--surface-3); border-radius: 999px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Mobile */
.menu-btn { display: none; }
@media (max-width: 920px) {
  .sidebar { position: fixed; left: -260px; transition: left .2s; }
  .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
  .menu-btn { display: grid; }
  .content { padding: 16px; }
  .topbar { padding: 0 16px; }
  .search { display: none; }
}

/* Print */
@media print { .sidebar, .topbar, .btn, .btn-primary, .btn-ghost { display: none !important; } }
