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

body {
    font-family: system-ui, -apple-system, sans-serif;
    background: #f8fafc;
    color: #1e293b;
    min-height: 100vh;
    line-height: 1.5;
}

/* Top Navigation */
.top-nav {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0 1.5rem;
    height: 56px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    z-index: 200;
}

.top-nav .brand {
    font-weight: 700;
    font-size: 1.15rem;
    color: #2563eb;
    text-decoration: none;
    margin-right: 0.5rem;
    white-space: nowrap;
}

.nav-links {
    display: flex;
    gap: 0.25rem;
}

.nav-links a {
    color: #64748b;
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}

.nav-links a:hover {
    background: #f1f5f9;
    color: #1e293b;
}

.nav-links a.active {
    background: #eff6ff;
    color: #2563eb;
    font-weight: 600;
}

.nav-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-right input {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    color: #1e293b;
    padding: 0.4rem 0.75rem;
    border-radius: 0.375rem;
    font-size: 0.85rem;
    width: 150px;
    transition: width 0.3s, border-color 0.2s;
}

.nav-right input:focus {
    outline: none;
    border-color: #2563eb;
    width: 200px;
}

.nav-right input::placeholder {
    color: #94a3b8;
}

#notif-bell {
    text-decoration: none;
    font-size: 1.2rem;
    position: relative;
}

#notif-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    background: #dc2626;
    color: #fff;
    font-size: 0.65rem;
    padding: 1px 4px;
    border-radius: 9999px;
    font-weight: 700;
    display: none;
}

/* Mobile hamburger */
.hamburger {
    display: none;
    background: none;
    border: none;
    color: #64748b;
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 0.375rem;
    line-height: 1;
}

.hamburger:hover {
    background: #f1f5f9;
    color: #1e293b;
}

/* Legacy sidebar/topbar - hide */
.sidebar, .sidebar-overlay, .topbar, nav { display: none; }

/* Main content */
main {
    max-width: 1100px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

h1 {
    margin-bottom: 1.25rem;
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
}

h2 {
    margin-bottom: 0.75rem;
    font-size: 1.15rem;
    font-weight: 600;
    color: #1e293b;
}

/* Cards */
.card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.card:hover {
    border-color: #cbd5e1;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: #0f172a;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}

/* Portfolio Summary */
.portfolio-summary {
    background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
    border: 1px solid #dbeafe;
}

.portfolio-summary .stat-value {
    color: #0f172a;
}

.allocation-bar {
    display: flex;
    height: 8px;
    border-radius: 4px;
    overflow: hidden;
    margin: 0.75rem 0;
    background: #e2e8f0;
}

.allocation-bar div {
    transition: width 0.3s;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}

/* Recommendation Cards */
.recommendation-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-left: 4px solid #94a3b8;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.5rem;
}

.recommendation-card.buy {
    border-left-color: #16a34a;
    background: #f0fdf4;
}

.recommendation-card.sell {
    border-left-color: #dc2626;
    background: #fef2f2;
}

.recommendation-card.hold {
    border-left-color: #f59e0b;
    background: #fffbeb;
}

.recommendation-card .ticker {
    font-weight: 700;
    font-size: 1rem;
    color: #0f172a;
}

.recommendation-card .action {
    font-weight: 600;
    font-size: 0.85rem;
    padding: 0.15rem 0.5rem;
    border-radius: 0.25rem;
    display: inline-block;
}

.recommendation-card .reason {
    font-size: 0.85rem;
    color: #475569;
    margin-top: 0.35rem;
}

/* Macro Grid */
.macro-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.macro-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.macro-card .macro-label {
    font-size: 0.75rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-weight: 500;
}

.macro-card .macro-value {
    font-size: 1.25rem;
    font-weight: 700;
    color: #0f172a;
    margin-top: 0.25rem;
}

.macro-card .macro-date {
    font-size: 0.7rem;
    color: #94a3b8;
}

/* Holdings Table */
.holdings-table {
    width: 100%;
    border-collapse: collapse;
}

.holdings-table thead {
    background: #f8fafc;
}

.holdings-table th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0;
}

.holdings-table td {
    padding: 0.6rem 0.75rem;
    font-size: 0.88rem;
    border-bottom: 1px solid #f1f5f9;
}

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

