/* ============================================================
   CIEL Lab — Custom Styles
   ============================================================ */

/* ── Root variables ────────────────────────────────────── */
:root {
    --bg-primary: #070c1b;
    --bg-card: rgba(15, 23, 42, 0.6);
    --bg-sidebar: rgba(10, 17, 35, 0.85);
    --border-subtle: rgba(99, 179, 237, 0.08);
    --glow-cyan: rgba(6, 182, 212, 0.15);
    --glow-violet: rgba(139, 92, 246, 0.15);
    --glow-amber: rgba(245, 158, 11, 0.15);
    --glow-emerald: rgba(16, 185, 129, 0.15);
}

/* ── Base ───────────────────────────────────────────────── */
body {
    background: var(--bg-primary);
    background-image:
        radial-gradient(ellipse 80% 50% at 50% -20%, rgba(6, 182, 212, 0.08), transparent),
        radial-gradient(ellipse 60% 40% at 80% 100%, rgba(139, 92, 246, 0.06), transparent);
}

/* ── Scrollbar ─────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, 0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, 0.35); }

/* ── Glass Card ────────────────────────────────────────── */
.glass-card {
    background: var(--bg-card);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.glass-card:hover {
    border-color: rgba(99, 179, 237, 0.18);
    box-shadow: 0 8px 32px rgba(6, 182, 212, 0.08);
    transform: translateY(-2px);
}

/* ── Glow effects per category ─────────────────────────── */
.glow-cyan:hover   { box-shadow: 0 8px 32px var(--glow-cyan); border-color: rgba(6, 182, 212, 0.25); }
.glow-violet:hover { box-shadow: 0 8px 32px var(--glow-violet); border-color: rgba(139, 92, 246, 0.25); }
.glow-amber:hover  { box-shadow: 0 8px 32px var(--glow-amber); border-color: rgba(245, 158, 11, 0.25); }
.glow-emerald:hover{ box-shadow: 0 8px 32px var(--glow-emerald); border-color: rgba(16, 185, 129, 0.25); }

/* ── Sidebar ───────────────────────────────────────────── */
.sidebar-bg {
    background: var(--bg-sidebar);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    color: #94a3b8;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.2s ease;
    text-decoration: none;
    position: relative;
}
.nav-item:hover {
    color: #e2e8f0;
    background: rgba(99, 179, 237, 0.06);
}
.nav-item.active {
    color: #22d3ee;
    background: rgba(6, 182, 212, 0.1);
}
.nav-item.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    width: 3px;
    height: 60%;
    background: linear-gradient(to bottom, #06b6d4, #3b82f6);
    border-radius: 0 3px 3px 0;
}

.nav-icon {
    font-size: 1.15rem;
    width: 24px;
    text-align: center;
}

/* ── Stat Card ─────────────────────────────────────────── */
.stat-card {
    background: var(--bg-card);
    backdrop-filter: blur(12px);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 20px 24px;
    position: relative;
    overflow: hidden;
}
.stat-card::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    border-radius: 14px 14px 0 0;
}
.stat-card.stat-cyan::after    { background: linear-gradient(90deg, #06b6d4, #0ea5e9); }
.stat-card.stat-emerald::after { background: linear-gradient(90deg, #10b981, #34d399); }
.stat-card.stat-violet::after  { background: linear-gradient(90deg, #8b5cf6, #a78bfa); }
.stat-card.stat-amber::after   { background: linear-gradient(90deg, #f59e0b, #fbbf24); }

/* ── Progress Bar ──────────────────────────────────────── */
.progress-track {
    background: rgba(30, 41, 59, 0.8);
    border-radius: 999px;
    height: 6px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    border-radius: 999px;
    transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
    background: linear-gradient(90deg, #06b6d4, #3b82f6);
}

/* ── Difficulty dots ───────────────────────────────────── */
.diff-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
}
.diff-dot.on  { background: #06b6d4; box-shadow: 0 0 6px rgba(6, 182, 212, 0.5); }
.diff-dot.off { background: rgba(51, 65, 85, 0.6); }

/* ── Module badge ──────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}
.badge-cyan    { background: rgba(6,182,212,0.12); color: #22d3ee; }
.badge-violet  { background: rgba(139,92,246,0.12); color: #a78bfa; }
.badge-amber   { background: rgba(245,158,11,0.12); color: #fbbf24; }
.badge-emerald { background: rgba(16,185,129,0.12); color: #34d399; }

/* ── Code block ────────────────────────────────────────── */
.code-block {
    background: #0d1117;
    border: 1px solid rgba(99, 179, 237, 0.08);
    border-radius: 10px;
    padding: 16px 20px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    line-height: 1.7;
    overflow-x: auto;
    color: #c9d1d9;
    position: relative;
}
.code-block .lang-label {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 0.65rem;
    color: #484f58;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.06em;
}

/* ── Fiche sections ────────────────────────────────────── */
.fiche-section {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    padding: 24px 28px;
    margin-bottom: 20px;
}
.fiche-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Quiz styles ───────────────────────────────────────── */
.quiz-option {
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 14px 18px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 12px;
}
.quiz-option:hover {
    border-color: rgba(6, 182, 212, 0.3);
    background: rgba(6, 182, 212, 0.05);
}
.quiz-option.selected {
    border-color: #06b6d4;
    background: rgba(6, 182, 212, 0.1);
}
.quiz-option.correct {
    border-color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}
.quiz-option.incorrect {
    border-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}
.quiz-option .option-letter {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    background: rgba(30, 41, 59, 0.8);
    color: #94a3b8;
    flex-shrink: 0;
}
.quiz-option.selected .option-letter {
    background: rgba(6, 182, 212, 0.3);
    color: #22d3ee;
}

/* ── Annales card ──────────────────────────────────────── */
.annale-card {
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.2s ease;
}
.annale-card:hover {
    border-color: rgba(99, 179, 237, 0.18);
    transform: translateX(4px);
}
.annale-card .annale-arrow {
    transition: transform 0.2s ease;
}
.annale-card:hover .annale-arrow {
    transform: translateX(4px);
    color: #22d3ee;
}

/* ── PDF Viewer ────────────────────────────────────────── */
.pdf-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border: 1px solid rgba(99, 179, 237, 0.12);
    border-radius: 10px;
    background: rgba(15, 23, 42, 0.6);
    color: #94a3b8;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.25s ease;
    backdrop-filter: blur(8px);
}
.pdf-back-btn:hover {
    color: #22d3ee;
    border-color: rgba(6, 182, 212, 0.3);
    background: rgba(6, 182, 212, 0.08);
    transform: translateX(-3px);
}

.pdf-info-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    margin-bottom: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    border-radius: 12px;
    backdrop-filter: blur(12px);
}

.pdf-download-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(6, 182, 212, 0.1);
    color: #22d3ee;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
    border: 1px solid rgba(6, 182, 212, 0.15);
}
.pdf-download-btn:hover {
    background: rgba(6, 182, 212, 0.2);
    border-color: rgba(6, 182, 212, 0.35);
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(6, 182, 212, 0.15);
}

.pdf-viewer-container {
    position: relative;
    width: 100%;
    height: 80vh;
    border-radius: 12px;
    overflow: hidden;
    background: #0d1117;
    border: 1px solid var(--border-subtle);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.pdf-loading-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(7, 12, 27, 0.9);
    z-index: 10;
    border-radius: 12px;
}

.pdf-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(6, 182, 212, 0.15);
    border-top-color: #06b6d4;
    border-radius: 50%;
    animation: pdfSpin 0.8s linear infinite;
}

@keyframes pdfSpin {
    to { transform: rotate(360deg); }
}

.pdf-error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    text-align: center;
    height: 100%;
}

.pdf-error-icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
    animation: fadeIn 0.5s ease both;
}

@media (max-width: 768px) {
    .pdf-viewer-container {
        height: 60vh;
    }
    .pdf-info-bar {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
}

/* ── Animations ────────────────────────────────────────── */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}
@keyframes slideInLeft {
    from { opacity: 0; transform: translateX(-20px); }
    to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 8px rgba(6, 182, 212, 0.2); }
    50%      { box-shadow: 0 0 20px rgba(6, 182, 212, 0.4); }
}

.animate-in {
    animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) both;
}
.animate-fade {
    animation: fadeIn 0.4s ease both;
}

/* Stagger children */
.stagger > * { animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0.05s; }
.stagger > *:nth-child(2) { animation-delay: 0.1s; }
.stagger > *:nth-child(3) { animation-delay: 0.15s; }
.stagger > *:nth-child(4) { animation-delay: 0.2s; }
.stagger > *:nth-child(5) { animation-delay: 0.25s; }
.stagger > *:nth-child(6) { animation-delay: 0.3s; }
.stagger > *:nth-child(7) { animation-delay: 0.35s; }
.stagger > *:nth-child(8) { animation-delay: 0.4s; }

/* ── KaTeX dark override ───────────────────────────────── */
.katex { color: #e2e8f0 !important; }
.katex .mord, .katex .mbin, .katex .mrel,
.katex .mop, .katex .mpunct { color: #e2e8f0 !important; }

/* ── Mermaid dark override ─────────────────────────────── */
.mermaid svg { max-width: 100%; }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
    #sidebar { transform: translateX(-100%); transition: transform 0.3s ease; }
    #sidebar.open { transform: translateX(0); }
    main { margin-left: 0 !important; }
    #mobile-toggle { display: flex !important; }
}

/* ── Empty state ───────────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}
.empty-state .icon {
    font-size: 3.5rem;
    margin-bottom: 16px;
    opacity: 0.6;
}

/* ── Tooltip ───────────────────────────────────────────── */
.tooltip {
    position: relative;
}
.tooltip::after {
    content: attr(data-tip);
    position: absolute;
    bottom: 110%;
    left: 50%;
    transform: translateX(-50%);
    background: #1e293b;
    color: #e2e8f0;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}
.tooltip:hover::after { opacity: 1; }

/* ── Page transition ───────────────────────────────────── */
#app {
    transition: opacity 0.2s ease;
}

/* ═══════════════════════════════════════════════════════════
   NumWorks Calculator — FAB + Draggable Panel
   ═══════════════════════════════════════════════════════════ */

/* ── FAB Button ─────────────────────────────────────────── */
#calc-fab {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 900;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 22px;
    border: none;
    border-radius: 16px;
    background: linear-gradient(135deg, #06b6d4, #3b82f6);
    color: #fff;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow:
        0 4px 24px rgba(6, 182, 212, 0.35),
        0 0 0 0 rgba(6, 182, 212, 0);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    letter-spacing: 0.01em;
}

#calc-fab:hover {
    transform: translateY(-3px) scale(1.03);
    box-shadow:
        0 8px 32px rgba(6, 182, 212, 0.45),
        0 0 0 4px rgba(6, 182, 212, 0.12);
}

#calc-fab:active {
    transform: translateY(-1px) scale(0.98);
}

