﻿/* =========================================================
   AI VĂN BẢN EDITOR
   - Clean structure
   - Responsive
   - Mobile scroll fixed
========================================================= */

/* =========================
   1) RESET & BASE
========================= */
html,
body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

/* =========================
   2) PAGE LAYOUT
========================= */
.editor-page {
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: visible;
    background: linear-gradient(135deg, #fff7f7, #fef2f2);
    font-family: system-ui, -apple-system, sans-serif;
    color: #1f2937;
}

/* =========================
   3) TOP HEADER
========================= */
.editor-header {
    min-height: 38px;
    padding: 0 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: nowrap;
    background: linear-gradient(90deg, #7f1d1d, #991b1b);
    color: #fff;
    box-shadow: 0 2px 14px rgba(0, 0, 0, 0.08);
    z-index: 20;
}

.editor-header-left,
.editor-header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.editor-header h1 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    white-space: nowrap;
}

.back-btn {
    padding: 6px 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: 0.2s ease;
}

    .back-btn:hover {
        background: rgba(255, 255, 255, 0.22);
    }

.nd30-badge {
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}

/* =========================
   4) MAIN WORKSPACE
========================= */
.focus-workspace {
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: visible;
}

.focus-paper-container {
    flex: 1;
    display: flex;
    min-width: 0;
    min-height: 0;
    overflow: visible;
    background: #f8fafc;
}

/* =========================
   5) PREVIEW AREA
========================= */
.preview-container {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-width: 0;
    min-height: 0;
    padding: 14px 16px;
    overflow: visible;
    background: radial-gradient(circle at top left, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0) 35%), #eef2f7;
}

.preview-paper {
    width: 210mm;
    min-height: 297mm;
    margin: 0 0 10px;
    padding: 16mm 14mm 16mm 18mm;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.14);
    overflow: visible;
    font-family: "Times New Roman", serif;
    font-size: 12.2pt;
    line-height: 1.5;
    transform: scale(0.82);
    transform-origin: top center;
}

/* =========================
   6) RIGHT DRAWER
========================= */
.side-drawer {
    width: 360px;
    min-width: 360px;
    max-width: 360px;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(10px);
    border-left: 1px solid #f1d4d4;
    box-shadow: -8px 0 28px rgba(0, 0, 0, 0.05);
}

/* =========================
   7) DRAWER TABS
========================= */
.drawer-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    padding: 8px;
    background: #fff5f5;
    border-bottom: 1px solid #fee2e2;
    flex-shrink: 0;
}

