:root {
    --bg: #0f1419;
    --surface: #1a2332;
    --surface-2: #243044;
    --text: #e8eef7;
    --muted: #8b9cb3;
    --accent: #3d8bfd;
    --accent-dim: #2563eb;
    --ok: #22c55e;
    --warn: #f59e0b;
    --bad: #ef4444;
    --border: #2d3a4f;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
}

.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 1.25rem 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    min-height: 100vh;
    max-height: 100vh;
    overflow: hidden;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    font-weight: 700;
    font-size: 1.1rem;
    padding: 0 0.35rem;
    flex-shrink: 0;
}

.brand-mark {
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    background: var(--accent);
    color: white;
    display: grid;
    place-items: center;
}

.nav-sections {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
    padding-right: 0.15rem;
}

.nav-section {
    border-radius: 0.55rem;
}

.nav-section.expanded {
    background: rgba(36, 48, 68, 0.45);
}

.nav-section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.55rem 0.65rem;
    border: 0;
    border-radius: 0.55rem;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    text-align: left;
}

.nav-section-toggle:hover {
    background: var(--surface-2);
}

.nav-section.expanded > .nav-section-toggle {
    color: white;
}

.nav-section-label {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-width: 0;
}

.nav-section-icon {
    width: 1.25rem;
    text-align: center;
    flex-shrink: 0;
    font-size: 0.95rem;
    line-height: 1;
}

.nav-chevron {
    width: 0.4rem;
    height: 0.4rem;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: rotate(-45deg);
    transition: transform 0.15s ease;
    flex-shrink: 0;
    margin-right: 0.15rem;
}

.nav-section.expanded .nav-chevron {
    transform: rotate(45deg);
    border-color: var(--text);
}

.nav-links {
    list-style: none;
    padding: 0 0.35rem 0.4rem 0.55rem;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.nav-links a {
    display: block;
    padding: 0.4rem 0.65rem 0.4rem 1.55rem;
    border-radius: 0.45rem;
    color: var(--muted);
    font-size: 0.88rem;
}

.nav-links a:hover {
    color: var(--text);
    text-decoration: none;
    background: rgba(61, 139, 253, 0.08);
}

.nav-links a.active {
    background: var(--surface-2);
    color: white;
}

.sidebar-foot {
    margin-top: auto;
    font-size: 0.85rem;
    position: relative;
    z-index: 30;
    flex-shrink: 0;
    padding: 0 0.15rem;
}

.user-menu {
    position: relative;
    width: 100%;
}

.user-menu-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.user-menu-trigger:hover {
    border-color: var(--accent-dim);
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    border-radius: 999px;
    background: var(--accent);
    color: white;
    display: grid;
    place-items: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.user-label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.user-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-email {
    font-size: 0.75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-chevron {
    color: var(--muted);
    font-size: 0.7rem;
}

.user-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 20;
}

.user-menu-panel {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(100% + 0.4rem);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    z-index: 40;
}

.user-menu-section {
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.user-menu-section:last-child {
    border-bottom: none;
}

.user-menu-title {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-bottom: 0.35rem;
}

.user-menu-meta {
    font-size: 0.82rem;
    margin-bottom: 0.35rem;
    word-break: break-all;
}

.user-menu-roles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.user-menu-item {
    display: block;
    padding: 0.45rem 0.5rem;
    border-radius: 0.45rem;
    color: var(--text);
    text-decoration: none;
}

.user-menu-item:hover {
    background: var(--surface-2);
    text-decoration: none;
}

.user-menu-item.active {
    background: var(--surface-2);
    color: white;
}

.user-menu-foot .user-menu-item {
    font-size: 0.82rem;
}

.content {
    padding: 1.5rem 2rem 3rem;
    max-width: 1200px;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

h1 { margin: 0 0 0.25rem; font-size: 1.75rem; }
h2 { margin: 0 0 0.75rem; font-size: 1.15rem; }

.muted { color: var(--muted); font-size: 0.9rem; }

.btn {
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent-dim);
    color: white;
}

.btn.danger {
    background: #8b2e2e;
    border-color: #a33;
    color: #fff;
}

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
}

.stat-value { font-size: 1.75rem; font-weight: 700; }
.stat-label { color: var(--muted); font-size: 0.85rem; }

.two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1rem;
}

@media (max-width: 800px) {
    .app-shell { grid-template-columns: 1fr; }
    .two-col { grid-template-columns: 1fr; }
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.metric-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.metric-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
}

.metric-list li:last-child { border-bottom: none; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

.data-table th { color: var(--muted); font-weight: 600; }

.truncate {
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.status-effective, .status-effective .stat-value { color: var(--ok); }
.status-atrisk, .status-atrisk .stat-value { color: var(--warn); }
.status-failing, .status-failing .stat-value { color: var(--bad); }
.status-excepted, .status-excepted .stat-value { color: var(--muted); }
.status-notassessed, .status-notassessed .stat-value { color: var(--muted); }

.row-attention td { background: rgba(245, 158, 11, 0.06); }

.alert.error {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid var(--bad);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.framework-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1.25rem;
}

.chip {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 0.4rem 0.75rem;
    border-radius: 999px;
    cursor: pointer;
}

.chip.active {
    background: var(--accent);
    border-color: var(--accent-dim);
}

.readiness-header {
    display: flex;
    align-items: center;
    gap: 1.25rem;
    margin-bottom: 1rem;
}

.readiness-pct {
    font-size: 2.5rem;
    font-weight: 800;
    color: var(--ok);
}

.warn { color: var(--warn); }

.filter-input, .form-row select, .form-row input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
}

.form-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
    max-width: 320px;
}

#blazor-error-ui {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 0.75rem 1rem;
    background: #b32121;
    color: white;
    z-index: 1000;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
}

