/* ============================================
   OpenQristal — Academic Scientific Interface
   Inspired by LaTeX typesetting and
   the utilitarian precision of Fortran output.
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Crimson+Pro:ital,wght@0,400;0,500;0,600;0,700;1,400&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
    /* — Paper & surface — */
    --bg-primary: #f5f3ef;
    --bg-secondary: #eae7e1;
    --bg-tertiary: #e2dfd8;
    --bg-card: #ffffff;
    --bg-input: #ffffff;
    --bg-hover: #edebe6;

    /* — Borders — */
    --border-primary: #c4bfb6;
    --border-secondary: #d6d1c9;
    --border-accent: #1a365d;

    /* — Text — */
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-tertiary: #7a7a7a;
    --text-accent: #1a365d;

    /* — Accents (muted, academic) — */
    --accent-blue: #1a365d;
    --accent-blue-dim: #2c5282;
    --accent-green: #276749;
    --accent-green-dim: #2f855a;
    --accent-purple: #553c7b;
    --accent-orange: #9c4221;
    --accent-red: #9b2c2c;
    --accent-cyan: #285e61;
    --accent-pink: #97266d;
    --accent-yellow: #975a16;

    /* — Chart colors (publication-safe) — */
    --chart-1: #1a365d;
    --chart-2: #9b2c2c;
    --chart-3: #276749;
    --chart-4: #9c4221;
    --chart-5: #553c7b;
    --chart-6: #285e61;

    /* — Spacing — */
    --space-xs: 5px;
    --space-sm: 10px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-xxl: 48px;

    /* — Radius (soft, rounded) — */
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;

    /* — Shadows (subtle, soft) — */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.10);
    --shadow-glow: none;

    /* — Typography — */
    --font-serif: 'Crimson Pro', 'Cambria', 'Georgia', 'Times New Roman', serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
    --font-mono: 'JetBrains Mono', 'Consolas', 'Monaco', monospace;

    /* — Layout — */
    --navbar-height: 56px;
}

/* ============ RESET & BASE ============ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: auto;
    -moz-osx-font-smoothing: auto;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow-x: hidden;
    min-height: 100vh;
}

/* Scrollbar — subtle, thin */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: var(--bg-secondary); }
::-webkit-scrollbar-thumb { background: var(--border-primary); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ============ NAVIGATION ============ */
#navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--navbar-height);
    background: var(--accent-blue);
    border-bottom: 2px solid #0f2440;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-lg);
    z-index: 1000;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.nav-logo {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 1.3rem;
    color: #ffffff;
    letter-spacing: -0.5px;
}

.logo-accent {
    font-weight: 400;
    color: #a0c4e8;
}

.nav-title {
    font-family: var(--font-serif);
    font-weight: 600;
    font-size: 1.1rem;
    color: #ffffff;
    white-space: nowrap;
    letter-spacing: 0.2px;
}

.nav-subtitle {
    color: #8baac8;
    font-size: 0.72rem;
    white-space: nowrap;
    display: none;
    font-family: var(--font-sans);
}

@media (min-width: 1200px) {
    .nav-subtitle { display: inline; }
}

/* Right side of navbar */
.nav-right {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

/* Navigation context (shown in calculation workspace) */
.nav-context {
    flex: 1;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 0 var(--space-lg);
    min-width: 0;
}
.nav-back-btn {
    border: none;
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-family: var(--font-sans);
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s;
}
.nav-back-btn:hover {
    background: rgba(255,255,255,0.2);
}
.nav-calc-name {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: rgba(255,255,255,0.9);
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* ============ MAIN CONTENT ============ */
#main-content {
    margin-top: var(--navbar-height);
}

.section {
    display: none;
}

.section.active {
    display: block;
}

/* No fadeIn animation — instant, professional */
@keyframes fadeIn {
    from { opacity: 1; }
    to { opacity: 1; }
}

/* ============ CALCULATION WORKSPACE ============ */
.calc-workspace {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
}

.calc-sidebar {
    width: 210px;
    flex-shrink: 0;
    background: var(--bg-card);
    border-right: 1px solid var(--border-primary);
    padding: var(--space-md) 0;
    position: sticky;
    top: var(--navbar-height);
    height: calc(100vh - var(--navbar-height));
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.sidebar-section {
    padding: 0 var(--space-sm);
}

.sidebar-label {
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-tertiary);
    padding: var(--space-xs) var(--space-sm);
    margin-bottom: 2px;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-secondary);
    margin: var(--space-sm) var(--space-md);
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px var(--space-sm);
    border: none;
    background: none;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    text-align: left;
    transition: background 0.12s, color 0.12s;
}

.sidebar-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sidebar-item.active {
    background: var(--accent-blue);
    color: #ffffff;
    font-weight: 600;
}

.sidebar-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    font-size: 0.68rem;
    font-weight: 700;
    font-family: var(--font-mono);
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.sidebar-item.active .sidebar-num {
    background: rgba(255,255,255,0.25);
    color: #ffffff;
}

/* Pipeline step states in sidebar */
.sidebar-item.wf-done .sidebar-num {
    background: var(--accent-green);
    color: #ffffff;
}
.sidebar-item.wf-done {
    color: var(--accent-green);
}

.calc-content {
    flex: 1;
    min-width: 0;
    padding: var(--space-lg) var(--space-xl);
    max-width: 1200px;
}

/* When on dashboard, sections inside calc-content are hidden */
.calc-content .section {
    display: none;
}
.calc-content .section.active {
    display: block;
}

/* sidebar mobile handled in main responsive block */

.section-header {
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--accent-blue);
}

