:root{--accent:#2b7cff;--muted:#6b7280;--deplete:#ffe5e5}
html,body{height:100%;margin:0;font-family:Inter,system-ui,Segoe UI,Roboto,Arial;background:linear-gradient(180deg,#f7fafc 0,#fff 100%);color:#0b1220}

.page-header {
    text-align: center;
    padding: 25px 20px 5px;
    background: transparent;
}

.page-header h1 {
    font-size: 32px;
    font-weight: 800;
    margin: 0;
    background: linear-gradient(135deg, #1e293b 0%, #2b7cff 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.02em;
}

.page-header .tagline {
    font-size: 14px;
    color: var(--muted);
    margin: 4px 0 0;
    font-weight: 400;
}

.wrap{max-width:1000px;margin:15px auto 40px;padding:20px;border-radius:12px;background:white;box-shadow:0 6px 30px rgba(7,10,25,0.08)}
h1{margin:0 0 18px;font-size:20px}
.grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(220px,1fr));gap:14px;margin-bottom:20px}
.grid-2x3{display:grid;grid-template-columns:repeat(3,1fr);gap:14px;margin-bottom:20px}
.slider-item.empty{}
label{display:block;font-size:12px;color:var(--muted);margin-bottom:6px}
input[type=range]{width:100%;max-width:220px;margin:5px 0}
.value-display{font-weight:600;color:var(--accent);font-size:14px;margin-left:5px}
.editable-value{
    font-weight: 600;
    color: var(--accent);
    font-size: 14px;
    margin-left: 5px;
    border: 1px solid transparent;
    border-bottom: 1px dashed var(--accent);
    background: transparent;
    padding: 0 4px;
    width: 100px;
    outline: none;
    transition: all 0.2s;
}
.editable-value:focus {
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: white;
}
.hint{font-size:13px;color:#9ca3af;margin-top:6px; line-height:1.4;}
.hint-detail {
    display: block;
}
.divider{border:none;border-top:1px solid #e5e7eb;margin:20px 0}
.tabContainer{border:1px solid #e5e7eb;border-radius:10px;position:relative}
.tabHeader{display:flex;background:#f9fafb;border-bottom:1px solid #e5e7eb;border-radius:10px 10px 0 0}
.tabHeader div{padding:10px 18px;cursor:pointer;font-size:14px}
.tabHeader div:first-child{border-radius:10px 0 0 0}
.tabHeader .active{background:white;font-weight:600;border-bottom:2px solid var(--accent)}

/* Primary Tabs Styling */
.primaryTabHeader {
    display: flex;
    background: #f1f5f9;
    padding: 6px 6px 0;
    border-radius: 12px 12px 0 0;
    border: 1px solid #e2e8f0;
    border-bottom: none;
    gap: 4px;
}
.primaryTabBtn {
    padding: 12px 24px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--muted);
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
    text-decoration: none;
    display: flex;
    align-items: center;
}
.primaryTabBtn:hover {
    color: var(--accent);
    background: rgba(255,255,255,0.5);
}
.primaryTabBtn.active {
    color: var(--accent);
    background: white;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.02);
}
.primaryTabBody {
    border: 1px solid #e2e8f0;
    border-top: none;
    border-radius: 0 0 12px 12px;
    padding: 24px;
    background: white;
}
.primaryTabContent {
    display: none;
}
.primaryTabContent.active {
    display: block;
}

.tabBody{padding:18px;background:white;position:relative;border-radius:0 0 10px 10px}
.tabContent{display:none}
.tabContent.active{display:block}
canvas{margin:20px 0}
table{width:100%;border-collapse:collapse;margin-top:14px}
th,td{padding:8px 10px;border:1px solid #eef2ff;text-align:right}
th{background:#f6f9ff;font-weight:600}
td.age,th.age{text-align:center}
.depleted td{background:var(--deplete)}
.muted{color:#6b7280;font-size:13px}
button{background:var(--accent);color:#fff;padding:8px 14px;border-radius:8px;border:0;cursor:pointer}
button:disabled{opacity:.6;cursor:not-allowed}
.loaderOverlay{position:absolute;inset:0;background:rgba(255,255,255,0.8);display:flex;flex-direction:column;align-items:center;justify-content:center;z-index:10;display:none}
.spinner{width:40px;height:40px;border:4px solid #e5e7eb;border-top:4px solid var(--accent);border-radius:50%;animation:spin 1s linear infinite;margin-bottom:10px}
@keyframes spin{to{transform:rotate(360deg)}}
#mcOuterContainer { border:none !important; }
#mcOuterContainer td { border:none !important; }
#mcResultsTable, #mcPercentilesTable { font-size:13px; border-collapse:collapse; background:white; box-shadow:0 2px 8px rgba(0,0,0,0.03); margin:0; border:1px solid #93c5fd; }
#mcResultsTable th, #mcResultsTable td, #mcPercentilesTable th, #mcPercentilesTable td { padding:8px 14px; text-align:center !important; border:none !important; }
#mcResultsTable tbody tr td:first-child { background:#f3f4f6 !important; text-align:left !important; min-width:120px; font-weight:600; }
#mcPercentilesTable thead tr th { background:#f6f9ff !important; font-weight:600; }
#mcResultsTable td, #mcPercentilesTable td { font-weight:500; }
.sliderContainer { display:flex; align-items:center; gap:15px; margin:15px 0; flex-wrap:wrap; }
.sliderContainer label { font-size:13px; color:var(--muted); }
#simCountSlider { width:300px; }
#simCountValue { font-weight:600; color:var(--accent); min-width:50px; display:inline-block; }
.buttonContainer { display:flex; align-items:center; gap:20px; margin:15px 0; flex-wrap:wrap; }
#sampleTableContainer { margin-top:20px; overflow-x:auto; }
#sampleTable { width:100%; border-collapse:collapse; font-size:12px; }
#sampleTable th { background:#f0f4ff; font-weight:600; padding:8px 4px; text-align:center; border:1px solid #d0d9ff; }
#sampleTable td { padding:6px 4px; text-align:right; border:1px solid #e0e6ff; }
#sampleTable td:first-child { text-align:center; }
.radioGroup { display:flex; gap:20px; align-items:center; flex-wrap:wrap; margin:10px 0; }
.radioGroup label { font-size:13px; color:var(--muted); display:inline-flex; align-items:center; gap:4px; }
.slider-item { display:flex; flex-direction:column; }
#staticSummary {
    text-align: right;
    font-size: 14px;
    margin-bottom: 2px;
}
/* Samples slider (below chart) – hidden by default, shown after first MC run */
.samplesContainer {
    display: none;  /* hidden until simulation runs */
    align-items: center;
    justify-content: flex-end;
    gap: 15px;
    margin-top: 10px;
    margin-bottom: 5px;
}
.samplesContainer label {
    font-size: 13px;
    color: var(--muted);
}
#samplesSlider {
    width: 200px;
}
#samplesValue {
    font-weight: 600;
    color: var(--accent);
    min-width: 40px;
    display: inline-block;
    text-align: right;
}
/* Negative numbers red */
.negative { color: #dc2626; }
/* Depleted row background */
.depleted-row { background-color: #ffe5e5; }
#tableWrap table {
    font-size: 12px;
}
#tableWrap th,
#tableWrap td {
    padding: 6px 12px;
}

/* Mobile optimizations for tables */
@media (max-width: 600px) {
    .grid-2x3 {
        grid-template-columns: 1fr;
        gap: 20px;
    }
    .slider-item.empty {
        display: none;
    }
    .hint-detail {
        display: inline;
        margin-left: 4px;
    }
    input[type=range] {
        display: block;
        width: 100%;
        max-width: 100%;
    }
    label {
        width: 100%;
    }
    
    #tableWrap, #sampleTableContainer {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-left: -15px;
        width: calc(100% + 30px);
        padding: 0 5px;
    }
    
    #tableWrap table, #sampleTable {
        font-size: 9px !important; /* Super small font for mobile */
        width: 100%;
        table-layout: auto;
    }
    
    #tableWrap th, #tableWrap td, 
    #sampleTable th, #sampleTable td {
        padding: 4px 2px !important; /* Minimal padding */
        letter-spacing: -0.02em;
        white-space: nowrap;
    }

    /* Shorten some headers on mobile if possible via CSS */
    #tableWrap th:nth-child(2), #tableWrap td:nth-child(2) { /* Starting Corpus */ }
    
    /* Make the container take full width */
    .primaryTabBody {
        padding: 15px 10px;
    }
    
    .wrap {
        padding: 10px;
        margin: 5px auto;
    }
}

/* Tooltip styles */
.info-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    background: var(--muted);
    color: white;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    cursor: help;
    margin-left: 6px;
    position: relative;
    vertical-align: middle;
}

.tooltip {
    visibility: hidden;
    width: 450px;
    max-width: 80vw;
    background-color: #1f2937;
    color: #f9fafb;
    text-align: left;
    border-radius: 8px;
    padding: 14px;
    position: absolute;
    z-index: 1000;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.2s;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.3);
    font-size: 12px;
    line-height: 1.6;
    font-weight: normal;
    white-space: normal;
}

.tooltip ul {
    margin: 8px 0 0 0;
    padding-left: 18px;
}

.tooltip li {
    margin-bottom: 4px;
}

.info-icon:hover .tooltip {
    visibility: visible;
    opacity: 1;
}

/* Arrow for tooltip */
.tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: #1f2937 transparent transparent transparent;
}

