:root {
    --ink: #1b2430;
    --muted: #667085;
    --line: #d7dde7;
    --panel: #ffffff;
    --bg: #f4f6f8;
    --blue: #0f6f95;
    --blue-dark: #084b65;
    --red: #ff0000;
    --yellow: #ffff00;
    --green: #00b050;
    --sticky-topbar-height: 57px;
    --sticky-risk-header-height: 42px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--ink);
    background: var(--bg);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
}

a {
    color: var(--blue-dark);
    font-weight: 700;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 14px 28px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.brand {
    color: var(--ink);
    font-size: 20px;
    letter-spacing: 0;
}

.nav-links {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
}

.page-shell {
    width: min(1500px, calc(100% - 32px));
    margin: 24px auto 48px;
}

.page-heading {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
}

.page-heading h1 {
    margin: 0;
    font-size: 30px;
    letter-spacing: 0;
}

.page-heading p,
.muted,
.empty {
    color: var(--muted);
    margin: 4px 0 0;
}

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    margin-bottom: 18px;
}

.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--ink);
    padding: 8px 13px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}

.button.primary {
    background: var(--blue);
    border-color: var(--blue);
    color: #ffffff;
}

.danger-button {
    background: #b42318;
    border-color: #b42318;
    color: #ffffff;
}

.button-row,
.form-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.form-grid .wide,
.wide {
    grid-column: 1 / -1;
}

label {
    display: grid;
    gap: 6px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 9px 10px;
    color: var(--ink);
    background: #ffffff;
    font: inherit;
    font-weight: 400;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
}

.checkbox input,
.check-card input {
    width: auto;
}

.filters {
    display: grid;
    grid-template-columns: repeat(4, minmax(160px, 1fr)) auto;
    gap: 12px;
    align-items: end;
}

.data-table,
.print-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td,
.print-table th,
.print-table td {
    border: 1px solid var(--line);
    padding: 8px;
    vertical-align: top;
}

.data-table th,
.print-table th {
    background: #eef2f6;
    text-align: left;
}

.table-scroll {
    overflow: visible;
}

.risk-register {
    min-width: 980px;
    table-layout: fixed;
}

.sticky-risk-register {
    border-collapse: separate;
    border-spacing: 0;
}

.phase-risk-section {
    padding-top: 0;
}

.phase-table-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: baseline;
    position: sticky;
    top: var(--sticky-topbar-height);
    z-index: 7;
    margin: 0 -18px 0;
    padding: 12px 18px;
    border-bottom: 1px solid var(--line);
    background: #00a6d6;
    color: #000000;
}

.phase-table-heading h2 {
    margin: 0;
    font-size: 16px;
    letter-spacing: 0;
}

.phase-table-heading p {
    margin: 0;
    font-size: 13px;
}

.risk-register th:nth-child(1) {
    width: 24%;
}

.risk-register th:nth-child(2),
.risk-register th:nth-child(5) {
    width: 58px;
}

.risk-register th:nth-child(3) {
    width: 49%;
}

.risk-register th:nth-child(4) {
    width: 115px;
}

.sticky-risk-register thead th {
    position: sticky;
    top: calc(var(--sticky-topbar-height) + 46px);
    z-index: 6;
    background: #464d57;
    color: #ffffff;
    text-align: center;
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0;
}

.sticky-section-row td {
    position: sticky;
    top: calc(var(--sticky-topbar-height) + 46px + var(--sticky-risk-header-height));
    z-index: 5;
    box-shadow: 0 1px 0 var(--line);
}

.risk-cell {
    text-align: center;
    font-weight: bold;
    min-width: 72px;
}

.risk-cell small {
    display: block;
    margin-top: 4px;
    font-size: 10px;
    line-height: 1.2;
}

.inline-risk-cell {
    position: relative;
    padding: 4px;
}

.inline-risk-input {
    width: 44px;
    margin: 0 auto;
    padding: 5px 4px;
    text-align: center;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.9);
}

.inline-risk-cell small {
    display: none;
}

.risk-matrix-open {
    position: absolute;
    left: 50%;
    bottom: 4px;
    z-index: 3;
    min-height: 24px;
    width: max-content;
    min-width: 86px;
    border-color: #344054;
    border-radius: 5px;
    background: #ffffff;
    color: var(--ink);
    padding: 3px 7px;
    font-size: 11px;
    font-weight: 700;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%);
    box-shadow: 0 6px 16px rgba(16, 24, 40, 0.18);
}

