/* ============ GLOBAL STYLES ============ */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Light Mode Colors */
    --bg-primary: #faf9f7;
    --bg-secondary: #f0ede8;
    --bg-tertiary: #e5e1d9;
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
    
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-tertiary: #64748b;
    
    --accent-primary: #2563eb;
    --accent-secondary: #7c3aed;
    --accent-light: #dbeafe;
    
    --border-color: #e2e8f0;
    --border-subtle: #cbd5e1;
    
    --success-bg: #f0fdf4;
    --success-border: #86efac;
    --success-text: #166534;
    
    --error-bg: #fef2f2;
    --error-border: #fecaca;
    --error-text: #991b1b;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 25px 50px rgba(0, 0, 0, 0.15);
}

body.dark-mode {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-gradient: linear-gradient(135deg, #1e293b 0%, #334155 50%, #1e293b 100%);
    
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-tertiary: #94a3b8;
    
    --accent-primary: #3b82f6;
    --accent-secondary: #a78bfa;
    --accent-light: #1e3a8a;
    
    --border-color: #334155;
    --border-subtle: #475569;
    
    --success-bg: #064e3b;
    --success-border: #10b981;
    --success-text: #86efac;
    
    --error-bg: #7f1d1d;
    --error-border: #f87171;
    --error-text: #fecaca;
    
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 25px 50px rgba(0, 0, 0, 0.5);
}

html, body {
    height: 100%;
    width: 100%;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-gradient);
    min-height: 100vh;
    padding: 10px;
    color: var(--text-primary);
    transition: background 0.3s ease, color 0.3s ease;
}

/* ============ LAYOUT ============ */
.main-wrapper {
    display: flex;
    gap: 12px;
    max-width: 1500px;
    margin: 0 auto;
    height: 100%;
}

.container {
    flex: 1;
    background: var(--bg-primary);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 12px 18px;
    overflow-y: auto;
    transition: all 0.3s ease;
    position: relative;
}

.container::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary), #06b6d4, var(--accent-primary));
    background-size: 200% 100%;
    border-radius: 16px 16px 0 0;
    animation: accentShimmer 5s linear infinite;
    pointer-events: none;
}

.info-sidebar {
    width: 240px;
    background: var(--bg-primary);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 16px 18px;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.info-toggle {
    position: fixed;
    bottom: 32px;
    right: 32px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    cursor: pointer;
    font-size: 24px;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    z-index: 999;
    transition: all 0.3s ease;
}

.info-toggle:hover {
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

/* Collapsed via the close button: hide the panel, surface the toggle */
.info-sidebar.collapsed {
    display: none;
}

body.sidebar-collapsed .info-toggle {
    display: flex;
}

/* ============ HEADER ============ */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    flex-wrap: wrap;
    gap: 12px;
}

.header-title {
    flex: 1;
    min-width: 300px;
}

@keyframes gradientShift {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

@keyframes accentShimmer {
    0%   { background-position: 0% 0%; }
    100% { background-position: 200% 0%; }
}

h1 {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.45em;
    font-weight: 800;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.logo-mark {
    width: 1.5em;
    height: 1.5em;
    flex-shrink: 0;
    border-radius: 7px;
}

.logo-text {
    background: linear-gradient(270deg, var(--accent-primary), var(--accent-secondary), #06b6d4, var(--accent-primary));
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientShift 8s ease infinite;
}

.subtitle {
    color: var(--text-tertiary);
    font-size: 0.8em;
    font-weight: 400;
    line-height: 1.5;
}

.header-controls {
    display: flex;
    gap: 12px;
    align-items: center;
}

.mode-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 7px 13px;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.82em;
    font-weight: 600;
    color: var(--text-secondary);
    transition: border-color 0.2s ease, color 0.2s ease;
    text-transform: none;
    letter-spacing: 0;
    position: static;
    white-space: nowrap;
}

.mode-toggle::before {
    display: none;
}

.mode-toggle::after {
    display: none;
}

.mode-toggle:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: none;
    box-shadow: none;
}

/* ============ CONTENT WRAPPER ============ */
.content-wrapper {
    display: grid;
    grid-template-columns: 1.15fr 1fr;
    gap: 16px;
    margin-bottom: 6px;
}

.section {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

/* ============ SECTION TITLES ============ */
.section-title {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::before {
    content: '';
    width: 4px;
    height: 20px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 3px;
    flex-shrink: 0;
}

/* ============ TABS ============ */
.tab-buttons {
    display: flex;
    gap: 6px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 10px;
}

.tab-btn {
    flex: 1;
    padding: 6px 10px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95em;
    transition: all 0.25s ease;
    font-family: inherit;
    position: relative;
    overflow: hidden;
}

.tab-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: -1;
}

.tab-btn:hover {
    color: var(--text-primary);
    transform: translateY(-2px);
}

.tab-btn.active {
    background: var(--bg-primary);
    color: var(--accent-primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.2);
    font-weight: 700;
}

.tab-btn.active::before {
    opacity: 0.08;
}

.tab-content {
    display: none;
    animation: slideIn 0.25s ease;
}

.tab-content.active {
    display: block;
}

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

/* ============ FORM INPUTS ============ */
.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-group label {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.88em;
    text-transform: capitalize;
}

.input-group input,
.input-group textarea {
    padding: 6px 10px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.92em;
    font-family: 'Plus Jakarta Sans', sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.25s ease;
}

.input-group input:focus,
.input-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    background: var(--bg-primary);
    box-shadow: 0 0 0 4px var(--accent-light);
}

.input-group textarea {
    resize: vertical;
    min-height: 70px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.86em;
    line-height: 1.5;
}

/* ============ THRESHOLD CONTROL ============ */
.threshold-control {
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--bg-tertiary);
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.threshold-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.threshold-display label {
    font-weight: 700;
    color: var(--text-secondary);
    font-size: 0.95em;
}

.threshold-value {
    font-size: 1.5em;
    font-weight: 800;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    font-family: 'JetBrains Mono', monospace;
    min-width: 60px;
    text-align: right;
}

input[type="range"] {
    width: 100%;
    height: 8px;
    border-radius: 4px;
    background: var(--border-color);
    outline: none;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.4), 0 0 0 4px var(--accent-light);
    transition: all 0.2s ease;
}

input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 4px 20px rgba(37, 99, 235, 0.6), 0 0 0 5px var(--accent-light);
    transform: scale(1.15);
}

