/* ========================================================
   배송 경로 PRO - 통합 관리자 센터 공통 스타일 (css/admin.css)
   ======================================================== */

/* 1. 지도 컨테이너 및 카카오맵 오버레이/핀 */
#territory-map-container, 
#all-territories-map-container { 
    width: 100% !important; 
    height: 100% !important; 
    min-height: 400px; 
}

.custom-overlay { 
    background: #2563eb; 
    color: white; 
    padding: 3px 7px; 
    border-radius: 9999px; 
    font-size: 11px; 
    font-weight: 800; 
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.25); 
    border: 2px solid white; 
    white-space: nowrap; 
    transition: all 0.2s; 
    cursor: pointer; 
}

.custom-overlay.completed { 
    background: #059669; 
    border-color: #d1fae5; 
}

.custom-overlay.current { 
    background: #ea580c; 
    border-color: #fef08a; 
    animation: pulse 2s infinite; 
}

.driver-pin { 
    background: #0f172a; 
    color: #f8fafc; 
    border: 2px solid #38bdf8; 
    padding: 5px 10px; 
    border-radius: 12px; 
    font-weight: 900; 
    font-size: 11px; 
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35); 
    transition: all 0.2s; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    gap: 6px; 
}

.driver-pin:hover { 
    transform: translateY(-3px) scale(1.08); 
    background: #0284c7; 
    border-color: #ffffff; 
    color: #ffffff; 
    box-shadow: 0 10px 20px rgba(2, 132, 199, 0.4); 
}

/* 2. 스크롤바 제어 스타일 */
.hide-scrollbar::-webkit-scrollbar { 
    display: none; 
}
.hide-scrollbar { 
    -ms-overflow-style: none; 
    scrollbar-width: none; 
}

.custom-scrollbar::-webkit-scrollbar { 
    height: 8px; 
    width: 8px; 
}
.custom-scrollbar::-webkit-scrollbar-track { 
    background: #f1f5f9; 
    border-radius: 4px; 
}
.custom-scrollbar::-webkit-scrollbar-thumb { 
    background: #94a3b8; 
    border-radius: 4px; 
}
.custom-scrollbar::-webkit-scrollbar-thumb:hover { 
    background: #64748b; 
}

/* 3. 테이블 및 공통 인터랙션 스타일 */
.sortable-th { 
    cursor: pointer; 
    user-select: none; 
    transition: background-color 0.15s; 
    white-space: nowrap; 
}
.sortable-th:hover { 
    background-color: #e2e8f0; 
}

.excel-table th { 
    background-color: #f8fafc; 
    position: sticky; 
    top: 0; 
    z-index: 10; 
    box-shadow: inset 0 -1px 0 #e2e8f0; 
}
.excel-table td, 
.excel-table th { 
    border: 1px solid #e2e8f0; 
    padding: 0.5rem 0.75rem; 
    font-size: 11px; 
}
.excel-table tr:hover td { 
    background-color: #eef2ff; 
}

