:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e3e6ea;
    --text: #1d2430;
    --muted: #6b7482;
    --accent: #2f6fde;
    --accent-soft: #e8f0fd;
    --code-bg: #0f1722;
    --code-text: #d9e1ec;
    --radius: 8px;

    --blue-bg: #e6efff;   --blue-fg: #1f56c2;
    --green-bg: #e3f6ea;  --green-fg: #1b7a3f;
    --red-bg: #fde8e8;    --red-fg: #b42323;
    --orange-bg: #fff0e0; --orange-fg: #b35a00;
    --yellow-bg: #fdf6d8; --yellow-fg: #8a6a00;
    --teal-bg: #def5f3;   --teal-fg: #0e7268;
    --purple-bg: #efe8fd; --purple-fg: #6236c4;
    --gray-bg: #eceef1;   --gray-fg: #4f5866;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #11151b;
        --surface: #181d25;
        --surface-2: #1d232c;
        --border: #2a313c;
        --text: #e5e9ef;
        --muted: #8e98a7;
        --accent: #6a9cf5;
        --accent-soft: #1d2a42;
        --code-bg: #0b0f15;

        --blue-bg: #1b2a47;   --blue-fg: #8db4ff;
        --green-bg: #15321f;  --green-fg: #74d39a;
        --red-bg: #3a1a1c;    --red-fg: #ff9a9a;
        --orange-bg: #3a2614; --orange-fg: #ffb870;
        --yellow-bg: #362e12; --yellow-fg: #f0d264;
        --teal-bg: #123331;   --teal-fg: #6fd8cc;
        --purple-bg: #2a1f45; --purple-fg: #bda2ff;
        --gray-bg: #262c35;   --gray-fg: #b3bcc8;
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.topbar .inner {
    max-width: 1400px; margin: 0 auto; padding: 14px 24px;
    display: flex; align-items: center; gap: 12px;
}
.brand { font-weight: 650; font-size: 16px; color: var(--text); }
.brand small { color: var(--muted); font-weight: 400; margin-left: 6px; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 15px; margin: 0 0 12px; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
}
.card-body { padding: 16px 18px; }
.card-header {
    padding: 12px 18px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
}
.card-header h2 { margin: 0; }

/* Estatísticas */
.stats { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; }
.stat {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 10px 14px; min-width: 120px; color: var(--text);
}
.stat:hover { text-decoration: none; border-color: var(--accent); }
.stat .n { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12px; }
.stats-caption { color: var(--muted); font-size: 12px; margin: -12px 0 12px; }