.section-header h1 {
    font-family: var(--font-serif);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: 2px;
    letter-spacing: -0.2px;
}

.section-desc {
    color: var(--text-secondary);
    font-size: 0.88rem;
    font-style: italic;
    font-family: var(--font-serif);
}

/* ============ DASHBOARD — CALCULATION MANAGER ============ */

#section-dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-xxl);
}

/* Hero Banner */
.dash-hero {
    background: var(--accent-blue);
    border-radius: var(--radius-lg);
    padding: var(--space-xxl) var(--space-xxl);
    margin-bottom: var(--space-xl);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-xl);
    flex-wrap: wrap;
}

.dash-hero-left {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.dash-hero-brand {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.dash-hero-logo {
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 2.4rem;
    color: #ffffff;
    letter-spacing: -1px;
    line-height: 1;
}

.dash-hero-logo .logo-accent {
    font-weight: 400;
    color: #a0c4e8;
}

.dash-hero-title {
    font-family: var(--font-serif);
    font-size: 1.7rem;
    font-weight: 600;
    color: #ffffff;
    margin: 0;
    line-height: 1.2;
}

.dash-hero-subtitle {
    font-family: var(--font-sans);
    font-size: 0.92rem;
    color: rgba(255,255,255,0.6);
    margin: 0;
    margin-top: 4px;
}

.dash-new-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 30px;
    background: #ffffff;
    color: var(--accent-blue);
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, box-shadow 0.15s;
    width: fit-content;
}

.dash-new-btn:hover {
    background: #f0f4f8;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.dash-hero-stats {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
    flex-shrink: 0;
}

.dash-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 64px;
}

.dash-stat-value {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    color: #ffffff;
    line-height: 1;
}

.dash-stat-label {
    font-size: 0.78rem;
    font-weight: 500;
    color: rgba(255,255,255,0.55);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.dash-stat-divider {
    width: 1px;
    height: 44px;
    background: rgba(255,255,255,0.15);
    flex-shrink: 0;
}

/* Dashboard Sections */
.dash-section {
    margin-bottom: var(--space-xxl);
}

.dash-section-head {
    display: flex;
    align-items: baseline;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    padding-bottom: var(--space-sm);
    border-bottom: 2px solid var(--accent-blue);
    flex-wrap: wrap;
}

.dash-section-title {
    font-family: var(--font-serif);
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin: 0;
    flex-shrink: 0;
}

.dash-section-desc {
    font-size: 0.9rem;
    color: var(--text-tertiary);
    font-style: italic;
    font-family: var(--font-serif);
}

.dash-section-count {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-tertiary);
    margin-left: auto;
}

