:root {
    --bg: #dbdbdb;
    --surface: #ffffff;
    --text: #111827;
    --muted: #666666;
    --primary: #1585c2;
    --danger: #b91c1c;
    --ok: #166534;
    --border: #c7c7c7;
    --table-head: #1585c2;
    --table-success: #8ee18f;
    --avatar: #dbdbdb;
    --badge: #ff4d0f;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.narrow {
    max-width: 420px;
}

.layout-two-col {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.email-local-wrap {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.email-local-wrap input {
    flex: 1;
}

.email-domain-fixed {
    font-weight: 600;
    color: #4b5563;
    white-space: nowrap;
}

.admin-layout {
    display: grid;
    gap: 1rem;
    grid-template-columns: 220px minmax(0, 1fr);
    align-items: start;
}

.admin-sidebar {
    position: sticky;
    top: 1rem;
}

.admin-sidebar h2 {
    margin-top: 0;
}

.admin-nav {
    display: grid;
    gap: 0.5rem;
}

.admin-nav-link {
    display: block;
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border);
    background: #efefef;
    padding: 0.6rem 0.7rem;
    border-radius: 4px;
    font-weight: 600;
}

.admin-nav-link.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.status-panel h2 {
    margin-top: 0;
}

.status-grid {
    display: grid;
    gap: 0.9rem;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.status-block {
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.75rem;
    background: #f9f9f9;
}

.status-block-wide {
    grid-column: 1 / -1;
}

.status-block h3 {
    margin: 0 0 0.55rem;
}

.status-list {
    margin: 0;
}

.status-omie-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    column-gap: 1.2rem;
    align-items: start;
}

.status-item {
    display: grid;
    grid-template-columns: 150px minmax(0, 1fr);
    gap: 0.35rem 0.75rem;
    align-items: baseline;
    margin-bottom: 0.45rem;
}

.status-list-side .status-item {
    grid-template-columns: 220px minmax(0, 1fr);
}

.status-list-side .status-item dt,
.status-list-side .status-item dd {
    white-space: nowrap;
}

.status-item dt {
    font-weight: 600;
    color: #4b5563;
}

.status-item dd {
    margin: 0;
    word-break: break-word;
}

.status-value-with-action {
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.35rem;
}

.icon-action-btn {
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.icon-action-btn:hover {
    background: transparent;
    color: inherit;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.16rem 0.45rem;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.status-ok {
    color: #0f5132;
    background: #d1e7dd;
    border-color: #a3cfbb;
}

.status-success {
    color: #166534;
    background: #dcfce7;
    border-color: #86efac;
}

.status-error {
    color: #842029;
    background: #f8d7da;
    border-color: #f1aeb5;
}

.status-neutral {
    color: #374151;
    background: #e5e7eb;
    border-color: #d1d5db;
}

@media (max-width: 900px) {
    .status-grid {
        grid-template-columns: 1fr;
    }

    .status-block-wide {
        grid-column: auto;
    }

    .status-omie-layout {
        grid-template-columns: 1fr;
    }

    .status-list-side .status-item {
        grid-template-columns: 150px minmax(0, 1fr);
    }

    .status-list-side .status-item dt,
    .status-list-side .status-item dd {
        white-space: normal;
    }
}

.admin-user-filters {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 180px 180px auto;
    gap: 0.6rem;
    align-items: end;
    margin-bottom: 0.85rem;
}

.months-table .current-month-row td {
    background: #fff3c4;
}

.months-table .actions-col {
    width: 42px;
}

.months-table th:first-child,
.months-table td:first-child {
    text-align: center;
}

.months-table .month-last-date {
    white-space: nowrap;
    text-align: center;
    width: 125px;
    font-size: 0.82rem;
    color: #8a8f99;
}

.months-table .month-prediction-count {
    white-space: nowrap;
    text-align: center;
    width: 70px;
    font-size: 0.82rem;
    color: #8a8f99;
}

.months-table .month-last-date-head {
    font-size: 0.82rem;
    color: #8a8f99;
    font-weight: 500;
}

.month-state-form {
    display: inline-flex;
    align-items: center;
}

.month-lock-btn {
    width: 28px;
    height: 24px;
    min-width: 28px;
    padding: 0.1rem 0.2rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #4b5563;
}

.month-lock-btn .bi {
    font-size: 1rem;
    line-height: 1;
}

.month-lock-btn:hover {
    border-color: #d1d5db;
    background: #f3f4f6;
}

.month-actions {
    position: relative;
    display: inline-flex;
}

.month-actions-btn {
    width: 30px;
    height: 24px;
    min-width: 30px;
    padding: 0.1rem 0.2rem;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: #4b5563;
}

.month-actions-btn:hover {
    border-color: #d1d5db;
    background: #f3f4f6;
}

.month-actions-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    min-width: 205px;
    background: #fff;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
    padding: 0.2rem;
    z-index: 20;
}

.month-actions-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border: 0;
    background: transparent;
    color: #111827;
    padding: 0.32rem 0.4rem;
    border-radius: 4px;
    text-align: left;
    font-size: 0.78rem;
    line-height: 1.1;
    white-space: nowrap;
}

.month-actions-item:hover {
    background: #f3f4f6;
}

.month-actions-item.is-danger {
    color: var(--danger);
}

.month-actions-item.is-danger:hover {
    background: #fee2e2;
}

.month-actions-form {
    margin: 0;
}

.month-state-text {
    color: #6b7280;
    font-size: 0.82rem;
    text-align: right;
}

.inline-form {
    display: inline;
}

.status-toggle {
    width: 36px;
    height: 20px;
    padding: 0;
    position: relative;
    border: 2px solid #0fb64f;
    border-radius: 999px;
    background: #22c55e;
}

.status-toggle.is-active {
    background: #22c55e;
    border-color: #16a34a;
}

.status-toggle.is-inactive {
    background: #9ca3af;
    border-color: #6b7280;
}

.status-toggle::after {
    content: "";
    position: absolute;
    top: 1px;
    left: 1px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #e5e7eb;
    border: 1px solid #9ca3af;
    transition: transform 0.2s ease;
}

.status-toggle.is-active::after {
    transform: translateX(16px);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.card {
    background: #f4f4f4;
    border: 1px solid var(--border);
    border-radius: 0;
    padding: 1rem;
}

.form-grid {
    display: grid;
    gap: 0.75rem;
}

label {
    display: grid;
    gap: 0.35rem;
    font-weight: 600;
}

input, button, select {
    font: inherit;
    padding: 0.55rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 4px;
}

button, .button-link {
    background: var(--primary);
    color: #fff;
    border: 1px solid var(--primary);
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
}

button:disabled,
button[disabled] {
    opacity: 0.55;
    cursor: not-allowed;
}

.ghost {
    background: transparent;
    color: var(--text);
}

.danger {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
}

.row {
    display: flex;
    align-items: center;
}

.space-between {
    justify-content: space-between;
}

.gap-sm {
    gap: 0.5rem;
}

.top-space {
    margin-top: 1rem;
}

.muted {
    color: var(--muted);
}

.error {
    color: var(--danger);
    font-weight: 600;
}

.success {
    color: var(--ok);
    font-weight: 600;
}

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

th, td {
    border-bottom: 1px solid var(--border);
    padding: 0.5rem;
    text-align: left;
}

.open-submissions-table td:nth-child(2) {
    text-align: center;
    padding-left: 0.3rem;
}

.mail-body {
    background: var(--bg);
}

.mail-shell {
    padding-top: 0.75rem;
}

.mail-header {
    margin-bottom: 1rem;
}

.mail-title-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.mail-title-row h1 {
    margin: 0;
    font-size: 1.9rem;
    letter-spacing: 0.2px;
}

.mail-actions {
    position: relative;
}

.header-icon-link,
.header-icon-btn {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid transparent;
    border-radius: 6px;
    background: transparent;
    color: #374151;
    text-decoration: none;
    padding: 0;
}

.header-icon-link .bi,
.header-icon-btn .bi {
    font-size: 1.2rem;
    line-height: 1;
}

.header-icon-link:hover,
.header-icon-btn:hover {
    border-color: #d1d5db;
    background: #f3f4f6;
    color: #111827;
}

.header-icon-link:focus-visible,
.header-icon-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.user-menu-wrap {
    position: relative;
    display: inline-flex;
}

.user-menu-popover {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 190px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    padding: 0.35rem;
    z-index: 30;
}

.user-menu-name {
    padding: 0.45rem 0.55rem;
    color: #6b7280;
    font-size: 0.88rem;
    font-weight: 600;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 0.25rem;
}

.user-menu-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
    color: #111827;
    border-radius: 6px;
    padding: 0.45rem 0.55rem;
}

.user-menu-item:hover {
    background: #f3f4f6;
}

.user-menu-link {
    display: block;
    text-decoration: none;
}

.user-actions-col {
    width: 60px;
    text-align: center;
}

.user-edit-btn {
    width: 28px;
    height: 28px;
    min-width: 28px;
    padding: 0;
    border-radius: 4px;
    border: 1px solid transparent;
    background: transparent;
    color: #4b5563;
}

.user-edit-btn:hover {
    border-color: #d1d5db;
    background: #f3f4f6;
    color: #111827;
}

.profile-static-value {
    margin: 0;
    padding: 0.55rem 0.1rem;
    color: #111827;
}

.static-field {
    display: grid;
    gap: 0.35rem;
}

.static-field-value {
    margin: 0;
    padding: 0.55rem 0.65rem;
    min-height: 2.35rem;
    display: flex;
    align-items: center;
    color: #111827;
    font: inherit;
    background: #efefef;
    border: 1px solid var(--border);
    border-radius: 4px;
}

.edit-enabled-row {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.35rem;
}

.edit-enabled-label {
    font-size: 0.92rem;
    color: #374151;
    font-weight: 600;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.8rem;
    flex-wrap: wrap;
    width: 100%;
}

.add-value-btn {
    margin-left: auto;
}

.month-label {
    font-weight: 700;
    margin: 0;
}

.month-nav-group {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    align-self: center;
}

.month-nav-btn {
    width: 24px;
    height: 24px;
    min-width: 24px;
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: #6b7280;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 0.8;
    font-size: 2rem;
    font-weight: 400;
    margin: 0;
    vertical-align: middle;
}

.month-nav-btn:hover {
    background: transparent;
    color: #374151;
}

.month-nav-btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

.month-nav-group input[type="month"] {
    min-width: 145px;
}

.board-grid {
    display: grid;
    grid-template-columns: 1fr 250px;
    gap: 1rem;
}

.porra-table th {
    background: var(--table-head);
    color: #fff;
    font-weight: 700;
    text-align: center;
    padding: 0.45rem 0.3rem;
}

.porra-table td {
    background: #efefef;
    border: 1px solid var(--border);
    text-align: center;
    padding: 0.35rem 0.3rem;
}

.porra-table th:nth-child(2),
.porra-table td:nth-child(2) {
    width: 38%;
}

.porra-table td:nth-child(2) {
    text-align: left;
    padding-left: 0.6rem;
}

.estado-pos {
    background: var(--table-success) !important;
    font-weight: 700;
}

.estado-neg {
    background: #f28b8b !important;
    font-weight: 700;
}

.board-side {
    display: grid;
    gap: 1rem;
    align-content: start;
}

.meta-table {
    border: 1px solid var(--border);
    background: #efefef;
}

.meta-table th,
.meta-table td {
    border: 1px solid var(--border);
    background: #efefef;
    text-align: left;
    white-space: nowrap;
}

.meta-table th {
    width: 75%;
    font-weight: 700;
}

.meta-table td {
    text-align: right;
}

.mini-ranking h3 {
    margin: 0 0 0.5rem;
    text-align: center;
}

.mini-ranking table {
    border: 1px solid var(--border);
    background: #efefef;
}

.mini-ranking td {
    border: 0;
    border-bottom: 1px solid var(--border);
    background: #efefef;
    padding: 0.35rem 0.5rem;
}

.mini-ranking td:first-child {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.side-rank-badge {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 999px;
    background: var(--badge);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}

.chart-box {
    margin-top: 1rem;
    padding: 0.75rem;
}

.ranking-chart {
    width: 100%;
    min-height: 320px;
    display: block;
}

.prediction-dialog {
    width: min(460px, 92vw);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0;
}

.prediction-dialog::backdrop {
    background: rgba(0, 0, 0, 0.35);
}

.dialog-form {
    padding: 1rem;
    display: grid;
    gap: 0.75rem;
    background: #f2f2f2;
}

.dialog-form h2 {
    margin: 0;
}

.add-prediction-dialog {
    overflow-x: hidden;
}

.add-prediction-dialog .dialog-form {
    overflow-x: hidden;
}

.add-prediction-dialog .dialog-form label {
    min-width: 0;
}

.add-prediction-dialog .dialog-form input,
.add-prediction-dialog .dialog-form select {
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

.modal-month-label {
    margin: -0.35rem 0 0.25rem;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

@media (max-width: 980px) {
    .admin-layout {
        grid-template-columns: 1fr;
    }

    .admin-sidebar {
        position: static;
    }

    .admin-user-filters {
        grid-template-columns: 1fr;
    }

    .header-controls {
        justify-content: flex-start;
        flex-wrap: wrap;
    }

    .add-value-btn {
        margin-left: 0;
    }

    .month-nav-group {
        width: 100%;
    }

    .month-nav-group input[type="month"] {
        flex: 1;
    }

    .board-grid {
        grid-template-columns: 1fr;
    }

    .mail-title-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .mail-actions {
        align-self: flex-end;
    }
}
