/* theme variables */
:root {
    /* modern 2026 palette: clean, sophisticated, gradient-ready */
    --bg-color: #f8fafc;
    --bg-gradient: linear-gradient(135deg, #f8fafc 0%, #f0f4f8 100%);
    --card-bg: #ffffff;
    --table-bg: #f4f7ff;
    --table-column-divider-color: rgba(15, 23, 42, 0.08);
    --table-column-divider-width: 1px;
    --card-shadow: 0 10px 40px rgba(15,23,42,0.08), 0 1px 3px rgba(15,23,42,0.12);
    --text-color: #0f172a;
    --text-secondary: #64748b;
    --button-bg: linear-gradient(135deg, #2563eb 0%, #1f3fb8 100%);
    --button-hover: linear-gradient(135deg, #4f8ff7 0%, #3b82f6 100%);
    --accent-primary: #3b82f6;  /* modern blue */
    --accent-secondary: #8b5cf6; /* purple */
    --border-color: #e2e8f0;
}

body.dark, html.dark {
    --bg-color: #1e1f24;
    --bg-gradient: linear-gradient(135deg, #1f2026 0%, #242631 60%, #1f222c 100%);
    --card-bg: #2a2d39;
    --table-bg: #333a4f;
    --table-column-divider-color: rgba(255, 255, 255, 0.12);
    --table-column-divider-width: 1px;
    --card-shadow: 0 12px 32px rgba(5, 7, 16, 0.6);
    --text-color: #d9dedb;
    --text-secondary: #b0b5c9;
    --button-bg: linear-gradient(135deg, #1d4ed8 0%, #1e3a8a 100%);
    --button-hover: linear-gradient(135deg, #1e3a8a 0%, #172554 100%);
    --accent-primary: #8b5cf6;
    --accent-secondary: #38bdf8;
    --border-color: rgba(255,255,255,0.14);
}

body {
    font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-gradient);
    color: var(--text-color);
    margin: 0;
    padding: 0;
    transition: background 0.4s ease, color 0.3s ease;
}

*, *::before, *::after {
    box-sizing: border-box;
}

.container {
    max-width: 1600px;
    margin: 50px auto;
    padding: 40px;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    transition: background 0.3s, box-shadow 0.3s;
}

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--header-border, #ddd);
    padding-bottom: 8px;
}

.header-main {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

h1 {
    margin-bottom: 2px;
    font-weight: 700;
    letter-spacing: -0.5px;
    font-size: 1.75em;
    color: var(--text-color);
}

.subtitle {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 1.05em;
    font-weight: 400;
    letter-spacing: 0.3px;
}

.main-nav {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: baseline;
    column-gap: 18px;
    row-gap: 10px;
    min-width: 0;
}

.main-nav-switcher {
    display: inline-flex;
    align-items: stretch;
    gap: 8px;
    padding: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    box-shadow: none;
    flex: 0 0 auto;
    align-self: baseline;
    position: relative;
    top: -2px;
}

.main-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    height: 38px;
    padding: 0 14px;
    min-width: 116px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--card-bg) 96%, var(--table-bg) 4%);
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
    line-height: 1;
    text-align: center;
    box-sizing: border-box;
}

.main-nav-toggle:hover {
    color: var(--text-color);
    background: color-mix(in srgb, var(--table-bg) 82%, var(--border-color) 18%);
}

.main-nav-toggle.is-active {
    color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 10%, var(--card-bg) 90%);
    border-color: color-mix(in srgb, var(--accent-primary) 24%, var(--border-color) 76%);
    box-shadow: 0 1px 6px rgba(59, 130, 246, 0.1);
}

.main-nav-panel {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 18px;
    min-width: 0;
    align-self: baseline;
}

.main-nav-panel[hidden] {
    display: none !important;
}

.main-nav a {
    display: inline-flex;
    align-items: center;
    text-decoration: none;
    color: var(--text-secondary);
    font-weight: 500;
    padding: 4px 0 2px;
    border-bottom: 2px solid transparent;
    transition: color 0.18s ease, border-color 0.18s ease;
    white-space: nowrap;
    box-sizing: border-box;
}

.main-nav a[data-phase-tooltip] {
    position: relative;
}

.main-nav a[data-phase-tooltip]::after {
    content: attr(data-phase-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    padding: 6px 10px;
    border-radius: 8px;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid color-mix(in srgb, var(--border-color) 45%, var(--text-secondary) 55%);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.12);
    font-size: 0.76rem;
    font-weight: 500;
    line-height: 1.2;
    width: max-content;
    max-width: 320px;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.08s ease;
    z-index: 60;
}

.main-nav a[data-phase-tooltip]:hover::after,
.main-nav a[data-phase-tooltip]:focus-visible::after {
    opacity: 1;
}

.main-nav a:hover {
    color: var(--text-color);
}

.main-nav a.active {
    color: var(--accent-primary);
    border-bottom-color: var(--accent-primary);
}

@media (max-width: 900px) {
    .main-nav {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .main-nav-switcher {
        width: 100%;
        justify-content: flex-start;
        border-radius: 16px;
        position: static;
    }

    .main-nav-panel {
        gap: 8px 14px;
    }
}

.projects-filter {
    margin: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.projects-filter select {
    max-width: 320px;
}

.sample-size-layout {
    display: grid;
    grid-template-columns: minmax(320px, 520px) minmax(320px, 1fr);
    gap: 24px;
    align-items: start;
}

.sample-size-form,
.sample-results {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.sample-card {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
}

.sample-card h2 {
    margin-top: 0;
    margin-bottom: 12px;
}

.sample-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

.sample-grid label {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-weight: 600;
}

.label-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    align-self: flex-start;
}

.sample-grid input,
.sample-grid select {
    width: 100%;
}

.sample-grid input {
    padding: 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-color);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
    font: inherit;
}

.sample-grid input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    outline: none;
}

body.dark .sample-grid input,
html.dark .sample-grid input,
body.dark .sample-grid select,
html.dark .sample-grid select {
    background: #d9dedb;
    color: #0f172a;
}

body.dark .sample-grid select option,
html.dark .sample-grid select option {
    background-color: #d9dedb !important;
    color: #0f172a !important;
}

.info-tooltip {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 15px;
    height: 15px;
    border-radius: 999px;
    border: 1px solid color-mix(in srgb, var(--border-color) 55%, var(--text-secondary) 45%);
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1;
    cursor: help;
    vertical-align: middle;
}

.info-tooltip-text {
    position: absolute;
    left: 50%;
    bottom: calc(100% + 10px);
    transform: translateX(-50%);
    width: 240px;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid color-mix(in srgb, var(--border-color) 35%, var(--text-color) 65%);
    font-size: 0.82rem;
    font-weight: 400;
    line-height: 1.35;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 40;
}

.info-tooltip-text-below {
    top: calc(100% + 10px);
    bottom: auto;
}

.info-tooltip-text-left {
    left: 0;
    transform: none;
}

.info-tooltip:hover .info-tooltip-text,
.info-tooltip:focus .info-tooltip-text,
.info-tooltip:focus-visible .info-tooltip-text {
    opacity: 1;
}

.sample-actions {
    display: flex;
    justify-content: flex-end;
}

.sample-help,
.sample-note,
.sample-kicker {
    color: var(--text-secondary);
}

.sample-size-number,
.sample-method-size {
    font-size: 2.5rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent-primary);
}

.sample-method-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 20px;
}

.sample-method-header {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 16px;
}

.sample-badge {
    margin: 6px 0 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.sample-formula {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 0.95rem;
    padding: 10px 12px;
    background: var(--table-bg);
    border-radius: 10px;
}

.sample-reference-list {
    margin: 0;
    padding-left: 18px;
    color: var(--text-secondary);
}

.sample-guidance-box {
    margin-top: 16px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--table-bg);
}

.sample-guidance-title {
    margin: 0 0 8px;
    font-weight: 600;
    color: var(--text-color);
}

@media (max-width: 980px) {
    .sample-size-layout {
        grid-template-columns: 1fr;
    }
}

.readiness-summary {
    margin-bottom: 20px;
}

.readiness-phase-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.readiness-summary-card {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    background: var(--card-bg);
    box-shadow: 0 8px 20px rgba(15,23,42,0.1);
}

.readiness-phase-card,
.readiness-phase-section {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: 0 8px 20px rgba(15,23,42,0.08);
}

.readiness-phase-card {
    padding: 16px;
}

.readiness-phase-card h3,
.readiness-phase-header h3 {
    margin-bottom: 8px;
}

.readiness-phase-description {
    margin: 0 0 10px;
    color: var(--text-secondary);
}

