:root {
    --ink: #172533;
    --muted: #627180;
    --navy: #17324d;
    --navy-2: #214969;
    --blue: #2477a8;
    --teal: #2f7f77;
    --orange: #ec6b2d;
    --orange-soft: #fff1e9;
    --paper: #f5f3ee;
    --surface: #ffffff;
    --surface-2: #f8fafb;
    --line: #dce2e6;
    --line-dark: #bdc7cf;
    --success: #2f7d52;
    --success-soft: #eaf6ef;
    --warning: #9b6816;
    --warning-soft: #fff7df;
    --danger: #a33d3d;
    --danger-soft: #fff0f0;
    --shadow: 0 12px 35px rgba(23, 50, 77, .10);
    --radius: 14px;
    --font: Inter, Aptos, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--paper); }

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink);
    background: var(--paper);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.45;
}

button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }

:focus-visible {
    outline: 3px solid rgba(36, 119, 168, .32);
    outline-offset: 2px;
}

.auth-page {
    display: grid;
    place-items: center;
    padding: 32px;
    background:
        linear-gradient(135deg, rgba(23,50,77,.97), rgba(33,73,105,.93)),
        repeating-linear-gradient(120deg, transparent 0 38px, rgba(255,255,255,.04) 39px 40px);
}

.auth-shell {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(360px, .85fr);
    width: min(970px, 100%);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.18);
    border-radius: 24px;
    background: var(--surface);
    box-shadow: 0 28px 80px rgba(4,18,31,.32);
}

.setup-shell { width: min(1040px, 100%); }