.tab-item {
    padding: 10px 8px;
    border-radius: 12px;
    text-align: center;
    font-size: 12px;
    font-weight: 700;
    color: #7f1d1d;
    white-space: nowrap;
    user-select: none;
    cursor: pointer;
    transition: 0.2s ease;
}

    .tab-item:hover {
        background: #ffe4e6;
    }

    .tab-item.active {
        background: linear-gradient(135deg, #991b1b, #b91c1c);
        color: #fff;
        box-shadow: 0 8px 18px rgba(153, 27, 27, 0.18);
    }

/* =========================
   8) DRAWER CONTENT
========================= */
.drawer-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 14px;
    background: linear-gradient(180deg, #ffffff, #fffafa);
}

    .drawer-body h6 {
        margin-bottom: 12px !important;
        font-size: 15px;
        color: #7f1d1d;
    }

.drawer-footer {
    position: sticky;
    bottom: 0;
    z-index: 5;
    flex-shrink: 0;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid #f3f4f6;
    box-shadow: 0 -6px 18px rgba(0, 0, 0, 0.03);
}

/* =========================
   9) FORM ELEMENTS
========================= */
input,
select,
textarea,
.form-control,
.form-select {
    padding: 10px 12px !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 12px !important;
    background: #fff !important;
    font-size: 13px !important;
    transition: all 0.18s ease;
}

    input:focus,
    textarea:focus,
    select:focus,
    .form-control:focus,
    .form-select:focus {
        border-color: #991b1b !important;
        box-shadow: 0 0 0 3px rgba(153, 27, 27, 0.1) !important;
    }

    textarea.form-control {
        min-height: 110px;
        max-height: 220px;
        resize: vertical;
        overflow-y: auto;
    }

label,
.form-label {
    margin-bottom: 5px;
    font-size: 13px;
    font-weight: 700;
    color: #374151;
}

.mb-3 {
    margin-bottom: 0.8rem !important;
}

.mb-2 {
    margin-bottom: 0.55rem !important;
}

/* =========================
   10) BUTTONS
========================= */
.btn {
    padding: 9px 14px;
    border: none;
    border-radius: 12px !important;
    font-size: 13px;
    font-weight: 700;
    transition: 0.18s ease;
}

    .btn:hover {
        transform: translateY(-1px);
    }

.btn-primary {
    background: linear-gradient(135deg, #991b1b, #b91c1c);
    color: #fff;
}

    .btn-primary:hover {
        background: linear-gradient(135deg, #7f1d1d, #991b1b);
    }

.btn-success {
    background: linear-gradient(135deg, #16a34a, #15803d);
    color: #fff;
}

    .btn-success:hover {
        filter: brightness(0.97);
    }

.btn-outline-secondary {
    border: 1px solid #d1d5db !important;
    background: #fff !important;
    color: #374151 !important;
}

/* =========================
   11) UPLOAD BOX
========================= */
.upload-box {
    display: block;
    padding: 12px;
    border: 1px dashed #fca5a5;
    border-radius: 12px;
    background: #fff5f5;
    text-align: center;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s ease;
}

    .upload-box:hover {
        background: #ffe4e6;
        border-color: #fb7185;
    }

/* =========================
   12) PAPER CONTENT
========================= */
.preview-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    width: 100%;
    margin-bottom: 8px;
    font-size: 11.4pt;
    line-height: 1.35;
}

.header-col {
    min-width: 0;
    text-align: center;
    overflow: visible;
}

.left-col {
    flex: 0 0 42%;
    max-width: 42%;
}

.right-col {
    flex: 0 0 58%;
    max-width: 58%;
}

.header-nowrap,
.header-line-nowrap {
    text-align: center;
    white-space: nowrap !important;
    word-break: keep-all !important;
    overflow-wrap: normal !important;
}

.header-nowrap {
    font-size: 10.8pt;
}

.header-line-nowrap {
    font-size: 10.5pt;
}

.gach-ngang,
.gach-ngang-dai,
.gach-ngang-trich-yeu {
    margin: 5px auto 7px;
    border-bottom: 1px solid #000;
}

.gach-ngang {
    width: 82px;
}

.gach-ngang-dai {
    width: 155px;
}

.gach-ngang-trich-yeu {
    width: 105px;
}

.noi-dung-render p {
    margin-bottom: 8px;
    text-align: justify;
}

.noi-dung-render ul {
    padding-left: 20px;
}

.noi-dung-render li {
    margin-bottom: 5px;
}

.generating-overlay {
    position: relative;
    opacity: 0.96;
}

/* =========================
   13) CUSTOM SCROLLBAR
========================= */
.preview-container::-webkit-scrollbar,
.drawer-body::-webkit-scrollbar,
textarea::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

.preview-container::-webkit-scrollbar-thumb,
.drawer-body::-webkit-scrollbar-thumb,
textarea::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 999px;
}

    .preview-container::-webkit-scrollbar-thumb:hover,
    .drawer-body::-webkit-scrollbar-thumb:hover,
    textarea::-webkit-scrollbar-thumb:hover {
        background: #9ca3af;
    }

/* =========================
   14) LARGE LAPTOP
========================= */
@media (max-width: 1400px) {
    .side-drawer {
        width: 340px;
        min-width: 340px;
        max-width: 340px;
    }

    .preview-paper {
        transform: scale(0.84);
        margin-bottom: -62px;
    }
}

/* =========================
   15) TABLET LANDSCAPE
========================= */
@media (max-width: 1200px) {
    .side-drawer {
        width: 320px;
        min-width: 320px;
        max-width: 320px;
    }

    .preview-container {
        padding: 10px;
    }

    .preview-paper {
        transform: scale(0.78);
        margin-bottom: -110px;
    }
}

/* =========================
   16) TABLET
========================= */
@media (max-width: 992px) {
    .focus-paper-container {
        flex-direction: column;
    }

    .preview-container {
        flex: 1 1 auto;
        padding: 10px;
    }

    .preview-paper {
        width: min(210mm, 100%);
        min-height: auto;
        transform: scale(0.94);
        margin-bottom: -18px;
        border-radius: 10px;
    }

    .side-drawer {
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        height: 42vh;
        border-top: 1px solid #f1d4d4;
        border-left: none;
        box-shadow: 0 -8px 20px rgba(0, 0, 0, 0.04);
    }

    .drawer-body,
    .drawer-footer {
        padding-left: 12px;
        padding-right: 12px;
    }
}

/* =========================
   17) MOBILE
========================= */
@media (max-width: 768px) {
    .editor-header {
        min-height: 56px;
        padding: 10px 12px;
        flex-wrap: wrap;
        align-items: center;
        gap: 8px;
    }

    .editor-header-left,
    .editor-header-right {
        width: 100%;
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .editor-header h1 {
        font-size: 14px;
        line-height: 1.25;
        white-space: normal;
    }

    .back-btn,
    .editor-header .btn,
    .nd30-badge {
        padding: 7px 10px;
        font-size: 11px;
    }

    .preview-container {
        padding: 8px;
        align-items: flex-start;
    }

    .preview-paper {
        width: 100%;
        min-height: auto;
        margin-bottom: 0;
        padding: 12mm 10mm 14mm 12mm;
        border-radius: 8px;
        font-size: 11.6pt;
        transform: none;
    }

    .preview-header-row {
        gap: 8px;
        font-size: 10.5pt;
    }

    .header-nowrap {
        font-size: 9.3pt;
    }

    .header-line-nowrap {
        font-size: 9pt;
    }

    .gach-ngang {
        width: 68px;
    }

    .gach-ngang-dai {
        width: 128px;
    }

    .gach-ngang-trich-yeu {
        width: 90px;
    }

    .side-drawer {
        height: 46vh;
    }

    .drawer-tabs {
        gap: 5px;
        padding: 6px;
    }

    .tab-item {
        padding: 9px 6px;
        border-radius: 10px;
        font-size: 11px;
    }

    .drawer-body,
    .drawer-footer {
        padding: 10px;
    }

    textarea.form-control {
        min-height: 96px;
        max-height: 180px;
    }

    .btn {
        padding: 10px 12px;
        font-size: 13px;
    }

    /* Fix scroll mobile */
    .editor-page,
    .focus-workspace,
    .focus-paper-container,
    .preview-container,
    .preview-paper {
        height: auto !important;
        min-height: auto !important;
        overflow: visible !important;
    }
}
