:root {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --accent: #4f46e5;
    --accent-light: #818cf8;
    --accent-bg: #eef2ff;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --chart-grid: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
    --radius: 8px;
    --radius-lg: 12px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg-primary: #1a1a2e;
        --bg-secondary: #16213e;
        --bg-tertiary: #0f3460;
        --text-primary: #e5e7eb;
        --text-secondary: #9ca3af;
        --text-muted: #6b7280;
        --border-color: #374151;
        --accent: #818cf8;
        --accent-light: #a5b4fc;
        --accent-bg: #312e81;
        --chart-grid: #374151;
        --shadow: 0 1px 3px rgba(0,0,0,0.3);
        --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3);
    }
}

/* Dark theme via data attribute */
[data-theme="dark"] {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border-color: #374151;
    --accent: #818cf8;
    --accent-light: #a5b4fc;
    --accent-bg: #312e81;
    --chart-grid: #374151;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3);
}

/* Light theme via data attribute */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --accent: #4f46e5;
    --accent-light: #818cf8;
    --accent-bg: #eef2ff;
    --chart-grid: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

.container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 20px;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 0;
}

.main-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 12px 20px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent);
}

.logo svg {
    width: 32px;
    height: 32px;
}

.logo-subtitle {
    font-size: 0.85rem;
    font-weight: 400;
    color: var(--text-secondary);
    margin-left: 4px;
}

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

.time-horizon {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-horizon label {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.time-horizon-control {
    display: flex;
    align-items: center;
    gap: 8px;
}

.time-horizon-control label {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.time-horizon-control input[type="range"] {
    width: 120px;
    accent-color: var(--accent);
}

.time-horizon-control span {
    font-size: 0.8rem;
    color: var(--text-primary);
    font-weight: 500;
    min-width: 80px;
}

select, input[type="text"], input[type="number"] {
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

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

button {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--accent);
    color: white;
}

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

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

.btn-secondary:hover {
    background: var(--border-color);
}

.btn-icon {
    padding: 8px;
    background: transparent;
    color: var(--text-secondary);
}

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

/* Hypothesis Tabs */
.hypothesis-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    margin-bottom: 12px;
    overflow: visible;
    flex-wrap: wrap;
}

.hypothesis-bar-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

#hypothesisTabs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-icon-round {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px dashed var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    font-size: 1.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.hypothesis-tab {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
    border: 2px solid transparent;
}

.hypothesis-tab:hover {
    background: var(--bg-tertiary);
}

.hypothesis-tab.active {
    background: var(--accent-bg);
    border-color: var(--accent);
}

.hypothesis-color {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.hypothesis-name {
    font-weight: 500;
    cursor: text;
}

.hypothesis-name input {
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--accent);
    color: inherit;
    font: inherit;
    width: 100px;
    padding: 0;
    outline: none;
}

.hypothesis-visibility {
    padding: 4px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    font-size: 14px;
}

.hypothesis-visibility:hover {
    opacity: 1;
}

.hypothesis-visibility.hidden {
    opacity: 0.3;
}

.hypothesis-delete {
    opacity: 0;
    transition: opacity 0.2s;
    padding: 2px 6px;
    font-size: 1rem;
    line-height: 1;
}

.hypothesis-tab:hover .hypothesis-delete {
    opacity: 1;
}

.compare-toggle {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.toggle-switch.active {
    background: var(--accent);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

/* Main Content Grid */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 24px;
}

@media (max-width: 1400px) {
    .main-grid {
        grid-template-columns: 1fr 1.2fr;
    }
}

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

/* Panels */
.panel {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.panel-sticky {
    position: sticky;
    top: 20px;
    align-self: start;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
}

@media (max-width: 1000px) {
    .panel-sticky {
        position: static;
        max-height: none;
    }
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.panel-title {
    font-size: 1rem;
    font-weight: 600;
}

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

.panel-header-controls select,
.panel-header-controls button {
    padding: 4px 10px;
    font-size: 0.8rem;
}

.panel-header-controls .time-horizon label {
    font-size: 0.8rem;
}

.panel-content {
    padding: 20px;
}

/* Curve Groups - stacked vertically */
.curve-group {
    display: block;
    width: 100%;
    margin-bottom: 28px;
}

.curve-group:last-child {
    margin-bottom: 0;
}

.curve-group-header {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Curve Editors Grid - within each group */
.curve-group-content {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (max-width: 600px) {
    .curve-group-content {
        grid-template-columns: 1fr;
    }
}

.curve-editor {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border-color);
}

.curve-editor-readonly {
    opacity: 0.85;
}

.curve-editor-readonly .curve-canvas {
    cursor: default;
}

.curve-editor-readonly .curve-controls {
    display: none;
}

.curve-editor-readonly .curve-label {
    color: var(--text-secondary);
}

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

.curve-label {
    font-weight: 500;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 6px;
}

.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    cursor: help;
    position: relative;
    flex-shrink: 0;
    transition: background 0.2s, color 0.2s;
}

.info-icon:hover {
    background: var(--accent);
    color: white;
}

.info-tooltip {
    position: fixed;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 400;
    color: var(--text-primary);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s;
    z-index: 10000;
    pointer-events: none;
    width: 240px;
    white-space: pre-line;
    text-align: left;
    line-height: 1.4;
}

.info-tooltip.visible {
    opacity: 1;
    visibility: visible;
}

.curve-value {
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-family: 'SF Mono', Monaco, monospace;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    opacity: 0.9;
    z-index: 5;
    pointer-events: none;
    transition: opacity 0.15s ease;
}

.curve-value.hidden {
    opacity: 0;
}

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

.constant-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.constant-toggle input {
    width: 14px;
    height: 14px;
    accent-color: var(--accent);
}

.curve-canvas-container {
    position: relative;
    background: var(--bg-tertiary);
    border-radius: var(--radius);
    overflow: hidden;
}

.curve-canvas {
    display: block;
    width: 100%;
    height: 150px;
    min-width: 200px;
    cursor: crosshair;
}

/* Curves Container - holds all curve groups */
.curves-container {
    display: flex;
    flex-direction: column;
    gap: 0;
}

/* Summary Grid */
.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

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

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

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

.summary-label {
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.summary-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary);
    font-family: 'SF Mono', Monaco, monospace;
}

/* Charts Grid */
.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

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

.chart-container {
    background: var(--bg-primary);
    border-radius: var(--radius);
    padding: 12px;
    border: 1px solid var(--border-color);
    min-width: 0;
}

.chart-container canvas {
    width: 100% !important;
    height: 200px !important;
}

.chart-title {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chart-wrapper {
    position: relative;
    height: 240px;
    min-height: 200px;
    width: 100%;
}

.chart-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Results Summary Table */
.results-summary {
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
    overflow-x: auto;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.summary-table th {
    text-align: right;
    padding: 6px 10px;
    font-weight: 500;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
}

.summary-table th:first-child {
    text-align: left;
}

.summary-table td {
    padding: 8px 10px;
    text-align: right;
    font-weight: 600;
    color: var(--text-primary);
}

.summary-table td:first-child {
    text-align: left;
    font-weight: 500;
}

.summary-table tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-color);
}

.hypothesis-color-dot,
.color-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    vertical-align: middle;
}

/* Milestones Dropdown */
.milestones-dropdown {
    position: relative;
}

.milestones-menu {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 280px;
    z-index: 201;
    overflow: hidden;
}

.milestones-menu.active {
    display: block;
}

.milestones-list {
    max-height: 200px;
    overflow-y: auto;
}

.milestone-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-color);
}

