/* ========================================
   1. GLOBAL VARIABLES & DESIGN SYSTEM
   Defines the color palette, typography, 
   and reusable tokens like shadows/radius.
======================================== */
:root {
    --font-display: 'Outfit', sans-serif;
    /* Heading font style */
    --font-body: 'Inter', sans-serif;
    /* Main content font style */

    --color-bg: #f5f7fa;
    /* Background color of the page */
    --color-surface: #ffffff;
    /* Card and surface background color */
    --color-surface-glass: rgba(255, 255, 255, 0.85);
    /* Transparent glass header effect */
    --color-primary: #4f46e5;
    /* Main branding indigo color */
    --color-primary-light: #6366f1;
    /* Hover state for primary buttons */
    --color-success: #10b981;
    /* Success green for printing/saving */
    --color-success-light: #059669;
    /* Hover state for success elements */
    --color-accent: #7c3aed;
    /* Secondary purple accent color */
    --color-accent-light: #8b5cf6;
    /* Hover state for accent elements */
    --color-text: #0f172a;
    /* Deep blue-black for main text */
    --color-text-muted: #64748b;
    /* Grayish blue for subtle text */
    --color-border: #e2e8f0;
    /* Base color for lines and borders */
    --color-border-hover: #cbd5e1;
    /* Hover state color for borders */

    --radius-sm: 8px;
    /* Small corner rounding */
    --radius-md: 12px;
    /* Standard corner rounding */
    --radius-lg: 20px;
    /* Large corner rounding for cards */

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    /* Tiny shadow for flat icons */
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    /* Regular shadow */
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    /* Heavy drop shadow */
    --shadow-primary: 0 10px 15px -3px rgba(79, 70, 229, 0.3);
    /* Glowing indigo shadow */
}

/* Main content fade effect */
.app-main {
    transition: opacity 0.5s ease;
}

.hidden {
    display: none !important;
}

/* Modal open-la irukum pothu main content-ah block panna */
body:has(.modal-overlay[style*="display: flex"]) .app-main {
    filter: blur(5px);
}

/* Print trigger hover effect */
.print-trigger:hover {
    background: var(--color-success-light) !important;
    transform: scale(1.05);
}

/* --- History Panel --- */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 20px;
}

.history-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 10px 16px;
    transition: all 0.2s;
    cursor: pointer;
    display: grid;
    /* Grid layout for perfect column alignment: Name, Subject, Date, Marks, Actions */
    grid-template-columns: 1.5fr 1fr 1fr 0.5fr auto;
    align-items: center;
    gap: 16px;
}

.history-item:hover {
    border-color: var(--color-primary);
    box-shadow: var(--shadow-sm);
    background: var(--color-surface);
}

.history-info h4 {
    margin: 0;
    color: var(--color-text);
    font-size: 0.95rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item p strong {
    color: var(--color-text);
    font-weight: 600;
    display: none;
    /* Hide labels in row view as columns provide context */
}

/* Specific styling for the generated date column to keep it readable */
.history-date {
    font-size: 0.8rem !important;
}

.history-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}



.btn-history {
    padding: 6px 12px;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.empty-history {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    background: var(--color-bg);
    border: 2px dashed var(--color-border);
    border-radius: var(--radius-lg);
    color: var(--color-text-muted);
    font-style: italic;
}


/* ========================================
   2. BASE RESET & APP STRUCTURE
   Global layout rules and the sticky header
   containing the title and progress steps.
======================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    font-family: var(--font-body);
    background: var(--color-bg);
    color: var(--color-text);
}

/* ========================================
   GLOBAL LAYOUT & NAVIGATION
   Styles for the main app shell, header,
   and progress indicators.
======================================== */
/* Main App Container Wrapper */
.app-container {
    /* Root wrapper for the whole app */
    height: 100vh;
    /* Fixed screen height */
    display: flex;
    /* Enables flexbox layout */
    flex-direction: column;
    /* Stacks header and main vertically */
    overflow: hidden;
    /* Prevents container-level scrolling */
}

/* Sticky Navigation Header */
.app-header {
    /* Top bar containing logo and steps */
    position: sticky;
    z-index: 1000;
    flex-shrink: 0;
    top: 0;
    padding: 10px 24px;
    background: var(--color-surface-glass);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--color-border);
    box-shadow: var(--shadow-sm);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 20px;
    width: 100%;
}

@media (max-width: 768px) {
    .app-header {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-align: center;
        gap: 15px;
        padding: 15px 10px;
    }

    .progress-indicator {
        grid-column: auto;
        width: 100vw !important;
        border-radius: 0 !important;
        border-left: none !important;
        border-right: none !important;
        margin: 0 -10px !important;
        padding: 10px 15px !important;
        max-width: 100vw;
    }
}

/* Logo and App Title Section */
.app-brand {
    /* Left section of header */
    display: flex;
    /* Horizontal arrangement */
    align-items: center;
    /* Vertically centers text and icon */
    gap: 6px;
    /* Reduced from 12px */
}

.app-brand h1 {
    /* App title text */
    font-size: 0.9rem;
    /* Reduced from 1.25rem - Smaller title */
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    /* Indigo-to-purple gradient */
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-brand .logo-icon {
    /* Icon before title */
    font-size: 1rem;
    /* Reduced from 1.5rem */
}

.small-note {
    /* New user welcome note */
    color: var(--color-text-muted);
    font-size: 0.7rem;
    /* Reduced from 0.9rem */
    margin-left: 3px;
    /* Reduced from 5px */
}

.header-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
    /* Reduced from 10px */
}

.app-title {
    font-family: var(--font-display);
    font-size: 0.8rem;
    /* Reduced from 1.5rem */
    font-weight: 700;
    color: var(--color-text);
    display: flex;
    align-items: center;
    gap: 5px;
    /* Reduced from 10px */
}

.app-title .icon {
    font-size: 0.9rem;
    /* Reduced from 1.8rem */
    color: var(--color-primary);
}

.app-subtitle {
    font-size: 0.75rem;
    /* Reduced from 1rem */
    color: var(--color-text-muted);
    margin-top: 5px;
}

.user-email {
    font-size: 0.7rem;
    /* Reduced from 0.85rem */
    color: var(--color-text-muted);
    margin-left: 8px;
}

/* Wrapper for Progress Steps (1, 2, 3...) */
.progress-indicator {
    /* Navigation tabs for steps */
    grid-column: 2;
    display: flex !important;
    justify-content: center !important;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    padding: 10px 20px;
    border-radius: 50px;
    border: 1.5px solid var(--color-border);
    overflow-x: auto !important;
    overflow-y: hidden;
    white-space: nowrap !important;
    flex-wrap: nowrap !important;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin: 0 auto;
    max-width: fit-content;
}

.progress-indicator::-webkit-scrollbar {
    display: none;
    /* Hide scrollbar for Chrome/Safari */
}

.progress-step {
    padding: 8px 18px;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--color-text-muted);
    border-radius: var(--radius-md);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
    border: 1px solid transparent;
    flex-shrink: 0;
    /* Important: prevents tabs from squishing on mobile */
    white-space: nowrap;
}

.progress-step:hover:not(.active) {
    background: rgba(255, 255, 255, 0.5);
    color: var(--color-primary);
}

.progress-step.active {
    /* Style for the currently active tab */
    background: var(--color-primary) !important;
    color: #fff !important;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    transform: scale(1.05);
    font-weight: 700;
    border: 1px solid var(--color-primary);
}

.print-trigger {
    background: #22C55E !important;
    color: white !important;
    border: none !important;
    font-weight: 800 !important;
    box-shadow: 0 4px 6px -1px rgba(34, 197, 94, 0.4);
}

.print-trigger:hover {
    background: #16a34a !important;
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(34, 197, 94, 0.4);
}

.logout-trigger {
    background: #F43F5E !important;
    color: white !important;
    border: none !important;
    font-weight: 800 !important;
    display: none;
    /* Initially hidden, shown by JS */
    box-shadow: 0 4px 6px -1px rgba(244, 63, 94, 0.4);
}

.logout-trigger:hover {
    background: #e11d48 !important;
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(244, 63, 94, 0.4);
}

/* Add pulsing animation for active tab */
.progress-step.active::after {
    content: '';
    position: absolute;
    top: -4px;
    right: -4px;
    width: 8px;
    height: 8px;
    background: var(--color-success);
    border-radius: 50%;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% {
        transform: scale(0.95);
        opacity: 1;
    }

    50% {
        transform: scale(1.1);
        opacity: 0.7;
    }

    100% {
        transform: scale(0.95);
        opacity: 1;
    }
}

/* Main Content Area (Scrollable) */
.app-main {
    /* Area below the fixed header */
    flex: 1;
    /* Takes up all remaining screen space */
    padding: 40px;
    /* Generous inner spacing for content */
    display: flex;
    /* Centers the tab cards */
    justify-content: center;
    /* Horizontal centering */
    align-items: flex-start;
    /* Aligns cards to the top */
    overflow-y: auto;
    /* Enables scrollbar if content is too tall */
    height: 100%;
    /* Full height within the container */
    box-sizing: border-box;
    /* Includes padding in dimensions */
}

.tab-content {
    /* Shared style for all tab panels */
    display: none;
    /* Hidden by default */
    width: 100%;
    /* Takes full available width */
    max-width: 900px;
    /* Limits width for readability */
    animation: fadeIn 0.3s;
    /* Smooth appearance animation */
}

.tab-content.active {
    /* Style for the current tab only */
    display: block;
    /* Makes the active tab visible */
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* --- Tab Card --- */
/* Card Container for Tab Content */
.tab-card {
    background: #ffffff;
    border-radius: var(--radius-lg);
    padding: 30px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05), 0 8px 10px -6px rgba(0, 0, 0, 0.05);
    border: 1px solid var(--color-border);
    margin-bottom: 30px;
    position: relative;
    overflow: hidden;
}

