/* ========================================================
   SMP - LaTeX Quick Viewer Stylesheet
   Secret of Mathematical Principles
   Quy chuẩn thiết kế đồng nhất theo hệ thống SMP
   (GeoGebra → TikZ Extractor & LaTeX Editor v2)
   ======================================================== */

:root {
    --body-bg: #0b1111;
    --widget-title-color: #fff;
    --widget-link-color: #888;
    --widget-badge-bg: rgba(255, 255, 255, 0.05);
    --widget-badge-color: #aaa;
    --exam-paper-bg: rgba(255, 255, 255, 0.025);
    --exam-paper-border: rgba(92, 225, 230, 0.09);
    --exam-text-color: #ddd;
    --exam-bold-color: #f4f4f4;
    --exam-title-color: #f0f0f0;
    --exam-divider-color: rgba(92, 225, 230, 0.1);
    --accent-cyan: #5ce1e6;
    --accent-gold: #c9a96e;
    --border-light: rgba(92, 225, 230, 0.12);
    --text-muted: #94a3b8;
    --pane-bg: #14181a;
    --pane-border: rgba(92, 225, 230, 0.15);
    --input-bg: #0f1315;
    --btn-bg: rgba(92, 225, 230, 0.08);
    --btn-hover: rgba(92, 225, 230, 0.20);
}

body:not(.dark-mode) {
    --body-bg: #f8fafc;
    --widget-title-color: #1e293b;
    --widget-link-color: #64748b;
    --widget-badge-bg: rgba(0, 0, 0, 0.05);
    --widget-badge-color: #475569;
    --exam-paper-bg: #ffffff;
    --exam-paper-border: rgba(15, 23, 42, 0.08);
    --exam-text-color: #334155;
    --exam-bold-color: #0f172a;
    --exam-title-color: #1e293b;
    --exam-divider-color: rgba(15, 23, 42, 0.08);
    --accent-cyan: #009eb3;
    --accent-gold: #b38938;
    --border-light: rgba(15, 23, 42, 0.08);
    --text-muted: #64748b;
    --pane-bg: #ffffff;
    --pane-border: rgba(15, 23, 42, 0.12);
    --input-bg: #f8fafc;
    --btn-bg: rgba(0, 158, 179, 0.08);
    --btn-hover: rgba(0, 158, 179, 0.16);
}

body {
    background-color: var(--body-bg);
    transition: background-color 0.3s ease;
    overflow-x: hidden;
}

body.embed-mode .main-wrapper {
    width: 100% !important;
    margin-left: 0 !important;
    padding-top: 0 !important;
}

.main-wrapper {
    position: relative;
    max-width: 2000px !important;
    width: 100% !important;
    margin: 0 auto !important;
    transform: none !important;
    left: 0 !important;
}

/* ── SMP Grid Layout ────────────────────────────────────── */
.main-content-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 36px;
    margin-top: 20px;
    min-width: 0;
}

.tags-comment-sidebar {
    display: flex;
    flex-direction: column;
    gap: 36px;
    position: sticky;
    top: 100px;
    height: fit-content;
    z-index: 1;
}

.side-widget-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.1rem;
    color: var(--widget-title-color);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    transition: color 0.3s ease;
}

body:not(.dark-mode) .side-widget-title {
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}

.side-widget-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.side-widget-list a {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--widget-link-color);
    text-decoration: none;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.side-widget-list a:hover {
    color: var(--accent-cyan);
    transform: translateX(4px);
}

.side-widget-list a span {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    background: var(--widget-badge-bg);
    padding: 2px 8px;
    border-radius: 12px;
    color: var(--widget-badge-color);
    transition: background-color 0.3s ease, color 0.3s ease;
}

@media (max-width: 1100px) {
    .main-content-layout {
        grid-template-columns: 1fr;
    }
    .tags-comment-sidebar {
        display: none;
    }
}

.main-articles-body {
    min-width: 0;
    width: 100%;
    overflow: hidden;
}

/* ── Navigation & Breadcrumbs (Chuẩn SMP) ───────────────── */
.exam-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--accent-cyan, #5ce1e6);
    text-decoration: none;
    font-size: 0.8rem;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 22px;
    opacity: 0.65;
    transition: opacity 0.2s;
}

.exam-back-btn:hover {
    opacity: 1;
}

