* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #f0f2f5;
    color: #2d3436;
    font-size: 14px;
}

/* ===== Header ===== */
header {
    background: #2c3e50;
    color: white;
    padding: 0 24px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    z-index: 100;
    position: relative;
}
.header-left {
    display: flex;
    align-items: baseline;
    gap: 12px;
}
.header-left h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: 0.5px;
}
.header-subtitle {
    font-size: 12px;
    color: #95a5a6;
    font-weight: 400;
}
.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
}
.header-right label {
    font-size: 12px;
    color: #bdc3c7;
    font-weight: 600;
}
.header-right input[type="number"] {
    width: 48px;
    padding: 4px 6px;
    border: 1px solid #4a6a8a;
    border-radius: 4px;
    font-size: 12px;
    background: #34495e;
    color: white;
    text-align: center;
}
.header-right input[type="number"]:focus {
    outline: none;
    border-color: #3498db;
}
/* File menu */
.file-menu { position: relative; }
.file-menu-btn {
    background: none;
    border: 1px solid transparent;
    color: #bdc3c7;
    font-size: 13px;
    padding: 4px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    letter-spacing: 0.2px;
}
.file-menu-btn:hover, .file-menu-btn.open {
    background: #34495e;
    border-color: #4a6a8a;
    color: #fff;
}
.file-menu-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    background: #2c3e50;
    border: 1px solid #4a6a8a;
    border-radius: 5px;
    min-width: 140px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.35);
    z-index: 1000;
    padding: 4px 0;
}
.file-menu-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: #ecf0f1;
    font-size: 13px;
    padding: 7px 16px;
    cursor: pointer;
}
.file-menu-item:hover { background: #3d5166; }
.file-menu-separator {
    height: 1px;
    background: #4a6a8a;
    margin: 4px 0;
}

.btn-run {
    padding: 6px 18px;
    background: #27ae60;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.3px;
    transition: background 0.15s;
}
.btn-run:hover { background: #2ecc71; }
.btn-run:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Main Layout ===== */
.main-layout {
    display: flex;
    height: calc(100vh - 48px);
}

/* ===== Left Tools Panel ===== */
#tools-panel {
    width: 160px;
    min-width: 140px;
    background: #2c3e50;
    overflow-y: auto;
    padding: 16px 10px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.panel-section {}
.panel-heading {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #7f8c8d;
    margin-bottom: 8px;
    padding: 0 4px;
}
.panel-btn {
    display: block;
    width: 100%;
    padding: 7px 10px;
    margin-bottom: 4px;
    border: 1px solid #3d566e;
    background: #34495e;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
    color: #ecf0f1;
    text-align: left;
    transition: all 0.1s;
    white-space: nowrap;
}
.panel-btn:hover {
    background: #4a6a8a;
    border-color: #5a8ab5;
    color: #fff;
}
.panel-btn-accent {
    border-color: #2e7d6e;
    background: #1e5f52;
    color: #b2dfdb;
}
.panel-btn-accent:hover {
    background: #26897a;
    border-color: #4db6ac;
    color: #fff;
}

/* Checkbox option in left panel */
.panel-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    color: #ecf0f1;
    font-size: 11px;
    cursor: pointer;
    border-radius: 4px;
}
.panel-checkbox:hover { background: rgba(255,255,255,0.05); }
.panel-checkbox input[type="checkbox"] {
    flex-shrink: 0;
    accent-color: #3498db;
}
.panel-radio-group {
    margin-top: 8px;
    padding: 6px 4px;
    border-radius: 4px;
    background: rgba(255,255,255,0.03);
}
.panel-radio-title {
    font-size: 10px;
    font-weight: 700;
    color: #95a5a6;
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.panel-radio {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
    color: #ecf0f1;
    cursor: pointer;
    padding: 4px 0;
}
.panel-radio input[type="radio"] {
    flex-shrink: 0;
    accent-color: #3498db;
}

/* Default value fields in left panel */
.panel-field {
    margin-bottom: 6px;
}
.panel-field label {
    display: block;
    font-size: 10px;
    color: #95a5a6;
    margin-bottom: 2px;
    padding: 0 4px;
}
.panel-field input[type="text"] {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #3d566e;
    background: #34495e;
    border-radius: 4px;
    font-size: 11px;
    color: #ecf0f1;
}
.panel-field input[type="text"]:focus {
    outline: none;
    border-color: #3498db;
}
.panel-field input[type="text"]::placeholder {
    color: #7f8c8d;
}

/* ===== Right Domain Panel ===== */
#domain-panel {
    width: 280px;
    min-width: 240px;
    background: #fff;
    border-left: 1px solid #e0e0e0;
    overflow-y: auto;
    padding: 16px 12px;
    flex-shrink: 0;
}
#domain-panel h2 {
    font-size: 14px;
    margin-bottom: 2px;
    color: #2c3e50;
}
#domain-panel .hint {
    font-size: 11px;
    color: #999;
    margin-bottom: 12px;
}