.progress-bar {
    width: 100%;
    background: var(--border-color);
    border-radius: 999px;
    height: 10px;
    margin-top: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.readiness-checklist {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.readiness-phase-section {
    padding: 18px;
}

.readiness-phase-header {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: flex-start;
    margin-bottom: 14px;
}

.readiness-phase-header p {
    margin: 0;
    color: var(--muted-text);
}

.readiness-phase-progress {
    min-width: 180px;
    text-align: right;
}

.readiness-phase-progress span {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}

.readiness-phase-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.readiness-item {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 16px;
    background: var(--card-bg);
}

.readiness-item select {
    min-width: 140px;
    padding: 8px 10px;
}

.status-not-started {
    border-left: 4px solid #cbd5f5;
}

.status-in-progress {
    border-left: 4px solid #facc15;
}

.status-complete {
    border-left: 4px solid #22c55e;
}

@media (max-width: 760px) {
    .readiness-phase-header,
    .readiness-item {
        flex-direction: column;
        align-items: stretch;
    }

    .readiness-phase-progress {
        min-width: 0;
        text-align: left;
    }

    .readiness-item select {
        width: 100%;
    }
}

.trace-form {
    margin-top: 24px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
}

.trace-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
    margin: 12px 0 16px;
}

.trace-form-grid textarea,
.trace-form-grid select {
    width: 100%;
    margin-top: 6px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
}

.trace-table-section {
    margin-top: 32px;
}

.trace-table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.trace-table-wrapper {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 260px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    margin-top: 12px;
}

.table-tools {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

/* Column visibility toggle */
.col-toggle-wrapper {
    position: relative;
}
.col-toggle-btn.has-hidden {
    font-weight: 600;
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}
.col-toggle-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 120;
    min-width: 220px;
    max-height: 360px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 6px 24px rgba(0,0,0,0.13);
    padding: 8px 0;
}
.col-toggle-show-all {
    display: block;
    width: 100%;
    padding: 7px 12px;
    border: none;
    border-radius: 6px;
    background: var(--accent-primary);
    color: #fff;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    box-shadow: none;
    transform: none;
}
.col-toggle-toolbar {
    display: flex;
    gap: 6px;
    padding: 4px 8px;
}
.col-toggle-toolbar .col-toggle-show-all {
    flex: 1;
}
.col-toggle-reset {
    background: var(--card-bg) !important;
    color: var(--text-color) !important;
    border: 1.5px solid var(--border-color) !important;
}
.col-toggle-hide-all {
    background: var(--card-bg) !important;
    color: var(--text-color) !important;
    border: 1.5px solid var(--border-color) !important;
}
.col-toggle-show-all:disabled {
    opacity: 0.4;
    cursor: default;
}
.col-toggle-show-all:not(:disabled):hover {
    filter: brightness(1.1);
}
.col-toggle-divider {
    height: 1px;
    margin: 6px 10px;
    background: var(--border-color);
}
.col-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 14px;
    cursor: grab;
    font-size: 0.88rem;
    color: var(--text-color);
    white-space: nowrap;
    transition: background 0.15s;
}
.col-toggle-row:hover {
    background: var(--table-bg);
}
.col-drag-handle {
    cursor: grab;
    color: var(--text-secondary, #94a3b8);
    font-size: 1rem;
    line-height: 1;
    user-select: none;
    flex-shrink: 0;
}
.col-toggle-row.col-dragging {
    opacity: 0.4;
    background: var(--accent-primary-alpha, rgba(99,102,241,0.12));
}
.col-toggle-row.col-drag-over {
    border-top: 2px solid var(--accent-primary);
    padding-top: 3px;
}
.col-toggle-hint {
    font-size: 0.75rem;
    color: var(--text-secondary, #94a3b8);
    padding: 2px 14px 4px;
    text-align: center;
    user-select: none;
}
.col-toggle-label {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
}
.col-toggle-row input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    flex-shrink: 0;
    accent-color: var(--accent-primary);
}

.table-panel {
    margin-top: 12px;
}

.table-panel-header {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 8px;
}

.table-panel-content {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    padding: 16px;
    transition: transform 0.35s ease;
    overflow: hidden;
}

.table-panel.collapsed .table-panel-content {
    transform: translateX(105%);
    opacity: 0;
    pointer-events: none;
}

.table-slide-toggle {
    border: 1px solid var(--accent-primary);
    background: var(--accent-primary);
    color: #fff;
    border-radius: 999px;
    padding: 6px 18px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.18);
    transition: background 0.2s ease, color 0.2s ease;
}

.table-panel.collapsed .table-slide-toggle {
    background: transparent;
    color: var(--accent-primary);
}

.link-multiselect {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.link-multiselect-toggle {
    border: 1px solid var(--border-color);
    background: var(--table-bg);
    color: var(--text-color);
    border-radius: 12px;
    padding: 10px 14px;
    text-align: left;
    cursor: pointer;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-top: 0;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.link-multiselect-toggle:hover {
    background: var(--table-bg);
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.12);
    transform: none;
}

.link-multiselect-toggle:active {
    background: var(--table-bg);
    transform: none;
}

.link-multiselect-toggle:focus {
    background: var(--table-bg);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.link-multiselect-toggle:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.link-multiselect-toggle-icon {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.link-multiselect-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    min-height: 30px;
}

.link-pill {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 10px;
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.35);
    font-size: 0.85em;
}

.link-multiselect-panel {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    width: min(460px, 100%);
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px;
    box-shadow: 0 18px 35px rgba(15, 23, 42, 0.22);
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: auto;
}

.link-multiselect-panel[hidden] {
    display: none !important;
}

.link-multiselect-head {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
}

.link-search-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0 10px;
    background: var(--table-bg);
}

.link-search-icon {
    font-size: 0.9em;
    color: var(--text-secondary);
}

.link-multiselect-search {
    width: 100%;
    padding: 8px 0;
    border-radius: 0;
    border: none;
    background: transparent;
    color: var(--text-color);
    outline: none;
}

.link-multiselect-search::placeholder {
    color: var(--text-secondary);
}

.link-multiselect-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-start;
}

.link-multiselect-action {
    border: 1px solid rgba(99, 102, 241, 0.35);
    background: rgba(99, 102, 241, 0.08);
    color: var(--text-color);
    border-radius: 10px;
    padding: 6px 10px;
    font-size: 0.85em;
    cursor: pointer;
    transition: background 0.2s ease;
}

.link-multiselect-action:hover {
    background: rgba(99, 102, 241, 0.18);
}

.link-multiselect-meta {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.link-multiselect-result-count {
    font-weight: 600;
}

.link-multiselect-empty {
    text-align: center;
    font-size: 0.9em;
    color: var(--text-secondary);
}

.link-multiselect-options {
    max-height: 240px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.link-option {
    display: flex;
    gap: 8px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 6px 10px;
    background: rgba(148, 163, 184, 0.08);
    align-items: center;
    flex-wrap: nowrap;
    justify-content: flex-start;
    text-align: left;
    width: 100%;
    transition: border 0.2s ease, background 0.2s ease, transform 0.15s ease, box-shadow 0.15s ease;
    cursor: pointer;
}

.link-option:hover {
    background: rgba(148, 163, 184, 0.15);
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.1);
}

.link-option:active {
    background: rgba(148, 163, 184, 0.25);
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}

.link-option.hidden {
    display: none !important;
}

.link-option.selected {
    border-color: rgba(59, 130, 246, 0.7);
    background: rgba(59, 130, 246, 0.08);
}

.link-option-main {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
    width: 100%;
    flex-wrap: nowrap;
    justify-content: flex-start;
}

.link-option-unreferenced {
    border-color: rgba(59, 130, 246, 0.6);
}

.link-option-text {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-width: 0;
    width: 100%;
    justify-content: flex-start;
}

.link-option-id {
    font-weight: 600;
    font-size: 0.85em;
    white-space: nowrap;
}

.link-option-desc {
    font-size: 0.75em;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.link-option-meta {
    display: flex;
    flex-direction: row;
    align-items: center;
    font-size: 0.65em;
    color: var(--text-secondary);
    gap: 6px;
    white-space: nowrap;
}

.link-option-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    border: 1px solid rgba(59, 130, 246, 0.25);
    background: rgba(59, 130, 246, 0.12);
    color: var(--text-color);
    font-weight: 500;
}

#docTable {
    width: max-content;
    min-width: 1200px;
    border-collapse: collapse;
    table-layout: auto;
}

#docTable th,
#docTable td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
}

#docTable th {
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--card-bg);
}

/* Freeze Actions and ID columns horizontally */
#docTable th[data-col="actions"],
#docTable td[data-col="actions"] {
    position: sticky;
    left: -16px;
    z-index: 5;
    background: var(--card-bg);
}

#docTable th[data-col="id"],
#docTable td[data-col="id"] {
    position: sticky;
    left: 0;
    z-index: 5;
    background: var(--card-bg);
    box-shadow: 2px 0 4px rgba(0, 0, 0, 0.06);
}

/* When both sticky row + column (top-left corner), raise z-index */
#docTable thead th[data-col="actions"],
#docTable thead th[data-col="id"] {
    z-index: 15;
}

.trace-summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.trace-summary-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    background: var(--card-bg);
    text-align: center;
}

.trace-summary-card.total {
    background: linear-gradient(135deg, rgba(59,130,246,0.12), rgba(79,70,229,0.2));
}