.tab-title {
    font-family: var(--font-display);
    font-size: 1.85rem;
    font-weight: 800;
    color: #1e293b;
    margin-bottom: 12px;
    position: relative;
    display: inline-block;
}

.tab-title::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 0;
    width: 45px;
    height: 5px;
    background: linear-gradient(90deg, var(--color-primary), var(--color-accent));
    border-radius: 3px;
}

.tab-subtitle {
    color: var(--color-text-muted);
    margin-bottom: 24px;
}

/* --- Enhanced Login UI --- */
.login-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 200px);
}

.login-container {
    display: flex;
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    width: 100%;
    max-width: 900px;
    min-height: 550px;
}

.login-aside {
    flex: 1;
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    padding: 40px;
    display: flex;
    align-items: center;
    color: white;
}

.aside-content {
    max-width: 320px;
}

.aside-icon {
    font-size: 3rem;
    margin-bottom: 20px;
    align-items: center;
    justify-content: center;
}

.aside-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 15px;
    line-height: 1.2;
}

.aside-text {
    font-size: 1rem;
    opacity: 0.9;
    line-height: 1.6;
    margin-bottom: 30px;
}

.feature-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.feature-tags span {
    background: rgba(255, 255, 255, 0.2);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.login-main {
    flex: 1.2;
    padding: 40px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.auth-box {
    animation: fadeIn 0.5s ease-out;
}

.auth-header {
    margin-bottom: 30px;
}

.auth-title {
    font-family: var(--font-display);
    font-size: 1.85rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-subtitle {
    color: var(--color-text-muted);
    font-size: 0.95rem;
}

.input-with-icon {
    position: relative;
    width: 100%;
    display: block;
}

.input-with-icon .icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 1.1rem;
    pointer-events: none;
    color: var(--color-text-muted);
    z-index: 20;
}

.input-with-icon input {
    width: 100% !important;
    padding-left: 45px !important;
    padding-right: 45px !important;
    position: relative;
    z-index: 1;
}

.toggle-password {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--color-text-muted);
    transition: all 0.2s;
    font-size: 1.1rem;
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Hide default browser password reveal button */
input::-ms-reveal,
input::-ms-clear {
    display: none;
}

input::-webkit-contacts-auto-fill-button,
input::-webkit-credentials-auto-fill-button {
    visibility: hidden;
    display: none !important;
    pointer-events: none;
}

.toggle-password:hover {
    color: var(--color-primary);
}

.auth-footer {
    margin-top: 30px;
    padding-top: 10px;
    border-top: 1px solid var(--color-border);
    text-align: center;
}

.auth-footer p {
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

/* User Info Panel */
.user-avatar {
    font-size: 4rem;
    margin-bottom: 20px;
    text-align: center;
}

.user-email-display {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--color-primary);
    text-align: center;
}

.user-status-card {
    background: #f8fafc;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 20px;
    margin-bottom: 30px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--color-success);
}

.pulse {
    animation: statusPulse 2s infinite;
}

@keyframes statusPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.4);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.status-meta {
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

.status-meta span {
    font-weight: 600;
    color: var(--color-text);
}

/* Responsive Login */
@media (max-width: 850px) {
    .login-container {
        flex-direction: column;
        max-width: 450px;
    }

    .login-aside {
        display: none;
    }
}


.tab-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 24px;
}

.tab-header-flex .tab-subtitle {
    margin-bottom: 0;
}

/* ========================================
   TAB 1: EXAM DETAILS - Functions Note
   This section controls the form layout 
   for setting up school name, class, 
   time duration, and total marks.
======================================== */
.form-grid {
    /* Grid layout for exam info inputs */
    display: grid;
    /* Enables CSS Grid */
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    /* Responsive columns */
    gap: 20px;
    /* Space between input fields */
}

.form-group {
    /* Wrapper for Label + Input pair */
    display: flex;
    /* Enables flex layout */
    flex-direction: column;
    /* Stacks label vertically above input */
}

.form-group label {
    /* Title text for input fields */
    font-size: 0.875rem;
    /* Small clear label font */
    font-weight: 500;
    /* Medium weight for readability */
    color: var(--color-text);
    /* High contrast text color */
    margin-bottom: 8px;
    /* Gap between label and box */
}

.form-group label .required {
    color: #ef4444;
    font-weight: 700;
}

.form-group input,
.form-group select {
    /* Styles for text boxes and dropdowns */
    padding: 12px 14px;
    /* comfortable typing space */
    font-size: 1rem;
    /* Standard readable font size */
    font-family: var(--font-body);
    /* Primary body font style */
    background: var(--color-bg);
    /* Light gray background color */
    border: 1px solid var(--color-border);
    /* Subtle separator line */
    border-radius: var(--radius-sm);
    /* Standard rounded corners */
    color: var(--color-text);
    /* Main text color for typing */
    outline: none;
    /* Removes default browser outline */
    transition: border-color 0.2s, box-shadow 0.2s;
    /* Smooth focus effects */
}

.form-group input:focus,
.form-group select:focus {
    /* Active state when clicking input */
    border-color: var(--color-primary);
    /* Highlights border with brand color */
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
    /* Glow effect around box */
}

/* --- Buttons --- */
.tab-actions {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 15px;
    /* Increased margin */
    border-top: 1.5px dashed #e2e8f0;
    /* Added separator */
}

.tab-actions:has(.btn:only-child) {
    justify-content: center;
}

.btn {
    /* Generic button class */
    padding: 14px 28px;
    /* Size of the button clickable area */
    font-size: 1.1rem;
    /* Large readable button text */
    font-weight: 600;
    /* Semi-bold text */
    font-family: var(--font-display);
    /* Heading font for buttons */
    border: none;
    /* Removes default borders */
    border-radius: var(--radius-md);
    /* Standard rounded corners */
    cursor: pointer;
    /* Hand cursor for interaction */
    transition: transform 0.15s, box-shadow 0.2s;
    /* Hover animations */
}

.btn:hover {
    /* Style when hovering with mouse */
    transform: translateY(-2px);
    /* Button lifts up slightly */
}

.btn:active {
    /* Style when clicking down */
    transform: translateY(0);
    /* Button resets to original position */
}

.btn-primary {
    /* Main action button style */
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    /* Gradient background */
    color: #fff;
    /* White legible text */
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
    /* Subtle blue shadow */
}

.btn-lg {
    padding: 14px 28px;
    font-size: 1.1rem;
}

.btn-outline-danger {
    background: transparent;
    border: 2px solid #ef4444;
    color: #ef4444;
}

.btn-outline-danger:hover {
    background: #ef4444;
    color: #fff;
}


.btn-primary:hover {
    /* Hover over main button */
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.4);
    /* Stronger shadow on hover */
}

.btn-success {
    /* Success action button style (e.g. Save PDF) */
    background: linear-gradient(135deg, var(--color-success), var(--color-success-light));
    /* Green gradient background */
    color: #fff;
    /* White legible text */
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
    /* Subtle green shadow */
}

.btn-success:hover {
    /* Hover over success button */
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
    /* Stronger shadow on hover */
}

.btn-secondary {
    background: var(--color-bg);
    border: 2px solid var(--color-border);
    color: var(--color-text);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.875rem;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--color-primary);
    color: var(--color-primary);
}

.btn-outline:hover {
    background: var(--color-primary);
    color: #fff;
}

/* --- Icon Buttons --- */
.btn-icon {
    /* Circular icon-only button */
    display: flex;
    /* Enables centering the icon */
    align-items: center;
    /* Vertically centers icon */
    justify-content: center;
    /* Horizontally centers icon */
    width: 38px;
    /* Fixed width for perfect circle */
    height: 38px;
    /* Fixed height matches width */
    border-radius: 50%;
    /* Makes the box a circle */
    border: none;
    /* No outer line */
    cursor: pointer;
    /* Click indication cursor */
    font-size: 1.15rem;
    /* Size of the icon graphic */
    transition: all 0.2s;
    /* Smooth hover effects */
    padding: 0;
    /* Removes internal padding */
    background: #f1f5f9;
    /* Light bluish gray background */
    color: var(--color-text);
    /* Dark color for the icon */
    aspect-ratio: 1/1;
    /* Force 1:1 square ratio */
    flex-shrink: 0;
    /* Prevents icon from squishing */
}

.btn-icon:hover {
    transform: scale(1.1);
}

.btn-icon.primary {
    background: var(--color-primary);
    color: white;
}

.btn-icon.danger {
    background: #fee2e2;
    color: #ef4444;
}

.btn-icon.stats {
    background: #e0e7ff;
    color: var(--color-primary);
}

/* ========================================
   TAB 2: CHAPTER SELECTION - Functions Note
   Styles for the grid of checkboxes that 
   allow users to choose which chapters 
   will be included in the question bank.
======================================== */
.chapter-grid {
    /* Grid for the chapter selection screen */
    display: grid;
    /* Enables grid item placement */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    /* Auto columns */
    gap: 16px;
    /* Standard spacing between cards */
    margin-bottom: 32px;
    /* Outer gap below the whole grid */
}

.chapter-item {
    /* Style for each chapter card */
    display: flex;
    /* Aligns checkbox and title side-by-side */
    align-items: center;
    /* Vertically centers icon and text */
    padding: 16px;
    /* Internal spacing within card */
    background: var(--color-bg);
    /* Secondary light background color */
    border: 2px solid var(--color-border);
    /* Subtle line around the card */
    border-radius: var(--radius-md);
    /* Rounded corner style */
    cursor: pointer;
    /* Show interaction possible */
    transition: all 0.2s;
    /* Smooth visual transitions */
    user-select: none;
    /* Prevents accidental text selection */
}

/* Hover effect for chapter cards */
.chapter-item:hover {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.05);
}

/* Styling for the checkbox input itself */
.chapter-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    cursor: pointer;
}

