:root {
    --ink: #152331;
    --muted: #647386;
    --line: #d7e0e8;
    --bg: #f3f7fb;
    --panel: #ffffff;
    --primary: #652579;
    --primary-dark: #461955;
    --accent: #9b5bb1;
    --danger: #b42318;
    --success: #177245;
    --warning: #9a6500;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

a {
    color: inherit;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 20px;
    color: #fff;
    background: linear-gradient(90deg, var(--primary-dark), var(--primary));
    box-shadow: 0 1px 0 rgba(0,0,0,.18);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    font-size: 22px;
    font-weight: 800;
    text-decoration: none;
}

.brand img {
    width: 42px;
    height: 42px;
    border-radius: 6px;
    object-fit: contain;
    background: #fff;
}

.brand span {
    max-width: 520px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.topbar nav a {
    padding: 7px 9px;
    border-radius: 6px;
    text-decoration: none;
}

.topbar nav a:hover {
    background: rgba(255,255,255,.16);
}

.container {
    width: min(1180px, calc(100% - 28px));
    margin: 22px auto 48px;
}

h1 {
    margin: 0 0 18px;
    font-size: 26px;
}

h2 {
    margin: 0 0 10px;
    font-size: 18px;
}

.login-body {
    min-height: 100vh;
}

.login-box {
    width: min(420px, calc(100% - 28px));
    margin: 12vh auto;
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.login-logo {
    display: block;
    width: min(220px, 80%);
    max-height: 86px;
    margin: 0 auto 16px;
    object-fit: contain;
}

.public-lookup-body {
    min-height: 100vh;
    background: #111;
}

.public-lookup {
    display: grid;
    place-items: center;
    width: min(calc(100% - 28px), 240px);
    min-height: 100vh;
    margin: 0 auto;
    padding: 32px 0;
}

.public-lookup-card {
    width: 100%;
    padding: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 18px 55px rgba(70, 25, 85, .12);
}

.public-lookup-heading {
    margin-bottom: 22px;
    text-align: center;
}

.public-lookup-card,
.public-lookup-card label,
.public-lookup-card input,
.public-lookup-card button {
    text-align: center;
}

.public-lookup-heading h1 {
    margin-bottom: 8px;
    font-size: 24px;
}

.public-lookup-heading p {
    margin: 0;
    color: var(--muted);
}

.public-lookup-heading .public-lookup-kicker {
    margin-bottom: 5px;
    color: var(--primary);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .08em;
    text-transform: uppercase;
}

.public-lookup-form label {
    color: var(--ink);
    font-size: 14px;
}

.public-lookup-form input {
    min-height: 50px;
    font-size: 18px;
}

.public-lookup-form small {
    margin-top: -8px;
    color: var(--muted);
}

.public-lookup-result {
    margin-top: 20px;
}

.lookup-status {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: center;
    padding: 16px;
    border: 1px solid;
    border-radius: 9px;
    line-height: 1.35;
    text-align: center;
}

.lookup-status-icon {
    display: grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: #fff;
    font-size: 23px;
    font-weight: 800;
    margin: 0 auto;
}

.lookup-status-success {
    color: var(--success);
    background: #edf8f1;
    border-color: #add6bf;
}

.lookup-status-success .lookup-status-icon {
    background: var(--success);
}

.lookup-status-not-found {
    color: #111;
    background: #fff0ef;
    border-color: #e8b2ad;
}

.lookup-status-not-found .lookup-status-icon {
    background: #111;
}

.lookup-status-error {
    color: var(--danger);
    background: #fff0ef;
    border-color: #e8b2ad;
}

.panel,
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.stats div {
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    border-top: 4px solid var(--accent);
}

.stats span {
    display: block;
    color: var(--muted);
    font-size: 13px;
}

.stats strong {
    display: block;
    margin-top: 6px;
    font-size: 28px;
}

.operator-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, 240px);
    justify-content: center;
    gap: 16px;
    margin-bottom: 18px;
}

.operator-stats article {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 240px;
    min-height: 170px;
    padding: 22px 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-top: 4px solid var(--accent);
    border-radius: 12px;
    box-shadow: 0 12px 30px rgba(70, 25, 85, .10);
    text-align: center;
}

.operator-stats span,
.operator-stats small {
    display: block;
    color: var(--muted);
}

.operator-stats strong {
    display: block;
    margin: 12px 0 8px;
    font-size: 40px;
    line-height: 1;
}

.mesa-status-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
    margin-top: 8px;
}

.mesa-status-actions form {
    margin: 0;
}

.operator-search {
    max-width: 620px;
}

