:root {
    --bg: #f6f7f4;
    --surface: #ffffff;
    --surface-2: #f0f2ed;
    --border: #dfe3da;
    --text: #1c2419;
    --text-muted: #67716083;
    --muted: #6b7568;
    --accent: #3f7d3a;
    --accent-ink: #2b5827;
    --accent-soft: #e7f0e4;
    --danger: #b3261e;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 15, .06), 0 6px 20px rgba(20, 30, 15, .05);
    font-synthesis: none;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #14170f;
        --surface: #1c211a;
        --surface-2: #232922;
        --border: #333a30;
        --text: #e7ebe2;
        --text-muted: #9aa593;
        --muted: #9aa593;
        --accent: #7bb56f;
        --accent-ink: #a7d69c;
        --accent-soft: #26301f;
        --danger: #f2a29b;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    }
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; }

/* ---- top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0 1.25rem;
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    display: flex;
    align-items: center;
    gap: .55rem;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--text);
}
.brand:hover { text-decoration: none; }

.brand-mark {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: .8rem;
    font-weight: 800;
}

.topnav { display: flex; gap: 1rem; }
.topnav a { color: var(--muted); font-weight: 600; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 1rem; }

.api-status { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: var(--muted); }
.api-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #b9c0b2; }
.api-status.ok .dot { background: #3f9d3a; }
.api-status.bad .dot { background: var(--danger); }

.lang-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.lang-toggle button {
    border: 0;
    background: var(--surface);
    color: var(--muted);
    padding: .3rem .6rem;
    font-weight: 700;
    font-size: .78rem;
    cursor: pointer;
}
.lang-toggle button.active { background: var(--accent); color: #fff; }

/* ---- layout ---- */
.app { max-width: 1180px; margin: 0 auto; padding: 1.25rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }
.card-body { padding: 1rem 1.15rem; }
.card-head {
    padding: .85rem 1.15rem;
    border-bottom: 1px solid var(--border);
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: .6rem;
}

h1 { font-size: 1.4rem; margin: 0 0 .15rem; }
h2 { font-size: 1rem; margin: 0; }
.page-head { margin-bottom: 1rem; }
.page-head .sub { color: var(--muted); }

/* ---- filters ---- */
.filters { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem 1rem; }
.field { display: flex; flex-direction: column; gap: .25rem; min-width: 0; }
.field.span2 { grid-column: span 2; }
.field label { font-size: .75rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.field input, .field select {
    padding: .45rem .55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    min-width: 0;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field-inline { flex-direction: row; align-items: center; gap: .4rem; }
.field-inline label { text-transform: none; letter-spacing: 0; }

.filter-actions { display: flex; gap: .5rem; margin-top: 1rem; }

.btn {
    padding: .5rem .9rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: .3rem .55rem; font-size: .8rem; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .875rem; }
table.data th, table.data td { padding: .55rem .7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
table.data tbody tr { cursor: pointer; }
table.data tbody tr:hover { background: var(--accent-soft); }
table.data td.wrap { white-space: normal; max-width: 280px; }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge {
    display: inline-block;
    padding: .1rem .45rem;
    border-radius: 999px;
    font-size: .74rem;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--muted);
    border: 1px solid var(--border);
}
.badge.tox-I, .badge.tox-II { background: #fbe4e2; color: #8f1d16; border-color: #f2c4bf; }
.badge.tox-III { background: #fbeecd; color: #7a5a08; border-color: #f0dca3; }
.badge.tox-IV, .badge.tox-V { background: #e0f0dc; color: #2f6b2a; border-color: #c3e2ba; }
@media (prefers-color-scheme: dark) {
    .badge.tox-I, .badge.tox-II { background: #3a201d; color: #f2a29b; border-color: #5a2a25; }
    .badge.tox-III { background: #33291180; color: #e6c877; border-color: #4d3d18; }
    .badge.tox-IV, .badge.tox-V { background: #22301d; color: #9dd48f; border-color: #33452b; }
}

/* ---- pagination ---- */
.pager { display: flex; align-items: center; gap: .8rem; margin-top: .9rem; flex-wrap: wrap; }
.pager .info { color: var(--muted); }

/* ---- selection / compare bar ---- */
.selectbar {
    position: sticky;
    bottom: 0;
    margin-top: 1rem;
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .7rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* ---- detail ---- */
.breadcrumb { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; color: var(--muted); margin-bottom: .8rem; font-size: .9rem; }
.breadcrumb .sep { opacity: .5; }

dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); font-weight: 600; }
dl.kv dd { margin: 0; }
@media (max-width: 620px) { dl.kv { grid-template-columns: 1fr; gap: .1rem 0; } dl.kv dd { margin-bottom: .5rem; } }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 860px) { .detail-grid { grid-template-columns: 1fr; } .filters { grid-template-columns: 1fr 1fr; } }
@media (max-width: 560px) { .filters { grid-template-columns: 1fr; } .field.span2 { grid-column: auto; } }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; padding: .15rem .55rem; font-size: .78rem; }

.callout { padding: .8rem 1rem; border-radius: 8px; background: var(--accent-soft); border: 1px solid var(--border); }
.error { padding: .9rem 1.1rem; border-radius: 8px; background: #fbe4e2; border: 1px solid #f0c8c3; color: #8f1d16; }
@media (prefers-color-scheme: dark) { .error { background: #331e1b; border-color: #4d2a25; color: #f2a29b; } }

.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 2.5rem 1rem; color: var(--muted); }

/* ---- cadastro / API key ---- */
.app.narrow { max-width: 640px; }
.stack > * + * { margin-top: .9rem; }
.small { font-size: .85rem; }
.key-box { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.key-box code { flex: 1; min-width: 0; overflow-wrap: anywhere; font-size: .85rem; }
.code-block { margin: 0; padding: .7rem .8rem; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); font-size: .8rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.key-input { width: 11rem; padding: .3rem .5rem; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font-size: .8rem; }