/* Quick Start Material Chips */
.dash-quick-grid {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
}

.dash-quick-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
    font-family: var(--font-sans);
}

.dash-quick-chip:hover {
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-sm);
    background: #f0f4f8;
}

.dash-chip-sym {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-blue);
    min-width: 36px;
}

.dash-chip-name {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

/* Empty state */
.calc-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-xxl) var(--space-lg);
    background: var(--bg-card);
    border: 2px dashed var(--border-secondary);
    border-radius: var(--radius-lg);
    text-align: center;
}

.calc-empty-icon {
    color: var(--border-primary);
}

.calc-empty-text {
    color: var(--text-tertiary);
    font-size: 0.95rem;
    max-width: 400px;
}

/* Calculation cards grid */
.calc-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-lg);
}

/* Individual calculation card */
.calc-card {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: relative;
}

.calc-card:hover {
    border-color: var(--accent-blue);
    box-shadow: var(--shadow-md);
}

.calc-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-sm);
}

.calc-card-name {
    font-family: var(--font-mono);
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.3;
    word-break: break-word;
}

.calc-card-delete {
    border: none;
    background: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px;
    border-radius: var(--radius-sm);
    line-height: 1;
    font-size: 1.1rem;
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.calc-card-delete:hover {
    color: var(--accent-red);
    background: rgba(155, 44, 44, 0.08);
}

.calc-card-material {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.calc-card-material strong {
    color: var(--text-primary);
}

/* Mini pipeline inside each card */
.calc-card-pipeline {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-top: 4px;
}

.calc-card-pip {
    flex: 1;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-tertiary);
    transition: background 0.25s;
}

.calc-card-pip.done {
    background: var(--accent-green);
}

.calc-card-pip.active {
    background: var(--accent-blue);
}

.calc-card-step-label {
    font-size: 0.78rem;
    font-family: var(--font-mono);
    color: var(--text-tertiary);
}

.calc-card-step-label strong {
    color: var(--accent-blue);
    font-weight: 600;
}

.calc-card-date {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    margin-top: auto;
    padding-top: 6px;
    border-top: 1px solid var(--border-secondary);
}

/* Active calculation highlight */
.calc-card--active {
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 2px rgba(26, 54, 93, 0.12);
}

/* Material Database Browser */
.dash-mat-search {
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 8px 14px;
    font-size: 0.9rem;
    font-family: var(--font-sans);
    color: var(--text-primary);
    width: 240px;
    margin-left: auto;
    flex-shrink: 0;
}

.dash-mat-search:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px var(--accent-blue);
}

.dash-mat-browser {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.dash-mat-category {
    background: var(--bg-card);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.dash-mat-cat-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 14px var(--space-lg);
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    background: none;
    border: none;
    width: 100%;
    font-family: var(--font-sans);
    text-align: left;
    transition: background 0.12s;
}

.dash-mat-cat-header:hover {
    background: var(--bg-hover);
}

.dash-mat-cat-chevron {
    transition: transform 0.2s;
    flex-shrink: 0;
    color: var(--text-tertiary);
}

.dash-mat-category.open .dash-mat-cat-chevron {
    transform: rotate(90deg);
}

.dash-mat-cat-count {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    color: var(--text-tertiary);
    font-weight: 400;
    margin-left: auto;
}

.dash-mat-cat-body {
    display: none;
    padding: 0 var(--space-lg) var(--space-lg);
}

.dash-mat-category.open .dash-mat-cat-body {
    display: block;
}

.dash-mat-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.dash-mat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border: 1px solid var(--border-secondary);
    border-radius: 20px;
    background: var(--bg-primary);
    cursor: pointer;
    transition: border-color 0.12s, background 0.12s;
    font-size: 0.88rem;
    color: var(--text-secondary);
    font-family: var(--font-sans);
}

.dash-mat-pill:hover {
    border-color: var(--accent-blue);
    background: #f0f4f8;
    color: var(--accent-blue);
}

.dash-mat-pill-id {
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.88rem;
}

