/* Google Fonts */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-color: #0f1115;
    --card-bg: rgba(255, 255, 255, 0.03);
    --card-border: rgba(255, 255, 255, 0.08);
    --primary: #7c3aed;
    /* Violet */
    --secondary: #10b981;
    /* Emerald */
    --accent: #f43f5e;
    /* Rose */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --gradient-1: linear-gradient(135deg, #7c3aed 0%, #2563eb 100%);
    --glass: blur(12px);
    --radius: 16px;
    --shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
}

body.light-mode {
    --bg-color: #f8fafc;
    /* Slate 50 */
    --card-bg: rgba(255, 255, 255, 0.85);
    --card-border: rgba(203, 213, 225, 0.6);
    /* Slate 300 */
    --text-primary: #1e293b;
    /* Slate 800 */
    --text-secondary: #64748b;
    /* Slate 500 */
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.05);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    /* Fixed height */
    overflow: hidden;
    /* Prevent body scroll */
    background-image:
        radial-gradient(circle at 15% 50%, rgba(124, 58, 237, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(16, 185, 129, 0.08), transparent 25%);
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.light-mode select,
body.light-mode input {
    background: white;
    border-color: var(--card-border);
    color: var(--text-primary);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

body.light-mode .stat-card:hover {
    border-color: var(--primary);
    transform: translateY(-4px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.05);
}

/* Layout */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 2rem;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 2rem;
    backdrop-filter: var(--glass);
    display: flex;
    flex-direction: column;
    gap: 2rem;
    height: calc(100vh - 4rem);
    position: sticky;
    top: 2rem;
    overflow-y: auto;
    /* Allow sidebar scrolling */
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
}

.sidebar::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, Opera */
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-1);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 1rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

select,
input {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 0.75rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: all 0.3s ease;
}

select:focus,
input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(124, 58, 237, 0.2);
}

button.btn-primary {
    background: var(--gradient-1);
    color: white;
    border: none;
    padding: 0.875rem;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, opacity 0.2s;
}

button.btn-primary:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

/* Main Content */
.main-content {
    display: flex;
    flex-direction: column;
    gap: 2.5rem;
    overflow-y: auto;
    padding-right: 0.5rem;
    scrollbar-width: none;
    /* Firefox */
    -ms-overflow-style: none;
    /* IE and Edge */
}

.main-content::-webkit-scrollbar {
    display: none;
    /* Chrome, Safari, Opera */
}

/* Header Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    backdrop-filter: var(--glass);
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-4px);
    border-color: rgba(255, 255, 255, 0.15);
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
}

.stat-trend {
    font-size: 0.875rem;
    margin-top: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.trend-up {
    color: var(--secondary);
}

.trend-down {
    color: var(--accent);
}

/* Hedging Strategy Section */
.strategy-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.strategy-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1rem;
    transition: transform 0.2s;
}

.strategy-card:hover {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.05);
}

