/* ==========================================================================
   Craxarc Lab - Global Stylesheet (Refactored)
   Structure:
   1. Variables
   2. Base
   3. Layout
   4. Components
   5. Specific Tools (DCF, Kelly)
   6. Media Queries (Mobile RWD)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Variables (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
    --bg-color: #f4f6f8;
    --sidebar-bg: #18181b;
    --panel-bg: #ffffff;
    --text-main: #27272a;
    --text-muted: #71717a;
    --border-color: #e4e4e7;
    --primary: #18181b;
    --accent: #18181b;
    --success: #10b981;
    --danger: #ef4444;
    --greedy: #e67e22;
    --shadow: rgba(0, 0, 0, 0.05);
}

/* --------------------------------------------------------------------------
   2. Base
   -------------------------------------------------------------------------- */
body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-color);
    color: var(--text-main);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex; /* Sidebar layout */
}

/* --------------------------------------------------------------------------
   3. Layout
   -------------------------------------------------------------------------- */
.sidebar {
    width: 260px;
    background-color: var(--sidebar-bg);
    color: #fff;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}
.sidebar-header {
    padding: 24px 20px;
    font-size: 1.5rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}
.nav-menu {
    flex: 1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.nav-item {
    padding: 12px 24px;
    color: #a1a1aa;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}
.nav-item:hover {
    background-color: rgba(255, 255, 255, 0.05);
    color: #fff;
}
.nav-item.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    border-left-color: #fff;
}
.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.8rem;
    color: #a1a1aa;
    text-align: center;
}

.main-content {
    flex: 1;
    padding: 40px;
    height: 100vh;
    overflow-y: auto;
    box-sizing: border-box;
}

/* Mobile Navbar & Backdrop (Hidden on Desktop) */
.mobile-navbar {
    display: none;
}
.sidebar-backdrop {
    display: none;
}

/* --------------------------------------------------------------------------
   4. Components (Reusable UI)
   -------------------------------------------------------------------------- */
.tool-section {
    display: none;
    animation: fadeIn 0.3s ease-out forwards;
}
.tool-section.active {
    display: block;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Common styles for Info Icons */
.info-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    flex-shrink: 0;
    padding: 2px;
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s;
}
.info-icon:hover { 
    color: var(--accent); 
    background-color: rgba(0, 0, 0, 0.05); 
}

/* Lucide Icon Vertical Align */
.lucide {
    vertical-align: middle;
}

/* Tooltip popup (from DCF) */
.tooltip-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; z-index: 99;
}
.tooltip-box {
    display: none; position: absolute; background: #ffffff; border: 1px solid var(--border-color);
    padding: 12px 16px; border-radius: 8px; font-size: 0.875rem; color: var(--text-main);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1); z-index: 100; max-width: 250px;
    line-height: 1.5; pointer-events: none;
}

