/* ------------------------------------------------------------
   1. THEME CONFIGURATION
   ------------------------------------------------------------ */
:root {
    /* Shared/Static Colors */
    --success:      #34d399;
    --danger:       #f87171;
    --coffee:       #FF5E5B; /* Ko-fi brand color approx */
}

/* THEME 1: DARK (Default Slate) */
[data-theme="dark"] {
    --bg-body:      #0f172a;        
    --bg-panel:     #1e293b;        
    --bg-input:     #334155;        
    --bg-chart:     #0b1120;
    --text-main:    #f1f5f9;        
    --text-muted:   #94a3b8;        
    --accent:       #38bdf8;            
    --border:       #334155;
    --chart-grid:   rgba(255,255,255,0.05);
    --chart-fill:   rgba(56, 189, 248, 0.15);
    --overlay:      rgba(0, 0, 0, 0.7);
}

/* THEME 2: LIGHT (Corporate) */
[data-theme="light"] {
    --bg-body:      #f1f5f9;
    --bg-panel:     #ffffff;
    --bg-input:     #e2e8f0;
    --bg-chart:     #e2e8f0;
    --text-main:    #0f172a;
    --text-muted:   #64748b;
    --accent:       #0284c7; 
    --border:       #cbd5e1;
    --chart-grid:   rgba(0,0,0,0.05);
    --chart-fill:   rgba(2, 132, 199, 0.15);
    --overlay:      rgba(255, 255, 255, 0.8);
}

/* THEME 3: CYBER (High Contrast/Purple) */
[data-theme="cyber"] {
    --bg-body:      #11001c; 
    --bg-panel:     #240046; 
    --bg-input:     #3c096c; 
    --bg-chart:     #10002b;
    --text-main:    #e0aaff;
    --text-muted:   #9d4edd;
    --accent:       #ff006e; 
    --border:       #5a189a;
    --chart-grid:   rgba(224, 170, 255, 0.1);
    --chart-fill:   rgba(255, 0, 110, 0.15);
    --overlay:      rgba(17, 0, 28, 0.9);
}

/* ------------------------------------------------------------
   2. RESET & LAYOUT
   ------------------------------------------------------------ */
* { box-sizing: border-box; transition: background-color 0.3s, color 0.3s, border-color 0.3s; }

body {
    font-family: 'Inter', sans-serif;
    margin: 0;
    background-color: var(--bg-body);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden; /* Desktop only - Mobile override below */
}

/* ------------------------------------------------------------
   3. SIDEBAR LAYOUT & INPUTS
   ------------------------------------------------------------ */
.sidebar {
    width: 320px;
    background-color: var(--bg-body);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 5;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--border);
    text-align: center;
    position: relative; 
}

.sidebar-header h1 {
    color: var(--text-main);
    font-size: 1.4rem;
    margin: 0 0 5px 0;
    font-weight: 700;
}

.subheading {
    font-size: 0.7rem;
    color: var(--text-muted);
    line-height: 1.3;
    margin-bottom: 15px;
    padding: 0 10px;
}

.equation-wrapper {
    font-size: 0.75rem; 
    color: var(--text-muted);
    margin-top: 5px;
    padding: 10px;
    background: var(--bg-panel); 
    border-radius: 8px;
    border: 1px solid var(--border);
    overflow-x: auto; 
    text-align: center;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Scrollbar Styling */
.sidebar-content::-webkit-scrollbar { width: 6px; }
.sidebar-content::-webkit-scrollbar-track { background: var(--bg-body); }
.sidebar-content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Typography for Sections */
.section-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    margin-top: 25px;
    margin-bottom: 12px;
    font-weight: 700;
}
.section-title:first-child { margin-top: 0; }

/* Custom Header Wrapper for the Withdrawal Curve line */
.section-header-wrapper {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0; /* Reset since it's the first element */
    margin-bottom: 12px;
}
.section-header-wrapper .section-title {
    margin: 0; /* Remove margin as wrapper handles it */
}

/* Inline Help Icon for Section Headers */
.inline-help-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: var(--bg-input);
    color: var(--text-muted);
    
    cursor: pointer;
    transition: all 0.2s ease;
}

.inline-help-icon:hover {
    background-color: var(--accent);
    color: var(--bg-body);
}

.inline-help-icon svg {
    width: 15px;
    height: 15px;
}

/* Input Elements */
.input-grid {
    display: grid;
    grid-template-columns: 1fr 90px;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}

.input-grid label {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.input-grid input, .input-grid select {
    background-color: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--text-main);
    border-radius: 4px;
    padding: 6px 4px 6px 8px;
    font-size: 0.85rem;
    text-align: right;
    outline: none;
    font-family: monospace;
    width: 100%;
    -moz-appearance: textfield;
}

input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.theme-grid {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}
.theme-select {
    text-align: left !important;
    cursor: pointer;
}

/* Dynamic Input Areas */
.dynamic-wrapper {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 10px;
    display: none;
}
.dynamic-wrapper.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

/* Action Buttons */
.cta-container {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: var(--bg-body);
}

button {
    width: 100%;
    background-color: var(--accent);
    color: var(--bg-body); 
    border: none;
    padding: 14px;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity 0.2s;
}
button:hover { opacity: 0.9; }
button:disabled { background-color: var(--text-muted); cursor: not-allowed; }

/* ------------------------------------------------------------
   4. MAIN CONTENT AREA
   ------------------------------------------------------------ */
