@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
    /* Modern Light */
    --bg: #F8FAFC;
    --bg-soft: #F1F5F9;
    --panel: #FFFFFF;
    --line: #E2E8F0;
    --ink: #0F172A;
    --muted: #64748B;
    --accent: #3B82F6;
    --accent-soft: #2563EB;
    --good: #10B981;
    --warn: #F59E0B;
    --bad: #EF4444;
    --shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.05), 0 8px 10px -6px rgba(15, 23, 42, 0.01);
    --shadow-hover: 0 20px 25px -5px rgba(15, 23, 42, 0.08), 0 8px 10px -6px rgba(15, 23, 42, 0.02);
    --font-heading: 'Inter', system-ui, sans-serif;
    --font-body: 'Inter', system-ui, sans-serif;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --hero-surface: #FFFFFF;
    --panel-highlight: #F8FAFC;
    --wall-block-surface: #FFFFFF;
    --chart-block-surface: #FFFFFF;
    
    /* Layer Visuals */
    --layer-c1: #DBEAFE;
    --layer-c2: #E0E7FF;
    --layer-c3: #E1E1FA;
    --layer-c4: #EDE9FE;
    --layer-c5: #F3E8FF;
    --layer-c6: #FAE8FF;
    
    --viz-temp-line: #EF4444;
    --viz-dew-line: #3B82F6;
    --viz-grid: #E2E8F0;
    --viz-axis: #94A3B8;
    --viz-text: #334155;
    
    --focus-ring: rgba(59, 130, 246, 0.5);
}

body[data-theme="business"] {
    /* Sleek Dark */
    --bg: #0B0F19;
    --bg-soft: #111827;
    --panel: #1F2937;
    --line: #374151;
    --ink: #F9FAFB;
    --muted: #9CA3AF;
    --accent: #60A5FA;
    --accent-soft: #3B82F6;
    --good: #34D399;
    --warn: #FBBF24;
    --bad: #F87171;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.7);
    --hero-surface: #1E293B;
    --panel-highlight: #111827;
    --wall-block-surface: #1E293B;
    --chart-block-surface: #1F2937;

    /* Layer Visuals */
    --layer-c1: #1E3A8A;
    --layer-c2: #312E81;
    --layer-c3: #3B2A63;
    --layer-c4: #4C1D95;
    --layer-c5: #581C87;
    --layer-c6: #701A75;

    --viz-temp-line: #FCA5A5;
    --viz-dew-line: #93C5FD;
    --viz-grid: #374151;
    --viz-axis: #4B5563;
    --viz-text: #E5E7EB;
    
    --focus-ring: rgba(96, 165, 250, 0.5);
}

body[data-theme="builder"] {
    /* High-Visibility Builder */
    --bg: #1A1C1A;
    --bg-soft: #232524;
    --panel: #2C2E2D;
    --line: #424945;
    --ink: #F3F4F6;
    --muted: #A1A1AA;
    --accent: #FACC15; 
    --accent-soft: #EAB308;
    --good: #4ADE80;
    --warn: #FB923C;
    --bad: #F87171;
    --shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
    --hero-surface: #272A29;
    --panel-highlight: #1F2120;
    --wall-block-surface: #272A29;
    --chart-block-surface: #2C2E2D;

    /* Layer Visuals */
    --layer-c1: #424945;
    --layer-c2: #4E5652;
    --layer-c3: #58615C;
    --layer-c4: #66706B;
    --layer-c5: #717C76;
    --layer-c6: #818D86;

    --viz-temp-line: #F87171;
    --viz-dew-line: #38BDF8;
    --viz-grid: #3F4642;
    --viz-axis: #6B7280;
    --viz-text: #E5E7EB;
    
    --focus-ring: rgba(250, 204, 21, 0.5);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--ink);
    font-family: var(--font-body);
    background: var(--bg);
    transition: background-color 0.3s ease, color 0.3s ease;
    line-height: 1.5;
}

/* Subtle background texture */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    background-image:
        radial-gradient(var(--line) 1px, transparent 1px);
    background-size: 32px 32px;
    opacity: 0.3;
    pointer-events: none;
    z-index: -1;
}

/* Layout */
.page-shell {
    width: min(1280px, calc(100% - 32px));
    margin: 0 auto;
    padding: 40px 0 60px;
    animation: fadeIn 0.4s ease-out;
}

.page-shell-wide {
    width: min(1480px, calc(100% - 32px));
}

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

/* Typography */
h1, h2, h3, h4 {
    margin: 0;
    font-family: var(--font-heading);
    font-weight: 700;
    line-height: 1.2;
    color: var(--ink);
    letter-spacing: -0.02em;
}

h1 { font-size: clamp(2rem, 5vw, 3rem); }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }

p {
    color: var(--muted);
    margin: 0 0 1rem;
}

/* Hero Section */
.hero {
    display: grid;
    grid-template-columns: 1fr;
    gap: 24px;
    margin-bottom: 32px;
    padding: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius-xl);
    background: var(--hero-surface);
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
}