/* Label text for chapter items */
.chapter-item label {
    font-weight: 500;
    cursor: pointer;
    flex: 1;
}

/* --- Question Selector --- */
.section-group {
    /* Grouping for section categories */
    margin-bottom: 32px;
    /* Space between groups */
    padding: 20px;
    /* Inner comfort space */
    background: var(--color-bg);
    /* Light gray area color */
    border-radius: var(--radius-md);
    /* Curved edges for the group */
}

.section-group h3 {
    /* Subsection headings within bank */
    font-size: 1.125rem;
    /* Medium heading size */
    margin-bottom: 16px;
    /* Spacing before list below */
    color: var(--color-primary);
    /* Indigo branding color */
}

.question-selector {
    /* List area for choosing questions */
    display: flex;
    /* Column stacking of questions */
    flex-direction: column;
    /* Vertical layout */
    gap: 12px;
    /* Spacing between individual selectors */
}

/* ========================================
   TAB 4: QUESTION SELECTION - Functions Note
   Styles for the question bank list, filtering 
   by difficulty/source, and the sidebar tabs 
   for different sections (sub-tabs).
======================================== */
.section-tabs {
    /* Sidebar sub-navigation for Part selections */
    display: flex;
    /* Row of buttons */
    gap: 8px;
    /* Space between buttons */
    margin-bottom: 24px;
    /* Outer gap below the tab bar */
    flex-wrap: nowrap;
    /* Forces single line instead of wrapping */
    overflow-x: auto;
    /* Enables horizontal scrolling */
    padding-bottom: 12px;
    /* Breathing room for scrollbar */
    scrollbar-width: thin;
    /* Thin scrollbar for Firefox */
    -webkit-overflow-scrolling: touch;
    /* Smooth scroll on mobile */
}

/* Custom scrollbar for horizontal tabs */
.section-tabs::-webkit-scrollbar {
    height: 6px;
}

.section-tabs::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.section-tabs::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.section-tabs::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

.section-tab {
    /* Individual button in the sub-nav */
    padding: 10px 20px;
    /* Size of the tab button */
    font-size: 0.95rem;
    /* Clear readable size */
    font-weight: 500;
    /* Semi-bold text style */
    flex-shrink: 0;
    /* Prevents tab from shrinking */
    white-space: nowrap;
    /* Prevents text from wrapping to next line */
    background: var(--color-bg);
    /* Non-active background color */
    border: 2px solid var(--color-border);
    /* Subtle border color */
    border-radius: var(--radius-md);
    /* Rounded tab corners */
    cursor: pointer;
    /* Show click is possible */
    transition: all 0.2s;
    /* Hover animations */
}

/* Hover state for section tabs */
.section-tab:hover {
    border-color: var(--color-primary);
    background: rgba(99, 102, 241, 0.1);
}

/* Active state for the selected section tab */
.section-tab.active {
    background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
    color: #fff;
    border-color: var(--color-primary);
}

/* --- Question Selection Area --- */
.question-selection-area {
    min-height: 300px;
    position: relative;
    z-index: 1050;
}

.section-question-panel {
    background: var(--color-bg);
    padding: 20px;
    border-radius: var(--radius-md);
}

.question-filters {
    padding: 16px;
    background: var(--color-surface);
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
}

.filter-row {
    /* Horizontal container for filter dropdowns */
    display: flex;
    /* Side-by-side alignment */
    gap: 20px;
    /* Space between filter groups */
    align-items: center;
    /* Vertically centers dropdowns */
    flex-wrap: wrap;
    /* Wraps on mobile screens */
}

.filter-group {
    /* Individual filter with label */
    display: flex;
    /* Aligns text label and select box */
    align-items: center;
    /* Vertical centering */
    gap: 8px;
    /* Minor gap between label and box */
}

.filter-group select {
    /* Styles the dropdown elements */
    padding: 6px 12px;
    /* Inner typing/selection space */
    border: 1px solid var(--color-border);
    /* Subtle separator line */
    border-radius: var(--radius-sm);
    /* Standard corner rounding */
}

.checkbox-group label {
    /* Text styling for filter checkboxes */
    display: flex;
    /* Aligns icon and text */
    align-items: center;
    /* Vertical centering */
    gap: 6px;
    /* Gap between box and text */
    cursor: pointer;
    /* Suggest interaction */
    font-size: 0.9rem;
    /* Small clear text */
}

.question-list-container {
    /* Scrolling container for the bank */
    max-height: 500px;
    /* Limits bank height for workspace */
    overflow-y: auto;
    /* Enables vertical scrolling */
    margin-bottom: 20px;
    /* Space below the list area */
    border: 1px solid var(--color-border);
    /* Outer line around the bank */
    border-radius: var(--radius-sm);
    /* Slightly curved corners */
}

/* Layout for the list of questions */
.question-list {
    display: flex;
    flex-direction: column;
}

/* Individual question item container */
.question-item {
    display: flex;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    cursor: pointer;
    transition: background 0.2s;
}

.question-item:last-child {
    border-bottom: none;
}

.question-item:hover {
    background: var(--color-surface);
}

/* Highlight style for selected question item */
.question-item.selected {
    background: rgba(99, 102, 241, 0.05);
    /* faint primary color */
    border-left: 3px solid var(--color-primary);
}

/* Container for question text content */
.question-content {
    flex: 1;
}

/* Styling for the question text itself */
.q-text {
    margin-bottom: 6px;
    font-size: 0.95rem;
    line-height: 1.5;
}

.q-tags {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.tag {
    font-size: 0.75rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.tag-blue {
    background: #dbeafe;
    color: #1e40af;
}

.tag-orange {
    background: #ffedd5;
    color: #9a3412;
}

.tag-gray {
    background: #f3f4f6;
    color: #4b5563;
}

.section-header-panel {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 2px solid var(--color-border);
    padding-bottom: 16px;
    margin-bottom: 20px;
}

.section-info {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.no-questions {
    color: var(--color-text-muted);
    font-style: italic;
    text-align: center;
}

/* ========================================
   TAB 3: SECTION BUILDER - Functions Note
   Styles for configuring Parts (Part A, B, etc.),
   setting marks per question, and choosing 
   how many questions to attempt.
======================================== */
.section-card {
    /* Config card for a paper part (e.g. Part A) */
    background: #ffffff;
    /* Clean white background */
    border: 1.5px solid var(--color-border);
    border-left: 6px solid var(--color-primary);
    /* Vibrant side accent */
    border-radius: var(--radius-md);
    padding: 22px;
    padding-left: 48px;
    margin-bottom: 20px;
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
}

.section-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: var(--color-primary-light);
}

.section-card.dragging {
    opacity: 0.5;
    transform: scale(0.98);
    border-style: dashed;
    border-color: var(--color-primary);
}

.section-drag-handle {
    position: absolute;
    left: -5px;
    /* Nudge handle slightly out for cleaner look */
    top: 50%;
    transform: translateY(-50%);
    cursor: grab;
    color: var(--color-text-muted);
    font-size: 24px;
    /* Slightly larger for usability */
    padding: 10px 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.section-drag-handle:active {
    cursor: grabbing;
}


.section-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    padding-bottom: 14px;
    border-bottom: 1px solid #f1f5f9;
}

.section-number {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--color-primary);
}

/* Main container for section marks input */
.section-marks {
    font-size: 1rem;
    font-weight: 600;
    color: #000;
    margin-right: 50px;
    /* Add space to avoid remove button */
}

.section-total-marks {
    font-size: 1rem;
    font-weight: 700;
    color: var(--color-primary);
    background: rgba(59, 130, 246, 0.1);
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.remove-section-btn {
    /* Red button to delete a Part */
    position: absolute;
    /* Fixed position within the card */
    top: 10px;
    /* Pushed to the top edge */
    right: 10px;
    /* Pushed to the right edge */
    background: #ef4444;
    /* Danger red color */
    color: #fff;
    /* White contrast icon */
    border: none;
    /* No outer border line */
    border-radius: 50%;
    /* Perfect circle shape */
    width: 32px;
    /* Equal width for circle */
    height: 32px;
    /* Equal height for circle */
    cursor: pointer;
    /* Click indication cursor */
    font-size: 18px;
    /* Size of the 'X' symbol */
    line-height: 1;
    /* Centers 'X' vertically */
    transition: all 0.2s;
    /* Smooth hover animation */
}

/* Hover effect for the delete button */
.remove-section-btn:hover {
    background: #dc2626;
    transform: scale(1.1);
}

/* Grid for section configuration inputs */
.section-config {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
}

/* Wrapper for individual configuration field */
.config-field {
    display: flex;
    flex-direction: column;
}

/* Label styling for configuration fields */
.config-field label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--color-text);
}

/* Input fields inside configuration section */
.config-field select,
.config-field input {
    padding: 10px 12px;
    font-size: 0.95rem;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color 0.2s;
}

.config-field select:focus,
.config-field input:focus {
    border-color: var(--color-primary);
}

