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

:root {
    --bg-0: #0a0e17;
    --bg-1: #0f1520;
    --bg-2: #151d2c;
    --bg-3: #1c2738;
    --border: #243049;
    --border-light: #2d3d57;
    --text-primary: #e8ecf2;
    --text-secondary: #8b98b0;
    --text-muted: #586880;
    --accent: #22d3a7;
    --accent-dim: rgba(34, 211, 167, 0.12);
    --accent-hover: #1bc49a;
    --red: #ef4444;
    --red-dim: rgba(239, 68, 68, 0.12);
    --orange: #f59e0b;
    --blue: #3b82f6;
    --blue-dim: rgba(59, 130, 246, 0.12);
    --font-body: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.3);
}

html { font-size: 15px; }
body {
    font-family: var(--font-body);
    background: var(--bg-0);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* === HEADER === */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}
.header-left { display: flex; align-items: center; gap: 1rem; }
.logo { display: flex; align-items: center; gap: 0.5rem; }
.logo-icon { font-size: 1.4rem; color: var(--accent); }
.logo-text { font-weight: 700; font-size: 1.1rem; letter-spacing: -0.02em; }
.logo-tag {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    background: var(--bg-3);
    padding: 2px 6px;
    border-radius: 4px;
}
.header-nav { display: flex; gap: 2px; }
.nav-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    cursor: pointer;
    border-radius: 6px;
    transition: all 0.15s;
}
.nav-btn:hover { color: var(--text-primary); background: var(--bg-2); }
.nav-btn.active { color: var(--accent); background: var(--accent-dim); }
.header-right { display: flex; align-items: center; gap: 0.5rem; }
.status-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}
.status-dot.active { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.status-label { font-size: 0.75rem; color: var(--text-muted); font-family: var(--font-mono); }

/* === SEARCH === */
.search-bar {
    padding: 1.2rem 1.5rem;
    background: var(--bg-1);
    border-bottom: 1px solid var(--border);
}
.search-container {
    max-width: 680px;
    margin: 0 auto;
    display: flex;
    gap: 0.5rem;
}
.search-container input {
    flex: 1;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
    text-transform: uppercase;
}
.search-container input::placeholder {
    text-transform: none;
    color: var(--text-muted);
    font-family: var(--font-body);
}
.search-container input:focus { border-color: var(--accent); }

/* === BUTTONS === */
.btn-primary {
    background: var(--accent);
    color: var(--bg-0);
    border: none;
    border-radius: var(--radius);
    padding: 0.7rem 1.5rem;
    font-family: var(--font-body);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }

/* === MAIN === */
.main-content {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 1.5rem;
}

/* === WELCOME === */
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 1rem;
    text-align: center;
}
.welcome-icon { font-size: 3rem; color: var(--accent); margin-bottom: 1.5rem; opacity: 0.6; }
.welcome-state h2 { font-weight: 600; margin-bottom: 0.5rem; }
.welcome-state p { color: var(--text-secondary); max-width: 480px; margin-bottom: 2rem; line-height: 1.6; }
.quick-tickers { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center; }
.ticker-pill {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: 0.4rem 0.9rem;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.15s;
}
.ticker-pill:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-dim);
}

/* === LOADING / ERROR === */
.loading-state, .error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 4rem 1rem;
    text-align: center;
}
.spinner {
    width: 32px; height: 32px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 1rem;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-state p { color: var(--text-secondary); }
.loading-dots::after { content: ''; animation: dots 1.5s steps(4, end) infinite; }
@keyframes dots {
    0% { content: ''; }
    25% { content: '.'; }
    50% { content: '..'; }
    75% { content: '...'; }
}
.error-state p { color: var(--red); }
.hidden { display: none !important; }

/* === RESULTS === */
.results-container { animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* === STOCK HEADER === */
.stock-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1.5rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}
.stock-name h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.stock-ticker {
    font-family: var(--font-mono);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 500;
}
.price-value {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

/* === INFO GRID === */
.info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 0.75rem;
    margin-bottom: 2rem;
}
.info-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.info-label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.info-value { font-size: 1rem; font-weight: 600; }

/* === SECTION TITLES === */
.section-title {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* === RATIOS GRID === */
.ratios-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.5rem;
}
.ratio-item {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
}
.ratio-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ratio-value { font-family: var(--font-mono); font-size: 1rem; font-weight: 600; margin-top: 0.2rem; }
.ratio-value.positive { color: var(--accent); }
.ratio-value.negative { color: var(--red); }

/* === VALUATION FORM === */
.valuation-form {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    margin-bottom: 1.5rem;
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: flex-end;
}
.form-row { display: flex; flex-direction: column; gap: 0.3rem; flex: 1; min-width: 180px; }
.form-row label { font-size: 0.75rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.form-row input {
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.6rem 0.8rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
}
.form-row input:focus { border-color: var(--accent); }
.valuation-results { min-height: 120px; }

/* === VALUATION RESULT CARDS === */
.val-card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    margin-bottom: 0.75rem;
}
.val-card h4 {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 0.75rem;
}
.val-card .val-main {
    font-family: var(--font-mono);
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--accent);
}
.val-detail { font-size: 0.85rem; color: var(--text-secondary); margin-top: 0.5rem; line-height: 1.5; }
.val-detail pre {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    background: var(--bg-3);
    padding: 0.75rem;
    border-radius: 6px;
    overflow-x: auto;
    margin-top: 0.5rem;
    white-space: pre-wrap;
}

/* === PERIOD SELECTOR === */
.period-selector { display: flex; gap: 4px; margin-bottom: 1rem; }
.period-btn {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.35rem 0.8rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s;
}
.period-btn:hover { border-color: var(--accent); color: var(--accent); }
.period-btn.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* === CHART === */
.chart-container {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1rem;
    margin-bottom: 1.5rem;
    height: 360px;
}

/* === INDICATORS GRID === */
.indicators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.5rem;
}

/* === AI CHAT === */
.ai-chat { margin-bottom: 1.5rem; }
.ai-input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}
.ai-input-group input {
    flex: 1;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.7rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
}
.ai-input-group input:focus { border-color: var(--accent); }
.ai-presets { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.preset-btn {
    background: var(--bg-2);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 0.78rem;
    padding: 0.3rem 0.7rem;
    border-radius: 16px;
    cursor: pointer;
    transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.ai-results {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    min-height: 120px;
    line-height: 1.7;
    white-space: pre-wrap;
    font-size: 0.9rem;
}

/* === PORTFOLIO === */
.portfolio-form { margin-bottom: 1.5rem; }
.form-help { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.5rem; }
.portfolio-form textarea {
    width: 100%;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.8rem 1rem;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    outline: none;
    resize: vertical;
    margin-bottom: 0.75rem;
}
.portfolio-form textarea:focus { border-color: var(--accent); }
.portfolio-results {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    min-height: 100px;
}

/* === MUTED TEXT === */
.muted { color: var(--text-muted); font-size: 0.85rem; }

/* === FOOTER === */
.footer {
    text-align: center;
    padding: 1.5rem;
    border-top: 1px solid var(--border);
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
    .header { flex-wrap: wrap; height: auto; padding: 0.75rem; gap: 0.5rem; }
    .header-nav { order: 3; width: 100%; overflow-x: auto; gap: 0; }
    .nav-btn { font-size: 0.78rem; padding: 0.4rem 0.7rem; }
    .main-content { padding: 1rem; }
    .stock-header { flex-direction: column; gap: 0.5rem; }
    .valuation-form { flex-direction: column; }
    .ai-input-group { flex-direction: column; }
}