.exam-meta {
    display: flex;
    gap: 10px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.exam-tag {
    font-size: 0.7rem;
    font-family: 'JetBrains Mono', monospace;
    padding: 4px 13px;
    border-radius: 20px;
    border: 1px solid rgba(92, 225, 230, 0.35);
    color: var(--accent-cyan, #5ce1e6);
    display: inline-flex;
    align-items: center;
}

/* ── Hero Banner ────────────────────────────────────────── */
.latex-hero {
    margin-bottom: 22px;
}

.latex-hero h1 {
    font-family: 'Playfair Display', serif;
    font-size: 1.6rem;
    color: var(--exam-title-color);
    margin: 0 0 5px 0;
}

.latex-hero p {
    font-size: 0.85rem;
    color: var(--exam-text-color);
    opacity: 0.7;
    margin: 0;
}

/* ── Extension Install Banner (Hộp Cài Đặt Tiện Ích) ──── */
.ext-install-banner, .extension-install-card {
    background: var(--exam-paper-bg);
    border: 1px solid var(--exam-paper-border);
    border-radius: 12px;
    padding: 22px 28px;
    margin-bottom: 22px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    position: relative;
    overflow: hidden;
    transition: background 0.3s, border-color 0.3s;
}

.ext-install-banner::before, .extension-install-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: linear-gradient(180deg, var(--accent-cyan), var(--accent-gold));
}

.install-info {
    flex: 1;
    min-width: 280px;
}

.ext-badge-row, .install-badge-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.ext-badge, .install-badge {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    padding: 3px 9px;
    border-radius: 4px;
    background: rgba(92, 225, 230, 0.12);
    color: var(--accent-cyan);
    border: 1px solid rgba(92, 225, 230, 0.28);
}

.install-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--exam-title-color);
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.install-desc {
    font-size: 0.86rem;
    color: var(--exam-text-color);
    opacity: 0.75;
    line-height: 1.6;
    margin: 0;
}

.install-desc kbd {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.15);
    padding: 1px 5px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    color: var(--accent-cyan);
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-download-ext {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, var(--accent-cyan) 0%, #00b4d8 100%);
    color: #0b1111;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 700;
    font-size: 0.82rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 10px 18px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(92, 225, 230, 0.35);
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-download-ext:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(92, 225, 230, 0.45);
    color: #000;
}

.btn-guide-ext {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(92, 225, 230, 0.08);
    color: var(--exam-title-color);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    padding: 9px 15px;
    border-radius: 8px;
    border: 1px solid rgba(92, 225, 230, 0.25);
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-guide-ext:hover {
    background: rgba(92, 225, 230, 0.18);
    border-color: rgba(92, 225, 230, 0.5);
    color: var(--accent-cyan);
    transform: translateY(-1px);
}

/* ── Workspace 2 Cột Đối Xứng (Studio Panes) ────────────── */
.viewer-workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 24px;
}

@media (max-width: 960px) {
    .viewer-workspace {
        grid-template-columns: 1fr;
    }
}

.viewer-pane {
    background: var(--exam-paper-bg);
    border: 1px solid var(--exam-paper-border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    transition: background 0.3s, border-color 0.3s;
}

.pane-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.18);
    border-bottom: 1px solid var(--pane-border);
}

body:not(.dark-mode) .pane-header {
    background: rgba(0, 0, 0, 0.03);
}

.pane-title {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.74rem;
    font-weight: 600;
    color: var(--accent-cyan, #5ce1e6);
    display: flex;
    align-items: center;
    gap: 8px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.pane-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pane-btn {
    background: rgba(92, 225, 230, 0.08);
    border: 1px solid rgba(92, 225, 230, 0.20);
    color: var(--exam-text-color);
    font-size: 0.72rem;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.18s ease;
    font-family: 'JetBrains Mono', monospace;
}

.pane-btn:hover {
    background: rgba(92, 225, 230, 0.20);
    border-color: rgba(92, 225, 230, 0.45);
    color: var(--accent-cyan);
}

.pane-btn.active {
    background: rgba(92, 225, 230, 0.25);
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
    font-weight: 700;
}

.pane-btn.danger:hover {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    color: #ef4444;
}

.pane-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 420px;
    position: relative;
}

#raw-input {
    width: 100%;
    height: 100%;
    min-height: 420px;
    padding: 22px 24px;
    border: none;
    outline: none;
    background: var(--input-bg);
    color: var(--exam-text-color);
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.94rem;
    line-height: 1.85;
    letter-spacing: 0.02em;
    word-spacing: 0.04em;
    resize: vertical;
    box-sizing: border-box;
}

#raw-input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

/* ── Output Views ───────────────────────────────────────── */
.output-view-panel {
    width: 100%;
    height: 100%;
    min-height: 420px;
    box-sizing: border-box;
    overflow-y: auto;
    background: var(--input-bg);
}

/* BẢNG RENDER TOÁN CHUẨN SÁCH GIÁO KHOA */
#preview-view {
    font-family: "Times New Roman", Times, serif !important;
    font-size: 1.20rem !important;
    line-height: 2.2 !important;
    letter-spacing: 0.025em !important;
    word-spacing: 0.06em !important;
    color: var(--exam-text-color, #e2e8f0);
    padding: 24px 28px;
    white-space: pre-wrap;
    word-break: break-word;
}

#preview-view .katex {
    font-size: 1.05em;
    color: inherit;
}

