:root {
    --bg: #f3f5fa;
    --panel: #ffffff;
    --text: #131a2c;
    --muted: #667085;
    --muted-light: #98a2b3;
    --border: #e6e9f0;
    --border-strong: #d3d9e6;

    --primary: #2b58e0;
    --primary-dark: #1c3fa8;
    --primary-light: #eef2ff;
    --primary-ring: rgba(43, 88, 224, 0.18);

    --good: #12805c;
    --good-bg: #e7f8f1;
    --bad: #c0362c;
    --bad-bg: #fdedec;
    --warning: #9a6700;
    --warning-bg: #fff6e0;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;

    --shadow-sm: 0 1px 2px rgba(19, 26, 44, 0.05), 0 1px 1px rgba(19, 26, 44, 0.03);
    --shadow-md: 0 8px 24px rgba(19, 26, 44, 0.08), 0 2px 6px rgba(19, 26, 44, 0.04);
    --shadow-lg: 0 16px 40px rgba(19, 26, 44, 0.12);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, Arial, sans-serif;
    font-size: 15.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: min(1180px, calc(100% - 20px));
    margin: 0 auto;
}

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Header & Nav ---------- */
.topbar {
    background: #0d1526;
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.nav-wrap {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 58px;
    padding: 0 16px;
}

.brand {
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 17px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 9px;
    letter-spacing: -0.01em;
}

.brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--primary), #6d8ffb);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-mark svg {
    width: 17px;
    height: 17px;
}

.nav-toggle {
    background: rgba(255,255,255,0.06);
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    border-radius: 10px;
}

.nav-toggle:hover { background: rgba(255,255,255,0.12); }
.nav-toggle svg { width: 20px; height: 20px; }

.topbar nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #0d1526;
    flex-direction: column;
    gap: 2px;
    padding: 8px 10px 14px;
    border-top: 1px solid rgba(255,255,255,0.08);
    box-shadow: var(--shadow-lg);
}

.topbar nav.active { display: flex; }

.topbar nav a {
    color: #cbd2e1;
    text-decoration: none;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
}

.topbar nav a svg { width: 18px; height: 18px; opacity: 0.85; flex-shrink: 0; }

.topbar nav a:hover { color: #fff; background: rgba(255,255,255,0.06); }

.topbar nav a.active {
    color: #fff;
    background: var(--primary);
}

/* ---------- Main content ---------- */
.page { padding: 18px 0 44px; }

/* ---------- Hero ---------- */
.hero {
    margin-bottom: 18px;
}

.hero h1 {
    margin: 0 0 6px;
    font-size: 22px;
}

.hero p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    max-width: 60ch;
}

/* ---------- Forms ---------- */
.search-panel, .panel {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: var(--shadow-sm);
}

.search-panel {
    background: linear-gradient(180deg, #ffffff 0%, #fbfcff 100%);
}

.search-panel label {
    display: block;
    font-weight: 600;
    margin-bottom: 7px;
    font-size: 13.5px;
    color: var(--text);
}

.search-panel small, .metric small {
    display: block;
    color: var(--muted-light);
    margin-top: 7px;
    font-size: 12px;
}

.search-row {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.search-panel input,
.search-panel select {
    width: 100%;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font: inherit;
    background: #fff;
    min-height: 46px;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.search-panel input::placeholder { color: var(--muted-light); }

.search-panel input:focus,
.search-panel select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-ring);
}

.search-panel button {
    border: 0;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border-radius: var(--radius-sm);
    padding: 13px 18px;
    font-weight: 700;
    font-size: 14.5px;
    cursor: pointer;
    min-height: 46px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: 0 4px 14px rgba(43, 88, 224, 0.28);
    transition: transform 0.1s ease, box-shadow 0.15s ease, filter 0.15s ease;
}

.search-panel button:hover { filter: brightness(1.06); }
.search-panel button:active { transform: translateY(1px); }

.search-panel button:disabled {
    background: var(--muted-light);
    box-shadow: none;
    cursor: not-allowed;
}

.form-grid { display: grid; gap: 12px; margin-bottom: 12px; }
.form-grid.two { grid-template-columns: 1fr; }
.form-grid.three { grid-template-columns: 1fr; }
.date-range { display: grid; grid-template-columns: 1fr; gap: 10px; }

/* ---------- Summary metrics ---------- */
.summary-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.metric {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    box-shadow: var(--shadow-sm);
}

.metric span {
    color: var(--muted);
    display: block;
    font-size: 11.5px;
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

.metric strong {
    display: block;
    font-size: 21px;
    margin-bottom: 2px;
    letter-spacing: -0.01em;
}

.metric.highlight {
    background: linear-gradient(135deg, var(--primary-light), #ffffff);
    border-color: #dbe4ff;
}

/* ---------- Sections ---------- */
.section-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-title h2 {
    font-size: 16.5px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title > span {
    color: var(--muted);
    font-size: 12px;
    background: var(--bg);
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    font-weight: 600;
}

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; }

th, td { text-align: left; padding: 10px; vertical-align: top; }

th {
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1.5px solid var(--border);
    font-weight: 700;
}

td { border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: 0; }

/* Data table -> cards en mobile */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { display: none; }

.data-table tbody tr {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    margin-bottom: 12px;
    box-shadow: var(--shadow-sm);
}

.data-table tbody tr:last-child { margin-bottom: 0; }

.data-table td {
    display: block;
    padding: 7px 0;
    border: none;
    text-align: left;
}

.data-table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--muted-light);
    font-size: 10.5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 3px;
}

/* ---------- Status badges ---------- */
.status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 11px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 12px;
}