.auth-brand {
    min-height: 520px;
    padding: 64px;
    color: white;
    background:
        radial-gradient(circle at 85% 20%, rgba(236,107,45,.28), transparent 28%),
        linear-gradient(150deg, #17324d, #214969 70%, #2f7f77);
}

.auth-brand h1 {
    max-width: 620px;
    margin: 14px 0 18px;
    font-size: clamp(2.15rem, 5vw, 4rem);
    line-height: .98;
    letter-spacing: -.045em;
}

.auth-brand > p:last-of-type { max-width: 560px; color: rgba(255,255,255,.8); font-size: 1.08rem; }

.brand-mark {
    display: inline-grid;
    width: 58px;
    height: 58px;
    place-items: center;
    border-radius: 16px;
    color: white;
    background: var(--orange);
    font-weight: 800;
    letter-spacing: -.04em;
    box-shadow: 0 10px 24px rgba(0,0,0,.18);
}

.brand-mark.small { width: 40px; height: 40px; border-radius: 11px; font-size: .88rem; box-shadow: none; }
.eyebrow { margin: 30px 0 0; color: #ffd7c4; font-size: .78rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }

.setup-benefits { display: grid; gap: 10px; margin: 34px 0 0; padding: 0; list-style: none; }
.setup-benefits li::before { content: "✓"; display: inline-grid; width: 24px; height: 24px; margin-right: 10px; place-items: center; border-radius: 50%; background: rgba(255,255,255,.12); color: #ffd7c4; font-weight: 800; }

.auth-card { display: grid; align-content: center; padding: 52px; background: var(--surface); }
.stack-form { display: grid; gap: 18px; }
.form-grid { display: grid; gap: 16px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

label { color: var(--navy); font-size: .82rem; font-weight: 750; letter-spacing: .01em; }
label small, .field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: .77rem; font-weight: 450; }

input, select, textarea {
    width: 100%;
    margin-top: 7px;
    border: 1px solid var(--line-dark);
    border-radius: 9px;
    color: var(--ink);
    background: white;
    transition: border-color .15s, box-shadow .15s;
}

input, select { height: 42px; padding: 0 12px; }
textarea { min-height: 98px; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,119,168,.11); outline: none; }

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: 9px;
    font-size: .84rem;
    font-weight: 750;
    text-decoration: none;
    transition: transform .12s, box-shadow .12s, background .12s;
}
.button:hover { transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.primary { color: white; background: var(--orange); box-shadow: 0 8px 18px rgba(236,107,45,.22); }
.button.primary:hover { background: #db5b20; }
.button.secondary { border-color: var(--line-dark); color: var(--navy); background: white; }
.button.secondary:hover { border-color: var(--blue); color: var(--blue); }
.button.ghost { color: var(--muted); background: transparent; }
.button.ghost:hover { color: var(--navy); background: rgba(255,255,255,.65); }
.button.danger { border-color: #e9bbbb; color: var(--danger); background: white; }
.button.compact { min-height: 34px; padding: 0 11px; font-size: .78rem; }
.button.wide { width: 100%; min-height: 47px; }
.button[disabled] { cursor: not-allowed; opacity: .55; transform: none; }

.alert { margin-bottom: 20px; padding: 12px 14px; border-radius: 10px; font-size: .84rem; }
.alert p { margin: 0; }
.alert p + p { margin-top: 5px; }
.alert-error { border: 1px solid #efc1c1; color: var(--danger); background: var(--danger-soft); }
.alert-success { border: 1px solid #b9dfc9; color: var(--success); background: var(--success-soft); }
.security-note { margin: 22px 0 0; color: var(--muted); font-size: .76rem; text-align: center; }

.app-page { background: #f2f4f5; }
.topbar {
    position: sticky;
    z-index: 50;
    top: 0;
    display: grid;
    grid-template-columns: auto 1fr auto;
    min-height: 70px;
    align-items: center;
    gap: 26px;
    padding: 10px 24px;
    border-bottom: 1px solid #d6dde1;
    background: rgba(255,255,255,.96);
    backdrop-filter: blur(14px);
}

.brand-lockup { display: flex; align-items: center; gap: 11px; white-space: nowrap; }
.brand-lockup strong, .brand-lockup span { display: block; }
.brand-lockup strong { font-size: .96rem; }
.brand-lockup span { color: var(--muted); font-size: .69rem; }

.main-nav { display: flex; justify-content: center; gap: 4px; }
.nav-button { height: 38px; padding: 0 13px; border: 0; border-radius: 9px; color: var(--muted); background: transparent; font-size: .81rem; font-weight: 700; }
.nav-button:hover { color: var(--navy); background: #f0f3f5; }
.nav-button.active { color: var(--navy); background: #e9eef2; box-shadow: inset 0 -2px var(--orange); }

.user-actions { display: flex; align-items: center; gap: 8px; }
.actor-field { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: .7rem; }
.actor-field input { width: 150px; height: 34px; margin: 0; font-size: .78rem; }

.app-main { width: min(1800px, 100%); margin: 0 auto; padding: 24px; }
.view-shell { display: grid; gap: 18px; }
.view-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }
.view-title h1 { margin: 0; color: var(--navy); font-size: clamp(1.55rem, 2.5vw, 2.15rem); letter-spacing: -.035em; }
.view-title p { margin: 5px 0 0; color: var(--muted); font-size: .88rem; }
.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: 0 3px 14px rgba(23,50,77,.04); }
.panel-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; color: var(--navy); font-size: 1rem; }
.panel-body { padding: 18px; }

.toolbar { display: grid; grid-template-columns: minmax(230px, 1fr) repeat(3, minmax(150px, auto)); gap: 10px; padding: 14px; border-bottom: 1px solid var(--line); background: var(--surface-2); }
.toolbar label { font-size: .7rem; }
.toolbar input, .toolbar select { height: 38px; margin-top: 4px; font-size: .8rem; }
.toolbar.systems-toolbar { grid-template-columns: minmax(250px, 1fr) minmax(180px, 260px); }
.search-field { position: relative; }
.search-field input { padding-left: 36px; }
.search-field::before { position: absolute; left: 13px; bottom: 10px; content: "⌕"; color: var(--muted); font-size: 1.1rem; }

.legend { display: flex; flex-wrap: wrap; align-items: center; gap: 13px; padding: 10px 14px; border-bottom: 1px solid var(--line); color: var(--muted); background: #fff; font-size: .73rem; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot { display: inline-grid; width: 23px; height: 23px; place-items: center; border: 1px solid var(--line-dark); border-radius: 6px; background: white; color: var(--success); font-size: .72rem; font-weight: 900; }
.legend-dot.inherited { border-style: dashed; background: #eef5f4; color: var(--teal); }

.matrix-wrap { max-height: calc(100vh - 290px); min-height: 420px; overflow: auto; overscroll-behavior: contain; }
.matrix-table { width: max-content; min-width: 100%; border-collapse: separate; border-spacing: 0; font-size: .76rem; }
.matrix-table th, .matrix-table td { min-width: 76px; height: 46px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; vertical-align: middle; }
.matrix-table thead th { position: sticky; z-index: 12; top: 0; color: var(--navy); background: #edf1f4; font-weight: 800; }
.matrix-table thead tr:nth-child(2) th { z-index: 11; top: 47px; background: #f7f9fa; }
.matrix-table .system-heading { z-index: 20; left: 0; width: 300px; min-width: 300px; text-align: left; }
.matrix-table .system-cell { position: sticky; z-index: 8; left: 0; width: 300px; min-width: 300px; padding: 8px 12px; text-align: left; background: white; box-shadow: 5px 0 10px rgba(23,50,77,.045); }
.matrix-table tbody tr:hover td { background: #fbfcfd; }
.matrix-table tbody tr:hover .system-cell { background: #f7fafb; }
.department-group { min-width: 150px !important; border-bottom: 2px solid #aebbc5 !important; }
.department-group span { display: block; margin-top: 1px; color: var(--muted); font-size: .64rem; font-weight: 600; }
.scope-heading { max-width: 110px; min-width: 84px !important; font-size: .69rem; line-height: 1.15; }
.scope-heading.whole { color: #9c4b23; background: var(--orange-soft) !important; }

.system-cell-main { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.system-name { display: block; overflow-wrap: anywhere; color: var(--navy); font-size: .8rem; font-weight: 780; }
.system-name.iconless { padding: 0; border: 0; text-align: left; background: transparent; }
.system-name.iconless:hover { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.system-meta { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 5px; }
.badge { display: inline-flex; min-height: 20px; align-items: center; padding: 1px 7px; border-radius: 999px; color: #52616e; background: #edf1f3; font-size: .62rem; font-weight: 700; }
.badge.sjaelland { color: #1b638e; background: #e5f2f9; }
.badge.hovedstaden { color: #267069; background: #e7f3f0; }
.badge.new { color: #9b4b21; background: var(--orange-soft); }
.badge.warning { color: var(--warning); background: var(--warning-soft); }
.icon-button { display: inline-grid; width: 28px; min-width: 28px; height: 28px; place-items: center; border: 1px solid transparent; border-radius: 7px; color: var(--muted); background: transparent; font-size: .9rem; }
.icon-button:hover { border-color: var(--line); color: var(--navy); background: white; }

.mapping-cell { position: relative; padding: 4px !important; background: #fcfdfd; }
.mapping-cell.whole { background: #fffaf7; }
.mapping-toggle { display: grid; width: 34px; height: 34px; margin: 0 auto; place-items: center; border: 1px solid #c9d2d8; border-radius: 8px; color: transparent; background: white; font-size: .9rem; font-weight: 900; }
.mapping-toggle:hover { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(36,119,168,.08); }
.mapping-toggle.selected { border-color: #72ae8c; color: white; background: var(--success); }
.mapping-toggle.inherited { border-style: dashed; border-color: #8fb9b4; color: var(--teal); background: #eaf4f2; }
.mapping-note { position: absolute; right: 3px; bottom: 2px; display: grid; width: 18px; height: 18px; place-items: center; border: 0; border-radius: 50%; color: #9b4b21; background: #ffe2d4; font-size: .65rem; }

.empty-state { display: grid; min-height: 360px; place-items: center; padding: 40px; text-align: center; }
.empty-state > div { max-width: 520px; }
.empty-state .empty-icon { display: grid; width: 62px; height: 62px; margin: 0 auto 18px; place-items: center; border-radius: 18px; color: var(--orange); background: var(--orange-soft); font-size: 1.7rem; }
.empty-state h2 { margin: 0 0 8px; color: var(--navy); }
.empty-state p { margin: 0 0 20px; color: var(--muted); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric-card { padding: 18px; border: 1px solid var(--line); border-radius: var(--radius); background: white; }
.metric-card span { display: block; color: var(--muted); font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; }
.metric-card strong { display: block; margin: 8px 0 2px; color: var(--navy); font-size: 2rem; line-height: 1; letter-spacing: -.045em; }
.metric-card small { color: var(--muted); }
.metric-card.accent { border-color: #f3c3ad; background: linear-gradient(150deg, #fff, var(--orange-soft)); }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, .6fr); gap: 14px; }
.progress-list { display: grid; gap: 10px; }
.progress-row { display: grid; grid-template-columns: minmax(170px, 1fr) 1.2fr auto; align-items: center; gap: 15px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.progress-row:last-child { border-bottom: 0; }
.progress-row strong, .progress-row small { display: block; }
.progress-row small { margin-top: 3px; color: var(--muted); }
.progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #e8edf0; }
.progress-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--teal), #5aa89e); }
.progress-track .progress-not_started { width: 0; }
.progress-track .progress-in_progress { width: 35%; }
.progress-track .progress-ready { width: 75%; }
.progress-track .progress-completed { width: 100%; }
.status-pill { display: inline-flex; min-height: 26px; align-items: center; padding: 2px 9px; border-radius: 999px; font-size: .68rem; font-weight: 800; white-space: nowrap; }
.status-not_started { color: #687681; background: #edf0f2; }
.status-in_progress { color: #80540e; background: #fff2ce; }
.status-ready { color: #1f648c; background: #e6f3fa; }
.status-completed { color: #26704a; background: #e6f5ed; }

.quality-list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.quality-list li { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.quality-list li:last-child { border-bottom: 0; }
.quality-list span { color: var(--muted); }
.quality-list strong { color: var(--navy); }

.organisation-stack { display: grid; gap: 18px; }
.organisation-block { overflow: hidden; }
.organisation-title { display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 15px 18px; color: white; background: var(--navy); }
.organisation-title h2 { margin: 0; font-size: 1.05rem; }
.organisation-title .button { color: white; }
.department-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 12px; padding: 14px; }
.department-card { display: grid; gap: 13px; padding: 16px; border: 1px solid var(--line); border-radius: 12px; background: white; }
.department-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.department-card h3 { margin: 0; color: var(--navy); font-size: 1rem; }
.coordinator { color: var(--muted); font-size: .78rem; }
.coordinator strong { color: var(--ink); }
.section-list { display: flex; flex-wrap: wrap; gap: 6px; min-height: 26px; }
.section-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 1px solid #d8e2e1; border-radius: 7px; color: #3f6964; background: #eff6f5; font-size: .7rem; }
.section-chip button { padding: 0; border: 0; color: inherit; background: transparent; font-weight: 800; }
.department-actions { display: flex; flex-wrap: wrap; gap: 7px; }
.status-select { width: auto; min-width: 150px; height: 34px; margin: 0; font-size: .72rem; }

.data-table-wrap { overflow: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.data-table th, .data-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.data-table th { position: sticky; top: 0; color: var(--navy); background: #edf1f4; font-size: .69rem; text-transform: uppercase; letter-spacing: .05em; }
.data-table tbody tr:hover { background: #fafcfd; }
.data-table .actions { white-space: nowrap; text-align: right; }
.truncate { display: -webkit-box; overflow: hidden; -webkit-box-orient: vertical; -webkit-line-clamp: 2; color: var(--muted); }

.audit-list { display: grid; }
.audit-item { display: grid; grid-template-columns: 150px 150px 1fr; gap: 18px; padding: 13px 18px; border-bottom: 1px solid var(--line); }
.audit-item:last-child { border-bottom: 0; }
.audit-time, .audit-actor { color: var(--muted); font-size: .75rem; }
.audit-summary { font-size: .82rem; }

.modal-backdrop { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(10,27,42,.62); backdrop-filter: blur(4px); }
.modal { width: min(720px, 100%); max-height: calc(100vh - 48px); overflow: auto; border-radius: 18px; background: white; box-shadow: 0 25px 70px rgba(3,15,25,.35); }
.modal.wide { width: min(960px, 100%); }
.modal-header { position: sticky; z-index: 2; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 18px 20px; border-bottom: 1px solid var(--line); background: white; }
.modal-header h2 { margin: 0; color: var(--navy); font-size: 1.15rem; }
.modal-close { display: grid; width: 34px; height: 34px; place-items: center; border: 0; border-radius: 8px; color: var(--muted); background: #f0f3f5; font-size: 1.2rem; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding-top: 18px; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.detail { padding: 10px 0; border-bottom: 1px solid var(--line); }
.detail.full { grid-column: 1 / -1; }
.detail span, .detail strong { display: block; }
.detail span { color: var(--muted); font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; }
.detail strong { margin-top: 4px; font-size: .84rem; white-space: pre-wrap; }

.toast-root { position: fixed; z-index: 200; right: 22px; bottom: 22px; display: grid; gap: 8px; }
.toast { min-width: 260px; max-width: 420px; padding: 12px 15px; border-radius: 10px; color: white; background: var(--navy); box-shadow: var(--shadow); font-size: .82rem; animation: toast-in .18s ease-out; }
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.loading-state { display: grid; min-height: 60vh; place-items: center; align-content: center; color: var(--muted); }
.spinner { width: 34px; height: 34px; border: 3px solid #d8e0e4; border-top-color: var(--orange); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1120px) {
    .topbar { grid-template-columns: auto 1fr; }
    .main-nav { grid-column: 1 / -1; grid-row: 2; justify-content: flex-start; overflow-x: auto; }
    .user-actions { justify-self: end; }
    .matrix-wrap { max-height: calc(100vh - 340px); }
    .metric-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 780px) {
    .auth-page { padding: 14px; }
    .auth-shell { grid-template-columns: 1fr; }
    .auth-brand { min-height: auto; padding: 36px 28px; }
    .auth-brand h1 { font-size: 2.4rem; }
    .auth-card { padding: 30px 24px; }
    .form-grid.two, .form-grid.three { grid-template-columns: 1fr; }
    .topbar { display: flex; flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
    .main-nav { order: 3; width: 100%; justify-content: flex-start; }
    .user-actions { margin-left: auto; }
    .actor-field { display: none; }
    .app-main { padding: 14px; }
    .view-header { align-items: flex-start; flex-direction: column; }
    .header-actions { justify-content: flex-start; }
    .toolbar { grid-template-columns: 1fr 1fr; }
    .search-field { grid-column: 1 / -1; }
    .metric-grid { grid-template-columns: 1fr 1fr; }
    .content-grid { grid-template-columns: 1fr; }
    .audit-item { grid-template-columns: 1fr; gap: 3px; }
    .details-grid { grid-template-columns: 1fr; }
    .detail.full { grid-column: auto; }
}

@media (max-width: 500px) {
    .metric-grid { grid-template-columns: 1fr; }
    .toolbar { grid-template-columns: 1fr; }
    .search-field { grid-column: auto; }
    .brand-lockup div { display: none; }
    .nav-button { padding: 0 10px; }
    .matrix-table .system-heading, .matrix-table .system-cell { width: 210px; min-width: 210px; }
}

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