/* Large display for total marks calculation */
.total-marks-display {
    text-align: center;
    padding: 18px;
    background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
    color: #ffffff;
    border-radius: var(--radius-md);
    font-size: 1.3rem;
    font-weight: 800;
    margin-bottom: 25px;
    box-shadow: 0 10px 15px -3px rgba(30, 41, 59, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* ========================================
   TAB 5: PREVIEW & TOOLS - Functions Note
   Styles for the final question paper layout, 
   MS Word formatting toolbar, and the 
   A4-sized paper simulation.
======================================== */
.preview-container {
    width: 100%;
    max-width: 210mm;
    margin: 0 auto;
}



/* Optional: remove margin-top from first group to align better */
.preview-actions .toolbar-group:first-child {
    padding-left: 0;
}

/* Vertical column of tool buttons */
/* Vertical column of tool buttons */
.preview-actions {
    /* MS Word style formatting toolbar - Unified Sticky */
    position: sticky;
    top: -40px;
    z-index: 100;
    background: #ffffff;
    display: flex;
    justify-content: center;
    align-items: stretch;
    gap: 0;
    margin-bottom: 1px;
    padding: 8px 12px;
    background: #f8fafc;
    /* Slightly off-white for contrast */
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    overflow-x: auto;
}

.toolbar-group {
    display: flex;
    flex-direction: row;
    /* Single row flow */
    justify-content: center;
    padding: 0 10px;
    border-right: 1px solid #e2e8f0;
    align-items: center;
    gap: 6px;
}

.toolbar-group:last-child {
    border-right: none;
}

/* Single line of tool buttons within a group */
.toolbar-row {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: center;
}

/* Hide labels to save height as requested */
.toolbar-label {
    display: none;
}

/* Tool Buttons & Inputs */
/* Base style for individual tool icons/buttons */
.tool-btn {
    /* Single formatting button (Bold/Italic) */
    width: 26px;
    /* Small standard button width */
    height: 26px;
    /* Small standard button height */
    display: flex;
    /* Enables centering the tool icon */
    align-items: center;
    /* Vertically centers icon */
    justify-content: center;
    /* Horizontally centers icon */
    background: transparent;
    /* No background by default */
    border: 1px solid transparent;
    /* No border until hovered or active */
    border-radius: 4px;
    /* Tiny rounded button corners */
    cursor: pointer;
    /* Click indication pointer */
    font-weight: 500;
    /* Standard tool label weight */
    font-size: 0.85rem;
    /* Standard tool icon scale */
    color: #374151;
    /* Dark gray tool color */
    transition: all 0.1s;
    /* Very fast hover reaction */
}

.tool-btn:hover {
    background: #e5e7eb;
    border-color: #9ca3af;
}

/* Active state for toggle buttons (Bold, Italic, etc.) */
.tool-btn.active {
    background: #dbeafe;
    border-color: #3b82f6;
    color: #1d4ed8;
}

.tool-btn.bold-btn {
    font-weight: 800;
    font-size: 1rem;
}

.tool-btn.italic-btn {
    font-style: italic;
}

.tool-btn.underline-btn {
    text-decoration: underline;
}

/* Input fields in the toolbar (Font size, Color) */
.tool-select {
    padding: 2px 4px;
    height: 26px;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    background: white;
    font-family: inherit;
    font-size: 0.85rem;
    color: #334155;
    outline: none;
}

.tool-select:focus {
    border-color: #3b82f6;
}

.tool-color-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.tool-color-input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
}

.tool-color-label {
    font-size: 0.7rem;
    font-weight: bold;
    margin-top: -2px;
}

.tool-size-display {
    min-width: 25px;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
}


/* ========================================
   8. PAPER & QUESTION SIMULATION
   Styles that mimic a real printed page
   and provide the "Straight Alignment" fix.
======================================== */
.paper {
    /* Simulated physical paper sheet */
    width: 210mm;
    /* Standard A4 paper width */
    min-height: 297mm;
    /* Standard A4 paper height */
    height: auto;
    /* Grows if content exceeds one page */
    background: #fff;
    /* Paper white color */
    color: #111;
    /* Dark ink-black text */
    margin: 0 auto;
    /* horizontal centering on screen */
    padding: 5mm;
    /* Standard printing margins */
    border-radius: var(--radius-lg);
    /* visual padding on screen only */
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.2);
    /* Floating paper effect */
    box-sizing: border-box;
    /* Ensures padding doesn't increase width */
    font-family: 'Times New Roman', Times, serif;
    /* Professional academic font */
    font-size: 12pt;
    /* Standard document text size */
    line-height: 1.6;
    /* Vertical spacing for readability */
    overflow-y: visible;
    /* Prevents content clipping */
    word-wrap: break-word;
    /* Breaks long text to next line */
}

/* Main header block of the question paper */
.paper-header {
    text-align: center;
    margin-bottom: 10px;
    border-bottom: 2px solid #333;
    padding-bottom: 10px;
    line-height: 1;
}

/* Exam Name Title (e.g. "Biology") */
.exam-title {
    font-size: 18pt;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 5px;
}

/* Meta information row (Class, Time, Marks) */
.paper-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11pt;
    margin-bottom: 2px;
}

.paper-header p {
    margin: 0.5px;
}

.meta-left,
.meta-right {
    text-align: left;
}

.meta-right {
    text-align: right;
}

.meta-center h2 {
    /* Center subheading (e.g. "PART-I") */
    font-size: 12pt;
    /* Slightly larger meta text */
    font-weight: bold;
    /* Bold emphasis */
    text-transform: uppercase;
    /* Uppercase styling */
    margin: 0;
    /* Resets default margins */
}

.paper-content {
    margin-top: 20px;
}

/* Section styles from previous CSS */
.section {
    margin-bottom: 25px;
}

/* Header for each Part/Section (Part A) */
.section-header {
    display: flex;
    flex-wrap: nowrap;
    /* Force single row */
    justify-content: space-between;
    align-items: center;
    background: #f0f0f0;
    padding: 8px 12px;
    margin-bottom: 12px;
    border-left: 4px solid #333;
    gap: 15px;
    /* Minimum space between title and marks */
}

.section-title {
    font-weight: bold;
    font-size: 13.5pt;
    flex: 1;
    /* Allow title to take up available space */
}

.section-marks {
    font-size: 10pt;
    font-weight: bold;
    color: #000;
    white-space: nowrap;
    /* Prevent marks from wrapping */
    flex-shrink: 0;
    /* Prevent marks from being squished */
}

.section-note {
    font-size: 10pt;
    font-style: italic;
    margin-bottom: 12px;
    color: #444;
}

.compulsory-header-notice {
    color: #000000;
    font-weight: 700;
    font-size: 10pt;
    margin-left: 10px;
}

/* --- Question Paper Components --- */

/* Main container for a single question block */
.question {
    /* Container for number + text + options */
    display: flex;
    /* Aligns number to the left of text */
    align-items: flex-start;
    /* Top alignment of both columns */
    margin-bottom: 1.2rem;
    /* Increased from 5px - Gap between consecutive questions as requested by user */
    width: 100%;
    /* Spans full width of paper */
}

/* Container for the Question Number label (1.) */
.question-number {
    /* Style for the question index (e.g. 1.) */
    font-weight: bold;
    /* Bold question index */
    width: 35px;
    /* Fixed column width for index */
    min-width: 35px;
    /* Prevents shrinking behavior */
    flex-shrink: 0;
    /* Stable layout for numbers */
    line-height: 1.6;
    /* Matches question text spacing */
    text-align: left;
    /* Left-aligned inside its column */
}

/* Wrapper for the question text and options */
.question-content {
    /* Area hosting text and options */
    flex: 1;
    /* Fills remaining width after number */
    min-width: 0;
    /* Responsive grid fix */
    line-height: 1.6;
    /* Standard line spacing */
}

/* Actual text of the question */
.question-text {
    /* Main question body text area */
    display: block;
    white-space: pre-wrap;
    /* Preserves breaks for editing and equations */
}

.options {
    margin-left: 25px;
    margin-top: 5px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    align-items: flex-start;
}

/* Container for inline options (a) ... (b) ... */
.options-inline {
    /* Row layout for short MCQs */
    margin-left: 0px;
    /* No margin for grid layout */
    margin-top: 8px;
    /* Minor space above options */
    display: grid;
    /* Base grid setup */
    gap: 5px 15px;
    /* Grid row and column spacing */
    width: 100%;
}

/* Specific Layout Variations */
.options-inline.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.options-inline.cols-2 {
    grid-template-columns: repeat(2, 1fr);
}

.options-inline.cols-1 {
    grid-template-columns: 1fr;
}

