/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    background: #F5F5F3;
    color: #1A1A18;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Navbar */
.navbar {
    background: #1A1A18;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand { display: flex; align-items: center; gap: 10px; }
.brand-icon { font-size: 20px; }
.brand-name { font-size: 18px; font-weight: 600; color: #FFFFFF; letter-spacing: -0.3px; }
.brand-sub { font-size: 12px; color: #888780; border-left: 1px solid #333; padding-left: 10px; margin-left: 4px; }
.nav-links { display: flex; gap: 4px; }
.nav-link { color: #B0AEA8; text-decoration: none; padding: 8px 16px; border-radius: 6px; font-size: 14px; font-weight: 500; transition: all 0.15s; }
.nav-link:hover { color: #FFFFFF; background: #2A2A28; }
.nav-link.active { color: #FFFFFF; background: #2E5E4A; }

/* Main */
.main-content { flex: 1; padding: 24px; max-width: 1400px; width: 100%; margin: 0 auto; }

/* Summary bar */
.summary-bar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.summary-item { background: #FFFFFF; border: 0.5px solid #E0DED8; border-radius: 10px; padding: 12px 20px; display: flex; flex-direction: column; gap: 2px; min-width: 120px; }
.summary-label { font-size: 11px; color: #888780; font-weight: 500; }
.summary-value { font-size: 22px; font-weight: 600; color: #1A1A18; }
.highlight-buy  { border-left: 3px solid #1D9E75; }
.highlight-hold { border-left: 3px solid #BA7517; }
.highlight-sell { border-left: 3px solid #E24B4A; }
.highlight-buy  .summary-value { color: #0F6E52; }
.highlight-hold .summary-value { color: #854F0B; }
.highlight-sell .summary-value { color: #B01C1C; }

/* Strategy note */
.strategy-note { background: #EAF3F0; border: 0.5px solid #A8D4C4; border-radius: 8px; padding: 10px 16px; font-size: 12px; color: #1B6B4A; margin-bottom: 20px; }

/* Table wrapper */
.table-wrapper { background: #FFFFFF; border: 0.5px solid #E0DED8; border-radius: 12px; overflow-x: auto; margin-bottom: 24px; }
.section-title { font-size: 13px; font-weight: 600; color: #595957; margin-bottom: 10px; padding-left: 2px; }

/* Tables */
.signals-table, .breakdown-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.signals-table th, .breakdown-table th { text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 600; color: #888780; text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid #F0EEE8; white-space: nowrap; background: #FAFAF8; }
.signals-table td, .breakdown-table td { padding: 10px 12px; border-bottom: 0.5px solid #F0EEE8; white-space: nowrap; vertical-align: middle; }
.signals-table tr:last-child td, .breakdown-table tr:last-child td { border-bottom: none; }
.signals-table tr:hover td { background: #FAFAF8; }

/* Row tinting */
.row-strong-buy td { background: #F4FBF8; }
.row-buy        td { background: #FAFDF9; }
.row-reduce     td { background: #FFFAF9; }
.row-swp        td { background: #FEF5F5; }
.signals-table tr.row-strong-buy:hover td { background: #EAF6F1; }
.signals-table tr.row-swp:hover td { background: #FDE8E8; }

/* Cell styles */
.rank { color: #B0AEA8; font-weight: 500; width: 36px; }
.index-name strong { font-size: 13px; }
.center { text-align: center; }
.muted { color: #888780; }
.fund-name { font-size: 11px; color: #595957; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos { color: #0F6E52; font-weight: 500; }
.neg { color: #B01C1C; font-weight: 500; }

/* Score bar */
.score-bar-wrap { display: flex; flex-direction: column; gap: 3px; min-width: 80px; }
.score-val { font-size: 12px; font-weight: 600; }
.score-bar { height: 4px; background: #F0EEE8; border-radius: 2px; overflow: hidden; }
.score-fill { height: 100%; border-radius: 2px; }
.score-fill.strong-buy { background: #1D9E75; }
.score-fill.buy        { background: #5DCAA5; }
.score-fill.hold       { background: #BA7517; }
.score-fill.reduce     { background: #E07A3A; }
.score-fill.swp        { background: #E24B4A; }

/* Badges */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge-strong-buy { background: #D6EFE5; color: #085041; }
.badge-buy        { background: #E8F7F2; color: #0F6E52; }
.badge-hold       { background: #FEF3CD; color: #7B4F00; }
.badge-reduce     { background: #FDEEE5; color: #8B3A10; }
.badge-swp        { background: #FDEAEA; color: #B01C1C; }

/* Mini bars */
.mini-bar-wrap { display: flex; align-items: center; gap: 8px; }
.mini-bar-wrap span { font-size: 12px; width: 36px; flex-shrink: 0; }
.mini-bar { flex: 1; height: 6px; background: #F0EEE8; border-radius: 3px; overflow: hidden; min-width: 60px; }
.mini-bar div { height: 100%; border-radius: 3px; }

/* Index sub label */
.index-id-sub { font-size: 10px; color: #B0AEA8; margin-top: 2px; font-weight: 400; }

/* Tooltip */
.tooltip-wrap { position: relative; display: inline-block; cursor: default; }
.fund-short { font-size: 11px; color: #595957; border-bottom: 1px dashed #B0AEA8; }
.tooltip-text { visibility: hidden; opacity: 0; background: #1A1A18; color: #FFFFFF; font-size: 12px; padding: 6px 10px; border-radius: 6px; position: absolute; z-index: 200; bottom: 125%; left: 0; white-space: nowrap; transition: opacity 0.15s; pointer-events: none; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.tooltip-text::after { content: ""; position: absolute; top: 100%; left: 14px; border: 5px solid transparent; border-top-color: #1A1A18; }
.tooltip-wrap:hover .tooltip-text { visibility: visible; opacity: 1; }

/* Refresh button */
.refresh-btn { display: inline-block; margin-top: 4px; background: #1A1A18; color: #FFFFFF; text-decoration: none; padding: 5px 12px; border-radius: 6px; font-size: 12px; font-weight: 500; transition: background 0.15s; }
.refresh-btn:hover { background: #2E5E4A; }

/* Flash messages */
.flash-success { background: #D6EFE5; border: 0.5px solid #5DCAA5; color: #085041; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }
.flash-error { background: #FDEAEA; border: 0.5px solid #F09595; color: #B01C1C; padding: 10px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; }

/* Coming soon */
.coming-soon { background: #FFFFFF; border: 0.5px solid #E0DED8; border-radius: 12px; padding: 60px; text-align: center; }
.coming-soon h2 { font-size: 22px; margin-bottom: 12px; color: #1A1A18; }
.coming-soon p { color: #888780; font-size: 15px; }

/* Footer */
.footer { background: #F0EEE8; border-top: 0.5px solid #E0DED8; padding: 12px 24px; text-align: center; font-size: 11px; color: #B0AEA8; }

/* Responsive */
@media (max-width: 768px) {
    .main-content { padding: 12px; }
    .brand-sub { display: none; }
    .nav-link { padding: 8px 10px; font-size: 13px; }
    .summary-bar { gap: 8px; }
    .summary-item { min-width: 90px; padding: 10px 14px; }
    .summary-value { font-size: 18px; }
}

/* ── Portfolio form ─────────────────────────────────────────── */
.form-card {
    background: #FFFFFF;
    border: 0.5px solid #E0DED8;
    border-radius: 12px;
    padding: 24px;
    margin-bottom: 24px;
}
.form-title {
    font-size: 15px;
    font-weight: 600;
    color: #1A1A18;
    margin-bottom: 16px;
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px;
    margin-bottom: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { font-size: 11px; font-weight: 600; color: #888780; text-transform: uppercase; letter-spacing: 0.04em; }
.form-group input,
.form-group select {
    padding: 8px 10px;
    border: 0.5px solid #D0CEC8;
    border-radius: 6px;
    font-size: 13px;
    background: #FAFAF8;
    color: #1A1A18;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus { border-color: #1D9E75; background: #FFFFFF; }

.form-actions { display: flex; gap: 10px; }
.btn-primary { background: #1A1A18; color: #FFFFFF; border: none; padding: 8px 20px; border-radius: 6px; font-size: 13px; font-weight: 500; cursor: pointer; transition: background 0.15s; }
.btn-primary:hover { background: #2E5E4A; }
.btn-secondary { background: transparent; color: #595957; border: 0.5px solid #D0CEC8; padding: 8px 20px; border-radius: 6px; font-size: 13px; cursor: pointer; }
.btn-secondary:hover { background: #F0EEE8; }

/* ── Exit zone badges ───────────────────────────────────────── */
.exit-zone {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
}
.zone-0 { background: #E8F7F2; color: #0F6E52; }
.zone-1 { background: #FEF9E5; color: #7B5A00; }
.zone-2 { background: #FEF3CD; color: #7B4F00; }
.zone-3 { background: #FDEEE5; color: #8B3A10; }
.zone-4 { background: #FDEAEA; color: #B01C1C; }

/* ── Charts ─────────────────────────────────────────────────── */
.charts-row {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}
.chart-card {
    background: #FFFFFF;
    border: 0.5px solid #E0DED8;
    border-radius: 12px;
    padding: 20px;
}
.chart-title {
    font-size: 13px;
    font-weight: 600;
    color: #595957;
    margin-bottom: 14px;
}
.form-hint {
    font-size: 12px;
    color: #888780;
    line-height: 1.7;
    margin-bottom: 4px;
}
@media (max-width: 900px) {
    .charts-row { grid-template-columns: 1fr; }
}

/* ── Fund comparison panel ──────────────────────────────────── */
.expand-cell { width: 28px; text-align: center; }
.expand-arrow { font-size: 10px; color: #B0AEA8; transition: color 0.15s; }
.signal-row:hover .expand-arrow { color: #1D9E75; }

.fund-panel td { padding: 0 !important; }
.fund-panel-inner {
    background: #F8FAF9;
    border-top: 2px solid #1D9E75;
    border-bottom: 1px solid #E0DED8;
    padding: 16px 20px;
}
.fund-panel-title {
    font-size: 13px;
    font-weight: 600;
    color: #1A1A18;
    margin-bottom: 12px;
}

.fund-compare-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.fund-compare-table th {
    text-align: left;
    padding: 6px 10px;
    font-size: 10px;
    font-weight: 600;
    color: #888780;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom: 1px solid #E0DED8;
    background: #F0F0EE;
    white-space: nowrap;
}
.fund-compare-table td {
    padding: 8px 10px;
    border-bottom: 0.5px solid #EEECEA;
    vertical-align: middle;
}
.fund-compare-table tr:last-child td { border-bottom: none; }
.fund-compare-table tr:hover td { background: #FFFFFF; }

.primary-row td { background: #F0FBF6; }
.primary-row:hover td { background: #E5F8EF !important; }
.primary-row td:first-child { color: #0F6E52; font-size: 14px; }

/* Fund type badges */
.type-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    white-space: nowrap;
}
.type-index    { background: #E6F1FB; color: #185FA5; }
.type-active   { background: #EAF3F0; color: #1B6B4A; }
.type-flexicap { background: #FAEEDA; color: #7B4F00; }
.type-multicap { background: #EDE8FB; color: #4A3A8A; }

/* Primary fund highlight in main table */
.primary-fund { 
    font-weight: 500; 
    color: #0F6E52;
    border-bottom: 1px dashed #5DCAA5;
}

/* ── Fund search dropdown ───────────────────────────────────── */
.search-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #FFFFFF;
    border: 0.5px solid #D0CEC8;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    z-index: 500;
    max-height: 320px;
    overflow-y: auto;
    margin-top: 2px;
}
.search-item {
    padding: 10px 14px;
    cursor: pointer;
    border-bottom: 0.5px solid #F0EEE8;
    transition: background 0.1s;
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: #F4FBF8; }
.search-item-warn { background: #FFFBF4; }
.search-item-warn:hover { background: #FEF3CD; }
.search-name { font-size: 13px; font-weight: 500; color: #1A1A18; }
.search-meta { font-size: 11px; color: #888780; margin-top: 2px; }

.selected-fund-box {
    padding: 8px 10px;
    border: 0.5px solid #D0CEC8;
    border-radius: 6px;
    background: #FAFAF8;
    font-size: 13px;
    min-height: 38px;
    display: flex;
    align-items: center;
}
.selected-fund-active {
    border-color: #1D9E75;
    background: #F4FBF8;
}

/* ── Edit button in holdings table ─────────────────────────── */
.edit-btn {
    background: none;
    border: 0.5px solid #D0CEC8;
    border-radius: 4px;
    color: #888780;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
    transition: all 0.15s;
}
.edit-btn:hover {
    background: #1D9E75;
    border-color: #1D9E75;
    color: #FFFFFF;
}