.s0 { color: var(--muted); background: #edf0f5; }
.s1 { color: var(--good); background: var(--good-bg); }
.s2 { color: var(--warning); background: var(--warning-bg); }
.s3, .s4, .s5, .s6 { color: var(--bad); background: var(--bad-bg); }

/* ---------- Chips ---------- */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 11px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}

.chip-ok, .chip-fine-paid { color: var(--good); background: var(--good-bg); }
.chip-pending { color: var(--warning); background: var(--warning-bg); }
.chip-fine-due { color: var(--bad); background: var(--bad-bg); }

/* ---------- Alerts ---------- */
.alert {
    border-radius: var(--radius-sm);
    padding: 14px 16px;
    margin-bottom: 16px;
    font-size: 14px;
    display: flex;
    align-items: flex-start;
    gap: 11px;
}

.alert::before {
    flex-shrink: 0;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 800;
}

.alert.error {
    background: var(--bad-bg);
    color: var(--bad);
    border: 1px solid #f6cfc9;
}
.alert.error::before { content: "!"; background: #f6cfc9; color: var(--bad); }

.alert.neutral {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}
.alert.neutral::before { content: "i"; background: var(--border-strong); color: var(--muted); }

.alert.success {
    background: var(--good-bg);
    color: var(--good);
    border: 1px solid #b9e8d3;
}
.alert.success::before { content: "✓"; background: #b9e8d3; color: var(--good); }

.alert strong { display: block; margin-bottom: 3px; }
.alert > div { flex: 1; }

/* ---------- Empty state ---------- */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--muted);
}

.empty-state .empty-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto 14px;
    border-radius: 50%;
    background: var(--bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted-light);
}

.empty-state .empty-icon svg { width: 24px; height: 24px; }

.empty-state p {
    margin: 0;
    font-size: 14px;
}

.empty {
    color: var(--muted);
    margin: 12px 0;
    font-size: 14px;
}

/* ---------- Result banner ---------- */
.result-banner {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 20px;
    border-radius: var(--radius-md);
    margin-bottom: 16px;
    font-size: 14px;
}

.result-banner strong {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 19px;
    letter-spacing: -0.01em;
}

.result-banner.good { background: var(--good-bg); color: var(--good); }
.result-banner.bad { background: var(--bad-bg); color: var(--bad); }
.result-banner span { font-size: 13px; opacity: 0.85; }

/* ---------- Details/collapsible ---------- */
details > summary {
    cursor: pointer;
    font-weight: 600;
    padding: 4px 0;
    color: var(--primary);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    gap: 6px;
}

details > summary::-webkit-details-marker { display: none; }

details > summary::before {
    content: "▸";
    font-size: 11px;
    transition: transform 0.15s ease;
}

details[open] > summary::before { transform: rotate(90deg); }

details > summary:hover { opacity: 0.8; }
details[open] > summary { margin-bottom: 12px; }

/* ---------- Combobox ---------- */
.combobox-wrapper { position: relative; }

.combobox-input {
    width: 100%;
    border: 1.5px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0 6px 0 14px;
    font: inherit;
    background: #fff;
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.combobox-wrapper:focus-within .combobox-input {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-ring);
}

.combobox-input input {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    flex: 1;
    min-height: 46px;
    width: 100%;
    color: var(--text);
}

.combobox-input input::placeholder { color: var(--muted-light); }
.combobox-input input:focus { outline: none; }

.combobox-clear {
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    padding: 6px 9px;
    font-size: 15px;
    flex-shrink: 0;
    border-radius: 6px;
}

.combobox-clear:hover { color: var(--text); background: var(--bg); }

.combobox-list {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    max-height: 220px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 10;
    display: none;
    box-shadow: var(--shadow-md);
    padding: 6px;
}

.combobox-list.active { display: block; }

.combobox-option {
    padding: 10px 11px;
    cursor: pointer;
    font-size: 14px;
    border-radius: 8px;
}

.combobox-option:hover, .combobox-option.active { background: var(--primary-light); }