.domain-section { margin-bottom: 2px; }
.domain-header {
    cursor: pointer;
    padding: 7px 8px;
    background: #f5f6fa;
    border-radius: 4px;
    font-weight: 600;
    font-size: 12px;
    user-select: none;
    display: flex;
    align-items: center;
    gap: 6px;
    color: #34495e;
    transition: background 0.1s;
    justify-content: space-between;
}
.domain-header:hover { background: #ecf0f1; }
.domain-header-main {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}
.collapse-icon { font-size: 9px; width: 10px; color: #999; }
.domain-select-all {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-weight: 600;
    color: #636e72;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    background: #fff;
    border: 1px solid #d8dde3;
}
.domain-select-all:hover {
    background: #fdfefe;
    border-color: #c8d1db;
}
.domain-select-all input[type="checkbox"] {
    margin: 0;
    accent-color: #3498db;
}

.domain-body { padding: 2px 0 2px 6px; }
.domain-element {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    padding: 3px 4px;
    cursor: pointer;
    font-size: 11px;
    line-height: 1.3;
    border-radius: 3px;
}
.domain-element:hover { background: #f5f6fa; }
.domain-element input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; }
.el-id {
    font-weight: 700;
    color: #2c3e50;
    white-space: nowrap;
    font-size: 10px;
}

/* Selection context panel */
#selection-context { margin-bottom: 8px; }
.sel-context-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: #eaf3fb;
    border: 1px solid #aacfe8;
    border-radius: 5px;
    flex-wrap: wrap;
}
.sel-context-count {
    font-size: 11px;
    font-weight: 600;
    color: #1a6b9a;
    flex: 1;
    white-space: nowrap;
}
.sel-context-btn {
    font-size: 11px;
    padding: 3px 8px;
    background: #3498db;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
}
.sel-context-btn:hover { background: #2980b9; }
.sel-context-clear {
    background: none;
    border: none;
    cursor: pointer;
    color: #7fb3d3;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 3px;
}
.sel-context-clear:hover { color: #e74c3c; background: #fdecea; }
.sel-context-form {
    margin-top: 4px;
    padding: 6px;
    background: #f8f9fa;
    border: 1px solid #d0d7de;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.sel-context-form input {
    font-size: 11px;
    padding: 4px 6px;
    border: 1px solid #d0d7de;
    border-radius: 3px;
    outline: none;
}
.sel-context-form input:focus { border-color: #3498db; }

/* Custom domain UI */
.custom-domain-section .domain-header { background: #f0f4f8; }
.custom-domain-delete-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: #aaa;
    font-size: 12px;
    padding: 2px 4px;
    border-radius: 3px;
    line-height: 1;
}
.custom-domain-delete-btn:hover { color: #e74c3c; background: #fdecea; }

.custom-domain-element-row {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 4px;
    font-size: 11px;
    border-radius: 3px;
}
.custom-domain-element-row:hover { background: #f5f6fa; }
.custom-el-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-el-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #ccc;
    font-size: 10px;
    padding: 1px 3px;
    border-radius: 2px;
    flex-shrink: 0;
}
.custom-el-remove:hover { color: #e74c3c; background: #fdecea; }

.custom-domain-add-form {
    display: flex;
    gap: 4px;
    padding: 4px 2px 2px;
    align-items: center;
}
.custom-el-label-input {
    flex: 1;
    min-width: 0;
    font-size: 11px;
    padding: 3px 5px;
    border: 1px solid #d0d7de;
    border-radius: 3px;
    outline: none;
}
.custom-el-label-input:focus { border-color: #3498db; }
.custom-el-add-btn {
    font-size: 10px;
    padding: 3px 6px;
    background: #3498db;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
    white-space: nowrap;
}
.custom-el-add-btn:hover { background: #2980b9; }

#new-domain-container { margin-top: 8px; padding: 2px; }
.btn-new-domain {
    width: 100%;
    font-size: 11px;
    padding: 5px 8px;
    background: #fff;
    border: 1px dashed #aaa;
    border-radius: 4px;
    color: #555;
    cursor: pointer;
    text-align: center;
}
.btn-new-domain:hover { background: #f5f6fa; border-color: #3498db; color: #3498db; }

#new-domain-form {
    display: flex;
    flex-direction: column;
    gap: 5px;
    padding: 6px;
    background: #f8f9fa;
    border: 1px solid #d0d7de;
    border-radius: 4px;
}
#new-domain-form input {
    font-size: 11px;
    padding: 4px 6px;
    border: 1px solid #d0d7de;
    border-radius: 3px;
    outline: none;
}
#new-domain-form input:focus { border-color: #3498db; }
.new-domain-form-btns { display: flex; gap: 4px; }
.btn-create-domain {
    flex: 1;
    font-size: 11px;
    padding: 4px 6px;
    background: #27ae60;
    color: #fff;
    border: none;
    border-radius: 3px;
    cursor: pointer;
}
.btn-create-domain:hover { background: #219a52; }
.btn-cancel-domain {
    font-size: 11px;
    padding: 4px 6px;
    background: #ecf0f1;
    color: #555;
    border: 1px solid #d0d7de;
    border-radius: 3px;
    cursor: pointer;
}
.btn-cancel-domain:hover { background: #dfe6e9; }

#results-viz-toggles {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.result-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: #2c3e50;
    padding: 7px 8px;
    border-radius: 4px;
    background: #f5f6fa;
    cursor: pointer;
    user-select: none;
}
.result-toggle:hover {
    background: #ecf0f1;
}
.result-toggle-text {
    flex: 1;
}
.result-switch {
    position: relative;
    width: 38px;
    height: 22px;
    flex-shrink: 0;
}
.result-switch input[type="checkbox"] {
    position: absolute;
    inset: 0;
    margin: 0;
    opacity: 0;
    cursor: pointer;
    z-index: 2;
}
.result-switch-slider {
    position: absolute;
    inset: 0;
    border-radius: 999px;
    background: #b8c2cc;
    transition: background 0.18s ease;
}
.result-switch-slider::before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.22);
    transition: transform 0.18s ease;
}
.result-switch input[type="checkbox"]:checked + .result-switch-slider {
    background: #3498db;
}
.result-switch input[type="checkbox"]:checked + .result-switch-slider::before {
    transform: translateX(16px);
}
.result-switch input[type="checkbox"]:focus-visible + .result-switch-slider {
    outline: 2px solid #2c3e50;
    outline-offset: 1px;
}

/* ===== Main Content ===== */
main {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
}

/* ===== Step Tabs ===== */
.step-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-bottom: 12px;
}
.tab-btn {
    padding: 8px 20px;
    border: 1px solid #ddd;
    border-bottom: 2px solid #ddd;
    background: #f5f6fa;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    color: #95a5a6;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 8px;
}
.tab-btn:hover { background: #ecf0f1; color: #636e72; }
.tab-btn.active {
    background: #fff;
    color: #2c3e50;
    border-bottom-color: #fff;
    position: relative;
    z-index: 1;
}
.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ddd;
    color: #888;
    font-size: 11px;
    font-weight: 700;
}
.tab-btn.active .step-num {
    background: #2c3e50;
    color: #fff;
}
.dep-count-badge {
    font-size: 11px;
    color: #95a5a6;
    margin-left: 12px;
}

/* Results tab - distinct color */
.tab-results {
    border-color: #27ae60;
}
.tab-results.active {
    border-bottom-color: #fff;
}
.tab-results .step-num {
    background: #27ae60;
    color: #fff;
}

/* ===== Tab Content Panels ===== */
.tab-content {
    display: none;
    flex: 1;
    min-height: 0;
}
.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* ===== DSM Editor ===== */
#dsm-container {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    margin-bottom: 20px;
    overflow: auto;
}
#dsm-canvas-wrapper {
    min-height: 280px;
    padding: 12px;
    position: relative;
}
#dsm-empty-msg {
    text-align: center;
    padding: 80px 20px;
    color: #999;
    cursor: pointer;
}
#dsm-empty-msg p { margin-bottom: 6px; font-size: 13px; }
#dsm-empty-msg:hover { color: #666; }

#dsm-table {
    border-collapse: collapse;
    font-size: 12px;
    width: auto;
}
#dsm-table th, #dsm-table td {
    border: 1px solid #e8e8e8;
    padding: 0;
    text-align: center;
}