.project-panel {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    margin-bottom: 24px;
}

.trace-phase-banner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
    padding: 14px 16px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-bg) 88%, var(--table-bg) 12%);
    box-shadow: var(--card-shadow);
}

.trace-phase-banner h2 {
    margin: 0 0 4px;
    font-size: 1.05rem;
}

.trace-phase-banner p {
    margin: 0;
    color: var(--text-secondary);
}

.trace-phase-tables {
    margin-top: 6px !important;
}

.trace-phase-banner .secondary-btn {
    font-size: 0.9rem;
    white-space: nowrap;
}

.doc-tab-empty-state {
    padding: 12px 14px;
    border: 1px dashed var(--border-color);
    border-radius: 14px;
    color: var(--text-secondary);
    background: color-mix(in srgb, var(--card-bg) 92%, var(--table-bg) 8%);
}

.project-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

.project-controls input,
.project-controls select {
    flex: 1;
    min-width: 220px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
}

.trace-content {
    margin-top: 16px;
}

.doc-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.doc-tab {
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
}

.doc-tab.active {
    background: var(--accent-primary);
    color: #fff;
    border-color: var(--accent-primary);
}

.doc-body {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.trace-card {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.trace-card textarea,
.trace-card select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    resize: none;
}

.trace-table-wrapper {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--table-bg);
    box-shadow: var(--card-shadow);
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - 260px);
    padding: 16px;
}

.trace-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px 16px;
    margin-top: 12px;
}

.trace-form-grid .form-field {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.trace-form-grid .form-field label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.trace-instance-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.trace-instance-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
}

.trace-instance-controls label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: min(420px, 100%);
}

.trace-instance-summary {
    flex: 1 1 220px;
    min-width: 220px;
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.trace-instance-summary strong {
    display: block;
    color: var(--text-color);
    margin-bottom: 2px;
}

.doc-instance-modal {
    width: min(1180px, calc(100vw - 32px));
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 28px 30px;
    overflow: hidden;
}

#docInstanceModalBody {
    overflow: auto;
    min-width: 0;
    padding-bottom: 4px;
}

.doc-instance-manager {
    display: grid;
    grid-template-columns: 1fr;
    gap: 18px;
    min-width: 0;
}

.doc-instance-panel {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-bg) 94%, var(--table-bg) 6%);
    padding: 16px;
    min-width: 0;
    overflow: visible;
}

.doc-instance-panel h3 {
    margin: 0 0 8px;
}

.doc-instance-panel p {
    margin: 0 0 14px;
    color: var(--text-secondary);
}

.doc-instance-list {
    display: grid;
    gap: 12px;
}

.doc-instance-card {
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 14px;
    background: var(--card-bg);
    min-width: 0;
}

.doc-instance-card.is-active {
    border-color: color-mix(in srgb, var(--accent-primary) 55%, var(--border-color) 45%);
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent-primary) 25%, transparent);
}

.doc-instance-card-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.doc-instance-card-title {
    font-weight: 700;
    color: var(--text-color);
    overflow-wrap: anywhere;
}

.doc-instance-card-code {
    margin-top: 4px;
    font-size: 0.86rem;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.doc-instance-active-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    color: var(--accent-primary);
    background: color-mix(in srgb, var(--accent-primary) 14%, var(--card-bg) 86%);
    border: 1px solid color-mix(in srgb, var(--accent-primary) 35%, transparent);
}

.doc-instance-card-meta {
    margin: 10px 0;
    display: grid;
    gap: 6px;
    color: var(--text-secondary);
    font-size: 0.92rem;
    min-width: 0;
}

.doc-instance-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 12px;
}

.doc-instance-form-grid {
    display: grid;
    gap: 12px;
    min-width: 0;
}

.doc-instance-form-grid label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.doc-instance-form-grid input {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
}

.doc-instance-form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
    align-items: center;
    justify-content: flex-start;
}

.doc-instance-form-actions .secondary-btn,
.doc-instance-form-actions .text-btn {
    width: auto;
    min-width: 0;
    flex: 0 0 auto;
    padding-inline: 16px;
}

.doc-instance-empty {
    padding: 14px;
    border-radius: 12px;
    border: 1px dashed var(--border-color);
    color: var(--text-secondary);
}

@media (max-width: 900px) {
    .doc-instance-manager {
        grid-template-columns: 1fr;
        min-width: 0;
    }

    .doc-instance-modal {
        width: min(98vw, 760px);
        max-height: 94vh;
        padding: 26px 24px;
    }
}

.form-field.full-span {
    grid-column: 1 / -1;
}

.form-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 10px;
}

.form-section-header h2 {
    margin: 0;
}

.form-section-body.collapsed {
    display: none;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 14px;
}

.guidance-panel {
    margin-top: 16px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--table-bg);
    padding: 8px 12px;
    box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.05);
}

.guidance-panel summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    list-style: none;
}

.guidance-panel summary::-webkit-details-marker {
    display: none;
}

.guidance-content {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 12px;
}

.guidance-section h3 {
    margin: 0 0 8px 0;
    font-size: 0.95em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.guidance-section ul {
    margin: 0;
    padding-left: 18px;
}

.guidance-section li {
    margin-bottom: 6px;
    font-size: 0.9em;
}

.edit-banner {
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent-primary);
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.icon-btn {
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 1.2em;
    line-height: 1;
    margin-right: 6px;
    padding: 2px;
    color: var(--text-secondary);
}

.icon-btn:last-child {
    margin-right: 0;
}

.icon-btn:hover {
    color: var(--text-color);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.85em;
    font-weight: 600;
}

.status-badge .status-date {
    font-weight: 400;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.status-badge.active {
    background: rgba(34, 197, 94, 0.15);
    color: #15803d;
}

.status-badge.inactive {
    background: rgba(248, 113, 113, 0.15);
    color: #b91c1c;
}

.doc-filters {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    width: 100%;
    align-items: center;
}

.inactive-toggle-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.buttons-row {
    justify-content: space-between;
}

.inactive-btn-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.doc-filters .filter-field {
    flex: 1 1 220px;
    min-width: 180px;
}

.doc-filters label {
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text-secondary);
}

.doc-filters input,
.doc-filters select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
}

.doc-filters .text-btn {
    align-self: center;
}

.toggle-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 18px;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    cursor: pointer;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: border 0.2s ease, color 0.2s ease;
}

.toggle-pill input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 18px;
    height: 18px;
    margin: 0;
    cursor: pointer;
    flex-shrink: 0;
}

.toggle-pill span {
    font-size: 0.9em;
    line-height: 1.2;
}

.inactive-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 8px;
    background: rgba(248, 113, 113, 0.18);
    color: #b91c1c;
    border-radius: 999px;
    font-weight: 600;
    font-size: 0.85em;
}

.trace-table-wrapper table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
    min-width: 1200px;
}

.trace-table-wrapper th,
.trace-table-wrapper td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border-color);
    border-right: var(--table-column-divider-width) solid var(--table-column-divider-color);
    position: relative;
}

.trace-table-wrapper thead th {
    position: sticky;
    top: -16px;
    z-index: 10;
    background: var(--card-bg) !important;
    box-shadow: 0 1px 0 var(--border-color);
}

.trace-table-wrapper th:last-child,
.trace-table-wrapper td:last-child {
    border-right: none;
}

.row-inactive {
    background: rgba(248, 113, 113, 0.08);
}

.row-locked {
    background: color-mix(in srgb, var(--card-bg) 80%, #f59e0b 20%);
    box-shadow: inset 4px 0 0 rgba(245, 158, 11, 0.55);
}

.entry-id-cell {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.entry-lock-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75em;
    font-weight: 600;
    color: #92400e;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.entry-action-lock {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 999px;
    font-size: 0.95rem;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.doc-lock-notice {
    margin-bottom: 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(245, 158, 11, 0.4);
    background: rgba(251, 191, 36, 0.14);
    color: #92400e;
    font-weight: 600;
}

.column-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    padding: 4px 6px;
    border-radius: 8px;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.column-header.filter-active {
    background: rgba(59, 130, 246, 0.12);
    border: 1px solid rgba(59, 130, 246, 0.4);
}

.column-filter-btn {
    border: 1px solid transparent;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    font-size: 0.9em;
    line-height: 1;
}

.column-controls {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.column-controls:empty {
    display: none;
}

.column-sort-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.75em;
    color: var(--text-secondary);
    padding: 0 3px;
    line-height: 1;
}

.column-sort-btn.active {
    color: var(--accent-primary);
}

.column-filter-btn.active {
    color: var(--accent-primary);
    position: relative;
}

.column-filter-btn.active::after {
    content: '';
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-primary);
    display: inline-block;
    margin-left: 4px;
}

.column-filter-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 220px;
    background: var(--card-bg);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(15, 23, 42, 0.18);
    padding: 12px 14px;
    z-index: 2500;
}

.column-filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.column-filter-header button {
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 1.1em;
    cursor: pointer;
}