/* Filtros */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filters .grow { flex: 1 1 260px; }
input, select {
    font: inherit; color: var(--text); background: var(--surface-2);
    border: 1px solid var(--border); border-radius: 6px; padding: 7px 10px; min-height: 36px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.btn {
    font: inherit; border: 1px solid var(--accent); background: var(--accent); color: #fff;
    border-radius: 6px; padding: 7px 14px; min-height: 36px; cursor: pointer;
}
.btn.secondary { background: transparent; color: var(--accent); }
.btn:hover { text-decoration: none; filter: brightness(1.05); }

/* Tabela */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--surface-2); white-space: nowrap; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--accent-soft); }
tbody tr:last-child td { border-bottom: 0; }
td.mono, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
td.nowrap { white-space: nowrap; }
/* Lista de e-mails: larguras automáticas; textos longos quebram em vez de serem cortados. */
table.email-list td.text { overflow-wrap: break-word; }
table.email-list td.text:nth-child(2) { min-width: 18ch; }
table.email-list .nw { white-space: nowrap; }
.muted { color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* Badges */
.badge {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge.blue { background: var(--blue-bg); color: var(--blue-fg); }
.badge.green { background: var(--green-bg); color: var(--green-fg); }
.badge.red { background: var(--red-bg); color: var(--red-fg); }
.badge.orange { background: var(--orange-bg); color: var(--orange-fg); }
.badge.yellow { background: var(--yellow-bg); color: var(--yellow-fg); }
.badge.teal { background: var(--teal-bg); color: var(--teal-fg); }
.badge.purple { background: var(--purple-bg); color: var(--purple-fg); }
.badge.gray { background: var(--gray-bg); color: var(--gray-fg); }

/* Paginação */
.pagination { display: flex; justify-content: space-between; align-items: center; padding: 12px 18px; border-top: 1px solid var(--border); gap: 12px; flex-wrap: wrap; }
.pagination .pages { display: flex; gap: 6px; }

/* Detalhes */
.back { display: inline-block; margin-bottom: 14px; }
.detail-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-head h1 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 20px; }
@media (max-width: 980px) { .grid-2 { grid-template-columns: 1fr; } }

dl.kv { display: grid; grid-template-columns: 200px minmax(0, 1fr); margin: 0; }
dl.kv dt, dl.kv dd { padding: 8px 0; border-bottom: 1px solid var(--border); margin: 0; }
dl.kv dt { color: var(--muted); font-size: 13px; padding-right: 12px; }
dl.kv dd { word-break: break-word; }
dl.kv > :nth-last-child(-n+2) { border-bottom: 0; }
@media (max-width: 640px) { dl.kv { grid-template-columns: 1fr; } dl.kv dt { border-bottom: 0; padding-bottom: 0; } }

dl.kv dl.kv { grid-template-columns: minmax(80px, max-content) minmax(0, 1fr); column-gap: 16px; padding-left: 12px; border-left: 2px solid var(--border); }
dl.kv dl.kv dt { padding-right: 0; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
    content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px;
    border-radius: 50%; background: var(--surface); border: 2px solid var(--muted);
}
.timeline li.current::before { background: var(--accent); border-color: var(--accent); }
.timeline .when { color: var(--muted); font-size: 12px; }

pre.json {
    margin: 0; padding: 16px 18px; background: var(--code-bg); color: var(--code-text);
    border-radius: 0 0 var(--radius) var(--radius); overflow: auto; max-height: 560px;
    font: 12.5px/1.55 ui-monospace, "Cascadia Code", Consolas, monospace;
}
.tabs { display: flex; gap: 6px; }
.tabs button {
    font: inherit; font-size: 13px; background: transparent; color: var(--muted);
    border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
.tabs button[aria-selected="true"] { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

@media (max-width: 640px) {
    main { padding: 16px; }
    .topbar .inner { padding: 12px 16px; }
}

/* Navegação e menu do usuário */
.nav { display: flex; gap: 4px; margin-left: 16px; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 6px; }
.nav a:hover { text-decoration: none; color: var(--text); background: var(--surface-2); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.user-menu { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13px; }
.user-menu form { margin: 0; }
.link-button { font: inherit; background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link-button:hover { text-decoration: underline; }
.link-button.danger { color: var(--red-fg); }

/* Alertas e formulários */
.alert { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; }
.alert.success { background: var(--green-bg); color: var(--green-fg); }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.card.narrow { max-width: 520px; }
.form { display: flex; flex-direction: column; gap: 14px; }
.form > label, .fieldset > label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }
.form input[type="text"], .form input[type="email"], .form input[type="password"] { width: 100%; }
.form input[aria-invalid="true"] { border-color: var(--red-fg); }
.form label.check, .fieldset label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
.form label.check input { min-height: 0; width: 16px; height: 16px; }
.field-error { color: var(--red-fg); font-size: 13px; margin: -8px 0 0; }
.hint { color: var(--muted); font-size: 12px; }
.fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0; display: flex; flex-direction: column; gap: 10px; }
.fieldset legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
.fieldset:disabled { opacity: .65; }
.form-actions { display: flex; gap: 10px; }
.btn.block { width: 100%; }
td.actions { display: flex; gap: 14px; align-items: center; }
td.actions form { margin: 0; }

/* Página de login */
.auth-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-box { width: 100%; max-width: 380px; padding: 0; margin: 0; }
.auth-brand { text-align: center; margin-bottom: 16px; font-size: 18px; }
.auth-box h1 { margin-bottom: 12px; }
.auth-foot { text-align: center; font-size: 12px; }

@media (max-width: 640px) {
    .topbar .inner { flex-wrap: wrap; }
    .nav { margin-left: 0; order: 3; width: 100%; }
}