/* 4. 애니메이션 효과 */
@keyframes popIn {
    0% { transform: translate(-50%, -85%) scale(0.9); opacity: 0; }
    100% { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}
.animate-pop-in { 
    animation: popIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards; 
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-slide-up { 
    animation: slideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards; 
}

/* 5. 주문서 거래명세표(A4 규격) 전용 레이아웃 */
.invoice-container { 
    background-color: white; 
    border: 1px solid #d1d5db; 
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15); 
    width: 210mm; 
    height: 296mm; 
    margin: 0 auto; 
    position: relative; 
    display: flex; 
    flex-direction: column; 
    box-sizing: border-box; 
    overflow: hidden; 
    flex-shrink: 0; 
}

.invoice-half { 
    height: 148mm; 
    background-color: #ffeb5c !important; 
    padding: 5mm 8mm; 
    box-sizing: border-box; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
    -webkit-print-color-adjust: exact; 
    print-color-adjust: exact; 
}

.invoice-cut-line { 
    border-top: 1px dashed #6b7280; 
    width: 100%; 
    margin: 0; 
}

.invoice-title { 
    text-align: center; 
    font-size: 21px; 
    font-weight: 900; 
    letter-spacing: 6px; 
    text-decoration: underline; 
    margin-bottom: 5px; 
    color: #000; 
    font-family: 'Malgun Gothic', 'Dotum', sans-serif; 
}

.invoice-table { 
    width: 100%; 
    border-collapse: collapse; 
    border: 2px solid #000; 
    font-size: 10px; 
    margin-bottom: 4px; 
    table-layout: fixed; 
    color: #000; 
    font-family: 'Malgun Gothic', 'Dotum', sans-serif; 
}

.invoice-table th, 
.invoice-table td { 
    border: 1px solid #000; 
    padding: 2px 5px; 
    height: 27px; 
    vertical-align: middle; 
    overflow: hidden; 
}

.double-height { 
    height: 54px !important; 
}
.double-height td { 
    height: 54px !important; 
}

.multi-line-text { 
    white-space: normal !important; 
    word-break: break-all; 
    line-height: 1.3; 
}

.invoice-label { 
    background-color: transparent; 
    font-weight: bold; 
    text-align: center; 
    white-space: nowrap; 
    letter-spacing: -0.2px; 
}

.writing-mode-vertical { 
    writing-mode: vertical-rl; 
    text-orientation: upright; 
    text-align: center; 
    letter-spacing: 3px; 
    padding: 2px !important; 
}

.text-fit-auto { 
    font-size: 9.5px; 
    letter-spacing: -0.3px; 
    white-space: nowrap; 
    overflow: hidden; 
    text-overflow: ellipsis; 
}

.inv-text-center { text-align: center; }
.inv-text-left { text-align: left; padding-left: 6px !important; }
.inv-text-right { text-align: right; padding-right: 6px !important; }
.inv-font-bold { font-weight: bold; }

/* 6. 워드형 웹 문서 서식 에디터 (doc-editor) 전용 스타일 */
.doc-editor-toolbar { 
    user-select: none; 
    z-index: 20; 
}

.doc-canvas-paper { 
    width: 210mm; 
    min-height: 297mm; 
    background: #ffffff; 
    margin: 0 auto; 
    padding: 12mm 15mm; 
    box-sizing: border-box; 
    border-radius: 6px; 
}

.doc-sheet { 
    width: 100%; 
    background: #ffffff; 
    color: #111827; 
    font-family: 'Malgun Gothic', 'Dotum', sans-serif; 
}

.doc-header { 
    text-align: center; 
    margin-bottom: 12px; 
}

.doc-main-title { 
    font-size: 24px; 
    font-weight: 900; 
    letter-spacing: 6px; 
    text-decoration: underline; 
    margin-bottom: 6px; 
    outline: none; 
}

.doc-main-title:focus { 
    background-color: #e0e7ff; 
    border-radius: 4px; 
}

.doc-meta-row { 
    display: flex; 
    justify-content: space-between; 
    font-size: 11px; 
    font-weight: bold; 
    color: #374151; 
    margin-bottom: 6px; 
}

.doc-table { 
    width: 100%; 
    border-collapse: collapse; 
    border: 2px solid #000; 
    font-size: 11px; 
    table-layout: fixed; 
    margin-bottom: 6px; 
    color: #000; 
}

.doc-table th, 
.doc-table td { 
    border: 1px solid #000; 
    padding: 5px 6px; 
    vertical-align: middle; 
    line-height: 1.3; 
}

.doc-table th { 
    background: #f1f5f9; 
    text-align: center; 
    font-weight: bold; 
    color: #111827; 
}

.vertical-header { 
    text-align: center; 
    line-height: 1.3; 
    letter-spacing: 2px; 
    font-weight: 900; 
}

/* 워드형 편집 영역 포커스 효과 */
[contenteditable="true"] { 
    outline: none; 
    transition: background-color 0.15s; 
}

[contenteditable="true"]:hover { 
    background-color: #f8fafc; 
    cursor: text; 
}

[contenteditable="true"]:focus { 
    background-color: #eff6ff !important; 
    box-shadow: inset 0 0 0 1px #3b82f6; 
    border-radius: 2px; 
}

.doc-sign-area { 
    text-align: right; 
    font-size: 11px; 
    font-weight: bold; 
    margin-top: 16px; 
}

/* 7. 인쇄 모드 최적화 (A4 Portrait) */
@media print {
    @page { 
        size: A4 portrait; 
        margin: 0; 
    }
    body, html { 
        margin: 0; 
        padding: 0; 
        width: 100%; 
        height: 100%; 
        background: white; 
    }
    .invoice-container { 
        box-shadow: none !important; 
        border: none !important; 
        margin: 0 !important; 
        page-break-after: always; 
        width: 210mm; 
        height: 296mm; 
    }
    .invoice-half { 
        height: 148mm; 
        page-break-inside: avoid; 
    }

    /* 인쇄 시 에디터 툴바, 안내 화면 완전 숨김 */
    .doc-editor-toolbar,
    #preview-placeholder { 
        display: none !important; 
    }

    .print-page-wrapper { 
        page-break-after: always; 
        width: 210mm; 
        height: 297mm; 
        padding: 8mm 10mm; 
        box-sizing: border-box; 
    }
    .print-page-wrapper:last-child { 
        page-break-after: auto; 
    }
    .driver-marking-bar { 
        -webkit-print-color-adjust: exact; 
        print-color-adjust: exact; 
    }
}
/* 메시지 센터: 기능과 선택 상태를 유지하는 전용 레이아웃 */
#message-section { background: #f2f5fa; gap: 18px; padding: 22px; }
#message-section .message-main { border-color: #dfe6ef; box-shadow: 0 8px 30px #16335808; }
#message-section .message-toolbar { padding: 14px 20px; border-color: #edf0f5; }
#message-section .message-toolbar:first-of-type { background: #fff; }
#message-section [role="group"] { background: #edf2f8; padding: 4px; border-radius: 14px; gap: 4px; }
#message-section [role="group"] button { padding: 10px 16px; border-radius: 10px; font-size: 13px; font-weight: 800; transition: background .15s; }
#message-section [role="group"] button span { font-size: 11px; font-weight: 500; }
#message-section [role="group"] button[aria-pressed="true"] { background: #245fe8; color: #fff; box-shadow: 0 3px 8px #245fe82b; }
#message-section [data-dispatch-sound] { margin-left: auto; border-radius: 10px; color: #475569; background: #fff; }
#message-section [data-dispatch-sound][aria-pressed="false"] { background: #f1f5f9; color: #64748b; }
#message-section .message-toolbar label { display: flex; align-items: center; gap: 5px; color: #64748b; }
#message-section input[type="date"] { padding: 7px; border: 1px solid #dce3ed; border-radius: 8px; background: #fff; color: #334155; }
#message-section .message-clear { margin-left: auto; padding: 8px 11px; border: 1px solid #fecdd3; border-radius: 9px; color: #be123c; background: #fff7f8; font-weight: 700; }
#message-section #dispatch-message-feed { min-height: 140px; background: #f7f9fc; padding: 22px; }
#message-section #dispatch-message-feed > div { border-radius: 16px; }
#message-section #message-input { min-height: 78px; font-size: 13px; line-height: 1.7; }
#message-section #btn-send-message { border-radius: 11px; }
#message-section .message-templates { width: 290px; border-color: #dfe6ef; box-shadow: none; }
#message-section button:focus-visible { outline: 3px solid #93b4ff; outline-offset: 2px; }
@media (max-width: 1400px) {
    #message-section { flex-wrap: wrap; overflow-y: auto; padding: 14px; }
    #message-section .message-main { flex: 1 0 100%; height: min(780px, 90vh); }
    #message-section .message-templates { width: 100%; height: auto; min-height: 260px; }
}