/* Dashboard & Goal Tracking Styles */
.form-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(3px);
    display: none;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.form-container {
    background: #fff;
    border: none;
    border-radius: 16px;
    padding: 30px;
    width: 100%;
    max-width: 650px;
    margin: 0;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    max-height: 90vh;
    overflow-y: auto;
}
.form-grid {
    display: flex;
    flex-direction: column;
    gap: 15px;
}
.form-grid input {
    padding: 12px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
    transition: border-color 0.2s;
}
.form-grid input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(43, 124, 255, 0.1);
}
.flex-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.flex-row > * {
    flex: 1;
    min-width: 100px;
}
.allocation-input {
    background: #f8fafc;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #f1f5f9;
}
.allocation-input label {
    font-weight: 600;
    margin-bottom: 12px;
    color: #1e293b;
}
.allocation-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}
.allocation-grid div {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.allocation-grid input {
    width: 100% !important;
    text-align: center;
    padding: 8px 4px;
}
.investment-tagger {
    background: #fff;
    padding: 15px;
    border-radius: 10px;
    border: 1px solid #e2e8f0;
}
.tagger-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: #f8fafc;
    border-radius: 8px;
    margin-bottom: 8px;
    border: 1px solid #f1f5f9;
}
.remove-tag {
    cursor: pointer;
    color: #ef4444;
    font-weight: bold;
    padding: 5px;
    font-size: 18px;
    line-height: 1;
}
.add-tag-btn {
    font-size: 13px;
    background: #f1f5f9;
    color: #475569;
    border: 1px dashed #cbd5e1;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    margin-top: 5px;
    width: 100%;
    font-weight: 600;
}
.add-tag-btn:hover { background: #e2e8f0; color: var(--accent); border-color: var(--accent); }

.investment-selector-popup {
    position: absolute;
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1);
    border-radius: 12px;
    z-index: 2100;
    max-height: 300px;
    overflow-y: auto;
    width: 450px;
    max-width: 90vw;
}
.selector-item {
    padding: 12px 16px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid #f1f5f9;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
}
.selector-item:hover { background: #f8fafc; }
.selector-item:last-child { border-bottom: none; }

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 25px;
    padding-top: 20px;
    border-top: 1px solid #f1f5f9;
}
.progress-container {
    height: 6px;
    background: #e2e8f0;
    border-radius: 3px;
    overflow: hidden;
    margin: 8px 0;
}
.progress-bar {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s ease;
}
.goal-card, .investment-card {
    background: white;
    border: 1px solid #e2e8f0;
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 10px;
    position: relative;
    transition: all 0.2s;
}
.goal-card:hover, .investment-card:hover {
    border-color: var(--accent);
    box-shadow: 0 4px 12px rgba(43, 124, 255, 0.08);
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}
.card-title {
    font-weight: 700;
    color: #1e293b;
    font-size: 14px;
}
.card-amount {
    font-weight: 600;
    font-size: 14px;
}
.xirr-badge {
    display: inline-block;
    padding: 1px 6px;
    background: #ecfdf5;
    color: #065f46;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
}
.goal-alloc-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 12px;
    font-size: 11px;
    color: var(--muted);
}
.goal-alloc-items-group {
    display: flex;
    gap: 6px;
    flex-wrap: nowrap;
    overflow: hidden;
}
.goal-alloc-item {
    display: flex;
    align-items: center;
    gap: 2px;
    font-weight: 400; /* Removed bold/500 */
    white-space: nowrap;
}
.goal-alloc-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.goal-progress-info {
    flex: 1;
    text-align: right;
    font-size: 11px;
    color: var(--muted);
    min-width: 100%; 
    margin-top: 4px;
}