/* Serial number column */
#dsm-table .sn-col {
    width: 28px; min-width: 28px;
    background: #f8f9fa;
    font-weight: 600;
    font-size: 10px;
    color: #aaa;
}
.sn-cell {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 10px;
    color: #aaa;
    width: 28px;
    min-width: 28px;
}

/* Corner / row headers */
#dsm-table .corner {
    min-width: 140px;
    background: #f8f9fa;
    text-align: left !important;
    padding-left: 28px !important;
    font-size: 11px;
    color: #636e72;
}
#dsm-table .action-col {
    width: 24px; min-width: 24px;
    background: #f8f9fa;
}

.col-header {
    min-width: 32px;
    width: 32px;
    background: #f8f9fa;
    font-weight: 600;
    font-size: 11px;
    padding: 4px 2px !important;
    color: #636e72;
}

.row-header {
    background: #f8f9fa;
    font-weight: 600;
    font-size: 11px;
    padding: 4px 6px !important;
    text-align: left !important;
    white-space: nowrap;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    cursor: default;
    color: #2c3e50;
}

/* Drag handle */
.drag-handle {
    cursor: grab;
    color: #ccc;
    margin-right: 4px;
    font-size: 11px;
    user-select: none;
}
.drag-handle:hover { color: #888; }
.drag-handle:active { cursor: grabbing; }

.element-name { cursor: text; }
.element-name:hover { text-decoration: underline dotted #aaa; }

/* Drag and drop indicators */
.dsm-row[draggable="true"] { transition: opacity 0.15s; }
.dsm-row.dragging { opacity: 0.35; }
.dsm-row.drop-above td { box-shadow: inset 0 3px 0 0 #3498db; }
.dsm-row.drop-below td { box-shadow: inset 0 -3px 0 0 #3498db; }

.btn-remove {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: #ddd;
    font-size: 14px;
    cursor: pointer;
    border-radius: 3px;
    line-height: 1;
    padding: 0;
    transition: color 0.1s;
}
.btn-remove:hover { color: #e74c3c; background: #fde8e8; }

.diagonal {
    background: #b0b3b8 !important;
}

/* ===== MDM Domain Grouping ===== */
.domain-header-row th {
    padding: 0 !important;
    border: none !important;
}
.domain-spacer {
    background: transparent !important;
    border: none !important;
}
.domain-col-header {
    font-size: 10px !important;
    font-weight: 700 !important;
    text-align: center !important;
    padding: 3px 2px !important;
    letter-spacing: 0.5px;
    background: #fff !important;
}

/* Thick borders at domain boundaries */
.domain-border-left {
    border-left: 2.5px solid #999 !important;
}
.domain-border-top td,
.domain-border-top th {
    border-top: 2.5px solid #999 !important;
}

/* Intra-domain cells get a subtle tinted background */
.intra-domain {
    background: rgba(0,0,0,0.02);
}

/* ===== Dependency cells (Tab 1) ===== */
.dep-cell {
    width: 32px;
    height: 28px;
    cursor: pointer;
    user-select: none;
    font-size: 13px;
    color: #ddd;
    transition: background 0.1s;
}
.dep-cell:hover {
    background: #e8f4fd !important;
}
.dep-cell.dep-active {
    background: #d5f5e3 !important;
    color: #27ae60;
    font-weight: 700;
}

/* ===== Value cells (Tab 2 & 3) ===== */
.no-dep-cell {
    background: #fafafa !important;
}

/* Active dependency cells in likelihood/impact tabs - blue tint */
.dsm-cell.has-dep {
    background: #e8f4fd !important;
    padding: 0 !important;
}

.dsm-cell {
    padding: 0 !important;
}
.cell-input {
    width: 44px;
    height: 28px;
    border: none;
    text-align: center;
    font-size: 11px;
    background: transparent;
    padding: 2px;
    color: #2c3e50;
}
.cell-input:focus {
    background: #fff9c4;
    outline: 2px solid #3498db;
}
.cell-input.input-error {
    background: #fde8e8 !important;
    outline: 2px solid #e74c3c;
}
.cell-input::placeholder {
    color: #c0d6e8;
    font-size: 9px;
}

/* Selected row */
.selected-row td {
    background-color: #edf2ff !important;
}
.selected-row .diagonal {
    background-color: #dce5ff !important;
}
.selected-row .cell-input {
    background-color: transparent;
}

/* ===== Results ===== */
.results-layout {
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}
.plot-container {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 8px;
    min-height: 450px;
}
.plot-container-sm {
    min-height: 380px;
}
.viz-panel {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
}
.viz-controls {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    border-bottom: 1px dashed #e0e0e0;
    padding-bottom: 10px;
    margin-bottom: 12px;
}
.viz-control label,
.viz-label {
    font-size: 11px;
    font-weight: 700;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    display: block;
    margin-bottom: 4px;
}
.viz-control select {
    min-width: 220px;
    padding: 6px 8px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    color: #2c3e50;
}
.viz-control select:focus {
    outline: none;
    border-color: #3498db;
}
.viz-mode {
    display: inline-flex;
    border: 1px solid #dcdcdc;
    border-radius: 6px;
    overflow: hidden;
}
.viz-mode-btn {
    border: none;
    padding: 6px 12px;
    background: #f5f6fa;
    font-size: 12px;
    font-weight: 600;
    color: #636e72;
    cursor: pointer;
    transition: all 0.15s;
}
.viz-mode-btn:hover {
    background: #ecf0f1;
    color: #2c3e50;
}
.viz-mode-btn.active {
    background: #2c3e50;
    color: #fff;
}
.viz-note {
    font-size: 11px;
    color: #95a5a6;
}
.viz-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 16px;
}
.viz-card h3 {
    font-size: 13px;
    margin: 0 0 8px;
    color: #636e72;
}
#results-matrices {
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 12px;
    overflow-x: auto;
}
#results-matrices .matrix-controls {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 10px;
}
.matrix-control label {
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 4px;
}
.matrix-control select {
    min-width: 200px;
    padding: 6px 8px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    color: #2c3e50;
}
.matrix-control select:disabled {
    background: #f5f6fa;
    color: #95a5a6;
}
#results-matrices h3 {
    font-size: 13px;
    margin: 12px 0 8px;
    color: #636e72;
}
#results-matrices h3:first-child { margin-top: 0; }

.result-matrix .diagonal { background: #b0b3b8; }

.clarkson-matrix,
.result-matrix {
    border-collapse: collapse;
    font-size: 11px;
    margin-bottom: 12px;
    width: auto;
}
.clarkson-matrix th, .clarkson-matrix td,
.result-matrix th, .result-matrix td {
    border: 1px solid #e8e8e8;
    padding: 0;
    text-align: center;
    white-space: nowrap;
}
.clarkson-matrix th,
.result-matrix th {
    background: #f8f9fa;
    font-weight: 600;
    color: #636e72;
    padding: 4px 2px;
}
/* data cells in numeric matrix */
.result-matrix td[data-row] {
    padding: 3px 5px;
    font-size: 11px;
}
.crp-cell {
    position: relative;
    width: 32px;
    height: 32px;
    padding: 0 !important;
    background: #fff;
}
.crp-box {
    position: absolute;
    bottom: 2px;
    left: 2px;
    background: rgba(39, 174, 96, 0.45);
    border: 1px solid rgba(39, 174, 96, 0.75);
    box-sizing: border-box;
}

/* ===== Abstraction level bar ===== */
.abstraction-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 10px 14px;
}
.abstraction-left {
    display: flex;
    align-items: center;
    gap: 12px;
}
.abstraction-left .viz-label {
    margin-bottom: 0;
    white-space: nowrap;
}
.domain-level-note {
    font-size: 11px;
    color: #7f8c8d;
    font-style: italic;
    max-width: 480px;
    line-height: 1.4;
}
.abs-level-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ===== Direct overlay scatter toggle ===== */
.scatter-controls {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 18px;
    margin: -4px 0 8px;
}
.scatter-scale-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.scatter-toggle {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    font-size: 11px;
    color: #636e72;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 4px;
    background: #f5f6fa;
    border: 1px solid #e0e0e0;
    user-select: none;
    transition: background 0.12s;
}
.scatter-toggle:hover { background: #ecf0f1; }
.scatter-toggle input[type="checkbox"] { accent-color: #3498db; }

/* ===== Generic DSM-style structural cells (used in result matrices too) ===== */
.sn-col {
    width: 28px;
    min-width: 28px;
    font-size: 10px;
    font-weight: 600;
    color: #aaa;
    background: #f8f9fa;
    text-align: center;
    padding: 4px 2px !important;
}
.clarkson-matrix .corner,
.result-matrix .corner {
    min-width: 140px;
    background: #f8f9fa;
    text-align: left !important;
    font-size: 11px;
    color: #636e72;
    padding: 4px 8px !important;
}
/* Domain-coloured row headers: let inline style win over class background */
.clarkson-matrix .row-header,
.result-matrix .row-header {
    background: transparent;  /* overridden by inline style="background:..." */
    padding: 4px 8px !important;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ===== Propagation Highlighting (unified) ===== */
.clarkson-matrix .row-header[data-element],
.clarkson-matrix th[data-element],
.result-matrix .row-header[data-element],
.result-matrix th[data-element] {
    cursor: pointer;
    transition: background 0.12s;
}
.clarkson-matrix .row-header[data-element]:hover,
.clarkson-matrix th[data-element]:hover,
.result-matrix .row-header[data-element]:hover,
.result-matrix th[data-element]:hover {
    background: #dce5ff !important;
}
/* Dim non-highlighted cells */
.clarkson-matrix.hl-mode .crp-cell.hl-off .crp-box,
.result-matrix.hl-mode td[data-row].hl-off {
    opacity: 0.1;
}
/* Emphasise highlighted cells */
.clarkson-matrix.hl-mode .crp-cell.hl-on {
    background: rgba(52, 152, 219, 0.1) !important;
}
.result-matrix.hl-mode td[data-row].hl-on {
    box-shadow: inset 0 0 0 2px #3498db;
    opacity: 1;
}

/* ===== Export Dialog ===== */
.svg-export-dialog {
    border: none;
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.25);
    padding: 0;
    width: min(1100px, 96vw);
    height: min(680px, 90vh);
    max-width: none;
    max-height: none;
    font-family: inherit;
    overflow: hidden;
}
.svg-export-dialog[open] {
    display: flex;
    flex-direction: column;
}
.svg-export-dialog::backdrop {
    background: rgba(0,0,0,0.45);
}
.svg-export-dialog form {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

/* Header */
.export-dialog-header {
    padding: 14px 20px 12px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
}
.export-dialog-header h2 {
    font-size: 15px;
    font-weight: 700;
    color: #2c3e50;
    margin: 0;
}

/* Body: left settings + right preview */
.export-dialog-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left settings panel */
.export-settings-panel {
    width: 260px;
    min-width: 220px;
    flex-shrink: 0;
    border-right: 1px solid #eee;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Tab navigation (top of left panel) */
.export-tab-nav {
    display: flex;
    flex-shrink: 0;
    border-bottom: 1px solid #eee;
    background: #f8f9fa;
}
.export-tab-btn {
    flex: 1;
    padding: 9px 6px;
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    color: #95a5a6;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.12s;
}
.export-tab-btn:hover { color: #2c3e50; background: #ecf0f1; }
.export-tab-btn.active {
    color: #2c3e50;
    border-bottom-color: #3498db;
    background: #fff;
}

/* Tab panes */
.export-tab-pane {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    gap: 10px;
    flex-direction: column;
}
.export-tab-pane.active { display: flex; }
.export-tab-pane::-webkit-scrollbar { width: 5px; }
.export-tab-pane::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }

/* Field rows inside tabs */
.export-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.export-field label {
    font-size: 10px;
    font-weight: 700;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.export-field input,
.export-field select {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 12px;
    background: #fff;
    color: #2c3e50;
    box-sizing: border-box;
}
.export-field input[type="checkbox"] {
    width: auto;
    accent-color: #3498db;
}
.export-field input:focus,
.export-field select:focus {
    outline: none;
    border-color: #3498db;
}

/* Section labels inside tabs */
.export-section-label {
    font-size: 9px;
    font-weight: 700;
    color: #95a5a6;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-top: 4px;
    padding-bottom: 1px;
    border-bottom: 1px solid #f0f0f0;
}
/* Horizontal row: font select + size input side by side */
.export-field-row {
    display: flex;
    gap: 5px;
    align-items: flex-end;
}
.export-field-row > select,
.export-field-row > .font-select {
    flex: 1;
    min-width: 0;
    padding: 5px 4px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 11px;
    background: #fff;
    color: #2c3e50;
}
.export-field-row > input[type="number"] {
    width: 52px;
    flex-shrink: 0;
    padding: 5px 4px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 11px;
    text-align: center;
    color: #2c3e50;
}
.export-field-row > select:focus,
.export-field-row > input:focus {
    outline: none;
    border-color: #3498db;
}
/* Compact field (label above input, used in Axes tab) */
.export-field.compact {
    flex: 1;
    gap: 2px;
}
.export-field.compact label {
    font-size: 9px;
}
.export-field.compact input {
    padding: 4px 6px;
    font-size: 11px;
}
/* Font select styling */
select.font-select {
    max-width: 100%;
}
/* Inline checkbox label (checkbox + text on same line) */
.export-field label:has(input[type="checkbox"]) {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11px;
    font-weight: 600;
    color: #2c3e50;
    text-transform: none;
    letter-spacing: 0;
    cursor: pointer;
}

/* Right preview panel */
.export-preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 12px 14px;
    gap: 6px;
}
.export-preview-label {
    font-size: 10px;
    font-weight: 700;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}
.export-preview {
    flex: 1;
    background: #fafafa;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    overflow: auto;
    position: relative;
}
.export-preview .js-plotly-plot { flex-shrink: 0; }
.export-preview-table {
    transform-origin: top left;
    padding: 8px;
    position: absolute;
    top: 0;
    left: 0;
}
.export-preview-loading {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #aaa;
    font-size: 12px;
    font-style: italic;
}

/* Footer */
.export-dialog-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.export-footer-left {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.export-footer-zoom {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: center;
}
.zoom-label {
    font-size: 11px;
    font-weight: 700;
    color: #636e72;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
.zoom-pct {
    font-size: 12px;
    color: #636e72;
}
#export-zoom-range {
    width: 110px;
    accent-color: #3498db;
    cursor: pointer;
}
#export-zoom-num {
    width: 52px;
    padding: 4px 6px;
    border: 1px solid #dcdcdc;
    border-radius: 4px;
    font-size: 12px;
    text-align: center;
    color: #2c3e50;
}
.export-footer-right {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Buttons */
.dialog-btn {
    padding: 7px 14px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.12s;
    white-space: nowrap;
}
.dialog-btn-primary {
    background: #27ae60;
    color: #fff;
    border-color: #219a52;
}
.dialog-btn-primary:hover { background: #2ecc71; }
.dialog-btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.dialog-btn-secondary {
    background: #f5f6fa;
    color: #636e72;
    border-color: #dcdcdc;
}
.dialog-btn-secondary:hover { background: #ecf0f1; color: #2c3e50; }

/* Per-plot SVG download button */
.btn-svg {
    display: inline-block;
    padding: 1px 7px;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: #636e72;
    background: #f0f2f5;
    border: 1px solid #dcdcdc;
    border-radius: 3px;
    cursor: pointer;
    vertical-align: middle;
    letter-spacing: 0.3px;
    transition: all 0.12s;
}
.btn-svg:hover {
    background: #e0e4e8;
    color: #2c3e50;
    border-color: #aaa;
}

/* ===== Reports Tab ===== */
#tab-content-reports.active {
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
}
.report-toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid #e8e8e8;
    background: #f8f9fa;
    flex-shrink: 0;
    flex-wrap: wrap;
}
.report-toolbar-title {
    font-size: 14px;
    font-weight: 700;
    color: #1a1a2e;
    margin-right: 4px;
}
.report-actions {
    display: flex;
    gap: 8px;
}
.btn-report {
    padding: 6px 16px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background: #3a7bd5;
    color: #fff;
    transition: background 0.15s;
}
.btn-report:hover { background: #2c65ba; }
.btn-report-pdf { background: #e67e22; }
.btn-report-pdf:hover { background: #ca6d13; }
.report-status {
    font-size: 12px;
    color: #888;
}
.report-iframe {
    flex: 1;
    width: 100%;
    border: none;
    background: white;
}

/* ===== Scrollbar styling ===== */
#domain-panel::-webkit-scrollbar,
#tools-panel::-webkit-scrollbar,
#dsm-container::-webkit-scrollbar,
main::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
#domain-panel::-webkit-scrollbar-thumb,
#tools-panel::-webkit-scrollbar-thumb,
#dsm-container::-webkit-scrollbar-thumb,
main::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 3px;
}
#tools-panel::-webkit-scrollbar-thumb {
    background: #4a6a8a;
}
#domain-panel::-webkit-scrollbar-track,
#tools-panel::-webkit-scrollbar-track,
#dsm-container::-webkit-scrollbar-track,
main::-webkit-scrollbar-track {
    background: transparent;
}
