/* Eduwise Paper Bank — Dark Material Design */

:root {
    --qp-header-h: 56px;
    --qp-footer-h: 44px;
    --qp-bottom-nav-h: 64px;

    --md-bg: #0a0a0a;
    --md-surface: #141414;
    --md-surface-2: #1e1e1e;
    --md-surface-3: #262626;
    --md-surface-4: #2e2e2e;
    --md-primary: #90caf9;
    --md-primary-dark: #42a5f5;
    --md-accent: #82b1ff;
    --md-success: #66bb6a;
    --md-warning: #ffa726;
    --md-danger: #ef5350;
    --md-text: #f5f5f5;
    --md-text-secondary: #9e9e9e;
    --md-border: #333;
    --md-border-light: #404040;
    --md-ripple: rgba(144, 202, 249, 0.12);
    --md-elevation-1: 0 2px 8px rgba(0, 0, 0, 0.55), 0 1px 3px rgba(0, 0, 0, 0.45);
    --md-elevation-2: 0 8px 28px rgba(0, 0, 0, 0.6), 0 4px 12px rgba(0, 0, 0, 0.45);
    --md-elevation-3: 0 16px 48px rgba(0, 0, 0, 0.65);
    --shadow-blue: 0 10px 36px rgba(33, 150, 243, 0.38), 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-green: 0 10px 36px rgba(76, 175, 80, 0.35), 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-purple: 0 10px 36px rgba(156, 39, 176, 0.35), 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-cyan: 0 10px 36px rgba(0, 188, 212, 0.32), 0 4px 14px rgba(0, 0, 0, 0.45);
    --shadow-orange: 0 10px 36px rgba(255, 152, 0, 0.3), 0 4px 14px rgba(0, 0, 0, 0.45);
    --formula-accent: #b388ff;
    --formula-accent-dim: #7c4dff;
    --formula-glow: rgba(179, 136, 255, 0.35);
    --md-radius: 14px;
    --md-radius-sm: 8px;
}

* { box-sizing: border-box; }

html {
    scroll-behavior: smooth;
}

body.qp-app {
    margin: 0;
    background:
        radial-gradient(ellipse 120% 80% at 50% -20%, rgba(33, 150, 243, 0.14) 0%, transparent 55%),
        radial-gradient(ellipse 80% 50% at 100% 50%, rgba(156, 39, 176, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse 60% 40% at 0% 80%, rgba(0, 188, 212, 0.06) 0%, transparent 45%),
        var(--md-bg);
    color: var(--md-text);
    font-family: 'Roboto', 'Segoe UI', system-ui, -apple-system, sans-serif;
    padding-top: var(--qp-header-h);
    padding-bottom: var(--qp-footer-h);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ── App bar (header) ── */
.qp-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--qp-header-h);
    z-index: 1040;
    background: #000;
    border-bottom: 1px solid var(--md-border);
    box-shadow: var(--md-elevation-2);
}

.qp-nav {
    padding: 0;
    height: var(--qp-header-h);
}

.qp-nav .navbar-brand {
    font-size: 1.05rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    color: var(--md-text) !important;
    gap: 0.35rem;
}

.qp-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: linear-gradient(135deg, #1565c0, #42a5f5);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem !important;
}

.qp-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.qp-brand-text small {
    font-size: 0.62rem;
    font-weight: 400;
    color: var(--md-text-secondary);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.qp-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: var(--md-radius-sm);
    padding: 0.5rem 0.85rem !important;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--md-text-secondary) !important;
    transition: background 0.2s, color 0.2s;
}

.qp-nav .nav-link:hover {
    background: var(--md-surface-3);
    color: var(--md-text) !important;
}

.qp-nav .nav-link.active {
    background: var(--md-ripple);
    color: var(--md-primary) !important;
}

.qp-nav .dropdown-toggle::after {
    margin-left: 0.35rem;
    vertical-align: 0.15em;
}

.qp-nav-dropdown {
    background: var(--md-surface-2, #1a1a1a);
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius-sm);
    padding: 0.35rem;
    min-width: 12rem;
    box-shadow: var(--md-elevation-3);
}

.qp-nav-dropdown .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--md-text-secondary);
}

.qp-nav-dropdown .dropdown-item:hover,
.qp-nav-dropdown .dropdown-item:focus {
    background: var(--md-surface-3);
    color: var(--md-text);
}

.qp-nav-dropdown .dropdown-item.active {
    background: var(--md-ripple);
    color: var(--md-primary);
}

.qp-settings-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--md-text-secondary) !important;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.2s, color 0.2s;
}

.qp-settings-btn:hover,
.qp-settings-btn:focus {
    background: var(--md-surface-3);
    color: var(--md-primary) !important;
}

.qp-settings-btn .material-icons {
    transition: transform 0.35s ease;
}

.qp-settings-btn:hover .material-icons {
    transform: rotate(45deg);
}

.qp-support-btn {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    color: var(--md-text-secondary) !important;
    cursor: pointer;
    width: 100%;
    text-align: left;
    transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.qp-support-btn:hover,
.qp-support-btn:focus {
    background: rgba(0, 188, 212, 0.12);
    color: #4dd0e1 !important;
    box-shadow: inset 0 0 0 1px rgba(0, 188, 212, 0.25);
}

.qp-support-btn .material-icons {
    transition: transform 0.25s ease;
}

.qp-support-btn:hover .material-icons {
    transform: scale(1.08);
}

/* ── Support / license modal ── */
.qp-support-modal {
    overflow: hidden;
    border-radius: 18px !important;
    box-shadow:
        0 28px 80px rgba(0, 0, 0, 0.75),
        0 0 60px rgba(0, 188, 212, 0.12),
        0 0 40px rgba(124, 77, 255, 0.1);
}

.qp-support-hero {
    position: relative;
    padding: 2rem 1.5rem 1.75rem;
    background:
        linear-gradient(135deg, #061018 0%, #0d1f35 38%, #1a1038 72%, #0a1628 100%);
    border-bottom: 1px solid rgba(77, 208, 225, 0.2);
    overflow: hidden;
}

.qp-support-hero-glow {
    position: absolute;
    inset: -40% -20% auto;
    height: 140%;
    background:
        radial-gradient(ellipse 55% 45% at 50% 0%, rgba(0, 188, 212, 0.28) 0%, transparent 62%),
        radial-gradient(ellipse 40% 35% at 85% 20%, rgba(124, 77, 255, 0.22) 0%, transparent 55%);
    pointer-events: none;
}

.qp-support-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    z-index: 2;
    opacity: 0.85;
}

.qp-support-hero-inner {
    position: relative;
    z-index: 1;
}

.qp-support-product-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #1565c0, #00acc1);
    box-shadow:
        0 12px 32px rgba(0, 172, 193, 0.35),
        0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}

.qp-support-product-icon .material-icons {
    font-size: 2.2rem;
    color: #fff;
}

.qp-support-product-name {
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: 0.01em;
    color: #fff;
}

.qp-support-product-tagline {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.62);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.qp-support-body {
    background: linear-gradient(180deg, var(--md-surface) 0%, #101010 100%);
}

.qp-support-license-strip {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 0;
    padding: 1.1rem 1.5rem;
    background: linear-gradient(90deg, rgba(102, 187, 106, 0.12), rgba(0, 188, 212, 0.08));
    border-bottom: 1px solid rgba(102, 187, 106, 0.22);
}

.qp-support-license-icon {
    font-size: 2rem !important;
    color: #81c784;
    flex-shrink: 0;
}

.qp-support-license-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--md-text-secondary);
    margin-bottom: 0.15rem;
}