/* Modal styles (from Kelly) */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.5); z-index: 1000;
}
.modal-overlay.active { display: flex; justify-content: center; align-items: center; }
.modal-content {
    background: #fff; padding: 25px; border-radius: 12px; width: 90%; max-width: 600px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2); max-height: 90vh; overflow-y: auto; position: relative;
}
.modal-content h3 { margin-top: 0; color: var(--primary); border-bottom: 1px solid var(--border-color); padding-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.modal-close { background: none; border: none; font-size: 1.5em; cursor: pointer; color: var(--text-muted); }
.modal-close:hover { color: var(--danger); }

/* --------------------------------------------------------------------------
   5. Specific Tools
   -------------------------------------------------------------------------- */

/* DCF Styles (namespaced with #discounted-cash-flow) */
#discounted-cash-flow .container {
    display: grid; grid-template-columns: 1fr 1fr; gap: 40px; max-width: 1200px; width: 100%; margin: 0 auto;
}
#discounted-cash-flow .panel {
    background: var(--panel-bg); border: 1px solid var(--border-color); border-radius: 20px; padding: 30px; box-shadow: 0 10px 30px -10px var(--shadow);
}
#discounted-cash-flow h2 {
    margin-top: 0; font-weight: 600; font-size: 1.5rem; margin-bottom: 24px; border-bottom: 1px solid var(--border-color); padding-bottom: 16px; color: var(--text-main);
}
#discounted-cash-flow .form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
#discounted-cash-flow .form-group { display: flex; flex-direction: column; position: relative; }
#discounted-cash-flow .form-group.full-width { grid-column: span 2; }
#discounted-cash-flow label { font-size: 0.875rem; color: var(--text-muted); margin-bottom: 8px; display: flex; align-items: center; font-weight: normal; }
#discounted-cash-flow input {
    background: #fafafa; border: 1px solid var(--border-color); border-radius: 8px;
    padding: 12px 16px; color: var(--text-main); font-size: 1rem; transition: all 0.3s;
    width: 100%; box-sizing: border-box;
}
#discounted-cash-flow input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(39, 39, 42, 0.1); }
#discounted-cash-flow .result-box {
    background: #fafafa; border: 1px solid var(--border-color); border-radius: 12px;
    padding: 24px; margin-bottom: 20px; text-align: center; transition: transform 0.3s ease;
}
#discounted-cash-flow .result-box:hover { transform: translateY(-2px); }
#discounted-cash-flow .result-label { font-size: 1rem; color: var(--text-muted); margin-bottom: 8px; }
#discounted-cash-flow .result-value { font-size: 3rem; font-weight: 700; margin-bottom: 8px; }
#discounted-cash-flow .result-change { font-size: 1.25rem; font-weight: 600; }
#discounted-cash-flow .up { color: var(--success); }
#discounted-cash-flow .down { color: var(--danger); }
#discounted-cash-flow .slider-container { margin-top: 30px; }
#discounted-cash-flow .slider-header { display: flex; justify-content: space-between; margin-bottom: 12px; }
#discounted-cash-flow .slider-value { font-size: 1.5rem; font-weight: 600; color: var(--accent); }
#discounted-cash-flow input[type=range] { -webkit-appearance: none; width: 100%; background: transparent; padding: 0; }
#discounted-cash-flow input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none; height: 20px; width: 20px; border-radius: 50%;
    background: var(--accent); cursor: pointer; margin-top: -8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); transition: transform 0.1s;
}
#discounted-cash-flow input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.2); }
#discounted-cash-flow input[type=range]::-webkit-slider-runnable-track { width: 100%; height: 4px; cursor: pointer; background: #d4d4d8; border-radius: 2px; }
#discounted-cash-flow .metrics-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 24px; border-top: 1px solid var(--border-color); padding-top: 20px; }
#discounted-cash-flow .metric-card { background: #fafafa; border: 1px solid var(--border-color); border-radius: 8px; padding: 12px; transition: background 0.3s ease; }
#discounted-cash-flow .metric-card:hover { background: #f4f4f5; }
#discounted-cash-flow .metric-label { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 4px; }
#discounted-cash-flow .metric-value { font-size: 1.125rem; font-weight: 600; color: var(--text-main); }