/* Expanded Goal Styles */
.goal-card.expanded {
    border-color: var(--accent);
    box-shadow: 0 4px 15px rgba(43, 124, 255, 0.12);
}
.expanded-content {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px solid #f1f5f9;
    overflow-x: auto;
}
.linked-inv-table {
    width: 100%;
    font-size: 11px;
    border: none;
    margin-top: 0;
}
.linked-inv-table th {
    background: #f8fafc;
    color: #64748b;
    font-weight: 600;
    text-align: left;
    padding: 6px 8px;
    border: none;
    border-bottom: 1px solid #f1f5f9;
}
.linked-inv-table td {
    padding: 8px;
    border: none;
    border-bottom: 1px solid #f8fafc;
    text-align: left;
}
.linked-inv-table tr:last-child td {
    border-bottom: none;
}
.linked-inv-table .val-col {
    text-align: right;
    font-weight: 600;
    color: #1e293b;
}

.card-amount-main {
    text-align: right; 
    font-size: 16px; 
    font-weight: 800; 
    color: var(--accent);
}
.inv-units-info {
    font-size: 12px; 
    color: var(--muted);
    margin-bottom: 4px;
}

@media (max-width: 480px) {
    .goal-alloc-items-group {
        font-size: 2.4vw; /* Dynamic size to fit 4 items on small screens */
        gap: 1.5vw;
    }
    .goal-alloc-dot {
        width: 1vw;
        height: 1vw;
    }
    .linked-inv-table {
        font-size: 9px;
    }
    .linked-inv-table th, .linked-inv-table td {
        padding: 4px;
    }
    /* Investment Selector & Tagger mobile fixes */
    .selector-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 10px 14px;
        gap: 2px;
    }
    .selector-item span:first-child {
        font-size: 13px;
    }
    .selector-item span:last-child {
        font-size: 10px !important;
    }
    
    /* Investment Card mobile fixes */
    .investment-card .card-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 2px;
    }
    .investment-card .card-amount-main {
        text-align: left;
        font-size: 15px;
    }
    .inv-card-body {
        margin-top: 6px;
    }
    
    .tagger-row {
        padding: 6px 8px;
        gap: 6px;
    }
    .tagger-row span {
        font-size: 11px !important;
    }
    .tagger-row input {
        width: 45px !important;
        padding: 2px !important;
        font-size: 11px !important;
    }
}