.qp-support-license-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--md-text);
    line-height: 1.25;
}

.qp-support-section {
    padding-top: 1.25rem;
}

.qp-support-dev-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.15rem;
    border-radius: var(--md-radius);
    background: var(--md-surface-2);
    border: 1px solid var(--md-border);
    box-shadow: var(--md-elevation-1);
}

.qp-support-dev-avatar {
    width: 52px;
    height: 52px;
    border-radius: 14px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(124, 77, 255, 0.35), rgba(179, 136, 255, 0.2));
    border: 1px solid rgba(179, 136, 255, 0.35);
}

.qp-support-dev-avatar .material-icons {
    color: #ce93d8;
    font-size: 1.6rem;
}

.qp-support-dev-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--md-text-secondary);
    margin-bottom: 0.2rem;
}

.qp-support-dev-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--md-text);
}

.qp-support-dev-company {
    font-size: 0.88rem;
    color: var(--md-primary);
    margin-top: 0.1rem;
}

.qp-support-contact-card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
    height: 100%;
    padding: 1rem;
    border-radius: var(--md-radius-sm);
    text-decoration: none;
    color: inherit;
    background: var(--md-surface-2);
    border: 1px solid var(--md-border);
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.qp-support-contact-card:hover {
    transform: translateY(-2px);
    color: inherit;
    background: var(--md-surface-3);
    border-color: rgba(144, 202, 249, 0.35);
    box-shadow: var(--md-elevation-2);
}

.qp-support-contact-icon {
    font-size: 1.35rem !important;
    padding: 0.45rem;
    border-radius: 10px;
    background: var(--md-surface-3);
}

.qp-support-contact-icon--phone { color: #66bb6a; background: rgba(102, 187, 106, 0.12); }
.qp-support-contact-icon--mail { color: #42a5f5; background: rgba(66, 165, 245, 0.12); }
.qp-support-contact-icon--web { color: #4dd0e1; background: rgba(77, 208, 225, 0.12); }

.qp-support-contact-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--md-text-secondary);
}

.qp-support-contact-value {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--md-text);
    word-break: break-word;
    line-height: 1.35;
}

.qp-support-footer {
    background: #0c0c0c !important;
    padding: 0.85rem 1.5rem 1.15rem !important;
}

@media (max-width: 767.98px) {
    .qp-support-product-name {
        font-size: 1.3rem;
    }

    .qp-support-contacts .col-md-4 + .col-md-4 {
        margin-top: 0;
    }
}

.qp-settings-list {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.88rem;
    background: var(--md-surface-2);
    border-color: var(--md-border);
}

.qp-db-migration-box {
    border-color: rgba(56, 189, 248, 0.35) !important;
    background: rgba(56, 189, 248, 0.06);
}

.qp-settings-modal-dialog {
    max-width: 60%;
    width: 60%;
}

.qp-settings-tabs .nav-link {
    font-weight: 600;
}

#qpGeminiKeysTable input.form-control-sm {
    min-width: 7rem;
}

@media (max-width: 991.98px) {
    .qp-settings-modal-dialog {
        max-width: calc(100% - 1rem);
        width: auto;
    }
}

.qp-nav-icon {
    font-size: 1.15rem !important;
}

.navbar-toggler {
    border-color: var(--md-border-light);
    padding: 0.35rem 0.55rem;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 2px var(--md-ripple);
}

/* ── Footer (desktop) ── */
.qp-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--qp-footer-h);
    z-index: 1030;
    background: #000;
    color: var(--md-text-secondary);
    font-size: 0.78rem;
    display: flex;
    align-items: center;
    border-top: 1px solid var(--md-border);
}

.qp-main {
    min-height: calc(100vh - var(--qp-header-h) - var(--qp-footer-h));
}

/* ── Mobile bottom nav ── */
.qp-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--qp-bottom-nav-h);
    z-index: 1045;
    background: #000;
    border-top: 1px solid var(--md-border);
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.5);
}

.qp-bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    color: var(--md-text-secondary);
    text-decoration: none;
    font-size: 0.65rem;
    font-weight: 500;
    padding: 0.35rem 0;
    transition: color 0.2s;
}

.qp-bottom-nav a .material-icons {
    font-size: 1.35rem;
}

.qp-bottom-nav a.active {
    color: var(--md-primary);
}

.qp-bottom-nav a:hover {
    color: var(--md-text);
}

.qp-bottom-nav-profile {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.15rem;
    min-width: 0;
    padding: 0.35rem 0;
    border: 0;
    background: transparent;
    color: var(--md-text-secondary);
    font-size: 0.65rem;
    font-weight: 500;
}

.qp-bottom-nav-profile .material-icons {
    font-size: 1.35rem;
}

.qp-bottom-nav-profile:hover {
    color: var(--md-text);
}

/* ── Typography ── */
.qp-page-title {
    font-weight: 500;
    color: var(--md-text);
    letter-spacing: -0.01em;
    font-size: clamp(1.25rem, 4vw, 1.65rem);
}

.qp-page-sub {
    color: var(--md-text-secondary);
    font-size: 0.9rem;
}

.qp-page-sub a {
    color: var(--md-primary);
}