.strategy-title {
    font-size: 0.85rem;
    color: var(--secondary);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.strategy-value {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.strategy-sub {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.tag-best {
    color: var(--secondary);
    font-size: 0.7rem;
    border: 1px solid var(--secondary);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 0.5rem;
}

.tag-worst {
    color: var(--accent);
    font-size: 0.7rem;
    border: 1px solid var(--accent);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 0.5rem;
}

/* Charts Section */
.chart-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    backdrop-filter: var(--glass);
    min-height: 450px;
    /* Increased slightly */
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Prevent spillover */
    position: relative;
    z-index: 1;
    /* Establish stacking context */
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-title {
    font-size: 1.25rem;
    font-weight: 600;
}

/* Portfolio Section */
.portfolio-section {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 2rem;
    backdrop-filter: var(--glass);
}

.risk-meter {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    margin-top: 1rem;
    overflow: hidden;
}

/* Data Table */
.table-wrapper {
    overflow-x: auto;
    margin-top: 1rem;
}

.history-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.95rem;
}

.history-table th {
    text-align: right;
    padding: 1rem;
    color: var(--text-secondary);
    font-weight: 600;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 2px solid var(--card-border);
    white-space: nowrap;
}

.history-table th:first-child {
    text-align: left;
}

.history-table td {
    padding: 1rem;
    color: var(--text-primary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    transition: background 0.2s;
}

.history-table tr:hover td {
    background: rgba(255, 255, 255, 0.03);
}

.history-table tr:last-child td {
    border-bottom: none;
}

body.light-mode .history-table td {
    border-bottom-color: rgba(0, 0, 0, 0.05);
}

body.light-mode .history-table tr:hover td {
    background: rgba(0, 0, 0, 0.02);
}

.risk-fill {
    height: 100%;
    background: linear-gradient(to right, var(--secondary), var(--primary), var(--accent));
    width: 0%;
    /* JS will animate this */
    transition: width 1s ease-out;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.main-content>* {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Trend Indicators */
.trend-indicator {
    display: inline-block;
    padding: 0.5rem 1.25rem;
    border-radius: 99px;
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 0.75rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.trend-indicator.bullish {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
    border: 2px solid rgba(16, 185, 129, 0.3);
}

.trend-indicator.bearish {
    background: rgba(244, 63, 94, 0.15);
    color: #f43f5e;
    border: 2px solid rgba(244, 63, 94, 0.3);
}

body.light-mode .trend-indicator.bullish {
    background: rgba(16, 185, 129, 0.12);
    color: #047857;
    border: 2px solid rgba(16, 185, 129, 0.2);
}

body.light-mode .trend-indicator.bearish {
    background: rgba(244, 63, 94, 0.12);
    color: #be123c;
    border: 2px solid rgba(244, 63, 94, 0.2);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Print Styles */
@media print {
    @page {
        margin: 0.5cm;
    }

    body {
        background: white;
        color: black;
        height: auto;
        overflow: visible;
        font-size: 10pt;
    }

    .container {
        display: block;
        padding: 0;
        height: auto;
    }

    .sidebar {
        position: static;
        width: 100%;
        height: auto;
        border: none;
        padding: 1rem 0;
        background: transparent;
        overflow: visible;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 1rem;
        align-items: start;
    }

    /* Hide Controls */
    .brand,
    #theme-toggle,
    .control-group,
    hr {
        display: none !important;
    }

    /* Format Corporate Requirement for Print */
    .sidebar .stat-card {
        grid-column: 1 / -1;
        border: 1px solid #ddd;
        break-inside: avoid;
        background: #f9f9f9;
        color: black;
    }

    .sidebar label {
        color: #555;
    }

    .sidebar input {
        border: none;
        background: transparent;
        color: black;
        padding: 0;
        font-weight: bold;
        text-align: right;
    }

    /* Main Content Layout */
    .main-content {
        padding: 0;
        overflow: visible;
        width: 100%;
    }

    .stat-card,
    .chart-container {
        break-inside: avoid;
        page-break-inside: avoid;
        border: 1px solid #ddd;
        background: white;
        box-shadow: none;
        margin-bottom: 1rem;
        color: black;
    }

    .section-title {
        font-size: 1.1rem;
        color: #333;
    }

    .stat-value {
        font-size: 1.5rem;
        color: #000;
    }

    .stat-label {
        color: #555;
    }

    /* Ensure Chart is Visible */
    canvas {
        max-height: 300px;
        width: 100% !important;
    }

    /* Hide scrollbars */
    ::-webkit-scrollbar {
        display: none;
    }

    * {
        scrollbar-width: none;
    }
}

/* Theme Switch Toggle */
.theme-switch {
    position: relative;
    display: inline-block;
    width: 52px;
    height: 28px;
    /* margin-left: auto; */
}

.theme-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #e2e8f0;
    /* Light mode bg - Slate 200 */
    transition: .4s;
    border-radius: 34px;
    border: 1px solid var(--card-border);
}

.slider:before {
    position: absolute;
    content: "\2600";
    /* Sun emoji Unicode */
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    height: 20px;
    width: 20px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* Checked = Dark Mode */
input:checked+.slider {
    background-color: #334155;
    /* Slate 700 */
    border-color: rgba(255, 255, 255, 0.1);
}

input:checked+.slider:before {
    transform: translateX(24px);
    content: "\1F319";
    /* Moon emoji Unicode */
    background-color: #1e293b;
    /* Slate 800 */
    color: white;
    /* Moon color */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
    font-size: 12px;
}

/* Loading Overlay Cinematic */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #0f172a;
    /* Deep space blue */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 99999;
    overflow: hidden;
    transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.6s;
}

#loading-overlay::before {
    content: '';
    position: absolute;
    width: 150%;
    height: 150%;
    background: radial-gradient(circle at center, rgba(37, 99, 235, 0.15) 0%, transparent 60%);
    animation: pulseGlow 4s infinite alternate ease-in-out;
}

body:not(.loading) #loading-overlay {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    display: none;
    /* Force hide if visibility isn't enough */
}

.space-scene {
    position: relative;
    width: 300px;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.rocket-wrapper {
    position: relative;
    z-index: 10;
    animation: rocketShake 0.1s infinite;
}

.rocket {
    font-size: 5rem;
    transform: rotate(45deg);
    filter: drop-shadow(0 0 15px rgba(255, 255, 255, 0.4));
    display: block;
}

.rocket-fire {
    position: absolute;
    bottom: -10px;
    left: -10px;
    width: 40px;
    height: 40px;
    background: linear-gradient(to top, transparent, #3b82f6, #60a5fa);
    filter: blur(8px);
    border-radius: 50%;
    transform: rotate(45deg);
    animation: firePulse 0.2s infinite alternate;
    z-index: -1;
}

.stars-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.star-particle {
    position: absolute;
    background: linear-gradient(to right, rgba(96, 165, 250, 0.8), transparent);
    border-radius: 20px;
    animation: starWarp 0.8s infinite linear;
}

.loading-text {
    margin-top: 3rem;
    text-align: center;
    z-index: 20;
    color: white;
}

.loading-text h3 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
    text-transform: uppercase;
    background: linear-gradient(to right, #60a5fa, #ffffff);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.loading-text p {
    color: #94a3b8;
    font-size: 1rem;
    font-weight: 400;
}

@keyframes rocketShake {

    0%,
    100% {
        transform: translate(0, 0);
    }

    25% {
        transform: translate(1px, 1px);
    }

    50% {
        transform: translate(-1px, 2px);
    }

    75% {
        transform: translate(-2px, -1px);
    }
}

@keyframes firePulse {
    from {
        transform: scale(1) rotate(45deg);
        opacity: 0.8;
    }

    to {
        transform: scale(1.4) rotate(45deg);
        opacity: 1;
    }
}

@keyframes starWarp {
    0% {
        transform: translateX(100px);
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    100% {
        transform: translateX(-600px);
        opacity: 0;
    }
}

@keyframes pulseGlow {
    from {
        transform: scale(0.8);
        opacity: 0.4;
    }

    to {
        transform: scale(1.2);
        opacity: 0.7;
    }
}

/* Blur content when loading */
body.loading .container {
    filter: blur(8px) grayscale(0.5);
    pointer-events: none;
    transition: filter 0.5s ease;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 100000;
}

.modal-content {
    background: var(--bg-color);
    /* Light/Dark aware */
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.req-item {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.req-item-info {
    flex-grow: 1;
}

.req-item-label {
    font-weight: 600;
    color: var(--secondary);
    margin-bottom: 0.25rem;
}

.req-item-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.req-item-actions {
    display: flex;
    gap: 0.5rem;
}

.btn-icon {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    padding: 4px 8px;
    font-size: 0.8rem;
    cursor: pointer;
}

.btn-icon:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Corporate Requirements Modal Styling */
#req-modal .modal-content {
    background: #ffffff !important;
    /* Always white background for clarity */
    color: #1e293b !important;
    border: none;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

#req-modal .modal-header h3 {
    color: #1e293b !important;
    font-weight: 700;
}

#req-modal .modal-body h4 {
    color: #1e293b !important;
    margin-top: 1.5rem;
}

#req-modal .modal-body label {
    display: block;
    margin-top: 1rem;
    font-weight: 600;
    color: #475569 !important;
    /* Dark grey labels */
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#req-modal .modal-body input[type="text"],
#req-modal .modal-body input[type="number"],
#req-modal .modal-body input[type="email"] {
    width: 100%;
    padding: 0.85rem;
    background: #ffffff !important;
    border: 2px solid #e2e8f0 !important;
    border-radius: 10px;
    color: #000000 !important;
    /* ABSOLUTE BLACK TEXT */
    margin-top: 0.4rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 500;
    box-shadow: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-text-fill-color: #000000 !important;
    /* Override browser override */
}

#req-modal .modal-body input:focus {
    outline: none;
    border-color: #7c3aed !important;
    box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1);
}

#req-modal .modal-body hr {
    border: none;
    border-top: 1px solid #e2e8f0;
    margin: 1.5rem 0;
}

/* Ensure requirements list items are also visible in the white modal */
.req-item {
    background: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
    color: #1e293b !important;
}

.req-item-label {
    color: #7c3aed !important;
}

.req-item-meta {
    color: #64748b !important;
}

/* Checkbox specific */
#req-modal .modal-body input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    accent-color: #7c3aed;
    cursor: pointer;
}

#save-req-btn.highlight-update {
    background: #2563eb;
    /* Stronger blue for update */
    background: var(--gradient-1);
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.4);
    transform: scale(1.02);
}