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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: white;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

/* Header */
.header {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
    color: white;
    padding: 30px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header h1 {
    font-size: 32px;
    font-weight: 700;
    margin-bottom: 5px;
}

.subtitle {
    font-size: 14px;
    opacity: 0.9;
}

.status-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255, 255, 255, 0.2);
    padding: 10px 20px;
    border-radius: 25px;
    font-size: 14px;
}

.pulse {
    width: 10px;
    height: 10px;
    background: #4ade80;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Configuration Panel */
.config-panel {
    padding: 30px 40px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.config-section {
    background: white;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.config-section h3 {
    color: #1e3c72;
    margin-bottom: 15px;
    font-size: 16px;
    font-weight: 600;
}

.ticker-container {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.ticker-input-field {
    flex: 1;
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s;
}

.ticker-input-field:focus {
    outline: none;
    border-color: #667eea;
}

.btn-add {
    padding: 10px 20px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-add:hover {
    background: #5568d3;
}

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

.ticker-tag {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #667eea;
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
}

.ticker-tag .remove {
    cursor: pointer;
    font-weight: bold;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.ticker-tag .remove:hover {
    opacity: 1;
}

.select-field {
    width: 100%;
    padding: 10px 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    cursor: pointer;
    transition: border-color 0.3s;
}

.select-field:focus {
    outline: none;
    border-color: #667eea;
}

.param-grid {
    display: grid;
    gap: 15px;
}

.param-item label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: #555;
    font-weight: 500;
}

.param-item input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: #e0e0e0;
    outline: none;
    -webkit-appearance: none;
}

.param-item input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
}

.param-item input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #667eea;
    cursor: pointer;
    border: none;
}

.btn-calculate {
    grid-column: 1 / -1;
    padding: 15px 40px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 700;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-calculate:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.6);
}

.btn-calculate:active {
    transform: translateY(0);
}

/* Results Container */
.results-container {
    padding: 30px 40px;
    display: grid;
    gap: 25px;
}

/* Signal Panel */
.signal-panel {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.signal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.3);
}

.signal-header h2 {
    font-size: 24px;
}

.signal-state {
    padding: 8px 20px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    font-weight: 700;
    font-size: 18px;
}

.signal-state.risk-on {
    background: #4ade80;
    color: #065f46;
}

.signal-state.risk-off {
    background: #f87171;
    color: #7f1d1d;
}

.signal-state.critical {
    background: #ef4444;
    color: white;
    animation: pulse 1s infinite;
}

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

.metric {
    text-align: center;
}

.metric-label {
    display: block;
    font-size: 12px;
    opacity: 0.9;
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.metric-value {
    display: block;
    font-size: 24px;
    font-weight: 700;
}

.metric-value.action {
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    display: inline-block;
}

.recommendation {
    background: rgba(255, 255, 255, 0.15);
    padding: 15px 20px;
    border-radius: 10px;
    margin-bottom: 20px;
    font-size: 16px;
    line-height: 1.6;
}

.betas-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
}

.beta-item {
    background: rgba(255, 255, 255, 0.1);
    padding: 12px;
    border-radius: 8px;
    text-align: center;
}

.beta-ticker {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 5px;
}

.beta-value {
    font-size: 20px;
    font-weight: 700;
}