#calc-fab.active {
    background: linear-gradient(135deg, #0e7490, #1d4ed8);
    box-shadow:
        0 4px 16px rgba(6, 182, 212, 0.25),
        0 0 0 3px rgba(6, 182, 212, 0.15);
}

.calc-fab-icon {
    width: 22px;
    height: 22px;
    flex-shrink: 0;
}

.calc-fab-label {
    white-space: nowrap;
}

/* ── Pulse animation on idle ───────────────────────────── */
@keyframes calcFabPulse {
    0%, 100% { box-shadow: 0 4px 24px rgba(6, 182, 212, 0.35), 0 0 0 0 rgba(6, 182, 212, 0); }
    50%      { box-shadow: 0 4px 24px rgba(6, 182, 212, 0.35), 0 0 0 8px rgba(6, 182, 212, 0.08); }
}

#calc-fab:not(:hover):not(.active) {
    animation: calcFabPulse 3s ease-in-out infinite;
}

/* ── Backdrop ──────────────────────────────────────────── */
#calc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 950;
    background: rgba(3, 7, 18, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.35s ease;
}

#calc-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

/* ── Panel ─────────────────────────────────────────────── */
#calc-panel {
    position: fixed;
    z-index: 1000;
    right: 24px;
    bottom: 100px;
    width: 370px;

    background: rgba(10, 17, 35, 0.95);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(6, 182, 212, 0.18);
    border-radius: 16px;
    box-shadow:
        0 20px 60px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(6, 182, 212, 0.06),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);

    opacity: 0;
    pointer-events: none;
    transform: translateY(24px) scale(0.96);
    transition: opacity 0.35s ease, transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