/* ── Cards & surfaces ── */
.qp-card {
    background: linear-gradient(145deg, var(--md-surface) 0%, #111 100%);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--md-radius);
    box-shadow:
        var(--md-elevation-2),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s;
}

.qp-card:hover {
    transform: translateY(-2px);
    border-color: rgba(144, 202, 249, 0.15);
    box-shadow:
        0 12px 40px rgba(33, 150, 243, 0.18),
        var(--md-elevation-2),
        0 0 0 1px rgba(144, 202, 249, 0.08) inset;
}

.qp-panel {
    background: linear-gradient(160deg, var(--md-surface-2) 0%, #161616 100%);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: var(--md-radius);
    box-shadow:
        0 6px 24px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(255, 255, 255, 0.04) inset;
    transition: box-shadow 0.25s, border-color 0.25s;
}

.qp-panel:hover {
    border-color: rgba(179, 136, 255, 0.2);
    box-shadow:
        0 8px 32px rgba(124, 77, 255, 0.15),
        0 6px 24px rgba(0, 0, 0, 0.5);
}

.qp-section-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: var(--md-text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.qp-section-title .material-icons {
    font-size: 1rem;
    color: var(--md-primary);
}

/* ── Gradient dashboard cards ── */
.qp-dash-card {
    position: relative;
    border: none;
    border-radius: 16px;
    padding: 1.25rem 1.35rem;
    overflow: hidden;
    color: #fff;
    min-height: 110px;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.qp-dash-card::before {
    content: "";
    position: absolute;
    top: -40%;
    right: -20%;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.12);
    pointer-events: none;
}

.qp-dash-card::after {
    content: "";
    position: absolute;
    bottom: -30%;
    left: -10%;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.15);
    pointer-events: none;
}

.qp-dash-card:hover {
    transform: translateY(-4px) scale(1.01);
}

.qp-dash-card--blue {
    background: linear-gradient(135deg, #0d47a1 0%, #1565c0 45%, #42a5f5 100%);
    box-shadow: var(--shadow-blue);
}

.qp-dash-card--blue:hover {
    box-shadow: 0 14px 48px rgba(33, 150, 243, 0.5), 0 6px 20px rgba(0, 0, 0, 0.4);
}

.qp-dash-card--green {
    background: linear-gradient(135deg, #1b5e20 0%, #2e7d32 45%, #66bb6a 100%);
    box-shadow: var(--shadow-green);
}

.qp-dash-card--green:hover {
    box-shadow: 0 14px 48px rgba(76, 175, 80, 0.48), 0 6px 20px rgba(0, 0, 0, 0.4);
}

.qp-dash-card--cyan {
    background: linear-gradient(135deg, #006064 0%, #00838f 45%, #26c6da 100%);
    box-shadow: var(--shadow-cyan);
}

.qp-dash-card--cyan:hover {
    box-shadow: 0 14px 48px rgba(0, 188, 212, 0.45), 0 6px 20px rgba(0, 0, 0, 0.4);
}

.qp-dash-card--purple {
    background: linear-gradient(135deg, #4a148c 0%, #7b1fa2 45%, #ab47bc 100%);
    box-shadow: var(--shadow-purple);
}

.qp-dash-card--purple:hover {
    box-shadow: 0 14px 48px rgba(156, 39, 176, 0.45), 0 6px 20px rgba(0, 0, 0, 0.4);
}

.qp-dash-card--orange {
    background: linear-gradient(135deg, #e65100 0%, #ef6c00 45%, #ffa726 100%);
    box-shadow: var(--shadow-orange);
}

.qp-dash-icon {
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.18);
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    z-index: 1;
}

.qp-dash-icon .material-icons {
    font-size: 1.35rem;
    opacity: 0.95;
}

.qp-dash-label {
    font-size: 0.78rem;
    font-weight: 500;
    opacity: 0.88;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    position: relative;
    z-index: 1;
}

.qp-dash-value {
    font-size: clamp(1.75rem, 5vw, 2.25rem);
    font-weight: 700;
    line-height: 1.15;
    margin-top: 0.35rem;
    position: relative;
    z-index: 1;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

/* legacy stat card fallback */
.qp-stat-card {
    border: 1px solid var(--md-border) !important;
    border-radius: var(--md-radius) !important;
    background: var(--md-surface) !important;
    border-left: 4px solid var(--md-primary-dark) !important;
    transition: transform 0.2s, box-shadow 0.2s;
    color: var(--md-text);
    box-shadow: var(--shadow-blue);
}

.qp-stat-card:hover {
    transform: translateY(-2px);
}

.qp-stat-card.qp-stat-success { border-left-color: var(--md-success) !important; box-shadow: var(--shadow-green); }
.qp-stat-card.qp-stat-info { border-left-color: var(--md-accent) !important; box-shadow: var(--shadow-cyan); }

.qp-stat-card .display-6 {
    font-size: clamp(1.5rem, 5vw, 1.85rem);
    font-weight: 700;
    color: var(--md-primary);
}

.qp-stat-card.qp-stat-success .display-6 { color: var(--md-success); }
.qp-stat-card.qp-stat-info .display-6 { color: var(--md-accent); }

/* ── Question cards ── */
.qp-math-block {
    line-height: 1.75;
    word-break: break-word;
    color: var(--md-text);
}

.qp-option {
    margin: 0.25rem 0 0.25rem 0.5rem;
    padding: 0.35rem 0.5rem;
    border-radius: var(--md-radius-sm);
}

.qp-q-card {
    background: linear-gradient(145deg, #181818 0%, var(--md-surface) 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.07) !important;
    border-radius: var(--md-radius) !important;
    transition: box-shadow 0.25s, border-color 0.25s, transform 0.25s;
    color: var(--md-text);
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.03) inset;
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
}

#qpQuestionsList {
    overflow-x: hidden;
    max-width: 100%;
}

.qp-q-card:hover {
    transform: translateY(-2px);
    box-shadow:
        0 10px 36px rgba(33, 150, 243, 0.2),
        0 4px 20px rgba(0, 0, 0, 0.5);
    border-color: rgba(66, 165, 245, 0.25) !important;
}

.qp-q-card .card-body {
    padding: 1rem;
}

.qp-answer-badge {
    display: inline-block;
    background: rgba(102, 187, 106, 0.15);
    color: #a5d6a7;
    border-radius: var(--md-radius-sm);
    padding: 0.2rem 0.65rem;
    font-weight: 500;
    font-size: 0.88rem;
    border: 1px solid rgba(102, 187, 106, 0.35);
}

.qp-badge-ai {
    background: rgba(66, 165, 245, 0.2);
    color: #90caf9;
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.qp-badge-manual {
    background: rgba(255, 167, 38, 0.2);
    color: #ffcc80;
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
}

.qp-badge-scan {
    background: rgba(102, 187, 106, 0.2);
    color: #a5d6a7;
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.qp-badge-reference {
    background: rgba(255, 213, 79, 0.18);
    color: #ffe082;
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.7rem;
    font-weight: 600;
    max-width: 100%;
    white-space: normal;
    text-align: left;
}

.qp-badge-question-source {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    background: rgba(96, 165, 250, 0.14) !important;
    color: #93c5fd !important;
    border: 1px solid rgba(147, 197, 253, 0.28);
    border-radius: 6px;
    padding: 0.28rem 0.55rem;
    font-size: 0.72rem;
    font-weight: 600;
    max-width: 100%;
    white-space: normal;
    text-align: left;
    line-height: 1.35;
}

.qp-badge-question-source .qp-src-icon {
    font-size: 0.95rem;
    line-height: 1;
    flex-shrink: 0;
}

.qp-badge-question-source--link {
    cursor: pointer;
    border: none;
    text-align: left;
}

.qp-badge-question-source--link:hover,
.qp-badge-question-source--link:focus {
    background: rgba(96, 165, 250, 0.24) !important;
    color: #bfdbfe !important;
    outline: none;
    box-shadow: 0 0 0 2px rgba(147, 197, 253, 0.35);
}

.qp-badge-question-source .qp-src-open-icon {
    font-size: 0.85rem;
    opacity: 0.75;
    margin-left: 0.15rem;
}

.qp-rag-pdf-modal-body {
    min-height: 60vh;
    max-height: calc(100vh - 10rem);
    display: flex;
    flex-direction: column;
    background: #3a3f44;
}

.qp-rag-pdf-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: #cbd5e1;
}

.qp-rag-pdf-scroll {
    flex: 1 1 auto;
    overflow: auto;
    padding: 1rem;
    min-height: 0;
}

.qp-rag-pdf-pages {
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.qp-rag-pdf-page {
    background: #fff;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
}

.qp-rag-pdf-page--target {
    box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.85), 0 2px 12px rgba(0, 0, 0, 0.35);
}

.qp-rag-pdf-dock {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1060;
    display: flex;
    align-items: stretch;
    gap: 0.35rem;
    max-width: min(420px, calc(100vw - 2rem));
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.96), rgba(30, 41, 59, 0.96));
    border: 1px solid rgba(147, 197, 253, 0.35);
    border-radius: 12px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    padding: 0.35rem;
    backdrop-filter: blur(8px);
}

.qp-rag-pdf-dock-main {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    border: none;
    background: transparent;
    color: #e2e8f0;
    text-align: left;
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    cursor: pointer;
}

.qp-rag-pdf-dock-main:hover,
.qp-rag-pdf-dock-main:focus {
    background: rgba(96, 165, 250, 0.15);
    outline: none;
}

.qp-rag-pdf-dock-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.qp-rag-pdf-dock-title {
    font-size: 0.82rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qp-rag-pdf-dock-sub {
    font-size: 0.72rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.qp-rag-pdf-dock-close {
    flex-shrink: 0;
    align-self: center;
    padding: 0.2rem 0.35rem;
    line-height: 1;
}

.qp-reference-checkboxes {
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius-sm);
    padding: 0.55rem 0.65rem;
    background: rgba(255, 255, 255, 0.02);
    max-height: 9.5rem;
    overflow-y: auto;
}

.qp-badge-diagram {
    background: rgba(171, 71, 188, 0.2);
    color: #ce93d8;
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.qp-badge-rag-active,
.qp-badge-rag-fallback,
.qp-badge-rag-scan,
.qp-badge-rag-off {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    border-radius: 6px;
    padding: 0.18rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 700;
    vertical-align: middle;
}

.qp-badge-rag-active {
    background: rgba(34, 197, 94, 0.18);
    color: #86efac;
    border: 1px solid rgba(74, 222, 128, 0.35);
}

.qp-badge-rag-fallback {
    background: rgba(251, 191, 36, 0.15);
    color: #fcd34d;
    border: 1px solid rgba(251, 191, 36, 0.32);
}

.qp-badge-rag-scan,
.qp-badge-rag-off {
    background: rgba(148, 163, 184, 0.14);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.28);
}

.qp-rag-icon,
.qp-rag-banner-icon {
    font-size: 0.95rem;
    line-height: 1;
}

.qp-rag-session-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.35rem;
    line-height: 1.45;
}

.qp-rag-session-banner .qp-badge-rag-active {
    font-size: 0.68rem;
    padding: 0.1rem 0.35rem;
}

.qp-badge-date {
    background: var(--md-surface-3);
    color: var(--md-text-secondary);
    border: 1px solid var(--md-border);
    border-radius: 6px;
    padding: 0.1rem 0.45rem;
    font-size: 0.75rem;
}

/* ── Bootstrap dark overrides ── */
.qp-app .form-control,
.qp-app .form-select {
    background: var(--md-surface-2);
    border: 1px solid var(--md-border);
    color: var(--md-text);
    border-radius: var(--md-radius-sm);
    font-size: 0.9rem;
}

.qp-app .form-control:focus,
.qp-app .form-select:focus {
    background: var(--md-surface-3);
    border-color: var(--md-primary-dark);
    color: var(--md-text);
    box-shadow:
        0 0 0 3px rgba(66, 165, 245, 0.22),
        0 4px 16px rgba(33, 150, 243, 0.15);
}

.qp-app .form-control::placeholder {
    color: #666;
}

.qp-app .form-label {
    color: var(--md-text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
}

.qp-app .form-check-input {
    background-color: var(--md-surface-3);
    border-color: var(--md-border-light);
}

.qp-app .form-check-input:checked {
    background-color: var(--md-primary-dark);
    border-color: var(--md-primary-dark);
}

.qp-app .form-check-label {
    color: var(--md-text);
}

.qp-app .btn {
    border-radius: var(--md-radius-sm);
    font-weight: 500;
    letter-spacing: 0.02em;
    text-transform: none;
    transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
}

.qp-app .btn:active {
    transform: scale(0.98);
}

.qp-app .btn-primary {
    background: linear-gradient(135deg, #1565c0, #1976d2);
    border-color: #1976d2;
    box-shadow: 0 4px 16px rgba(25, 118, 210, 0.4);
}

.qp-app .btn-primary:hover {
    background: linear-gradient(135deg, #0d47a1, #1565c0);
    border-color: #1565c0;
    box-shadow: 0 6px 24px rgba(25, 118, 210, 0.55);
}

.qp-app .btn-success {
    background: linear-gradient(135deg, #2e7d32, #43a047);
    border-color: #388e3c;
    box-shadow: 0 4px 16px rgba(56, 142, 60, 0.35);
}

.qp-app .btn-success:hover {
    background: linear-gradient(135deg, #1b5e20, #2e7d32);
    border-color: #2e7d32;
    box-shadow: 0 6px 24px rgba(56, 142, 60, 0.5);
}

.qp-app .btn-outline-primary {
    color: var(--md-primary);
    border-color: var(--md-primary-dark);
}

.qp-app .btn-outline-primary:hover {
    background: var(--md-ripple);
    color: var(--md-primary);
    border-color: var(--md-primary);
}

.qp-app .btn-outline-secondary {
    color: var(--md-text-secondary);
    border-color: var(--md-border-light);
}

.qp-app .btn-outline-secondary:hover {
    background: var(--md-surface-3);
    color: var(--md-text);
    border-color: var(--md-border-light);
}

.qp-app .btn-outline-danger {
    color: var(--md-danger);
    border-color: rgba(239, 83, 80, 0.5);
}

.qp-app .badge.bg-secondary {
    background: var(--md-surface-4) !important;
    color: var(--md-text-secondary);
}

.qp-app .badge.bg-primary-subtle {
    background: rgba(66, 165, 245, 0.15) !important;
    color: #90caf9 !important;
    border: 1px solid rgba(66, 165, 245, 0.3);
}

.qp-app .badge.bg-info-subtle {
    background: rgba(0, 188, 212, 0.15) !important;
    color: #80deea !important;
    border: 1px solid rgba(0, 188, 212, 0.3);
}

.qp-app .text-muted {
    color: var(--md-text-secondary) !important;
}

.qp-app a {
    color: var(--md-primary);
}

.qp-app .alert-info {
    background: rgba(66, 165, 245, 0.12);
    border-color: rgba(66, 165, 245, 0.35);
    color: #90caf9;
}

.qp-app .alert-secondary {
    background: var(--md-surface-2);
    border-color: var(--md-border);
    color: var(--md-text-secondary);
}

.qp-app .alert-warning {
    background: rgba(255, 167, 38, 0.12);
    border-color: rgba(255, 167, 38, 0.35);
    color: #ffcc80;
}

.qp-app .alert-danger {
    background: rgba(239, 83, 80, 0.12);
    border-color: rgba(239, 83, 80, 0.35);
    color: #ef9a9a;
}

.qp-app .alert-success {
    background: rgba(102, 187, 106, 0.12);
    border-color: rgba(102, 187, 106, 0.35);
    color: #a5d6a7;
}

.qp-app .table {
    color: var(--md-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--md-border);
}

.qp-app .table thead th,
.qp-app .table-light th,
.qp-app .table-light td {
    background: var(--md-surface-2) !important;
    color: var(--md-text-secondary) !important;
    border-color: var(--md-border);
}

.qp-app .table-hover tbody tr:hover {
    background: rgba(66, 165, 245, 0.06) !important;
}

.qp-app .table td,
.qp-app .table th {
    border-color: var(--md-border);
}

.qp-app .input-group .btn {
    border-radius: 0 var(--md-radius-sm) var(--md-radius-sm) 0;
}

/* ── Loading overlay ── */
.qp-loading {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 10, 0.92);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 0.75rem;
    color: var(--md-text);
}

.qp-loading.show { display: flex; }

.qp-loading-visual {
    position: relative;
    width: 88px;
    height: 88px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    background: rgba(0, 188, 212, 0.08);
    border: 1px solid rgba(0, 188, 212, 0.22);
    box-shadow: 0 0 32px rgba(0, 188, 212, 0.15);
}

.qp-loading-icon {
    font-size: 2.75rem !important;
    color: #22d3ee;
}

.qp-loading-sub {
    max-width: 28rem;
    text-align: center;
    line-height: 1.4;
}

.qp-loading-progress {
    width: min(320px, 80vw);
    height: 6px;
    background: rgba(148, 163, 184, 0.2);
    border-radius: 999px;
    overflow: hidden;
}

.qp-loading-progress .progress-bar {
    background: linear-gradient(90deg, #0891b2, #22d3ee, #67e8f9);
    transition: width 0.25s ease;
}

.qp-loading-bar-indeterminate {
    animation: qp-loading-bar-slide 1.4s ease-in-out infinite;
}

.qp-loading--generate .qp-loading-icon {
    animation: qp-loading-pulse 1.2s ease-in-out infinite;
}

.qp-loading--scan .qp-loading-icon {
    color: #38bdf8;
}

.qp-loading--scan .qp-loading-scan-line {
    display: block;
}

.qp-loading-scan-line {
    display: none;
    position: absolute;
    left: 8px;
    right: 8px;
    height: 2px;
    background: linear-gradient(90deg, transparent, #38bdf8, transparent);
    box-shadow: 0 0 10px rgba(56, 189, 248, 0.8);
    animation: qp-scan-line 1.6s ease-in-out infinite;
}

.qp-loading--upload .qp-loading-icon,
.qp-loading--rag .qp-loading-icon {
    animation: qp-loading-bounce 1s ease-in-out infinite;
}

@keyframes qp-loading-pulse {
    0%, 100% { transform: scale(1); opacity: 1; filter: drop-shadow(0 0 0 rgba(34, 211, 238, 0)); }
    50% { transform: scale(1.08); opacity: 0.92; filter: drop-shadow(0 0 12px rgba(34, 211, 238, 0.55)); }
}

@keyframes qp-scan-line {
    0% { top: 14px; opacity: 0.2; }
    50% { opacity: 1; }
    100% { top: 70px; opacity: 0.2; }
}

@keyframes qp-loading-bar-slide {
    0% { width: 12%; margin-left: 0; }
    50% { width: 45%; margin-left: 30%; }
    100% { width: 12%; margin-left: 88%; }
}

@keyframes qp-loading-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* ── Filters ── */
.qp-filter-bar {
    border-radius: var(--md-radius) !important;
    box-shadow:
        0 8px 32px rgba(0, 188, 212, 0.12),
        var(--md-elevation-2);
    border-color: rgba(0, 188, 212, 0.12) !important;
}

/* ── Split layout: 20% sidebar / 80% main (Paper Bank & Generator) ── */
.qp-bank-layout,
.qp-gen-layout {
    display: flex;
    gap: 1.25rem;
    align-items: flex-start;
}

.qp-bank-sidebar {
    width: 20%;
    flex: 0 0 20%;
    min-width: 200px;
    max-width: 280px;
    position: sticky;
    top: calc(var(--qp-header-h) + 1rem);
    max-height: calc(100vh - var(--qp-header-h) - var(--qp-footer-h) - 2rem);
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--md-border-light) transparent;
}

.qp-bank-sidebar .qp-section-title {
    font-size: 0.68rem;
}

.qp-bank-main {
    width: 80%;
    flex: 1 1 80%;
    min-width: 0;
}

.qp-bank-empty {
    border: 1px dashed rgba(144, 202, 249, 0.25);
    background: linear-gradient(145deg, rgba(20, 20, 20, 0.9), rgba(26, 26, 40, 0.5));
}

.qp-bank-empty-icon {
    font-size: 3rem;
    color: rgba(144, 202, 249, 0.45);
}

@media (max-width: 991.98px) {
    .qp-bank-layout {
        flex-direction: column;
    }

    .qp-bank-sidebar {
        width: 100%;
        flex: none;
        max-width: none;
        position: static;
        max-height: none;
        overflow: visible;
    }

    .qp-bank-main {
        width: 100%;
        flex: none;
    }
}

.qp-filter-bar .form-select,
.qp-filter-bar .form-control {
    font-size: 0.88rem;
}

.qp-multi-select {
    min-height: 5.5rem;
}

.qp-advanced-gen .qp-adv-chevron {
    transition: transform 0.2s ease;
}

.qp-advanced-panel textarea.qp-adv-query {
    font-size: 0.75rem;
    line-height: 1.45;
    resize: vertical;
    min-height: 8rem;
}

.qp-advanced-panel textarea.qp-adv-query::placeholder {
    color: rgba(176, 190, 197, 0.55);
    white-space: pre-line;
}

.qp-adv-tabs .nav-link {
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--md-on-surface-variant, #b0bec5);
    border-color: rgba(144, 202, 249, 0.15);
}

.qp-adv-tabs .nav-link.active {
    color: #4dd0e1;
    background: rgba(0, 188, 212, 0.08);
    border-color: rgba(0, 188, 212, 0.35);
}

#qpAdvancedGenModal .modal-dialog {
    max-height: calc(100vh - 1rem);
    margin: 0.5rem auto;
}

#qpAdvancedGenModal .modal-content {
    max-height: calc(100vh - 1rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#qpAdvancedGenModal .qp-adv-modal-form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#qpAdvancedGenModal .qp-adv-modal-body {
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    -webkit-overflow-scrolling: touch;
}

#qpAdvancedGenModal .modal-footer {
    flex-shrink: 0;
}

#qpAdvancedGenModal .qp-adv-multi-select {
    min-height: 6.5rem;
    max-height: 6.5rem;
}

#qpAdvancedGenModal .qp-adv-query {
    min-height: 10rem;
    max-height: 14rem;
    resize: vertical;
}

/* ── Poll UI ── */
.qp-poll-option {
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius-sm);
    padding: 0.7rem 1rem;
    margin-bottom: 0.5rem;
    cursor: pointer;
    transition: all 0.15s;
    background: var(--md-surface-2);
}

.qp-poll-option:hover {
    border-color: var(--md-primary-dark);
    background: var(--md-surface-3);
}

.qp-poll-option.selected {
    border-color: var(--md-primary);
    background: var(--md-ripple);
    box-shadow:
        0 0 0 2px rgba(66, 165, 245, 0.3),
        0 6px 20px rgba(33, 150, 243, 0.2);
}

.qp-score-ring {
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: conic-gradient(var(--md-success) calc(var(--pct) * 1%), var(--md-surface-3) 0);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
}

.qp-score-ring span {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: var(--md-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.5rem;
    color: var(--md-text);
}

/* ── Modals ── */
.qp-modal {
    border: 1px solid rgba(179, 136, 255, 0.2);
    border-radius: var(--md-radius);
    overflow: hidden;
    background: var(--md-surface);
    color: var(--md-text);
    box-shadow:
        0 24px 64px rgba(0, 0, 0, 0.7),
        0 0 48px rgba(124, 77, 255, 0.12);
}

.qp-modal-header {
    background: linear-gradient(135deg, #0a0a0a 0%, #1a1030 50%, #0d1a2e 100%);
    color: var(--md-text);
    border-bottom: 1px solid rgba(179, 136, 255, 0.2);
}

.qp-modal .modal-body {
    background: var(--md-surface);
}

.qp-modal .modal-footer {
    background: var(--md-surface-2);
    border-top: 1px solid var(--md-border);
}

.qp-save-count-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    background: linear-gradient(135deg, rgba(25, 118, 210, 0.15), rgba(124, 77, 255, 0.1));
    border: 1px solid rgba(66, 165, 245, 0.3);
    border-radius: var(--md-radius-sm);
    padding: 1rem 1.25rem;
    box-shadow: 0 4px 20px rgba(33, 150, 243, 0.15);
}

.qp-count-badge {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1565c0, #7c4dff);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    flex-shrink: 0;
    box-shadow: 0 4px 20px rgba(124, 77, 255, 0.45);
}

.qp-save-preview {
    max-height: 220px;
    overflow-y: auto;
    background: var(--md-surface-2);
    border-radius: var(--md-radius-sm);
    padding: 0.75rem;
    border: 1px solid rgba(179, 136, 255, 0.2);
    box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* ── Formula / equation UI ── */
.qp-math-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    align-items: center;
    padding: 0.75rem 0.85rem;
    background: linear-gradient(135deg, #12121f 0%, #1a1530 50%, #0f1a28 100%);
    border-radius: var(--md-radius-sm);
    border: 1px solid rgba(179, 136, 255, 0.28);
    box-shadow:
        0 6px 24px rgba(124, 77, 255, 0.18),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.qp-math-toolbar-label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--formula-accent);
    margin-right: 0.25rem;
}

.qp-math-btn {
    font-size: 0.8rem;
    min-width: 2.35rem;
    border-color: rgba(179, 136, 255, 0.35) !important;
    color: #e1bee7 !important;
    background: rgba(124, 77, 255, 0.1) !important;
    transition: all 0.2s ease;
}

.qp-math-btn:hover {
    background: rgba(124, 77, 255, 0.28) !important;
    border-color: var(--formula-accent) !important;
    color: #fff !important;
    box-shadow: 0 0 16px var(--formula-glow);
    transform: translateY(-1px);
}

.qp-math-btn:active {
    transform: scale(0.96);
}

.qp-formula-group {
    position: relative;
    border-radius: var(--md-radius-sm);
    transition: box-shadow 0.25s ease;
}

.qp-formula-group:focus-within {
    box-shadow:
        0 0 0 2px rgba(124, 77, 255, 0.45),
        0 8px 32px rgba(124, 77, 255, 0.2);
}

.qp-formula-group:focus-within .qp-formula-label {
    color: var(--formula-accent);
}

.qp-formula-label {
    transition: color 0.2s;
}

.qp-latex-field {
    font-family: 'Roboto Mono', 'Consolas', monospace;
    font-size: 0.9rem;
    border-radius: var(--md-radius-sm);
    border-color: rgba(179, 136, 255, 0.2);
    background: linear-gradient(180deg, #1a1525 0%, var(--md-surface-2) 100%);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.qp-latex-field:focus {
    border-color: var(--formula-accent) !important;
    background: linear-gradient(180deg, #1e1830 0%, var(--md-surface-3) 100%) !important;
    box-shadow:
        0 0 0 3px rgba(124, 77, 255, 0.25),
        0 4px 20px rgba(124, 77, 255, 0.18) !important;
    color: #f3e5f5;
}

.qp-latex-field::placeholder {
    color: rgba(179, 136, 255, 0.35);
}

.qp-live-preview {
    margin-top: 0.45rem;
    padding: 0.55rem 0.75rem;
    background: linear-gradient(90deg, rgba(124, 77, 255, 0.1) 0%, rgba(30, 30, 30, 0.6) 100%);
    border: 1px dashed rgba(179, 136, 255, 0.3);
    border-left: 3px solid rgba(124, 77, 255, 0.4);
    border-radius: var(--md-radius-sm);
    min-height: 2.25rem;
    font-size: 0.9rem;
    color: var(--md-text);
    transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}

.qp-formula-group:focus-within .qp-live-preview {
    border-left-color: var(--formula-accent);
    border-color: rgba(179, 136, 255, 0.45);
    background: linear-gradient(90deg, rgba(124, 77, 255, 0.18) 0%, rgba(30, 30, 30, 0.8) 100%);
    box-shadow: inset 0 0 20px rgba(124, 77, 255, 0.08);
}

.qp-live-preview.qp-has-math {
    border-left-color: var(--formula-accent);
    border-style: solid;
    background: linear-gradient(90deg, rgba(124, 77, 255, 0.14) 0%, rgba(26, 21, 40, 0.9) 100%);
    box-shadow: 0 2px 12px rgba(124, 77, 255, 0.12);
}

.qp-paste-zone {
    border-radius: var(--md-radius-sm);
    padding: 0.5rem;
    margin: -0.5rem;
    transition: box-shadow 0.25s, background 0.25s;
}

.qp-paste-zone:focus-within {
    background: rgba(124, 77, 255, 0.06);
    box-shadow:
        0 0 0 2px rgba(124, 77, 255, 0.5),
        0 8px 32px rgba(124, 77, 255, 0.22);
}

.qp-smart-paste {
    border-color: rgba(0, 188, 212, 0.3) !important;
    background: linear-gradient(180deg, #0d1f22 0%, var(--md-surface-2) 100%) !important;
}

.qp-smart-paste:focus {
    border-color: #26c6da !important;
    box-shadow:
        0 0 0 3px rgba(0, 188, 212, 0.22),
        0 4px 20px rgba(0, 188, 212, 0.15) !important;
}

.qp-crop-stage {
    max-height: 65vh;
    background: #111;
    border-radius: var(--md-radius-sm);
    overflow: hidden;
}

.qp-crop-stage img {
    display: block;
    max-width: 100%;
}

.qp-image-preview {
    background: #fff;
    padding: 0.5rem;
    border-radius: var(--md-radius-sm);
    border: 1px solid var(--md-border);
}

.qp-image-preview img {
    max-height: 280px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.qp-q-diagram-wrap {
    background: #fff;
    padding: 0.5rem;
    border-radius: var(--md-radius-sm);
    border: 1px solid var(--md-border);
    margin: 0.5rem 0;
    text-align: center;
}

.qp-q-diagram {
    max-width: 100%;
    max-height: 340px;
    width: auto;
    height: auto;
    object-fit: contain;
    margin: 0 auto;
    display: block;
    border-radius: 4px;
    background: #fff;
}

.qp-btn-icon {
    font-size: 1.1rem !important;
    vertical-align: middle;
    margin-right: 0.15rem;
}

.qp-action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

/* ── Save to Bank FAB ── */
.qp-save-fab {
    position: fixed;
    right: max(1.25rem, env(safe-area-inset-right, 0px));
    bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
    z-index: 1040;
    width: 3.75rem;
    height: 3.75rem;
    border: none;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #22c55e 0%, #15803d 100%);
    color: #fff;
    box-shadow:
        0 4px 14px rgba(21, 128, 61, 0.45),
        0 8px 28px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.qp-save-fab:hover,
.qp-save-fab:focus-visible {
    transform: scale(1.07) translateY(-2px);
    box-shadow:
        0 6px 20px rgba(21, 128, 61, 0.55),
        0 12px 32px rgba(0, 0, 0, 0.28);
    color: #fff;
    outline: none;
}

.qp-save-fab:active {
    transform: scale(0.96);
}

.qp-save-fab .material-icons {
    font-size: 1.75rem;
}

.qp-save-fab-count {
    position: absolute;
    top: -0.15rem;
    right: -0.15rem;
    min-width: 1.45rem;
    height: 1.45rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #fff;
    color: #15803d;
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1.45rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.qp-save-fab--active {
    animation: qp-save-fab-pop 0.35s ease;
}

@keyframes qp-save-fab-pop {
    0% { transform: scale(0.85); opacity: 0.6; }
    70% { transform: scale(1.08); }
    100% { transform: scale(1); opacity: 1; }
}

/* ── Paper Bank pick FAB ── */
.qp-pick-fab {
    position: fixed;
    right: max(1.25rem, env(safe-area-inset-right, 0px));
    bottom: max(1.5rem, env(safe-area-inset-bottom, 0px));
    z-index: 1040;
    width: 3.75rem;
    height: 3.75rem;
    border: none;
    border-radius: 50%;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(145deg, #42a5f5 0%, #1565c0 100%);
    color: #fff;
    box-shadow:
        0 4px 14px rgba(21, 101, 192, 0.45),
        0 8px 28px rgba(0, 0, 0, 0.22);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.qp-pick-fab:hover,
.qp-pick-fab:focus-visible {
    transform: scale(1.07) translateY(-2px);
    box-shadow:
        0 6px 20px rgba(21, 101, 192, 0.55),
        0 12px 32px rgba(0, 0, 0, 0.28);
    color: #fff;
    outline: none;
}

.qp-pick-fab:active {
    transform: scale(0.96);
}

.qp-pick-fab .material-icons {
    font-size: 1.65rem;
}

.qp-pick-fab-count {
    position: absolute;
    top: -0.15rem;
    right: -0.15rem;
    min-width: 1.45rem;
    height: 1.45rem;
    padding: 0 0.4rem;
    border-radius: 999px;
    background: #fff;
    color: #1565c0;
    font-size: 0.75rem;
    font-weight: 800;
    line-height: 1.45rem;
    text-align: center;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.25);
    pointer-events: none;
}

.qp-pick-fab--pop {
    animation: qp-save-fab-pop 0.35s ease;
}

.qp-picked-list {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.qp-picked-row {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.qp-picked-row-main {
    flex: 1;
    min-width: 0;
}

.qp-picked-row-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-bottom: 0.25rem;
}

.qp-picked-row-text {
    font-size: 0.9rem;
    line-height: 1.45;
    word-break: break-word;
}

.qp-picked-remove {
    flex-shrink: 0;
    padding: 0.2rem 0.45rem;
}

.qp-answer-confidence {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    padding: 0.35rem 0.55rem;
}

.qp-answer-confidence .qp-conf-icon {
    font-size: 0.95rem;
    line-height: 1;
}

.qp-conf-high {
    background: rgba(34, 197, 94, 0.18) !important;
    color: #4ade80 !important;
    border: 1px solid rgba(74, 222, 128, 0.35);
}

.qp-conf-med {
    background: rgba(245, 158, 11, 0.18) !important;
    color: #fbbf24 !important;
    border: 1px solid rgba(251, 191, 36, 0.35);
}

.qp-conf-low {
    background: rgba(239, 68, 68, 0.16) !important;
    color: #f87171 !important;
    border: 1px solid rgba(248, 113, 113, 0.35);
}

@media (max-width: 575.98px) {
    .qp-save-fab {
        right: max(1rem, env(safe-area-inset-right, 0px));
        bottom: max(4.30rem, env(safe-area-inset-bottom, 0px));
        width: 3.5rem;
        height: 3.5rem;
    }

    .qp-save-fab .material-icons {
        font-size: 1.55rem;
    }

    .qp-pick-fab {
        right: max(1rem, env(safe-area-inset-right, 0px));
        bottom: max(4.30rem, env(safe-area-inset-bottom, 0px));
        width: 3.5rem;
        height: 3.5rem;
    }

    .qp-pick-fab .material-icons {
        font-size: 1.45rem;
    }
}

/* ── Results ── */
.qp-results-table th {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--md-text-secondary);
}

.qp-results-table td {
    vertical-align: middle;
}

.qp-poll-stat {
    text-align: center;
    padding: 1.1rem 1rem;
    border-radius: var(--md-radius);
    background: linear-gradient(145deg, var(--md-surface-2), var(--md-surface));
    border: 1px solid rgba(255, 255, 255, 0.06);
    box-shadow: var(--md-elevation-2);
    transition: transform 0.25s, box-shadow 0.25s;
}

.qp-poll-stat:hover {
    transform: translateY(-2px);
}

.qp-poll-stat.qp-dash-card {
    text-align: left;
    padding: 1.1rem 1.25rem;
    min-height: 90px;
}

.qp-poll-stat.qp-dash-card .qp-dash-label {
    opacity: 0.9;
}

.qp-poll-stat.qp-dash-card .val,
.qp-poll-stat.qp-dash-card .qp-dash-value {
    font-size: clamp(1.2rem, 4vw, 1.55rem);
    font-weight: 700;
    color: #fff;
    margin-top: 0.25rem;
}

.qp-poll-stat .val {
    font-size: clamp(1.2rem, 4vw, 1.6rem);
    font-weight: 700;
    color: var(--md-primary);
}

/* KaTeX on dark — formula highlight */
.qp-app .katex {
    color: #e8eaf6;
}

.qp-live-preview .katex,
.qp-math-block .katex {
    color: #e1bee7;
}

.qp-math-mixed {
    white-space: normal;
    line-height: 1.75;
}

.qp-math-mixed .qp-text-segment {
    white-space: normal;
}

.qp-math-mixed .qp-math-segment {
    display: inline-block;
    vertical-align: baseline;
    margin: 0 0.12em;
}

.qp-math-mixed .qp-math-segment .katex {
    display: inline-block;
}

/* Prose explanations — preserve spaces, wrap long lines, no horizontal overflow */
.qp-prose-math,
.qp-math-block.qp-prose-math {
    overflow-wrap: anywhere;
    word-break: break-word;
    max-width: 100%;
    white-space: normal;
}

.qp-prose-math .qp-text-segment {
    white-space: normal;
}

.qp-prose-math .katex {
    white-space: normal;
}

.qp-formula-group:focus-within .katex {
    color: #f3e5f5;
}

.qp-answer-badge .katex {
    color: #a5d6a7;
}

/* ── Responsive: tablet & phone ── */
@media (max-width: 991.98px) {
    .qp-nav .navbar-collapse {
        background: #000;
        border-top: 1px solid var(--md-border);
        padding: 0.5rem 0 0.75rem;
        margin-top: 0.25rem;
        border-radius: 0 0 var(--md-radius-sm) var(--md-radius-sm);
    }

    .qp-nav .nav-link {
        padding: 0.65rem 1rem !important;
    }

    .qp-nav-dropdown {
        background: transparent;
        border: 0;
        box-shadow: none;
        padding: 0 0 0 0.75rem;
        margin: 0;
    }

    .qp-nav .dropdown-menu {
        position: static !important;
        float: none;
        transform: none !important;
    }
}

@media (max-width: 767.98px) {
    body.qp-app {
        padding-bottom: var(--qp-bottom-nav-h);
    }

    .qp-footer {
        display: none;
    }

    .qp-bottom-nav {
        display: flex;
    }

    .qp-main {
        min-height: calc(100vh - var(--qp-header-h) - var(--qp-bottom-nav-h));
    }

    .qp-brand-text span:not(small) {
        font-size: 0.95rem;
    }

    .qp-page-title {
        font-size: 1.2rem;
    }

    .qp-action-bar {
        width: 100%;
    }

    .qp-action-bar .btn {
        flex: 1 1 auto;
        font-size: 0.85rem;
        padding: 0.5rem 0.65rem;
    }

    .qp-filter-bar .col-md-2,
    .qp-filter-bar .col-md-4,
    .qp-filter-bar .col-md-8 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .qp-q-card .card-body {
        padding: 0.85rem;
    }

    .qp-q-card .float-end {
        float: none !important;
        margin-bottom: 0.5rem !important;
    }

    .qp-stat-card .display-6,
    .qp-dash-value {
        font-size: 1.45rem;
    }

    .qp-dash-card {
        min-height: 96px;
        padding: 1rem 1.1rem;
    }

    .qp-dash-icon {
        width: 36px;
        height: 36px;
        top: 0.85rem;
        right: 0.85rem;
    }

    .qp-modal-dialog {
        margin: 0.5rem;
    }
}

@media (max-width: 575.98px) {
    .qp-header .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
    }

    .qp-main .container-fluid {
        padding-left: 0.75rem !important;
        padding-right: 0.75rem !important;
        padding-top: 1rem !important;
        padding-bottom: 1rem !important;
    }

    .d-flex.flex-wrap.justify-content-between.align-items-end {
        flex-direction: column;
        align-items: stretch !important;
    }

    .d-flex.flex-wrap.justify-content-between.align-items-end > .btn,
    .d-flex.flex-wrap.justify-content-between.align-items-end > a.btn {
        width: 100%;
    }
}

/* Offline exam — draggable subject section order */
#qpOfflineExamModal .exam-subject-order-wrap,
#qpSaveExamModal .exam-subject-order-wrap {
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--md-radius-sm, 6px);
    padding: 0.5rem;
    background: rgba(0, 0, 0, 0.2);
}

.exam-subject-sort {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.exam-subject-sort li {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.45rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.04);
    font-size: 0.78rem;
    cursor: grab;
    user-select: none;
}

.exam-subject-sort li.exam-subject-dragging {
    opacity: 0.55;
    cursor: grabbing;
}

.exam-subject-sort li.exam-subject-drag-over {
    border-color: rgba(144, 202, 249, 0.65);
    background: rgba(33, 150, 243, 0.12);
}

.exam-subject-grip {
    font-size: 1rem !important;
    opacity: 0.55;
    flex-shrink: 0;
}

.exam-subject-num {
    font-weight: 700;
    min-width: 1.1rem;
    color: var(--md-primary-light, #90caf9);
}

.exam-subject-label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.qp-q-card .form-check {
    position: relative;
    z-index: 2;
}

.qp-q-card.qp-q-pick-saved {
    border-left: 4px solid #ffc107 !important;
    box-shadow:
        0 0 0 1px rgba(255, 193, 7, 0.28),
        var(--md-elevation-1, 0 2px 8px rgba(0, 0, 0, 0.25));
}

.qp-q-pick-rate {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.72rem;
    vertical-align: middle;
    background: rgba(255, 193, 7, 0.18) !important;
    color: #ffc107 !important;
    border: 1px solid rgba(255, 193, 7, 0.35) !important;
    transition: background 0.15s ease, transform 0.1s ease;
}

.qp-q-pick-rate:hover,
.qp-q-pick-rate:focus {
    background: rgba(255, 193, 7, 0.28) !important;
    transform: translateY(-1px);
}

.qp-q-pick-rate-zero {
    background: rgba(108, 117, 125, 0.15) !important;
    color: #adb5bd !important;
    border-color: rgba(108, 117, 125, 0.3) !important;
}

.qp-q-pick-rate-zero:hover,
.qp-q-pick-rate-zero:focus {
    background: rgba(108, 117, 125, 0.22) !important;
}

.qp-pick-rate-icon {
    font-size: 0.85rem !important;
    vertical-align: -2px;
    margin-right: 1px;
}

.qp-q-meta-badges {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.2rem 0;
}

.qp-bank-id-active {
    padding: 0.35rem 0.5rem;
    border-radius: var(--md-radius-sm);
    background: rgba(0, 188, 212, 0.12);
    border: 1px solid rgba(0, 188, 212, 0.28);
    color: #4dd0e1;
    line-height: 1.35;
    word-break: break-word;
}

.qp-bank-id-input {
    font-family: 'Roboto Mono', monospace;
    font-size: 0.88rem;
    line-height: 1.55;
    resize: vertical;
    min-height: 10rem;
}

.qp-bank-id-count {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.03em;
}

.qp-q-card.qp-q-pick-new {
    border-left: 4px solid #66bb6a !important;
    box-shadow:
        0 0 0 1px rgba(102, 187, 106, 0.32),
        var(--md-elevation-1, 0 2px 8px rgba(0, 0, 0, 0.25));
}

.qp-badge-saved {
    background: rgba(255, 193, 7, 0.2) !important;
    color: #ffd54f !important;
    border: 1px solid rgba(255, 193, 7, 0.45) !important;
}

.qp-badge-new {
    background: rgba(102, 187, 106, 0.18) !important;
    color: #a5d6a7 !important;
    border: 1px solid rgba(102, 187, 106, 0.45) !important;
}

.qp-pick-legend {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    color: var(--md-text-muted, #9e9e9e);
}

.qp-pick-legend-item {
    padding: 0.1rem 0.45rem 0.1rem 0.55rem;
    border-left: 4px solid transparent;
    border-radius: 0 3px 3px 0;
    background: rgba(255, 255, 255, 0.04);
}

.qp-pick-legend-item.qp-q-pick-saved {
    border-left-color: #ffc107;
}

.qp-pick-legend-item.qp-q-pick-new {
    border-left-color: #66bb6a;
}

#qpPaperQuestionsWrap .qp-paper-q-card {
    border-left: 3px solid rgba(255, 193, 7, 0.65);
}

.qp-exam-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--md-text-muted, #9e9e9e);
    border-color: rgba(255, 255, 255, 0.08);
}

.qp-exam-table td {
    vertical-align: middle;
    border-color: rgba(255, 255, 255, 0.06);
}

/* ── Scan Questions ── */
.qp-scan-paper-zone {
    border: 1px dashed var(--md-border-light);
    border-radius: var(--md-radius-sm);
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
}

.qp-scan-camera-wrap {
    border-radius: var(--md-radius-sm);
    overflow: hidden;
    background: #000;
}

.qp-scan-camera-video {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    background: #000;
}

.qp-scan-image-list {
    min-height: 3rem;
}

.qp-scan-thumb-card {
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius-sm);
    overflow: hidden;
    background: var(--md-surface-2);
}

.qp-scan-thumb-img {
    display: block;
    width: 100%;
    height: 120px;
    object-fit: cover;
    background: #111;
}

.qp-scan-thumb-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.35rem 0.5rem;
    gap: 0.5rem;
}

.qp-scan-crop-stage {
    border: 1px solid var(--md-border);
    border-radius: var(--md-radius-sm);
    padding: 1rem;
    background: var(--md-surface-2);
}

.qp-scan-crop-stage-inner {
    max-height: min(60vh, 520px);
    overflow: hidden;
}

.qp-scan-crop-stage-inner img {
    display: block;
    max-width: 100%;
}

.qp-scan-file-input {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.qp-scan-file-label {
    cursor: pointer;
}

.qp-rule-view-body {
    white-space: pre-wrap;
    word-break: break-word;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--md-border-light);
    border-radius: var(--md-radius-sm);
    padding: 1rem;
    color: var(--md-on-surface, #e2e8f0);
}

.qp-rule-editor-card textarea {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.82rem;
}