.milestone-item:last-child {
    border-bottom: none;
}

.milestone-info {
    display: flex;
    align-items: center;
    gap: 8px;
}

.milestone-month {
    font-weight: 600;
    color: var(--accent);
    font-size: 0.85rem;
}

.milestone-name {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.milestone-delete {
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.milestone-delete:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.milestones-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.milestones-add {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.milestones-add input {
    flex: 1;
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
}

.milestones-add input::placeholder {
    color: var(--text-secondary);
}

.milestone-month-input {
    width: 90px !important;
    flex: none !important;
    text-align: center;
}

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 24px;
    min-width: 320px;
    box-shadow: var(--shadow-lg);
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 16px;
}

.modal-field {
    margin-bottom: 16px;
}

.modal-field label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.modal-field input, .modal-field select {
    width: 100%;
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 20px;
}

/* Template Dropdown */
.template-dropdown {
    position: relative;
    z-index: 200;
}

.template-menu {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    z-index: 201;
    overflow: hidden;
}

.template-menu.active {
    display: block;
}

.template-option {
    padding: 10px 16px;
    cursor: pointer;
    transition: background 0.2s;
}

.template-option:hover {
    background: var(--bg-tertiary);
}

.template-option-name {
    font-weight: 500;
}

.template-option-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.template-section-header {
    padding: 8px 16px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
}

.template-section-header:first-child,
#copyOptions:first-child + .template-section-header {
    border-top: none;
    margin-top: 0;
}

#copyHeader[style*="display:none"] + #copyOptions + .template-section-header {
    border-top: none;
    margin-top: 0;
}

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

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}