.column-filter-body {
    max-height: 200px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.column-filter-body label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.9em;
}

.column-filter-options {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.column-filter-multi-actions {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 8px;
}

.column-filter-multi-actions button {
    border: none;
    background: rgba(59, 130, 246, 0.15);
    color: var(--accent-primary);
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 0.8em;
    font-weight: 600;
    cursor: pointer;
}

.date-filter-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 10px;
}

.date-filter-field input[type="date"] {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--table-bg);
    color: var(--text-color);
}

.column-filter-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.column-resizer {
    position: absolute;
    top: 0;
    right: -7px;
    width: 14px;
    height: 100%;
    cursor: col-resize;
    z-index: 25;
}

.column-resizer::after {
    content: '';
    position: absolute;
    top: 6px;
    bottom: 6px;
    left: 50%;
    width: 2px;
    border-radius: 999px;
    background: rgba(148, 163, 184, 0.35);
    transition: background 0.2s ease, width 0.2s ease;
}

.column-resizer:hover::after,
.column-resizer.active::after {
    background: rgba(148, 163, 184, 0.6);
    width: 3px;
}

.doc-link {
    background: rgba(139, 92, 246, 0.18);
    border: 1px solid rgba(139, 92, 246, 0.4);
    color: var(--text-color);
    border-radius: 999px;
    padding: 2px 10px;
    font-size: 0.85em;
    margin-right: 6px;
    cursor: pointer;
}

.doc-link.backlink {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.45);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.doc-link .doc-link-doc {
    font-size: 0.7em;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.doc-link.inactive {
    background: rgba(248, 113, 113, 0.12);
    border-color: rgba(248, 113, 113, 0.45);
    color: #b91c1c;
}

.doc-link:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.row-highlight {
    animation: pulse 1.5s ease;
    background: rgba(56, 189, 248, 0.15);
}

@keyframes pulse {
    from { background: rgba(56, 189, 248, 0.3); }
    to { background: transparent; }
}

.trace-tooltip {
    position: fixed;
    background: rgba(15, 23, 42, 0.95);
    color: #fff;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 0.85em;
    max-width: 280px;
    z-index: 2000;
    box-shadow: 0 6px 20px rgba(0,0,0,0.35);
}

.risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 12px;
    border-radius: 999px;
    font-size: 0.85em;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.risk-badge .risk-score-value {
    font-variant-numeric: tabular-nums;
}

.risk-badge.risk-low {
    background: rgba(16, 185, 129, 0.2);
    color: #047857;
}

.risk-badge.risk-medium {
    background: rgba(245, 158, 11, 0.2);
    color: #92400e;
}

.risk-badge.risk-high {
    background: rgba(239, 68, 68, 0.2);
    color: #b91c1c;
}

.dark .risk-badge.risk-low {
    background: rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
}

.dark .risk-badge.risk-medium {
    background: rgba(245, 158, 11, 0.35);
    color: #fbbf24;
}

.dark .risk-badge.risk-high {
    background: rgba(239, 68, 68, 0.35);
    color: #fca5a5;
}

.risk-heatmap {
    margin: 12px 0;
    padding: 10px 12px 12px 12px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    transition: max-height 0.25s ease;
}

.risk-heatmap.collapsed {
    padding-bottom: 8px;
}

.risk-heatmap-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 12px;
}

.heatmap-hint {
    margin: 4px 0 0 0;
    color: var(--text-secondary);
    font-size: 0.85em;
}

.heatmap-level-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
}

.heatmap-level-pill {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid rgba(15, 23, 42, 0.08);
    font-weight: 700;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.heatmap-level-pill-label {
    font-size: 0.88rem;
}

.heatmap-level-pill-count {
    min-width: 1.5em;
    text-align: center;
    font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

.heatmap-level-pill.risk-low {
    background: linear-gradient(135deg, rgba(34,197,94,0.16), rgba(34,197,94,0.28));
    color: #065f46;
}

.heatmap-level-pill.risk-medium {
    background: linear-gradient(135deg, rgba(251,191,36,0.16), rgba(251,146,60,0.28));
    color: #92400e;
}

.heatmap-level-pill.risk-high {
    background: linear-gradient(135deg, rgba(248,113,113,0.2), rgba(239,68,68,0.35));
    color: #7f1d1d;
}

.heatmap-toggle button {
    border: 1px solid transparent;
    background: none;
    color: var(--accent-primary);
    font-weight: 600;
    cursor: pointer;
}

.heatmap-toggle button:hover {
    text-decoration: underline;
}

.risk-heatmap-grid {
    display: grid;
    grid-template-columns: 100px repeat(5, minmax(55px, 1fr));
    gap: 2px;
    align-items: stretch;
}

.risk-heatmap-grid.summary-mode {
    display: block;
}

.heatmap-summary-table {
    width: 100%;
    border-collapse: collapse;
}

.heatmap-summary-table th,
.heatmap-summary-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.heatmap-summary-table th {
    font-weight: 600;
    color: var(--text-secondary);
}

.heatmap-summary-table td .risk-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.risk-heatmap.collapsed .risk-heatmap-grid {
    display: none;
}

.heatmap-corner {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    font-size: 0.85em;
    color: var(--text-secondary);
    font-weight: 600;
}

.heatmap-prob-label,
.heatmap-severity-label {
    font-weight: 600;
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.heatmap-severity-label {
    justify-content: flex-start;
}

.heatmap-cell {
    border-radius: 10px;
    padding: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 48px;
    box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.05);
    text-align: center;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
}

.heatmap-cell:hover {
    transform: scale(1.06);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 1;
}

.heatmap-cell.heatmap-active {
    box-shadow: inset 0 0 0 3px var(--accent-primary), 0 2px 8px rgba(0,0,0,0.1);
}

.heatmap-level {
    font-weight: 700;
    font-size: 0.9em;
    margin-bottom: 4px;
}

.heatmap-count {
    font-size: 1.1em;
    font-variant-numeric: tabular-nums;
}

.heatmap-cell.risk-low {
    background: linear-gradient(135deg, rgba(34,197,94,0.2), rgba(34,197,94,0.35));
    color: #065f46;
}

.heatmap-cell.risk-medium {
    background: linear-gradient(135deg, rgba(251,191,36,0.2), rgba(251,146,60,0.35));
    color: #92400e;
}

.heatmap-cell.risk-high {
    background: linear-gradient(135deg, rgba(248,113,113,0.25), rgba(239,68,68,0.45));
    color: #7f1d1d;
}

.dark .heatmap-cell.risk-low {
    color: #bbf7d0;
}

.dark .heatmap-level-pill.risk-low {
    color: #bbf7d0;
}

.dark .heatmap-cell.risk-medium {
    color: #fde68a;
}

.dark .heatmap-level-pill.risk-medium {
    color: #fde68a;
}

.dark .heatmap-cell.risk-high {
    color: #fecaca;
}

.dark .heatmap-level-pill.risk-high {
    color: #fecaca;
}

/* Clickable summary rows */
.heatmap-summary-table tbody tr[data-hm-type="summary"] {
    cursor: pointer;
    transition: background 0.15s;
}

.heatmap-summary-table tbody tr[data-hm-type="summary"]:hover {
    background: rgba(59, 130, 246, 0.08);
}

.heatmap-summary-table tbody tr.heatmap-active {
    background: rgba(59, 130, 246, 0.12);
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

/* Filter banner */
.heatmap-filter-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    margin-top: 10px;
    background: rgba(59, 130, 246, 0.08);
    border: 1px solid rgba(59, 130, 246, 0.25);
    border-radius: 10px;
    font-size: 0.92em;
    color: var(--text-primary);
    animation: bannerSlideIn 0.25s ease;
}

@keyframes bannerSlideIn {
    from { opacity: 0; transform: translateY(-6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.heatmap-banner-icon {
    font-size: 1.1em;
}

.heatmap-banner-text {
    flex: 1;
}

.heatmap-banner-clear {
    background: none;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: 6px;
    padding: 4px 12px;
    font-size: 0.88em;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
}

.heatmap-banner-clear:hover {
    background: var(--accent-primary);
    color: #fff;
}

.input-hint {
    display: block;
    font-size: 0.8em;
    color: var(--text-secondary);
    margin-top: 4px;
}

@media (max-width: 900px) {
    .container {
        padding: 24px;
    }
}
.section {
    margin-bottom: 16px;
}

.fieldset {
    border: 1px solid #ccc;
    border-radius: 8px;
    padding: 16px 20px;
    margin-bottom: 24px;
    background: var(--card-bg);
}

fieldset.group {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
    background: var(--card-bg);
    transition: border-color 0.3s, box-shadow 0.3s;
}

fieldset.group:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.1);
}

fieldset.group legend {
    font-weight: 600;
    padding: 0 8px;
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.95em;
    letter-spacing: 0.4px;
}

label {
    display: block;
    margin-bottom: 5px;
    font-weight: bold;
}

select {
    width: 100%;
    padding: 12px 48px 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    color: var(--text-color);
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background 0.25s ease;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
    font-size: 0.95em;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image:
        linear-gradient(45deg, transparent 50%, var(--text-secondary) 50%),
        linear-gradient(135deg, var(--text-secondary) 50%, transparent 50%);
    background-position:
        calc(100% - 22px) 50%,
        calc(100% - 14px) 50%;
    background-size: 8px 8px, 8px 8px;
    background-repeat: no-repeat;
}

select:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.15);
}

select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    outline: none;
    background-color: var(--card-bg);
}

