:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: #eef2f7;
  font-size: 14px;
}
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: 230px;
  background: var(--bg);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { padding: 0 8px 18px; }
.brand-logo { display:block; width:100%; max-width:180px; height:auto; margin-bottom:12px; }
.brand-title { font-size: 15px; font-weight: 700; color: #fff; letter-spacing: .2px; line-height: 1.2; }
.brand small { display:block; font-weight: 400; color:#64748b; font-size: 11px; margin-top: 3px;}
.nav button {
  width: 100%; text-align: left; background: none; border: none; color: #cbd5e1;
  padding: 11px 12px; border-radius: 8px; cursor: pointer; font-size: 14px; margin-bottom: 3px;
  display: flex; align-items: center; gap: 10px;
}
.nav button:hover { background: #1e293b; color: #fff; }
.nav button.active { background: var(--accent); color: #fff; }
.nav button:disabled { opacity: .4; cursor: not-allowed; }
.sidebar .status-chip {
  margin-top: auto; font-size: 12px; padding: 10px 12px; background:#1e293b; border-radius: 8px; color:#94a3b8;
  overflow-wrap: anywhere; word-break: break-word; line-height: 1.4;
}
.status-chip b { color:#fff; }
.status-chip .dot { display:inline-block; width:8px; height:8px; border-radius:50%; background:#64748b; margin-right:6px;}
.status-chip.on .dot { background: var(--green); }

/* Main */
.main { flex: 1; padding: 28px 34px; max-width: none; min-width: 0; }
.page { display: none; }
.page.active { display: block; }
h1 { font-size: 22px; margin: 0 0 4px; }
.subtitle { color: var(--muted); margin: 0 0 22px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 20px 22px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; margin: 0 0 14px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.field { margin-bottom: 14px; flex: 1; min-width: 180px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
textarea { resize: vertical; min-height: 70px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }

button.btn {
  background: var(--accent); color: #fff; border: none; padding: 10px 18px; border-radius: 8px;
  font-size: 14px; font-weight: 600; cursor: pointer;
}
button.btn:hover { background: var(--accent-hover); }
button.btn.secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
button.btn.secondary:hover { background: var(--panel-2); }
button.btn.danger { background: #fff; color: var(--red); border: 1px solid #fecaca; }
button.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* tenant list */
.tenant { display:flex; align-items:center; justify-content:space-between; padding:10px 14px; border:1px solid var(--border); border-radius:8px; margin-bottom:8px; }
.tenant.active { border-color: var(--accent); background: #eff6ff; }
.tenant .who { min-width: 0; overflow-wrap: anywhere; word-break: break-word; padding-right: 10px; }
.tenant .who b { display:block; }
.tenant .who span { color: var(--muted); font-size:12px; }

/* user picker */
.userbox { border:1px solid var(--border); border-radius:8px; max-height:280px; overflow:auto; background:#fff; }
.userbox label { display:flex; gap:10px; align-items:center; padding:7px 12px; border-bottom:1px solid #f1f5f9; font-weight:400; color:var(--text); margin:0; cursor:pointer; }
.userbox label:hover { background: var(--panel-2); }
.userbox input { width:auto; }
.userbox .u-meta { color: var(--muted); font-size:12px; margin-left:auto; }
.picker-toolbar { display:flex; gap:10px; align-items:center; margin-bottom:10px; }
.picker-toolbar input[type=search] { flex:1; }
.count-badge { background:#eff6ff; color:var(--accent); padding:4px 10px; border-radius:20px; font-weight:600; font-size:12px; }

/* tables */
table { width:100%; border-collapse: collapse; font-size:13px; }
th, td { text-align:left; padding:9px 10px; border-bottom:1px solid var(--border); }
th { color:var(--muted); font-size:12px; text-transform:uppercase; letter-spacing:.3px; }
tr.compromised td { background: var(--red-bg); }
.pill { padding:2px 9px; border-radius:20px; font-size:12px; font-weight:600; }
.pill.yes { background:#dcfce7; color:var(--green); }
.pill.no { background:#f1f5f9; color:var(--muted); }
.pill.warn { background:#fef3c7; color:var(--amber); }

/* preview batch table */
.batch-time { width: 210px; }
.emails-toggle { color: var(--accent); cursor: pointer; font-size:12px; }
.emails-list { font-size:12px; color:var(--muted); margin-top:4px; display:none; }
.emails-list.show { display:block; }

/* metric cards */
.metrics { display:grid; grid-auto-flow:column; grid-auto-columns:minmax(0,1fr); gap:8px; margin-bottom:18px; overflow-x:auto; }
.metric { background:var(--panel); border:1px solid var(--border); border-radius:10px; padding:9px 10px; box-shadow:var(--shadow); min-width:0; }
.metric .val { font-size:17px; font-weight:700; line-height:1.15; white-space:nowrap; }
.metric .lbl { color:var(--muted); font-size:10.5px; margin-top:3px; line-height:1.2; }
.metric.red .val { color:var(--red); }
.metric.green .val { color:var(--green); }

/* misc */
.toast { position: fixed; bottom: 24px; right: 24px; background:#0f172a; color:#fff; padding:12px 18px; border-radius:10px; box-shadow:var(--shadow); opacity:0; transform:translateY(10px); transition:.25s; z-index:50; max-width: 360px;}
.toast.show { opacity:1; transform:translateY(0); }
.toast.error { background: var(--red); }
.toast.ok { background: var(--green); }
.spinner { display:inline-block; width:16px; height:16px; border:2px solid rgba(255,255,255,.4); border-top-color:#fff; border-radius:50%; animation:spin .7s linear infinite; vertical-align:middle;}
.spinner.dark { border-color: rgba(37,99,235,.3); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }
.collapsible summary { cursor:pointer; font-weight:600; font-size:13px; color:var(--muted); padding:6px 0; }
details.collapsible { border-top:1px solid var(--border); margin-top:8px; padding-top:6px;}
.banner { padding:12px 16px; border-radius:8px; background:#eff6ff; color:#1e3a8a; font-size:13px; margin-bottom:16px; border:1px solid #bfdbfe;}
.banner.warn { background:#fffbeb; color:#92400e; border-color:#fde68a; }
.guide h3 { margin: 22px 0 6px; font-size:15px; }
.guide ol { padding-left: 20px; line-height: 1.7; }
.guide code { background:#f1f5f9; padding:2px 6px; border-radius:5px; font-size:13px; }
.guide .perm { display:inline-block; background:#eff6ff; color:var(--accent); padding:2px 8px; border-radius:6px; font-family:monospace; font-size:12px; margin:2px 4px 2px 0;}

/* ============================================================
   Design polish
   ============================================================ */

/* Sticky table headers (within each overflow:auto container) */
table th { position: sticky; top: 0; background: var(--panel-2); z-index: 2; }

/* Subtle tab/page fade-in */
.page.active { animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* Behavior funnel */
.funnel { margin: 6px 0 4px; }
.funnel-row { display: flex; align-items: center; gap: 12px; margin: 7px 0; }
.funnel-row .lbl { width: 110px; text-align: right; color: var(--muted); font-size: 13px; }
.funnel-row .track { flex: 1; display: flex; justify-content: center; }
.funnel-bar { color: #fff; text-align: center; font-size: 13px; font-weight: 700; padding: 9px 6px; border-radius: 8px; min-width: 34px; transform-origin: center; animation: funnelin .5s ease; white-space: nowrap; }
.funnel-row .drop { width: 96px; color: var(--muted); font-size: 12px; }
@keyframes funnelin { from { transform: scaleX(.12); opacity: .25; } to { transform: scaleX(1); opacity: 1; } }

/* Metric count-up draw-in */
.metric .val { transition: color .2s; }
.metric { animation: fadein .3s ease; }

/* Skeleton loaders */
.skeleton { background: linear-gradient(90deg, #eef2f7 25%, #e2e8f0 37%, #eef2f7 63%); background-size: 400% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; }
.skel-line { height: 14px; margin: 10px 0; }
.skel-card { height: 78px; border-radius: 12px; margin-bottom: 14px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }

/* Friendly empty states */
.empty { text-align: center; padding: 28px 16px; color: var(--muted); }
.empty .ico { font-size: 30px; margin-bottom: 8px; }
.empty .t { font-weight: 600; color: var(--text); margin-bottom: 4px; }


/* Make each table's scroll wrapper a vertical scroll container so the
   position:sticky header actually pins (page-scroll wouldn't trigger it). */
.main div[style*="overflow:auto"] { max-height: 70vh; }
table th { box-shadow: 0 1px 0 var(--border); }

/* ---------- payload email preview modal ---------- */
.pv-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex;
  align-items: center; justify-content: center; z-index: 1000; padding: 24px; }
.pv-modal { background: #fff; border-radius: 14px; width: min(860px, 95vw); max-height: 92vh;
  display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.pv-head { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--border); }
.pv-title { font-weight: 700; font-size: 15px; }
.pv-meta { padding: 12px 18px; border-bottom: 1px solid var(--border); background: #f8fafc; font-size: 13px; }
.pv-meta > div { padding: 2px 0; }
.pv-meta span { display: inline-block; width: 64px; color: var(--muted); }
.pv-frame { flex: 1; width: 100%; min-height: 55vh; border: 0; background: #fff; }

/* ---------- phish resistance score badge ---------- */
.named { display: inline-flex; align-items: center; gap: 7px; }
.score-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 26px; height: 26px; padding: 0 6px; border-radius: 999px;
  background: #64748b; color: #fff; font-weight: 700; font-size: 12px;
  line-height: 1; cursor: default; box-shadow: 0 1px 2px rgba(0,0,0,.15);
}
.score-badge.nodata { background: #e2e8f0; color: #64748b; box-shadow: none; }
.score-arrow { font-size: 11px; font-weight: 700; }
.score-arrow.up { color: #16a34a; }
.score-arrow.down { color: #dc2626; }

/* ---------- health tab ---------- */
.health-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0 4px; }
.health-row {
  display: grid; grid-template-columns: 16px 200px 1fr 60px; align-items: center;
  gap: 12px; padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: #fff;
}
.health-row .health-dot { width: 12px; height: 12px; border-radius: 50%; }
.health-row.ok .health-dot { background: #16a34a; }
.health-row.bad .health-dot { background: #dc2626; }
.health-row .health-name { font-weight: 600; }
.health-row .health-detail { color: var(--muted); font-size: 13px; }
.health-row .health-state { text-align: right; font-weight: 700; font-size: 12px; }
.health-row.ok .health-state { color: #16a34a; }
.health-row.bad .health-state { color: #dc2626; }
@media (max-width: 640px) {
  .health-row { grid-template-columns: 16px 1fr; }
  .health-row .health-detail, .health-row .health-state { grid-column: 2; text-align: left; }
}