input[type="range"]::-moz-range-thumb {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    cursor: pointer;
    border: none;
    box-shadow: 0 2px 12px rgba(37, 99, 235, 0.4), 0 0 0 4px var(--accent-light);
}

/* ============ CLASS LABELS ============ */
/* Shared left-panel control blocks used by Binary and Multi-class */
.config-section {
    margin-top: 16px;
}

.config-section + .config-section {
    margin-top: 18px;
}

.config-title {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-tertiary);
    margin: 0 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.config-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.config-row .input-group input {
    padding: 7px 10px;
    font-size: 0.9em;
}

.config-hint {
    font-size: 0.78em;
    color: var(--text-tertiary);
    line-height: 1.5;
    margin-top: 8px;
    font-style: italic;
}

@media (max-width: 640px) {
    .config-row {
        grid-template-columns: 1fr;
    }
}

/* ============ CONFUSION MATRIX ============ */
.matrix-container {
    display: flex;
    justify-content: center;
    overflow-x: auto;
    margin: 6px 0;
}

.confusion-matrix {
    display: inline-grid;
    grid-template-columns: 140px 120px 120px 120px;
    grid-template-rows: auto auto auto auto;
    gap: 2px;
    background: var(--border-color);
    padding: 2px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.matrix-cell {
    background: var(--bg-secondary);
    padding: 9px 12px;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    min-height: 56px;
    font-weight: 600;
    transition: all 0.2s ease;
}

.matrix-cell.header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-weight: 700;
    font-size: 0.8em;
}

