:root {
    color-scheme: light;
    --ink: #172f36;
    --muted: #51666b;
    --accent: #136250;
    --accent-hover: #0c473a;
    --accent-soft: #e1f1eb;
    --line: #d7e3df;
    --surface: #fff;
    --canvas: #f3f6f4;
    --radius: 14px;
    --focus: #b34e16;
    font: 16px/1.5 system-ui, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; display: grid; place-items: center; background: var(--canvas); color: var(--ink); }
main { width: min(94vw, 460px); padding: clamp(20px, 5vw, 36px); border-radius: var(--radius); background: var(--surface); box-shadow: 0 14px 48px #173a3518; }
header { font-size: 1.65rem; font-weight: 720; }
header strong { color: var(--accent); }
h1, h2, h3 { line-height: 1.2; text-wrap: balance; }
h1 { font-size: clamp(1.7rem, 3vw, 2.45rem); letter-spacing: -.035em; margin: 0 0 .65em; }
h2 { font-size: 1.26rem; margin: 0 0 .75em; }
h3 { font-size: 1.02rem; }
p { margin: .55em 0 1em; }
small { display: block; color: var(--muted); font-size: .82rem; }
a { color: var(--accent); text-underline-offset: .18em; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only, .skip-link:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}
.skip-link:focus { position: fixed; inset: .6rem auto auto .6rem; padding: .65rem 1rem; z-index: 60; background: #fff; }
label { display: block; font-size: .89rem; font-weight: 650; margin: .85rem 0; }
input, select, textarea, button { font: inherit; }
input:not([type=hidden], [type=checkbox], [type=radio]), select, textarea {
    color: var(--ink);
    border: 1px solid #aebfba;
    border-radius: 9px;
    max-width: 100%;
    padding: .62rem .75rem;
    min-height: 42px;
    background: var(--surface);
}
label > input:not([type=hidden], [type=checkbox], [type=radio]), label > select, label > textarea {
    display: block;
    width: 100%;
    margin-top: .35rem;
    font-weight: 450;
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
textarea { min-height: 6rem; resize: vertical; }
select { min-width: 0; }
button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-height: 42px;
    padding: .51rem .9rem;
    border: 1px solid transparent;
    border-radius: 9px;
    background: var(--accent);
    color: white;
    font-size: .88rem;
    font-weight: 680;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
}
button:hover, .button:hover { background: var(--accent-hover); color: white; }
button:disabled { opacity: .6; cursor: default; }
.secondary, .button.secondary { background: #fff; border-color: var(--line); color: var(--ink); }
.secondary:hover, .button.secondary:hover { background: var(--accent-soft); color: var(--accent-hover); }
button.danger { background: #963818; }
button.danger:hover { background: #772b12; }
section, details, fieldset {
    padding: clamp(14px, 2vw, 22px);
    margin: 1rem 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    min-width: 0;
}
summary { cursor: pointer; color: var(--accent); font-weight: 680; }
section > :first-child { margin-top: 0; }
section > :last-child { margin-bottom: 0; }
body:not(.portal) main > header { margin-bottom: 1.2rem; }
body:not(.portal) main form > button { width: 100%; }
[role=alert], [role=status].notice, p[role=status]:not(:empty) { padding: .7rem .95rem; border-radius: 10px; }
[role=alert] { background: #faebdf; color: #752f17; border: 1px solid #ecd2c3; }
[role=status].notice, p[role=status]:not(:empty) { background: var(--accent-soft); color: #184c40; }
pre { white-space: pre-wrap; overflow-wrap: anywhere; }
nav { margin: 1rem 0; }
.portal main nav { display: flex; align-items: center; flex-wrap: wrap; gap: .45rem; font-size: 0; }
.portal main nav a {
    padding: .47rem .73rem;
    border-radius: 9px;
    background: var(--surface);
    border: 1px solid var(--line);
    font-size: .84rem;
    font-weight: 650;
    line-height: 1.4;
    text-decoration: none;
}
.portal main nav a:hover, .portal main nav a[aria-current] { background: var(--accent-soft); color: var(--accent-hover); }
.portal main nav a[aria-current] { border-color: #9dc8ba; }
.table-scroll { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; background: var(--surface); font-size: .89rem; }
th, td { padding: .78rem .9rem; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
th { color: #36545b; background: #eaf1ee; white-space: nowrap; font-size: .78rem; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f5faf8; }
td > a { font-weight: 680; }
body.portal {
    display: grid;
    grid-template: "sidebar toolbar" auto "sidebar content" minmax(0, 1fr) / 244px minmax(0, 1fr);
    place-items: stretch;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}
.portal-sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    padding: 18px 13px 15px;
    min-height: 0;
    overflow: hidden;
    background: #173a39;
    color: #eef6f3;
}
.portal-sidebar .portal-brand { display: flex; gap: .65rem; align-items: center; border-radius: 10px; padding: .4rem; margin: 0 0 1rem; color: #fff; text-decoration: none; font-size: 1.12rem; }
.brand-mark { display: grid; place-items: center; flex: 0 0 38px; min-height: 38px; background: #dbefe6; color: #155443; border-radius: 10px; font-size: .78rem; font-weight: 780; }
.portal-brand strong, .mobile-brand strong { color: #9fe2cb; }
.portal-sidebar small { color: #bfd4ce; font-size: .75rem; overflow-wrap: anywhere; }
.portal-sidebar nav { margin: 0; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.portal-sidebar .nav-group { margin: 0 0 .34rem; padding: 0; background: none; border: 0; border-radius: 9px; }
.nav-group > summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .4rem;
    list-style: none;
    color: #d8e8e4;
    border-radius: 8px;
    padding: .6rem .58rem;
    font-size: .77rem;
    letter-spacing: .025em;
}
.nav-group > summary::-webkit-details-marker { display: none; }
.nav-group > summary::after { content: ''; width: 7px; height: 7px; border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor; transform: rotate(-45deg); }
.nav-group[open] > summary::after { transform: rotate(45deg); }
.nav-group > a, .sidebar-account a {
    display: flex;
    align-items: center;
    gap: .58rem;
    margin: .15rem 0;
    padding: .49rem .64rem;
    border-radius: 8px;
    color: #f1f8f6;
    font-size: .855rem;
    line-height: 1.35;
    text-decoration: none;
}
.nav-group a span { width: 1.15rem; text-align: center; font-size: 1rem; }
.nav-group a:hover, .nav-group summary:hover, .sidebar-account a:hover { background: #2b504d; }
.nav-group a[aria-current] { background: #d2eee2; color: #183e35; font-weight: 750; }
.sidebar-account { flex: none; border-top: 1px solid #78948e60; margin-top: .6rem; padding-top: .5rem; display: flex; justify-content: space-between; align-items: center; gap: .35rem; }
.sidebar-account .account-name { font-weight: 630; overflow-wrap: anywhere; }
.sidebar-account button { background: #315553; min-height: 36px; padding: .36rem .57rem; font-size: .75rem; }
.portal-toolbar {
    grid-area: toolbar;
    padding: .7rem clamp(16px, 3vw, 42px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}
.portal-context { color: var(--muted); font-size: .84rem; }
.portal-context span { margin: 0 .36rem; }
.portal-context strong { color: var(--ink); }
.portal-search { display: flex; flex: 0 1 338px; gap: .42rem; }
.portal-search input { width: 100%; min-width: 0; font-size: .9rem; }
.portal-search button { background: var(--accent-soft); color: var(--accent-hover); }
.portal-search button:hover { background: #cce8de; }
.portal > main {
    grid-area: content;
    width: 100%;
    min-width: 0;
    max-width: none;
    overflow: auto;
    overscroll-behavior: contain;
    padding: clamp(17px, 3vw, 42px);
    background: transparent;
    box-shadow: none;
    border-radius: 0;
}
.portal main > article { padding: 1rem; margin: .65rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.portal main > article h3 { margin-top: .15rem; }
.mobile-top, .mobile-nav-toggle, .mobile-nav-backdrop, .mobile-menu-close { display: none; }
.module-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 208px), 1fr)); gap: .7rem; }
.module-grid section { margin: 0; }
.module-tile {
    min-height: 58px;
    display: flex;
    align-items: center;
    gap: .6rem;
    padding: .62rem .72rem;
    border: 1px solid var(--line);
    border-radius: 11px;
    background: var(--surface);
    color: var(--ink);
    text-decoration: none;
    font-size: .88rem;
}
.module-tile:hover { background: var(--accent-soft); border-color: #a8c9bf; }
.tile-icon { display: grid; place-items: center; flex: 0 0 30px; min-height: 30px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); }
.tile-arrow { margin-left: auto; color: var(--accent); }
.page-heading, .section-heading, .action-row { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .7rem; }
.page-heading { margin-bottom: 1.15rem; }
.page-heading h1, .section-heading h2, .page-heading p { margin: 0; }
.page-heading p { margin-top: .35rem; color: var(--muted); }
.action-row { justify-content: flex-start; }
.form-grid, .filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit,minmax(min(100%, 180px),1fr));
    align-items: start;
    gap: .65rem 1rem;
}
.form-grid > label, .filter-bar > label { margin: 0; }
.form-grid .full-row, .form-grid > textarea { grid-column: 1 / -1; }
.form-grid .action-row, .filter-bar .action-row { grid-column: 1 / -1; margin: .3rem 0 0; }
.filter-bar { padding: 1rem; margin: 1rem 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.inline-form { display: flex; align-items: end; flex-wrap: wrap; gap: .6rem; }
.inline-form > label { flex: 1 1 145px; margin: 0; }
.inline-form > label:first-of-type { flex: 3 1 240px; }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: .7rem; flex-wrap: wrap; margin-top: .8rem; }
.empty-state { color: var(--muted); padding: .75rem 0; }
.badge { display: inline-block; padding: .19rem .52rem; border-radius: 1rem; font-size: .78rem; font-weight: 680; background: #eaf0ee; color: #36545b; }
.badge.positive { color: #185646; background: #def1e9; }
.badge.warning { color: #743311; background: #fae9d8; }
.badge.negative { color: #832e2a; background: #f8e6e3; }
.stats { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: .8rem; margin-bottom: 1rem; }
.stat {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 88px;
    justify-content: space-between;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .8rem .95rem;
    background: var(--surface);
    text-decoration: none;
    color: var(--ink);
}
.stat:hover { background: var(--accent-soft); border-color: #a8c9bf; }
.stat strong { font-size: clamp(1.35rem, 3vw, 1.95rem); line-height: 1.05; }
.stat small { color: var(--muted); font-weight: 650; }
.dashboard-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); align-items: start; gap: 1rem; }
.dashboard-grid > section { margin: 0; }
.dashboard-grid .wide-panel { grid-column: 1 / -1; }
.task { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: .64rem; border-top: 1px solid var(--line); padding: .7rem 0; }
.task > div { min-width: 0; overflow-wrap: anywhere; }
.task details { padding: .4rem .65rem; margin: 0; }
.task-list > .task:first-child { border-top: 0; }
.dashboard-panel .section-heading { align-items: start; margin-bottom: .65rem; }
.dashboard-panel .section-heading a { font-size: .82rem; }
.dashboard-panel .module-grid { margin-bottom: .5rem; }
details.module-group { padding: .65rem .8rem; margin: .5rem 0; }
.module-group[open] > summary { margin-bottom: .6rem; }
footer { color: var(--muted); margin-top: 1.4rem; font-size: .79rem; }
.permission-groups { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,300px),1fr)); gap: .7rem; }
.permission-groups fieldset { margin: 0; }
.permissions { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,160px),1fr)); gap: .35rem; }
.permissions label { display: flex; align-items: start; gap: .45rem; margin: .35rem 0; }
.permission-groups .permissions { display: block; }
.permission-groups code { display: block; color: var(--muted); overflow-wrap: anywhere; }
dialog {
    width: min(540px, 94vw);
    max-height: 86dvh;
    overflow: auto;
    padding: clamp(16px, 3vw, 28px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    color: var(--ink);
}
dialog::backdrop { background: #173a396b; }
.dialog-heading { display: flex; justify-content: space-between; align-items: center; gap: .7rem; margin-bottom: 1rem; }
.dialog-heading h2 { margin: 0; }
.calendar { display: grid; grid-template-columns: repeat(7,minmax(0,1fr)); gap: .35rem; }
.calendar > strong { text-align: center; padding: .28rem; font-size: .8rem; color: var(--muted); }
.calendar-day { min-height: 82px; padding: .37rem; border: 1px solid var(--line); border-radius: 8px; overflow-wrap: anywhere; }
.calendar-day.today { border-color: #77aa9a; background: #f1f9f5; }
.calendar-day small { font-size: .75rem; background: #eff5f2; border-radius: 5px; padding: .24rem .31rem; margin-top: .32rem; }
.calendar-agenda { display: none; }
.calendar-agenda ul { padding-left: 1.1rem; }
.calendar-agenda li { margin: .35rem 0; }
.search-results { list-style: none; margin: .25rem 0 0; padding: 0; }
.search-results li { border-top: 1px solid var(--line); }
.search-results a { display: block; padding: .6rem 0; text-decoration: none; }
.search-results a:hover strong { text-decoration: underline; }
.label-page main { text-align: center; }
.label-page img { display: block; margin: auto; }
@media (max-width: 760px) {
    body.portal { display: block; height: auto; overflow: visible; }
    body.portal:has(.mobile-nav-toggle:checked) { height: 100dvh; overflow: hidden; }
    .mobile-top {
        position: sticky;
        top: 0;
        z-index: 20;
        display: flex;
        align-items: center;
        justify-content: space-between;
        min-height: 57px;
        padding: .45rem .95rem;
        color: white;
        background: #173a39;
    }
    .mobile-brand { color: white; font-weight: 740; text-decoration: none; }
    .mobile-brand:hover { color: white; }
    .mobile-menu-button, .mobile-menu-close { display: block; margin: 0; padding: .53rem .8rem; border-radius: 8px; background: #315553; color: #fff; cursor: pointer; }
    .mobile-menu-close { margin-bottom: .65rem; }
    .mobile-nav-toggle { display: block; position: fixed; inset: 9px 16px auto auto; width: 76px; height: 37px; opacity: 0; z-index: 21; cursor: pointer; }
    body:has(.mobile-nav-toggle:focus-visible) .mobile-menu-button { outline: 3px solid #ebc092; outline-offset: 2px; }
    .portal-sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(87vw,330px); height: 100dvh; z-index: 40; }
    .mobile-nav-toggle:checked ~ .portal-sidebar { display: flex; }
    .mobile-nav-toggle:checked ~ .mobile-nav-backdrop { display: block; position: fixed; inset: 0; z-index: 30; margin: 0; background: #1d38367a; }
    .portal-toolbar { padding: .61rem .95rem; }
    .portal-context { display: none; }
    .portal-search { flex: 1 1 100%; }
    .portal > main { padding: 1.15rem .95rem; overflow: visible; }
    .portal input:not([type=hidden], [type=checkbox], [type=radio]), .portal select, .portal textarea { font-size: 16px; }
    .portal button, .portal .button { min-height: 44px; }
    .portal .table-scroll table { min-width: 490px; }
    .stats { gap: .4rem; }
    .stat { min-height: 82px; padding: .56rem .45rem; }
    .stat small { font-size: .72rem; }
    .calendar { display: none; }
    .calendar-agenda { display: block; }
}
@media print {
    body.portal { display: block; height: auto; overflow: visible; background: white; }
    .portal > main { padding: 0; overflow: visible; }
    .portal-sidebar, .portal-toolbar, .skip-link, .mobile-top, .mobile-nav-toggle, .mobile-nav-backdrop, .portal main nav, .portal button, .label-page .no-print { display: none !important; }
    .label-page main { box-shadow: none; width: 60mm; padding: 3mm; }
    .label-page img { width: 35mm; height: 35mm; }
}

.record-facts { display: grid; grid-template-columns: repeat(auto-fit,minmax(min(100%,150px),1fr)); gap: .75rem; margin: .4rem 0 1.15rem; }
.record-facts dt { color: var(--muted); font-size: .82rem; }
.record-facts dd { margin: .2rem 0 0; font-weight: 650; overflow-wrap: anywhere; }
.portal main .inline-form + .inline-form { margin-top: .75rem; }
.calendar-agenda.explicit-agenda { display: block; }
.agenda-day { display: grid; grid-template-columns: minmax(0,112px) minmax(0,1fr); gap: .6rem; padding: .68rem 0; border-top: 1px solid var(--line); }
.agenda-day h3, .agenda-day ul { margin: 0; }
.agenda-day h3 { font-size: .91rem; padding-top: .35rem; }
.agenda-day li { overflow-wrap: anywhere; }
@media (max-width: 760px) {
    .calendar-mode { display: none; }
    .agenda-day { grid-template-columns: minmax(0,1fr); gap: .2rem; }
}
.document-form { margin-top: 1.15rem; }

@media (max-width: 990px) { .dashboard-grid { grid-template-columns: minmax(0,1fr); } }

.record-mobile { display: none; }
@media (min-width: 1160px) {
    .dashboard-panel .inline-form {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(142px, .56fr) auto;
    }
}
@media (max-width: 760px) {
    .portal .table-scroll .record-table { min-width: 0; }
    .record-desktop { display: none; }
    .record-mobile { display: block; overflow-wrap: anywhere; }
    .record-table td { min-width: 0; padding: .65rem .6rem; overflow-wrap: anywhere; }
    .record-table .badge { white-space: normal; }
}

/* Group headers in the sidebar sit apart from individual destinations. */
.portal-sidebar .nav-group { margin-bottom: .65rem; }
.nav-group > summary {
    background: #294d4a;
    color: #f0faf6;
    border-left: 3px solid #6f9f92;
    padding: .66rem .63rem;
    font-size: .735rem;
    font-weight: 750;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.nav-group[open] > summary { background: #355d57; border-color: #9cddc6; margin-bottom: .3rem; }
.nav-group > a { margin-left: .5rem; }