.header-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }

.btn {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.45rem 0.85rem;
    border-radius: 6px;
    cursor: pointer;
}

.btn.primary { background: var(--accent); border-color: var(--accent-dim); color: white; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.85rem; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    margin-bottom: 1rem;
}

.form-card { max-width: 480px; }
.form-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

.stat-value-sm { font-size: 1.1rem; font-weight: 600; }

.alert.success {
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid var(--ok);
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
}

.policy-editor { margin-bottom: 1.5rem; }

.editor-toolbar {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
    padding: 0.5rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 0.5rem 0.5rem 0 0;
}

.editor-surface {
    min-height: 320px;
    padding: 1rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 0 0 0.5rem 0.5rem;
    outline: none;
}

.editor-surface.readonly { opacity: 0.85; }
.editor-status { margin-left: auto; color: var(--muted); font-size: 0.85rem; align-self: center; }

.comment-list { list-style: none; padding: 0; margin: 0; }
.comment-item { padding: 0.75rem 0; border-bottom: 1px solid var(--border); }
.comment-item.resolved { opacity: 0.6; }
.comment-anchor { border-left: 3px solid var(--accent); padding-left: 0.75rem; color: var(--muted); margin: 0.35rem 0; }

.comments-panel .form-row { flex-direction: row; flex-wrap: wrap; align-items: center; max-width: none; }
.muted-input { flex: 1; min-width: 180px; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: grid;
    place-items: center;
    z-index: 50;
}

.modal { max-width: 520px; width: 90%; }
.modal.modal-wide { max-width: 760px; }
.modal-wide { max-height: 85vh; overflow-y: auto; }

.setup-guide {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    padding: 0.85rem 1rem;
    margin: 1rem 0;
}

.setup-guide h3 {
    margin: 0 0 0.35rem;
    font-size: 0.95rem;
}

.setup-guide-steps {
    margin: 0.5rem 0 0;
    padding-left: 1.25rem;
    font-size: 0.88rem;
    line-height: 1.5;
}

.setup-guide-steps li {
    margin-bottom: 0.35rem;
}

.setup-guide-doc {
    margin: 0.65rem 0 0;
    font-size: 0.85rem;
}