.dash-mat-pill:hover .dash-mat-pill-id {
    color: var(--accent-blue);
}

/* Session Log Toggle */
.dash-log-section {
    margin-bottom: 0;
}

.dash-log-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) 0;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    transition: color 0.15s;
}

.dash-log-toggle:hover {
    color: var(--text-secondary);
}

.dash-log-chevron {
    transition: transform 0.2s;
}

.dash-log-toggle.open .dash-log-chevron {
    transform: rotate(90deg);
}

.dash-log-body {
    margin-top: var(--space-sm);
}

.dash-log-body .log-output {
    max-height: 200px;
    min-height: 80px;
    font-size: 0.82rem;
}

@media (max-width: 768px) {
    .dash-hero {
        flex-direction: column;
        align-items: flex-start;
        padding: var(--space-lg);
    }
    .dash-hero-stats {
        width: 100%;
        justify-content: space-between;
    }
    .dash-mat-search {
        width: 100%;
    }
    .dash-section-head {
        flex-direction: column;
        gap: var(--space-xs);
    }
    .calc-grid {
        grid-template-columns: 1fr;
    }
}

/* ============ PANEL LAYOUT ============ */
.panel-layout {
    display: grid;
    grid-template-columns: 270px 1fr;
    gap: var(--space-lg);
    align-items: start;
}

@media (max-width: 900px) {
    .panel-layout {
        grid-template-columns: 1fr;
    }
}

.controls-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    position: sticky;
    top: calc(var(--navbar-height) + var(--space-lg));
}

.results-panel {
    min-height: 400px;
}

/* ============ CONTROLS ============ */
.control-group {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.control-label {
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

.control-select,
.control-input {
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    width: 100%;
}

.control-select:focus,
.control-input:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px var(--accent-blue);
}

.control-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 10 10'%3E%3Cpath fill='%234a4a4a' d='M5 7L1 3h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    padding-right: 26px;
}

.control-row {
    display: flex;
    gap: var(--space-sm);
    align-items: end;
}

.range-separator {
    color: var(--text-tertiary);
    padding: 6px 3px;
    flex-shrink: 0;
    font-size: 0.82rem;
}

.control-range {
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
    height: 3px;
    border-radius: 4px;
    background: var(--border-primary);
    outline: none;
    margin-top: 4px;
}

.control-range::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: 2px solid #ffffff;
    box-shadow: 0 0 0 1px var(--border-primary);
}

.control-range::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: 2px solid #ffffff;
}

.range-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-blue);
    text-align: right;
    min-width: 36px;
    font-weight: 500;
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
}

.toggle-label input[type="checkbox"] {
    accent-color: var(--accent-blue);
    width: 14px;
    height: 14px;
}

/* ============ BUTTONS ============ */
.btn-primary {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    padding: 8px 16px;
    background: var(--accent-blue);
    color: #ffffff;
    border: 1px solid #0f2440;
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    letter-spacing: 0.2px;
}

.btn-primary:hover {
    background: var(--accent-blue-dim);
}

.btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    padding: 5px 12px;
    background: var(--bg-card);
    color: var(--text-secondary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
}

.btn-secondary:hover {
    color: var(--text-primary);
    border-color: var(--accent-blue);
    background: var(--bg-hover);
}

.atom-mode-btn.active {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: var(--bg-hover);
    font-weight: 600;
}

.btn-danger {
    padding: 6px 14px;
    background: #fff5f5;
    color: var(--accent-red);
    border: 1px solid var(--accent-red);
    border-radius: var(--radius-sm);
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    margin-top: var(--space-xs);
}

.btn-danger:hover {
    background: #fed7d7;
}

.btn-sm { padding: 4px 10px; font-size: 0.75rem; }

.btn-icon {
    padding: 3px 7px;
    background: none;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
}

.btn-icon:hover {
    color: var(--accent-red);
    border-color: var(--accent-red);
}

.btn-icon-inline {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
}

/* ============ DATA TABLE (publication-quality) ============ */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.data-table th {
    text-align: left;
    padding: 5px 8px;
    color: var(--text-secondary);
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-top: 2px solid var(--text-primary);
    border-bottom: 1px solid var(--text-primary);
}

