:root {
    color-scheme: light;
    --background: #f4f7f6;
    --surface: #ffffff;
    --surface-soft: #edf3f1;
    --border: #d9e3df;
    --text: #17221f;
    --muted: #62716d;
    --primary: #126a5a;
    --primary-strong: #0a5145;
    --focus: #1d75bd;
    --danger: #b42318;
    --danger-soft: #fef3f2;
    --warning: #9a6700;
    --warning-soft: #fff8c5;
    --ok: #16794c;
    --ok-soft: #e8f7ef;
    --shadow: 0 18px 48px rgb(24 53 45 / 10%);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
        "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
    outline-offset: 2px;
}

.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;
}

.login-page {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 1.5rem;
    background:
        radial-gradient(circle at 15% 15%, #d5eee7 0, transparent 32rem),
        radial-gradient(circle at 85% 85%, #dce9f2 0, transparent 30rem),
        var(--background);
}

.login-shell {
    width: min(100%, 28rem);
}

.login-card {
    padding: clamp(1.5rem, 5vw, 2.5rem);
    border: 1px solid rgb(255 255 255 / 70%);
    border-radius: 1.25rem;
    background: rgb(255 255 255 / 94%);
    box-shadow: var(--shadow);
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 1rem;
    background: var(--primary);
    color: white;
    font-size: 1.45rem;
    font-weight: 800;
    box-shadow: 0 8px 20px rgb(18 106 90 / 22%);
}

.brand-mark-small {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.7rem;
    font-size: 1rem;
}

.eyebrow {
    margin: 1.5rem 0 0.25rem;
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 0.5rem;
    font-size: clamp(1.7rem, 4vw, 2.25rem);
    letter-spacing: -0.035em;
}

h2 {
    font-size: 1.2rem;
}

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

.stack {
    display: grid;
    gap: 0.7rem;
    margin-top: 1.75rem;
}

label {
    color: #32413d;
    font-size: 0.88rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 2.75rem;
    padding: 0.7rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--surface);
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--focus);
}

textarea {
    resize: vertical;
}

.button {
    min-height: 2.65rem;
    padding: 0.65rem 1rem;
    border: 1px solid transparent;
    border-radius: 0.65rem;
    font-weight: 750;
}

.button-primary {
    margin-top: 0.65rem;
    background: var(--primary);
    color: white;
}

.inline-button {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.button-primary:hover {
    background: var(--primary-strong);
}

.button:disabled,
select:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

.button-secondary {
    border-color: var(--border);
    background: var(--surface);
    color: var(--text);
}

.button-quiet {
    background: transparent;
    color: var(--primary);
}

.alert {
    padding: 0.8rem 0.9rem;
    border-radius: 0.65rem;
}

.alert-error {
    border: 1px solid #fecdca;
    background: var(--danger-soft);
    color: var(--danger);
}

.alert-success {
    border: 1px solid #a6e1c1;
    background: var(--ok-soft);
    color: var(--ok);
}

.page-alert {
    margin-bottom: 1rem;
}

.topbar {
    position: sticky;
    z-index: 30;
    top: 0;
    display: flex;
    align-items: center;
    min-height: 4.5rem;
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    background: rgb(255 255 255 / 94%);
    backdrop-filter: blur(12px);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    color: var(--text);
    font-size: 1.1rem;
    font-weight: 850;
    text-decoration: none;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: auto;
}

.identity {
    display: grid;
    text-align: right;
}

.identity span {
    color: var(--muted);
    font-size: 0.78rem;
}

.nav-toggle {
    display: none;
    margin-left: auto;
    border: 0;
    background: transparent;
    font-size: 1.5rem;
}

.app-shell {
    display: grid;
    grid-template-columns: 16rem minmax(0, 1fr);
    min-height: calc(100vh - 4.5rem);
}

.sidebar {
    padding: 1.25rem 0.85rem;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.sidebar nav {
    display: grid;
    gap: 0.35rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    border-radius: 0.65rem;
    color: #42514d;
    font-weight: 650;
    text-decoration: none;
}

.nav-link.active {
    background: var(--surface-soft);
    color: var(--primary);
}

.nav-link.disabled {
    color: #8b9693;
    cursor: default;
}

.workspace {
    min-width: 0;
    padding: clamp(1rem, 3vw, 2.5rem);
}

.workspace-header {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.5rem;
}

.workspace-header .eyebrow {
    margin-top: 0;
}

.organization-selector {
    width: min(100%, 25rem);
}

.organization-selector label {
    display: block;
    margin-bottom: 0.35rem;
}

.inline-controls {
    display: flex;
    gap: 0.5rem;
}

.empty-state {
    display: grid;
    place-items: center;
    min-height: 28rem;
    padding: 2rem;
    border: 1px dashed #b9cac4;
    border-radius: 1rem;
    background: var(--surface);
    text-align: center;
}

.empty-state p {
    max-width: 42rem;
    color: var(--muted);
}

.empty-icon {
    display: grid;
    place-items: center;
    width: 4rem;
    height: 4rem;
    margin-bottom: 1rem;
    border-radius: 1rem;
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 2rem;
}

.status-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.65rem;
    margin-top: 1rem;
}

.status {
    padding: 0.45rem 0.65rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 750;
}

.status-ok {
    background: var(--ok-soft);
    color: var(--ok);
}

.status-warning {
    background: var(--warning-soft);
    color: var(--warning);
}

.status-critical {
    background: var(--danger-soft);
    color: var(--danger);
}

.section-tabs {
    position: sticky;
    z-index: 20;
    top: 5rem;
    display: flex;
    gap: 0.4rem;
    margin-bottom: 1.25rem;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.8rem;
    background: rgb(255 255 255 / 94%);
    box-shadow: 0 8px 24px rgb(24 53 45 / 6%);
    backdrop-filter: blur(12px);
}

.section-tabs a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.55rem;
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 750;
    text-decoration: none;
}