.beta-value.high { color: #4ade80; }
.beta-value.low { color: #fbbf24; }

/* GSSA Panel */
.gssa-panel {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.gssa-panel h2 {
    color: #1e3c72;
    margin-bottom: 20px;
    font-size: 20px;
}

.gssa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}

.gssa-card {
    padding: 20px;
    border-radius: 10px;
    text-align: center;
}

.gssa-card.k-plus { background: linear-gradient(135deg, #667eea20, #667eea40); border: 2px solid #667eea; }
.gssa-card.k-minus { background: linear-gradient(135deg, #f8717120, #f8717140); border: 2px solid #f87171; }
.gssa-card.gamma { background: linear-gradient(135deg, #fbbf2420, #fbbf2440); border: 2px solid #fbbf24; }
.gssa-card.reliability { background: linear-gradient(135deg, #4ade8020, #4ade8040); border: 2px solid #4ade80; }

.gssa-card h4 {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 10px;
    opacity: 0.8;
}

.gssa-value {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 5px;
}

.gssa-detail {
    font-size: 12px;
    opacity: 0.7;
}

.reliability-circle {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    margin: 0 auto 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    font-weight: 700;
    color: white;
}

/* Chart Containers */
.chart-container {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.chart-container h2 {
    color: #1e3c72;
    margin-bottom: 20px;
    font-size: 20px;
}

.chart-container canvas {
    max-height: 400px;
}

/* Metrics Panel */
.metrics-panel {
    background: white;
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.metrics-panel h2 {
    color: #1e3c72;
    margin-bottom: 20px;
    font-size: 20px;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
}

.metric-card {
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.metric-card h3 {
    font-size: 16px;
    margin-bottom: 15px;
    opacity: 0.8;
}

.big-number {
    font-size: 36px;
    font-weight: 700;
    margin-bottom: 10px;
}

.metric-detail {
    font-size: 14px;
    opacity: 0.7;
}

.metric-card.uaf {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.metric-card.bh {
    background: #f3f4f6;
    color: #374151;
}

.metric-card.outperf {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
}

.metric-card.baseline {
    background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
    color: white;
}

.metric-card.cost {
    background: #fef3c7;
    color: #92400e;
}

/* Spectral Table */
.spectral-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.spectral-table th, .spectral-table td {
    padding: 8px 12px;
    text-align: left;
    border-bottom: 1px solid #e5e7eb;
}

.spectral-table th {
    background: #f9fafb;
    font-weight: 600;
    font-size: 13px;
    text-transform: uppercase;
}

.spectral-table .highlight {
    background: #eff6ff;
    font-weight: 600;
}

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

.modal-content {
    background: white;
    border-radius: 16px;
    padding: 30px;
    max-width: 800px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-content h2 {
    color: #1e3c72;
    margin-bottom: 20px;
}

.modal-close {
    float: right;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

/* Index Overlay Controls */
.index-overlay-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e5e7eb;
}

.index-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: 20px;
    border: 2px solid #e0e0e0;
    background: white;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.2s;
}

.index-toggle.active {
    border-color: currentColor;
    background: currentColor;
    color: white;
}

.index-toggle .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Ollama Section */
.ollama-section {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 25px;
    border-radius: 12px;
    margin-top: 15px;
}

.ollama-section h2 {
    color: #a78bfa;
    margin-bottom: 15px;
}

.ollama-content {
    line-height: 1.8;
    font-size: 15px;
}

.btn-ollama {
    padding: 10px 25px;
    background: linear-gradient(135deg, #a78bfa 0%, #7c3aed 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.btn-ollama:hover {
    transform: translateY(-1px);
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.loading-content {
    text-align: center;
    color: white;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-content p {
    font-size: 18px;
    margin-bottom: 10px;
}

.loading-detail {
    font-size: 14px;
    opacity: 0.7;
}

/* Toggle Switch */
.toggle-container {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    border-radius: 24px;
    transition: 0.3s;
}

.toggle-slider:before {
    content: "";
    position: absolute;
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    border-radius: 50%;
    transition: 0.3s;
}

input:checked + .toggle-slider {
    background-color: #667eea;
}

input:checked + .toggle-slider:before {
    transform: translateX(20px);
}

/* ============================================= */
/* Tab Navigation                                */
/* ============================================= */
.tab-navigation {
    display: flex;
    background: #f0f2f5;
    border-bottom: 2px solid #e0e0e0;
    padding: 0 40px;
}

.tab-btn {
    padding: 14px 28px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    position: relative;
    top: 2px;
}

.tab-btn:hover {
    color: #1e3c72;
}

.tab-btn.active {
    color: #1e3c72;
    border-bottom-color: #667eea;
    background: white;
}

/* Tab Panels */
.tab-panel {
    display: none;
}

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

/* ============================================= */
/* Systemic Stability Tab                        */
/* ============================================= */
.systemic-controls {
    padding: 30px 40px 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.systemic-controls h2 {
    color: #1e3c72;
    margin-bottom: 8px;
    font-size: 22px;
}

.systemic-subtitle {
    color: #666;
    font-size: 14px;
    margin-bottom: 20px;
}

.systemic-actions {
    display: flex;
    align-items: center;
    gap: 20px;
}

.systemic-actions .btn-calculate {
    grid-column: auto;
    width: auto;
}

.systemic-end-date {
    font-size: 16px;
    font-weight: 700;
    color: #1e3c72;
    background: #e8eaf6;
    padding: 8px 16px;
    border-radius: 8px;
}

.systemic-chart-wrapper {
    padding: 30px 40px;
}

.systemic-chart-container {
    min-height: 500px;
}

.systemic-chart-container canvas {
    min-height: 480px;
    max-height: 600px;
}

.systemic-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e5e7eb;
}

.systemic-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    background: #f3f4f6;
    cursor: pointer;
    transition: opacity 0.2s;
    border: 1px solid #e0e0e0;
}

.systemic-legend-item:hover {
    background: #e5e7eb;
}

.systemic-legend-item.hidden {
    opacity: 0.3;
}

.systemic-legend-item .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* ============================================= */
/* Risk Gauge Tab (Tab 3)                        */
/* ============================================= */
.riskgauge-controls {
    padding: 30px 40px 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.riskgauge-controls h2 {
    color: #1e3c72;
    margin-bottom: 8px;
    font-size: 22px;
}

.riskgauge-content {
    padding: 30px 40px;
    display: grid;
    gap: 25px;
}

.riskgauge-chart-container {
    min-height: 420px;
}

.riskgauge-chart-container canvas {
    min-height: 400px;
    max-height: 520px;
}

/* DEFCON Panel */
.defcon-panel {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: white;
    padding: 25px;
    border-radius: 12px;
}

.defcon-panel h2 {
    color: #a78bfa;
    margin-bottom: 15px;
    font-size: 20px;
}

.defcon-summary {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.defcon-badge {
    padding: 10px 20px;
    border-radius: 10px;
    font-weight: 700;
    font-size: 16px;
    text-align: center;
}

.defcon-badge.level-low {
    background: #4ade80;
    color: #065f46;
}

.defcon-badge.level-medium {
    background: #fbbf24;
    color: #78350f;
}

.defcon-badge.level-high {
    background: #f97316;
    color: white;
}

.defcon-badge.level-critical {
    background: #ef4444;
    color: white;
    animation: pulse 1.5s infinite;
}

/* DEFCON Table */
.defcon-table {
    width: 100%;
    border-collapse: collapse;
}

.defcon-table th {
    background: rgba(255, 255, 255, 0.1);
    color: #a78bfa;
    padding: 10px 14px;
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 2px solid rgba(255, 255, 255, 0.15);
}

.defcon-table td {
    padding: 10px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    font-size: 14px;
}

.defcon-table tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.defcon-status-ok {
    color: #4ade80;
    font-weight: 700;
}

.defcon-status-alert {
    color: #ef4444;
    font-weight: 700;
}

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

/* ============================================= */
/* Trade Suggestions Panel                       */
/* ============================================= */
.suggestions-panel {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #e2e8f0;
    padding: 25px;
    border-radius: 12px;
    margin-bottom: 20px;
}

.suggestions-panel h2 {
    color: #a78bfa;
    margin-bottom: 15px;
    font-size: 20px;
}

.suggestions-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 15px;
}

.suggestions-meta-item {
    background: rgba(255, 255, 255, 0.08);
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}

.suggestions-meta-item.regime-stable {
    background: rgba(74, 222, 128, 0.15);
    color: #4ade80;
}

.suggestions-meta-item.regime-unstable {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

/* Position Alerts */
.position-alert-item {
    padding: 8px 14px;
    border-radius: 8px;
    margin-bottom: 8px;
    font-size: 13px;
    font-weight: 500;
}

.position-alert-item.alert-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border-left: 3px solid #ef4444;
}

.position-alert-item.alert-warning {
    background: rgba(251, 191, 36, 0.12);
    color: #fde68a;
    border-left: 3px solid #fbbf24;
}

/* Regime Change Warning */
.regime-change-warning {
    background: rgba(245, 158, 11, 0.15);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #fde68a;
    padding: 10px 16px;
    border-radius: 8px;
    margin-bottom: 15px;
    font-size: 14px;
}

/* Suggestions table overrides (dark theme) */
.suggestions-panel .spectral-table th {
    background: rgba(255, 255, 255, 0.08);
    color: #a78bfa;
    border-bottom: 2px solid rgba(255, 255, 255, 0.12);
}

.suggestions-panel .spectral-table td {
    color: #e2e8f0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.suggestions-panel .spectral-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* (Responsive rules moved to end of file) */

/* ============================================= */
/* Portfolio Tab (Tab 4)                          */
/* ============================================= */
.portfolio-controls {
    padding: 30px 40px 20px;
    background: #f8f9fa;
    border-bottom: 2px solid #e0e0e0;
}

.portfolio-controls h2 {
    color: #1e3c72;
    margin-bottom: 8px;
    font-size: 22px;
}

.portfolio-actions {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin-top: 15px;
}

.portfolio-account-group {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 5px 0;
    border-bottom: 1px solid #e2e8f0;
    margin-bottom: 10px;
}

.portfolio-account-group label {
    font-size: 14px;
    font-weight: 600;
    color: #1e3c72;
}

.portfolio-init-group,
.portfolio-run-group {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.portfolio-init-group label,
.portfolio-run-group label {
    font-size: 14px;
    font-weight: 500;
    color: #555;
}

.portfolio-content {
    padding: 30px 40px;
    display: grid;
    gap: 25px;
}

/* Spectral table (reused for positions & trades) */
.spectral-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.spectral-table th {
    background: #f1f5f9;
    color: #475569;
    padding: 10px 12px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}

.spectral-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

.spectral-table tbody tr:hover {
    background: #f8fafc;
}

/* =====================================================
   AUTH PAGES (Login / Register)
   ===================================================== */

.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.auth-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    padding: 40px;
    width: 100%;
    max-width: 420px;
}

.auth-header {
    text-align: center;
    margin-bottom: 30px;
}

.auth-header h1 {
    font-size: 24px;
    color: #1e3c72;
    margin-bottom: 8px;
}

.auth-header p {
    font-size: 14px;
    color: #64748b;
}

.auth-error {
    background: #fef2f2;
    color: #dc2626;
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 20px;
    border: 1px solid #fecaca;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-field label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}

.auth-field input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.auth-field input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

.auth-submit {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 4px;
}

.auth-submit:hover {
    opacity: 0.9;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 13px;
    color: #64748b;
}

.auth-footer a {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* =====================================================
   HELP PAGE
   ===================================================== */

.help-back-link {
    color: white;
    text-decoration: none;
    padding: 8px 20px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.15);
    font-size: 13px;
    font-weight: 600;
    transition: background 0.2s;
}

.help-back-link:hover {
    background: rgba(255, 255, 255, 0.3);
}

.help-content {
    padding: 30px 40px 40px;
    max-width: 900px;
    margin: 0 auto;
}

.help-toc {
    background: #f0f4ff;
    padding: 24px 30px;
    border-radius: 12px;
    margin-bottom: 30px;
    border-left: 4px solid #667eea;
}

.help-toc h2 {
    font-size: 18px;
    color: #1e3c72;
    margin-bottom: 12px;
}

.help-toc ol {
    list-style-position: inside;
    padding: 0;
}

.help-toc li {
    margin-bottom: 6px;
}

.help-toc a {
    color: #2a5298;
    text-decoration: none;
    font-size: 15px;
}

.help-toc a:hover {
    text-decoration: underline;
}

.help-section {
    margin-bottom: 36px;
}

.help-section > h2 {
    font-size: 22px;
    color: #1e3c72;
    border-bottom: 2px solid #667eea;
    padding-bottom: 8px;
    margin-bottom: 20px;
}

.help-card {
    background: #f8f9fa;
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 16px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.help-card h3 {
    font-size: 16px;
    color: #1e3c72;
    margin-bottom: 10px;
}

.help-card p {
    font-size: 14px;
    line-height: 1.7;
    color: #333;
    margin-bottom: 8px;
}

.help-card ul, .help-card ol {
    padding-left: 20px;
    margin-bottom: 8px;
}

.help-card li {
    font-size: 14px;
    line-height: 1.7;
    color: #333;
    margin-bottom: 4px;
}

.help-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 13px;
}

.help-table th {
    background: #1e3c72;
    color: white;
    padding: 10px 14px;
    text-align: left;
    font-weight: 600;
}

.help-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #e0e0e0;
    vertical-align: top;
    line-height: 1.6;
}

.help-table tr:last-child td { border-bottom: none; }
.help-table tr:nth-child(even) td { background: #f0f4ff; }

.help-color-green { background: #22c55e; color: white; font-weight: 600; text-align: center; border-radius: 4px; }
.help-color-yellow { background: #eab308; color: white; font-weight: 600; text-align: center; border-radius: 4px; }
.help-color-orange { background: #f97316; color: white; font-weight: 600; text-align: center; border-radius: 4px; }
.help-color-red { background: #ef4444; color: white; font-weight: 600; text-align: center; border-radius: 4px; }

.help-dl {
    margin: 0;
}

.help-dl dt {
    font-weight: 700;
    color: #1e3c72;
    margin-top: 10px;
    font-size: 14px;
}

.help-dl dd {
    margin-left: 0;
    padding-left: 16px;
    font-size: 14px;
    line-height: 1.7;
    color: #333;
    border-left: 3px solid #667eea;
    margin-bottom: 8px;
}

.help-formula {
    background: #1e3c72;
    color: #4ade80;
    font-family: 'Courier New', monospace;
    font-size: 18px;
    font-weight: 700;
    padding: 14px 24px;
    border-radius: 8px;
    text-align: center;
    margin: 12px 0;
    letter-spacing: 1px;
}

.help-footer {
    text-align: center;
    padding: 30px 0 10px;
    color: #888;
    font-size: 13px;
    border-top: 1px solid #e0e0e0;
    margin-top: 20px;
}

.help-print-note {
    margin-top: 6px;
    font-style: italic;
}

.help-print-note kbd {
    background: #e0e0e0;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: inherit;
    font-size: 12px;
}

/* Help link in dashboard header */
.help-link {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    font-size: 18px;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
}

.help-link:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* Print styles for PDF export */
@media print {
    body {
        background: white;
        padding: 0;
    }
    .container {
        box-shadow: none;
        border-radius: 0;
    }
    .header {
        background: #1e3c72 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .help-back-link { display: none; }
    .help-print-note { display: none; }
    .help-card {
        break-inside: avoid;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .help-section { break-inside: avoid; }
    .help-table th {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .help-formula {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .help-color-green, .help-color-yellow, .help-color-orange, .help-color-red {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
}

/* =====================================================
   USER MENU (in header)
   ===================================================== */

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

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.15);
    padding: 8px 16px;
    border-radius: 20px;
}

.user-menu-name {
    font-size: 13px;
    font-weight: 600;
    color: white;
}

.user-menu-logout {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    transition: background 0.2s;
}

.user-menu-logout:hover {
    background: rgba(255, 255, 255, 0.25);
    color: white;
}

/* =====================================================
   RESPONSIVE — Tablet (≤ 1024px)
   ===================================================== */
@media (max-width: 1024px) {
    .header { padding: 20px 25px; }
    .config-panel { padding: 20px 25px; }
    .results-container { padding: 20px 25px; }
    .systemic-controls { padding: 20px 25px 15px; }
    .systemic-chart-wrapper { padding: 20px 25px; }
    .riskgauge-controls { padding: 20px 25px 15px; }
    .riskgauge-content { padding: 20px 25px; }
    .portfolio-controls { padding: 20px 25px 15px; }
    .portfolio-content { padding: 20px 25px; }
    .tab-navigation { padding: 0 25px; }
}

/* =====================================================
   RESPONSIVE — Phone / Small tablet (≤ 768px)
   ===================================================== */
@media (max-width: 768px) {
    html, body {
        padding: 0;
        max-width: 100vw;
        width: 100%;
        overflow-x: clip;
    }

    .container {
        border-radius: 0;
        box-shadow: none;
        max-width: 100vw;
        width: 100%;
    }

    /* Header */
    .header {
        flex-direction: column;
        gap: 12px;
        text-align: center;
        padding: 15px;
    }
    .header h1 { font-size: 24px; }
    .header-right { flex-wrap: wrap; justify-content: center; }

    /* Tab navigation — horizontal scroll */
    .tab-navigation {
        padding: 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    .tab-navigation::-webkit-scrollbar { display: none; }
    .tab-btn {
        padding: 10px 16px;
        font-size: 13px;
        flex-shrink: 0;
        white-space: nowrap;
    }

    /* Config panel */
    .config-panel {
        grid-template-columns: 1fr;
        padding: 15px;
        gap: 15px;
    }
    .config-section { padding: 15px; }

    /* Results */
    .results-container { padding: 15px; gap: 15px; min-width: 0; }
    .signal-panel { padding: 18px; }
    .signal-header h2 { font-size: 18px; }
    .metric-value { font-size: 20px; }

    /* Metrics panel */
    .metrics-panel { padding: 15px; }
    .metrics-panel h2 { font-size: 18px; margin-bottom: 15px; }

    /* Metrics grid — single column on phone */
    .metrics-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    .big-number {
        font-size: 22px;
        word-break: break-all;
        overflow-wrap: break-word;
    }
    .metric-card {
        padding: 15px;
        min-width: 0;
    }
    .metric-card h3 { font-size: 14px; margin-bottom: 10px; }
    .metric-detail { font-size: 12px; }

    /* GSSA grid — single column on phone */
    .gssa-grid {
        grid-template-columns: 1fr !important;
        gap: 12px;
    }
    .gssa-value { font-size: 20px; }

    /* Charts — reduce min-heights, contain overflow for table scroll */
    .chart-container {
        padding: 15px;
        min-width: 0;
        max-width: 100%;
        overflow: hidden;
    }
    .chart-container h2 { font-size: 16px; }
    .chart-container canvas { max-height: 300px; }
    .systemic-chart-container { min-height: 280px; }
    .systemic-chart-container canvas { min-height: 260px; max-height: 400px; }
    .riskgauge-chart-container { min-height: 250px; }
    .riskgauge-chart-container canvas { min-height: 230px; max-height: 380px; }

    /* Systemic & Risk Gauge */
    .systemic-controls { padding: 15px; }
    .systemic-controls h2 { font-size: 18px; }
    .systemic-chart-wrapper { padding: 15px; }
    .systemic-actions {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .riskgauge-controls { padding: 15px; }
    .riskgauge-content { padding: 15px; }

    /* DEFCON */
    .defcon-summary { flex-direction: column; }
    .defcon-panel { padding: 15px; min-width: 0; overflow: hidden; }

    /* Suggestions panel */
    .suggestions-panel { min-width: 0; overflow: hidden; }

    /* Portfolio controls */
    .portfolio-controls { padding: 15px; }
    .portfolio-controls h2 { font-size: 18px; }
    .portfolio-content {
        padding: 15px;
        gap: 15px;
        min-width: 0;
    }
    .portfolio-account-group,
    .portfolio-init-group,
    .portfolio-run-group {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .portfolio-init-group .ticker-input-field,
    .portfolio-run-group .ticker-input-field,
    .portfolio-account-group .ticker-input-field {
        width: 100% !important;
    }
    .portfolio-init-group .btn-calculate,
    .portfolio-run-group .btn-calculate,
    .portfolio-run-group .btn-add {
        width: 100%;
    }
    .portfolio-init-group label,
    .portfolio-run-group label,
    .portfolio-account-group label {
        font-size: 13px;
    }
    .portfolio-init-group input,
    .portfolio-run-group input,
    .portfolio-account-group input,
    .portfolio-init-group select,
    .portfolio-run-group select {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    /* Tables — smaller text, scroll handled by overflow-x wrapper */
    .spectral-table { font-size: 12px; }
    .spectral-table th { font-size: 10px; padding: 8px; }
    .spectral-table td { padding: 8px; }
    .defcon-table th { padding: 8px 10px; font-size: 11px; }
    .defcon-table td { padding: 8px 10px; font-size: 13px; }

    /* Modal */
    .modal-content { padding: 20px; width: 95%; }

    /* Ollama */
    .ollama-section { padding: 18px; }

    /* Auth pages */
    .auth-card { padding: 25px; margin: 0 10px; }

    /* Help page */
    .help-content { padding: 20px; }
}

/* =====================================================
   RESPONSIVE — Small phone (≤ 480px)
   ===================================================== */
@media (max-width: 480px) {
    .header h1 { font-size: 20px; }
    .subtitle { font-size: 12px; }
    .status-badge { padding: 8px 14px; font-size: 12px; }
    .user-menu { padding: 6px 12px; }
    .user-menu-name { font-size: 12px; }

    /* Tabs — even smaller */
    .tab-btn { padding: 10px 12px; font-size: 12px; }

    /* Config */
    .config-section { padding: 12px; }
    .config-section h3 { font-size: 14px; }
    .btn-calculate { padding: 12px 20px; font-size: 14px; width: 100%; }

    /* Metrics — single column */
    .metrics-grid { grid-template-columns: 1fr !important; }
    .gssa-grid { grid-template-columns: 1fr !important; }
    .metric-row { grid-template-columns: 1fr 1fr; }
    .big-number { font-size: 20px; }
    .metric-card { padding: 12px; }

    /* Betas */
    .betas-grid { grid-template-columns: 1fr 1fr; }

    /* Signal */
    .signal-header { flex-direction: column; gap: 10px; align-items: flex-start; }
    .signal-state { font-size: 14px; }

    /* Charts */
    .chart-container { padding: 12px; }
    .chart-container h2 { font-size: 15px; }

    /* Portfolio */
    .portfolio-controls { padding: 12px; }
    .portfolio-content { padding: 12px; gap: 12px; }

    /* Auth */
    .auth-card { padding: 20px; margin: 0 5px; }
    .auth-header h1 { font-size: 20px; }

    /* Help page */
    .help-content { padding: 15px; }
    .help-card { padding: 14px 16px; }
    .help-section > h2 { font-size: 18px; }
    .help-formula { font-size: 15px; padding: 10px 16px; }
    .help-table { font-size: 12px; }
    .help-table th, .help-table td { padding: 8px 10px; }
}