.inline-risk-cell:hover .risk-matrix-open,
.inline-risk-cell:focus-within .risk-matrix-open {
    opacity: 1;
    pointer-events: auto;
}

.inline-who-select,
.inline-who-custom {
    min-width: 0;
    font-size: 12px;
    padding: 5px 6px;
}

.inline-who-select {
    min-height: 64px;
}

.inline-who-custom {
    margin-top: 4px;
}

.inline-status {
    display: block;
    min-height: 17px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.inline-status.saved {
    color: #027a48;
}

.inline-status.error {
    color: #b42318;
}

.risk-red {
    background: var(--red) !important;
    color: #ffffff !important;
}

.risk-yellow {
    background: var(--yellow) !important;
    color: #000000 !important;
}

.risk-green {
    background: var(--green) !important;
    color: #ffffff !important;
}

.risk-invalid {
    background: #111827;
    color: #ffffff;
}

.phase-row td {
    background: #00a6d6 !important;
    color: #000000;
    font-weight: bold;
    scroll-margin-top: calc(var(--sticky-topbar-height) + var(--sticky-risk-header-height) + 34px);
}

.phase-row span {
    display: block;
    font-weight: 400;
}

.section-row td {
    background: #d9d9d9 !important;
    font-weight: bold;
    scroll-margin-top: calc(var(--sticky-topbar-height) + var(--sticky-risk-header-height));
}

.section-row-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.section-row-content form {
    margin: 0;
}

.section-row-content .mini-button {
    opacity: 0;
    pointer-events: none;
}

.section-row:hover .mini-button,
.section-row:focus-within .mini-button {
    opacity: 1;
    pointer-events: auto;
}

.hover-action-cell {
    position: relative;
}

.cell-text {
    min-height: 42px;
}

.row-hover-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    opacity: 0;
    pointer-events: none;
    position: absolute;
    right: 8px;
    top: 8px;
    z-index: 2;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.14);
    transition: opacity 120ms ease;
}

.hover-action-cell:hover .row-hover-actions,
.hover-action-cell:focus-within .row-hover-actions {
    opacity: 1;
    pointer-events: auto;
}

.mini-button,
.drag-chip {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: #ffffff;
    color: var(--ink);
    padding: 3px 7px;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none;
    white-space: nowrap;
}

.drag-chip {
    cursor: grab;
    color: var(--muted);
}

.mini-button.danger {
    color: #b42318;
}

.risk-draggable-row {
    cursor: grab;
    scroll-margin-top: 190px;
}

.risk-draggable-row input,
.risk-draggable-row select,
.risk-draggable-row textarea,
.risk-draggable-row button,
.risk-draggable-row a {
    cursor: auto;
}

.risk-draggable-row.is-dragging {
    opacity: 0.55;
}

.risk-draggable-row.drag-over-before td {
    border-top: 3px solid var(--blue);
}

.risk-draggable-row.drag-over-after td {
    border-bottom: 3px solid var(--blue);
}

.risk-draggable-row.anchor-highlight td {
    animation: anchorPulse 1.8s ease;
}

.section-row.anchor-highlight td,
.phase-table-heading.anchor-highlight {
    animation: anchorPulse 1.6s ease;
}

@keyframes anchorPulse {
    0% {
        box-shadow: inset 0 0 0 9999px rgba(15, 111, 149, 0.16);
    }
    100% {
        box-shadow: inset 0 0 0 9999px rgba(15, 111, 149, 0);
    }
}

.actions {
    display: flex;
    gap: 8px;
    align-items: flex-start;
    flex-wrap: wrap;
    font-size: 13px;
}

.link-button {
    min-height: 0;
    border: 0;
    padding: 0;
    color: var(--blue-dark);
    background: transparent;
    font-weight: 700;
}

.link-button.danger {
    color: #b42318;
}

.confirm-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.42);
}

.confirm-dialog {
    width: min(420px, 100%);
    border-radius: 8px;
    background: #ffffff;
    border: 1px solid var(--line);
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    padding: 20px;
}

.confirm-dialog h2 {
    margin: 0 0 8px;
    font-size: 20px;
}

.confirm-dialog p {
    margin: 0;
    color: var(--muted);
}

.confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 18px;
}

.risk-matrix-overlay {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.42);
}

.risk-matrix-dialog {
    width: min(980px, 100%);
    max-height: calc(100vh - 40px);
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 24px 60px rgba(15, 23, 42, 0.28);
    padding: 18px;
}

