/* Master Exam Studio Pro - Stylesheet */
:root {
    --primary: #15803d;
    --primary-hover: #166534;
    --secondary: #1d4ed8;
    --accent: #b45309;
    --bg-page: #f1f5f9;
    --panel-bg: #ffffff;
    --border-ui: #cbd5e1;
    --spiral-margin: 26mm;
    --pdf-font-size: 10pt;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg-page);
    margin: 0;
    padding: 20px;
    color: #1e293b;
}

.control-panel {
    background: var(--panel-bg);
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.08);
    margin-bottom: 24px;
    border-top: 6px solid var(--primary);
    max-width: 1300px;
    margin-left: auto;
    margin-right: auto;
}

.header-title-box {
    text-align: center;
    border-bottom: 2px solid #e2e8f0;
    padding-bottom: 14px;
    margin-bottom: 20px;
}
.header-title-box h1 {
    margin: 0;
    color: #0f172a;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.header-title-box p {
    margin: 6px 0 0 0;
    color: #64748b;
    font-size: 13.5px;
    font-weight: 500;
}
.vercel-badge {
    background: #0f172a;
    color: #fff;
    font-size: 11px;
    padding: 3px 9px;
    border-radius: 12px;
    font-weight: 700;
    display: inline-block;
    margin-left: 8px;
    vertical-align: middle;
}

.section-header {
    font-size: 15px;
    font-weight: 700;
    margin-top: 18px;
    margin-bottom: 10px;
    border-bottom: 1.5px dashed var(--border-ui);
    padding-bottom: 5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.form-group { margin-bottom: 12px; }
label {
    font-weight: 600;
    display: block;
    margin-bottom: 5px;
    color: #334155;
    font-size: 12.5px;
}
input, select, textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border-ui);
    border-radius: 6px;
    box-sizing: border-box;
    font-size: 13.5px;
    background: #fff;
    transition: border-color 0.2s;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
input[type="file"] {
    padding: 6px;
    background: #f8fafc;
    cursor: pointer;
}
input[type="color"] {
    padding: 2px;
    height: 38px;
    cursor: pointer;
    border: none;
}
textarea {
    resize: vertical;
    font-family: 'Consolas', 'Courier New', monospace;
    background: #f8fafc;
    line-height: 1.5;
}
#rawInput {
    height: 240px;
    font-size: 13.5px;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 14px; }
.grid-5 { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.grid-6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; }

@media (max-width: 900px) {
    .grid-6, .grid-5, .grid-4, .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 600px) {
    .grid-6, .grid-5, .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* Tag Shortcut Toolbar */
.tag-helper-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 8px;
    border: 1.5px solid #cbd5e1;
    margin-bottom: 8px;
    align-items: center;
}
.btn-tag {
    background: #ffffff;
    border: 1.5px solid #94a3b8;
    padding: 7px 12px;
    border-radius: 6px;
    font-size: 12.5px;
    font-weight: 700;
    color: #1e293b;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn-tag:hover {
    background: #e2e8f0;
    border-color: #64748b;
    transform: translateY(-1px);
}
.btn-tag.active-tag {
    background: #15803d !important;
    color: #ffffff !important;
    border-color: #166534 !important;
    box-shadow: 0 0 0 3px rgba(22, 101, 52, 0.25), 0 2px 6px rgba(0,0,0,0.15) !important;
    transform: scale(1.03);
}
.tag-status-dot {
    display: none;
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    box-shadow: 0 0 6px #4ade80;
}
.btn-tag.active-tag .tag-status-dot {
    display: inline-block;
}

/* Sticky Active Mode Banner */
#activeModeBanner {
    display: none;
    padding: 10px 16px;
    background: #f0fdf4;
    border: 1.5px solid #22c55e;
    border-left: 6px solid #15803d;
    border-radius: 7px;
    margin-bottom: 10px;
    font-size: 13px;
    color: #14532d;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.btn-reset-mode {
    background: #dc2626;
    color: white;
    border: none;
    padding: 5px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
    transition: all 0.2s;
}
.btn-reset-mode:hover {
    background: #b91c1c;
    transform: translateY(-1px);
}

