:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1a1d21;
  --muted: #6b7280;
  --accent: #2563eb;
  --listed: #b91c1c;
  --listed-bg: #fef2f2;
  --clear: #15803d;
  --clear-bg: #f0fdf4;
  --unknown: #b45309;
  --unknown-bg: #fffbeb;
  --radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --surface: #1f2227;
    --border: #343941;
    --text: #e8eaed;
    --muted: #9aa1ab;
    --accent: #60a5fa;
    --listed-bg: #2a1616;
    --clear-bg: #13251a;
    --unknown-bg: #2a2113;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 2rem 1rem;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

main { max-width: 720px; margin: 0 auto; }

h1 { font-size: 1.25rem; margin: 0; }

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}

.who { display: flex; align-items: center; gap: .75rem; color: var(--muted); font-size: .875rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.centered { max-width: 360px; margin: 10vh auto; }

label { display: block; margin: 1rem 0; font-size: .875rem; color: var(--muted); }

input, textarea {
  width: 100%;
  margin-top: .35rem;
  padding: .6rem .7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
  padding: .6rem 1.1rem;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}

button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: transparent; color: var(--accent); border: 1px solid var(--border); }
button.link { background: none; color: var(--muted); padding: 0; text-decoration: underline; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1rem; border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; color: var(--muted); border-radius: 0;
  border-bottom: 2px solid transparent; padding: .5rem .9rem;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

#lookup-form { display: flex; gap: .5rem; }
#lookup-form input { margin-top: 0; font-size: 1.05rem; }

.row { display: flex; align-items: center; gap: .75rem; margin-top: .75rem; }

.verdict {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.verdict.listed  { background: var(--listed-bg);  border-color: var(--listed); }
.verdict.clear   { background: var(--clear-bg);   border-color: var(--clear); }
.verdict.unknown { background: var(--unknown-bg); border-color: var(--unknown); }
.verdict.error   { background: var(--listed-bg);  border-color: var(--border); }

.badge {
  flex: 0 0 auto;
  align-self: flex-start;
  padding: .3rem .6rem;
  border-radius: 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .05em;
  background: var(--surface);
  border: 1px solid currentColor;
}

.verdict.listed  .badge { color: var(--listed); }
.verdict.clear   .badge { color: var(--clear); }
.verdict.unknown .badge { color: var(--unknown); }
.verdict.error   .badge { color: var(--muted); }

.verdict-body p { margin: .4rem 0; }

dl { display: grid; grid-template-columns: auto 1fr; gap: .2rem .75rem; margin: .6rem 0 0; font-size: .85rem; }
dt { color: var(--muted); }
dd { margin: 0; }

.pending { margin-top: 1.25rem; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.error { color: var(--listed); font-size: .875rem; }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; font-size: .875rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 500; }

.pill { padding: .15rem .5rem; border-radius: 999px; font-size: .7rem; font-weight: 700; }
.pill.listed  { background: var(--listed-bg);  color: var(--listed); }
.pill.clear   { background: var(--clear-bg);   color: var(--clear); }
.pill.unknown { background: var(--unknown-bg); color: var(--unknown); }
.pill.error   { background: var(--listed-bg);  color: var(--muted); }

.summary {
  margin-top: 1rem;
  padding: .7rem .9rem;
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  font-size: .875rem;
}

.stat-grid { display: flex; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stat {
  flex: 1 1 140px;
  padding: .9rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.stat b { display: block; font-size: 1.5rem; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .78rem; }


/* =========================== admin =========================== */

.admin-body { padding: 0; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 1.5rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}

.brand { display: flex; align-items: center; gap: .9rem; min-width: 0; }
.brand-mark {
  font-size: .7rem; font-weight: 700; letter-spacing: .08em;
  padding: .25rem .45rem; border-radius: 4px;
  background: var(--accent); color: #fff;
}
.crumbs { display: flex; align-items: center; gap: .5rem; font-size: .875rem; color: var(--muted); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); text-decoration: underline; }
.crumbs strong { color: var(--text); font-weight: 600; }

.chip {
  padding: .2rem .55rem; border-radius: 999px;
  border: 1px solid var(--border); font-size: .78rem; color: var(--muted);
}

.admin-main { max-width: 1080px; margin: 0 auto; padding: 1.5rem; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.panel-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 1rem; }
.panel-actions { display: flex; gap: .6rem; align-items: center; }
.panel-actions input[type=search] { width: 190px; margin: 0; padding: .45rem .65rem; font-size: .85rem; }

.footnote { padding: .9rem 1.25rem; margin: 0; border-top: 1px solid var(--border); }
.pad { padding: 1.5rem; text-align: center; }

.table-scroll { overflow-x: auto; }

table.users { width: 100%; border-collapse: collapse; font-size: .875rem; margin: 0; }
table.users th {
  text-align: left; font-weight: 500; font-size: .72rem;
  letter-spacing: .04em; text-transform: uppercase; color: var(--muted);
  padding: .6rem 1rem; border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.users td { padding: .7rem 1rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.users tbody tr:last-child td { border-bottom: 0; }
table.users tbody tr:hover { background: color-mix(in srgb, var(--accent) 5%, transparent); }
table.users tr.is-inactive { opacity: .5; }
th.num, td.num { text-align: right; }

.user-cell { display: flex; align-items: center; gap: .65rem; }
.avatar {
  flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  color: var(--accent); font-size: .68rem; font-weight: 700;
}
.user-name { display: flex; align-items: center; gap: .4rem; font-weight: 500; }
.tag {
  font-size: .62rem; text-transform: uppercase; letter-spacing: .05em;
  padding: .1rem .35rem; border-radius: 3px;
  background: var(--listed-bg); color: var(--listed); border: 1px solid currentColor;
}

.mini { width: 78px; margin: 0; padding: .3rem .45rem; font-size: .82rem; }
select.mini { width: auto; }
input.mini.num { text-align: right; }

.switch { display: inline-block; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
  display: block; width: 34px; height: 19px; border-radius: 999px;
  background: var(--border); position: relative; transition: background .15s;
}
.switch .track::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--surface); box-shadow: 0 1px 2px rgba(0,0,0,.3);
  transition: transform .15s;
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(15px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.meter { width: 88px; height: 4px; margin-top: .3rem; background: var(--border); border-radius: 2px; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); transition: width .2s; }
.meter span.hot { background: var(--listed); }

.actions { white-space: nowrap; text-align: right; }
.icon-btn {
  background: none; border: 1px solid transparent; color: var(--muted);
  padding: .28rem .5rem; border-radius: 5px; font-size: .78rem; cursor: pointer;
}
.icon-btn:hover { border-color: var(--border); color: var(--text); background: var(--bg); }
.icon-btn.danger:hover { color: var(--listed); border-color: var(--listed); }

/* stat tiles */
.stat-grid { display: flex; gap: .9rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.stat {
  flex: 1 1 150px; padding: .9rem 1.1rem;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface);
}
.stat b { display: block; font-size: 1.45rem; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: .76rem; }
.stat.warn { border-color: var(--unknown); background: var(--unknown-bg); }
.stat.warn b { color: var(--unknown); }

/* dialogs */
dialog.sheet {
  width: min(460px, calc(100vw - 2rem));
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 1.4rem;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}
dialog.sheet::backdrop { background: rgba(0,0,0,.45); }
dialog.sheet h2 { margin: 0 0 .9rem; font-size: 1.05rem; }
dialog.sheet label { margin: .8rem 0 0; }
.field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.field-grid label:first-child, .field-grid label:nth-child(2) { grid-column: 1 / -1; }
.switch-row { display: flex; align-items: center; gap: .5rem; grid-column: 1 / -1; }
.switch-row input { width: auto; margin: 0; }
.sheet-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.3rem; }
button.ghost { background: none; color: var(--muted); border: 1px solid var(--border); }
button.danger-btn { background: var(--listed); }

.hint { display: block; color: var(--muted); font-size: .72rem; margin-top: .25rem; }
.tiny { font-size: .74rem; }

/* toast */
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  padding: .6rem 1rem; border-radius: 7px; font-size: .85rem; z-index: 50;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--clear); box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.bad { border-color: var(--listed); color: var(--listed); }

@media (max-width: 720px) {
  .admin-main { padding: 1rem; }
  .panel-actions { width: 100%; }
  .panel-actions input[type=search] { flex: 1; width: auto; }
  .field-grid { grid-template-columns: 1fr; }
}

/* ======================== agent lookup UI ======================== */

.signin-brand { margin-bottom: .9rem; }
#signin h1 { font-size: 1.3rem; margin: 0 0 .2rem; }

.tabs { display: flex; gap: .25rem; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); }
.tabs button {
  background: none; color: var(--muted); border-radius: 0;
  border-bottom: 2px solid transparent; padding: .55rem .9rem; font-size: .9rem;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

.search-bar { display: flex; gap: .6rem; }
.search-bar input {
  margin: 0; font-size: 1.15rem; letter-spacing: .02em; padding: .75rem .9rem;
  font-variant-numeric: tabular-nums;
}
.search-bar button { padding: .75rem 1.6rem; font-size: .95rem; }

/* verdict card */
.verdict {
  display: flex; gap: 1rem; margin-top: 1.25rem; padding: 1.15rem 1.25rem;
  border: 1px solid var(--border); border-left-width: 4px;
  border-radius: var(--radius); background: var(--surface);
}
.verdict.listed  { border-color: var(--listed);  background: var(--listed-bg); }
.verdict.clear   { border-color: var(--clear);   background: var(--clear-bg); }
.verdict.unknown { border-color: var(--unknown); background: var(--unknown-bg); }
.verdict.error   { border-color: var(--border); }
.verdict.pending { border-left-color: var(--accent); }
.verdict.stale   { border-style: dashed; }

.verdict-mark {
  flex: 0 0 auto; width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; font-size: 1.25rem; font-weight: 700;
  background: var(--surface); border: 2px solid currentColor;
}
.verdict.listed  .verdict-mark { color: var(--listed); }
.verdict.clear   .verdict-mark { color: var(--clear); }
.verdict.unknown .verdict-mark { color: var(--unknown); }
.verdict.error   .verdict-mark { color: var(--muted); }

.verdict-body { min-width: 0; flex: 1; }
.verdict-head { display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap; }
.verdict-label { font-size: .95rem; font-weight: 700; letter-spacing: .04em; }
.verdict.listed  .verdict-label { color: var(--listed); }
.verdict.clear   .verdict-label { color: var(--clear); }
.verdict.unknown .verdict-label { color: var(--unknown); }
.verdict-phone {
  font-size: 1.05rem; font-variant-numeric: tabular-nums; color: var(--text);
}
.verdict-line { margin: .35rem 0 0; font-size: .9rem; }
.warn-line { margin: .5rem 0 0; font-size: .82rem; color: var(--unknown); }

.flags { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .7rem; }
.flag {
  font-size: .72rem; font-weight: 600; padding: .18rem .5rem; border-radius: 999px;
  background: var(--surface); border: 1px solid currentColor; color: var(--listed);
}

dl.facts {
  display: grid; grid-template-columns: auto 1fr; gap: .25rem .9rem;
  margin: .8rem 0 0; font-size: .82rem;
}
dl.facts dt { color: var(--muted); }
dl.facts dd { margin: 0; }

.prov { display: block; margin-top: .75rem; font-size: .72rem; color: var(--muted); }

.spinner {
  flex: 0 0 auto; width: 24px; height: 24px; margin: 8px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.5s; } }

.section-label {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--muted); margin: 1.75rem 0 .5rem; font-weight: 600;
}
.recent-list { list-style: none; margin: 0; padding: 0; }
.recent-list li {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .2rem; border-bottom: 1px solid var(--border); font-size: .85rem;
}
.recent-list li:last-child { border-bottom: 0; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex: 0 0 auto; }
.dot.listed { background: var(--listed); }
.dot.clear { background: var(--clear); }
.dot.unknown { background: var(--unknown); }
.dot.error { background: var(--muted); }
.mono { font-variant-numeric: tabular-nums; }