.data-table td {
    padding: 3px 4px;
}

.data-table input {
    background: var(--bg-input);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    padding: 4px 7px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.82rem;
    width: 100%;
}

.data-table input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.data-table .atom-elem { max-width: 50px; }
.data-table .atom-x,
.data-table .atom-y,
.data-table .atom-z { max-width: 70px; }

.full-width { width: 100%; }

.data-table.full-width td,
.data-table.full-width th {
    padding: 7px 10px;
}

.data-table.full-width td {
    font-family: var(--font-mono);
    font-size: 0.82rem;
}

.data-table.full-width thead th {
    border-top: 2px solid var(--text-primary);
    border-bottom: 1px solid var(--text-primary);
}

.data-table.full-width tbody tr {
    border-bottom: 1px solid var(--border-secondary);
}

.data-table.full-width tbody tr:last-child {
    border-bottom: 2px solid var(--text-primary);
}

.data-table.full-width tbody tr:hover {
    background: #faf9f7;
}

/* ============ PROGRESS ============ */
.progress-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.progress-bar {
    width: 100%;
    height: 3px;
    background: var(--border-secondary);
    border-radius: 4px;
    overflow: hidden;
}

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

.progress-fill.indeterminate {
    width: 30%;
    animation: indeterminate 1.5s infinite ease-in-out;
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

.progress-text {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

/* ============ CHARTS ============ */
.chart-container {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    height: 420px;
    position: relative;
    cursor: pointer;
}

.chart-container::after {
    content: '⛶';
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 1.1rem;
    color: var(--text-tertiary);
    opacity: 0;
    transition: opacity 0.15s;
    pointer-events: none;
    z-index: 2;
}

.chart-container:hover::after {
    opacity: 0.7;
}

.chart-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}

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

.chart-half {
    height: 320px;
}

/* ============ CHART POPUP MODAL ============ */
.chart-popup-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 32px;
}

.chart-popup-overlay.active {
    display: flex;
}

.chart-popup {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: 0 24px 64px rgba(0,0,0,0.25);
    width: 90vw;
    max-width: 1400px;
    height: 82vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chart-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
    flex-shrink: 0;
}

.chart-popup-title {
    font-family: var(--font-serif);
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-accent);
}

.chart-popup-close {
    background: none;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    width: 36px;
    height: 36px;
    font-size: 1.4rem;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.12s, color 0.12s;
    line-height: 1;
}

.chart-popup-close:hover {
    background: var(--accent-red);
    color: #ffffff;
    border-color: var(--accent-red);
}

.chart-popup-body {
    flex: 1;
    padding: 24px;
    min-height: 0;
    position: relative;
}

.chart-popup-body canvas {
    width: 100% !important;
    height: 100% !important;
}

/* ============ 3D VIEWER ============ */
.viewer-container {
    margin-bottom: var(--space-md);
}

.three-viewer {
    background: #f0eee9;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    height: 360px;
    position: relative;
    overflow: hidden;
}

.three-viewer canvas {
    border-radius: var(--radius-md);
}

.viewer-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-tertiary);
    gap: var(--space-sm);
}

.viewer-placeholder svg {
    opacity: 0.2;
}

.viewer-controls {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-xs) 0;
}

/* ============ INFO PANELS (data-sheet style) ============ */
.info-panel {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
}

.info-panel h3 {
    font-family: var(--font-serif);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: var(--space-sm);
    text-transform: none;
    letter-spacing: 0;
    border-bottom: 1px solid var(--border-secondary);
    padding-bottom: var(--space-xs);
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: var(--space-sm);
}

.info-item {
    display: flex;
    flex-direction: column;
    gap: 1px;
}

.info-item-label {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}

.info-item-value {
    font-family: var(--font-mono);
    font-size: 0.92rem;
    font-weight: 500;
    color: var(--text-primary);
}

.info-item-value.accent {
    color: var(--accent-blue);
    font-weight: 600;
}

.info-item-value.green {
    color: var(--accent-green);
    font-weight: 600;
}