.main-content {
    flex: 1;
    overflow-y: auto;
    padding: 30px 30px 10px 30px;
    display: flex;
    flex-direction: column;
    gap: 25px;
    background-color: var(--bg-chart);
    position: relative;
}

/* ------------------------------------------------------------
   5. COMPONENTS: STAT CARDS
   ------------------------------------------------------------ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.stat-card {
    background: var(--bg-panel);
    padding: 25px;
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    border: 1px solid var(--border);
    text-align: center;
    position: relative; /* For icon positioning */
}

.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; letter-spacing: 0.05em; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--text-main); margin: 8px 0; }
.stat-sub { font-size: 0.85rem; color: var(--accent); font-weight: 500;}

/* ------------------------------------------------------------
   6. COMPONENTS: CHART
   ------------------------------------------------------------ */
.chart-container {
    background: var(--bg-panel);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    height: 600px; 
    position: relative;
    width: 100%;
}

.loading-overlay {
    position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.7);
    backdrop-filter: blur(2px);
    display: flex; justify-content: center; align-items: center;
    border-radius: 12px; z-index: 20; display: none;
    color: var(--accent); font-weight: 600; font-size: 1.1rem;
}

canvas#cowsChart { width: 100% !important; height: 100% !important; }

/* ------------------------------------------------------------
   7. COMPONENTS: DATA TABLE
   ------------------------------------------------------------ */
.table-wrapper { display: flex; justify-content: center; }

.table-container {
    background: var(--bg-panel);
    padding: 20px;
    padding-right: 35px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    overflow-x: auto;
    width: fit-content;
    max-width: 100%;
    position: relative; /* For icon positioning */
}

table { border-collapse: collapse; font-size: 0.85rem; margin: 0 auto; }
th { text-align: right; padding: 10px 15px; background-color: var(--bg-body); color: var(--text-muted); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 15px; border-bottom: 1px solid var(--border); color: var(--text-main); text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr:hover td { background-color: var(--bg-input); }

/* ------------------------------------------------------------
   8. HELP ICONS & POPUPS
   ------------------------------------------------------------ */
.help-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    z-index: 10;
}

.table-container .help-icon {
    top: 25px;
    right: 5px;
}

.help-icon:hover {
    background: var(--accent);
    color: var(--bg-body);
}

.help-icon svg {
    width: 16px;
    height: 16px;
}

/* Footer Links */
.footer-links {
    margin-top: auto;
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 15px;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding: 0;
    border-top: 1px solid transparent;
}

.footer-links span {
    cursor: pointer;
    text-decoration: underline;
    transition: color 0.2s;
}

.footer-links span:hover {
    color: var(--accent);
}

.coffee-link {
    font-weight: 700;
    color: var(--text-main);
    text-decoration: underline;
    display: inline-flex;
    align-items: center;
    transition: transform 0.2s;
}
.coffee-link:hover {
    transform: scale(1.05);
    color: var(--accent);
}

.footer-separator {
    width: 1px;
    background: var(--text-muted);
    height: 12px;
    display: inline-block;
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--overlay);
    z-index: 1000;
    display: none;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
    animation: fadeIn 0.3s ease;
}

.modal-content {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    width: 100%;
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
    padding: 30px;
    border-radius: 12px;
    position: relative;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    color: var(--text-main);
}

.close-btn {
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.close-btn:hover { color: var(--danger); }

.modal-body h2 { margin-top: 0; color: var(--accent); font-size: 1.2rem; }
.modal-body h3 { font-size: 1rem; color: var(--text-main); margin-top: 20px; border-bottom: 1px solid var(--border); padding-bottom: 5px; }
.modal-body p, .modal-body ul, .modal-body dl { font-size: 0.9rem; line-height: 1.6; color: var(--text-muted); }
.modal-body strong { color: var(--text-main); font-weight: 600; }

/* Definitions List Styling */
.modal-body dt { color: var(--accent); font-weight: 700; margin-top: 12px; font-size: 0.9rem; }
.modal-body dd { margin-left: 0; margin-bottom: 8px; color: var(--text-muted); }

.disclaimer { background: rgba(248, 113, 113, 0.1); border: 1px solid var(--danger); padding: 10px; border-radius: 6px; font-size: 0.8rem; margin-top: 20px; color: var(--text-main); }


/* ------------------------------------------------------------
   9. MOBILE RESPONSIVENESS
   ------------------------------------------------------------ */

/* New Mobile Toggle Button Styles */
.mobile-toggle-btn {
    display: none; /* Hidden on desktop */
    width: 100%;
    padding: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    color: var(--accent);
    text-align: center;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 10px;
    border-radius: 6px;
}

@media (max-width: 960px) {
    
    body {
        flex-direction: column; 
        height: auto; 
        overflow-x: hidden; 
        overflow-y: auto; 
    }

    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-content {
        display: none; 
        padding-bottom: 0;
    }
    
    .sidebar-content.show-mobile {
        display: block;
    }

    .mobile-toggle-btn {
        display: block;
    }

    .cta-container {
       display: block;
       padding: 10px 20px 20px 20px; 
       border-top: none; 
   }
    
    .main-content {
        width: 100%;
        height: auto;
        overflow: visible;
        padding: 15px;
    }

    .stats-grid {
        grid-template-columns: 1fr; 
        gap: 10px;
    }

    .chart-container {
        height: 400px;
        padding: 10px;
    }

    .footer-links {
        flex-wrap: wrap;
        justify-content: center;
        margin-top: 30px;
    }
}