.risk-matrix-titlebar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.risk-matrix-titlebar h2 {
    margin: 0;
    font-size: 22px;
}

.risk-matrix-titlebar p {
    margin: 3px 0 0;
    color: var(--muted);
}

.icon-close-button {
    width: 34px;
    min-height: 34px;
    padding: 0;
    font-size: 18px;
    line-height: 1;
}

.risk-matrix-picker-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}

.risk-matrix-picker-table th,
.risk-matrix-picker-table td {
    border: 1px solid var(--line);
    padding: 8px;
    vertical-align: middle;
}

.risk-matrix-picker-table thead th {
    background: #464d57;
    color: #ffffff;
    text-align: center;
}

.risk-matrix-picker-table tbody th {
    width: 42%;
    background: #f2f4f7;
    font-size: 13px;
    text-align: left;
}

.risk-matrix-picker-table td {
    text-align: center;
}

.risk-matrix-score {
    width: 100%;
    min-height: 52px;
    border: 2px solid transparent;
    border-radius: 6px;
    font-size: 22px;
    font-weight: 800;
}

.risk-matrix-score:hover,
.risk-matrix-score:focus,
.risk-matrix-score.selected {
    border-color: #101828;
    outline: none;
}

.floating-toast {
    position: fixed;
    top: 72px;
    left: 50%;
    z-index: 120;
    transform: translateX(-50%);
    max-width: min(560px, calc(100% - 32px));
    border: 1px solid #abefc6;
    border-radius: 8px;
    background: #ecfdf3;
    color: #054f31;
    padding: 12px 16px;
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.2);
    font-weight: 700;
    transition: opacity 180ms ease, transform 180ms ease;
}

.floating-toast.error {
    border-color: #fecdca;
    background: #fef3f2;
    color: #912018;
}

.floating-toast.is-leaving {
    opacity: 0;
    transform: translate(-50%, -8px);
}

.flash {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    background: #ecfdf3;
    color: #054f31;
}

.flash-error {
    background: #fef3f2;
    color: #912018;
}

.status-pill,
.tag {
    display: inline-flex;
    border-radius: 999px;
    background: #eef2f6;
    padding: 3px 8px;
    font-size: 12px;
    font-weight: 700;
}

.muted-row {
    opacity: 0.62;
}

.risk-register .muted-row td {
    background-color: #f2f4f7 !important;
    color: #667085 !important;
}

.risk-register .muted-row .risk-red,
.risk-register .muted-row .risk-yellow,
.risk-register .muted-row .risk-green {
    background-color: #e4e7ec !important;
    color: #667085 !important;
}

.metric-grid {
    display: grid;
    grid-template-columns: repeat(6, minmax(130px, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}

.metric {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    padding: 15px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 700;
}

.metric strong {
    display: block;
    margin-top: 6px;
    font-size: 28px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}

.detail-grid p {
    margin: 6px 0 0;
}

.action-list {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
}

.checklist-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.check-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    background: #ffffff;
}

.check-card span {
    display: flex;
    gap: 9px;
    align-items: flex-start;
}

.check-card.selected {
    border-color: var(--blue);
    box-shadow: inset 4px 0 0 var(--blue);
}

.sticky-actions {
    position: sticky;
    bottom: 0;
    background: var(--bg);
    padding: 14px 0;
    margin-top: 12px;
}

.print-body {
    background: #ffffff;
    color: #000000;
    width: min(1100px, calc(100% - 32px));
    margin: 24px auto;
}

.print-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 18px;
}

.print-cover h1 {
    font-size: 34px;
    margin-bottom: 4px;
}

.selected-print-row td {
    background: #e0f2fe;
    font-weight: bold;
}

code {
    background: #eef2f6;
    border-radius: 4px;
    padding: 2px 4px;
}

@media (max-width: 820px) {
    .topbar,
    .page-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .filters,
    .form-grid,
    .metric-grid,
    .detail-grid,
    .checklist-grid {
        grid-template-columns: 1fr;
    }
}

@media print {
    body {
        background: #ffffff;
        font-size: 10pt;
    }

    .no-print,
    .topbar {
        display: none !important;
    }

    .print-body {
        width: auto;
        margin: 0;
    }

    table {
        page-break-inside: auto;
        border-collapse: collapse;
        width: 100%;
    }

    tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    th,
    td {
        border: 1px solid #333 !important;
        padding: 4px;
        vertical-align: top;
    }

    .page-break {
        page-break-before: always;
    }
}