/* Action Buttons */
.btn-group {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 18px;
}
.action-btn {
    border: none;
    padding: 13px 18px;
    font-size: 14.5px;
    border-radius: 7px;
    cursor: pointer;
    font-weight: 700;
    flex: 1;
    min-width: 170px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.action-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 12px -2px rgba(0,0,0,0.15);
}
.btn-pdf { background: #15803d; color: white; }
.btn-pdf:hover { background: #166534; }
.btn-word { background: #b91c1c; color: white; }
.btn-word:hover { background: #991b1b; }
.btn-ppt { background: #0284c7; color: white; }
.btn-ppt:hover { background: #0369a1; }
.btn-save-md { background: #7c3aed; color: white; }
.btn-save-md:hover { background: #6d28d9; }
.btn-save-txt { background: #475569; color: white; }
.btn-save-txt:hover { background: #334155; }

#toast {
    visibility: hidden;
    min-width: 280px;
    background: #0f172a;
    color: white;
    text-align: center;
    border-radius: 8px;
    padding: 12px 20px;
    position: fixed;
    z-index: 9999;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    font-weight: 600;
    font-size: 13.5px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.25);
    transition: all 0.3s;
}
#toast.show { visibility: visible; bottom: 40px; }

/* ==============================================================
   PRINT MEDIA STYLES (A4, 26MM SPIRAL, RIGHT OMR, ZERO BLANK FOOTER)
   ============================================================== */
#print-area { display: none; background: #fff; }

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }
    * {
        box-sizing: border-box;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    body {
        background: #fff;
        padding: 0;
        margin: 0;
        font-family: 'Nirmala UI', 'Mangal', 'Segoe UI', Arial, sans-serif;
        font-size: var(--pdf-font-size, 10pt);
        color: #0f172a;
    }
    .control-panel, #toast { display: none !important; }
    #print-area { display: block !important; }

    .pdf-page {
        width: 210mm;
        height: 297mm;
        max-height: 297mm;
        padding-top: 10mm;
        padding-bottom: 9mm;
        padding-left: var(--spiral-margin, 26mm);
        padding-right: 10mm;
        page-break-after: always;
        break-after: page;
        position: relative;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        overflow: hidden;
    }

    .pdf-page::before {
        content: "";
        position: absolute;
        left: 20mm;
        top: 12mm;
        bottom: 12mm;
        width: 0;
        border-left: 1px dashed #cbd5e1;
        pointer-events: none;
    }

    .pdf-header {
        border-bottom: 2px solid #0f172a;
        padding-bottom: 4px;
        display: flex;
        justify-content: space-between;
        align-items: flex-end;
        font-size: 9.5pt;
        width: 100%;
        margin-bottom: 6px;
    }
    .header-left {
        display: flex;
        flex-direction: column;
    }
    .header-title {
        font-size: 13pt;
        font-weight: 800;
        color: #0f172a;
        line-height: 1.15;
    }
    .header-subtitle {
        font-size: 8.5pt;
        color: #475569;
        font-weight: 600;
        margin-top: 1px;
    }
    .header-right {
        font-size: 8pt;
        font-weight: 700;
        color: #1e3a8a;
        background: #eff6ff;
        padding: 3px 8px;
        border-radius: 4px;
        border: 1px solid #bfdbfe;
        white-space: nowrap;
    }

    .page-body-container {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        gap: 8px;
        overflow: hidden;
    }

    .exam-q-row {
        flex: 1;
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        border-bottom: 1px dashed #e2e8f0;
        padding-bottom: 6px;
        padding-top: 2px;
    }
    .exam-q-row:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .exam-q-content {
        flex: 1;
        font-size: 9.5pt;
        line-height: 1.45;
        text-align: justify;
    }

    .exam-origin-badge {
        display: inline-block;
        background: #f8fafc;
        border: 1px solid #cbd5e1;
        border-left: 3px solid #0284c7;
        color: #0369a1;
        font-size: 7.8pt;
        font-weight: 700;
        padding: 1px 7px;
        border-radius: 3px;
        margin-bottom: 4px;
    }

    .q-stem {
        font-weight: 700;
        color: #0f172a;
        margin-bottom: 5px;
    }
    .q-number {
        display: inline-block;
        color: #15803d;
        font-weight: 800;
        margin-right: 4px;
    }

    .options-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 3px 12px;
        margin-top: 4px;
        font-size: 9.2pt;
    }
    .opt-item {
        display: flex;
        align-items: flex-start;
        gap: 4px;
        line-height: 1.35;
    }
    .opt-lbl {
        font-weight: 700;
        color: #475569;
        flex-shrink: 0;
    }

    .bilingual-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 4px;
    }
    .bilingual-td {
        width: 50%;
        vertical-align: top;
        padding-right: 8px;
    }

    .exam-omr-col {
        width: 38px;
        flex-shrink: 0;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: flex-start;
        background: #f8fafc;
        border: 1px solid #e2e8f0;
        border-radius: 5px;
        padding: 4px 2px;
        gap: 3px;
        margin-top: 2px;
    }
    .omr-title {
        font-size: 6.8pt;
        font-weight: 800;
        color: #64748b;
        letter-spacing: 0.5px;
        border-bottom: 1px solid #cbd5e1;
        width: 100%;
        text-align: center;
        padding-bottom: 2px;
        margin-bottom: 1px;
    }
    .omr-bubble {
        width: 17px;
        height: 17px;
        border-radius: 50%;
        border: 1.2px solid #475569;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 7.2pt;
        font-weight: 700;
        color: #334155;
        background: #ffffff;
    }
    .omr-bubble.filled {
        background: #0f172a !important;
        color: #ffffff !important;
        border-color: #0f172a !important;
    }

    .exam-s-row {
        flex: 1;
        border: 1px solid #e2e8f0;
        border-left: 4px solid #15803d;
        background: #ffffff;
        border-radius: 6px;
        padding: 8px 12px;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        font-size: 9.3pt;
        line-height: 1.45;
        overflow: hidden;
    }
    .solution-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px dashed #cbd5e1;
        padding-bottom: 4px;
        margin-bottom: 6px;
    }
    .ans-key-badge {
        background: #dcfce7;
        color: #15803d;
        font-weight: 800;
        font-size: 9.5pt;
        padding: 2px 10px;
        border-radius: 4px;
        border: 1px solid #86efac;
    }
    .exp-text {
        color: #1e293b;
        text-align: justify;
        margin-top: 4px;
    }

    .yt-player-card {
        margin-top: 6px;
        background: #f8fafc;
        border: 1px solid #cbd5e1;
        border-left: 4px solid #dc2626;
        border-radius: 6px;
        padding: 6px 10px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        break-inside: avoid;
    }
    .yt-main-info {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
    }
    .yt-play-icon {
        background: #dc2626;
        color: #fff;
        width: 28px;
        height: 28px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        flex-shrink: 0;
    }
    .yt-title-badge {
        font-size: 8.5pt;
        font-weight: 800;
        color: #b91c1c;
    }
    .yt-clip-time {
        font-size: 8pt;
        font-weight: 700;
        color: #1e3a8a;
    }
    .yt-qr-box {
        display: flex;
        flex-direction: column;
        align-items: center;
        border-left: 1px dashed #cbd5e1;
        padding-left: 8px;
        flex-shrink: 0;
    }
    .yt-qr-label {
        font-size: 6.8pt;
        font-weight: 700;
        color: #475569;
        margin-top: 2px;
        text-align: center;
    }

    .web-link-card {
        margin-top: 6px;
        background: #f8fafc;
        border: 1px solid #cbd5e1;
        border-left: 4px solid #0284c7;
        border-radius: 6px;
        padding: 6px 10px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 10px;
        break-inside: avoid;
    }
    .web-link-info {
        display: flex;
        align-items: center;
        gap: 8px;
        flex: 1;
    }
    .web-link-icon {
        background: #0284c7;
        color: #fff;
        width: 26px;
        height: 26px;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 13px;
        flex-shrink: 0;
    }
    .web-link-title {
        font-size: 8.5pt;
        font-weight: 800;
        color: #0369a1;
    }
    .web-link-url {
        font-size: 7.8pt;
        color: #475569;
        word-break: break-all;
        text-decoration: underline;
    }

    .section-divider-page {
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
        height: 297mm;
    }
    .section-divider-card {
        border: 3px double #0f172a;
        padding: 36px 45px;
        border-radius: 12px;
        background: #f8fafc;
        width: 80%;
    }
    .section-divider-card h2 {
        font-size: 22pt;
        color: #15803d;
        margin: 0 0 12px 0;
    }
    .section-divider-card h3 {
        font-size: 14pt;
        color: #0f172a;
        margin: 0 0 10px 0;
    }
    .section-divider-card p {
        font-size: 10.5pt;
        color: #64748b;
        margin: 0;
    }

    .page-footer {
        border-top: 1.2px solid #cbd5e1;
        padding-top: 4px;
        display: flex;
        justify-content: space-between;
        font-size: 8pt;
        color: #64748b;
        width: 100%;
    }
    .footer-left { font-weight: 600; }
    .footer-center { color: #94a3b8; }
    .footer-right { font-weight: 700; color: #0f172a; }
}


/* Enhanced YouTube Video Preview Card */
.yt-preview-card {
    margin: 8px 0;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-left: 5px solid #dc2626;
    border-radius: 8px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    break-inside: avoid;
    page-break-inside: avoid;
}
.yt-thumb-box {
    position: relative;
    width: 140px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    flex-shrink: 0;
    background: #000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.15);
}
.yt-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.yt-play-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(220, 38, 38, 0.9);
    color: #ffffff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.4);
    pointer-events: none;
}
.yt-duration-badge {
    position: absolute;
    bottom: 4px;
    right: 4px;
    background: rgba(15, 23, 42, 0.88);
    color: #ffffff;
    font-size: 6.8pt;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 3px;
    letter-spacing: 0.3px;
}
.yt-meta-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.yt-badge-tag {
    font-size: 8.5pt;
    font-weight: 800;
    color: #b91c1c;
    display: flex;
    align-items: center;
    gap: 5px;
}
.yt-icon-logo {
    background: #dc2626;
    color: #fff;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
}
.yt-time-info {
    font-size: 8pt;
    font-weight: 700;
    color: #1e3a8a;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
    width: fit-content;
}
.yt-watch-btn {
    font-size: 7.5pt;
    color: #0284c7;
    text-decoration: underline;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.yt-qr-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    border-left: 1px dashed #cbd5e1;
    padding-left: 10px;
    flex-shrink: 0;
}
.yt-qr-label {
    font-size: 6.8pt;
    font-weight: 700;
    color: #475569;
    margin-top: 3px;
    text-align: center;
}

@media print {
    .yt-preview-card {
        padding: 5px 8px;
        margin: 4px 0;
        border: 1px solid #94a3b8;
        border-left: 4px solid #dc2626;
        break-inside: avoid !important;
        page-break-inside: avoid !important;
    }
    .yt-thumb-box {
        width: 110px;
        height: 65px;
    }
    .yt-play-overlay {
        width: 24px;
        height: 24px;
        font-size: 11px;
    }
    .yt-duration-badge {
        font-size: 6pt;
        padding: 1px 4px;
    }
    .yt-badge-tag {
        font-size: 7.8pt;
    }
    .yt-time-info {
        font-size: 7.2pt;
        padding: 1px 6px;
    }
}
