:root {
    --portal-bg: #f3f7f5;
    --portal-ink: #172d26;
    --portal-muted: #506358;
    --portal-accent: #176447;
    --portal-border: #dce7e0;
}

body { display: flex; flex-direction: column; min-height: 100dvh; background: var(--portal-bg); color: var(--portal-ink); }
[hidden] { display: none !important; }
a { color: var(--portal-accent); }
h1 { font-size: clamp(1.85rem, 4vw, 2.65rem); font-weight: 700; letter-spacing: -.035em; }
h2 { font-size: 1.3rem; font-weight: 650; }
.subtitle { color: var(--portal-muted); margin-bottom: 1.5rem; }
.btn-primary {
    --bs-btn-bg: #176447; --bs-btn-border-color: #176447;
    --bs-btn-hover-bg: #104d36; --bs-btn-hover-border-color: #104d36;
    --bs-btn-active-bg: #104d36; --bs-btn-active-border-color: #104d36;
    --bs-btn-disabled-bg: #176447; --bs-btn-disabled-border-color: #176447;
}
.btn-outline-primary {
    --bs-btn-color: #176447; --bs-btn-border-color: #176447;
    --bs-btn-hover-bg: #176447; --bs-btn-hover-border-color: #176447;
    --bs-btn-active-bg: #176447; --bs-btn-active-border-color: #176447;
}
:focus-visible { outline: 3px solid #36876a; outline-offset: 3px; }
.portal-header :focus-visible { outline-color: #b2ebd5; }

.portal-header { position: sticky; top: 0; z-index: 1020; background: #142f26; color: white; }
.portal-main :is(a, button, input, select, textarea, summary) { scroll-margin-top: 7rem; }
.portal-nav, .nav-links, .nav-account { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; }
.portal-nav { min-height: 4.2rem; padding-block: .75rem; }
.portal-nav a { color: #e9f5ef; text-decoration: none; }
.nav-links a { border-radius: .55rem; padding: .45rem .7rem; }
.nav-links a:hover, .nav-links [aria-current] { background: #284b3e; color: white; }
.portal-nav .brand { font-weight: 750; margin-right: .75rem; }
.nav-account { margin-left: auto; }
.portal-main { flex: 1 0 auto; padding-block: clamp(1.75rem, 4vw, 3.5rem); }
.portal-footer { padding: 1rem 0; border-top: 1px solid var(--portal-border); color: var(--portal-muted); text-align: center; font-size: .85rem; }
.page-heading { margin-bottom: clamp(1rem, 3vw, 1.75rem); }
.page-heading h1 { margin-bottom: .3rem; }
.page-context { margin-bottom: .35rem; color: var(--portal-accent); font-size: .9rem; font-weight: 650; }
.back-link { display: inline-block; margin-bottom: 1.25rem; font-size: .9rem; font-weight: 600; }

.surface { background: white; border: 1px solid var(--portal-border); border-radius: 1rem; overflow: hidden; box-shadow: 0 8px 24px rgb(23 45 38 / .045); }
.form-surface { padding: clamp(1rem, 4vw, 2rem); }
.section-heading { margin: 0; padding: 1.25rem 1rem; }
.table-toolbar { display: grid; grid-template-columns: minmax(14rem, 26rem) auto; align-items: end; justify-content: space-between; gap: 1rem 1.5rem; padding: 1.25rem; }
.form-label, .state-filter legend { color: var(--portal-ink); font-size: .9rem; font-weight: 650; }
.state-filter { min-width: 0; }
.state-options { display: flex; flex-wrap: wrap; gap: .25rem; padding: .2rem; border: 1px solid var(--portal-border); border-radius: .7rem; background: var(--portal-bg); }
.state-options .btn { padding: .28rem .6rem; color: var(--portal-muted); font-size: .9rem; }
.state-options .btn:hover { color: var(--portal-accent); }
.state-options .btn-check:checked + .btn { border-color: #c5dbce; background: white; color: var(--portal-accent); font-weight: 650; }
.state-options .btn-check:focus-visible + .btn { outline: 3px solid #36876a; outline-offset: 1px; }
.results { margin: 0; padding: .55rem 1.25rem; border-top: 1px solid var(--portal-border); color: var(--portal-muted); font-size: .85rem; }
.service-feedback .alert { margin: .5rem 1.25rem; }
.table > thead { --bs-table-bg: #edf4ef; }
.table > :not(caption) > * > * { padding: .85rem 1rem; border-color: var(--portal-border); }
.services-table thead th { color: var(--portal-muted); font-size: .85rem; }
.services-table .service-number { white-space: nowrap; font-variant-numeric: tabular-nums; }
.services-table tbody tr:hover > * { --bs-table-bg: #f8fbf9; }
.service-client { font-weight: 650; }
.beneficiary { display: block; color: var(--portal-muted); margin-top: .2rem; }
.beneficiary > span { display: block; white-space: pre-line; overflow-wrap: anywhere; }
.beneficiary-edit { display: inline-block; margin-top: .45rem; font-size: .875rem; font-weight: 600; text-underline-offset: .2em; }
.status-pill { display: inline-block; padding: .25rem .55rem; border-radius: .5rem; background: #edf1ef; font-size: .85rem; font-weight: 650; }
.status-pill[data-state="Activo"], .status-synced { color: #115740; background: #e1f4e9; }
.status-pill[data-state="Suspendido"], .status-pending { color: #754609; background: #fff0d9; }
.status-pill[data-state="Cancelado"] { color: #642934; background: #f6e5e8; }
.empty-state { margin: 0; padding: 1.5rem 1rem; color: var(--portal-muted); }

.beneficiary-page { max-width: 940px; }
.form-section { min-width: 0; display: flow-root; padding: clamp(1rem, 4vw, 1.75rem); }
.form-section + .form-section { border-top: 1px solid var(--portal-border); }
.form-section legend { float: none; margin-bottom: .85rem; font-size: 1.1rem; font-weight: 700; }
.form-footer, .form-actions { display: flex; align-items: center; gap: .7rem; flex-wrap: wrap; }
.form-footer { justify-content: space-between; padding: 1rem clamp(1rem, 4vw, 1.75rem); border-top: 1px solid var(--portal-border); background: #f8fbf9; }
.form-footer .status-pill { margin-bottom: .35rem; }
.form-actions { margin-left: auto; }
.original-comments summary { font-weight: 650; cursor: pointer; }
.original-comments[open] summary { margin-bottom: .7rem; }

.help-layout { display: grid; grid-template-columns: minmax(13rem, 16rem) minmax(0, 1fr); gap: 1.25rem; align-items: start; }
.help-index { position: sticky; top: 5.5rem; }
.help-index a { display: block; padding: .4rem 0; text-underline-offset: .18em; }
.help-content { display: grid; gap: 1rem; }
.help-content section { scroll-margin-top: 6rem; }
.help-content li + li { margin-top: .35rem; }
.help-statuses { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.help-sync dd:last-child { margin-bottom: 0; }
.help-sync .status-pill { margin-bottom: .35rem; }

.login-shell { display: grid; flex: 1 0 auto; place-items: center; padding: 1.5rem 1rem; }
.login-card { width: min(100%, 27rem); padding: clamp(1.25rem, 5vw, 2.25rem); }
.login-logo { display: block; max-width: 9rem; max-height: 4rem; object-fit: contain; margin-bottom: 1.4rem; }

.portal-dialog { color: var(--portal-ink); width: min(28rem, calc(100% - 2rem)); padding: 1.5rem; border: 1px solid var(--portal-border); border-radius: 1rem; }
.portal-dialog::backdrop { background: rgb(10 30 24 / .65); }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .6rem; }

@media (max-width: 767px) {
    .table-toolbar { grid-template-columns: minmax(0, 1fr); }
    .help-layout { grid-template-columns: minmax(0, 1fr); }
    .help-index { position: static; }
    .help-content section { scroll-margin-top: 10rem; }
}

@media (max-width: 575px) {
    .portal-nav { gap: .6rem 1rem; }
    .nav-account { width: 100%; justify-content: space-between; }
    .table-toolbar { gap: .8rem; padding: 1rem; }
    .state-options { gap: .15rem; }
    .state-options .btn { font-size: .8rem; padding-inline: .4rem; }
    .services-table > :not(caption) > * > * { padding: .75rem .4rem; overflow-wrap: anywhere; }
    .services-table .btn { padding-inline: .35rem; font-size: .8rem; }
    .services-table .service-number { white-space: normal; font-size: .85rem; }
    .form-actions, .form-actions form { width: 100%; }
    .form-actions .btn { flex-grow: 1; width: 100%; }
}
