:root {
  --canvas: #eef1f5;
  --surface: #ffffff;
  --ink: #121926;
  --muted: #5b6577;
  --line: #d5dbe4;
  --accent: #2447d6;
  --accent-soft: #e4e9fb;
  --ok: #14784a;
  --ok-soft: #dcf2e6;
  --bad: #b8301c;
  --bad-soft: #fbe3de;
  --wait: #6b7486;
  --wait-soft: #e6e9ee;
  /* anatomia da URL */
  --u-sub: #2447d6;
  --u-slug: #0c7a6f;
  --u-aff: #9a3d00;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font: 15px/1.5 var(--sans); }
h1, h2, h3, p { margin: 0; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.boot { padding: 48px 24px; color: var(--muted); }

/* ---------- controles ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { border-color: #aab3c2; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1c39b4; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 3px 10px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: none; color: var(--muted); }
.btn.ghost:hover { color: var(--ink); background: var(--wait-soft); }

label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 500; color: var(--muted); }
input[type=text], input[type=email], select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--ink);
  font-weight: 400; font-size: 15px; min-width: 0;
}
input.mono { font-family: var(--mono); font-size: 14px; }

/* ---------- topo ---------- */
.top { background: var(--ink); color: #fff; display: flex; align-items: center; gap: 28px; padding: 0 24px; flex-wrap: wrap; }
.top h1 { font-size: 16px; font-weight: 600; padding: 16px 0; }
.tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.tabs button {
  background: none; border: 0; color: #b9c1cf; padding: 17px 12px 14px; cursor: pointer; border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs button:hover { color: #fff; }
.tabs button[aria-current=page] { color: #fff; border-bottom-color: #8ea3ff; font-weight: 500; }
.who { display: flex; align-items: center; gap: 12px; font-size: 13px; color: #b9c1cf; padding: 8px 0; }
.who .btn { background: none; color: #fff; border-color: #414b5e; }

/* ---------- tela de links ---------- */
.links { display: grid; grid-template-columns: 272px minmax(0, 1fr); gap: 24px; padding: 24px; max-width: 1500px; margin: 0 auto; align-items: start; }
.rail { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 18px; display: grid; gap: 14px; position: sticky; top: 16px; }
.rail h2 { font-size: 15px; font-weight: 600; }

.anatomy { border-top: 1px solid var(--line); padding-top: 14px; font-size: 13px; color: var(--muted); display: grid; gap: 6px; }
.anatomy code { font-family: var(--mono); font-size: 11.5px; line-height: 1.7; overflow-wrap: anywhere; color: var(--ink); }

.summary { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.summary .count { font-size: 20px; font-weight: 600; margin-right: 6px; }
.summary .spacer { flex: 1; }
.rail-actions { display: grid; gap: 8px; }
.rail-actions .btn { justify-content: center; }
.hint.changed { color: var(--u-aff); margin-top: -4px; }

/* filtro de status: botões agrupados com contagem */
.segmented { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); overflow: hidden; flex-wrap: wrap; }
.segmented .seg { border: 0; background: none; padding: 6px 12px; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; font-weight: 500; color: var(--muted); }
.segmented .seg + .seg { border-left: 1px solid var(--line); }
.segmented .seg:hover { color: var(--ink); }
.segmented .seg .n { font-size: 12px; padding: 0 7px; border-radius: 99px; background: var(--wait-soft); color: var(--wait); }
.segmented .seg.ok .n { background: var(--ok-soft); color: var(--ok); }
.segmented .seg.bad .n { background: var(--bad-soft); color: var(--bad); }
.segmented .seg[aria-pressed=true] { background: var(--ink); color: #fff; }
.summary + .summary { margin-top: -6px; }
.pill { font-size: 13px; padding: 2px 10px; border-radius: 99px; font-weight: 500; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.wait { background: var(--wait-soft); color: var(--wait); }

.product { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; margin-bottom: 18px; overflow: hidden; }
.product > header { display: flex; align-items: center; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.product h2 { font-size: 18px; font-weight: 600; flex: 1; }
.offer h3 { font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 18px 6px; background: #f7f8fa; border-bottom: 1px solid var(--line); }
.offer + .offer h3 { border-top: 1px solid var(--line); }

.row { display: grid; grid-template-columns: 78px minmax(0, 1fr) minmax(150px, 220px) auto; gap: 14px; align-items: center; padding: 10px 18px; }
.row + .row { border-top: 1px solid #edf0f4; }
.row .who-aff { font-size: 13px; line-height: 1.35; min-width: 0; }
.row .who-aff b { font-weight: 500; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .who-aff span { color: var(--muted); }

/* o elemento central da tela: a URL com cada parte identificável */
.url { font-family: var(--mono); font-size: 13.5px; word-break: break-all; color: var(--muted); text-decoration: none; line-height: 1.55; }
.url:hover { text-decoration: underline; text-decoration-color: var(--line); }
.url .sub, code .sub { color: var(--u-sub); font-weight: 600; }
.url .dom, code .dom { color: var(--ink); font-weight: 500; }
.url .slug, code .slug { color: var(--u-slug); font-weight: 600; }
.url .aff, code .aff { color: var(--u-aff); font-weight: 600; }

.tag { font-family: var(--mono); font-size: 12.5px; font-weight: 600; text-align: center; padding: 3px 0; border-radius: 4px; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.bad { background: var(--bad-soft); color: var(--bad); }
.tag.wait { background: var(--wait-soft); color: var(--wait); font-weight: 400; }

.empty { background: var(--surface); border: 1px dashed #b6bfcc; border-radius: 8px; padding: 32px; max-width: 640px; }
.empty h2 { font-size: 18px; margin-bottom: 8px; }
.empty ul { margin: 10px 0 0; padding-left: 20px; color: var(--muted); }
.note { font-size: 13px; color: var(--muted); margin-bottom: 14px; }

/* ---------- cadastros ---------- */
.manage { padding: 24px; max-width: 1100px; margin: 0 auto; }
.manage > header { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; }
.manage h2 { font-size: 20px; font-weight: 600; flex: 1; }
.manage .search { width: min(320px, 100%); padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); font-size: 15px; }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 2px; font-size: 14px; color: var(--muted); }
.pager-buttons { display: inline-flex; align-items: center; gap: 10px; }
.page-of { color: var(--ink); font-weight: 500; }
table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
th { text-align: left; font-size: 13px; font-weight: 600; color: var(--muted); padding: 10px 16px; background: #f7f8fa; border-bottom: 1px solid var(--line); }
td { padding: 11px 16px; border-bottom: 1px solid #edf0f4; vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; width: 1%; }
td .mono, .mono { font-family: var(--mono); font-size: 13.5px; }
td small { color: var(--muted); display: block; }
td .acc + .acc { margin-top: 10px; }
.chip { display: inline-block; background: var(--wait-soft); border-radius: 4px; padding: 1px 8px; margin: 1px 4px 1px 0; font-size: 13px; }

/* ---------- formulários ---------- */
dialog { border: 0; border-radius: 10px; padding: 0; width: min(680px, calc(100vw - 32px)); box-shadow: 0 24px 60px rgba(18, 25, 38, .28); color: var(--ink); }
dialog::backdrop { background: rgba(18, 25, 38, .5); }
dialog form { display: grid; gap: 16px; padding: 24px; max-height: calc(100vh - 48px); overflow-y: auto; }
dialog h2 { font-size: 18px; font-weight: 600; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px 14px; margin: 0; display: grid; gap: 10px; min-width: 0; }
legend { font-size: 13px; font-weight: 600; color: var(--muted); padding: 0 6px; }
.line { display: grid; gap: 8px; align-items: center; }
.line.c3 { grid-template-columns: 1fr 1fr 1.3fr auto; }
.line.c2 { grid-template-columns: 1fr 1fr auto; }
.line.c1 { grid-template-columns: 1fr auto; }
.sub-block { border-top: 1px solid var(--line); padding-top: 10px; display: grid; gap: 8px; }
.sub-block:first-of-type { border-top: 0; padding-top: 0; }
.hint { font-size: 13px; color: var(--muted); font-weight: 400; }
.error { background: var(--bad-soft); color: var(--bad); border-radius: 6px; padding: 8px 12px; font-size: 14px; }
.foot { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- lista suspensa de múltipla escolha ---------- */
.ms { display: grid; gap: 6px; min-width: 0; }
.ms-control { display: flex; align-items: center; gap: 8px; min-height: 38px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); cursor: pointer; }
.ms-control:hover { border-color: #aab3c2; }
.ms-control[aria-expanded=true] { border-color: var(--accent); }
.ms-chips { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; min-width: 0; }
.ms-chip { display: inline-flex; align-items: center; gap: 2px; background: var(--accent-soft); color: var(--ink); border-radius: 4px; padding: 1px 2px 1px 8px; font-size: 13px; max-width: 100%; }
.ms-x { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 15px; line-height: 1; padding: 0 5px; border-radius: 3px; }
.ms-x:hover { color: var(--bad); background: #fff; }
.ms-more { font-size: 13px; color: var(--muted); align-self: center; }
.ms-placeholder { flex: 1; color: var(--muted); font-size: 14px; }
.ms-caret { color: var(--muted); font-size: 12px; }
.ms-panel { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: 0 8px 24px rgba(18, 25, 38, .12); overflow: hidden; }
.ms-search { width: 100%; border: 0; border-bottom: 1px solid var(--line); padding: 9px 12px; font-size: 14px; outline: none; }
.ms-list { list-style: none; margin: 0; padding: 4px 0; max-height: 220px; overflow-y: auto; }
.ms-list li { display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.ms-list li.active { background: #f1f3f7; }
.ms-list li[aria-selected=true] { font-weight: 500; }
.ms-check { width: 16px; height: 16px; flex: none; border: 1px solid #aab3c2; border-radius: 3px; display: inline-grid; place-items: center; font-size: 12px; color: #fff; }
.ms-list li[aria-selected=true] .ms-check { background: var(--accent); border-color: var(--accent); }
.ms-list .ms-none { color: var(--muted); cursor: default; }
.ms-foot { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border-top: 1px solid var(--line); background: #f7f8fa; flex-wrap: wrap; }
.ms-count { flex: 1; font-size: 13px; color: var(--muted); padding-left: 4px; }
.chip.exclusive { background: var(--u-aff); color: #fff; }

/* ---------- login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login .card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 36px; width: min(420px, 100%); display: grid; gap: 16px; }
.login h1 { font-size: 24px; font-weight: 600; }
.login p { color: var(--muted); }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 8px 16px; border-radius: 6px; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .15s; }
#toast.show { opacity: 1; }

@media (max-width: 900px) {
  .links { grid-template-columns: 1fr; padding: 16px; }
  .rail { position: static; grid-template-columns: 1fr 1fr; align-items: end; }
  .rail h2, .rail .anatomy { grid-column: 1 / -1; }
  .rail .btn { align-self: end; justify-content: center; }
  .rail .rail-actions, .rail .hint.changed { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
  .row { grid-template-columns: 70px minmax(0, 1fr) auto; }
  .row .who-aff { grid-column: 2 / -1; grid-row: 2; }
  .manage { padding: 16px; overflow-x: auto; }
  .manage > header { flex-wrap: wrap; }
  .manage .search { order: 3; width: 100%; }
  .line.c3, .line.c2 { grid-template-columns: 1fr; }
  .top { gap: 8px 20px; padding: 0 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
