:root {
    /* Light Mode */
    --bg-gradient: linear-gradient(135deg, #f6f8fd 0%, #f1f5f9 100%);
    --panel-bg: rgba(255, 255, 255, 0.7);
    --panel-border: rgba(255, 255, 255, 0.5);
    --panel-shadow: 0 8px 32px rgba(31, 38, 135, 0.07);
    --text-main: #1e293b;
    --text-muted: #64748b;
    --primary-color: #3b82f6;
    --primary-hover: #2563eb;
    --secondary-color: #e2e8f0;
    --secondary-hover: #cbd5e1;
    --secondary-text: #475569;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --input-bg: rgba(255, 255, 255, 0.9);
    --input-border: #cbd5e1;
    --input-focus: #3b82f6;
    --funnel-base-color: #3b82f6;
    --funnel-gradient: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
    --table-header-bg: #f8fafc;
    --table-border: #e2e8f0;
}

[data-theme="dark"] {
    --bg-gradient: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    --panel-bg: rgba(30, 41, 59, 0.7);
    --panel-border: rgba(255, 255, 255, 0.1);
    --panel-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary-color: #334155;
    --secondary-hover: #475569;
    --secondary-text: #cbd5e1;
    --success-color: #34d399;
    --warning-color: #fbbf24;
    --danger-color: #f87171;
    --input-bg: rgba(15, 23, 42, 0.6);
    --input-border: #475569;
    --input-focus: #60a5fa;
    --funnel-base-color: #60a5fa;
    --funnel-gradient: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%);
    --table-header-bg: #1e293b;
    --table-border: #334155;
}

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

body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-gradient);
    color: var(--text-main);
    min-height: 100vh;
    padding: 20px;
    transition: background 0.3s ease, color 0.3s ease;
}

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Typography & Utilities */
h1, h2, h3 {
    font-weight: 600;
}

h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-main);
}

.helper-text {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Glassmorphism Panel */
.glass-panel {
    background: var(--panel-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 24px;
    box-shadow: var(--panel-shadow);
    transition: background 0.3s ease, border 0.3s ease, box-shadow 0.3s ease;
}

/* Header */
.main-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-icon {
    font-size: 2rem;
    color: var(--primary-color);
    background: rgba(59, 130, 246, 0.1);
    padding: 12px;
    border-radius: 12px;
}

.header-titles h1 {
    font-size: 1.5rem;
    line-height: 1.2;
}

.header-titles .subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

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

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

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

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

.btn-outline {
    background-color: transparent;
    border: 1px solid var(--primary-color);
    color: var(--primary-color);
}

.btn-outline:hover {
    background-color: rgba(59, 130, 246, 0.1);
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--secondary-color);
    color: var(--text-main);
}

/* Main Layout */
.main-content {
    display: grid;
    grid-template-columns: 1fr 1.5fr;
    gap: 24px;
    align-items: start;
}

/* Panels */
.config-section, .results-section {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.panel-header h2 {
    margin-bottom: 0;
}

/* Forms */
.form-group.row {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
}

.col {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-control {
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    color: var(--text-main);
    padding: 10px 14px;
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: all 0.2s;
    width: 100%;
}

.form-control:focus {
    border-color: var(--input-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

/* Steps Container */
.steps-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.step-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: 12px;
    padding: 12px 16px;
    transition: all 0.2s;
}

.step-card:hover {
    border-color: var(--input-focus);
}

.step-number {
    background: var(--primary-color);
    color: white;
    font-size: 0.85rem;
    font-weight: 700;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    flex-shrink: 0;
}

.step-inputs {
    display: flex;
    flex: 1;
    gap: 12px;
    align-items: center;
}

.step-inputs > div {
    flex: 1;
}

.step-inputs .form-control {
    padding: 8px 12px;
    background: transparent;
    border-color: transparent;
}
.step-inputs .form-control.value-input {
    text-align: right;
    font-family: monospace;
    font-size: 1.05rem;
    border-left: 1px solid var(--input-border);
    border-radius: 0;
}
.step-inputs .form-control:focus {
    background: var(--panel-bg);
}

/* Results / Quick Stats */
.panels-header-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
}

.stat-box {
    display: flex;
    flex-direction: column;
}
.stat-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    font-weight: 600;
}
.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.export-buttons {
    display: flex;
    gap: 10px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
    background: rgba(0, 0, 0, 0.02);
    border: 2px dashed var(--input-border);
    border-radius: 12px;
}

[data-theme="dark"] .empty-state {
    background: rgba(255, 255, 255, 0.02);
}

/* Visual Funnel Representation */
.visual-funnel {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-top: 10px;
    gap: 0;
}

.funnel-layer-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    margin-bottom: 2px;
}

.funnel-layer {
    background: var(--funnel-gradient);
    height: 45px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 0.9rem;
    position: relative;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
}

.funnel-layer-name {
    position: absolute;
    left: 15px;
    font-weight: 500;
    white-space: nowrap;
}

.funnel-layer-value {
    position: absolute;
    right: 15px;
    font-family: monospace;
    font-size: 1.05rem;
}

.funnel-connector {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 35px;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
}
.funnel-connector i {
    margin-right: 5px;
    color: var(--danger-color);
}

/* Data Table */
.table-responsive {
    overflow-x: auto;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.results-table th, .results-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--table-border);
}