.pill { padding: .15rem .5rem; border-radius: 999px; font-size: .68rem; font-weight: 700; }
.pill.listed  { background: var(--listed-bg);  color: var(--listed); }
.pill.clear   { background: var(--clear-bg);   color: var(--clear); }
.pill.unknown { background: var(--unknown-bg); color: var(--unknown); }
.pill.error   { background: var(--bg);         color: var(--muted); }

.summary {
  margin: .9rem 0; padding: .65rem .85rem; font-size: .85rem;
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 6px; background: var(--bg);
}

.chip.hot { color: var(--listed); border-color: var(--listed); }

#tab-bulk textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; }

/* --- layout corrections --- */

/* Inputs default to width:100%, which overflows inside a flex row. */
.search-bar input { flex: 1 1 auto; width: auto; min-width: 0; }
.panel-actions input[type=search] { flex: 0 0 auto; }

/* Keep the header's contents on the same column as the page body. */
.app-header { padding: .85rem 0; }
.app-header > * { min-width: 0; }
.app-header { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.app-header::before, .app-header::after { content: none; }
.app-header .brand { padding-left: max(1.5rem, calc((100vw - 1080px) / 2)); }
.app-header .who { padding-right: max(1.5rem, calc((100vw - 1080px) / 2)); }

.who { display: flex; align-items: center; gap: .7rem; }

/* --- full detail groups --- */

.detail-groups { margin-top: 1rem; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }

details.group { border-bottom: 1px solid var(--border); background: var(--surface); }
details.group:last-child { border-bottom: 0; }

details.group > summary {
  cursor: pointer; padding: .6rem 1rem; font-size: .82rem; font-weight: 600;
  list-style: none; display: flex; align-items: center; gap: .5rem;
  color: var(--text); user-select: none;
}
details.group > summary::-webkit-details-marker { display: none; }
details.group > summary::before {
  content: '\25B8'; color: var(--muted); font-size: .7rem;
  transition: transform .15s; display: inline-block;
}
details.group[open] > summary::before { transform: rotate(90deg); }
details.group > summary:hover { background: var(--bg); }
details.group .count {
  margin-left: auto; font-size: .68rem; font-weight: 500; color: var(--muted);
  border: 1px solid var(--border); border-radius: 999px; padding: .05rem .4rem;
}

dl.facts.wide {
  grid-template-columns: minmax(110px, auto) 1fr;
  padding: .2rem 1rem .9rem; margin: 0; gap: .3rem .9rem;
}
dl.facts.wide dd { word-break: break-word; }