@media (min-width: 768px) {
    .card-title { font-size: 15px; }
    .card-amount { font-size: 15px; }
    .goal-alloc-row { font-size: 12px; }
    .goal-alloc-items-group { gap: 12px; }
    .goal-progress-info { 
        min-width: auto; 
        margin-top: 0;
    }
    .goal-alloc-item { gap: 5px; }
    .goal-alloc-dot { width: 8px; height: 8px; }
    .xirr-badge { font-size: 11px; }
    .linked-inv-table { font-size: 12px; }
}
.add-btn-subtle {
    width: 100%;
    padding: 12px;
    background: #fff;
    color: #64748b;
    border: 2px dashed #e2e8f0;
    border-radius: 10px;
    font-weight: 600;
    margin-top: 10px;
    cursor: pointer;
    transition: all 0.2s;
}
.add-btn-subtle:hover {
    background: #f8fafc;
    color: var(--accent);
    border-color: var(--accent);
}
.goal-card, .investment-card {
    cursor: pointer;
    user-select: none;
}
/* Toggle Switch */
.nav-toggle-container {
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-toggle-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
}
.switch {
  position: relative;
  display: inline-block;
  width: 34px;
  height: 20px;
}
.switch input { 
  opacity: 0;
  width: 0;
  height: 0;
}
.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #e2e8f0;
  transition: .4s;
}
.slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
}
input:checked + .slider {
  background-color: var(--accent);
}
input:checked + .slider:before {
  transform: translateX(14px);
}
.slider.round {
  border-radius: 34px;
}
.slider.round:before {
  border-radius: 50%;
}
.mf-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.2s;
}
.mf-result-item:hover {
    background: #f8fafc;
}
.mf-result-item:last-child {
    border-bottom: none;
}
.mf-result-name {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    display: block;
    margin-bottom: 2px;
}
.mf-result-code {
    font-size: 11px;
    color: var(--muted);
}
.live-status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #10b981;
    border-radius: 50%;
    margin-left: 6px;
    margin-right: 3px;
    vertical-align: middle;
    box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
}
.live-status-text {
    font-size: 9px;
    font-weight: 700;
    color: #059669;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.surplus-text {
    color: #059669;
    font-weight: 600;
    font-size: 10px;
}

/* Toast/Error notification system */
#toastContainer {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: #ef4444; /* Default to error red */
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    font-size: 14px;
    font-weight: 600;
    pointer-events: auto;
    animation: slideIn 0.3s ease-out, shake 0.5s ease-in-out;
    max-width: 350px;
}

.toast.success {
    background: #10b981;
    animation: slideIn 0.3s ease-out; /* No shake for success */
}

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

@keyframes fadeOut {
    from { opacity: 1; transform: scale(1); }
    to { opacity: 0; transform: scale(0.95); }
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.toast.fade-out {
    animation: fadeOut 0.3s ease-in forwards;
}

.mobile-only { display: none; }
@media (max-width: 600px) {
    .mobile-only { display: inline; }
    .desktop-only { display: none; }
}