@media (min-width: 900px) {
    .hero {
        grid-template-columns: 2fr 1fr;
    }
}

.app-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 24px;
    margin-bottom: 32px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--panel);
    box-shadow: var(--shadow);
}

.app-toolbar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.app-toolbar-brand h1 {
    font-size: 1.25rem;
    margin: 0;
}

.app-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 6px 12px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: var(--bg-soft);
}

.toolbar-group-vertical {
    flex-direction: column;
    align-items: flex-start;
    border-radius: var(--radius-md);
    padding: 12px 16px;
}

.toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}

.toolbar-value,
.toolbar-link {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--ink);
    text-decoration: none;
    transition: color 0.2s ease;
}

.toolbar-link:hover {
    color: var(--accent);
}

.label-with-help {
    display: flex;
    align-items: center;
    gap: 6px;
}

.help-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: transparent;
    border: 1.5px solid var(--muted);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 800;
    cursor: pointer;
    transition: all 0.2s ease;
    padding: 0;
}

.help-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Modals */
.app-modal {
    padding: 0;
    border: none;
    border-radius: var(--radius-xl);
    background: var(--panel);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    max-width: 500px;
    width: 90%;
    color: var(--ink);
}

.app-modal::backdrop {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
}

.app-modal-content {
    display: flex;
    flex-direction: column;
}

.app-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--line);
}

.app-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
}

.app-modal-body {
    padding: 24px;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--muted);
}


.toolbar-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 4px 10px;
    border-radius: 99px;
    background: rgba(59, 130, 246, 0.1);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

body[data-theme="builder"] .toolbar-badge {
    background: rgba(250, 204, 21, 0.1);
    color: var(--accent);
    border: 1px solid rgba(250, 204, 21, 0.2);
}

/* Theme Switcher */
.theme-switcher {
    display: flex;
    gap: 6px;
}
.theme-option {
    padding: 8px 14px;
    border-radius: 99px;
    background: var(--bg-soft);
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.2s ease;
}

.theme-option:hover {
    background: var(--line);
    color: var(--ink);
}

.theme-option.is-active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Grid & Panels */
.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}

@media (min-width: 1024px) {
    .input-page-grid {
        grid-template-columns: minmax(320px, 1fr) minmax(600px, 2fr);
        align-items: start;
    }
}

.results-page-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
    align-items: start;
}

@media (min-width: 1024px) {
    .results-page-layout {
        grid-template-columns: minmax(320px, 1fr) minmax(700px, 2.5fr);
    }
}

.panel {
    border-radius: var(--radius-xl);
    padding: 32px;
    background: var(--panel);
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    transition: box-shadow 0.3s ease;
}

.panel:hover {
    box-shadow: var(--shadow-hover);
}

.section-head {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 24px;
}

@media (min-width: 768px) {
    .section-head.with-actions {
        flex-direction: row;
        align-items: center;
        justify-content: space-between;
    }
}

.section-head p {
    margin: 0;
    max-width: 600px;
}

/* Cards */
.intro-steps { display: grid; gap: 16px; }
.intro-card {
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--bg-soft);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.intro-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}
.intro-card span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    margin-bottom: 16px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.9rem;
}
.intro-card strong {
    display: block;
    margin-bottom: 8px;
    font-size: 1.05rem;
    color: var(--ink);
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
}

.full-width { grid-column: 1 / -1; }

label {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--muted);
}

input, select {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--bg);
    color: var(--ink);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

/* Mode Switch */
.mode-switch {
    display: inline-flex;
    gap: 8px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 99px;
    background: var(--bg-soft);
    margin-bottom: 24px;
}

.mode-option {
    position: relative;
    cursor: pointer;
}

.mode-option input {
    position: absolute; opacity: 0; pointer-events: none;
}

.mode-option span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border-radius: 99px;
    color: var(--muted);
    font-weight: 600;
    font-size: 0.85rem;
    transition: all 0.2s ease;
}