select option {
    background-color: var(--card-bg) !important;
    color: var(--text-color) !important;
}

select:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: var(--table-bg);
    color: var(--text-secondary);
}

select::-ms-expand {
    display: none;
}

button {
    padding: 12px 28px;
    margin-top: 15px;
    cursor: pointer;
    background: var(--button-bg);
    color: white;
    border: none;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.975em;
    font-weight: 600;
    box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}

button:hover {
    background: var(--button-hover);
    box-shadow: 0 8px 25px rgba(59, 130, 246, 0.4);
    transform: translateY(-2px);
}

button:active {
    transform: scale(0.98);
}

button:focus {
    outline: none;
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2);
}

.secondary-btn {
    border: none;
    background: var(--button-bg);
    color: #fff;
    padding: 10px 18px;
    border-radius: 999px;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(59, 130, 246, 0.25);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.secondary-btn:hover {
    background: var(--button-hover);
    transform: translateY(-1px);
}

.secondary-btn.outline {
    background: transparent;
    color: var(--accent-primary);
    border: 1px solid var(--accent-primary);
    box-shadow: none;
}

.secondary-btn.outline:hover {
    background: rgba(59,130,246,0.1);
    transform: none;
}

.text-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 8px 12px;
    box-shadow: none;
    cursor: pointer;
}

.text-btn:hover {
    color: var(--accent-primary);
    background: rgba(59,130,246,0.08);
}

.project-panel {
    margin-top: 24px;
    padding: 18px;
    border: 1px dashed var(--border-color);
    border-radius: 12px;
    background: rgba(148, 163, 184, 0.08);
}

.project-panel h3 {
    margin-top: 0;
    margin-bottom: 12px;
}

.project-controls {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
}

.project-controls input,
.project-controls select {
    flex: 1;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
}

.project-controls button {
    flex-shrink: 0;
}

.project-template-help {
    flex: 2;
    min-width: 280px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: color-mix(in srgb, var(--card-bg) 94%, var(--table-bg) 6%);
    color: var(--text-secondary);
    font-size: 0.92em;
    line-height: 1.35;
}

.project-status {
    font-size: 0.9em;
    color: var(--accent-primary);
    min-height: 1.2em;
    margin: 4px 0;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.project-status.visible {
    opacity: 1;
}

.project-sync-notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: 8px 0 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(245, 158, 11, 0.35);
    background: rgba(251, 191, 36, 0.12);
    color: var(--text-color);
}

.project-sync-notice[hidden] {
    display: none;
}

.project-sync-notice button {
    flex-shrink: 0;
}

.project-hint {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin: 6px 0 0;
}

.project-editors {
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: color-mix(in srgb, var(--card-bg) 88%, var(--accent-primary) 12%);
}

.project-editors-label {
    display: block;
    font-size: 0.8em;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
}

.project-editors-empty {
    font-size: 0.9em;
    color: var(--text-secondary);
}

.project-editors-list {
    margin: 0;
    padding-left: 18px;
    color: var(--text-color);
}

.project-editors-list li {
    margin: 4px 0;
}

.readiness-item-copy {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.readiness-item-locked {
    background: color-mix(in srgb, var(--card-bg) 88%, #f59e0b 12%);
}

.readiness-lock-badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.75em;
    font-weight: 600;
    color: #92400e;
    background: rgba(251, 191, 36, 0.18);
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.compare-controls-panel {
    margin-top: 20px;
    border-top: 1px solid var(--border-color);
    padding-top: 16px;
}

.comparison-grid {
    margin-top: 20px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 18px;
}

.comparison-card {
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 18px;
    background: var(--card-bg);
    box-shadow: 0 8px 20px rgba(15,23,42,0.1);
}

.comparison-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.comparison-metric,
.comparison-driver {
    margin: 6px 0;
    font-size: 0.95em;
}

.comparison-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.tag-chip {
    background: rgba(59,130,246,0.12);
    color: var(--text-color);
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 0.85em;
}

.comparison-overrides ul,
.comparison-confidence ul {
    list-style: disc;
    list-style-position: outside;
    padding-left: 1.4em;
    margin: 4px 0 0;
}

.risk-breakdown ul {
    list-style: none;
    padding: 0;
    margin: 4px 0 0;
}

.risk-breakdown li,
.comparison-overrides li,
.comparison-confidence li {
    margin-bottom: 4px;
    font-size: 0.9em;
    padding-left: 0.4em;
    text-indent: -0.4em;
}

.risk-breakdown span {
    font-weight: 600;
}

.comparison-drivers ol {
    margin: 6px 0 0;
    padding-left: 1.6em;
    list-style-position: outside;
}

.section-title {
    font-weight: 600;
    margin: 12px 0 4px;
    font-size: 0.95em;
}

.comparison-placeholder {
    color: var(--text-secondary);
}

.heatmap-scale.mini {
    height: 28px;
}

.heatmap-scale.mini .heatmap-gradient {
    height: 10px;
}

.heatmap-scale.mini .heatmap-indicator {
    top: -8px;
}

/* remove old theme btn styles (unused) */
.theme-toggle {
    display: none;
}

/* ── Time-zone selector ───────────────────────────────── */
.tz-selector-wrapper {
    display: inline-flex;
    align-items: center;
}

.tz-selector-wrapper select {
    font-family: inherit;
    font-size: 0.8rem;
    padding: 5px 8px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.tz-selector-wrapper select:hover,
.tz-selector-wrapper select:focus {
    border-color: var(--primary);
}

/* modern toggle switch */
.theme-switch-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.theme-switch {
    position: relative;
    width: 72px;
    height: 32px;
    background: var(--card-bg);
    border-radius: 999px;
    border: 1px solid var(--border-color);
    transition: all 0.4s ease;
    cursor: pointer;
    padding: 0;
    box-shadow: inset 0 0 6px rgba(15,23,42,0.12);
}

.theme-switch input {
    opacity: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;
    left: 0;
    margin: 0;
    cursor: pointer;
    z-index: 2;
}

.theme-switch .slider {
    position: absolute;
    top: 3px;
    left: 4px;
    height: 26px;
    width: 26px;
    background: #fff;
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    border: 1px solid transparent;
    z-index: 2;
    pointer-events: none;
}

/* Suppress slider animation on initial page load */
html.no-transition .theme-switch .slider {
    transition: none !important;
}

/* Position slider correctly on load before JS checks the checkbox */
html.no-transition.dark .theme-switch .slider {
    transform: translateX(38px);
    border-color: var(--accent-primary);
}

.theme-switch input:checked + .slider,
.theme-switch input:checked ~ .slider {
    transform: translateX(38px);
    border-color: var(--accent-primary);
}

.icon-moon, .icon-sun {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    font-size: 1.05em;
    line-height: 1;
    user-select: none;
    pointer-events: none;
    transition: opacity 0.3s ease;
    color: var(--text-secondary);
}

.icon-moon {
    left: calc(4px + 13px);
    opacity: 0.9;
}

.icon-sun {
    left: calc(4px + 38px + 13px);
    opacity: 0.4;
}

.theme-switch input:checked ~ .icon-moon {
    opacity: 0.3;
}

.theme-switch input:checked ~ .icon-sun {
    opacity: 1;
}

body.dark .theme-switch,
html.dark .theme-switch {
    background: #1f2937;
    border-color: #2f3a4a;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.45);
}

body.dark .icon-moon,
html.dark .icon-moon,
body.dark .icon-sun,
html.dark .icon-sun {
    color: #e2e8f0;
}

button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.download-btn {
    margin-top: 24px;
    background: linear-gradient(135deg, #ef476f 0%, #f84a5e 100%) !important;
    box-shadow: 0 4px 15px rgba(239, 71, 111, 0.35);
}

.download-btn:hover {
    background: linear-gradient(135deg, #f84a5e 0%, #e53e52 100%) !important;
    box-shadow: 0 8px 25px rgba(239, 71, 111, 0.45);
}

#evaluateBtn {
    width: 100%;
}

@media (min-width: 600px) {
    form {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 24px;
    }
    fieldset.group {
        grid-column: span 2;
    }
    #evaluateBtn {
        grid-column: span 2;
        max-width: 300px;
        justify-self: center;
    }
}
.results {
    margin-top: 30px;
    padding: 24px;
    background: var(--card-bg);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.05);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    display: none;
}

.results.visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.results.visible {
    opacity: 1;
    transform: translateY(0);
}

.results-title {
    margin-top: 0;
    font-size: 1.3em;
    font-weight: 600;
    border-bottom: 1px solid #ddd;
    padding-bottom: 8px;
    margin-bottom: 16px;
}

.download-btn {
    margin-top: 20px;
    background: linear-gradient(135deg, #ef476f 0%, #f84a5e 100%);
    box-shadow: 0 4px 15px rgba(239, 71, 111, 0.3);
}

.download-btn:hover {
    background: linear-gradient(135deg, #f84a5e 0%, #e53e52 100%);
    box-shadow: 0 8px 25px rgba(239, 71, 111, 0.4);
}
.disclaimer {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-top: 12px;
    font-style: italic;
    line-height: 1.5;
}

.results h2 {
    margin-top: 24px;
    margin-bottom: 12px;
    font-size: 1.1em;
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
    color: var(--accent-primary);
}

#results ul {
    list-style: disc;
    list-style-position: outside;
    padding-left: 1.6em;
}

#results ul li {
    margin-bottom: 6px;
    padding-left: 0.5em;
    text-indent: -0.5em;
}

#docsSection ul {
    list-style: square;
    list-style-position: outside;
    padding-left: 1.8em;
}

#docsSection ul li {
    margin-bottom: 6px;
    padding-left: 0.5em;
    text-indent: -0.5em;
}
.standard-link {
    color: var(--accent-primary);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s ease;
    padding-bottom: 2px;
    border-bottom: 1px solid transparent;
}

