:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --line-strong: #d1d5db;
  --accent: #2563eb;
  --accent-soft: #eff6ff;
  --green: #047857;
  --green-soft: #ecfdf5;
  --amber: #b45309;
  --amber-soft: #fffbeb;
  --red: #b91c1c;
  --red-soft: #fef2f2;
  --sidebar: #0b0d10;
  --sidebar-ink: #e5e7eb;
  --sidebar-muted: #8b93a1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; }
pre, code { font-family: var(--mono); }

.app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  flex: 0 0 248px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  padding: 4px 8px 22px;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: linear-gradient(140deg, #3b82f6, #1d4ed8);
  border-radius: 9px;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-name { font-weight: 650; letter-spacing: -0.01em; font-size: 15px; }
.brand-sub { display: block; font-size: 10.5px; color: var(--sidebar-muted); font-weight: 400; letter-spacing: 0.02em; margin-top: 1px; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-section {
  font-size: 10px; text-transform: uppercase; letter-spacing: 0.09em;
  color: #6b7280; padding: 16px 10px 6px;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--sidebar-muted); font-weight: 500; font-size: 13.5px;
  text-decoration: none;
}
.nav a:hover { background: rgba(255,255,255,0.05); color: #fff; text-decoration: none; }
.nav a.active { background: rgba(255,255,255,0.09); color: #fff; }
.nav a .nav-icon { width: 16px; height: 16px; opacity: 0.8; flex: 0 0 16px; }
.nav a.active .nav-icon { opacity: 1; }
.nav-badge {
  margin-left: auto; font-size: 10px; font-weight: 600;
  background: rgba(37, 99, 235, 0.25); color: #93c5fd;
  padding: 1px 6px; border-radius: 999px;
}

.sidebar-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,0.07); padding-top: 14px; }
.sidebar-user { display: flex; align-items: center; gap: 9px; padding: 6px 8px 10px; }
.avatar {
  width: 30px; height: 30px; border-radius: 8px;
  background: #1f2937; color: #cbd5e1;
  display: grid; place-items: center; font-size: 11px; font-weight: 600;
  flex: 0 0 30px;
}
.sidebar-user .meta { min-width: 0; }
.sidebar-user .name { color: #f3f4f6; font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .email { color: var(--sidebar-muted); font-size: 10.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-actions { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 0 4px; }
.link-button {
  background: none; border: 0; color: var(--sidebar-muted); cursor: pointer;
  font-size: 11.5px; padding: 5px 6px; border-radius: 6px;
}
.link-button:hover { color: #fff; background: rgba(255,255,255,0.06); }
.lang-switch { color: var(--sidebar-muted); font-size: 11.5px; padding: 5px 6px; border-radius: 6px; }
.lang-switch:hover { color: #fff; background: rgba(255,255,255,0.06); text-decoration: none; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 58px; display: flex; align-items: center; gap: 12px;
  padding: 0 28px; border-bottom: 1px solid var(--line);
  background: rgba(255,255,255,0.78); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 20;
}
.topbar .crumb { color: var(--muted); font-size: 12.5px; }
.topbar .crumb strong { color: var(--ink); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; cursor: pointer; }
.content { padding: 28px; max-width: 1240px; width: 100%; margin: 0 auto; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 22px; letter-spacing: -0.02em; font-weight: 650; }
.page-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; }

/* ---------- Cards & stats ---------- */
.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }
.card-head {
  padding: 15px 18px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.card-head h2 { margin: 0; font-size: 13.5px; font-weight: 650; }
.card-head .sub { color: var(--muted); font-size: 12px; }
.card-body { padding: 18px; }
.card-body.tight { padding: 0; }
.card-foot { padding: 12px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat .label { color: var(--muted); font-size: 12px; display: flex; align-items: center; gap: 6px; }
.stat .value { font-size: 26px; font-weight: 650; letter-spacing: -0.03em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat .hint { color: var(--muted); font-size: 11px; margin-top: 2px; }
.stat .dot { width: 6px; height: 6px; border-radius: 99px; background: var(--accent); }
.dot.green { background: var(--green); } .dot.amber { background: var(--amber); } .dot.red { background: var(--red); }

.grid-2 { display: grid; grid-template-columns: 1.55fr 1fr; gap: 18px; align-items: start; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }

.chart { display: flex; align-items: flex-end; gap: 8px; height: 150px; padding: 4px 2px 0; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 7px; height: 100%; justify-content: flex-end; }
.chart .bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; }
.chart .bar {
  width: 100%; min-height: 3px; border-radius: 5px 5px 2px 2px;
  background: linear-gradient(180deg, #3b82f6, #2563eb);
  opacity: 0.9;
}
.chart .bar.zero { background: #e5e7eb; }
.chart .cap { font-size: 10.5px; color: var(--muted); }
.chart .num { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; background: #fafafa; white-space: nowrap; }
tbody tr:hover { background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
td { font-size: 13px; }
td .sub { display: block; color: var(--muted); font-size: 11.5px; margin-top: 2px; }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
tr.clickable { cursor: pointer; }
.subject { font-weight: 550; color: var(--ink); }
.truncate { max-width: 380px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mail-table .mail-from { font-weight: 500; }
.mail-table .mail-unread .mail-from,
.mail-table .mail-unread .subject { font-weight: 700; color: var(--ink); }
.mail-table .mail-unread { background: #fbfdff; }
.mail-table .mail-unread:hover { background: #f5f9ff; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.01em;
  border: 1px solid transparent; white-space: nowrap;
}
.badge::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.badge.sent, .badge.verified, .badge.received, .badge.delivered, .badge.found { background: var(--green-soft); color: var(--green); border-color: #a7f3d0; }
.badge.queued, .badge.sending, .badge.pending { background: var(--amber-soft); color: var(--amber); border-color: #fde68a; }
.badge.failed, .badge.bounced, .badge.missing { background: var(--red-soft); color: var(--red); border-color: #fecaca; }
.badge.canceled, .badge.suppressed { background: #f3f4f6; color: #4b5563; border-color: #e5e7eb; }
.badge.blue { background: var(--accent-soft); color: #1d4ed8; border-color: #bfdbfe; }
.badge.plain::before { display: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  border: 1px solid var(--line-strong); background: #fff; color: var(--ink);
  height: 34px; padding: 0 13px; border-radius: 8px;
  font-size: 12.5px; font-weight: 550; cursor: pointer; text-decoration: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { background: #f9fafb; text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.primary:hover { background: #1f2937; }
.btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.accent:hover { background: #1d4ed8; }
.btn.danger { color: var(--red); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: #f3f4f6; color: var(--ink); }
.btn.sm { height: 28px; padding: 0 9px; font-size: 11.5px; border-radius: 7px; }
.btn.icon { width: 32px; padding: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Forms ---------- */
.form-grid { display: grid; gap: 13px; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: #374151; }
.field .help { font-size: 11px; color: var(--muted); }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid var(--line-strong); background: #fff;
  color: var(--ink); border-radius: 8px; padding: 8px 10px; height: 36px;
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.input { height: auto; min-height: 84px; resize: vertical; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12); }
.input::placeholder { color: #9ca3af; }
.input.mono { font-family: var(--mono); font-size: 12px; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, #6b7280 50%), linear-gradient(135deg, #6b7280 50%, transparent 50%); background-position: calc(100% - 15px) 15px, calc(100% - 10px) 15px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline-form .input { width: auto; min-width: 220px; }
.checkbox { display: flex; align-items: flex-start; gap: 7px; font-size: 12.5px; color: #374151; }
.checkbox input { margin-top: 2px; }

/* ---------- Flash ---------- */
.flash {
  display: flex; align-items: flex-start; gap: 9px;
  padding: 11px 14px; border-radius: 9px; margin-bottom: 16px;
  font-size: 12.5px; border: 1px solid; animation: fadeIn 0.18s ease;
}
.flash.ok { background: var(--green-soft); border-color: #a7f3d0; color: #065f46; }
.flash.err { background: var(--red-soft); border-color: #fecaca; color: #991b1b; }
.flash .x { margin-left: auto; background: none; border: 0; cursor: pointer; color: currentColor; opacity: 0.55; padding: 0 2px; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-2px); } to { opacity: 1; transform: none; } }

/* ---------- Code / secret ---------- */
.secret {
  display: flex; gap: 8px; align-items: center;
  background: #f9fafb; border: 1px dashed var(--line-strong);
  border-radius: 8px; padding: 8px 10px;
  font-family: var(--mono); font-size: 12px; word-break: break-all;
}
.secret code { flex: 1; min-width: 0; }
.code {
  background: #0f172a; color: #e2e8f0; border-radius: 10px;
  padding: 14px 16px; overflow: auto; font-size: 12px; line-height: 1.6;
  font-family: var(--mono); white-space: pre;
}
.code.small { padding: 10px 12px; font-size: 11.5px; }
.kbd { font-family: var(--mono); font-size: 11.5px; background: #f3f4f6; border: 1px solid var(--line); border-bottom-width: 2px; padding: 1px 6px; border-radius: 5px; }

/* ---------- Detail ---------- */
.detail-grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 12.5px; }
.kv .k { color: var(--muted); }
.kv .v { word-break: break-word; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); padding: 0 12px; overflow-x: auto; }
.tab {
  border: 0; background: none; padding: 11px 10px 10px; margin-bottom: -1px;
  color: var(--muted); font-size: 12.5px; font-weight: 550; cursor: pointer;
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.tab-panel { display: none; padding: 16px 18px; }
.tab-panel.active { display: block; }
.preview-frame { width: 100%; height: 460px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
pre.body-view {
  margin: 0; background: #f9fafb; border: 1px solid var(--line);
  border-radius: 8px; padding: 13px; overflow: auto; max-height: 460px;
  font-size: 11.8px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
}
.raw-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.event-list { display: flex; flex-direction: column; }
.event-item { display: flex; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.event-item:last-child { border-bottom: 0; }
.event-dot { width: 8px; height: 8px; border-radius: 99px; background: var(--accent); margin-top: 7px; flex: 0 0 8px; }
.event-item .event-body { min-width: 0; }
.event-item .event-type { font-weight: 600; font-size: 12.5px; }
.event-item .event-time { color: var(--muted); font-size: 11px; }
.event-item pre { margin: 6px 0 0; font-size: 11px; color: #475569; white-space: pre-wrap; word-break: break-word; }

/* ---------- Misc ---------- */
.empty { padding: 42px 24px; text-align: center; color: var(--muted); }
.empty .icon { width: 42px; height: 42px; border-radius: 12px; background: #f3f4f6; display: grid; place-items: center; margin: 0 auto 10px; }
.empty h3 { margin: 0 0 4px; color: var(--ink); font-size: 14px; }
.empty p { margin: 0 auto 14px; max-width: 420px; font-size: 12.5px; }
.quick-list { display: grid; gap: 9px; }
.quick-item { display: flex; align-items: center; gap: 10px; font-size: 12.5px; }
.quick-item .check { width: 18px; height: 18px; border-radius: 99px; border: 1px solid var(--line-strong); display: grid; place-items: center; font-size: 10px; color: var(--muted); flex: 0 0 18px; }
.quick-item .check.done { background: var(--green-soft); border-color: #a7f3d0; color: var(--green); }
.quick-item code { background: #f3f4f6; padding: 1px 5px; border-radius: 4px; font-size: 11px; }
.copy-group { display: flex; align-items: center; gap: 8px; }
.check-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.check-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; padding: 2px 7px; border-radius: 999px; background: #f3f4f6; color: #4b5563; }
.check-pill.ok { background: var(--green-soft); color: var(--green); }
.check-pill.no { background: var(--red-soft); color: var(--red); }
.alert { border: 1px solid #fde68a; background: var(--amber-soft); color: #92400e; border-radius: 9px; padding: 11px 13px; font-size: 12.5px; }
.alert.danger { border-color: #fecaca; background: var(--red-soft); color: #991b1b; }
.alert.info { border-color: #bfdbfe; background: var(--accent-soft); color: #1e40af; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.tiny { font-size: 11px; }
.mt-0 { margin-top: 0; } .mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-8 { margin-bottom: 8px; } .mb-16 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.divider { height: 1px; background: var(--line); margin: 16px 0; }
.pagination { display: flex; align-items: center; gap: 8px; }
.pagination .info { color: var(--muted); font-size: 12px; margin-right: auto; }

/* ---------- Login ---------- */
.auth-shell { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 0.95fr; background: #fff; }
.auth-left {
  background: radial-gradient(1200px 600px at 10% -10%, #1e3a8a 0%, #0b1220 45%, #070a10 100%);
  color: #fff; padding: 54px; display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-left::after {
  content: ""; position: absolute; inset: 0;
  background-image: radial-gradient(rgba(255,255,255,0.06) 1px, transparent 1px);
  background-size: 22px 22px; pointer-events: none;
}
.auth-left .brand { padding: 0; position: relative; z-index: 1; }
.auth-hero { max-width: 440px; position: relative; z-index: 1; }
.auth-hero h1 { font-size: 34px; line-height: 1.14; letter-spacing: -0.035em; margin: 0 0 14px; font-weight: 650; }
.auth-hero p { color: #94a3b8; font-size: 14px; line-height: 1.65; margin: 0 0 22px; }
.auth-features { display: grid; gap: 11px; }
.auth-feature { display: flex; align-items: center; gap: 10px; color: #cbd5e1; font-size: 12.5px; }
.auth-feature .tick { width: 20px; height: 20px; border-radius: 99px; background: rgba(37,99,235,0.2); border: 1px solid rgba(96,165,250,0.35); display: grid; place-items: center; color: #93c5fd; font-size: 10px; }
.auth-foot { color: #64748b; font-size: 11.5px; position: relative; z-index: 1; }
.auth-right { display: grid; place-items: center; padding: 40px; }
.auth-card { width: 100%; max-width: 360px; }
.auth-card h2 { font-size: 21px; letter-spacing: -0.02em; margin: 0 0 5px; }
.auth-card .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
.auth-card .field { margin-bottom: 12px; }
.auth-card .btn { width: 100%; height: 38px; margin-top: 6px; }
.auth-note { margin-top: 18px; color: var(--muted); font-size: 11.5px; line-height: 1.6; }
.mobile-brand { display: none; }

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 60; transform: translateX(-102%); transition: transform 0.2s ease; }
  .sidebar.open { transform: none; box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
  .menu-toggle { display: inline-flex; }
  .app { display: block; }
  .content { padding: 20px 16px; }
  .topbar { padding: 0 16px; }
  .grid-3 { grid-template-columns: 1fr; }
  .auth-shell { grid-template-columns: 1fr; }
  .auth-left { display: none; }
  .mobile-brand { display: flex; margin-bottom: 26px; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .stat-grid { grid-template-columns: 1fr; }
  .page-head h1 { font-size: 19px; }
  .truncate { max-width: 200px; }
}