/* ============ LOG OUTPUT (terminal feel) ============ */
.log-container {
    background: var(--bg-card);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    margin-bottom: var(--space-md);
}

.log-container h3 {
    font-family: var(--font-serif);
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-bottom: var(--space-sm);
    border-bottom: 1px solid var(--border-secondary);
    padding-bottom: var(--space-xs);
}

.log-output {
    background: #1a1a2e;
    border: 1px solid #2d2d44;
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    color: #b8c0cc;
    max-height: 300px;
    overflow-y: auto;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-all;
}

/* ============ EXPORT BAR ============ */
.export-bar {
    display: flex;
    gap: var(--space-sm);
    justify-content: flex-end;
    padding: var(--space-xs) 0;
}

/* ============ PLACEHOLDERS ============ */
.results-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 300px;
    color: var(--text-tertiary);
    gap: var(--space-sm);
    background: var(--bg-card);
    border: 1px dashed var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-xl);
    text-align: center;
}

.results-placeholder svg {
    opacity: 0.15;
}

.results-placeholder p {
    font-size: 0.88rem;
    max-width: 280px;
    font-style: italic;
    font-family: var(--font-serif);
}

/* ============ TOAST NOTIFICATIONS ============ */
#toast-container {
    position: fixed;
    bottom: var(--space-lg);
    right: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    z-index: 9999;
}

.toast {
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    animation: toastIn 0.2s ease;
    max-width: 380px;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.toast.info {
    background: #ebf5ff;
    border: 1px solid var(--accent-blue);
    color: var(--accent-blue);
}

.toast.success {
    background: #f0fff4;
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
}

.toast.error {
    background: #fff5f5;
    border: 1px solid var(--accent-red);
    color: var(--accent-red);
}

.toast.warning {
    background: #fffff0;
    border: 1px solid var(--accent-yellow);
    color: var(--accent-yellow);
}

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

@keyframes toastOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* ============ LOADING SPINNER ============ */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent-blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============ RESPONSIVE ============ */
@media (max-width: 768px) {
    #navbar {
        padding: 0 var(--space-md);
    }

    .nav-brand .nav-title { display: none; }

    #section-dashboard {
        padding: var(--space-md);
    }

    .calc-workspace {
        flex-direction: column;
    }

    .calc-sidebar {
        width: 100%;
        height: auto;
        position: static;
        flex-direction: row;
        overflow-x: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-primary);
        padding: var(--space-xs) var(--space-sm);
        gap: 2px;
    }

    .sidebar-section {
        display: flex;
        gap: 2px;
        padding: 0;
    }

    .sidebar-label { display: none; }
    .sidebar-divider { display: none; }
    .sidebar-num { display: none; }

    .sidebar-item {
        font-size: 0.72rem;
        padding: 5px 8px;
        white-space: nowrap;
    }

    .calc-content {
        padding: var(--space-md);
    }

    .panel-layout,
    .panel-layout-wide {
        grid-template-columns: 1fr;
    }

    .controls-panel {
        position: static;
    }
}


/* ============ INPUT MODE TABS ============ */
.input-mode-tabs {
    display: flex;
    gap: 0;
    border-bottom: 1px solid var(--border-primary);
    margin-bottom: var(--space-sm);
}

.mode-tab {
    flex: 1;
    padding: 6px 8px;
    border: none;
    background: none;
    color: var(--text-tertiary);
    font-family: var(--font-sans);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    text-align: center;
    border-radius: 0;
    margin-bottom: -1px;
}

.mode-tab:hover {
    color: var(--text-primary);
    background: none;
}

.mode-tab.active {
    color: var(--accent-blue);
    background: none;
    border-bottom-color: var(--accent-blue);
    font-weight: 600;
}

.struct-mode {
    display: none;
}
.struct-mode.active {
    display: block;
}

/* ============ INIT STEPS BAR ============ */
.init-steps-bar {
    display: flex;
    gap: 2px;
    margin-bottom: var(--space-md);
}

.init-step {
    flex: 1;
    padding: 4px 3px;
    text-align: center;
    font-size: 0.68rem;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border: 1px solid transparent;
}