.results-table th {
    background: var(--table-header-bg);
    color: var(--text-muted);
    font-weight: 600;
}

.results-table th:first-child { border-top-left-radius: 8px; border-bottom-left-radius: 8px; }
.results-table th:last-child { border-top-right-radius: 8px; border-bottom-right-radius: 8px; }

.results-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
}
[data-theme="dark"] .results-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.02);
}

.text-right { text-align: right !important; }
.text-center { text-align: center !important; }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success-color); border: 1px solid rgba(16, 185, 129, 0.2); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning-color); border: 1px solid rgba(245, 158, 11, 0.2); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger-color); border: 1px solid rgba(239, 68, 68, 0.2); }
.badge-neutral { background: rgba(100, 116, 139, 0.1); color: var(--secondary-text); border: 1px solid rgba(100, 116, 139, 0.2); }

/* Analysis Report */
.analysis-item {
    padding: 16px;
    border-bottom: 1px solid var(--panel-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.analysis-item:last-child {
    border-bottom: none;
}
.analysis-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.analysis-title {
    font-weight: 600;
    font-size: 0.95rem;
}
.analysis-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
}
.analysis-source {
    font-size: 0.75rem;
    margin-top: 4px;
}
.analysis-source a {
    color: var(--primary-color);
    text-decoration: none;
}
.analysis-source a:hover {
    text-decoration: underline;
}

/* Tooltip */
.tooltip-btn { position: relative; }
.tooltip-btn::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #fff;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: 0.2s;
    z-index: 10;
    pointer-events: none;
}
.tooltip-btn:hover::after {
    opacity: 1;
    visibility: visible;
}

/* Export Overlay */
.export-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}
.export-overlay.active {
    opacity: 1;
    visibility: visible;
}
.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255,255,255,0.3);
    border-radius: 50%;
    border-top-color: white;
    animation: spin 1s ease-in-out infinite;
    margin-bottom: 20px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Export Styles for PDF and PNG */
.export-mode {
    background: #ffffff !important;
    color: #000000 !important;
}
.export-mode .glass-panel {
    background: #ffffff !important;
    border: 1px solid #e2e8f0 !important;
    box-shadow: none !important;
    border-radius: 0 !important;
    color: #000000 !important;
    max-width: 100% !important;
}
.export-mode .text-muted { color: #475569 !important; }
.export-mode .no-export { display: none !important; }
.export-mode .export-header {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    padding: 15px;
    border-bottom: 2px solid #3b82f6;
    margin-bottom: 20px;
    background: #ffffff;
}
.export-mode .export-logo {
    font-size: 1.5rem;
    font-weight: 700;
    color: #3b82f6;
}
.export-mode .export-link {
    font-size: 0.9rem;
    color: #64748b;
}

/* Responsive */
@media (max-width: 992px) {
    .main-content {
        grid-template-columns: 1fr;
    }
}
@media (max-width: 768px) {
    .form-group.row {
        flex-direction: column;
    }
    .header-titles h1 {
        font-size: 1.2rem;
    }
    .main-header {
        padding: 16px;
    }
}