/* Default fallback if no class specified */
.options-inline:not([class*="cols-"]) {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

/* Ensure new lines (divs/br) behave correctly in editable mode */
.options-inline>div,
.options-inline br {
    display: none;
    /* Hide manual breaks in Grid, let Grid handle flow */
}

.options-inline .option {
    display: block;
    margin: 0;
    line-height: 1.4;
    white-space: pre-wrap;
    /* Preserves breaks for multi-line equations in options */
}

/* Table for Match the Following questions */
.match-table {
    width: auto;
    border-collapse: collapse;
    margin: 10px 0 10px 25px;
    font-size: 11pt;
}

.match-table th,
.match-table td {
    border: 1px solid #999;
    padding: 3px 8px;
    text-align: left;
}

.match-table th {
    background: #e8e8e8;
}

.assertion-block {
    margin-left: 8px;
    /* Reduced from 25px */
    margin-top: 5px;
    font-size: 11pt;
}

.assertion-block p {
    margin-bottom: 2px;
    /* Reduced from 4px */
}

.or-divider {
    text-align: center;
    font-weight: bold;
    margin: 0;
    /* Reduced from 2px 0 - Even tighter spacing as requested by user */
    font-size: 10pt;
}

.sub-question {
    margin-left: 3px;
    /* Reduced from 25px - Closer to question number */
    margin-bottom: 2px;
    /* Reduced from 4px - Further reduced for tighter spacing */
    display: block;
    /* Keep as block for proper line breaks */
}

.sub-question::first-line {
    display: inline;
    /* Number and text inline */
}

.compulsory-tag {
    background: #ef4444;
    color: #fff;
    font-size: 8pt;
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 8px;
    font-weight: bold;
    text-transform: uppercase;
}

.compulsory-header-notice {
    color: #000000;
    font-weight: bold;
    font-size: 10pt;
    margin-left: 10px;
}



/* ========================================
   11. PRINT OPTIMIZATION
   Specific rules triggered by the browser's 
   print engine to ensure high-quality output.
======================================== */



/* ========================================
   9. INTERACTIVE CARDS & SLOTS
   Feedback for drag-and-drop operations
   and highlighting selected question placeholders.
======================================== */
.q-card {
    /* Single question slot container */
    display: flex;
    /* Aligns handle, number, and text */
    align-items: flex-end;
    /* Text block-ah mukkiaama kizha thallum */
    /* Forces children to match card height */
    background: var(--color-surface);
    /* White card background */
    border: 1px solid var(--color-border);
    /* Subtle line around the slot */
    border-radius: var(--radius-md);
    /* Smooth card outer corners */
    overflow: visible;
    /* Allows tags to pop outside */
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    /* Smooth movement feel */
    position: relative;
    padding: 20px 5px 10px 10px;
    /* Added padding for better breathing room */
    padding-bottom: 10px;
    /* Text-ah card bottom-la irunthu konjam lift pannum */
    min-height: 100px;
    /* Card-kku height tharum */
}

/* Anchor for action buttons */

.q-card:hover {
    border-color: var(--color-primary-light);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.q-handle {
    /* Drag handler for reordering */
    display: flex;
    /* Centering the drag icon */
    align-items: center;
    /* Vertical centering */
    justify-content: center;
    /* Horizontal centering */
    padding: 0 10px;
    /* Clickable handle width */
    background: transparent;
    /* Invisible background default */
    cursor: grab;
    /* Hand icon for dragging */
    color: var(--color-text-muted);
    /* Subtle color for the icon */
    font-size: 1.5rem;
    /* Size of the handle dots */
    font-weight: bold;
    /* Emphasis on the handle icon */
    border-right: 1px solid transparent;
    /* Hidden line until active */
    transition: all 0.2s;
    /* Fast interaction feedback */
    user-select: none;
    /* Prevents highlighting dots */
}

.q-handle:hover {
    color: var(--color-primary);
    background: rgba(79, 70, 229, 0.05);
}

.q-card:active .q-handle {
    cursor: grabbing;
}

.q-num-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 70px;
    padding: 10px;
    background: #f8fafc;
    border-right: 1px solid var(--color-border);
}

.q-num-panel .q-num {
    font-family: var(--font-display);
    font-weight: 800;
    font-size: 1rem;
    color: var(--color-primary);
}

.q-num-panel .q-badge-mini {
    font-size: 0.65rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 4px;
    margin-top: 5px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.q-main {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}


.q-text-panel {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    gap: 4px;
    padding-bottom: 25px;
    min-height: 100px;
    align-items: center;
    /* Center alignment with flex-end */
}

.q-card .q-text {
    /* Main question text in the slot */
    font-size: 1rem;
    /* Clear reading size */
    font-weight: 500;
    /* Slightly thicker for clarity */
    color: var(--color-text);
    /* High contrast text color */
    line-height: 1.5;
    /* Comfortable reading flow */
}

.dragging {
    opacity: 0.5;
    border: 2px dashed var(--color-primary) !important;
    transform: scale(0.98);
}

.filled-slot {
    border-left: 4px solid var(--color-primary);
}

.placeholder-slot {
    border: 1px dashed var(--color-border);
    justify-content: center;
    padding: 24px;
    background: rgba(248, 250, 252, 0.5);
    cursor: pointer;
}

.placeholder-slot:hover {
    background: white;
    border-style: solid;
    border-color: var(--color-primary-light);
}

.placeholder-slot .q-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.active-selection-slot {
    /* Inline panel within Question Selection area */
    display: grid !important;
    grid-template-rows: 60px 1fr !important;
    width: 100% !important;
    max-width: 1000px !important;
    height: 600px !important;
    /* Fixed height to prevent expansion */
    max-height: 80vh !important;
    min-height: 400px !important;
    background: #fff !important;
    border: 3px solid var(--color-primary) !important;
    box-shadow: 0 15px 45px rgba(0, 0, 0, 0.25) !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden !important;
    margin: 15px auto 25px auto !important;
    position: relative !important;
    z-index: 999 !important;
}

.inline-selection-body {
    display: grid !important;
    grid-template-columns: 260px 1fr !important;
    overflow: hidden !important;
    min-height: 0 !important;
    height: 100% !important;
}

.inline-bank-list {
    min-width: 0;
    height: 100%;
    overflow-y: scroll !important;
    /* Force vertical scrollbar to exist */
    background: #fff;
    padding: 5px;
    display: block !important;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

/* Backdrop overlay behind the panel */
#question-panel-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.25);
    z-index: 998;
    animation: fadeIn 0.2s;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }

    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.q-actions {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 16px;
    background: #fcfcfc;
}

.q-card-actions {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 6px;
    z-index: 100;
}

.q-card-actions .btn-icon {
    width: 32px;
    height: 32px;
}

.qm-header-title {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ========================================
   10. MODALS & RESPONSIVE DESIGN
   Popup windows for importing/exporting 
   and mobile compatibility rules.
======================================== */
@media (max-width: 768px) {
    .app-main {
        padding: 20px;
    }

    .tab-card {
        padding: 20px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .chapter-grid {
        grid-template-columns: 1fr;
    }

    .tab-actions {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }
}

/* --- Import Modal --- */
.modal-overlay {
    /* Dimmed background behind popup */
    position: fixed;
    /* Stays pinned to the window */
    top: 0;
    /* Aligns to top edge */
    left: 0;
    /* Aligns to left edge */
    right: 0;
    /* Aligns to right edge */
    bottom: 0;
    /* Aligns to bottom edge */
    background: rgba(0, 0, 0, 0.5);
    /* Semi-transparent black */
    backdrop-filter: blur(4px);
    /* Blurs the main app behind */
    display: flex;
    /* Enables centering the modal */
    justify-content: center;
    /* Horizontal centering */
    align-items: center;
    /* Vertical centering */
    z-index: 1000;
    /* High priority above all else */
    animation: fadeIn 0.2s;
    /* Quick appearance animation */
}

.modal-container {
    /* The actual interactive popup box */
    background: #fff;
    /* Solid white modal area */
    width: 90%;
    /* Responsive width on mobile */
    max-width: 600px;
    /* Limits modal scale on desktop */
    border-radius: var(--radius-lg);
    /* Large rounded modal edges */
    box-shadow: var(--shadow-xl, 0 25px 50px -12px rgba(0, 0, 0, 0.25));
    /* Heavy modal shadow */
    display: flex;
    /* Content stacks vertically */
    flex-direction: column;
    /* Stack header, body, footer */
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    /* Professional slide entry */
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideIn {
    from {
        transform: translateY(-10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    margin: 0;
    color: var(--color-primary);
    font-size: 1.25rem;
}

.modal-body {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-footer {
    padding: 20px 24px;
    background: #f8fafc;
    border-top: 1px solid var(--color-border);
    border-bottom-left-radius: var(--radius-lg);
    border-bottom-right-radius: var(--radius-lg);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-import {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-import:hover {
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.4);
}

/* Inline Bank Empty State */
.bank-no-results {
    padding: 60px 40px;
    text-align: center;
    color: var(--color-text-muted);
    font-style: italic;
    background: #fdfdfd;
    border: 1px dashed #e2e8f0;
    border-radius: var(--radius-md);
    margin: 20px;
    font-size: 0.95rem;
}

/* Prevent question list panel from shrinking to fit content */
/* .inline-bank-list moved to active-selection section for grid consistency */

/* Custom scrollbar for a more premium look */
.inline-bank-list::-webkit-scrollbar {
    width: 8px;
}

.inline-bank-list::-webkit-scrollbar-track {
    background: #f1f5f9;
}

.inline-bank-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.inline-bank-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Bank card: ensure question text wraps and doesn't widen the panel */
.bank-card {
    width: 100%;
    box-sizing: border-box;
    word-wrap: break-word;
    overflow-wrap: break-word;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    cursor: pointer;
    border: 1px solid #f1f5f9;
}

.bank-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    background: #f8fafc;
    border-color: var(--color-primary);
}

/* Inner content of bank card must not overflow */
.bank-card>div {
    min-width: 0;
    width: 100%;
}

/* Question text inside bank card must wrap */
.bank-card div[style*="font-weight: 600"] {
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: normal;
}

/* Inline filter sidebar must not shrink */
.inline-filters-sidebar {
    flex-shrink: 0;
    width: 250px;
    min-width: 250px;
}

.bank-chapter-header {
    margin-top: 25px !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03) !important;
}

/* Registration Number Table/Boxes */
.reg-no-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: -10px;
    /* Adjusting to fit top right alignment */
}

.reg-no-label {
    font-size: 10pt;
    font-weight: bold;
    font-family: 'Times New Roman', serif;
}

.reg-no-grid {
    display: flex;
    border: 1.5px solid #000;
}

.reg-no-box {
    width: 20px;
    height: 25px;
    border: 0.5px solid #000;
    background: transparent;
}

/*Footer Actions*/
.preview-footer-actions {
    width: 100%;
    max-width: 210mm;
    margin: 20px auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 10px;
}

/* Image Selection & Resizing */
.resizable-img {
    cursor: move;
}

.resizable-img.selected {
    outline: 2px solid var(--color-primary);
}

/* Overlay Manager */
#image-tools-overlay {
    position: absolute;
    border: 1px dashed var(--color-primary);
    pointer-events: none;
    /* Let events pass to paper for selection, but handles intercept */
    z-index: 1000;
    display: none;
    box-shadow: 0 0 0 10000px rgba(0, 0, 0, 0);
    /* Invisible large shadow to catch clicks outside? No. */
}

.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background: white;
    border: 1px solid var(--color-primary);
    pointer-events: auto;
    z-index: 1001;
}

.resize-handle.nw {
    top: -5px;
    left: -5px;
    cursor: nw-resize;
}

.resize-handle.ne {
    top: -5px;
    right: -5px;
    cursor: ne-resize;
}

.resize-handle.sw {
    bottom: -5px;
    left: -5px;
    cursor: sw-resize;
}

.resize-handle.se {
    bottom: -5px;
    right: -5px;
    cursor: se-resize;
}

.remove-btn-img {
    position: absolute;
    top: -30px;
    right: 0;
    background: #ef4444;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.8rem;
    cursor: pointer;
    pointer-events: auto;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.paper {
    position: relative;
    /* Context for absolute items */
}

/* --- Modal Styles --- */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 8px;
    width: 400px;
    max-width: 90%;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.modal-title {
    font-size: 18px;
    font-weight: bold;
    color: #333;
}

.close-modal-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #666;
}

.close-modal-btn:hover {
    color: #f00;
}

/* --- Symbol Grid --- */
.symbol-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 10px;
}

.symbol-btn {
    /* Button for inserting math symbols */
    width: 100%;
    /* Fills grid cell */
    height: 40px;
    /* Standard tap target height */
    font-size: 18px;
    /* Visible math symbol scale */
    border: 1px solid #ccc;
    /* Light border for the button */
    background: #f9f9f9;
    /* Light background color */
    border-radius: 4px;
    /* Softened button corners */
    cursor: pointer;
    /* Click indication */
    display: flex;
    /* Enables symbol centering */
    align-items: center;
    /* Vertical centering */
    justify-content: center;
    /* Horizontal centering */
}

.symbol-btn:hover {
    background: #e0e0e0;
    border-color: #999;
}

/* --- Equation List --- */
.equation-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.equation-option {
    /* Item in the equation template list */
    display: flex;
    /* Aligns preview and label */
    align-items: center;
    /* Vertical centering */
    padding: 10px;
    /* Inner comfort space */
    border: 1px solid #ddd;
    /* Subtle separator line */
    border-radius: 4px;
    /* Card-like rounded corners */
    cursor: pointer;
    /* Interaction pointer */
    background: #fff;
    /* Default white background */
    transition: background 0.2s;
    /* Smooth selection effect */
}

.equation-option:hover {
    background: #f0f8ff;
    border-color: #007bff;
}

.equation-preview {
    font-family: 'Times New Roman', Times, serif;
    font-size: 1.2em;
    margin-right: 15px;
    min-width: 60px;
    text-align: center;
}

.equation-label {
    font-size: 14px;
    color: #333;
}

/* --- Rendered Equation Styles --- */
.mq-fraction {
    display: inline-block;
    vertical-align: middle;
    text-align: center;
    margin: 0 5px;
}

.mq-numerator {
    display: inline-block;
    border-bottom: 1px solid black;
    padding: 0 2px;
}

.mq-denominator {
    display: block;
    padding: 0 2px;
}

.mq-sqrt {
    display: inline-block;
}

.mq-sqrt-symbol {
    /* The  symbol */
    font-size: 1.2em;
}

.mq-sqrt-content {
    border-top: 1px solid black;
    padding-top: 2px;
    display: inline-block;
}

/* --- Equation Form Styles --- */
.equation-form-container {
    border-top: 1px solid #eee;
    margin-top: 15px;
    padding-top: 15px;
}

.equation-input-group {
    margin-bottom: 10px;
}

.equation-input-group label {
    display: block;
    font-size: 12px;
    color: #666;
    margin-bottom: 4px;
}

.equation-input-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
}

.equation-live-preview-box {
    margin: 15px 0;
    padding: 10px;
    border: 1px dashed #ccc;
    background: #fdfdfd;
    text-align: center;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Times New Roman', serif;
    font-size: 1.5em;
}

.eq-back-btn {
    background: none;
    border: none;
    color: #007bff;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 10px;
    padding: 0;
}

.eq-back-btn:hover {
    text-decoration: underline;
}

.eq-insert-btn {
    /* Final 'Add to Paper' button */
    width: 100%;
    /* Spans full modal width */
    padding: 10px;
    /* Generous clickable area */
    background: #28a745;
    /* Success green color */
    color: white;
    /* Clean white text contrast */
    border: none;
    /* Removes default button edge */
    border-radius: 4px;
    /* Matches other UI corners */
    cursor: pointer;
    /* Show interaction possible */
    font-weight: bold;
    /* Emphasis on the primary action */
}

.eq-insert-btn:hover {
    background: #218838;
}

/* --- Registration Number Section --- */
.reg-no-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}

.reg-no-label {
    font-weight: bold;
    font-size: 11pt;
}

.reg-no-grid {
    display: flex;
    gap: 0;
    border: 1px solid #000;
}

.reg-no-box {
    width: 25px;
    height: 25px;
    border-right: 1px solid #000;
}

.reg-no-box:last-child {
    border-right: none;
}

/* ========================================
   12. APPLICATION FOOTER
   Styles for the sticky bottom bar 
   with status, credits, and contact.
======================================== */
.app-footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 2px 40px;
    flex-shrink: 0;
    z-index: 100;
}

