:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #f1f3f6;
  --line: #e3e6ec;
  --line-soft: #eef0f4;
  --ink: #1b2330;
  --muted: #667085;
  --muted-2: #98a2b3;
  --accent: #2f6feb;
  --accent-ink: #ffffff;
  --pass: #1f9d57;
  --fail: #d64545;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 6px 24px rgba(16,24,40,.10);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.logo { font-size: 16px; font-weight: 700; letter-spacing: .2px; padding: 6px 10px 18px; }
.logo span { color: var(--accent); font-weight: 600; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 9px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.nav-item:hover { background: var(--panel-2); color: var(--ink); }
.nav-item.active { background: #eaf1ff; color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.badge-count { font-size: 11px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 0 7px; min-width: 20px; text-align: center; }
.badge-count:empty { display: none; }
.signout { margin-top: 12px; }

.content { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 26px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: rgba(245,246,248,.9); backdrop-filter: blur(6px); z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 600; }
.topbar-actions { display: flex; gap: 10px; }
.view { padding: 24px 26px; }

/* ---------- Cards / panels ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 24px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.card .k { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .05em; }
.card .v { font-size: 28px; font-weight: 650; margin-top: 6px; }
.card .v small { font-size: 13px; color: var(--muted); font-weight: 500; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; margin-bottom: 22px; box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line-soft); gap: 12px; }
.panel-head h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; }
.panel-body { padding: 4px 0; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
thead th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted-2); padding: 10px 18px; border-bottom: 1px solid var(--line-soft); font-weight: 600; }
tbody td { padding: 12px 18px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--panel-2); }
.empty { padding: 34px 18px; text-align: center; color: var(--muted); }

/* ---------- Badges / pills ---------- */
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--muted); background: var(--panel-2); }
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.pass, .pill.done, .pill.online { color: var(--pass); border-color: rgba(31,157,87,.3); background: rgba(31,157,87,.10); }
.pill.fail, .pill.failed, .pill.error, .pill.offline { color: var(--fail); border-color: rgba(214,69,69,.3); background: rgba(214,69,69,.10); }
.pill.partial, .pill.running, .pill.scoring, .pill.queued, .pill.pending { color: var(--warn); border-color: rgba(183,121,31,.3); background: rgba(183,121,31,.10); }
.pill.sent, .pill.notif, .pill.sms { color: var(--accent); border-color: rgba(47,111,235,.3); background: rgba(47,111,235,.10); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; font-weight: 600; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.05); background: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--fail); border-color: rgba(214,69,69,.35); background: transparent; }
.btn.danger:hover { background: rgba(214,69,69,.08); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 5px; font-weight: 600; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; color: var(--ink); font: inherit;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,111,235,.15); }
textarea { min-height: 70px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
.hint { color: var(--muted-2); font-size: 12px; margin-top: 4px; }

/* ---------- Modal ---------- */
.modal-scrim { position: fixed; inset: 0; background: rgba(16,24,40,.35); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; z-index: 40; }
.modal { width: min(560px, 92vw); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.modal .m-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.modal .m-head h3 { margin: 0; font-size: 15px; }
.modal .m-body { padding: 8px 20px 4px; max-height: 66vh; overflow: auto; }
.modal .m-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line-soft); }
.x { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }

/* ---------- Drawer (run detail) ---------- */
.drawer-scrim { position: fixed; inset: 0; background: rgba(16,24,40,.30); z-index: 30; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(620px, 96vw); background: var(--bg); border-left: 1px solid var(--line); box-shadow: var(--shadow); z-index: 31; overflow-y: auto; padding: 22px 24px; }
.drawer h2 { margin: 0 0 4px; font-size: 18px; }
.drawer .sub { color: var(--muted); margin-bottom: 18px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 12px; margin-bottom: 18px; }
.kv .k { color: var(--muted); font-size: 13px; }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 60; }
.toast { background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 8px; padding: 11px 16px; box-shadow: var(--shadow); min-width: 240px; animation: slidein .18s ease; }
.toast.ok { border-left-color: var(--pass); }
.toast.err { border-left-color: var(--fail); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: min(360px, 90vw); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; box-shadow: var(--shadow); }
.auth-brand { font-size: 20px; font-weight: 700; margin-bottom: 18px; }
.auth-brand span { color: var(--accent); }
.banner { padding: 9px 12px; border-radius: 8px; margin-bottom: 12px; font-size: 13px; }
.banner.error { color: var(--fail); background: rgba(214,69,69,.08); border: 1px solid rgba(214,69,69,.3); }
.auth-card .btn { margin-top: 18px; }

/* ---------- utility ---------- */
.spinner { display: inline-block; width: 15px; height: 15px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { display: flex; align-items: center; gap: 10px; color: var(--muted); padding: 30px 18px; justify-content: center; }
.truncate { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
