/* ═══════════════════════════════════════════════════════════════
   K&G Official Document & Business Letter Design System
   주식회사 케앤지 공식 공문 / 업무협조전 스타일시트
   ═══════════════════════════════════════════════════════════════ */

:root {
    --primary-color: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --slate-900: #0f172a;
    --slate-800: #1e293b;
    --slate-700: #334155;
    --slate-600: #475569;
    --slate-500: #64748b;
    --slate-400: #94a3b8;
    --slate-300: #cbd5e1;
    --slate-200: #e2e8f0;
    --slate-100: #f1f5f9;
    --slate-50: #f8fafc;
    --border-color: #cbd5e1;
    --danger-color: #ef4444;
    --success-color: #10b981;
    --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    --a4-shadow: 0 10px 25px -5px rgba(15, 23, 42, 0.14), 0 8px 10px -6px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
    background-color: #f1f5f9;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, system-ui, Roboto, 'Helvetica Neue', 'Segoe UI', 'Apple SD Gothic Neo', 'Noto Sans KR', 'Malgun Gothic', sans-serif;
    color: var(--slate-800);
    font-size: 13px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── 1. Top ERP Header & Toolbar ── */
.app-header {
    background: #ffffff;
    border-bottom: 1px solid var(--border-color);
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    z-index: 100;
    height: 52px;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.brand-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 15px;
    font-weight: 700;
    color: var(--slate-900);
}

.brand-badge i {
    font-size: 20px;
    color: var(--primary-color);
}

.nav-tabs-custom {
    display: flex;
    background: var(--slate-100);
    border-radius: 6px;
    padding: 3px;
    gap: 2px;
}

.nav-tab-btn {
    border: none;
    background: transparent;
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: var(--slate-600);
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
}

.nav-tab-btn:hover {
    color: var(--slate-900);
}

.nav-tab-btn.active {
    background: #ffffff;
    color: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.btn-custom {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 14px;
    font-size: 12.5px;
    font-weight: 600;
    border-radius: 5px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn-custom i {
    font-size: 15px;
}

.btn-primary-custom {
    background-color: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
}
.btn-primary-custom:hover {
    background-color: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-custom {
    background-color: #ffffff;
    color: var(--slate-700);
    border-color: var(--border-color);
}
.btn-outline-custom:hover {
    background-color: var(--slate-50);
    border-color: var(--slate-400);
    color: var(--slate-900);
}

/* ── 2. Main Dual Layout (Editor + Live Preview) ── */
.main-wrapper {
    padding: 12px 16px;
    max-width: 1760px;
    margin: 0 auto;
    height: calc(100vh - 52px);
    box-sizing: border-box;
}

.split-layout {
    display: grid;
    grid-template-columns: minmax(440px, 46%) 1fr;
    gap: 16px;
    height: 100%;
    align-items: stretch;
}

@media (max-width: 1100px) {
    html, body {
        overflow: auto;
        height: auto;
    }
    .main-wrapper {
        height: auto;
    }
    .split-layout {
        grid-template-columns: 1fr;
        height: auto;
    }
}

/* ── 3. Left Panel: Editor Form (독립 스크롤) ── */
.editor-panel {
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.panel-header {
    background: var(--slate-50);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.panel-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--slate-800);
    display: flex;
    align-items: center;
    gap: 6px;
}

.preset-selector {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preset-select {
    padding: 4px 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
    background: #ffffff;
    outline: none;
    cursor: pointer;
}
.preset-select:focus {
    border-color: var(--primary-color);
}

.editor-panel .panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.form-section-title {
    font-size: 11.5px;
    font-weight: 700;
    color: var(--slate-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 5px;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 12px;
}

.form-group {
    margin-bottom: 12px;
}

.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
    margin-bottom: 4px;
}

.form-control-custom {
    width: 100%;
    padding: 7px 10px;
    font-size: 12.5px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    outline: none;
    color: var(--slate-800);
    background-color: #ffffff;
    transition: border-color 0.15s;
    font-family: inherit;
}

.form-control-custom:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

.user-tag {
    font-size: 11px;
    color: var(--primary-dark);
    background: var(--primary-light);
    padding: 2px 6px;
    border-radius: 3px;
    margin-left: 6px;
    font-weight: 500;
}

/* Quick Insertion Bar */
.quick-insert-bar {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
    background: var(--slate-50);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    padding: 5px 8px;
}

.quick-btn {
    border: 1px solid var(--border-color);
    background: #ffffff;
    font-size: 11px;
    font-weight: 600;
    color: var(--slate-700);
    padding: 2px 7px;
    border-radius: 3px;
    cursor: pointer;
    transition: all 0.1s;
}

.quick-btn:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-color: #93c5fd;
}

.textarea-body {
    width: 100%;
    min-height: 260px;
    padding: 10px;
    font-size: 12.5px;
    line-height: 1.6;
    border: 1px solid var(--border-color);
    border-radius: 0 0 4px 4px;
    outline: none;
    color: var(--slate-900);
    resize: vertical;
    font-family: 'Consolas', 'Pretendard', monospace;
}

.textarea-body:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
}

/* ── 4. Right Panel: Real-time Live A4 Preview ── */
.preview-panel {
    background: #cbd5e1;
    border-radius: 8px;
    padding: 12px 14px 40px;
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow-y: auto;
    position: relative;
    border: 1px solid var(--border-color);
}

.preview-toolbar {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 14px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(4px);
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid rgba(203, 213, 225, 0.8);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.preview-status {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
    display: flex;
    align-items: center;
    gap: 6px;
}

.preview-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Zoom Controls */
.zoom-btn-group {
    display: inline-flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    overflow: hidden;
}

.zoom-btn {
    border: none;
    background: transparent;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--slate-600);
    cursor: pointer;
    transition: background 0.15s;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.zoom-btn:hover {
    background: var(--slate-100);
    color: var(--slate-900);
}

.zoom-btn.active {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.zoom-level {
    font-size: 11px;
    font-weight: 700;
    color: var(--slate-800);
    padding: 0 4px;
    min-width: 32px;
    text-align: center;
}

/* Page Fit Warning Badge */
.page-fit-badge {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.page-fit-badge.fit-ok {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.page-fit-badge.fit-warn {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.toggle-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--slate-700);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    user-select: none;
    background: #ffffff;
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

/* ── 5. Standard A4 Paper Viewport & Multi-Sheet Container ── */
.a4-preview-viewport {
    width: 100%;
    display: flex;
    justify-content: center;
    padding-bottom: 50px;
    overflow-x: auto;
}

.a4-zoom-wrapper {
    transform-origin: top center;
    transition: transform 0.15s ease-out;
}

.a4-pages-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 28px;
}

/* Page Separator Tag in screen preview */
.page-divider-bar {
    width: 210mm;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 14px;
    background: #e2e8f0;
    color: #334155;
    font-size: 11px;
    font-weight: 700;
    border-radius: 6px;
    border: 1px dashed #94a3b8;
    user-select: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.page-divider-bar i {
    font-size: 15px;
    margin-right: 6px;
    color: var(--primary-color);
}

/* Discrete A4 Paper Sheet */
.a4-sheet {
    width: 210mm;
    height: 297mm;
    min-height: 297mm;
    max-height: 297mm;
    background: #ffffff;
    box-shadow: var(--a4-shadow);
    padding: 15mm 20mm 15mm 20mm;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: relative;
    color: #111827;
    line-height: 1.6;
    overflow: hidden;
}

/* A4 Company Letterhead Header (Executive Global Corporate Identity) */
.letterhead-header {
    border-bottom: 1px solid #cbd5e1;
    padding-bottom: 10px;
    margin-bottom: 16px;
    position: relative;
}

.letterhead-header::after {
    display: none;
}

.letterhead-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Brand Group: Logo + Architectural Vertical Divider + Company Names */
.letterhead-brand {
    display: flex;
    align-items: center;
}

.letterhead-logo {
    max-height: 40px;
    max-width: 130px;
    height: auto;
    object-fit: contain;
    display: block;
}

.letterhead-logo-fallback {
    font-size: 17px;
    font-weight: 900;
    color: #1e3a8a;
    letter-spacing: -0.5px;
    border: 1.5px solid #1e3a8a;
    padding: 2px 8px;
    border-radius: 4px;
}

.letterhead-brand-divider {
    width: 1px;
    height: 30px;
    background-color: #cbd5e1;
    margin: 0 14px;
    flex-shrink: 0;
}

.letterhead-name-group {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.letterhead-corp-kr {
    font-size: 15.5px;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.3px;
    line-height: 1.25;
}

.letterhead-corp-en {
    font-size: 8.5px;
    font-weight: 700;
    color: #64748b;
    letter-spacing: 1.6px;
    text-transform: uppercase;
    margin-top: 2px;
}

/* Right Side: Clean Structured Corporate Contact Block */
.letterhead-contact {
    text-align: right;
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.letterhead-contact-line {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    font-size: 10.5px;
    color: #334155;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.contact-chip {
    display: inline-flex;
    align-items: center;
}

.chip-lbl {
    font-size: 8px;
    font-weight: 800;
    color: #1e3a8a;
    background: #f1f5f9;
    padding: 1px 4.5px;
    border-radius: 3px;
    letter-spacing: 0.5px;
    margin-right: 4px;
    text-transform: uppercase;
}

.contact-sep {
    color: #cbd5e1;
    margin: 0 8px;
    font-weight: 300;
}

.letterhead-contact-addr {
    font-size: 9.5px;
    color: #64748b;
    font-weight: 400;
    letter-spacing: -0.2px;
}

/* Document Title (Optional Central Title) */
.doc-title-wrapper {
    text-align: center;
    margin: 10px 0 16px;
}

.doc-main-title {
    font-size: 19px;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: 2.5px;
    display: inline-block;
    padding: 0 14px 6px;
    border-bottom: 1.5px solid #0f172a;
    margin: 0;
}

/* Document Meta Container (Executive Open Clean Grid) */
.doc-meta-container {
    border-top: 1px solid #cbd5e1;
    border-bottom: 1.5px solid #0f172a;
    background: transparent;
    padding: 10px 2px 12px;
    margin-bottom: 18px;
}

.doc-meta-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.doc-meta-table td {
    padding: 3px 4px;
    vertical-align: top;
}

.doc-meta-table .meta-label {
    width: 62px;
    font-weight: 700;
    color: #475569;
    white-space: nowrap;
    letter-spacing: 1.5px;
    font-size: 12px;
}

.doc-meta-table .meta-colon {
    width: 14px;
    text-align: center;
    font-weight: 400;
    color: #94a3b8;
}

.doc-meta-table .meta-val {
    color: #0f172a;
    font-weight: 500;
    font-size: 12px;
    line-height: 1.55;
}

.doc-meta-table .doc-subject-val {
    font-weight: 800;
    color: #0f172a;
    font-size: 12.5px;
    letter-spacing: -0.2px;
}

.meta-divider {
    display: none;
}

/* Document Body Content */
.doc-body-content {
    font-size: 12px;
    line-height: 1.75;
    color: #1e293b;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: inherit;
}

/* Attached Items & Postscript */
.doc-attach-box {
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px dashed #cbd5e1;
    font-size: 11.5px;
    color: #334155;
    line-height: 1.65;
    white-space: pre-wrap;
}

/* Document Bottom Closing Sign-off */
.doc-closing-area {
    margin-top: 24px;
    text-align: right;
    position: relative;
    padding-right: 20px;
}

.doc-sign-text {
    font-size: 14px;
    font-weight: 700;
    color: #0f172a;
    letter-spacing: 0.5px;
    display: inline-block;
    position: relative;
}

.doc-seal-img {
    position: absolute;
    right: -45px;
    top: -14px;
    width: 60px;
    height: 60px;
    object-fit: contain;
    mix-blend-mode: multiply;
    pointer-events: none;
}

/* A4 Footer Info & Page Numbering */
.a4-footer {
    border-top: 1px solid var(--slate-200);
    padding-top: 6px;
    margin-top: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 9.5px;
    color: var(--slate-500);
}

.footer-page-num {
    font-weight: 700;
    color: var(--slate-700);
    font-size: 10.5px;
    letter-spacing: 1px;
}

/* ── 6. Archive View (공문 보관함 / 발송대장) ── */
.archive-wrapper {
    display: none;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--card-shadow);
    padding: 20px;
    height: 100%;
    overflow-y: auto;
}

.archive-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.archive-search-box {
    display: flex;
    gap: 8px;
    align-items: center;
}

.archive-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12.5px;
}

.archive-table th {
    background: var(--slate-50);
    padding: 10px;
    border-bottom: 2px solid var(--border-color);
    font-weight: 700;
    color: var(--slate-700);
    text-align: left;
}

.archive-table td {
    padding: 10px;
    border-bottom: 1px solid var(--slate-200);
    color: var(--slate-800);
    vertical-align: middle;
}

.archive-table tr:hover td {
    background-color: var(--slate-50);
}

.badge-tag {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--slate-100);
    color: var(--slate-700);
}

/* ── 7. Settings Modal ── */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    z-index: 999;
    align-items: center;
    justify-content: center;
}

.modal-overlay.active {
    display: flex;
}

.modal-card {
    background: #ffffff;
    border-radius: 8px;
    width: 520px;
    max-width: 92vw;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2);
    overflow: hidden;
}

.modal-header-custom {
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--slate-50);
}

.modal-header-custom h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--slate-800);
}

.modal-body-custom {
    padding: 18px;
}

.modal-footer-custom {
    padding: 12px 18px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    background: var(--slate-50);
}

/* ── 8. Printing Styles (@media print) ── */
@media print {
    @page {
        size: A4 portrait;
        margin: 0 !important;
    }

    body, html {
        background: #ffffff !important;
        margin: 0 !important;
        padding: 0 !important;
        width: 210mm !important;
        height: auto !important;
        overflow: visible !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide everything except A4 sheets */
    .app-header,
    .editor-panel,
    .preview-toolbar,
    .archive-wrapper,
    .modal-overlay,
    .page-divider-bar,
    .no-print {
        display: none !important;
        height: 0 !important;
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
    }

    .main-wrapper,
    .split-layout,
    .preview-panel,
    .a4-preview-viewport,
    .a4-zoom-wrapper,
    .a4-pages-container {
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 210mm !important;
        max-width: 210mm !important;
        min-height: auto !important;
        max-height: none !important;
        border: none !important;
        background: transparent !important;
        box-shadow: none !important;
        transform: none !important;
        overflow: visible !important;
    }

    .a4-sheet {
        width: 210mm !important;
        height: 297mm !important;
        min-height: 297mm !important;
        max-height: 297mm !important;
        box-sizing: border-box !important;
        padding: 15mm 20mm !important;
        margin: 0 !important;
        background: #ffffff !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        box-shadow: none !important;
        border: none !important;
        overflow: hidden !important;
        page-break-before: auto !important;
        page-break-after: always !important;
        break-after: page !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .a4-sheet:last-child {
        page-break-after: auto !important;
        break-after: auto !important;
    }

    .a4-content-top,
    .a4-content-bottom,
    .letterhead-header,
    .doc-meta-container,
    .doc-closing-area,
    .a4-footer {
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .letterhead-header {
        border-bottom: 1px solid #cbd5e1 !important;
    }

    .letterhead-header::after {
        display: none !important;
    }

    .letterhead-brand-divider {
        background: #cbd5e1 !important;
    }

    .chip-lbl {
        background: #f1f5f9 !important;
        color: #1e3a8a !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .doc-meta-container {
        border-top: 1px solid #cbd5e1 !important;
        border-bottom: 1.5px solid #0f172a !important;
        border-left: none !important;
        border-right: none !important;
        background: transparent !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .doc-main-title {
        border-bottom: 1.5px solid #0f172a !important;
        color: #0f172a !important;
    }

    .doc-seal-img {
        mix-blend-mode: normal !important;
    }
}