.section-tabs a:hover {
    background: var(--surface-soft);
}

.section-tabs span {
    display: inline-grid;
    place-items: center;
    min-width: 1.45rem;
    height: 1.45rem;
    padding: 0 0.35rem;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 0.72rem;
}

.management-section {
    margin-bottom: 1.25rem;
    scroll-margin-top: 9rem;
    border: 1px solid var(--border);
    border-radius: 1rem;
    background: var(--surface);
    box-shadow: 0 10px 30px rgb(24 53 45 / 5%);
    overflow: hidden;
}

.section-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 2rem;
    padding: 1.25rem 1.4rem;
    border-bottom: 1px solid var(--border);
}

.section-heading .eyebrow {
    margin: 0 0 0.2rem;
}

.section-heading h2,
.editor-card h3,
.list-card h3 {
    margin-bottom: 0;
}

.section-heading > p {
    max-width: 34rem;
    margin-bottom: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.section-heading-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 1rem;
}

.section-heading-actions p {
    max-width: 34rem;
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
    text-align: right;
}

.collapse-button {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 2.35rem;
    padding: 0.4rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    background: var(--surface);
    color: var(--primary);
    font-size: 0.8rem;
    font-weight: 750;
}

.collapse-button:hover {
    background: var(--surface-soft);
}

[data-collapse-icon] {
    font-size: 1.1rem;
    line-height: 1;
}

.collapsible-section.is-collapsed .section-heading {
    border-bottom: 0;
}

.management-grid {
    display: grid;
    grid-template-columns: minmax(22rem, 1.2fr) minmax(18rem, 0.8fr);
}

.management-grid-compact {
    grid-template-columns: minmax(22rem, 1.45fr) minmax(16rem, 0.55fr);
}

.editor-card,
.list-card {
    padding: 1.4rem;
}

.editor-card {
    background: color-mix(in srgb, var(--surface-soft) 48%, white);
}

.management-grid > .list-card {
    order: -1;
    border-right: 1px solid var(--border);
}

.editor-card h3,
.list-card h3 {
    font-size: 1rem;
}

.editor-card.is-editing {
    box-shadow: inset 0.25rem 0 0 var(--primary);
}

.editor-card.is-dirty {
    box-shadow: inset 0.25rem 0 0 var(--warning);
}

.editor-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 0.85rem;
}

.context-name {
    color: var(--muted);
    font-weight: 550;
}