#calc-panel.open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

#calc-panel.dragging {
    cursor: grabbing;
    box-shadow:
        0 30px 80px rgba(0, 0, 0, 0.6),
        0 0 0 2px rgba(6, 182, 212, 0.25);
}

/* ── Panel Header (drag handle) ────────────────────────── */
#calc-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(99, 179, 237, 0.08);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    border-radius: 16px 16px 0 0;
    background: rgba(15, 23, 42, 0.4);
}

#calc-panel-header:active {
    cursor: grabbing;
}

.calc-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.calc-header-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: linear-gradient(135deg, rgba(6, 182, 212, 0.2), rgba(59, 130, 246, 0.2));
    display: flex;
    align-items: center;
    justify-content: center;
    color: #22d3ee;
}

.calc-header-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: #e2e8f0;
    letter-spacing: 0.01em;
}

.calc-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.calc-header-actions button {
    width: 30px;
    height: 30px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.calc-header-actions button:hover {
    background: rgba(99, 179, 237, 0.08);
    color: #94a3b8;
}

#calc-close-btn:hover {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #f87171 !important;
}

/* ── Panel Body ────────────────────────────────────────── */
#calc-panel-body {
    border-radius: 0 0 16px 16px;
    overflow: hidden;
    line-height: 0;
}

#calc-iframe {
    width: 100%;
    max-height: 70vh;
}

/* ── Responsive FAB ────────────────────────────────────── */
@media (max-width: 768px) {
    #calc-fab {
        bottom: 20px;
        right: 20px;
        padding: 12px 16px;
        border-radius: 14px;
        font-size: 0.75rem;
    }

    .calc-fab-label {
        display: none;
    }

    #calc-panel {
        right: 8px;
        left: 8px;
        bottom: 80px;
        width: auto;
    }
}