.standard-link:hover {
    color: var(--accent-secondary);
    border-bottom-color: var(--accent-primary);
}

.standard-link:focus {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
    border-radius: 2px;
}

.classification-highlight {
    font-size: 1.1em;
    font-weight: 600;
    margin-bottom: 8px;
}

.override-callouts {
    background: rgba(59, 130, 246, 0.08);
    border-left: 4px solid var(--accent-primary);
    padding: 12px 16px;
    border-radius: 8px;
    margin-top: 12px;
}

.inline-link-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0 16px;
    padding: 6px 16px;
    background: none;
    border: 1px solid var(--accent-primary);
    color: var(--accent-primary);
    border-radius: 999px;
    font-size: 0.9em;
    box-shadow: none;
}

.inline-link-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    box-shadow: none;
}

.modal {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.65);
    backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 999;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--card-bg);
    color: var(--text-color);
    width: min(640px, 92vw);
    border-radius: 20px;
    padding: 32px;
    box-shadow: 0 30px 60px rgba(15, 23, 42, 0.35);
    position: relative;
}

.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5em;
    cursor: pointer;
    padding: 0;
    box-shadow: none;
}

.modal-subtitle {
    color: var(--text-secondary);
    margin-top: -4px;
    margin-bottom: 16px;
}

.inactive-modal #inactiveModalBody {
    max-height: 60vh;
    overflow-y: auto;
}

.project-access-grid {
    display: grid;
    gap: 12px;
    max-height: 60vh;
    overflow-y: auto;
}

.project-access-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 180px;
    gap: 16px;
    align-items: center;
    padding: 12px 14px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    background: color-mix(in srgb, var(--card-bg) 94%, var(--table-bg) 6%);
}

.project-access-name {
    font-weight: 600;
}

.project-access-meta {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.project-access-select {
    width: 100%;
}

.word-modal {
    width: min(900px, 96vw);
    padding: 28px 32px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
}

.word-modal > h2,
.word-modal > p,
.word-modal > .modal-close {
    flex-shrink: 0;
}

.word-modal #wordExportForm {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.word-form-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: scroll;
    scrollbar-gutter: stable;
    padding-right: 10px;
    border-right: 1px solid var(--border-color);
}

.word-form-scroll::-webkit-scrollbar {
    width: 12px;
}

.word-form-scroll::-webkit-scrollbar-track {
    background: color-mix(in srgb, var(--table-bg) 85%, var(--border-color) 15%);
    border-radius: 999px;
}

.word-form-scroll::-webkit-scrollbar-thumb {
    background: color-mix(in srgb, var(--border-color) 55%, var(--text-secondary) 45%);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.word-form-scroll::-webkit-scrollbar-thumb:hover {
    background: color-mix(in srgb, var(--border-color) 35%, var(--text-color) 65%);
    background-clip: padding-box;
}

/* ── Audit Trail Modal ────────────────────────────────── */

.audit-modal {
    width: min(580px, 92vw);
}

.audit-modal #auditModalBody {
    max-height: 60vh;
    overflow-y: auto;
}

.audit-timeline {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 4px 0;
}

.audit-record {
    border-left: 3px solid var(--border-color);
    padding: 10px 14px;
    border-radius: 0 10px 10px 0;
    background: rgba(148, 163, 184, 0.06);
}

.audit-record-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.audit-action {
    font-weight: 600;
    font-size: 0.85em;
    padding: 2px 8px;
    border-radius: 6px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.audit-created {
    background: rgba(34, 197, 94, 0.15);
    color: #22c55e;
}

.audit-edited {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.audit-deactivated {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.audit-restored {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.audit-timestamp {
    font-size: 0.8em;
    color: var(--text-secondary);
}

.audit-changes {
    list-style: none;
    padding: 0;
    margin: 6px 0 0 0;
    font-size: 0.85em;
}

.audit-changes li {
    padding: 3px 0;
    line-height: 1.4;
}

.audit-field {
    font-weight: 600;
    color: var(--text-color);
}

.audit-from {
    color: var(--text-secondary);
    text-decoration: line-through;
    opacity: 0.7;
}

.audit-to {
    color: var(--text-color);
}

/* ── End Audit Trail ──────────────────────────────────── */

/* ── Full Change History ─────────────────────────────── */

.full-history-btn {
    margin-top: 10px;
}

.full-history-modal {
    width: min(1250px, 97vw);
}

.full-history-project-name {
    margin-top: -2px;
    margin-bottom: 8px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.full-history-modal #fullHistoryBody {
    max-height: 68vh;
    overflow-y: auto;
    overflow-x: auto;
}

.fh-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.fh-toolbar .fh-result-count {
    margin-bottom: 0;
}

.full-history-filters {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    margin-bottom: 12px;
    background: rgba(148, 163, 184, 0.06);
    border: 1px solid var(--input-border);
    border-radius: 10px;
}

.fh-filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-end;
}

.fh-filter-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1 1 140px;
    min-width: 120px;
}

.fh-filter-field label {
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.fh-filter-field select,
.fh-filter-field input[type="text"],
.fh-filter-field input[type="date"] {
    padding: 8px 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 1.05rem;
}

.fh-filter-actions {
    flex-direction: row !important;
    align-items: flex-end !important;
    gap: 6px;
    flex: 0 0 auto;
}

/* ── FH Multi-dropdown ────────────────────────────────── */

.fh-multi-dropdown {
    position: relative;
}

.fh-multi-toggle {
    width: 100%;
    padding: 8px 32px 8px 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-secondary);
    font-size: 1.05rem;
    text-align: left;
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b7280'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.fh-multi-toggle.has-selection {
    color: var(--text-color);
    font-weight: 500;
}

.fh-multi-panel {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    min-width: 100%;
    max-height: 220px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    z-index: 100;
    padding: 6px 0;
}

.fh-multi-panel.open {
    display: block;
}

.fh-multi-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 1.05rem;
    color: var(--text-color);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.1s;
}

.fh-multi-option:hover {
    background: rgba(59, 130, 246, 0.08);
}

.fh-multi-option input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 15px;
    height: 15px;
    margin: 0;
    cursor: pointer;
}

.fh-multi-search-wrap {
    padding: 6px 8px;
    border-bottom: 1px solid var(--input-border);
    position: sticky;
    top: 0;
    background: var(--card-bg);
    z-index: 1;
}

.fh-multi-search {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.95rem;
    outline: none;
    box-sizing: border-box;
}

.fh-multi-search:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

/* ── End FH Multi-dropdown ────────────────────────────── */

.fh-result-count {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding-left: 2px;
}

.fh-entry-badge {
    font-weight: 700;
    font-size: 0.8em;
    color: var(--accent-primary);
}

.fh-doctype-badge {
    font-size: 0.75em;
    padding: 1px 7px;
    border-radius: 6px;
    background: rgba(148, 163, 184, 0.12);
    color: var(--text-secondary);
    font-weight: 500;
}

.fh-description {
    font-size: 0.8em;
    color: var(--text-secondary);
    margin: 2px 0 4px 0;
    font-style: italic;
}

.fh-record .audit-record-header {
    flex-wrap: wrap;
    gap: 6px;
}

.fh-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 1.05rem;
}

.fh-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--card-bg);
    text-align: left;
    padding: 10px 14px;
    font-size: 0.92rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--input-border);
    white-space: nowrap;
}

.fh-table th.fh-sortable {
    cursor: pointer;
    user-select: none;
}

.fh-table th.fh-sortable:hover {
    background: rgba(148, 163, 184, 0.18);
    color: var(--text-color);
}

.fh-table td {
    padding: 9px 14px;
    border-bottom: 1px solid var(--input-border);
    vertical-align: top;
    line-height: 1.5;
}