/* RiskBalanceTool Styles (namespaced with #kelly-equity-risk) */
#kelly-equity-risk .container {
    max-width: 1400px; margin: 0 auto; line-height: 1.6;
}
#kelly-equity-risk .main-layout { display: flex; gap: 25px; align-items: flex-start; }
#kelly-equity-risk .left-col { flex: 1.5; min-width: 0; }
#kelly-equity-risk .right-col { flex: 1; min-width: 0; }
#kelly-equity-risk h2, #kelly-equity-risk h3 { margin-top: 0; color: var(--primary); border-bottom: 2px solid var(--border-color); padding-bottom: 6px; }
#kelly-equity-risk .grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
#kelly-equity-risk .grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 15px; }
#kelly-equity-risk .input-group { margin-bottom: 10px; display: flex; flex-direction: column; }
#kelly-equity-risk label { display: block; font-weight: bold; margin-bottom: 5px; color: #34495e; font-size: 0.9em; }
#kelly-equity-risk input[type="number"], #kelly-equity-risk input[type="text"] {
    width: 100%; padding: 8px; border: 1px solid var(--border-color); border-radius: 6px; font-size: 15px; box-sizing: border-box; transition: border-color 0.3s;
}
#kelly-equity-risk input:focus { border-color: var(--accent); outline: none; }
#kelly-equity-risk .desc { font-size: 0.8em; color: var(--text-muted); margin-top: 4px; }
#kelly-equity-risk .summary-dashboard { background: var(--primary); color: white; padding: 15px 20px; border-radius: 12px; margin-bottom: 15px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); }
#kelly-equity-risk .summary-dashboard h3 { border-bottom-color: #4a6582; color: white; }
#kelly-equity-risk .kpi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
#kelly-equity-risk .kpi-card { background: rgba(255,255,255,0.1); padding: 20px; border-radius: 8px; text-align: center; }
#kelly-equity-risk .kpi-title { font-size: 0.9em; opacity: 0.8; margin-bottom: 5px; }
#kelly-equity-risk .kpi-value { font-size: 2.5em; font-weight: bold; margin: 0; line-height: 1; }
#kelly-equity-risk .kpi-safe { color: var(--success); }
#kelly-equity-risk .kpi-warn { color: #f1c40f; }
#kelly-equity-risk .kpi-danger { color: var(--danger); }
#kelly-equity-risk .unified-row { display: flex; gap: 25px; align-items: stretch; margin-bottom: 10px; transition: transform 0.2s ease, opacity 0.2s ease; position: relative; }
#kelly-equity-risk .unified-row.dragging { opacity: 0.5; border: 2px dashed var(--accent); transform: scale(0.99); border-radius: 8px; }
#kelly-equity-risk .unified-row.drag-over-top::before { content: ""; position: absolute; top: -7px; left: 0; width: 100%; height: 4px; background-color: var(--accent); border-radius: 2px; z-index: 10; }
#kelly-equity-risk .unified-row.drag-over-bottom::after { content: ""; position: absolute; bottom: -7px; left: 0; width: 100%; height: 4px; background-color: var(--accent); border-radius: 2px; z-index: 10; }
#kelly-equity-risk .asset-block { background: #fdfdfd; border: 1px solid var(--border-color); padding: 12px 15px; border-radius: 8px; border-left: 4px solid var(--accent); height: 100%; box-sizing: border-box; }
#kelly-equity-risk .asset-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
#kelly-equity-risk .asset-title { font-weight: bold; font-size: 1.1em; color: var(--primary); display: flex; align-items: center; gap: 10px; }
#kelly-equity-risk .drag-handle { color: #bdc3c7; font-size: 1.3em; cursor: grab; padding-right: 5px; user-select: none; }
#kelly-equity-risk .drag-handle:active { cursor: grabbing; color: var(--accent); }
#kelly-equity-risk .asset-title input { width: 150px; padding: 5px 10px; font-weight: bold; color: var(--primary); }
#kelly-equity-risk .btn-remove { background: #fee; color: var(--danger); border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 0.9em; font-weight: bold; }
#kelly-equity-risk .btn-remove:hover { background: var(--danger); color: white; }
#kelly-equity-risk .btn-copy { background: #e0f2fe; color: #0284c7; border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 0.9em; font-weight: bold; margin-right: 5px; transition: background 0.3s; }
#kelly-equity-risk .btn-copy:hover { background: #bae6fd; }
#kelly-equity-risk .btn-helper { background: var(--bg-color); color: var(--accent); border: none; padding: 6px 12px; border-radius: 4px; cursor: pointer; font-size: 0.9em; font-weight: bold; margin-right: 5px; transition: background 0.3s; }
#kelly-equity-risk .btn-helper:hover { background: var(--accent); color: white; }
#kelly-equity-risk .btn-add { display: block; width: 100%; background: var(--bg-color); color: var(--accent); border: 2px dashed var(--accent); padding: 10px; text-align: center; font-size: 1.1em; font-weight: bold; border-radius: 8px; cursor: pointer; transition: background 0.3s; margin-bottom: 15px; }
#kelly-equity-risk .btn-add:hover { background: var(--border-color); }
#kelly-equity-risk .btn-add:disabled { background: #eee; color: #aaa; border-color: #ccc; cursor: not-allowed; }
#kelly-equity-risk .result-block { background: #fff; border: 1px solid var(--border-color); padding: 12px 15px; border-radius: 8px; height: 100%; box-sizing: border-box; display: flex; flex-direction: column; justify-content: center; }
#kelly-equity-risk .bars-wrapper { display: flex; flex-direction: column; gap: 12px; }
#kelly-equity-risk .bar-row { display: flex; flex-direction: column; gap: 4px; }
#kelly-equity-risk .res-label { font-size: 0.85em; color: var(--text-muted); display: flex; justify-content: space-between; font-weight: bold; }
#kelly-equity-risk .res-bar-container { background: #eef2f5; height: 12px; border-radius: 6px; overflow: hidden; width: 100%; }
#kelly-equity-risk .res-bar { height: 100%; width: 0%; transition: width 0.5s ease, background-color 0.5s ease; }
#kelly-equity-risk .res-bar.proportional { background: var(--accent); }
#kelly-equity-risk .res-pct { font-weight: bold; }
#kelly-equity-risk .res-pct.proportional { color: var(--accent); }
#kelly-equity-risk .res-zero { color: #95a5a6 !important; }
#kelly-equity-risk .res-bar.zero-bar { background: #ccc !important; }
#kelly-equity-risk .explanation-box { background: #fdfbf7; padding: 25px; border-radius: 8px; border-left: 5px solid #f39c12; font-size: 0.95em; height: 100%; box-sizing: border-box; }
#kelly-equity-risk .explanation-box h4 { color: #d35400; margin-top: 0; margin-bottom: 15px; font-size: 1.1em; }
#kelly-equity-risk .explanation-box ul { padding-left: 20px; margin: 0; }
#kelly-equity-risk .explanation-box li { margin-bottom: 15px; }
#kelly-equity-risk .explanation-box li:last-child { margin-bottom: 0; }
#kelly-equity-risk .noscript-warning { background: var(--danger); color: white; padding: 15px; text-align: center; font-weight: bold; margin-bottom: 20px; border-radius: 8px; }
#kelly-equity-risk .toggle-container { display: flex; align-items: center; gap: 8px; font-size: 0.95em; font-weight: bold; flex-shrink: 0; white-space: nowrap; }
#kelly-equity-risk .toggle-switch { position: relative; width: 44px; height: 24px; display: inline-block; flex-shrink: 0; }
#kelly-equity-risk .toggle-switch input { opacity: 0; width: 0; height: 0; }
#kelly-equity-risk .slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #bdc3c7; transition: .3s; border-radius: 24px; }
#kelly-equity-risk .slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
#kelly-equity-risk input:checked + .slider { background-color: var(--success); }
#kelly-equity-risk input:checked + .slider:before { transform: translateX(20px); }