.init-step.active {
    color: var(--accent-blue);
    background: #ebf5ff;
    border-color: var(--accent-blue);
}

.init-step.completed {
    color: var(--accent-green);
    background: #f0fff4;
    border-color: var(--accent-green);
}

.init-step.running {
    color: var(--accent-orange);
    background: #fffaf0;
    border-color: var(--accent-orange);
    animation: pulse 1.5s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* ============ CIF TEXTAREA ============ */
.control-textarea {
    background: var(--bg-input);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    padding: 7px 10px;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    width: 100%;
    resize: vertical;
    line-height: 1.55;
}

.control-textarea:focus {
    outline: none;
    border-color: var(--accent-blue);
    box-shadow: 0 0 0 1px var(--accent-blue);
}

/* ============ WIEN2K LOG OUTPUT ============ */
.oq-log-output .log-ene {
    color: #6fa8dc;
    font-weight: 600;
}
.oq-log-output .log-dis {
    color: #93c47d;
    font-weight: 600;
}
.oq-log-output .log-for {
    color: #e69138;
    font-weight: 600;
}
.oq-log-output .log-lap {
    color: #7a7a8e;
}
.oq-log-output .log-mix {
    color: #b4a7d6;
}
.oq-log-output .log-cor {
    color: #76a5af;
}

/* ============ WARNING BOX ============ */
.warning-box {
    background: #fffff0;
    border: 1px solid var(--accent-yellow);
    border-left: 3px solid var(--accent-yellow);
    border-radius: var(--radius-sm);
    padding: var(--space-sm) var(--space-md);
    color: #744210;
    font-size: 0.82rem;
    margin-top: var(--space-xs);
}

/* ============ SESSION PANEL ============ */
/* (session-panel removed) */

/* ============ WIDER PANEL FOR STRUCTGEN ============ */
.panel-layout-wide {
    grid-template-columns: 310px 1fr;
}

@media (max-width: 900px) {
    .panel-layout-wide {
        grid-template-columns: 1fr;
    }
}

/* ============ WYCKOFF ENTRIES ============ */
.wyckoff-entry {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-bottom: var(--space-xs);
}

.wyckoff-entry .control-input,
.wyckoff-entry .control-select {
    flex-shrink: 0;
}

/* ============ RESPONSIVE UPDATES ============ */
/* ============ EXPORT BUTTON (subtle, small) ============ */
.export-btn {
    padding: 3px 10px;
    font-size: 0.72rem;
    font-weight: 500;
    font-family: var(--font-sans);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    letter-spacing: 0.2px;
}

.export-btn:hover {
    color: var(--accent-blue);
    border-color: var(--accent-blue);
    background: var(--bg-hover);
}

/* ============ COMPARISON GRID (multi-select materials) ============ */
.comparison-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-xs);
    max-height: 280px;
    overflow-y: auto;
    padding: var(--space-xs);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
}

.comparison-grid label {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    font-size: 0.82rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
}

.comparison-grid label:hover {
    background: var(--bg-hover);
}

.comparison-grid input[type="checkbox"] {
    accent-color: var(--accent-blue);
    width: 13px;
    height: 13px;
}

/* ============ DATABASE SEARCH BAR ============ */
.db-search-bar {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* ============ DATABASE RESULTS TABLE ============ */
.db-results-table {
    font-size: 0.82rem;
}

.db-results-table td:last-child {
    width: 60px;
    text-align: center;
}

.db-load-btn {
    padding: 2px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    border: 1px solid var(--accent-blue);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--accent-blue);
    cursor: pointer;
}

.db-load-btn:hover {
    background: var(--accent-blue);
    color: #fff;
}

/* ============ SPIN-DOS CHART ============ */
.spin-dos-chart {
    position: relative;
}

/* ============ LANGUAGE TOGGLE ============ */
.lang-toggle {
    display: flex;
    align-items: center;
    gap: 2px;
    margin-left: auto;
    flex-shrink: 0;
    padding-left: var(--space-md);
    border-left: 1px solid rgba(255,255,255,0.15);
}

