:root {
    --bg-main: #f3f4f6;
    --bg-card: #ffffff;
    --text-main: #111827;
    --text-muted: #6b7280;
    --border-color: #e5e7eb;
    --input-bg: #f9fafb;
    --input-border: #d1d5db;
    
    --accent-green: #10b981;
    --accent-green-bg: #d1fae5;
    --accent-purple: #8b5cf6;
    --accent-purple-bg: #ede9fe;
    --accent-teal: #14b8a6;
    --accent-teal-bg: #ccfbf1;
    --accent-yellow: #f59e0b; 
    --accent-red: #ef4444;
}

[data-theme="light"] {
    /* Critical UI Fix: Makes the "Open Risk" orange text beautifully readable in Light Mode */
    --accent-yellow: #b45309; 
}

[data-theme="dark"] {
    --bg-main: #0f1115;
    --bg-card: #18191e;
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --border-color: #27272a;
    --input-bg: #1f2128;
    --input-border: #3f3f46;

    --accent-green-bg: rgba(16, 185, 129, 0.15);
    --accent-purple-bg: rgba(139, 92, 246, 0.15);
    --accent-teal-bg: rgba(20, 184, 166, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', sans-serif; background-color: var(--bg-main); color: var(--text-main); transition: background-color 0.3s, color 0.3s; min-height: 100vh; padding: 2rem; }
.container { max-width: 1240px; margin: 0 auto; }

/* Utilities */
.text-green { color: var(--accent-green) !important; }
.text-yellow { color: var(--accent-yellow) !important; }
.text-red { color: var(--accent-red) !important; }
.text-purple { color: var(--accent-purple) !important; }
.text-teal { color: var(--accent-teal); }
.text-muted { color: var(--text-muted) !important; }
.bg-purple { background-color: var(--accent-purple); }
.font-mono { font-family: 'Courier New', Courier, monospace; font-weight: 600;}
.font-bold { font-weight: 600; }
.col { display: flex; flex-direction: column; }
.sub-text { color: var(--text-muted); font-size: 0.85rem; }
.text-xs { font-size: 0.75rem; opacity: 0.8; margin-top: 2px;}

/* Form Resets */
input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { appearance: textfield; -moz-appearance: textfield;}

/* Navigation & Controls */
.top-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.nav-links { display: flex; gap: 1.5rem; margin-right: auto; margin-left: 2.5rem; }
.nav-link { color: var(--text-muted); text-decoration: none; font-weight: 500; font-size: 1rem; transition: color 0.2s; padding-bottom: 4px; border-bottom: 2px solid transparent; }
.nav-link:hover, .nav-link.active { color: var(--text-main); }
.nav-link.active { border-color: var(--accent-purple); }
.top-actions { display: flex; align-items: center; gap: 0.75rem; }
.icon-btn { background: transparent; border: none; color: var(--text-muted); cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0.5rem; border-radius: 0.5rem; transition: 0.2s; font-weight: 600;}
.icon-btn:hover { color: var(--text-main); background: var(--border-color); }

/* Global Cards & Panels */
.panel, .modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 1.25rem;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.10);
}
.panel-label { font-size: 0.72rem; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.panel-title { margin-top: 0.3rem; font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; }
.panel-sub { margin-top: 0.3rem; font-size: 0.88rem; line-height: 1.5; color: var(--text-muted); }

/* Hero Panel (Stacked for better spacing) */
.hero-panel {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border-radius: 24px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.12), rgba(139, 92, 246, 0.08)), var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
    transition: background 0.5s ease;
}
.hero-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.hero-kicker { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.18em; text-transform: uppercase; color: var(--text-muted); }
.hero-title { margin-top: 0.35rem; font-weight: 800; letter-spacing: -0.05em; line-height: 1.1;}

/* 4 Column Grid for Hero Meta Alignments */
.hero-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.75rem; align-self: stretch; }

/* FIXED ALIGNMENT: Linear Left-aligned Hero Chips without flex margins */
.hero-chip {
    padding: 1.25rem 1rem; border-radius: 18px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex; flex-direction: column; justify-content: flex-start; align-items: flex-start; gap: 0.5rem;
}
[data-theme="light"] .hero-chip { background: rgba(255, 255, 255, 0.78); border-color: rgba(148, 163, 184, 0.22); }
.hero-chip .label { font-size: 0.72rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; width: 100%; line-height: 1;}
.hero-chip .value { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.03em; width: 100%; line-height: 1.1; }
.hero-chip .sub { font-size: 0.8rem; width: 100%; line-height: 1; font-weight: 600;}

/* Progress Bar */
.progress-bar { height: 8px; background: var(--border-color); border-radius: 4px; overflow: hidden; margin-bottom: 0.5rem; position: relative; }
.progress-fill { height: 100%; position: absolute; top: 0; left: 0; transition: width 0.4s ease, background-color 0.4s ease; }
.progress-labels { display: flex; justify-content: space-between; font-size: 0.75rem; font-weight: 600;}

/* Inputs */
.input-group label { display: block; margin-bottom: 0.45rem; font-size: 0.88rem; font-weight: 600; color: var(--text-muted); }