.current-contract-label {
    color: var(--ok) !important;
    font-weight: 750;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.85rem;
    margin: 1rem 0 0.4rem;
}

.form-grid label:not(.checkbox-label) {
    display: grid;
    gap: 0.35rem;
}

.form-grid-single {
    grid-template-columns: 1fr;
}

.span-two {
    grid-column: span 2;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-height: 2.75rem;
}

.checkbox-label input {
    width: 1.1rem;
    min-height: 1.1rem;
    accent-color: var(--primary);
}

.color-fieldset {
    min-width: 0;
    margin: 0;
    padding: 0;
    border: 0;
}

.color-fieldset legend {
    margin-bottom: 0.45rem;
    color: #32413d;
    font-size: 0.88rem;
    font-weight: 700;
}

.color-palette {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.color-option {
    position: relative;
    display: grid;
    place-items: center;
}

.color-option input {
    position: absolute;
    width: 1px;
    min-height: 1px;
    opacity: 0;
}

.color-swatch {
    display: block;
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--surface);
    border-radius: 50%;
    background: var(--surface-soft);
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
}

.role-color.role-color-0f766e,
.color-swatch.role-color-0f766e {
    background-color: #0f766e;
}

.role-color.role-color-2563eb,
.color-swatch.role-color-2563eb {
    background-color: #2563eb;
}

.role-color.role-color-4f46e5,
.color-swatch.role-color-4f46e5 {
    background-color: #4f46e5;
}

.role-color.role-color-7c3aed,
.color-swatch.role-color-7c3aed {
    background-color: #7c3aed;
}

.role-color.role-color-c026d3,
.color-swatch.role-color-c026d3 {
    background-color: #c026d3;
}

.role-color.role-color-dc2626,
.color-swatch.role-color-dc2626 {
    background-color: #dc2626;
}

.role-color.role-color-ea580c,
.color-swatch.role-color-ea580c {
    background-color: #ea580c;
}

.role-color.role-color-ca8a04,
.color-swatch.role-color-ca8a04 {
    background-color: #ca8a04;
}

.role-color.role-color-16a34a,
.color-swatch.role-color-16a34a {
    background-color: #16a34a;
}

.role-color.role-color-475569,
.color-swatch.role-color-475569 {
    background-color: #475569;
}

.color-option input:checked + .color-swatch {
    box-shadow:
        0 0 0 2px var(--surface),
        0 0 0 4px var(--text);
}

.color-option input:focus-visible + .color-swatch {
    outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
    outline-offset: 3px;
}

.form-hint {
    margin: 0.7rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.field-hint {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
}

.label-optional {
    color: var(--muted);
    font-weight: 500;
}

.entity-list {
    display: grid;
    margin-top: 1rem;
}

.management-grid > .list-card .entity-list {
    max-height: 36rem;
    padding-right: 0.35rem;
    overflow-y: auto;
    scrollbar-gutter: stable;
}

.entity-row {
    display: grid;
    grid-template-columns: minmax(10rem, 1fr) auto auto;
    align-items: center;
    gap: 0.75rem;
    min-height: 4rem;
    padding: 0.65rem 0;
    border-top: 1px solid var(--border);
}

.entity-row:first-child {
    border-top: 0;
}

.entity-row[data-entity-select] {
    cursor: pointer;
    transition:
        background-color 120ms ease,
        box-shadow 120ms ease;
}

.entity-row[data-entity-select]:hover {
    background: color-mix(in srgb, var(--primary-soft) 45%, white);
}

.entity-row[data-entity-select]:focus-visible {
    border-radius: 0.65rem;
    outline: 3px solid color-mix(in srgb, var(--focus) 55%, transparent);
    outline-offset: -2px;
}

.entity-row.is-selected {
    border-radius: 0.65rem;
    background: color-mix(in srgb, var(--primary-soft) 75%, white);
    box-shadow: inset 0.2rem 0 0 var(--primary);
}

.entity-main {
    display: grid;
    gap: 0.15rem;
}

.entity-main span,
.empty-list {
    color: var(--muted);
    font-size: 0.82rem;
}

.entity-main .entity-description {
    color: var(--text);
    line-height: 1.45;
    white-space: pre-line;
}

.empty-list {
    margin: 1rem 0 0;
    padding: 1rem;
    border-radius: 0.65rem;
    background: var(--surface-soft);
}

.state-pill {
    padding: 0.3rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 750;
}

.state-active {
    background: var(--ok-soft);
    color: var(--ok);
}

.state-inactive {
    background: #eef0f0;
    color: var(--muted);
}

.state-ended {
    background: var(--danger-soft);
    color: var(--danger);
}

.button-small {
    min-height: 2.1rem;
    padding: 0.4rem 0.65rem;
    font-size: 0.78rem;
}

.button-danger {
    border-color: #fecdca;
    background: var(--danger-soft);
    color: var(--danger);
}

.button-danger:hover {
    border-color: var(--danger);
    background: #fee4e2;
}

.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.4rem;
}