.combobox-option-label { display: block; font-weight: 500; color: var(--text); }
.combobox-option-code { display: block; font-size: 11.5px; color: var(--muted-light); margin-top: 1px; }

/* ---------- Loading spinner ---------- */
.spinner {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.spinner::before {
    content: '';
    width: 15px;
    height: 15px;
    border: 2.5px solid rgba(255,255,255,0.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-text { color: #fff; font-size: 14px; font-weight: 700; }

/* ---------- Data pair rows (transparencia) ---------- */
.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.field-row:last-child { border-bottom: none; }

.field-row .field-label {
    color: var(--muted);
    font-weight: 600;
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.field-row .field-value { font-size: 14.5px; word-break: break-word; }

.result-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: 14px;
    background: var(--panel);
}

.result-card:first-of-type { margin-top: 0; }

.result-card-title {
    display: block;
    margin-bottom: 6px;
    font-size: 15px;
    font-weight: 700;
}

/* ---------- Utilities ---------- */
code {
    background: var(--bg);
    padding: 2px 6px;
    border-radius: 5px;
    font-size: 13px;
}

.panel a, .hero a, .methodology a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 600;
}

.panel a:hover, .hero a:hover, .methodology a:hover {
    text-decoration: underline;
}

.long-text { white-space: pre-line; line-height: 1.65; font-size: 14px; }
.wide { max-height: 600px; overflow-y: auto; }

/* ---------- Footer ---------- */
.footer {
    padding: 22px 0 30px;
    color: var(--muted-light);
    font-size: 12.5px;
    border-top: 1px solid var(--border);
    margin-top: 24px;
    text-align: center;
}

/* ---------- Variable list cards ---------- */
.variable-card {
    display: block;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 12px;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow-sm);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.variable-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.variable-card:last-child { margin-bottom: 0; }

.variable-card-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    margin-bottom: 8px;
    display: block;
}

.variable-card-value {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 10px;
}

.variable-card-value strong { font-size: 19px; }
.variable-card-value span { font-size: 12.5px; color: var(--muted); }

.variable-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag {
    display: inline-flex;
    align-items: center;
    padding: 4px 9px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
}

/* ---------- Methodologies ---------- */
.methodologies { display: flex; flex-direction: column; gap: 14px; }

.methodology {
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 16px;
    background: var(--panel);
}

.methodology p { margin: 8px 0; font-size: 14px; }
.methodology strong { display: block; }

/* ---------- Tablet breakpoint ---------- */
@media (min-width: 768px) {
    .container { width: min(1180px, calc(100% - 32px)); }

    .nav-wrap {
        align-items: center;
        flex-direction: row;
        min-height: 66px;
        padding: 0 32px;
    }

    .nav-toggle { display: none; }

    .topbar nav {
        display: flex;
        position: static;
        background: none;
        flex-direction: row;
        gap: 4px;
        padding: 0;
        border-top: none;
        box-shadow: none;
        margin-left: auto;
    }

    .topbar nav a {
        color: #cbd2e1;
        padding: 9px 13px;
        font-size: 13.5px;
    }

    .topbar nav a svg { width: 16px; height: 16px; }

    .topbar nav a:hover { color: #fff; background: rgba(255,255,255,0.08); }
    .topbar nav a.active { color: #fff; background: var(--primary); }

    .page { padding: 40px 0 56px; }

    .hero {
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        gap: 24px;
        margin-bottom: 26px;
    }

    .hero h1 { font-size: 30px; }
    .hero p { font-size: 14.5px; }

    .summary-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; }

    .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid.three { grid-template-columns: 1.3fr 1.3fr 1.4fr; }
    .date-range { grid-template-columns: 1fr 1fr; }

    .search-row { flex-direction: row; align-items: center; }
    .search-panel button { width: auto; }

    .search-panel, .panel { padding: 24px; }

    .data-table thead { display: table-header-group; }

    .data-table tbody tr {
        display: table-row;
        background: none;
        border: none;
        border-radius: 0;
        padding: 0;
        margin-bottom: 0;
        box-shadow: none;
    }

    .data-table td {
        display: table-cell;
        border-bottom: 1px solid var(--border);
        padding: 12px 10px;
        text-align: left;
    }

    .data-table td::before { display: none; }
    tbody tr:last-child td { border-bottom: 0; }

    .field-row { grid-template-columns: 190px 1fr; align-items: baseline; gap: 12px; }

    .variable-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
    .variable-card-title { margin-bottom: 4px; }
    .variable-card-value { margin-bottom: 4px; }
}

/* ---------- Small mobile ---------- */
@media (max-width: 374px) {
    .container { width: calc(100% - 12px); }
    .nav-wrap { padding: 0 12px; }
    body { font-size: 14.5px; }
    .hero h1 { font-size: 20px; }
    .metric strong { font-size: 18px; }
}