.fh-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.04);
}

.admin-users-table th,
.admin-users-table td,
.fh-table th,
.fh-table td {
    background: var(--card-bg);
    border-right: 1px solid rgba(148, 163, 184, 0.28);
}

.admin-users-table th:last-child,
.admin-users-table td:last-child,
.fh-table th:last-child,
.fh-table td:last-child {
    border-right: none;
}

.admin-users-table th,
.fh-table th {
    position: sticky !important;
    top: 0;
    z-index: 20;
}

.admin-users-table th:first-child,
.admin-users-table td:first-child,
.fh-table th:first-child,
.fh-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    box-shadow: 1px 0 0 var(--input-border);
}

.admin-users-table td:not(:first-child),
.fh-table td:not(:first-child) {
    position: static;
}

.admin-users-table th:first-child,
.fh-table th:first-child {
    z-index: 30;
}

.admin-users-table tbody tr:hover td,
.fh-table tbody tr:hover td {
    background: rgba(59, 130, 246, 0.04);
}

.admin-users-table tbody tr:hover td:first-child,
.fh-table tbody tr:hover td:first-child {
    background: rgba(59, 130, 246, 0.04);
}

.fh-desc-cell {
    max-width: 260px;
    color: var(--text-secondary);
    font-style: italic;
}

.fh-date-cell {
    white-space: nowrap;
    font-size: 1rem;
    color: var(--text-secondary);
}

.fh-changes-cell {
    font-size: 1rem;
    max-width: 340px;
}

.fh-changes-cell .audit-from {
    text-decoration: line-through;
    opacity: 0.7;
}

@media (max-width: 600px) {
    .fh-filter-field {
        flex: 1 1 100%;
    }
}

/* ── End Full Change History ──────────────────────────── */

.word-form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.word-form-grid label,
#wordExportForm > label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.88em;
}

#wordExportForm input,
#wordExportForm textarea,
#wordExportForm select {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.95em;
}

#wordExportForm textarea {
    resize: vertical;
    min-height: 44px;
}

.signature-section {
    margin-top: 10px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px;
    background: var(--table-bg);
}

.change-control-grid label:last-child {
    grid-column: 1 / -1;
}

.signature-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.signature-header h3 {
    margin: 0;
    font-size: 0.95em;
}

.signature-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.signature-row label {
    flex: 1;
    font-size: 0.82em;
    color: var(--text-secondary);
}

.signature-row button {
    border: none;
    background: none;
    color: var(--accent-primary);
    font-weight: 600;
    cursor: pointer;
    padding: 4px 8px;
    font-size: 0.82em;
    flex-shrink: 0;
}

.signature-row button:hover {
    text-decoration: underline;
}

.final-history-panel {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 10px;
    background: var(--table-bg);
    margin-bottom: 6px;
}

.word-export-context-panel {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 10px 12px;
    background: color-mix(in srgb, var(--card-bg) 92%, var(--accent-primary) 8%);
    margin-bottom: 10px;
}

.word-export-context-title {
    font-size: 0.82em;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
}

.word-export-context-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 18px;
}

.word-export-context-item {
    min-width: 0;
}

.word-export-context-item strong {
    display: block;
    font-size: 0.82em;
    color: var(--text-secondary);
    margin-bottom: 2px;
}

.word-export-context-note {
    margin-top: 10px;
    font-size: 0.88em;
    color: var(--text-secondary);
}
.final-history-header {
    font-size: 0.82em;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 6px;
}
.final-history-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    flex-wrap: wrap;
    padding: 3px 0;
    font-size: 0.84em;
    color: var(--text-color);
    border-bottom: 1px solid var(--border-color);
}
.final-history-row:last-child {
    border-bottom: none;
}
.final-history-row.latest {
    font-weight: 600;
}
.final-history-rev {
    min-width: 56px;
    font-weight: 600;
    color: var(--accent-primary);
}
.final-history-date {
    flex: 1;
    color: var(--text-secondary);
    font-size: 0.92em;
}
.final-history-user {
    color: var(--text-secondary);
    font-size: 0.92em;
}

.final-history-meta {
    width: 100%;
    color: var(--text-secondary);
    font-size: 0.82em;
}

.word-modal-actions {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.word-modal-actions .secondary-btn {
    padding: 8px 20px;
    font-size: 0.9em;
    border-radius: 8px;
    box-shadow: none;
}

.word-modal-actions .secondary-btn:hover {
    transform: none;
}

.word-modal-actions .text-btn {
    padding: 8px 14px;
    font-size: 0.9em;
}

.inactive-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 12px;
}

.inactive-table th,
.inactive-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
}

.inactive-table th {
    font-size: 0.8em;
    text-transform: uppercase;
    color: var(--text-secondary);
    letter-spacing: 0.05em;
}

.inactive-table td .restore-link {
    color: var(--accent-primary);
    cursor: pointer;
    font-weight: 600;
    border: none;
    background: none;
    padding: 0;
}

.inactive-table td .restore-link:hover {
    text-decoration: underline;
}

.heatmap-scale {
    position: relative;
    height: 36px;
    margin: 12px 0 8px;
}

.heatmap-gradient {
    width: 100%;
    height: 14px;
    border-radius: 999px;
    background: linear-gradient(90deg, #22c55e 0%, #facc15 40%, #f97316 70%, #ef4444 100%);
    box-shadow: inset 0 0 6px rgba(0,0,0,0.2);
}

.heatmap-indicator {
    position: absolute;
    top: -6px;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 2px solid var(--accent-primary);
    background: var(--card-bg);
    transition: left 0.3s ease;
}

.heatmap-details {
    display: flex;
    gap: 24px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}

.heatmap-thresholds {
    list-style: disc inside;
    margin-top: 0;
}

.info-note {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin-top: -6px;
    margin-bottom: 8px;
}
.filter-actions {
    margin-top: 8px;
}

.filter-actions .text-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Custom Select Dropdown Styles */
.custom-select-wrapper {
    position: relative;
    width: 100%;
}

.custom-select-trigger {
    width: 100%;
    padding: 12px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    background: var(--card-bg);
    background-image: none;
    color: var(--text-color);
    font-size: 0.95em;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    box-sizing: border-box;
}

.custom-select-trigger:hover {
    border-color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.1);
}

.custom-select-trigger:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
    outline: none;
}

.custom-select-trigger-text {
    flex: 1;
    text-align: left;
}

.custom-select-trigger-icon {
    margin-left: 8px;
    flex-shrink: 0;
    font-size: 0.75em;
    transition: transform 0.3s ease;
}

.custom-select-trigger[aria-expanded="true"] .custom-select-trigger-icon {
    transform: scaleY(-1);
}

.custom-select-panel {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin-top: 6px;
    background: var(--card-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
    z-index: 1000;
    max-height: 320px;
    overflow-y: auto;
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.custom-select-option {
    padding: 12px 14px;
    cursor: pointer;
    color: var(--text-color);
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.custom-select-option:hover {
    background-color: rgba(59, 130, 246, 0.08);
    border-left-color: var(--accent-primary);
    padding-left: 14px;
}

.custom-select-option.selected {
    background-color: rgba(59, 130, 246, 0.15);
    color: var(--accent-primary);
    font-weight: 500;
    border-left-color: var(--accent-primary);
}

.custom-select-option:first-child {
    border-radius: 8px 8px 0 0;
}

.custom-select-option:last-child {
    border-radius: 0 0 8px 8px;
}

/* ── Header right / User info ─────────────────────────── */

.header-right {
    display: grid;
    grid-template-columns: auto auto;
    grid-template-areas:
        "user theme"
        "user tz";
    align-items: center;
    column-gap: 16px;
    row-gap: 8px;
    flex-shrink: 0;
}

.header-right .user-info {
    grid-area: user;
}

.header-right .theme-switch-wrapper {
    grid-area: theme;
    justify-self: center;
}

.header-right .tz-selector-wrapper {
    grid-area: tz;
    justify-self: center;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    white-space: nowrap;
    font-size: 0.95rem;
}

.user-badge {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-color);
}

@media (max-width: 900px) {
    .header-right {
        display: flex;
        flex-direction: column;
        align-items: flex-end;
        gap: 8px;
    }
}

.account-badge {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 44px;
    padding: 8px 14px;
    border-radius: 14px;
    box-sizing: border-box;
    line-height: 1.05;
}

.account-badge-org {
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.2px;
    color: #8b5cf6;
}

.account-badge-role {
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.45px;
    color: currentColor;
}

.role-admin {
    background: rgba(234, 88, 12, 0.15);
    color: #ea580c;
}

.role-editor {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.role-viewer {
    background: rgba(107, 114, 128, 0.15);
    color: #6b7280;
}

.role-super_admin {
    background: rgba(220, 38, 38, 0.15);
    color: #dc2626;
}

.role-developer {
    background: rgba(147, 51, 234, 0.16);
    color: #7c3aed;
}

.role-admin .account-badge-org,
.role-editor .account-badge-org,
.role-viewer .account-badge-org,
.role-super_admin .account-badge-org,
.role-developer .account-badge-org {
    color: var(--text-color);
}

.org-switcher-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.org-switcher-select {
    height: 32px;
    min-width: 160px;
    padding: 0 34px 0 12px;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--border-color) 55%, var(--text-secondary) 45%);
    background: var(--card-bg);
    color: var(--text-color);
    font-size: 0.85rem;
    box-sizing: border-box;
}

.btn-small {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 14px;
    margin: 0;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--border-color) 55%, var(--text-secondary) 45%);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    font-weight: 600;
    box-shadow: none;
    transform: none;
    transition: background 0.15s ease;
    box-sizing: border-box;
}