/* Classic Inputs */
.calc-input, .plan-input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border-radius: 10px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 600;
    outline: none;
    text-align: center;
    transition: all 0.2s ease;
}
.calc-input:hover, .plan-input:hover { border-color: var(--text-muted); }
.calc-input:focus, .plan-input:focus { border-color: var(--accent-purple); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15); background: var(--bg-card); }
.helper-line { margin-top: 0.5rem; color: var(--text-muted); font-size: 0.82rem; }

/* NEW: Solid yet subtle inputs for sleek Open Position table */
.pos-input-solid {
    width: 100%;
    padding: 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 600;
    outline: none;
    text-align: center;
    transition: all 0.2s ease;
}
[data-theme="light"] .pos-input-solid { background: rgba(0, 0, 0, 0.02); }
.pos-input-solid:hover { background: rgba(139, 92, 246, 0.05); border-color: var(--text-muted); }
.pos-input-solid:focus { border-color: var(--accent-purple); background: var(--input-bg); box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.12); }

/* Buttons & Pills */
.preset-btn { border: 1px solid var(--border-color); background: var(--input-bg); color: var(--text-main); padding: 0.66rem 0.9rem; border-radius: 999px; cursor: pointer; font-weight: 700; transition: 0.2s; }
.preset-btn:hover { border-color: var(--accent-purple); }
.preset-btn.active { background: var(--accent-purple); color: white; border-color: transparent; }
.save-pill { display: inline-flex; align-items: center; padding: 0.45rem 0.8rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.risk-pill { display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 8px; font-size: 0.95rem; transition: all 0.3s ease; }

/* Modal */
.modal-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(4px); }
.modal-overlay.hidden { display: none; }
.modal-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border-color); padding-bottom: 1rem; }

/* Dashboard Grid (9 columns detailed) */
.dash-grid {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 0.8fr 1.3fr 1.3fr 1.5fr 40px;
    gap: 0.75rem;
    align-items: center;
}
.plan-head { padding: 0.65rem 0; margin-top: 0.8rem; border-bottom: 1px solid var(--border-color); font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.16em; color: var(--text-muted); font-weight: 700; }

.position-row { padding: 0.5rem 0; margin: 0.2rem 0; border-bottom: 1px dashed var(--border-color); transition: background 0.2s; border-radius: 12px;}
.position-row:last-of-type { border-bottom: none; }
.position-row:hover { background: rgba(255, 255, 255, 0.02); }
[data-theme="light"] .position-row:hover { background: rgba(0, 0, 0, 0.02); }

.status-dot { width: 8px; height: 8px; background: var(--accent-green); border-radius: 50%; flex-shrink: 0;}

/* Alloc Bar */
.alloc-bar-bg { width: 100%; max-width: 60px; height: 6px; background: var(--border-color); border-radius: 3px; overflow: hidden; }
.alloc-bar-fill { height: 100%; border-radius: 3px; transition: width 0.3s ease;}

/* Delete Button */
.delete-btn { color: var(--text-muted); }
.delete-btn:hover { color: var(--accent-red); background: rgba(239, 68, 68, 0.1); }

.toggle-label { display: flex; align-items: center; cursor: pointer; font-size: 0.9rem; gap: 0.5rem; color: var(--text-muted); font-weight: 600;}

/* PERFECT SIMPLIFIED GRID */
body.simplified-view .detail-view-only { display: none !important; }
body.simplified-view .simple-view-only { display: flex !important; }

/* 5 Column Layout matching the 5 remaining visible headers in HTML */
/* Stock | Impact % | Loss@SL % | Alloc | Delete */
body.simplified-view .dash-grid { grid-template-columns: 2.2fr 1.3fr 1.3fr 1.5fr 40px; } 

@media (max-width: 1100px) {
    .dash-grid { min-width: 900px; }
    .table-container { overflow-x: auto; padding-bottom: 1rem;}
}
@media (max-width: 980px) {
    .hero-meta { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
    body { padding: 1rem; }
    .top-controls { flex-wrap: wrap; }
    .nav-links { margin: 0; }
    .hero-meta { grid-template-columns: 1fr; }
}

/* --------------------------------------
   CALCULATOR SPECIFIC STYLES
   -------------------------------------- */
.calc-grid { display: grid; grid-template-columns: 1fr 1.08fr; gap: 1rem; align-items: stretch;}
.preset-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0.8rem 0 0.9rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.summary-copy { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.5rem; margin-bottom: 2.5rem; margin-top: 1rem;}
.summary-label { font-size: 0.85rem; letter-spacing: 0.2em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; text-align: center; }
.big-number { font-size: clamp(4rem, 8vw, 6rem); line-height: 1; font-weight: 800; letter-spacing: -0.04em; background: linear-gradient(135deg, #60a5fa, #2563eb); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; text-align: center; display: flex; justify-content: center; width: 100%;}
.big-number-wrap { display: flex; justify-content: center; width: 100%; }

.metrics-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.7rem; margin-top: 0.85rem; flex: 1; }
.metric { padding: 0.9rem; border-radius: 18px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; justify-content: space-between; }
[data-theme="light"] .metric { background: rgba(255, 255, 255, 0.74); border-color: rgba(148, 163, 184, 0.18); }
.metric .label { font-size: 0.7rem; letter-spacing: 0.16em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.metric .value { margin-top: 0.35rem; font-size: 1.15rem; font-weight: 800; }