.operator-panel-page {
    display: grid;
    justify-items: center;
}

.operator-panel-page > h1,
.operator-panel-page > .alert {
    width: min(100%, 760px);
    text-align: center;
}

.operator-panel-page .operator-stats,
.operator-panel-page .operator-search,
.operator-panel-page .operator-voters {
    width: min(100%, 860px);
}

.operator-panel-page .operator-search {
    text-align: center;
}

.operator-panel-page .dni-search-form {
    width: min(100%, 560px);
    margin-right: auto;
    margin-left: auto;
    text-align: left;
}

.operator-panel-page .elector-dni-result {
    margin-right: auto;
    margin-left: auto;
    text-align: center;
}

.operator-voters h2 {
    text-align: center;
}

.operator-voters table {
    min-width: 560px;
}

.dni-search-form,
.role-new-form {
    display: grid;
    grid-template-columns: minmax(200px, 1fr) auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
}

.elector-dni-result {
    margin-top: 16px;
}

.roles-panel {
    margin-top: 18px;
}

.role-new-form {
    grid-template-columns: 180px minmax(180px, 1fr) minmax(210px, 1fr) auto;
}

.filters,
.form {
    display: grid;
    gap: 12px;
}

.filters {
    grid-template-columns: repeat(4, minmax(0, 1fr)) auto;
    align-items: end;
    margin-bottom: 18px;
}

.vote-review {
    display: grid;
    gap: 0;
    margin: 20px 0;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}

.vote-review div {
    display: grid;
    grid-template-columns: minmax(150px, 1fr) 2fr;
    gap: 16px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--line);
}

.vote-review div:last-child {
    border-bottom: 0;
}

.vote-review dt {
    color: var(--muted);
    font-weight: 700;
}

.vote-review dd {
    margin: 0;
    font-weight: 700;
}

.results-heading {
    margin-bottom: 3px;
}

.results-note,
.filtered-results-heading p {
    margin: 0 0 12px;
    color: var(--muted);
}

.filtered-results-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 16px;
}

.filtered-results-heading h2 {
    margin-bottom: 3px;
}

.group-summary {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.group-summary span {
    padding: 6px 9px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--panel);
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

.pagination-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.pagination-bar .results-note {
    margin-bottom: 0;
}

.home-filters {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    align-items: end;
}

.padron-filters {
    grid-template-columns: repeat(5, minmax(140px, 1fr)) repeat(4, auto);
}

.annulment-filters {
    grid-template-columns: repeat(4, minmax(140px, 1fr)) repeat(2, auto);
}

.logs-filters {
    grid-template-columns: repeat(3, minmax(150px, 1fr)) repeat(3, minmax(130px, 1fr)) auto;
}

.diagnostics-panel {
    margin-bottom: 18px;
}

.diagnostics-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(180px, 1fr));
    gap: 10px;
}

.diagnostics-grid div {
    padding: 11px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
}