/* --------------------------------------------------------------------------
   6. Media Queries (Mobile RWD overrides)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    /* Global Layout Overrides */
    body {
        flex-direction: column;
    }
    
    .main-content {
        padding: 20px; /* Reduce padding on mobile */
        height: auto;
        overflow-y: visible;
    }

    /* Sidebar Drawer Overrides */
    .sidebar {
        position: fixed;
        left: -260px;
        z-index: 1000;
        transition: left 0.3s ease;
        height: 100vh;
    }
    .sidebar.open {
        left: 0;
    }
    
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    .sidebar-backdrop.active {
        display: block;
        opacity: 1;
    }
    
    .mobile-navbar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
        background-color: var(--sidebar-bg);
        border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        position: sticky;
        top: 0;
        z-index: 900;
        width: 100%;
        box-sizing: border-box;
    }
    .mobile-nav-title {
        font-weight: bold;
        font-size: 1.2rem;
        color: #ffffff;
    }
    .hamburger-btn {
        background: none;
        border: none;
        padding: 0;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Sub-page (Specific Tools) Responsive Adjustments */
    
    /* DCF Mobile */
    #discounted-cash-flow .container,
    #discounted-cash-flow .form-grid,
    #discounted-cash-flow .metrics-grid {
        grid-template-columns: 1fr;
    }
    #discounted-cash-flow .form-group.full-width {
        grid-column: span 1;
    }

    /* Kelly Mobile */
    #kelly-equity-risk .grid-2 {
        grid-template-columns: 1fr;
    }
    #kelly-equity-risk .grid-4 {
        grid-template-columns: 1fr 1fr;
    }
    #kelly-equity-risk .main-layout,
    #kelly-equity-risk .unified-row {
        flex-direction: column;
    }

    /* Hide button text on mobile to save space */
    .btn-text {
        display: none;
    }
    .btn-helper i, .btn-copy i, .btn-remove i {
        margin-right: 0 !important;
    }
}