/* 통합 마스터 센터: 기기 종류 대신 사용 가능한 화면 폭에 맞춘 배치.
   다른 관리자/관제 화면에는 적용하지 않는다. */
body.master-center { width: 100%; height: 100vh; height: 100dvh; }
.master-center #master-panel, .master-center .master-main,
.master-center .master-tabs-panel, .master-center [id^="tab-content-"],
.master-center #account-history-main-content { min-width: 0; min-height: 0; }
.master-center .master-main { overscroll-behavior: contain; }
.master-center .master-actions { flex-wrap: wrap; }
.master-center > [id$="-modal"] { padding: 16px; }
.master-center > [id$="-modal"] > div {
    min-width: 0;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow-y: auto;
    overscroll-behavior: contain;
}
.master-center > [id$="-modal"] .flex-1 { min-height: 0; min-width: 0; }
.master-center #photo-preview-modal img { max-height: 60dvh; }
.master-center button:focus-visible, .master-center a:focus-visible {
    outline: 3px solid #60a5fa;
    outline-offset: 2px;
}

@media screen and (max-width: 1199px) {
    .master-center .master-header { padding: 16px 20px; gap: 16px; flex-wrap: wrap; }
    .master-center .master-main { padding: 20px; }
    .master-center .master-toolbar { align-items: stretch; }
    .master-center .master-actions { width: 100%; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .master-center .master-actions button { justify-content: center; }
    .master-center .master-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .master-center .master-tabs > button { min-width: 0; }
    .master-center #history-top-filter-bar > div { width: 100%; }
    .master-center #history-type-filter-group { flex-wrap: wrap; }
    .master-center #account-back-bar { flex-wrap: wrap; gap: 12px; }
    .master-center #account-profile-card .flex { flex-wrap: wrap; }
    .master-center #account-profile-card span { overflow-wrap: anywhere; }
    .master-center #tab-content-blocked input { min-width: 0; max-width: 100%; }
}

@media screen and (max-width: 767px) {
    .master-center .master-header { padding: 12px; gap: 12px; }
    .master-center .master-header > div { min-width: 0; }
    .master-center .master-header > div:last-child { width: 100%; justify-content: space-between; gap: 8px; }
    .master-center .master-header a { display: inline-flex; align-items: center; }
    .master-center .master-header h1 { flex-wrap: wrap; line-height: 1.4; }
    .master-center .master-header img { width: 64px !important; }
    .master-center .master-main { padding: 12px; }
    .master-center .master-toolbar { padding: 16px; }
    .master-center .master-actions { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .master-center .master-actions button { padding: 10px 8px; }
    .master-center .master-tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .master-center button, .master-center input:not([type="checkbox"]):not([type="hidden"]),
    .master-center select, .master-center a { min-height: 44px; }
    .master-center input:not([type="checkbox"]), .master-center select, .master-center textarea {
        min-width: 0; max-width: 100%; font-size: 16px;
    }
    .master-center input[type="checkbox"] { flex-shrink: 0; }
    .master-center #tab-content-history, .master-center #tab-content-blocked { padding: 12px; }
    .master-center #history-top-filter-bar { padding: 12px; }
    .master-center #history-top-filter-bar > div > div { width: 100%; min-width: 0; }
    .master-center #history-driver-search, .master-center #history-driver-select { width: 100%; min-width: 0; }
    .master-center #history-type-filter-group { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .master-center #history-type-filter-group button { padding: 8px 4px; }
    .master-center #account-back-bar, .master-center #account-profile-card { padding: 12px; }
    .master-center #account-profile-card > div > div { min-width: 0; max-width: 100%; }
    .master-center #account-profile-card .shrink-0 { flex-shrink: 1; }
    .master-center #history-notice-send-bar > div:first-child { flex-wrap: wrap; gap: 8px; }
    .master-center #account-history-main-content > .flex { flex-wrap: wrap; }
    .master-center #account-history-main-content > .flex > button { flex: 1 1 40%; }
    .master-center #account-history-main-content .justify-between { flex-wrap: wrap; gap: 8px; }
    .master-center #account-history-main-content .truncate { white-space: normal; overflow-wrap: anywhere; }
    .master-center #account-history-main-content .shrink-0 { flex-wrap: wrap; }
    .master-center [id^="pagination-"] > div,
    .master-center [id^="pagination-"] > div > div,
    .master-center #account-history-main-content .border-t > .flex { flex-wrap: wrap; }
    .master-center [id^="pagination-"] > div { padding: 12px; }
    .master-center #tab-content-memos > div:first-child { flex-wrap: wrap; gap: 8px; }
    .master-center #tab-content-blocked .justify-between { flex-wrap: wrap; gap: 8px; }
    .master-center #tab-content-blocked input { width: 100%; }

    /* 같은 행과 조작 버튼을 유지하면서 계정 정보를 카드로 표시한다. */
    .master-center .master-account-table { display: block; min-width: 0; width: 100%; white-space: normal; }
    .master-center .master-account-table tbody { display: grid; gap: 12px; padding: 2px; }
    .master-center .master-account-table tbody > tr {
        display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
        border: 1px solid #e2e8f0; border-radius: 14px; background: white; overflow: hidden;
    }
    .master-center .master-account-table td {
        display: block; padding: 10px 12px; min-width: 0; text-align: left;
        white-space: normal; overflow-wrap: anywhere; border: 0;
    }
    .master-center .master-account-table td::before {
        content: attr(data-label); display: block; margin-bottom: 5px;
        color: #64748b; font-size: 11px; font-weight: 700;
    }
    .master-center .master-account-table td[data-label="기기 고유번호"],
    .master-center .master-account-table td[data-label="기기 고유번호 (deviceId)"],
    .master-center .master-account-table td[data-label="기기 / 접속"],
    .master-center .master-account-table td[data-label="관리"],
    .master-center .master-account-table td[data-label="관리 / 삭제"],
    .master-center .master-account-table td[colspan] { grid-column: 1 / -1; }
    .master-center .master-account-table td[colspan]::before { display: none; }
    .master-center .master-history-table thead { display: block; overflow-x: auto; margin-bottom: 12px; }
    .master-center .master-history-table thead tr { display: flex; width: max-content; gap: 4px; border: 0; }
    .master-center .master-history-table th { min-width: 0; padding: 10px; }

    .master-center > [id$="-modal"] { padding: 8px; }
    .master-center > [id$="-modal"] > div {
        padding: 16px; border-radius: 18px;
        max-height: calc(100vh - 16px); max-height: calc(100dvh - 16px);
    }
    .master-center > [id$="-modal"] h3 { flex-wrap: wrap; }
    .master-center > [id$="-modal"] button { flex-shrink: 0; }
    .master-center #photo-gallery-modal > div, .master-center #photo-preview-modal > div { padding: 0; }
    .master-center #photo-gallery-modal > div > div { padding: 12px; }
    .master-center #photo-gallery-modal .flex-wrap > .flex { flex-wrap: wrap; }
    .master-center #photo-gallery-modal h3 { font-size: 14px; }
    .master-center #photo-gallery-modal .w-10 { display: none; }
    .master-center #photo-filter-driver-search { width: 100%; }
    .master-center #photo-preview-modal .min-h-\[300px\] { min-height: 0; }
    .master-center #photo-preview-sub { overflow-wrap: anywhere; }
    .master-center #blocked-devices-modal .flex-nowrap { flex-wrap: wrap; }
    .master-center #modal-blocked-device-id, .master-center #modal-blocked-device-memo { flex-basis: 100%; width: 100%; min-width: 0; }
    .master-center #blocked-devices-modal table { min-width: 580px; }
    .master-center #blocked-devices-modal .overflow-y-auto { overflow-x: auto; }
    .master-center #export-start-date, .master-center #export-end-date { width: 100%; flex-basis: 100%; }
    .master-center #excel-export-modal .items-center { flex-wrap: wrap; }
    .master-center #excel-export-modal .grid-cols-3 { grid-template-columns: 1fr; }
    .master-center #edit-modal-card > .border-t { flex-wrap: wrap; flex-shrink: 0; }
}
