:root {
  --ink: #2a1214;
  --ink-soft: #5c3438;
  --paper: #f7f1f1;
  --line: rgba(42, 18, 20, .12);
  --accent: #b94a4a;
  --muted: #8a6468;
  --warn: #9a6b12;
  --crit: #8b1e1e;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: Roboto, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
.wrap { width: min(1180px, calc(100% - 2rem)); margin: 0 auto; padding: 1.15rem 0 3rem; }
.brand { font-weight: 700; letter-spacing: -.02em; line-height: 1.1; margin: 0; font-size: 1.15rem; }
.logo { width: 32px; height: 32px; display: block; flex-shrink: 0; }
.brand-lockup { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.lede { margin: .45rem 0 0; color: var(--ink-soft); font-size: .95rem; line-height: 1.5; }
.card {
  border: 1px solid var(--line);
  border-radius: .85rem;
  background: #fff;
}
.pad { padding: 1.2rem 1.3rem; }
label { display: block; font-size: .8rem; font-weight: 600; margin: .85rem 0 .3rem; color: var(--ink-soft); }
input, input[type="search"] {
  width: 100%;
  padding: .6rem .75rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
}
input:focus { outline: 2px solid rgba(185, 74, 74, .35); border-color: var(--accent); }
.btn {
  font: inherit;
  font-size: .86rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #faf6f5;
  padding: .55rem 1rem;
  border-radius: .55rem;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.05); }
.btn:disabled { opacity: .45; cursor: not-allowed; filter: none; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-soft); }
.btn-row { padding: .28rem .55rem; font-size: .78rem; }
.err, .banner {
  background: rgba(139, 30, 30, .1);
  color: var(--crit);
  padding: .65rem .8rem;
  border-radius: .55rem;
  margin: 0 0 1rem;
  font-size: .9rem;
  font-weight: 500;
}
.banner.warn { background: rgba(154, 107, 18, .12); color: var(--warn); }
.muted { color: var(--muted); }

body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-card { width: min(400px, 92vw); padding: 1.6rem 1.55rem 1.45rem; }
.login-brand { margin-bottom: .35rem; }
.login-card .brand { font-size: 1.25rem; }
.login-card .btn { width: 100%; margin-top: 1.15rem; padding: .7rem; }

header.top {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem 1rem;
  align-items: center;
  margin-bottom: 1rem;
}
.stat { margin: .2rem 0 0; color: var(--muted); font-size: .82rem; font-weight: 500; }
.toolbar, .filter { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.filter { margin: 0 0 .75rem; }
.filter input[type="search"] { width: min(22rem, 100%); }
.check { display: flex; align-items: center; gap: .4rem; margin: 0; font-size: .85rem; font-weight: 500; color: var(--ink-soft); white-space: nowrap; }
.check input { width: auto; }

.tabs { display: flex; flex-wrap: wrap; gap: .25rem; margin-left: auto; }
.tab {
  font: inherit;
  font-size: .84rem;
  font-weight: 600;
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
  padding: .4rem .75rem;
  border-radius: .5rem;
  cursor: pointer;
}
.tab.is-on { background: #fff; color: var(--ink); border-color: var(--line); }
.tab-n {
  display: inline-block;
  min-width: 1.35rem;
  margin-left: .2rem;
  padding: .05rem .35rem;
  border-radius: 999px;
  background: rgba(185, 74, 74, .12);
  color: var(--accent);
  font-size: .72rem;
  font-variant-numeric: tabular-nums;
}
.queue-lede { margin: 0 0 .75rem; font-size: .88rem; }
.panel { display: none; }
.panel.is-on { display: block; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.kpi { padding: .9rem 1rem; }
.kpi .lbl { margin: 0; color: var(--muted); font-size: .75rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi .val { margin: .25rem 0 0; font-size: 1.35rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { margin: .15rem 0 0; color: var(--muted); font-size: .78rem; }

.table-card { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
th, td { text-align: left; padding: .7rem .85rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .78rem; letter-spacing: .02em; text-transform: uppercase; cursor: pointer; user-select: none; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgba(185, 74, 74, .06); }
.email { font-weight: 600; }
.email .tag { margin-left: .4rem; font-weight: 700; }
.bar {
  height: .45rem;
  background: rgba(42, 18, 20, .08);
  border-radius: 99px;
  overflow: hidden;
  min-width: 7rem;
}
.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.ok > span { background: var(--accent); }
.bar.warn > span { background: var(--warn); }
.bar.crit > span, .bar.over > span { background: var(--crit); }
.bar.unlimited { background: rgba(42, 18, 20, .06); }
.pct { display: flex; flex-direction: column; align-items: flex-end; gap: .3rem; }
.st {
  display: inline-block;
  font-size: .75rem;
  font-weight: 700;
  padding: .18rem .5rem;
  border-radius: 999px;
  background: rgba(42, 18, 20, .08);
}
.st-Scheduled, .st-Completed { background: rgba(185, 74, 74, .14); color: var(--accent); }
.st-TemporaryFailure { background: rgba(154, 107, 18, .14); color: var(--warn); }
.st-PermanentFailure { background: rgba(163, 59, 45, .12); color: var(--crit); }

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .75rem;
}
.metric { padding: .95rem 1rem; }
.metric .lbl { margin: 0; color: var(--muted); font-size: .78rem; font-weight: 600; }
.metric .val { margin: .3rem 0 0; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }

@media (max-width: 860px) {
  .kpis, .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tabs { margin-left: 0; width: 100%; }
}
@media (max-width: 560px) {
  .kpis, .metric-grid { grid-template-columns: 1fr; }
}

tbody tr[data-id] { cursor: pointer; }
.modal {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(920px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem);
}
.modal::backdrop { background: rgba(42, 18, 20, .45); }
.modal-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: .85rem;
  padding: 1rem 1.1rem 1.2rem;
  max-height: calc(100vh - 2rem);
  overflow: auto;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: .85rem;
}
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-h { margin: 1.1rem 0 .45rem; font-size: .95rem; }
.modal-note { margin: 0 0 .5rem; font-size: .78rem; }
.modal-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); }

tbody tr.unread td:first-child { font-weight: 600; }
.tag {
  display: inline-block;
  font-size: .7rem;
  font-weight: 700;
  padding: .1rem .4rem;
  border-radius: 999px;
  background: rgba(185, 74, 74, .14);
  color: var(--accent);
  vertical-align: middle;
}