.btn-small:hover {
    background: color-mix(in srgb, var(--table-bg) 82%, var(--border-color) 18%);
    color: var(--text-color);
    border-color: var(--border-color);
    box-shadow: none;
    transform: none;
}

.btn-edit-users {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    padding: 0 16px;
    font-size: 0.85rem;
    line-height: 1;
    border-radius: 8px;
    border: 1px solid color-mix(in srgb, var(--border-color) 55%, var(--text-secondary) 45%);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    font-weight: 600;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    box-sizing: border-box;
}

.btn-edit-users:hover {
    background: color-mix(in srgb, var(--table-bg) 82%, var(--border-color) 18%);
    color: var(--text-color);
    border-color: var(--border-color);
    box-shadow: none;
}

/* ── Audit user label ──────────────────────────────────── */

.audit-user {
    font-weight: 600;
    color: var(--text-color);
    font-size: 0.85rem;
}

.audit-record-header {
    gap: 8px;
}

/* ── Admin page ────────────────────────────────────────── */

.admin-grid {
    display: grid;
    grid-template-columns: 1fr 2fr;
    gap: 24px;
    margin-top: 20px;
}

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

.admin-card {
    background: var(--card-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 20px;
}

.admin-card h2 {
    font-size: 1.15rem;
    margin-bottom: 16px;
    color: var(--text-color);
}

/* Horizontal form layout */
.admin-form-horizontal {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.admin-form-row {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.admin-form-row .admin-field {
    flex: 1;
    min-width: 180px;
    margin-bottom: 0;
}
.admin-form-row .admin-field-btn {
    flex: 0 0 auto;
    min-width: auto;
    display: flex;
    align-items: flex-end;
}
.admin-form-row .admin-field-btn .btn {
    white-space: nowrap;
    height: 40px;
}

.admin-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 12px;
}

.admin-field label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.admin-field input,
.admin-field select {
    padding: 10px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.9rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.admin-field input:focus,
.admin-field select:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    outline: none;
}

.admin-field input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
}

.admin-form button[type="submit"] {
    margin-top: 8px;
    padding: 8px 16px;
    background: var(--accent-primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.85rem;
}

.admin-form button[type="submit"]:hover {
    opacity: 0.9;
}

.admin-error {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 6px;
}

.admin-success {
    color: #22c55e;
    font-size: 0.8rem;
    margin-top: 6px;
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.admin-table th,
.admin-table td {
    padding: 8px 10px;
    text-align: left;
    border-bottom: 1px solid var(--input-border);
}

.admin-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.admin-table select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.8rem;
}

/* Admin table toolbar / search */
.admin-table-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}
.admin-search-input {
    width: 100%;
    max-width: 340px;
    padding: 8px 12px;
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    transition: border-color 0.2s, box-shadow 0.2s;
}
.admin-search-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
    outline: none;
}

/* Sortable column headers */
.sortable-th {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: background 0.15s;
    padding-right: 18px;
}
.sortable-th:hover {
    background: rgba(148, 163, 184, 0.18);
}
.sort-icon {
    display: inline-block;
    margin-left: 4px;
    font-size: 0.7rem;
}
.sort-inactive {
    opacity: 0.3;
}
.sort-active {
    opacity: 1;
    color: var(--accent-primary);
}

/* Admin users table — title & role selects */
.admin-users-table .title-select,
.admin-users-table .role-select,
.admin-users-table .org-select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-color);
    font-size: 0.8rem;
}

.admin-users-table,
.fh-table {
    table-layout: fixed;
}

.admin-users-table {
    width: max-content;
    min-width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

#usersTableContainer,
#orgsTableContainer,
#auditLogContainer {
    max-height: calc(16 * 3rem);
    overflow-x: auto;
    overflow-y: auto;
    position: relative;
    display: block;
    -webkit-overflow-scrolling: touch;
}

.admin-users-table td,
.fh-table td {
    overflow: hidden;
}

.admin-users-table th,
.fh-table th {
    overflow: visible;
}

.audit-subref {
    margin-top: 4px;
    color: var(--text-secondary);
    font-size: 0.85em;
    font-weight: 400;
    line-height: 1.35;
    word-break: break-word;
    white-space: normal;
}

.audit-details-cell {
    max-width: 320px;
    white-space: normal;
    word-break: break-word;
    overflow-wrap: anywhere;
    text-overflow: initial;
}

.import-section {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--input-border);
}

.import-section h3 {
    font-size: 1rem;
    margin-bottom: 8px;
}

.import-section p {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* ── Traceability Map ── */
.map-container {
    position: relative;
    margin-top: 24px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
    overflow: hidden;
}

.map-canvas-wrapper {
    width: 100%;
    height: calc(100vh - 260px);
    min-height: 500px;
    cursor: grab;
    overflow: hidden;
}

.map-canvas-wrapper:active {
    cursor: grabbing;
}

.map-svg {
    width: 100%;
    height: 100%;
}

.map-controls {
    position: absolute;
    top: 16px;
    left: 16px;
    z-index: 20;
    display: flex;
    gap: 6px;
}

.map-ctrl-btn {
    width: 38px;
    height: 38px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    font-weight: 700;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-color);
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
    transition: background 0.2s, transform 0.15s;
}

.map-ctrl-btn:hover {
    background: var(--table-bg);
    transform: scale(1.05);
}

.map-ctrl-btn:last-child {
    width: auto;
    padding: 0 14px;
    font-size: 0.85rem;
    font-weight: 600;
}

.map-legend {
    position: absolute;
    bottom: 16px;
    left: 16px;
    z-index: 20;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 18px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.08);
}

.map-legend h3 {
    margin: 0 0 10px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.legend-items {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 16px;
    margin-bottom: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--text-color);
    white-space: nowrap;
}

.legend-dot {
    width: 12px;
    height: 12px;
    border-radius: 4px;
    flex-shrink: 0;
}

.legend-line-items {
    display: flex;
    gap: 16px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.legend-line {
    display: inline-block;
    width: 28px;
    height: 2px;
    vertical-align: middle;
    flex-shrink: 0;
    margin-top: 1px;
}

.legend-line.solid {
    background: var(--text-secondary);
}

.legend-line.dashed {
    background: repeating-linear-gradient(
        90deg,
        var(--text-secondary) 0px,
        var(--text-secondary) 6px,
        transparent 6px,
        transparent 10px
    );
}

/* Node hover animation */
.map-node {
    transition: opacity 0.3s ease;
}

.map-node .node-rect {
    transition: filter 0.3s ease;
}

.map-edge {
    transition: opacity 0.3s ease;
}

.edge-label {
    pointer-events: none;
}

.waterfall-reference {
    margin-top: 24px;
    padding: 24px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: var(--card-bg);
    box-shadow: var(--card-shadow);
}

.waterfall-reference-header h2 {
    margin: 0 0 6px;
}

.waterfall-reference-header .subtitle {
    margin: 0 0 18px;
}

.waterfall-iteration-note {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
    padding: 10px 14px;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: color-mix(in srgb, var(--card-bg) 88%, var(--table-bg) 12%);
    color: var(--text-secondary);
    font-size: 0.92rem;
}

.waterfall-iteration-icon {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
}

.waterfall-diagram {
    display: flex;
    align-items: stretch;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 4px;
}

.waterfall-stage {
    min-width: 190px;
    padding: 16px 18px;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    background: color-mix(in srgb, var(--card-bg) 88%, var(--table-bg) 12%);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}

.waterfall-stage-phase {
    margin-bottom: 8px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-secondary);
}

.waterfall-stage-title {
    margin-bottom: 10px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--text-color);
}

.waterfall-stage-docs {
    font-size: 0.92rem;
    line-height: 1.55;
    color: var(--text-secondary);
}

.waterfall-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-secondary);
}

.waterfall-iteration-flow {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
    color: var(--text-secondary);
    font-size: 0.92rem;
    font-weight: 600;
}

.waterfall-iteration-flow span:first-child,
.waterfall-iteration-flow span:last-child {
    font-size: 1.2rem;
    color: var(--text-color);
}

@media (max-width: 900px) {
    .waterfall-iteration-note {
        display: flex;
        border-radius: 16px;
    }

    .waterfall-diagram {
        gap: 10px;
    }

    .waterfall-stage {
        min-width: 220px;
    }
}