.footer-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    gap: 10px;
}

.footer-info,
.footer-status,
.footer-contact {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex: 1;
    align-items: center;
}


.version-tag {
    font-size: 0.65rem;
    font-weight: 400;
    color: var(--color-primary);
    background: auto;
    padding: 1px 5px;
    border-radius: 3px;
}

.copyright {
    font-size: 0.65rem;
    color: var(--color-text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-success);
    display: inline-block;
}

.status-text {
    font-size: 0.65rem;
    color: var(--color-text-muted);
}

.contact-label {
    font-size: 0.65rem;
    color: var(--color-text-muted);
}

.contact-link {
    font-size: 0.65rem;
    color: var(--color-primary);
    text-decoration: none;
    font-weight: 600;
}

.contact-link:hover {
    text-decoration: underline;
}

@media (max-width: 768px) {
    .footer-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }

    .footer-info,
    .footer-status,
    .footer-contact {
        align-items: center;
    }
}

/* Consolidated Print Settings */
@media print {
    @page {
        margin: 10mm;
        size: A4;
    }

    /* Hide UI elements */
    .no-print,
    .app-header,
    .progress-indicator,
    .header-actions,
    .paper-toolbar,
    .preview-actions,
    .preview-footer-actions,
    .tab-actions,
    .btn,
    .app-footer {
        display: none !important;
    }

    /* Hide all application tabs by default in print */
    .tab-content {
        display: none !important;
    }

    /* Force visibility only for the Preview Paper tab */
    #tab5.tab-content {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        max-width: none !important;
        background: transparent !important;
        box-shadow: none !important;
        height: auto !important;
        overflow: visible !important;
    }

    /* Hide the helper titles in the preview panel */
    #tab5 .tab-title,
    #tab5 .tab-subtitle,
    #tab5 .tab-header-flex {
        display: none !important;
    }

    body {
        background: #fff !important;
        margin: 0 !important;
        padding: 0 !important;
    }

    .app-container,
    .app-main,
    .preview-container {
        display: block !important;
        width: 100% !important;
        height: auto !important;
        /* Allow multi-page height */
        min-height: auto !important;
        margin: 0 !important;
        padding: 0 !important;
        box-shadow: none !important;
        max-width: none !important;
        overflow: visible !important;
        /* Remove scrollbars and clipping */
    }

    /* The Paper Sheet */
    .paper {
        width: 100% !important;
        min-height: auto !important;
        height: auto !important;
        /* Do NOT force padding to 0, allow JS-set margins to work */
        /* padding: 0 !important;  <-- Removed this */
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        display: block !important;
        overflow: visible !important;
        background: white !important;
        color: black !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Section & Question breaks */
    .section {
        page-break-inside: auto !important;
        break-inside: auto !important;
        margin-bottom: 20px !important;
    }

    .question {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        margin-bottom: 15px !important;
        display: flex !important;
        /* Preserve alignment */
    }

    .question-number {
        width: 35px !important;
        flex-shrink: 0 !important;
    }

    .question-content {
        flex: 1 !important;
    }

    /* Header adjustments */
    .paper-header {
        border-bottom: 2px solid #000 !important;
        margin-bottom: 20px !important;
        padding-bottom: 10px !important;
    }

    /* Reg boxes */
    .reg-no-wrapper {
        margin-bottom: 15px !important;
    }

    .reg-no-box {
        border: 1px solid #000 !important;
        width: 25px !important;
        height: 25px !important;
    }
}

/* Formula Reference Sheet Styles */
.formula-reference-section {
    page-break-before: always;
    margin-top: 50px;
    padding: 30px;
    background: #fff;
    border: 1px solid #ddd;
}

/* --- Formula Reference Sheet Styling --- */
@media screen {
    .formula-reference-section {
        display: none !important;
        /* Hide completely in preview tab */
    }
}

@media print {
    .formula-reference-section {
        display: block !important;
        page-break-before: always;
        border-top: 2px solid #333;
        padding-top: 20px;
    }
}

.chapter-formula-block {
    margin-bottom: 30px;
}

.chapter-formula-block h3 {
    font-family: 'Outfit', sans-serif;
    color: var(--color-primary);
    border-bottom: 2px solid var(--color-primary);
    padding-bottom: 5px;
    margin-bottom: 15px;
    font-size: 1.25rem;
}

.formula-reference-section table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Times New Roman', serif;
}

.formula-reference-section th,
.formula-reference-section td {
    border: 1px solid #cbd5e1;
    padding: 12px;
    text-align: left;
}

.formula-reference-section th {
    background-color: #f8fafc;
    font-weight: bold;
    text-transform: uppercase;
    font-size: 0.9rem;
    letter-spacing: 0.05em;
}

.formula-reference-section td:last-child {
    text-align: center;
    font-size: 1.1rem;
}

/* Image Resizing Handles */
.resize-handle {
    position: absolute;
    width: 10px;
    height: 10px;
    background-color: var(--color-primary);
    border: 1px solid #fff;
    border-radius: 50%;
    z-index: 100;
}