.holdings-table a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 600;
}

.holdings-table a:hover {
    text-decoration: underline;
}

/* News Impact Cards */
.news-impact-card {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 0.75rem 0;
    border-bottom: 1px solid #f1f5f9;
}

.news-impact-card:last-child {
    border-bottom: none;
}

.impact-icon {
    font-size: 1.1rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
}

.news-impact-card .news-title {
    font-weight: 500;
    font-size: 0.88rem;
    color: #1e293b;
    line-height: 1.4;
}

.news-impact-card .news-meta {
    font-size: 0.78rem;
    color: #94a3b8;
    margin-top: 0.25rem;
}

.news-impact-card .affected-tickers {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.25rem;
    flex-wrap: wrap;
}

.ticker-tag {
    background: #eff6ff;
    color: #2563eb;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
}

/* Tab Bar */
.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e2e8f0;
    margin-bottom: 1.25rem;
}

.tab-bar button {
    background: none;
    border: none;
    color: #64748b;
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: color 0.15s, border-color 0.15s;
    border-radius: 0;
}

.tab-bar button:hover {
    color: #1e293b;
    background: none;
}

.tab-bar button.active {
    color: #2563eb;
    border-bottom-color: #2563eb;
    font-weight: 600;
    background: none;
}

.tab-content {
    display: none;
}

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

