/* 05_Management/forms/purchase_order.css */
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.8/dist/web/static/pretendard.css');

:root {
    --primary-color: #2b579a;
    --primary-hover: #1e3f70;
    --secondary-color: #4f6b8a;
    --bg-light: #f4f6f9;
    --card-border: #e2e8f0;
    --text-dark: #1e293b;
    --text-muted: #64748b;
    --border-color: #cbd5e1;
    --table-header-bg: #f8fafc;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --info-color: #0284c7;
    --danger-color: #ef4444;
}

* {
    box-sizing: border-box;
}

body {
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    margin: 0;
    padding: 20px;
    font-size: 13px;
    line-height: 1.5;
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid #e2e8f0;
}

.page-title-area h1 {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-dark);
    margin: 0 0 4px 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.page-title-area p {
    margin: 0;
    font-size: 12px;
    color: var(--text-muted);
}

.header-actions {
    display: flex;
    gap: 8px;
}

/* ── ECOUNT ERP 스타일 메인 리본 툴바 & 컨트롤 CSS ── */
.erp-top-toolbar {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 6px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-height: 40px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.erp-title-tag {
    font-weight: 800;
    font-size: 13.5px;
    color: #0f172a;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    padding-right: 12px;
    border-right: 1px solid #e2e8f0;
}

/* 상태별 세그먼트 탭 */
.erp-tab-group {
    display: inline-flex;
    background: #f1f5f9;
    padding: 2px;
    border-radius: 4px;
    gap: 2px;
    border: 1px solid #e2e8f0;
}

.erp-tab-group .btn-check + .erp-tab-btn {
    border: none;
    background: transparent;
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 3px;
    color: #475569;
    cursor: pointer;
    transition: all 0.1s ease;
    user-select: none;
    line-height: 20px;
    display: inline-block;
}

.erp-tab-group .btn-check:checked + .erp-tab-btn {
    background: #ffffff;
    color: #2563eb;
    font-weight: 700;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

/* 콤팩트 버튼 & 인풋 */
.btn-erp {
    height: 28px;
    padding: 0 10px;
    font-size: 12px;
    font-weight: 600;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    transition: all 0.15s ease;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
}

.btn-erp:hover {
    background: #f8fafc;
    color: #0f172a;
    border-color: #94a3b8;
}

.btn-erp-primary {
    background: #2563eb;
    color: #ffffff;
    border-color: #1d4ed8;
}

.btn-erp-primary:hover {
    background: #1d4ed8;
    color: #ffffff;
    border-color: #1e40af;
}

/* 2행 필터 리본 */
.erp-filter-ribbon {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 6px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    min-height: 38px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.erp-preset-group .btn {
    height: 28px;
    font-size: 11.5px;
    padding: 0 9px;
    border-radius: 0;
    line-height: 26px;
    border-color: #cbd5e1;
}

.erp-preset-group .btn:first-child { border-top-left-radius: 4px; border-bottom-left-radius: 4px; }
.erp-preset-group .btn:last-child { border-top-right-radius: 4px; border-bottom-right-radius: 4px; }

.erp-input-date {
    width: 125px !important;
    height: 28px !important;
    font-size: 12px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    border: 1px solid #cbd5e1 !important;
}

.erp-select-target {
    width: 120px !important;
    height: 28px !important;
    font-size: 12px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    border: 1px solid #cbd5e1 !important;
}

.erp-search-box {
    width: 220px;
    min-width: 160px;
}

.erp-search-box .form-control {
    height: 28px !important;
    font-size: 12px !important;
    border-radius: 4px !important;
    border: 1px solid #cbd5e1 !important;
    padding: 2px 8px !important;
}

.erp-search-box .form-control:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.erp-limit-select {
    width: 85px !important;
    height: 28px !important;
    font-size: 12px !important;
    padding: 2px 6px !important;
    border-radius: 4px !important;
    border: 1px solid #cbd5e1 !important;
}

/* 입력 필드 안내 플레이스홀더 (연한 회색, 이탤릭) */
input::placeholder, textarea::placeholder {
    color: #94a3b8 !important;
    font-style: italic;
    opacity: 0.85;
}

/* Table Card */
.table-card {
    background: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

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

.erp-table th {
    background: var(--table-header-bg);
    color: #475569;
    font-weight: 600;
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1.5px solid #cbd5e1;
    white-space: nowrap;
}

.erp-table td {
    padding: 10px 12px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: #334155;
}

.erp-table tbody tr:hover {
    background-color: #f8fafc;
}

.po-link {
    color: var(--primary-color);
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
}
.po-link:hover {
    text-decoration: underline;
}

/* Status Badges */
.badge-status {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-align: center;
}

.badge-draft { background-color: #f1f5f9; color: #475569; border: 1px solid #cbd5e1; }
.badge-issued { background-color: #e0f2fe; color: #0369a1; border: 1px solid #bae6fd; }
.badge-shipped { background-color: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.badge-completed { background-color: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* Action Buttons */
.btn-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 8px;
    font-size: 11px;
    font-weight: 500;
    border-radius: 4px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    color: #334155;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    line-height: 1.2;
    transition: all 0.15s;
}
.btn-action:hover {
    background: #f1f5f9;
    color: var(--primary-color);
}
.btn-action-primary {
    background: var(--primary-color);
    color: #ffffff;
    border-color: var(--primary-color);
    padding: 4px 10px;
    font-weight: 600;
}
.btn-action-primary:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

/* Modal Custom Styles */
.modal-xl-custom {
    max-width: 1100px;
}

.form-section-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1.5px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.items-grid-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin-bottom: 10px;
}

.items-grid-table th {
    background-color: #f1f5f9;
    border: 1px solid #cbd5e1;
    padding: 6px 6px;
    text-align: center;
    font-weight: 600;
}

.items-grid-table td {
    border: 1px solid #cbd5e1;
    padding: 4px 4px;
    vertical-align: middle;
}

.items-grid-table input, .items-grid-table select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 4px 6px;
    font-size: 12px;
}

.items-grid-table input:focus, .items-grid-table select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(43, 87, 154, 0.15);
}

.drawing-preview-box {
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    padding: 16px;
    text-align: center;
    background: #fafafa;
    position: relative;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
}

.drawing-preview-box:hover {
    border-color: var(--primary-color);
    background: #f8fafc;
}

.drawing-preview-img {
    max-width: 100%;
    max-height: 220px;
    object-fit: contain;
    border: 1px solid #e2e8f0;
    border-radius: 4px;
    margin-bottom: 8px;
}

/* Preset Badge List */
.preset-badge-group {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.preset-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: #e2e8f0;
    border-radius: 12px;
    font-size: 11px;
    color: #334155;
    cursor: pointer;
    transition: background 0.15s;
    user-select: none;
}
.preset-chip:hover {
    background: #cbd5e1;
}
.preset-chip.active {
    background: var(--primary-color);
    color: #ffffff;
}

/* ========================================================================= */
/* A4 Portrait Print Template (첨부 PDF와 100% 동일한 규격) */
/* ========================================================================= */
#printContainer {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }
    #printContainer, #printContainer * {
        visibility: visible;
    }
    #printContainer {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        background: #ffffff;
    }
    @page {
        size: A4 portrait;
        margin: 12mm 12mm 12mm 12mm;
    }
}

.po-print-sheet {
    width: 100%;
    max-width: 100%;
    background: #ffffff;
    color: #000000;
    font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 11px;
    line-height: 1.3;
}

.po-main-border-box {
    border: 1.5px solid #000000;
    padding: 0;
    margin-bottom: 0;
    box-sizing: border-box;
    background: #ffffff;
}

.po-print-title {
    text-align: center;
    font-size: 20px;
    font-weight: 800;
    padding: 8px 0;
    margin: 0;
    border-bottom: 1.5px solid #000000;
    letter-spacing: 1px;
}

/* 내부 모든 테이블 공통 규칙:
   부모 .po-main-border-box의 1.5px 테두리와 충돌/겹침/깎임 방지 */
.po-main-border-box table {
    width: 100%;
    table-layout: fixed;
    border-collapse: collapse;
    box-sizing: border-box;
    margin: 0;
}
.po-main-border-box table th:first-child,
.po-main-border-box table td:first-child {
    border-left: none !important;
}
.po-main-border-box table th:last-child,
.po-main-border-box table td:last-child {
    border-right: none !important;
}

.po-meta-table {
    border-bottom: 1.5px solid #000000;
}
.po-meta-table th, .po-meta-table td {
    border: 1px solid #000000;
    padding: 4px 6px;
    font-size: 10.5px;
}
.po-meta-table th {
    background-color: #ffffff;
    font-weight: bold;
    text-align: left;
    width: 16%;
}
.po-meta-table td {
    width: 34%;
}

.po-parties-table {
    border-bottom: 1.5px solid #000000;
}
.po-parties-table th {
    border: 1px solid #000000;
    padding: 4px 6px;
    font-size: 11px;
    font-weight: bold;
    text-align: left;
    background: #ffffff;
    width: 50%;
}
.po-parties-table td {
    border: 1px solid #000000;
    padding: 6px 8px;
    font-size: 10px;
    vertical-align: top;
    line-height: 1.35;
    width: 50%;
}

.po-terms-table {
    border-bottom: 1.5px solid #000000;
}
.po-terms-table th, .po-terms-table td {
    border: 1px solid #000000;
    padding: 4px 6px;
    font-size: 10px;
}
.po-terms-table th {
    font-weight: bold;
    text-align: left;
}

.po-products-table {
    border-bottom: 1.5px solid #000000;
}
.po-products-table th, .po-products-table td {
    border: 1px solid #000000;
    padding: 4px 4px;
    font-size: 10px;
}
.po-products-table th {
    text-align: center;
    font-weight: bold;
    background: #ffffff;
}
.po-products-table td.text-center { text-align: center; }
.po-products-table td.text-right { text-align: right; }
.po-products-table td.text-left { text-align: left; }

.po-total-row td {
    font-weight: bold;
    font-size: 10.5px;
    border-top: 1.5px solid #000000;
}

.po-amount-words-row td {
    border-top: 1.5px solid #000000 !important;
    padding: 5px 8px !important;
    font-size: 10.5px;
    font-weight: bold;
    text-align: left;
    background: #ffffff;
}

.po-notes-section {
    border-bottom: 1.5px solid #000000;
    padding: 6px 8px;
    font-size: 10px;
    line-height: 1.4;
    box-sizing: border-box;
}
.po-notes-title {
    font-weight: bold;
    font-size: 10.5px;
    margin-bottom: 4px;
    text-decoration: underline;
}

.po-drawing-wrap {
    text-align: center;
    margin: 8px 0;
}
.po-drawing-wrap img {
    max-width: 220px;
    max-height: 140px;
    object-fit: contain;
}

.po-signature-table {
    border-bottom: none;
}
.po-signature-table th {
    border: 1px solid #000000;
    padding: 4px 8px;
    font-size: 10.5px;
    font-weight: bold;
    text-align: left;
}
.po-signature-table td {
    border: 1px solid #000000;
    border-bottom: none !important;
    padding: 6px 8px;
    font-size: 10.5px;
}
.po-stamp-box {
    position: relative;
    height: 70px;
    display: flex;
    align-items: center;
}
/* 영문 자필 서명: 가장 아래 서명선 바로 위 배치 */
.po-eng-sign-bottom {
    position: absolute;
    bottom: 2px;
    left: 8px;
    max-height: 44px;
    max-width: 170px;
    object-fit: contain;
    z-index: 1;
}
/* 영문 자필 서명: 단독 중앙 배치 */
.po-eng-sign-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-height: 55px;
    max-width: 190px;
    object-fit: contain;
}
/* 대표자 자필 사인: 영문 서명 위 상단 배치 */
.po-sign-top {
    position: absolute;
    top: 2px;
    left: 20px;
    max-height: 36px;
    max-width: 110px;
    object-fit: contain;
    z-index: 2;
}
/* 대표자 자필 사인: 단독 중앙 배치 */
.po-sign-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    max-height: 52px;
    max-width: 140px;
    object-fit: contain;
}
/* 도장(직인): 영문 서명 끝에 약 30% 걸쳐 날인 */
.po-seal-overlap {
    position: absolute;
    bottom: -8px;
    right: 30px;
    width: 56px;
    height: 56px;
    object-fit: contain;
    mix-blend-mode: multiply;
    z-index: 3;
}
/* 도장(직인): 단독 중앙 배치 */
.po-seal-center {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 58px;
    height: 58px;
    object-fit: contain;
    mix-blend-mode: multiply;
}

.po-sign-footer {
    font-weight: bold;
    border-top: 1px solid #000;
    padding-top: 4px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    min-height: 22px;
}
.po-sign-date {
    font-size: 9px;
    font-weight: normal;
    color: #333;
}

/* ── 최근 입력 기록 드롭다운 (References, Terms of Payment, Delivery Date 등) ── */
.recent-history-dropdown {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 1095;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
    max-height: 180px;
    overflow-y: auto;
    display: none;
}

.recent-history-header {
    padding: 4px 8px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 10.5px;
    font-weight: 700;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.recent-history-item {
    padding: 5px 8px;
    font-size: 11.5px;
    color: #1e293b;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background-color 0.1s, color 0.1s;
    word-break: break-word;
}

.recent-history-item:last-child {
    border-bottom: none;
}

.recent-history-item:hover {
    background-color: #eff6ff;
    color: #2563eb;
    font-weight: 600;
}

/* ── 거래 당사자 (Buyer & Seller) 주소 3줄 textarea ── */
#formBuyerAddress, #formSellerAddress {
    resize: vertical;
    font-size: 11.5px;
    line-height: 1.45;
    min-height: 62px;
}