.diagnostics-grid span {
    display: block;
    margin-bottom: 5px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.diagnostics-grid strong {
    display: block;
    font-size: 14px;
}

.mesa-filter {
    grid-column: 1 / -1;
    margin: 0;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.mesa-filter legend {
    padding: 0 5px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.mesa-check-all {
    padding-bottom: 9px;
    border-bottom: 1px solid var(--line);
}

.mesa-options {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 8px 16px;
    max-height: 180px;
    margin-top: 10px;
    overflow-y: auto;
}

.filter-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 10px;
}

.result-status {
    display: inline-flex;
    padding: 3px 7px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.result-status.has-votes {
    color: #24643f;
    background: #e4f4ea;
}

.result-status.no-votes {
    color: #755816;
    background: #fff3d5;
}

.report-selector {
    display: grid;
    grid-template-columns: minmax(260px, 1fr) auto auto;
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
}

.report-sheet {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.report-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
}

.report-header > div:last-child {
    text-align: right;
}

.report-header h2,
.report-header p,
.report-mesa h3 {
    margin: 0;
}

.report-stats {
    margin-top: 16px;
}

.mesa-results {
    margin-bottom: 18px;
}

.report-mesa {
    margin-top: 16px;
    break-inside: avoid;
    page-break-inside: avoid;
}

.report-mesa h3 {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 8px 8px 0 0;
    background: #f5eef8;
}

.report-mesa table {
    min-width: 0;
    border: 1px solid var(--line);
}

.report-summary {
    margin-bottom: 22px;
}

.report-summary table {
    min-width: 0;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 12mm;
    }

    body {
        background: #fff;
    }

    .topbar,
    .no-print,
    main.container > h1 {
        display: none !important;
    }

    .container {
        width: 100%;
        max-width: none;
        margin: 0;
    }

    .report-sheet {
        padding: 0;
        border: 0;
    }

    .report-mesa table,
    .report-mesa h3 {
        font-size: 11px;
    }

    .report-mesa th,
    .report-mesa td {
        padding: 5px 7px;
    }
}

label {
    display: grid;
    gap: 5px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

input,
select {
    width: 100%;
    min-height: 40px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
}

.multi-select {
    min-height: 150px;
}

label small {
    color: var(--muted);
    font-weight: 400;
}

.check {
    display: flex;
    align-items: center;
    gap: 9px;
}

.check input {
    width: auto;
    min-height: auto;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 8px 13px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #fff;
    color: var(--ink);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.btn.primary {
    color: #fff;
    background: var(--primary);
    border-color: var(--primary);
}

.btn.danger {
    color: #fff;
    background: var(--danger);
    border-color: var(--danger);
}

.btn.muted,
.btn:disabled {
    color: var(--muted);
    background: #eef1f3;
    cursor: default;
}

.btn.small {
    min-height: 32px;
    padding: 5px 9px;
    font-size: 13px;
}

.btn.full {
    width: 100%;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 12px;
}

.card p {
    margin: 7px 0;
    color: var(--muted);
}

.badge {
    display: inline-flex;
    margin: 6px 0 10px;
    padding: 4px 8px;
    border-radius: 6px;
    color: #fff;
    font-size: 13px;
    font-weight: 800;
}

.badge.success {
    background: var(--success);
}

.badge.danger {
    background: var(--danger);
}

.badge.warning {
    background: var(--warning);
}

.alert {
    margin: 0 0 14px;
    padding: 11px 13px;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.alert.success {
    border-color: #add6bf;
    background: #edf8f1;
}

.alert.danger {
    border-color: #e8b2ad;
    background: #fff0ef;
}

.alert.warning {
    border-color: #e6cf93;
    background: #fff8e7;
}

.table-wrap {
    overflow-x: auto;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.preview {
    margin-top: 14px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 720px;
}

th,
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    background: #f5eef8;
    font-size: 13px;
}

.sort-link {
    color: inherit;
    text-decoration: none;
}

.sort-link:hover {
    color: var(--primary);
}

tfoot th {
    color: var(--ink);
    background: #eadcf0;
    font-size: 14px;
}

.mesa-form {
    display: grid;
    grid-template-columns: 140px minmax(180px, 1fr) auto auto;
    gap: 12px;
    align-items: end;
}

.wide-table {
    min-width: 1260px;
}

.wide-table th:first-child,
.wide-table td:first-child {
    width: 90px;
}

.wide-table th:nth-child(2),
.wide-table td:nth-child(2) {
    width: 230px;
}

.wide-table th:nth-child(4),
.wide-table td:nth-child(4) {
    width: 110px;
}

.save-table-btn {
    width: 100%;
}

.compact {
    min-width: 62px;
}

.grid2 {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr);
    gap: 14px;
    align-items: start;
}

.inline-form {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 8px;
}

.user-password-form {
    grid-template-columns: minmax(160px, 1fr) auto;
    min-width: 310px;
}

.narrow-panel {
    max-width: 440px;
}

code {
    white-space: pre-wrap;
}

@media (max-width: 760px) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .topbar nav {
        justify-content: flex-start;
    }

    .brand span {
        white-space: normal;
        font-size: 16px;
        line-height: 1.2;
    }

    .stats,
    .filters,
    .diagnostics-grid,
    .grid2,
    .mesa-form {
        grid-template-columns: 1fr;
    }

    .operator-panel-page .dni-search-form {
        grid-template-columns: 1fr;
    }

    .operator-panel-page .dni-search-form .btn {
        width: 100%;
    }

    .filtered-results-heading {
        align-items: stretch;
        flex-direction: column;
        gap: 0;
    }

    .report-selector {
        grid-template-columns: 1fr;
    }

    .report-header {
        flex-direction: column;
    }

    .report-header > div:last-child {
        text-align: left;
    }

    .group-summary {
        flex-wrap: wrap;
    }

    .pagination-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .container {
        width: min(100% - 18px, 1180px);
        margin-top: 14px;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }

    .dni-search-form,
    .role-new-form {
        grid-template-columns: 1fr;
    }

    .public-lookup {
        width: min(calc(100% - 18px), 240px);
        padding: 9px 0;
    }

    .public-lookup-card {
        padding: 22px 18px;
    }
}