.inline-actions,
.employee-row-actions {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.employee-row-actions {
    flex-wrap: wrap;
}

.role-color {
    width: 0.8rem;
    height: 2.4rem;
    border-radius: 999px;
    background-color: var(--surface-soft);
}

.entity-row:has(.role-color) {
    grid-template-columns: auto minmax(10rem, 1fr) auto auto;
}

.list-card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.summary-chip {
    padding: 0.35rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 750;
}

.personnel-row {
    grid-template-columns: minmax(13rem, 1fr) auto auto;
}

.personnel-row.static-row {
    grid-template-columns: 1fr;
}

.compact-select {
    width: auto;
    min-width: 7.8rem;
    min-height: 2.1rem;
    padding: 0.35rem 0.55rem;
    font-size: 0.78rem;
}

.field-group {
    min-width: 0;
    margin: 0.25rem 0;
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 0.7rem;
    background: rgb(255 255 255 / 55%);
}

.field-group legend {
    padding: 0 0.3rem;
    color: #32413d;
    font-size: 0.88rem;
    font-weight: 750;
}

.form-grid-nested {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin: 0;
}

.qualification-management {
    display: grid;
    grid-template-columns: minmax(22rem, 1.3fr) minmax(15rem, 0.55fr) minmax(15rem, 0.65fr);
}

.qualification-management > .list-card {
    order: -1;
    border-right: 1px solid var(--border);
}

.qualification-management > .editor-card {
    border-right: 1px solid var(--border);
}

.qualification-management > .editor-card:nth-child(2) {
    border-right: 0;
}

.qualification-list-card {
    min-width: 0;
}

.subsection-heading {
    margin-top: 2rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 760px) {
    .topbar {
        flex-wrap: wrap;
    }

    .nav-toggle {
        display: block;
    }

    .topbar-actions {
        width: 100%;
        margin-top: 0.6rem;
    }

    .identity {
        margin-right: auto;
        text-align: left;
    }

    .app-shell {
        display: block;
    }

    .sidebar {
        display: none;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar.open {
        display: block;
    }

    .workspace-header {
        display: grid;
    }

    .organization-selector {
        width: 100%;
    }

    .inline-controls {
        align-items: stretch;
    }

    .section-tabs {
        top: 0.5rem;
        overflow-x: auto;
    }

    .section-tabs a {
        white-space: nowrap;
    }

    .section-heading {
        display: grid;
        gap: 0.5rem;
    }

    .section-heading-actions {
        align-items: flex-start;
        justify-content: space-between;
    }

    .section-heading-actions p {
        text-align: left;
    }

    .management-grid,
    .management-grid-compact,
    .qualification-management {
        grid-template-columns: 1fr;
    }

    .editor-card,
    .qualification-management > .editor-card {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .management-grid > .list-card,
    .qualification-management > .list-card {
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .entity-row,
    .entity-row:has(.role-color) {
        grid-template-columns: auto minmax(0, 1fr) auto;
    }

    .entity-row:not(:has(.role-color)) .entity-main {
        grid-column: span 2;
    }

    .row-actions {
        grid-column: 2 / -1;
        justify-self: end;
    }

    .personnel-row {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .personnel-row .entity-main {
        grid-column: 1 / -1;
    }
}

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

    .span-two {
        grid-column: auto;
    }

    .form-grid-nested {
        grid-template-columns: 1fr;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