#preview-view .katex-display {
    margin: 1.2em 0;
    padding: 10px 0;
    overflow-x: auto;
    overflow-y: hidden;
}

#raw-view textarea {
    width: 100%;
    height: 100%;
    min-height: 420px;
    padding: 22px 24px;
    box-sizing: border-box;
    border: none;
    outline: none;
    background: transparent;
    color: var(--accent-cyan);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.92rem;
    line-height: 1.8;
    letter-spacing: 0.02em;
    resize: none;
}

/* ── Status Bar (Chân Mỗi Cột Pane) ─────────────────────── */
.status-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.12);
    border-top: 1px solid rgba(92, 225, 230, 0.08);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.72rem;
    color: var(--exam-text-color);
    opacity: 0.65;
}

body:not(.dark-mode) .status-bar {
    background: rgba(0, 0, 0, 0.02);
    border-top-color: rgba(15, 23, 42, 0.08);
}

.status-dot {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 6px;
    vertical-align: middle;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* ── Export & Actions Bar (Thanh Nút Hành Động) ──────────── */
.export-bar {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}

.export-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, rgba(92, 225, 230, 0.12), rgba(167, 139, 250, 0.12));
    border: 1px solid rgba(92, 225, 230, 0.28);
    border-radius: 9px;
    padding: 11px 20px;
    color: var(--exam-title-color);
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.78rem;
    letter-spacing: 0.8px;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.22s;
}

.export-btn:hover {
    background: linear-gradient(135deg, rgba(92, 225, 230, 0.22), rgba(167, 139, 250, 0.22));
    border-color: rgba(92, 225, 230, 0.6);
    transform: translateY(-2px);
    box-shadow: 0 5px 16px rgba(92, 225, 230, 0.12);
    color: var(--accent-cyan);
}

.export-btn.primary {
    background: linear-gradient(135deg, rgba(92, 225, 230, 0.25), rgba(92, 225, 230, 0.10));
    border-color: var(--accent-cyan);
    color: var(--accent-cyan);
}

.export-btn.purple {
    border-color: rgba(167, 139, 250, 0.3);
    color: #a78bfa;
}

.export-btn.purple:hover {
    border-color: rgba(167, 139, 250, 0.65);
    box-shadow: 0 5px 16px rgba(167, 139, 250, 0.12);
}

.export-btn.gold {
    border-color: rgba(251, 191, 36, 0.35);
    color: #fbbf24;
}

.export-btn.gold:hover {
    border-color: rgba(251, 191, 36, 0.7);
    color: #fef08a;
    box-shadow: 0 5px 16px rgba(251, 191, 36, 0.15);
}

/* ── Chân Trang & Thước Đo Thống Kê (Bottom Strip & Footer) ─ */
.exam-end {
    text-align: center;
    font-size: 0.75rem;
    color: var(--exam-text-color);
    opacity: 0.4;
    font-family: 'JetBrains Mono', monospace;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin: 40px 0 20px 0;
}


/* ── Modal Hướng Dẫn Cài Đặt ────────────────────────────── */
.guide-modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.guide-modal-backdrop.active {
    opacity: 1;
    pointer-events: auto;
}

.guide-modal {
    width: 600px;
    max-width: 90vw;
    max-height: 85vh;
    background: #14181a;
    border: 1px solid var(--pane-border);
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5), 0 0 30px rgba(92, 225, 230, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

body:not(.dark-mode) .guide-modal {
    background: #ffffff;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.15);
}

.guide-modal-backdrop.active .guide-modal {
    transform: scale(1);
}

.guide-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 22px;
    border-bottom: 1px solid var(--pane-border);
    background: rgba(0, 0, 0, 0.1);
}

body:not(.dark-mode) .guide-header {
    background: rgba(0, 0, 0, 0.02);
}

.guide-title {
    font-family: 'Playfair Display', serif;
    font-size: 1.15rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--exam-title-color);
    letter-spacing: 0.02em;
}

.guide-body {
    padding: 22px;
    overflow-y: auto;
    font-size: 0.90rem;
    line-height: 1.65;
    color: var(--exam-text-color);
}

.guide-step {
    display: flex;
    gap: 14px;
    margin-bottom: 20px;
}

.step-number {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(92, 225, 230, 0.2);
    color: var(--accent-cyan);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.88rem;
    flex-shrink: 0;
}

.step-content {
    flex: 1;
}

.step-content h4 {
    font-size: 0.98rem;
    margin-bottom: 4px;
    color: var(--exam-title-color);
    letter-spacing: 0.01em;
}

.step-content p {
    color: var(--exam-text-color);
    opacity: 0.8;
    margin-bottom: 6px;
    font-size: 0.86rem;
}

.step-code {
    display: inline-block;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    color: var(--accent-cyan);
}

.guide-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    border-top: 1px solid var(--pane-border);
    background: rgba(0, 0, 0, 0.05);
}