.cell-clickable { cursor: pointer; }
.cell-clickable:hover { background: rgba(120, 120, 120, 0.12); }
.icon-ok { color: #1a7f37; font-weight: 600; }
.icon-gap { color: #b42318; font-weight: 600; }

.data-table.compact td, .data-table.compact th { padding: 0.35rem 0.5rem; font-size: 0.9rem; }
.action-cell { display: flex; gap: 0.35rem; flex-wrap: wrap; align-items: center; }

textarea {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.5rem;
    border-radius: 6px;
    width: 100%;
}

.policy-content-card h2 { margin-top: 0; }
.version-picker { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; margin-bottom: 1rem; }

.policy-body-view {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.25rem;
    line-height: 1.65;
    font-size: 1rem;
}

.policy-body-view .policy-imported,
.editor-surface .policy-imported {
    max-width: 52rem;
}

.policy-body-view h1,
.editor-surface h1 {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.25;
    margin: 0 0 0.75rem;
}

.policy-body-view h2,
.editor-surface h2 {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.3;
    margin: 1.25rem 0 0.5rem;
}

.policy-body-view h3,
.editor-surface h3 {
    font-size: 1.1rem;
    font-weight: 600;
    line-height: 1.35;
    margin: 1rem 0 0.35rem;
}

.policy-body-view p,
.editor-surface p {
    margin: 0.5rem 0;
}

.policy-body-view h2.policy-subtitle,
.editor-surface h2.policy-subtitle {
    font-size: 1.5rem;
    margin-top: 0.5rem;
}

.policy-body-view p.policy-meta,
.editor-surface p.policy-meta {
    font-size: 0.95rem;
    margin: 0.2rem 0;
    line-height: 1.45;
}

.policy-body-view p.policy-meta strong,
.editor-surface p.policy-meta strong {
    font-weight: 700;
}

.policy-body-view ul.policy-list,
.editor-surface ul.policy-list {
    margin: 0.5rem 0 0.85rem 1.75rem;
    padding-left: 0.35rem;
    list-style-type: disc;
}

.policy-body-view ul.policy-list li,
.editor-surface ul.policy-list li {
    margin: 0.4rem 0;
    line-height: 1.55;
    padding-left: 0.25rem;
}

.policy-body-view hr.policy-rule,
.editor-surface hr.policy-rule {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 1rem 0;
}

.policy-body-view strong,
.editor-surface strong {
    font-weight: 700;
}

.policy-body-view table.policy-table,
.editor-surface table.policy-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0.75rem 0 1rem;
    font-size: 0.92rem;
}

.policy-body-view table.policy-table th,
.policy-body-view table.policy-table td,
.editor-surface table.policy-table th,
.editor-surface table.policy-table td {
    border: 1px solid var(--border);
    padding: 0.45rem 0.6rem;
    vertical-align: top;
    text-align: left;
    line-height: 1.45;
}

.policy-body-view table.policy-table th,
.editor-surface table.policy-table th {
    background: rgba(255, 255, 255, 0.04);
    font-weight: 700;
}

.policy-body-view figure.policy-figure,
.editor-surface figure.policy-figure {
    margin: 1rem 0;
    max-width: 100%;
    overflow: hidden;
}

.policy-body-view img.policy-embed-image,
.editor-surface img.policy-embed-image,
.policy-body-view .policy-image img,
.editor-surface .policy-image img {
    max-width: 100%;
    height: auto;
    display: block;
}

.policy-body-view h1, .policy-body-view h2, .policy-body-view h3 { margin-top: 0; }
.editor-surface h1, .editor-surface h2, .editor-surface h3 { margin-top: 0; }

.pdf-frame-wrap { border: 1px solid var(--border); border-radius: 0.5rem; overflow: hidden; }
.pdf-frame { width: 100%; min-height: 640px; border: 0; background: white; }

.data-table tr.row-selected { background: rgba(61, 139, 253, 0.12); }

.hidden-file { display: none; }
label.btn { cursor: pointer; display: inline-block; }

/* Embedded help (spec 16) */
.content { position: relative; }

.help-fab {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    z-index: 40;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--accent, #3d8bfd);
    color: white;
    font-weight: 700;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.help-fab:hover { filter: brightness(1.08); }

.help-panel-host { position: static; }

.help-panel {
    position: fixed;
    right: 1.25rem;
    bottom: 4.25rem;
    width: min(420px, calc(100vw - 2rem));
    max-height: min(70vh, 640px);
    overflow: auto;
    z-index: 41;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.35);
}

.help-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.help-panel-actions { margin-top: 1rem; }

.help-center { align-items: start; }
.help-sidebar { position: sticky; top: 1rem; }
.help-search { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.help-search .input { flex: 1; }
.help-section-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 1rem 0 0.4rem;
}
.help-group-label {
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 0.85rem;
    margin-bottom: 0.25rem;
}
.help-toc { list-style: none; padding: 0; margin: 0 0 0.5rem; }
.help-toc li { margin: 0.35rem 0; }
.help-toc .tiny { font-size: 0.8rem; margin-top: 0.15rem; }
button.linkish {
    background: none;
    border: 0;
    padding: 0;
    color: var(--accent, #3d8bfd);
    cursor: pointer;
    text-align: left;
    font: inherit;
}
button.linkish.active { font-weight: 700; text-decoration: underline; }
.help-body h1 { font-size: 1.35rem; margin-top: 0; }
.help-body h2 { font-size: 1.15rem; margin-top: 1.25rem; }
.help-body h3 { font-size: 1rem; margin-top: 1rem; }
.help-body.compact h1 { font-size: 1.1rem; }
.help-body ul, .help-body ol { padding-left: 1.2rem; }
.btn.ghost {
    background: transparent;
    border: 1px solid var(--border);
}


/* Compliance Context switcher */
.compliance-context-switcher {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0.75rem 1rem 0.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.compliance-context-switcher .context-label {
    font-size: 0.7rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    opacity: 0.7;
}
.compliance-context-switcher .context-select {
    width: 100%;
    background: rgba(0,0,0,0.25);
    color: inherit;
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 4px;
    padding: 0.35rem 0.5rem;
    font-size: 0.85rem;
}