.resize-handle-n {
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.resize-handle-s {
    bottom: -5px;
    left: 50%;
    transform: translateX(-50%);
    cursor: ns-resize;
}

.resize-handle-e {
    right: -5px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.resize-handle-w {
    left: -5px;
    top: 50%;
    transform: translateY(-50%);
    cursor: ew-resize;
}

.resize-handle-ne {
    top: -5px;
    right: -5px;
    cursor: nesw-resize;
}

.resize-handle-nw {
    top: -5px;
    left: -5px;
    cursor: nwse-resize;
}

.resize-handle-se {
    bottom: -5px;
    right: -5px;
    cursor: nwse-resize;
}

.resize-handle-sw {
    bottom: -5px;
    left: -5px;
    cursor: nesw-resize;
}

/* Styles when resizing is active */
.resizing-active {
    outline: 2px dashed var(--color-primary);
    /* No box-shadow to avoid affect layout */
}

/* Image Resizing & Print Styles */
@media print {

    .resize-handle,
    .resize-hint,
    .resizing-active {
        display: none !important;
        outline: none !important;
        border: none !important;
    }

    .question-diagram-wrapper {
        border: none !important;
        box-shadow: none !important;
        outline: none !important;
    }

    .resizable-image {
        cursor: default !important;
    }
}

/* Custom Dropdown for Month Input */
.custom-select-wrapper {
    position: relative;
}

.custom-select-container {
    position: relative;
    width: 100%;
}

.custom-select-input {
    width: 100%;
}

.custom-select-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    margin-top: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    display: none;
}

.custom-select-dropdown.show {
    display: block;
}

.custom-select-option {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 0.95rem;
    color: var(--color-text);
    transition: background 0.2s, color 0.2s;
}

.custom-select-option:hover {
    background: var(--color-primary, #3b82f6);
    color: #fff;
}

/* ========================================
   REFINED MOBILE RESPONSIVENESS
   ======================================== */

@media (max-width: 768px) {

    /* 1. Global Setup */
    .app-main {
        padding: 10px !important;
    }

    .tab-card {
        padding: 15px !important;
        border-radius: var(--radius-md) !important;
        margin-bottom: 10px !important;
    }

    .tab-title {
        font-size: 1.3rem !important;
        text-align: center !important;
    }

    /* Global Input & Button Adjustments for Mobile */
    input,
    select,
    textarea {
        font-size: 16px !important;
        /* Prevents auto-zoom on iOS */
        padding: 12px !important;
        width: 100% !important;
        box-sizing: border-box !important;
        margin-bottom: 5px !important;
    }

    .btn {
        width: 100% !important;
        margin-bottom: 10px !important;
        padding: 14px 20px !important;
        font-size: 1rem !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 8px !important;
        box-sizing: border-box !important;
    }

    .tab-actions,
    .auth-actions,
    .modal-footer {
        flex-direction: column !important;
        gap: 8px !important;
    }

    .tab-actions .btn,
    .auth-actions .btn,
    .modal-footer .btn {
        width: 100% !important;
        margin: 0 !important;
    }

    /* Keep small buttons small */
    .btn-icon,
    .btn-sm,
    .tool-btn,
    .close-modal-btn,
    .remove-section-btn,
    .q-handle,
    .section-drag-handle {
        width: auto !important;
        min-width: unset !important;
        padding: 8px !important;
        margin-bottom: 0 !important;
    }

    /* 2. Header & Progress Navigation */
    .app-header {
        grid-template-columns: 1fr !important;
        padding: 8px !important;
        gap: 8px !important;
    }

    .app-header-content {
        justify-content: center !important;
        text-align: center !important;
    }

    .progress-indicator {
        overflow-x: auto !important;
        justify-content: flex-start !important;
        padding-bottom: 10px !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 8px !important;
        scrollbar-width: none;
    }

    .progress-indicator::-webkit-scrollbar {
        display: none;
    }

    .progress-step {
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        padding: 6px 12px !important;
        font-size: 0.8rem !important;
    }

    /* 3. Login Section */
    .login-wrapper {
        min-height: auto !important;
        padding: 10px 0 !important;
    }

    .login-container {
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        box-shadow: none !important;
    }

    .login-main {
        padding: 20px !important;
    }

    .auth-title {
        font-size: 1.5rem !important;
        text-align: center !important;
    }

    /* 4. History Panel & Lists */
    .history-item {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
        padding: 15px !important;
        height: auto !important;
        margin-top: 30px;
    }

    .q-card {
        flex-direction: column !important;
        padding: 0 !important;
        position: relative !important;
        overflow: visible !important;
    }

    /* Unified Header Bar: Handle(Left), Num/Badges(Inline), Actions(Right) */
    .q-handle {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        height: 48px !important;
        width: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f1f5f9 !important;
        border-right: 1px solid var(--color-border) !important;
        z-index: 10 !important;
        margin: 0 !important;
        padding: 0 !important;
        color: #94a3b8 !important;
    }

    .q-num-panel {
        width: 100% !important;
        height: 48px !important;
        border-right: none !important;
        border-bottom: 1px solid var(--color-border) !important;
        flex-direction: row !important;
        justify-content: flex-start !important;
        align-items: center !important;
        padding: 0 150px 0 44px !important;
        /* L-Pad for handle, R-Pad for 4 buttons */
        background: #f8fafc !important;
        gap: 8px !important;
        margin: 0 !important;
    }

    .q-num-panel .q-num {
        font-size: 1.1rem !important;
        font-weight: 800 !important;
        color: var(--color-primary) !important;
    }

    .q-num-panel .q-badge-mini {
        margin: 0 !important;
        padding: 2px 6px !important;
        font-size: 0.65rem !important;
    }

    .q-card-actions {
        position: absolute !important;
        top: 0 !important;
        right: 0 !important;
        height: 48px !important;
        width: auto !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        padding-right: 8px !important;
        gap: 3px !important;
        z-index: 1000 !important;
        /* Ensure it's on top of other content */
        background: transparent !important;
        margin: 0 !important;
        border: none !important;
    }

    .q-card-actions .btn-icon {
        width: 28px !important;
        height: 28px !important;
        padding: 0 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        border-radius: 4px !important;
        background: white !important;
        box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05) !important;
        border: 1px solid #e2e8f0 !important;
        font-size: 12px !important;
    }

    .q-card-actions .btn-icon.danger {
        border-color: #fca5a5 !important;
        color: #ef4444 !important;
    }

    /* Target the main content area */
    .q-card>div:last-child {
        display: flex !important;
        flex-direction: column !important;
        padding: 12px !important;
        position: static !important;
    }

    /* Content flow: Question text below header */
    .q-card>div:last-child>div:first-child {
        padding-right: 0 !important;
        order: 2 !important;
    }

    .section-card {
        padding: 0 !important;
        position: relative !important;
        overflow: visible !important;
    }

    .section-drag-handle {
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        height: 44px !important;
        width: 36px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: #f1f5f9 !important;
        border-right: 1px solid var(--color-border) !important;
        z-index: 10 !important;
        margin: 0 !important;
        padding: 0 !important;
        color: #94a3b8 !important;
    }

    .remove-section-btn {
        position: absolute !important;
        top: 0 !important;
        right: 0 !important;
        height: 44px !important;
        width: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        z-index: 10 !important;
        background: #fee2e2 !important;
        color: #ef4444 !important;
        border: none !important;
        border-bottom-left-radius: 12px !important;
        margin: 0 !important;
        font-size: 20px !important;
    }

    .section-header-row {
        height: 44px !important;
        padding: 0 50px 0 46px !important;
        margin: 0 !important;
        background: #f8fafc !important;
        border-bottom: 1px solid var(--color-border) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
    }

    .section-number {
        font-size: 1rem !important;
        font-weight: 800 !important;
    }

    .section-config {
        padding: 20px 15px !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        gap: 15px !important;
    }

    .config-field {
        grid-column: span 2 !important;
    }

    /* Grids & Modal Configuration */
    .form-grid,
    .chapter-grid,
    .qm-bottom-actions {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .chapter-item {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 12px !important;
        padding: 12px !important;
        background: #fff !important;
        border: 1px solid var(--color-border) !important;
        border-radius: var(--radius-sm) !important;
        text-align: left !important;
    }

    .chapter-item input[type="checkbox"] {
        margin: 0 !important;
        width: 18px !important;
        height: 18px !important;
        flex-shrink: 0 !important;
        order: -1 !important;
        /* Ensure checkbox is on left */
    }

    .chapter-item label {
        margin: 0 !important;
        cursor: pointer !important;
        font-size: 0.95rem !important;
        line-height: 1.4 !important;
        flex: 1 !important;
    }

    .config-field {
        grid-column: span 1 !important;
    }

    .qm-section-info {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 10px !important;
        padding: 12px !important;
    }

    /* 6. Question Selection (Tab 4) */
    .section-tabs {
        overflow-x: auto !important;
        white-space: nowrap !important;
        padding-bottom: 5px !important;
        margin-bottom: 15px !important;
        display: flex !important;
        gap: 10px !important;
    }

    .active-selection-slot {
        height: 100vh !important;
        width: 100vw !important;
        margin: 0 !important;
        border-radius: 0 !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        grid-template-rows: auto 1fr !important;
    }

    .active-selection-header {
        height: auto !important;
        padding: 10px !important;
        flex-direction: column !important;
        gap: 10px !important;
    }

    .q-header-actions {
        width: 100% !important;
        justify-content: space-around !important;
    }

    .inline-selection-body {
        display: flex !important;
        flex-direction: column !important;
        overflow-y: auto !important;
    }

    .inline-filters-sidebar {
        display: block !important;
        width: 100% !important;
        min-width: unset !important;
        height: auto !important;
        border-right: none !important;
        border-bottom: 1px solid #e2e8f0 !important;
        background: #f1f5f9 !important;
        padding: 12px !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr !important;
        /* Two columns for filter fields */
        gap: 10px !important;
    }

    .inline-bank-list {
        padding: 10px !important;
    }

    /* 7. Preview & Toolbars (Tab 5) */
    .preview-actions {
        flex-wrap: wrap !important;
        justify-content: center !important;
        padding: 10px 5px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        background: white !important;
        box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    }

    .toolbar-group {
        padding: 8px !important;
        background: #f1f5f9 !important;
        border-radius: 8px !important;
        width: 48% !important;
        min-width: 140px !important;
        margin: 2px !important;
        flex-grow: 1 !important;
    }

    .preview-container {
        overflow-x: auto !important;
        padding: 15px 0 !important;
        background: #dee2e6 !important;
    }

    .paper {
        margin: 0 5px !important;
        transform: scale(0.9) !important;
        transform-origin: top left !important;
        min-width: 210mm !important;
    }

    .preview-footer-actions {
        flex-direction: column !important;
        padding: 15px !important;
        position: sticky !important;
        bottom: 0 !important;
        background: white !important;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05) !important;
    }

    /* Tab 4: Question Selection - Mobile Optimization */
    .question-filters {
        padding: 10px 12px !important;
        margin-bottom: 12px !important;
        background: #f8fafc !important;
        border: 1px solid #e2e8f0 !important;
    }

    .filter-row {
        gap: 8px !important;
        flex-wrap: wrap !important;
    }

    .filter-group {
        gap: 4px !important;
        font-size: 0.75rem !important;
        flex: 0 1 auto !important;
    }

    .filter-group label {
        font-size: 0.7rem !important;
        font-weight: 600 !important;
    }

    .filter-group select {
        padding: 4px 8px !important;
        font-size: 0.75rem !important;
        height: 28px !important;
        border-radius: 3px !important;
    }

    .checkbox-group label {
        font-size: 0.75rem !important;
        gap: 4px !important;
    }

    .question-list-container {
        max-height: 70vh !important;
        margin-bottom: 10px !important;
        border: 1px solid #e2e8f0 !important;
    }

    .bank-card {
        padding: 12px !important;
        margin-bottom: 6px !important;
        font-size: 0.8rem !important;
    }

    .q-card.filled-slot {
        min-height: 50px !important;
        padding: 0 !important;
    }

    /* 8. Modals & Footer */
    .modal-container {
        width: 95% !important;
        margin: 10px !important;
    }

    .footer-content {
        flex-direction: column !important;
        text-align: center !important;
    }
}

/* Landscape mode tweaks */
@media (max-width: 900px) and (orientation: landscape) {
    .app-header {
        position: relative !important;
    }

    .active-selection-slot {
        height: 100vh !important;
    }
}

/* ========================================
   PRINT & EXPORT OPTIMIZATIONS
   Ensures the final document looks perfect 
   when saved as PDF or printed to A4.
======================================== */
@media print {
    @page {
        margin: 0 !important;
        size: A4 portrait;
    }

    body {
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: visible !important;
    }

    .app-header,
    .tab-actions,
    .progress-indicator,
    .tool-btn,
    .btn,
    .tab-title,
    .tab-subtitle,
    .sidebar-left {
        display: none !important;
    }

    .app-main {
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
        display: block !important;
        background: #fff !important;
    }

    #tab5,
    .tab-content,
    .paper-preview-container {
        display: block !important;
        width: 100% !important;
        max-width: none !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
    }

    /* Hide the continuous sheet, show the paginated ones */
    #final-document-sheet.continuous-document {
        display: none !important;
    }
}