.matrix-cell.label {
    background: linear-gradient(135deg, #1e40af, #6d28d9);
    color: white;
    font-weight: 700;
    text-align: left;
    padding-left: 14px;
    font-size: 0.8em;
}

.matrix-cell.tp,
.matrix-cell.tn {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #15803d;
}

.matrix-cell.fp,
.matrix-cell.fn {
    background: linear-gradient(135deg, #fed7aa, #fcd34d);
    color: #b45309;
}

body.dark-mode .matrix-cell.tp,
body.dark-mode .matrix-cell.tn {
    background: linear-gradient(135deg, #064e3b, #0f766e);
    color: #86efac;
}

body.dark-mode .matrix-cell.fp,
body.dark-mode .matrix-cell.fn {
    background: linear-gradient(135deg, #7c2d12, #92400e);
    color: #fbbf24;
}

/* Magnitude shading: overlay intensity scales with cell value */
.matrix-cell.tp,
.matrix-cell.tn,
.matrix-cell.fp,
.matrix-cell.fn {
    position: relative;
    overflow: hidden;
}

.matrix-cell.tp::after,
.matrix-cell.tn::after,
.matrix-cell.fp::after,
.matrix-cell.fn::after {
    content: '';
    position: absolute;
    inset: 0;
    opacity: var(--cell-intensity, 0);
    transition: opacity 0.45s ease;
    pointer-events: none;
}

.matrix-cell.tp::after,
.matrix-cell.tn::after {
    background: linear-gradient(135deg, #22c55e, #16a34a);
}

.matrix-cell.fp::after,
.matrix-cell.fn::after {
    background: linear-gradient(135deg, #fb923c, #ea580c);
}

.matrix-cell .cell-value,
.matrix-cell .cell-label {
    position: relative;
    z-index: 1;
}

.matrix-cell.cell-changed {
    animation: cellPulse 0.5s ease;
}

@keyframes cellPulse {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.07); box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.45); }
    100% { transform: scale(1); }
}

.cell-value {
    font-size: 1.25em;
    font-weight: 800;
    color: inherit;
    font-family: 'JetBrains Mono', monospace;
}

.cell-input {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 100px;
    border: none;
    background: transparent;
    text-align: center;
    color: inherit;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.25em;
    font-weight: 800;
    padding: 0;
    margin: 0;
    outline: none;
    -moz-appearance: textfield;
    appearance: textfield;
    cursor: text;
}

.cell-input::-webkit-inner-spin-button,
.cell-input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.cell-input:focus {
    outline: 2px solid currentColor;
    outline-offset: 2px;
    border-radius: 4px;
}

.cell-label {
    font-size: 0.72em;
    color: inherit;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 700;
    opacity: 0.9;
}

/* ============ METRICS GRID ============ */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-top: 28px;
}

.metric-card {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    padding: 8px 12px;
    border-radius: 10px;
    text-align: center;
    transition: all 0.3s ease;
    cursor: help;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: -1;
}

.metric-card:hover {
    transform: translateY(-6px);
    border-color: var(--accent-primary);
    box-shadow: 0 12px 32px rgba(37, 99, 235, 0.2);
}

.metric-card:hover::before {
    opacity: 0.05;
}

/* Family accent bar: keeps interleaved metric families readable */
.metric-card.fam-ratio::after,
.metric-card.fam-complement::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
}

.metric-card.fam-ratio::after {
    background: linear-gradient(90deg, #7c3aed, #a855f7);
}

.metric-card.fam-complement::after {
    background: linear-gradient(90deg, #0891b2, #06b6d4);
}

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

.metric-name {
    font-size: 0.78em;
    color: var(--text-tertiary);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    text-align: left;
}

.metric-info-btn {
    width: 15px;
    height: 15px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 0.68em;
    font-weight: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font-style: italic;
    font-family: Georgia, 'Times New Roman', serif;
    transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
    flex-shrink: 0;
    text-transform: none;
    letter-spacing: 0;
    line-height: 1;
    box-shadow: none;
}

.metric-info-btn::before {
    display: none;
}

.metric-info-btn:active {
    transform: none;
}

.metric-info-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    transform: none;
    box-shadow: none;
}

.metric-value {
    font-size: 1.3em;
    font-weight: 800;
    color: var(--accent-primary);
    font-family: 'JetBrains Mono', monospace;
    margin-bottom: 3px;
}

.metric-formula {
    font-size: 0.7em;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.5;
}

.metric-aliases {
    font-size: 0.66em;
    color: var(--text-tertiary);
    font-style: italic;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px dashed var(--border-subtle);
    letter-spacing: 0.2px;
    line-height: 1.4;
}

.metric-ci {
    font-size: 0.62em;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
    margin-top: 1px;
    letter-spacing: 0.2px;
    line-height: 1.3;
}

.metric-ci:empty {
    display: none;
}

.metric-delta {
    font-size: 0.72em;
    font-weight: 700;
    margin-top: 2px;
    letter-spacing: 0.3px;
    font-family: 'JetBrains Mono', monospace;
    line-height: 1.3;
}

.metric-delta:empty {
    display: none;
}

.metric-delta.delta-pos { color: #16a34a; }
.metric-delta.delta-neg { color: #dc2626; }
.metric-delta.delta-neu { color: var(--text-tertiary); }

body.dark-mode .metric-delta.delta-pos { color: #86efac; }
body.dark-mode .metric-delta.delta-neg { color: #fca5a5; }

.toolbar-btn.active {
    background: var(--accent-light);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

/* ============ MULTI-CLASS ============ */
#mc-input-grid-wrap { display: none; }
#mc-metrics-panel { display: none; margin-top: 10px; }

body.mc-active .matrix-container,
body.mc-active .metrics-panel,
body.mc-active #curves-section {
    display: none !important;
}

body.mc-active #mc-input-grid-wrap { display: block; }
body.mc-active #mc-metrics-panel { display: block; }

.mc-matrix {
    display: inline-grid;
    gap: 2px;
    background: var(--border-color);
    padding: 2px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.mc-cell {
    background: var(--bg-secondary);
    padding: 6px 8px;
    min-height: 36px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.85em;
    font-family: 'JetBrains Mono', monospace;
}

.mc-cell.empty {
    background: transparent;
}

.mc-cell.mc-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-weight: 700;
    font-size: 0.74em;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.mc-cell.mc-row-label {
    background: linear-gradient(135deg, #1e40af, #6d28d9);
    color: white;
    font-weight: 700;
    font-size: 0.74em;
    font-family: 'Plus Jakarta Sans', sans-serif;
    padding-left: 10px;
    justify-content: flex-start;
}

.mc-cell.mc-diag {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #15803d;
}

.mc-cell.mc-off {
    background: linear-gradient(135deg, #fed7aa, #fcd34d);
    color: #b45309;
}

body.dark-mode .mc-cell.mc-diag {
    background: linear-gradient(135deg, #064e3b, #0f766e);
    color: #86efac;
}

body.dark-mode .mc-cell.mc-off {
    background: linear-gradient(135deg, #7c2d12, #92400e);
    color: #fbbf24;
}

/* ---- Input grid (editable NxN) ---- */
#mc-input-grid-wrap {
    margin: 8px 0 6px;
    overflow-x: auto;
}

.mc-input-grid-label {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.mc-grid-hint {
    font-weight: 400;
    color: var(--text-tertiary);
    text-transform: none;
    letter-spacing: 0;
}

#mc-input-grid {
    display: grid;
    gap: 2px;
    background: var(--border-color);
    padding: 2px;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
    width: fit-content;
    max-width: 100%;
    overflow-x: auto;
}

.mc-ig-corner {
    background: var(--bg-secondary);
    min-width: 60px;
}

.mc-ig-col-header {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    font-weight: 700;
    font-size: 0.8em;
    font-family: 'Plus Jakarta Sans', sans-serif;
    padding: 8px 6px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
}

.mc-ig-row-label {
    background: linear-gradient(135deg, #1e40af, #6d28d9);
    color: white;
    font-weight: 700;
    font-size: 0.8em;
    font-family: 'Plus Jakarta Sans', sans-serif;
    padding: 8px 12px;
    text-align: left;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mc-ig-cell {
    overflow: hidden;
    min-width: 60px;
}

/* Read-only totals row / column — neutral cells like the binary matrix totals */
.mc-ig-total {
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 800;
    font-size: 1em;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 56px;
    padding: 8px 6px;
}

.mc-ig-grand-total {
    font-weight: 800;
    color: var(--accent-primary);
}

.mc-ig-total-header,
.mc-ig-total-label {
    background: linear-gradient(135deg, #475569, #1e293b);
}

body.dark-mode .mc-ig-total-header,
body.dark-mode .mc-ig-total-label {
    background: linear-gradient(135deg, #1e293b, #0f172a);
}

body.dark-mode .mc-ig-total {
    background: var(--bg-tertiary);
}

.mc-ig-cell input {
    width: 100%;
    height: 100%;
    min-height: 56px;
    border: none;
    background: transparent;
    text-align: center;
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.05em;
    font-weight: 800;
    cursor: text;
    outline: none;
    padding: 0 6px;
    color: inherit;
    box-sizing: border-box;
    -moz-appearance: textfield;
    appearance: textfield;
}

.mc-ig-cell input::-webkit-inner-spin-button,
.mc-ig-cell input::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.mc-ig-cell input:focus {
    outline: 2px solid currentColor;
    outline-offset: -3px;
    border-radius: 4px;
}

.mc-ig-diag {
    background: linear-gradient(135deg, #dcfce7, #bbf7d0);
    color: #15803d;
}

.mc-ig-diag input { color: #15803d; }

.mc-ig-off {
    background: linear-gradient(135deg, #fed7aa, #fcd34d);
    color: #b45309;
}

.mc-ig-off input { color: #b45309; }

body.dark-mode .mc-ig-diag {
    background: linear-gradient(135deg, #064e3b, #0f766e);
    color: #86efac;
}
body.dark-mode .mc-ig-diag input { color: #86efac; }

body.dark-mode .mc-ig-off {
    background: linear-gradient(135deg, #7c2d12, #92400e);
    color: #fbbf24;
}
body.dark-mode .mc-ig-off input { color: #fbbf24; }

.mc-overall-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin: 10px 0 14px;
}

.mc-stat {
    background: var(--bg-secondary);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    padding: 8px 12px;
}

.mc-stat-label {
    font-size: 0.7em;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.mc-stat-value {
    font-size: 1.25em;
    font-weight: 800;
    color: var(--accent-primary);
    font-family: 'JetBrains Mono', monospace;
    margin-top: 2px;
}

.mc-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85em;
    margin-top: 6px;
}

.mc-table th,
.mc-table td {
    padding: 6px 10px;
    text-align: right;
    border-bottom: 1px solid var(--border-color);
    font-family: 'JetBrains Mono', monospace;
}

.mc-table th:first-child,
.mc-table td:first-child {
    text-align: left;
    font-family: 'Plus Jakarta Sans', sans-serif;
}

.mc-table th {
    color: var(--text-tertiary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.72em;
    letter-spacing: 0.4px;
}

.mc-table tfoot td {
    border-top: 2px solid var(--border-color);
    border-bottom: none;
    font-weight: 700;
    color: var(--text-primary);
}

.mc-table tfoot td:first-child {
    color: var(--accent-primary);
    text-transform: uppercase;
    font-size: 0.78em;
    letter-spacing: 0.3px;
}

@media (max-width: 768px) {
    .mc-overall-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ============ EMBED MODE ============ */
body.embed-mode {
    padding: 0;
    background: var(--bg-primary);
}

body.embed-mode .main-wrapper {
    gap: 0;
    max-width: none;
}

body.embed-mode .container {
    border-radius: 0;
    box-shadow: none;
    padding: 10px 14px;
}

body.embed-mode .container::before {
    display: none;
}

body.embed-mode .header,
body.embed-mode .top-toolbar,
body.embed-mode .info-sidebar,
body.embed-mode .info-toggle,
body.embed-mode .page-footer,
body.embed-mode .disclaimer,
body.embed-mode .definitions-section,
body.embed-mode .feedback-modal {
    display: none !important;
}

body.embed-mode #capture-zone {
    border: none;
    padding: 0;
    margin: 0;
}

/* ============ BASELINE COMPARISON ============ */
.baseline-control {
    margin-top: 12px;
    padding: 12px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.baseline-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
}

.baseline-title {
    font-size: 0.85em;
    font-weight: 700;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

.baseline-status {
    font-size: 0.78em;
    color: var(--text-tertiary);
    font-family: 'JetBrains Mono', monospace;
    font-style: italic;
}

.baseline-status.active {
    color: var(--accent-primary);
    font-style: normal;
    font-weight: 600;
}

.baseline-control .toolbar-btn {
    align-self: flex-start;
    padding: 8px 16px;
    font-size: 0.85em;
}

.baseline-hint {
    font-size: 0.78em;
    color: var(--text-secondary);
    line-height: 1.55;
    font-style: italic;
}

.baseline-hint strong {
    color: var(--text-primary);
    font-style: normal;
}

.baseline-hint .hint-pos {
    color: #16a34a;
    font-weight: 700;
    font-style: normal;
}

.baseline-hint .hint-neg {
    color: #dc2626;
    font-weight: 700;
    font-style: normal;
}

body.dark-mode .baseline-hint .hint-pos { color: #86efac; }
body.dark-mode .baseline-hint .hint-neg { color: #fca5a5; }

/* ============ METRICS PANEL ============ */
.metrics-panel {
    display: grid;
    grid-template-columns: 1.15fr 1px 1fr;
    gap: 16px;
    margin-top: 8px;
}

.metrics-left {
    min-width: 0;
}

.metrics-right {
    min-width: 0;
}

.metrics-separator {
    width: 1px;
    background: var(--border-color);
    align-self: stretch;
    margin: 4px 0;
}

.metrics-grid-2col {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-top: 9px;
}

/* Metric group color theming */
.metrics-left .section-title ~ .section-title::before {
    background: linear-gradient(135deg, #0d9488, #06b6d4);
}

.metrics-right .section-title::before {
    background: linear-gradient(135deg, #7c3aed, #a855f7);
}

/* ============ METRIC TOOLTIP ============ */
#metric-tooltip {
    position: absolute;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 11px 13px;
    max-width: 210px;
    box-shadow: var(--shadow-md);
    z-index: 1000;
    font-size: 0.82em;
    color: var(--text-secondary);
    line-height: 1.5;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

#metric-tooltip.visible {
    opacity: 1;
    pointer-events: auto;
}

.tooltip-more {
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.88em;
    text-decoration: none;
}

.tooltip-more:hover {
    text-decoration: underline;
}

/* ============ CAPTURE TOOLBAR ============ */
.top-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}

.toolbar-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.capture-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toolbar-btn {
    padding: 7px 14px;
    font-size: 0.8em;
    font-weight: 600;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    text-transform: none;
    letter-spacing: 0;
}

.toolbar-btn::before {
    display: none;
}

.toolbar-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-light);
    transform: none;
    box-shadow: none;
}

.toolbar-btn:active {
    transform: scale(0.97);
}


.capture-label {
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.2px;
}

.capture-btns {
    display: flex;
    gap: 6px;
}

.capture-btn {
    padding: 5px 12px;
    font-size: 0.75em;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    text-transform: uppercase;
}

.capture-btn::before {
    display: none;
}

.capture-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-light);
    transform: none;
    box-shadow: none;
}

.capture-btn:active {
    transform: scale(0.97);
}

/* ============ CSV UPLOAD ============ */
.csv-upload {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin: 20px 0 8px;
}

.csv-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 13px 24px;
    font-size: 0.95em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    border: none;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.csv-btn:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 32px rgba(37, 99, 235, 0.5);
}

#predictions .btn-primary {
    margin: 16px 0 12px;
}

.csv-hint {
    font-size: 0.78em;
    color: var(--text-tertiary);
}

.csv-columns {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    margin: 8px 0 4px;
    padding: 10px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
}

.csv-column-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
    flex: 1;
}

.csv-column-field label {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-secondary);
}

.csv-column-field select {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.9em;
}

.threshold-precise {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.threshold-precise label {
    font-size: 0.85em;
    font-weight: 600;
    color: var(--text-secondary);
}

.threshold-precise input[type="number"] {
    width: 110px;
    padding: 6px 8px;
    border-radius: 6px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95em;
}

.threshold-precise-hint {
    font-size: 0.78em;
    color: var(--text-tertiary);
}

/* ============ ROC / PR CURVES ============ */
.curves-panel {
    margin-top: 28px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.curves-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin: 16px 0;
}

.curve-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

.curve-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    width: 100%;
    gap: 12px;
}

.curve-title {
    font-size: 0.92em;
    font-weight: 700;
    color: var(--text-primary);
}

.curve-auc {
    font-size: 0.82em;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-primary);
    background: var(--accent-light);
    padding: 3px 10px;
    border-radius: 6px;
    white-space: nowrap;
}

.curve-canvas {
    max-width: 100%;
    border-radius: 8px;
}

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

/* ============ CAPTURE ZONE ============ */
#capture-zone {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px 18px 14px;
    background: var(--bg-primary);
    margin-bottom: 6px;
}

/* ============ DISCLAIMER ============ */
.disclaimer {
    margin-top: 32px;
    padding: 14px 18px;
    border-radius: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-left: 3px solid var(--border-subtle);
}

.disclaimer p {
    font-size: 0.78em;
    color: var(--text-tertiary);
    line-height: 1.7;
    font-style: italic;
}

/* ============ FOOTER ============ */
.page-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.85em;
    line-height: 1.7;
}

.page-footer .brand {
    font-family: 'Georgia', 'Times New Roman', serif;
    font-style: italic;
    font-size: 1.05em;
    color: var(--text-secondary);
    letter-spacing: 0.3px;
}

.footer-feedback-btn {
    margin-top: 12px;
    padding: 7px 16px;
    font-size: 0.92em;
    font-weight: 600;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
    text-transform: none;
    letter-spacing: 0;
}

.footer-feedback-btn::before {
    display: none;
}

.footer-feedback-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-light);
    transform: none;
    box-shadow: none;
}

/* ============ FEEDBACK MODAL ============ */
.feedback-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.feedback-box {
    background: var(--bg-primary);
    border-radius: 16px;
    box-shadow: var(--shadow-lg);
    padding: 24px;
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.feedback-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.feedback-head h3 {
    font-size: 1.15em;
    color: var(--text-primary);
}

.feedback-close {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.9em;
    padding: 0;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.feedback-close::before {
    display: none;
}

.feedback-close:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    transform: none;
    box-shadow: none;
}

.feedback-intro {
    font-size: 0.88em;
    color: var(--text-tertiary);
    line-height: 1.5;
}

.feedback-box .toolbar-btn {
    align-self: flex-start;
    padding: 9px 18px;
    font-size: 0.88em;
}

/* ============ BUTTONS ============ */
button {
    padding: 13px 24px;
    border: none;
    border-radius: 10px;
    font-size: 0.95em;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.25s ease;
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
}

button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.1);
    opacity: 0;
    transition: opacity 0.25s ease;
}

button:hover::before {
    opacity: 0.2;
}

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

.btn-primary {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
    color: white;
    box-shadow: 0 6px 20px rgba(37, 99, 235, 0.35);
}

.btn-primary:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 32px rgba(37, 99, 235, 0.5);
}

.config-section .presets {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
    margin-top: 0;
}

.config-section .preset-btn {
    width: 100%;
    border-radius: 999px;
    padding: 7px 14px;
    font-size: 0.78em;
}

.presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
}

.preset-btn {
    flex: 0 0 auto;
    padding: 7px 14px;
    background: var(--bg-tertiary);
    border: 2px solid var(--border-color);
    border-radius: 999px;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.2px;
    transition: all 0.25s ease;
    text-transform: capitalize;
}

.preset-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
    background: var(--accent-light);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.2);
}

/* ============ MESSAGES ============ */
.message {
    padding: 13px 16px;
    border-radius: 10px;
    font-size: 0.9em;
    font-weight: 600;
    display: none;
    border: 2px solid;
    margin-top: 12px;
    animation: fadeIn 0.25s ease;
}

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

.error-message {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error-border);
}

.success-message {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-border);
}

.info-box {
    background: var(--accent-light);
    border-left: 4px solid var(--accent-primary);
    padding: 8px 12px;
    border-radius: 8px;
    color: var(--accent-primary);
    font-size: 0.82em;
    margin-top: 6px;
    line-height: 1.5;
}

body.dark-mode .info-box {
    background: var(--accent-light);
    color: var(--text-primary);
    border-color: var(--accent-secondary);
}

/* ============ INFO SIDEBAR ============ */
.info-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--border-color);
}

.info-header h2 {
    font-size: 1.05em;
    margin: 0;
    background: linear-gradient(270deg, var(--accent-primary), var(--accent-secondary), #06b6d4, var(--accent-primary));
    background-size: 300% 300%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
    animation: gradientShift 8s ease infinite;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 24px;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.close-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.info-section {
    margin-bottom: 16px;
}

.info-section h3 {
    font-size: 0.82em;
    color: var(--accent-primary);
    margin-bottom: 7px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.info-section p {
    color: var(--text-secondary);
    font-size: 0.78em;
    line-height: 1.55;
    margin-bottom: 7px;
    font-style: italic;
}

.info-section ul {
    list-style: none;
    padding-left: 0;
}

.info-section li {
    color: var(--text-secondary);
    font-size: 0.78em;
    line-height: 1.55;
    margin-bottom: 5px;
    padding-left: 16px;
    position: relative;
}

.info-section li::before {
    content: '→';
    position: absolute;
    left: 0;
    color: var(--accent-primary);
    font-weight: 700;
}

/* ============ DEFINITIONS SECTION ============ */
.definitions-section {
    margin-top: 60px;
    padding-top: 40px;
    border-top: 2px solid var(--border-color);
}

.definitions-section h2 {
    font-size: 1.8em;
    margin-bottom: 30px;
    color: var(--text-primary);
}

.definition-group {
    margin-bottom: 32px;
}

.definition-group h3 {
    font-size: 1.2em;
    color: var(--accent-primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.definition-item {
    margin-bottom: 20px;
    background: var(--bg-secondary);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
}

.definition-item h4 {
    color: var(--text-primary);
    font-size: 1.05em;
    margin-bottom: 10px;
}

.definition-item p {
    color: var(--text-secondary);
    font-size: 0.95em;
    line-height: 1.6;
    margin-bottom: 8px;
}

.definition-item p:last-child {
    margin-bottom: 0;
}

/* ============ METRIC ↔ DEFINITION LINKING ============ */
.linkable {
    cursor: pointer;
    transition: color 0.18s ease, text-shadow 0.18s ease;
    user-select: none;
}

.linkable:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 3px;
    border-radius: 4px;
}

.metric-name.linkable:hover {
    color: var(--accent-primary);
}

.metric-name.linkable.linkable-down::after {
    content: " ↓";
    font-size: 0.85em;
    opacity: 0;
    transition: opacity 0.18s ease;
    margin-left: 2px;
}

.metric-name.linkable.linkable-down:hover::after {
    opacity: 0.7;
}

.definition-item h4.linkable:hover {
    color: var(--accent-primary);
}

.definition-item h4.linkable.linkable-up::after {
    content: " ↑";
    font-size: 0.85em;
    opacity: 0;
    transition: opacity 0.18s ease;
    margin-left: 4px;
    color: var(--accent-primary);
}

.definition-item h4.linkable.linkable-up:hover::after {
    opacity: 0.85;
}

@keyframes flashHighlight {
    0% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
        background-color: transparent;
    }
    15% {
        box-shadow: 0 0 0 5px rgba(124, 58, 237, 0.55), 0 0 22px 4px rgba(99, 102, 241, 0.35);
        background-color: rgba(124, 58, 237, 0.12);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(99, 102, 241, 0);
        background-color: transparent;
    }
}

.flash-highlight {
    animation: flashHighlight 1.6s ease-out;
    border-radius: 12px;
    position: relative;
    z-index: 1;
}

body.dark-mode .flash-highlight {
    animation-name: flashHighlightDark;
}

@keyframes flashHighlightDark {
    0% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0);
        background-color: transparent;
    }
    15% {
        box-shadow: 0 0 0 5px rgba(167, 139, 250, 0.65), 0 0 24px 6px rgba(59, 130, 246, 0.4);
        background-color: rgba(167, 139, 250, 0.18);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(167, 139, 250, 0);
        background-color: transparent;
    }
}

/* ============ RESPONSIVE DESIGN ============ */
@media (max-width: 1280px) {
    .main-wrapper {
        flex-direction: column;
    }

    .info-sidebar {
        width: 100%;
        order: 2;
        max-height: 300px;
    }

    .container {
        order: 1;
    }

    .info-toggle {
        display: flex;
    }
}

@media (max-width: 1200px) {
    .container {
        padding: 24px 28px;
    }

    .content-wrapper {
        max-width: 100%;
    }

    .confusion-matrix {
        grid-template-columns: 120px 100px 100px 100px;
    }

    .matrix-cell {
        padding: 10px 14px;
        min-height: 54px;
    }

    .cell-value {
        font-size: 1.4em;
    }

    .metrics-grid {
        grid-template-columns: 2fr 1fr;
    }
}

@media (max-width: 1024px) {
    .content-wrapper {
        max-width: 100%;
    }

    .main-wrapper {
        gap: 12px;
    }

    .container {
        padding: 28px;
    }

    h1 {
        font-size: 2.3em;
    }
}

@media (max-width: 768px) {
    .info-toggle {
        display: flex !important;
    }

    .info-sidebar {
        display: none;
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-width: 360px;
        z-index: 1000;
        border-radius: 0;
        border-left: 1px solid var(--border-color);
    }

    .info-sidebar.open {
        display: flex;
        flex-direction: column;
    }

    .header {
        flex-direction: column;
        align-items: flex-start;
    }

    h1 {
        font-size: 2em;
    }

    .confusion-matrix {
        width: 100%;
        max-width: 100%;
        grid-template-columns: minmax(80px, 1.1fr) repeat(3, minmax(0, 1fr));
    }

    .matrix-cell {
        padding: 10px 6px;
        min-height: 58px;
    }

    .cell-value {
        font-size: 1.2em;
    }

    .content-wrapper {
        grid-template-columns: 1fr;
    }

    .metrics-panel {
        grid-template-columns: 1fr;
    }

    .metrics-left {
        padding-bottom: 24px;
    }

    .metrics-right {
        padding-top: 24px;
    }

    .metrics-separator {
        width: 100%;
        height: 1px;
        align-self: auto;
        margin: 0;
    }
}

/* ============ MOBILE POLISH ============ */
html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

@media (max-width: 640px) {
    body {
        padding: 6px;
    }

    .container {
        padding: 14px 14px 18px;
        border-radius: 12px;
        overscroll-behavior: contain;
    }

    h1 {
        font-size: 1.55em;
        flex-wrap: wrap;
    }

    .subtitle {
        font-size: 0.78em;
    }

    .header {
        gap: 6px;
        margin-bottom: 6px;
    }

    .header-controls {
        flex-wrap: wrap;
    }

    .toolbar-actions {
        gap: 6px;
    }

    .toolbar-btn,
    .capture-btn {
        padding: 8px 12px;
        min-height: 36px;
    }

    /* "Save snapshot" label is redundant next to PNG/JPG/PDF chips on phones */
    .capture-label {
        display: none;
    }

    /* Tabs: shrink-to-fit, only scroll horizontally if they truly overflow */
    .tab-buttons {
        overflow-x: auto;
        flex-wrap: nowrap;
        scrollbar-width: none;
    }
    .tab-buttons::-webkit-scrollbar { display: none; }
    .tab-btn {
        flex: 1 1 0;
        min-width: 0;
        padding: 9px 10px;
        font-size: 0.85em;
        white-space: nowrap;
    }

    /* Confusion matrix: fluid width, no horizontal scroll */
    .matrix-container {
        margin: 4px 0;
        overflow-x: visible;
    }
    .confusion-matrix {
        width: 100%;
        max-width: 100%;
        grid-template-columns: minmax(72px, 1.1fr) repeat(3, minmax(0, 1fr));
        gap: 2px;
    }
    .matrix-cell {
        padding: 8px 4px;
        min-height: 54px;
    }
    .matrix-cell.label {
        padding-left: 8px;
        font-size: 0.7em;
    }
    .matrix-cell.header {
        font-size: 0.7em;
    }
    .cell-value {
        font-size: 1.05em;
    }
    .cell-label {
        font-size: 0.65em;
    }

    /* Inputs: comfortable touch targets, prevent iOS focus-zoom (>=16px) */
    .input-group input,
    .input-group textarea,
    .csv-column-field select,
    .threshold-precise input[type="number"],
    .cell-input {
        font-size: 16px;
        padding: 10px 12px;
    }
    .cell-input {
        padding: 4px;
    }
    .input-group textarea {
        min-height: 84px;
    }

    /* Threshold panel: keep value visible on small widths */
    .threshold-value {
        font-size: 1.25em;
    }
    .threshold-precise {
        gap: 8px;
    }
    .threshold-precise input[type="number"] {
        width: 100px;
    }

    /* Threshold slider: bigger touch thumb */
    input[type="range"] {
        height: 10px;
    }
    input[type="range"]::-webkit-slider-thumb {
        width: 26px;
        height: 26px;
    }
    input[type="range"]::-moz-range-thumb {
        width: 26px;
        height: 26px;
    }

    /* Primary actions full-width is the standard mobile pattern */
    .btn-primary,
    .csv-btn {
        width: 100%;
        padding: 14px 20px;
        font-size: 0.9em;
    }
    .csv-upload {
        margin: 14px 0 6px;
    }
    .csv-hint {
        font-size: 0.78em;
    }

    /* Binary inputs + presets keep 2x2 with breathing room */
    .binary-inputs {
        gap: 10px;
    }
    .binary-presets .preset-btn {
        padding: 9px 12px;
        font-size: 0.78em;
    }

    /* Metric cards readable on phones */
    .metric-card {
        padding: 10px 12px;
    }
    .metric-name {
        font-size: 0.8em;
    }
    .metric-value {
        font-size: 1.1em;
    }

    /* Section spacing */
    .metrics-left {
        padding-bottom: 16px;
    }
    .metrics-right {
        padding-top: 16px;
    }
    .curves-grid {
        gap: 16px;
    }

    /* Info sidebar drawer covers full screen on phones */
    .info-sidebar {
        max-width: 100%;
        border-left: none;
    }

    /* Capture zone tighter */
    #capture-zone {
        padding: 10px 12px 12px;
    }
}

/* Stack metric cards single-column on the smallest phones */
@media (max-width: 480px) {
    .metrics-grid-2col {
        grid-template-columns: 1fr;
    }
    h1 {
        font-size: 1.4em;
    }
    .container {
        padding: 12px 12px 16px;
    }
}

@media (max-width: 380px) {
    .confusion-matrix {
        grid-template-columns: minmax(64px, 1fr) repeat(3, minmax(0, 1fr));
    }
    .matrix-cell {
        padding: 6px 2px;
        min-height: 50px;
    }
    .cell-value {
        font-size: 0.95em;
    }
    .matrix-cell.label,
    .matrix-cell.header {
        font-size: 0.65em;
    }
}

/* Honour iOS / Android safe-areas (notch, home indicator) */
@supports (padding: max(0px)) {
    @media (max-width: 640px) {
        body {
            padding-left: max(6px, env(safe-area-inset-left));
            padding-right: max(6px, env(safe-area-inset-right));
            padding-bottom: max(6px, env(safe-area-inset-bottom));
        }
    }
}
