/* Core Color Palette & Variables */
:root {
    --primary: #0f172a; 
    --primary-light: #2563eb;
    --secondary: #f8fafc;
    --text-main: #334155;
    --text-dark: #0f172a;
    --border: #e2e8f0;
    --bg-body: #f1f5f9;
    --paper: #ffffff;
    
    --ans: #16a34a; --not-ans: #dc2626; --marked: #7c3aed; --not-vis: #94a3b8;
    --dash-green: #10b981; --dash-red: #ef4444; --dash-blue: #3b82f6; 
    --dash-purple: #8b5cf6; --dash-orange: #f59e0b;
    
    --font-ui: "Inter", system-ui, -apple-system, sans-serif;
    --font-paper: "Georgia", "Times New Roman", serif; 
}

/* Reset */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { font-family: var(--font-ui); background: var(--bg-body); color: var(--text-main); line-height: 1.6; }
.hidden { display: none !important; }
.text-green { color: var(--dash-green) !important; }
.text-red { color: var(--dash-red) !important; }
.text-orange { color: var(--dash-orange) !important; }
.text-blue { color: var(--dash-blue) !important; }
.text-purple { color: var(--dash-purple) !important; }

/* HEADER */
.app-header { background: var(--primary); color: white; padding: 0 24px; box-shadow: 0 4px 15px rgba(0,0,0,0.1); height: 65px; display: flex; align-items: center; position: sticky; top: 0; z-index: 100; }
.header-container { width: 100%; max-width: 1440px; margin: 0 auto; display: flex; justify-content: space-between; align-items: center; }
.brand-link { color: white; text-decoration: none; font-weight: 700; font-size: 1.25rem; display: flex; align-items: center; gap: 10px; }
.brand-link .icon { width: 22px; height: 22px; color: #60a5fa; }
.exam-title { font-size: 1.05rem; font-weight: 600; color: #e2e8f0; text-transform: uppercase; letter-spacing: 0.5px; }
.btn-outline { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: white; padding: 6px 14px; border-radius: 6px; font-size: 0.85rem; cursor: pointer; transition: 0.2s; }
.btn-outline:hover { background: rgba(255,255,255,0.15); border-color: white; }

/* EXAM LAYOUT */
.exam-layout { display: flex; max-width: 1440px; margin: 0 auto; gap: 24px; padding: 24px; height: calc(100vh - 65px); min-height: 550px; }
.question-panel { flex: 1; background: var(--paper); border-radius: 12px; border: 1px solid var(--border); box-shadow: 0 4px 20px rgba(15,23,42,0.03); display: flex; flex-direction: column; overflow: hidden; }
.panel-header { background: var(--secondary); padding: 18px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; flex-shrink: 0;}
.q-meta { display: flex; align-items: center; gap: 10px; }
.q-meta h2 { font-size: 1.15rem; color: var(--text-dark); font-weight: 600; }
.q-meta .muted { color: #94a3b8; font-weight: 400; }
.difficulty-badge { background: #fee2e2; color: #991b1b; padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.subject-badge { background: #e0e7ff; color: #3730a3; padding: 4px 10px; border-radius: 6px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; }
.timer-box { font-family: monospace; font-size: 1.25rem; font-weight: 700; color: #1e3a8a; background: #dbeafe; padding: 6px 14px; border-radius: 8px; border: 1px solid #bfdbfe; }

/* QUESTION SCROLL AREA */
.question-body { flex: 1; overflow-y: auto; padding: 36px 48px; position: relative;}
.upsc-text { font-family: var(--font-paper); font-size: 1.15rem; line-height: 1.85; color: #1c1917; margin-bottom: 32px; white-space: pre-line; }

.options-group { display: flex; flex-direction: column; gap: 14px; padding-bottom: 20px;}
.option-item { display: flex; align-items: flex-start; padding: 16px 24px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: 0.2s ease; background: var(--paper); }
.option-item:hover { border-color: var(--primary-light); background: #f4f8ff; }
.option-item.selected { border-color: var(--primary-light); background: #eff6ff; box-shadow: 0 0 0 1px var(--primary-light); }
.omr-circle { width: 28px; height: 28px; border: 2px solid #cbd5e1; border-radius: 50%; margin-right: 18px; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 700; color: #64748b; background: #fff; }
.option-item.selected .omr-circle { border-color: var(--primary-light); background: var(--primary-light); color: white; }
.option-label { font-family: var(--font-paper); font-size: 1.1rem; color: #1c1917; }

/* STICKY FOOTER */
.panel-footer { padding: 18px 32px; border-top: 1px solid var(--border); background: #f8fafc; display: flex; justify-content: space-between; flex-shrink: 0;}
.controls-left, .controls-right { display: flex; gap: 14px; }
button { font-family: var(--font-ui); padding: 12px 22px; border-radius: 6px; font-size: 0.95rem; font-weight: 600; cursor: pointer; border: none; transition: 0.2s ease; }
.btn-ghost { background: #fff; border: 1px solid #cbd5e1; color: #475569; }
.btn-ghost:hover { background: #f1f5f9; color: var(--text-dark); }
.btn-secondary { background: #fff; border: 1px solid var(--primary-light); color: var(--primary-light); }
.btn-secondary:hover:not(:disabled) { background: #eff6ff; }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; border-color: var(--border); color: #94a3b8; }
.btn-primary { background: var(--primary-light); color: white; }
.btn-primary:hover { background: #1d4ed8; }

/* SIDEBAR */
.side-panel { width: 340px; background: var(--paper); border-radius: 12px; border: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden;}
.test-info { padding: 24px; border-bottom: 1px solid var(--border); background: var(--secondary); text-align: center; }
.test-info h3 { font-size: 1.1rem; color: var(--text-dark); }
.date-stamp { font-size: 0.85rem; color: #64748b; font-weight: 600; text-transform: uppercase; margin-top: 5px;}
.legends-grid { padding: 18px; display: grid; grid-template-columns: 1fr 1fr; gap: 14px; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.legend-item { display: flex; align-items: center; font-weight: 500; color: #475569; }
.box { width: 28px; height: 28px; line-height: 28px; text-align: center; border-radius: 6px; color: white; font-weight: 700; margin-right: 10px; }
.box.answered, .palette-btn.answered { background: var(--ans); color: white; border-color: var(--ans); }
.box.not-answered, .palette-btn.not-answered { background: var(--not-ans); color: white; border-color: var(--not-ans); }
.box.marked, .palette-btn.marked { background: var(--marked); color: white; border-color: var(--marked); }
.box.not-visited, .palette-btn.not-visited { background: #f1f5f9; color: #64748b; border: 1px solid #cbd5e1; }

.palette-header { padding: 20px 20px 0; }
.palette-header h3 { font-size: 0.95rem; font-weight: 700; text-transform: uppercase; color: var(--text-dark); }
.palette-container { padding: 18px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; overflow-y: auto; flex: 1; align-content: start; }
.palette-btn { aspect-ratio: 1; border: 1px solid transparent; border-radius: 8px; font-size: 0.95rem; font-weight: 700; cursor: pointer; transition: 0.15s; display: flex; align-items: center; justify-content: center; }
.palette-btn.active { box-shadow: 0 0 0 2px #fff, 0 0 0 4px var(--text-dark); transform: scale(1.05); }
.submit-container { padding: 20px; border-top: 1px solid var(--border); background: var(--secondary); }
.btn-submit { width: 100%; background: #0ea5e9; color: white; padding: 14px; border-radius: 8px; font-size: 1.05rem; }
.btn-submit:hover { background: #0284c7; }

/* LOADING ANIMATION */
.submit-loader { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(15, 23, 42, 0.96); z-index: 9999; display: flex; align-items: center; justify-content: center; color: white; }
.loader-content { text-align: center; }
.spinner { width: 64px; height: 64px; border: 5px solid rgba(255,255,255,0.1); border-top-color: #3b82f6; border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 24px; }
.loader-text { font-size: 1.8rem; font-weight: 700; margin-bottom: 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================
   15+ FEATURES ANALYTICS DASHBOARD 
========================================= */
.result-dashboard { max-width: 1240px; margin: 40px auto; padding: 0 24px; animation: fadeIn 0.6s ease forwards; }
.dashboard-header { text-align: center; margin-bottom: 40px; }
.anim-trophy { font-size: 3.5rem; margin-bottom: 15px; }
.dashboard-header h2 { font-size: 2.2rem; color: var(--text-dark); font-weight: 800; }
.dashboard-header p { color: #64748b; font-size: 1.1rem; margin-top: 5px; }

.dashboard-actions-top { display: flex; justify-content: center; gap: 16px; margin-bottom: 40px; flex-wrap: wrap; }
.btn-dash { padding: 12px 26px; border-radius: 30px; font-size: 0.95rem; font-weight: 700; box-shadow: 0 4px 10px rgba(0,0,0,0.06); }
.btn-dash.primary { background: var(--dash-blue); color: white; }
.btn-dash.danger { background: var(--dash-red); color: white; }
.btn-dash.warning { background: var(--dash-orange); color: white; }
.btn-dash.outline { background: #fff; border: 2px solid var(--dash-blue); color: var(--dash-blue); box-shadow: none; }
.btn-dash:hover { transform: translateY(-2px); box-shadow: 0 6px 15px rgba(0,0,0,0.1); }

.section-title { font-size: 1.35rem; color: var(--text-dark); font-weight: 700; margin: 40px 0 20px; padding-bottom: 10px; border-bottom: 2px solid var(--border); }

/* GRID 1: CORE STATS */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 20px; margin-bottom: 30px; }
.stat-card { background: var(--paper); border-radius: 14px; padding: 24px; display: flex; align-items: center; gap: 18px; border: 1px solid var(--border); box-shadow: 0 4px 6px rgba(0,0,0,0.02); }
.stat-card.main-score { border-color: #bfdbfe; background: #f0fdf4; border-left: 5px solid var(--dash-green); }
.stat-icon { width: 54px; height: 54px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; color: white; flex-shrink: 0; }
.bg-blue { background: var(--dash-blue); } .bg-green { background: var(--dash-green); }
.bg-purple { background: var(--dash-purple); } .bg-orange { background: var(--dash-orange); }

.stat-data { flex: 1; }
.stat-data .label { font-size: 0.8rem; color: #64748b; text-transform: uppercase; font-weight: 700; }
.stat-data strong { display: block; font-size: 1.8rem; color: var(--text-dark); font-weight: 800; margin-top: 4px; }
.progress-bar { width: 100%; height: 8px; background: #e2e8f0; border-radius: 10px; margin-top: 10px; }
.progress-bar .fill { height: 100%; width: 0; border-radius: 10px; }
.fill.green { background: var(--dash-green); }

/* GRID 2: ADVANCED DIAGNOSTICS */
.advanced-metrics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 20px; }
.adv-card { background: var(--paper); border: 1px solid var(--border); border-radius: 14px; padding: 20px; text-align: center; }
.adv-card .label { font-size: 0.85rem; color: var(--text-main); font-weight: 700; display: block; margin-bottom: 8px;}
.adv-card strong { font-size: 1.6rem; font-weight: 800; display: block; margin-bottom: 8px; }
.adv-card p { font-size: 0.8rem; color: #64748b; line-height: 1.4;}

/* GRID 3: CHARTS */
.chart-flex { display: flex; gap: 20px; flex-wrap: wrap; }
.chart-box { flex: 1; min-width: 300px; background: var(--paper); border-radius: 14px; padding: 24px; border: 1px solid var(--border); text-align: center; }
.chart-box h4 { margin-bottom: 20px; color: var(--text-dark); font-size: 1.1rem; font-weight: 700; }

/* Perfect CSS Donut Chart */
.donut-chart {
    width: 150px; height: 150px; 
    border-radius: 50%; 
    margin: 0 auto 20px;
    display: flex; align-items: center; justify-content: center;
    background: #e2e8f0; /* default fallback */
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}
.donut-inner {
    width: 100px; height: 100px; 
    background: var(--paper); 
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; font-weight: 800; color: var(--text-dark);
}
.chart-legend { display: flex; justify-content: center; gap: 15px; font-size: 0.85rem; font-weight: 600; flex-wrap: wrap; }
.legend-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 6px; transform:translateY(2px); }

/* Subject Bars */
.subject-bars { display: flex; flex-direction: column; gap: 15px; text-align: left; }
.sub-row { display: flex; align-items: center; font-size: 0.9rem; font-weight: 600;}
.sub-label { width: 35%; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 10px;}
.sub-bar-bg { width: 65%; height: 12px; background: #e2e8f0; border-radius: 6px; display: flex; overflow: hidden; }
.sub-bar-fill.correct { background: var(--dash-green); }
.sub-bar-fill.wrong { background: var(--dash-red); }

/* Time Histogram */
.time-histogram { display: flex; align-items: flex-end; justify-content: center; gap: 12px; height: 150px; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.hist-bar-container { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; width: 40px;}
.hist-bar { width: 100%; background: #3b82f6; border-radius: 4px 4px 0 0; position: relative; transition: height 0.5s ease;}
.hist-label { font-size: 0.8rem; font-weight: 700; color: #64748b; margin-top: 8px;}
.hist-val { font-size: 0.75rem; font-weight: bold; margin-bottom: 5px; color: var(--text-dark);}

/* GRID 4: Waterfall & AI */
.insights-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; }
.waterfall-box { background: var(--paper); border: 1px solid var(--border); border-radius: 14px; padding: 24px; }
.waterfall-box h4 { margin-bottom: 20px; font-size: 1.1rem; color: var(--text-dark); }
.waterfall-row { display: flex; justify-content: space-between; padding: 12px 0; border-bottom: 1px dashed var(--border); font-size: 1rem; }
.waterfall-row.final { border-top: 2px solid var(--text-dark); border-bottom: none; margin-top: 10px; padding-top: 15px; font-size: 1.2rem; font-weight: 800; }
.waterfall-row strong { font-weight: 700; }

.feedback-box { background: linear-gradient(135deg, #0f172a, #1e293b); color: white; padding: 24px; border-radius: 14px; display: flex; flex-direction: column; gap: 15px; box-shadow: 0 10px 25px rgba(15,23,42,0.1); }
.feedback-box h4 { font-size: 1.1rem; color: #e2e8f0; border-bottom: 1px solid rgba(255,255,255,0.1); padding-bottom: 10px;}
.feed-item { font-size: 1.05rem; line-height: 1.5; }
.feed-item strong { color: #38bdf8; display: inline-block; margin-right: 5px; }

/* SOLUTIONS */
.solutions-wrapper { display: flex; flex-direction: column; gap: 24px; margin-bottom: 40px;}
.solution-card { background: var(--paper); border: 1px solid var(--border); border-radius: 12px; padding: 30px; box-shadow: 0 4px 6px rgba(0,0,0,0.02); }
.sol-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--border); padding-bottom: 15px; margin-bottom: 20px; }
.sol-status { font-weight: 700; padding: 6px 12px; border-radius: 6px; font-size: 0.8rem; text-transform: uppercase; color: white; }
.sol-status.correct { background: var(--ans); }
.sol-status.wrong { background: var(--not-ans); }
.sol-status.skipped { background: #64748b; }
.sol-options { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.sol-opt { padding: 14px 20px; border: 1px solid var(--border); border-radius: 8px; font-family: var(--font-paper); font-size: 1.05rem; display: flex; align-items: flex-start; color: #334155; }
.sol-opt strong { color: var(--text-dark); margin-right: 8px; }
.sol-opt.is-correct { background: #f0fdf4; border-color: #bbf7d0; font-weight: bold; color: #166534;}
.sol-opt.is-wrong { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.sol-exp { background: #fffbeb; border-left: 4px solid #f59e0b; padding: 24px; border-radius: 0 8px 8px 0; font-family: var(--font-paper); font-size: 1.05rem; line-height: 1.7; color: #451a03; }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(15px); } to { opacity: 1; transform: translateY(0); } }

/* Mobile Formatting */
@media screen and (max-width: 1024px) {
    .exam-layout { flex-direction: column; height: auto; padding: 16px; }
    .question-panel { height: auto; min-height: 500px; }
    .side-panel { width: 100%; height: auto; }
    .palette-container { grid-template-columns: repeat(8, 1fr); max-height: 200px; }
}

@media screen and (max-width: 640px) {
    .app-header { padding: 0 16px; height: 60px; }
    .exam-title { display: none; }
    .question-body { padding: 24px 20px; }
    .panel-footer { padding: 16px; flex-direction: column; gap: 12px; }
    .controls-left, .controls-right { width: 100%; justify-content: space-between; }
    .controls-left button, .controls-right button { flex: 1; text-align: center; padding: 12px 10px; font-size: 0.9rem;}
    .palette-container { grid-template-columns: repeat(5, 1fr); }
    
    .stats-grid, .advanced-metrics-grid { grid-template-columns: 1fr 1fr; }
    .chart-box, .waterfall-box, .feedback-box { min-width: 100%; }
    .solution-card { padding: 20px; }
    .sol-header { flex-direction: column; align-items: flex-start; gap: 10px; }
}