.lang-btn {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 3px 8px;
    border: 1px solid rgba(255,255,255,0.25);
    background: transparent;
    color: rgba(255,255,255,0.5);
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: background 0.15s, color 0.15s;
}

.lang-btn:first-child {
    border-radius: 6px 0 0 6px;
}

.lang-btn:last-child {
    border-radius: 0 6px 6px 0;
}

.lang-btn:hover {
    background: rgba(255,255,255,0.1);
    color: rgba(255,255,255,0.8);
}

.lang-btn.active {
    background: rgba(255,255,255,0.2);
    color: #ffffff;
    border-color: rgba(255,255,255,0.4);
}

/* ============ ADVANCED OPTIONS (collapsible) ============ */
.advanced-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: 6px 0;
    border: none;
    background: none;
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-tertiary);
    letter-spacing: 0.3px;
    transition: color 0.15s;
}

.advanced-toggle:hover {
    color: var(--text-secondary);
}

.advanced-toggle .chevron {
    display: inline-block;
    transition: transform 0.2s;
    font-size: 0.7rem;
}

.advanced-toggle.open .chevron {
    transform: rotate(90deg);
}

.advanced-body {
    display: none;
    padding: var(--space-sm) 0;
    border-top: 1px solid var(--border-secondary);
    margin-top: var(--space-xs);
}

.advanced-body.open {
    display: block;
}

.advanced-body .control-group {
    margin-bottom: var(--space-sm);
}

.advanced-body .control-group:last-child {
    margin-bottom: 0;
}

/* ============ NEW PROPERTY SECTIONS ============ */

/* Side-by-side chart layout */
.chart-row {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-md);
}
.chart-row .chart-container {
    flex: 1;
    min-width: 0;
}
@media (max-width: 900px) {
    .chart-row {
        flex-direction: column;
    }
}

/* Stacked charts (thermodynamics) */
.chart-stack .chart-container {
    margin-bottom: var(--space-md);
}
.chart-stack .chart-container:last-child {
    margin-bottom: 0;
}

/* Band alignment diagram (photocatalytic) */
.band-alignment-chart {
    position: relative;
    min-height: 320px;
}

/* Radar chart container (mechanical) */
.radar-chart {
    max-width: 420px;
    margin: 0 auto;
}

/* DOE target comparison table */
.doe-comparison {
    margin-top: var(--space-sm);
}
.doe-comparison td.pass {
    color: var(--accent-green);
    font-weight: 600;
}
.doe-comparison td.fail {
    color: var(--accent-red);
    font-weight: 600;
}

/* Tolerance factor scatter regions */
.tolerance-legend {
    display: flex;
    gap: var(--space-md);
    margin-top: var(--space-xs);
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.tolerance-legend-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 4px;
    vertical-align: middle;
}

/* XRD peak labels */
.xrd-peak-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Stability class badges */
.stability-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
}
.stability-badge.stable {
    background: rgba(39, 103, 73, 0.1);
    color: var(--accent-green);
}
.stability-badge.metastable {
    background: rgba(151, 90, 22, 0.1);
    color: var(--accent-yellow);
}
.stability-badge.unstable {
    background: rgba(155, 44, 44, 0.1);
    color: var(--accent-red);
}

/* Info item color helpers */
.info-item-value.green { color: var(--accent-green); }
.info-item-value.red { color: var(--accent-red); }
.info-item-value.yellow { color: var(--accent-yellow); }

/* (mobile styles consolidated above) */

/* SCF status badges */
.scf-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    padding: 2px 8px;
    border-radius: 3px;
    margin-left: 8px;
    font-family: var(--font-mono);
}
.scf-status-badge .scf-badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    display: inline-block;
}
.scf-status-badge.active {
    background: #e6f4ea;
    color: #1a5c2e;
    border: 1px solid #b7dfc3;
}
.scf-status-badge.active .scf-badge-dot {
    background: #1a7f37;
}
.scf-status-badge.standalone {
    background: #f5f5f5;
    color: #666;
    border: 1px solid #ddd;
}
.scf-status-badge.standalone .scf-badge-dot {
    background: #999;
}