/* Link more */
.link-more {
    display: inline-block;
    margin-top: 0.75rem;
    color: #2563eb;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}

.link-more:hover {
    text-decoration: underline;
}

/* Forms */
.form-row {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.form-group label {
    font-size: 0.8rem;
    color: #64748b;
    font-weight: 500;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="date"],
select {
    background: #ffffff;
    border: 1px solid #d1d5db;
    color: #1e293b;
    padding: 0.6rem 0.9rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s;
    min-width: 180px;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="password"]:focus,
input[type="date"]:focus,
select:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

input::placeholder {
    color: #94a3b8;
}

textarea {
    background: #ffffff;
    border: 1px solid #d1d5db;
    color: #1e293b;
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.95rem;
    outline: none;
    resize: vertical;
    width: 100%;
    min-height: 80px;
    font-family: inherit;
    transition: border-color 0.2s;
}

textarea:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Buttons */
button, .btn {
    background: #2563eb;
    color: #fff;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s;
    white-space: nowrap;
}

button:hover, .btn:hover {
    background: #1d4ed8;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger { background: #dc2626; }
.btn-danger:hover { background: #b91c1c; }
.btn-secondary { background: #6b7280; }
.btn-secondary:hover { background: #4b5563; }
.btn-success { background: #16a34a; }
.btn-success:hover { background: #15803d; }

.btn-outline {
    background: transparent;
    border: 1px solid #d1d5db;
    color: #374151;
}

.btn-outline:hover {
    background: #f3f4f6;
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: #ffffff;
    border-radius: 0.75rem;
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

thead {
    background: #f8fafc;
}

th {
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.75rem;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 2px solid #e2e8f0;
}

td {
    padding: 0.75rem 1rem;
    font-size: 0.9rem;
    border-bottom: 1px solid #f1f5f9;
}

tbody tr {
    transition: background 0.15s;
}

tbody tr:hover {
    background: #f8fafc;
}

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.badge-positive { background: #dcfce7; color: #16a34a; }
.badge-negative { background: #fee2e2; color: #dc2626; }
.badge-neutral { background: #f1f5f9; color: #64748b; }

/* Stat values */
.stat-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: #0f172a;
}

.stat-label {
    font-size: 0.78rem;
    color: #64748b;
    margin-top: 0.25rem;
}

.stat-change {
    font-size: 0.9rem;
    font-weight: 600;
}

.text-positive { color: #16a34a; }
.text-negative { color: #dc2626; }
.text-neutral { color: #6b7280; }

/* Filter buttons */
.filter-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.filter-btn {
    background: #ffffff;
    color: #64748b;
    border: 1px solid #e2e8f0;
    padding: 0.4rem 1rem;
    border-radius: 9999px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
}

.filter-btn:hover {
    border-color: #cbd5e1;
    color: #1e293b;
    background: #f8fafc;
}

.filter-btn.active {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

/* Loading */
.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #94a3b8;
    padding: 2rem 0;
}

.spinner {
    width: 1.25rem;
    height: 1.25rem;
    border: 2px solid #e2e8f0;
    border-top-color: #2563eb;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #94a3b8;
}

/* Messages */
.message {
    padding: 1rem;
    border-radius: 0.5rem;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.message-success {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #16a34a;
}

.message-error {
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #dc2626;
}

/* Signal badges */
.signal-buy { background: #dcfce7; color: #16a34a; padding: 0.3rem 0.8rem; border-radius: 9999px; font-weight: 700; font-size: 0.85rem; }
.signal-sell { background: #fee2e2; color: #dc2626; padding: 0.3rem 0.8rem; border-radius: 9999px; font-weight: 700; font-size: 0.85rem; }
.signal-hold { background: #fef3c7; color: #d97706; padding: 0.3rem 0.8rem; border-radius: 9999px; font-weight: 700; font-size: 0.85rem; }

/* Indicators grid */
.indicators-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.75rem;
}

.indicator-item {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.75rem;
    text-align: center;
}

.indicator-value {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
}

.indicator-label {
    font-size: 0.75rem;
    color: #64748b;
    margin-top: 0.25rem;
}

/* Chart container */
.chart-container {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 0.75rem;
    position: relative;
    height: 250px;
}

.candlestick-chart-wrap {
    width: 100%;
    height: 400px;
    margin-top: 0.75rem;
    border-radius: 0.5rem;
    overflow: hidden;
}

/* News card */
.news-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    margin-bottom: 0.75rem;
    transition: border-color 0.2s;
}

.news-card:hover {
    border-color: #cbd5e1;
}

.news-card .news-title {
    font-weight: 600;
    color: #0f172a;
    margin-bottom: 0.5rem;
    font-size: 0.95rem;
    line-height: 1.4;
}

.news-card .news-meta {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    font-size: 0.8rem;
    color: #94a3b8;
}

.news-card a {
    color: #2563eb;
    text-decoration: none;
}

.news-card a:hover {
    text-decoration: underline;
}

/* Result block / Query */
.result-block {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-top: 1rem;
    font-size: 0.9rem;
    line-height: 1.6;
    overflow-x: auto;
}

.result-block .md-h2 { margin: 1rem 0 0.5rem; font-size: 1.1rem; color: #0f172a; }
.result-block .md-h3 { margin: 0.75rem 0 0.5rem; font-size: 1rem; color: #1e293b; }
.result-block .md-li { margin-left: 1.5rem; list-style: disc; }
.result-block .md-li-num { margin-left: 1.5rem; list-style: decimal; }
.result-block .md-warning {
    margin-top: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 0.375rem;
    color: #b45309;
    font-size: 0.85rem;
}

/* Tooltips */
.tooltip-wrap { position: relative; display: inline-block; }

.tooltip-icon {
    display: inline-block;
    width: 1rem; height: 1rem; line-height: 1rem;
    text-align: center; font-size: 0.65rem; font-weight: 700;
    color: #94a3b8; background: #e2e8f0;
    border-radius: 50%; cursor: help;
    margin-left: 0.35rem; vertical-align: middle;
}

.tooltip-icon:hover { color: #1e293b; background: #cbd5e1; }

.tooltip-text {
    visibility: hidden; opacity: 0;
    position: absolute; bottom: calc(100% + 8px);
    left: 50%; transform: translateX(-50%);
    background: #0f172a; color: #e2e8f0;
    border: 1px solid #334155; border-radius: 0.5rem;
    padding: 0.5rem 0.75rem; font-size: 0.75rem;
    font-weight: 400; line-height: 1.4;
    white-space: normal; width: max-content; max-width: 260px;
    z-index: 100; pointer-events: none;
    transition: opacity 0.15s, visibility 0.15s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

.tooltip-text::after {
    content: ""; position: absolute; top: 100%; left: 50%;
    transform: translateX(-50%);
    border-width: 5px; border-style: solid;
    border-color: #334155 transparent transparent transparent;
}

.tooltip-wrap:hover .tooltip-text { visibility: visible; opacity: 1; }

/* Indicator explanation */
.indicator-explain {
    margin-top: 1rem;
    border-top: 1px solid #e2e8f0;
    padding-top: 0.75rem;
}

.indicator-explain summary {
    cursor: pointer; font-size: 0.85rem;
    color: #64748b; font-weight: 500;
    user-select: none; list-style: none;
    display: flex; align-items: center; gap: 0.4rem;
}

.indicator-explain summary::-webkit-details-marker { display: none; }
.indicator-explain summary::before { content: "\25B6"; font-size: 0.6rem; transition: transform 0.2s; }
.indicator-explain[open] summary::before { transform: rotate(90deg); }

.indicator-explain .explain-body {
    margin-top: 0.75rem; padding: 0.75rem 1rem;
    background: #f8fafc; border: 1px solid #e2e8f0;
    border-radius: 0.5rem; font-size: 0.8rem;
    line-height: 1.7; color: #475569;
}

.indicator-explain .explain-body ul { list-style: none; padding: 0; margin: 0.25rem 0 0 0; }
.indicator-explain .explain-body li { padding: 0.15rem 0; }

/* Action row */
.action-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

/* Auto-refresh toggle */
.auto-refresh-toggle {
    display: flex; align-items: center; gap: 0.5rem;
    color: #64748b; font-size: 0.9rem;
    cursor: pointer; margin-bottom: 1rem;
}
.auto-refresh-toggle input[type="checkbox"] {
    accent-color: #2563eb;
    width: 1rem; height: 1rem;
}

/* Chart bars */
.chart-bar-wrap {
    display: flex; align-items: flex-end;
    gap: 1px; height: 200px; padding-top: 0.5rem;
}
.chart-bar { flex: 1; min-width: 2px; border-radius: 1px 1px 0 0; cursor: crosshair; }
.chart-bar:hover { opacity: 0.8; }
.chart-labels {
    display: flex; justify-content: space-between;
    margin-top: 0.5rem; font-size: 0.7rem; color: #94a3b8;
}

/* Plan page specific */
.plan-section {
    margin-bottom: 1.5rem;
}

.plan-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #e2e8f0;
}

.plan-action-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.plan-action-card .ticker-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.plan-action-card .price-info {
    text-align: right;
    font-size: 0.85rem;
    color: #475569;
}

/* Settings page */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    .nav-links { display: none; }
    .hamburger { display: block; }
    .nav-right input { width: 100px; }
    .nav-right input:focus { width: 140px; }

    /* Mobile nav dropdown */
    .nav-links.open {
        display: flex;
        flex-direction: column;
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        background: #ffffff;
        border-bottom: 1px solid #e2e8f0;
        padding: 0.5rem;
        box-shadow: 0 4px 12px rgba(0,0,0,0.08);
        z-index: 199;
    }

    main { padding: 0.75rem; }
    h1 { font-size: 1.2rem; margin-bottom: 0.75rem; }

    .card { padding: 0.75rem; }
    .card-grid { grid-template-columns: 1fr; }
    .macro-grid { grid-template-columns: repeat(2, 1fr); }
    .indicators-grid { grid-template-columns: repeat(2, 1fr); }
    .summary-grid { grid-template-columns: repeat(2, 1fr); }

    table, .table-wrap {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    th, td { padding: 0.5rem 0.75rem; font-size: 0.85rem; white-space: nowrap; }

    .form-row { flex-direction: column; gap: 0.5rem; }
    .form-group { width: 100%; }
    input, select, textarea { font-size: 16px; }
    input[type="text"], input[type="number"] { min-width: unset; width: 100%; }

    .filter-bar { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 0.25rem; }
    .filter-btn { white-space: nowrap; flex-shrink: 0; }

    .action-row { flex-direction: column; gap: 0.5rem; }
    .action-row button { width: 100%; }

    .stat-value { font-size: 1.1rem; }

    .candlestick-chart-wrap, .chart-container { min-height: 200px; }

    .news-card { padding: 0.75rem; }
    .news-meta { flex-wrap: wrap; gap: 0.25rem; }

    .tab-bar { overflow-x: auto; }
    .tab-bar button { white-space: nowrap; flex-shrink: 0; }

    .settings-grid { grid-template-columns: 1fr; }
}