.mode-option input:checked + span {
    background: var(--panel);
    color: var(--ink);
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
body[data-theme="business"] .mode-option input:checked + span {
    background: var(--accent);
    color: #fff;
}

/* Expert Section */
.expert-section {
    display: grid;
    gap: 24px;
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--bg-soft);
    margin-bottom: 24px;
    animation: fadeIn 0.3s ease;
}
.expert-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px;
}
.expert-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 20px;
}
.expert-card {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
    transition: opacity 0.2s ease;
}
.expert-card.is-disabled {
    opacity: 0.5;
    pointer-events: none;
    filter: grayscale(100%);
}
.expert-card.is-disabled .expert-toggle {
    pointer-events: auto; /* allow toggling back */
}
.expert-card-wide { grid-column: 1 / -1; }
.expert-toggle {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-weight: 600;
    color: var(--ink);
    cursor: pointer;
}
.expert-toggle input[type="checkbox"] {
    width: 20px; height: 20px;
    accent-color: var(--accent);
    cursor: pointer;
}
.field-hint { font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.expert-subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 16px;
}
.checkbox-inline { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-inline input { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
input.is-readonly {
    background: var(--bg-soft);
    color: var(--muted);
    cursor: not-allowed;
    border-color: transparent;
}

/* Tables */
.layers-table-wrap, .result-table {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
}

.layers-table, .result-table table {
    width: 100%;
    border-collapse: collapse;
}

.layers-table th, .result-table th, 
.layers-table td, .result-table td {
    padding: 16px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    font-size: 0.95rem;
}

.layers-table th, .result-table th {
    background: var(--bg-soft);
    color: var(--muted);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.8rem;
    letter-spacing: 0.05em;
}

.layers-table tr:last-child td, .result-table tr:last-child td {
    border-bottom: none;
}

.danger-row {
    background: rgba(239, 68, 68, 0.05);
}

/* Actions & Buttons */
.actions, .toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}

.icon-btn {
    padding: 8px 10px;
    font-size: 1.1rem;
    line-height: 1;
    border-radius: var(--radius-sm);
}

.toolbar {
    margin-top: 32px;
    justify-content: space-between;
    flex-wrap: wrap;
    background: var(--bg-soft);
    padding: 20px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    border: none;
    font-family: inherit;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

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

.primary {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

.primary:hover {
    background: var(--accent-soft);
    box-shadow: 0 6px 16px rgba(59, 130, 246, 0.4);
}

.ghost, .remove-row {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line);
}

.ghost:hover, .remove-row:hover {
    background: var(--line);
}

.status-line { margin: 0; font-size: 0.9rem; font-weight: 500; color: var(--muted); }

/* Results Metrics */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    padding: 20px;
    border-radius: var(--radius-md);
    background: var(--panel);
    border: 1px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: transform 0.2s ease;
}

.metric-card:hover {
    transform: translateY(-2px);
    border-color: var(--accent);
}

.metric-card span {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: 0.05em;
}

.metric-card strong {
    font-size: 1.4rem;
    color: var(--ink);
    line-height: 1.2;
}

.result-panel {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--bg-soft);
    border: 1px solid var(--line);
    margin-bottom: 24px;
}

.result-panel h3 { margin-bottom: 16px; }

.result-panel.accent {
    background: var(--bg);
    border-color: var(--accent);
    position: relative;
    overflow: hidden;
}
.result-panel.accent::before {
    content: "";
    position: absolute; top: 0; left: 0; bottom: 0; width: 4px;
    background: var(--accent);
}

.expert-result-panel {
    background: var(--bg-soft);
    border: 1px dashed var(--accent);
}

.bullet-list { margin: 0; padding-left: 20px; color: var(--muted); }
.bullet-list li { margin-bottom: 8px; }

.expert-metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.expert-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.expert-column {
    padding: 20px;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--panel);
}

/* Visualization SVG */
.visual-block {
    padding: 24px;
    border-radius: var(--radius-lg);
    background: var(--chart-block-surface);
    border: 1px solid var(--line);
}

.visual-meta {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}

.visual-meta span { font-weight: 600; color: var(--muted); font-size: 0.9rem; }
.visual-meta strong { color: var(--ink); font-size: 0.9rem; }

.viz-svg { width: 100%; height: auto; display: block; border-radius: 8px; }
.viz-band-text { font-size: 13px; font-weight: 600; fill: var(--ink); }
.viz-band-subtext { font-size: 11px; fill: var(--ink); opacity: 0.8; }
.viz-axis-label { font-size: 11px; fill: var(--viz-text); font-weight: 500; }
.viz-intersection-label { font-size: 11px; fill: var(--viz-text); font-weight: 600; }
.viz-grid-line { stroke: var(--viz-grid); stroke-width: 1; stroke-dasharray: 4 4; }
.viz-depth-line { stroke: var(--viz-axis); stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.5; }
.viz-axis-line { stroke: var(--viz-axis); stroke-width: 1.5; }
.viz-band-separator { stroke: var(--viz-axis); stroke-width: 1; opacity: 0.3; }
.viz-section-label { font-size: 11px; font-weight: 600; text-transform: uppercase; fill: var(--muted); letter-spacing: 0.05em; }

.viz-line-temperature { stroke: var(--viz-temp-line); fill: none; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.viz-line-dewpoint { stroke: var(--viz-dew-line); fill: none; stroke-width: 3.5; stroke-linecap: round; stroke-linejoin: round; }
.viz-intersection { fill: var(--warn); stroke: var(--panel); stroke-width: 2; }

/* Legend */
.viz-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    justify-content: center;
}
.viz-legend span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--muted);
    font-weight: 600;
}
.legend-swatch {
    display: inline-block;
    width: 16px; height: 4px;
    border-radius: 2px;
}
.legend-swatch.temperature { background: var(--viz-temp-line); }
.legend-swatch.dewpoint { background: var(--viz-dew-line); }
.legend-swatch.intersection { background: var(--warn); width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); }