/* Dedicated Multi-Page Container for Prints/PDFs */
.a4-page {
    width: 210mm;
    height: 296mm;
    /* Fixed height is mandatory to prevent spill-over (which kills margins) */
    min-height: 296mm;
    padding: 10mm 12mm 15mm 12mm;
    /* Updated tighter margins */
    background: #fff;
    box-sizing: border-box;
    position: relative;
    overflow: hidden;
    /* MANDATORY: Prevents invisible overflow from spanning sheets */
    page-break-after: always;
    break-after: page;
    color: #334155;
    margin: 0 auto;
    border: none;
    box-shadow: none;
}

.a4-page:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
}

/* Print-mode utility for JS exports */
.print-mode {
    padding: 0 !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
    background: white !important;
}

/* Tab 5 Preview Separation Styles (Browser Only) */
#tab-5-preview-workspace {
    background-color: #f1f5f9;
    padding: 30px 0;
}

#a4-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 40px;
}

#a4-pages-container .a4-page {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    border-bottom: 2px dashed #94a3b8;
}

/* Ensure shadow/border doesn't show in PDF/Print */
@media print {
    #a4-pages-container .a4-page {
        box-shadow: none !important;
        border-bottom: none !important;
    }
}

.dashboard-filters {
    background: #f8fafc;
    padding: 12px 20px;
    border-radius: 16px;
    border: 1px solid #e2e8f0;
    margin-bottom: 25px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.02);
    display: flex;
    flex-wrap: wrap;
    /* Allows wrapping on smaller tablet screens */
    gap: 12px;
    align-items: center;
}

/* Desktop Single Line View */
@media (min-width: 992px) {
    .dashboard-filters {
        flex-wrap: wrap;
        /* Changed to wrap to prevent overlap if screen is tight */
        justify-content: flex-start;
    }

    .dashboard-filters .search-box-pill {
        flex: 2 1 200px;
        /* Grow, shrink, basis */
        min-width: 200px;
        max-width: 350px;
    }

    .dashboard-filters select,
    .dashboard-filters .filter-date-group {
        flex: 1 0 160px;
        /* Don't shrink below 160px */
        min-width: 160px;
    }

    .dashboard-filters .btn-clear {
        margin-left: auto;
        /* Pushes clear button to the end if space permits */
        flex-shrink: 0;
    }
}

.dashboard-filters select,
.dashboard-filters input {
    width: 80%;
    padding: 8px 12px;
    border-radius: 20px;
    border: 1.5px solid #e2e8f0;
    font-size: 0.85rem;
    outline: none;
    background: white;
    cursor: pointer;
    transition: all 0.2s ease;
}

.dashboard-filters .search-box-pill {
    position: relative;
    width: 80%;
}

.dashboard-filters .search-box-pill input {
    padding-left: 35px;
}

.dashboard-filters .filter-date-group {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
    flex: 1 0 auto;
    /* Ensure it stays in its own space */
}

.dashboard-filters .filter-date-group label {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
}

.dashboard-filters select:hover,
.dashboard-filters input:hover {
    border-color: var(--color-primary) !important;
}

.dashboard-filters select:focus,
.dashboard-filters input:focus {
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.dashboard-filters .btn-clear {
    background: #f1f5f9;
    border: none;
    color: #475569;
    padding: 8px 18px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.dashboard-filters .btn-clear:hover {
    background: #e2e8f0;
    color: #1e293b;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .dashboard-filters {
        flex-direction: column;
        align-items: stretch;
        padding: 15px;
    }

    .dashboard-filters .filter-date-group {
        flex-direction: row;
        justify-content: space-between;
    }

    .dashboard-filters .filter-date-group input {
        width: 100%;
    }
}

/* ========================================
   RECENT PAPERS DASHBOARD GRID
   ======================================== */
.papers-grid {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 15px;
}

.paper-card-v2 {
    background: #ffffff;
    border: 1.5px solid #f1f5f9;
    border-radius: 20px;
    padding: 12px 18px;
    display: flex;
    align-items: center;
    gap: 20px;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
}

.paper-card-v2:hover {
    border-color: var(--color-primary);
    background: #fcfdfe;
    transform: translateX(5px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
}

.paper-icon-visual {
    flex-shrink: 0;
}

.icon-orb {
    width: 60px;
    height: 60px;
    background: #f8fafc;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid #e2e8f0;
}

.icon-orb i {
    font-size: 1.6rem;
    color: var(--color-primary);
    opacity: 0.7;
}

.paper-body {
    flex: 3;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.paper-top-strip {
    display: flex;
    align-items: center;
    gap: 12px;
}

.paper-badge {
    background: #eff6ff;
    color: #1e40af;
    padding: 2px 10px;
    border-radius: 6px;
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
}

.paper-date-stamp {
    font-size: 0.75rem;
    color: #94a3b8;
    font-weight: 600;
}

.paper-title {
    font-size: 1.25rem;
    font-weight: 800;
    color: #1e293b;
    margin: 2px 0;
}

.paper-sub-meta {
    display: flex;
    gap: 15px;
}

.meta-item {
    font-size: 0.8rem;
    color: #64748b;
    display: flex;
    align-items: center;
    gap: 6px;
}

.paper-card-actions {
    flex: 1.5;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn-paper-v2 {
    padding: 10px 15px;
    border: none;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 800;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: 0.2s;
}

.btn-load {
    background: #f1f5f9;
    color: #475569;
    border: 1.5px solid #e2e8f0;
}

.btn-pdf {
    background: #dcfce7;
    color: #166534;
    border: 1.5px solid #bbf7d0;
}

.btn-delete {
    background: #fff1f2;
    color: #e11d48;
    border: 1.5px solid #ffe4e6;
}

.btn-pdf:hover {
    background: #bbf7d0;
    transform: translateY(-2px);
}

.btn-delete:hover {
    background: #ffe4e6;
    transform: translateY(-2px);
}

@media (max-width: 768px) {
    .paper-card-v2 {
        flex-direction: column;
        align-items: flex-start;
        padding: 20px;
    }

    .paper-card-actions {
        width: 100%;
        margin-top: 15px;
        padding-top: 15px;
        border-top: 1px solid #f1f5f9;
        justify-content: flex-start;
    }

    .paper-icon-visual {
        display: none;
    }
}

.skeleton-loader {
    grid-column: 1 / -1;
    text-align: center;
    padding: 40px;
    color: #94a3b8;
    background: #f8fafc;
    border: 2px dashed #e2e8f0;
    border-radius: 20px;
    font-weight: 600;
}

#final-document-sheet {
    contain: layout;
    /* Key fix for reflow */
    width: 210mm;
    margin: 0 auto;
    background: white;
    overflow: hidden;
    /* Rendering-a isolate pannum */
}