/* ============================================================
   estimate.css — 견적서 페이지
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --color-bg:     #f0f0ee;
  --color-dark:   #0f0f0f;
  --color-accent: #FDD000;
  --color-border: #d8d8d4;
  --color-white:  #ffffff;
  --font: 'Pretendard', -apple-system, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--color-bg);
  color: var(--color-dark);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* ---- 앱 헤더 ---- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 56px;
  background: var(--color-dark);
  color: var(--color-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  gap: 1rem;
}

.app-header__back {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  font-family: inherit;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: color 0.2s;
}
.app-header__back:hover { color: #fff; }

.app-header__title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.app-header__actions { display: flex; gap: 0.5rem; }

.btn-action {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255,255,255,0.12);
  color: var(--color-white);
  border: 1px solid rgba(255,255,255,0.2);
  padding: 0.5rem 1.1rem;
  border-radius: 100px;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  font-family: var(--font);
  transition: background 0.2s, transform 0.15s;
}
.btn-action:hover { background: rgba(255,255,255,0.22); transform: scale(1.02); }
.btn-action--send {
  background: var(--color-accent);
  color: var(--color-dark);
  border-color: var(--color-accent);
}
.btn-action--send:hover { background: #e6be00; }

/* ---- 저장 상태 ---- */
.save-status {
  font-size: 0.75rem;
  color: rgba(255,255,255,0.45);
  align-self: center;
  white-space: nowrap;
  transition: color 0.3s;
}

/* ---- 저장 모달 ---- */
.saved-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.saved-modal__inner {
  background: #fff;
  width: min(460px, 92vw);
  max-height: 72vh;
  border-radius: 14px;
  display: flex; flex-direction: column;
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,0.18);
}
.saved-modal__head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eee;
}
.saved-modal__head h3 { font-size: 1rem; font-weight: 700; }
.saved-modal__close {
  background: none; border: none; cursor: pointer;
  font-size: 1rem; color: #aaa; line-height: 1;
}
.saved-modal__close:hover { color: #333; }
.saved-modal__list { overflow-y: auto; flex: 1; padding: 0.5rem; }
.saved-modal__foot {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid #eee;
  display: flex; justify-content: flex-end;
}

.saved-item {
  display: flex; align-items: center;
  padding: 0.65rem 0.75rem;
  border-radius: 8px; border: 1px solid #eee;
  margin-bottom: 0.4rem; gap: 0.5rem;
}
.saved-item.is-current { border-color: #e85; background: #fff9f6; }
.saved-item__info { flex: 1; cursor: pointer; }
.saved-item__info:hover .saved-item__client { text-decoration: underline; }
.saved-item__no { font-size: 0.72rem; font-weight: 700; color: #e85; display: block; margin-bottom: 0.1rem; }
.saved-item__client { font-size: 0.9rem; font-weight: 600; display: block; }
.saved-item__meta { font-size: 0.72rem; color: #aaa; display: block; margin-top: 0.15rem; }
.saved-item__del {
  background: none; border: none; cursor: pointer;
  padding: 0.3rem; color: #ccc; font-size: 0.8rem; line-height: 1;
  border-radius: 4px; flex-shrink: 0;
}
.saved-item__del:hover { color: #e33; background: #fef2f2; }
.saved-empty { text-align: center; padding: 2.5rem 1rem; color: #bbb; font-size: 0.9rem; }

.btn-new-estimate {
  background: #0f0f0f; color: #fff;
  border: none; border-radius: 100px;
  padding: 0.5rem 1.2rem; font-size: 0.85rem; font-weight: 700;
  cursor: pointer; font-family: var(--font);
}
.btn-new-estimate:hover { background: #333; }

/* ---- 불러오기 배너 ---- */
.restore-banner {
  background: #fff8f0; border: 1px solid #ffd8b0;
  border-radius: 8px; padding: 0.6rem 0.75rem;
  margin-bottom: 1rem;
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.82rem; color: #555;
}
.restore-banner strong { color: #c05; }
.restore-banner__load {
  background: #c05; color: #fff; border: none;
  border-radius: 4px; padding: 0.25rem 0.6rem;
  font-size: 0.8rem; cursor: pointer; font-family: var(--font);
  margin-left: auto;
}
.restore-banner__dismiss {
  background: none; border: 1px solid #ddd;
  border-radius: 4px; padding: 0.25rem 0.5rem;
  font-size: 0.8rem; cursor: pointer; color: #999;
}

/* ---- 워크스페이스 ---- */
.workspace {
  display: grid;
  grid-template-columns: 500px 1fr;
  height: calc(100vh - 56px);
  overflow: hidden;
}

/* ---- 폼 패널 ---- */
.form-panel {
  background: var(--color-white);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
}

.form-panel__inner { padding: 1.25rem 1.25rem; }

.form-section {
  margin-bottom: 1.5rem;
}

.form-section__title {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: #999;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.field { display: flex; flex-direction: column; gap: 0.25rem; margin-bottom: 0.55rem; }
.field label { font-size: 0.78rem; font-weight: 600; color: #555; }
.field input, .field select, .field textarea {
  border: 1.5px solid var(--color-border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  font-family: var(--font);
  color: var(--color-dark);
  background: #fafaf8;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--color-dark);
  background: #fff;
}
.field textarea { resize: vertical; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; }

/* 빠른선택 */
/* ---- 서비스 유형 선택 ---- */
.type-selector {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 5px;
  margin-bottom: 0.75rem;
}
.type-btn {
  padding: 0.45rem 0;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
  font-family: var(--font);
  font-size: 0.82rem;
  font-weight: 700;
  color: #666;
  cursor: pointer;
  transition: all 0.18s;
  text-align: center;
}
.type-btn:hover {
  border-color: var(--color-dark);
  color: var(--color-dark);
}
.type-btn.is-active {
  background: var(--color-dark);
  border-color: var(--color-dark);
  color: var(--color-accent);
}

.quick-select {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin-bottom: 0.75rem;
}
.quick-select__label {
  font-size: 0.75rem;
  color: #999;
  font-weight: 600;
}
.class-select-dropdown {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--color-border);
  border-radius: 8px;
  background: var(--color-white);
  font-family: var(--font);
  font-size: 0.85rem;
  color: var(--color-dark);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
}
.class-select-dropdown:focus {
  outline: none;
  border-color: var(--color-accent);
}
.class-select-dropdown optgroup {
  font-weight: 700;
  color: #555;
}
.class-select-dropdown option {
  font-weight: 400;
  color: var(--color-dark);
}

/* ---- 필수항목 표시 ---- */
.req { color: #e74c3c; font-weight: 700; }

/* ---- 발송 모달 ---- */
.send-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.send-modal.is-open { display: flex; }
.send-modal__box {
  background: var(--color-white);
  border-radius: 12px;
  padding: 2rem;
  width: min(480px, 90vw);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.send-modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.send-modal__head h3 { font-size: 1.1rem; font-weight: 800; }
.send-modal__close {
  background: none; border: none; cursor: pointer;
  font-size: 1.1rem; color: #999; padding: 0.2rem;
}
.send-modal__desc { font-size: 0.85rem; color: #666; line-height: 1.7; }
.btn-send-confirm {
  background: var(--color-dark);
  color: var(--color-accent);
  border: none;
  border-radius: 8px;
  padding: 0.85rem;
  font-size: 0.95rem;
  font-weight: 700;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 0.5rem;
}
.btn-send-confirm:hover { background: #222; }
.btn-send-confirm:disabled { opacity: 0.5; cursor: not-allowed; }
.send-status { font-size: 0.85rem; min-height: 1.2em; }
.send-status--loading { color: #888; }
.send-status--success { color: #27ae60; font-weight: 600; }
.send-status--error   { color: #e74c3c; font-weight: 600; }

/* 항목 테이블 */
.btn-add-row {
  background: var(--color-dark);
  color: var(--color-white);
  border: none;
  border-radius: 100px;
  padding: 0.3rem 0.8rem;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.2s;
}
.btn-add-row:hover { background: #333; }

.items-table__head {
  display: grid;
  grid-template-columns: 1fr 48px 52px 72px 68px 22px;
  gap: 0.3rem;
  padding: 0.4rem 0.6rem;
  background: var(--color-bg);
  border-radius: 6px 6px 0 0;
  font-size: 0.71rem;
  font-weight: 700;
  color: #888;
  letter-spacing: 0.04em;
  border: 1.5px solid var(--color-border);
  border-bottom: none;
}

.items-table__body { border: 1.5px solid var(--color-border); border-radius: 0 0 6px 6px; overflow: hidden; }

.item-row {
  display: grid;
  grid-template-columns: 1fr 48px 52px 72px 68px 22px;
  gap: 0.3rem;
  padding: 0.3rem 0.6rem;
  align-items: center;
  border-bottom: 1px solid var(--color-border);
}
.item-row:last-child { border-bottom: none; }

.item-row input {
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 0.3rem 0.4rem;
  font-size: 0.82rem;
  font-family: var(--font);
  color: var(--color-dark);
  background: transparent;
  outline: none;
  width: 100%;
  transition: border-color 0.15s, background 0.15s;
  min-width: 0;
}
.item-row input:focus { border-color: var(--color-border); background: #fafaf8; }
.item-row input[type="number"] { text-align: right; }

.item-row__amount {
  font-size: 0.82rem;
  font-weight: 600;
  text-align: right;
  color: var(--color-dark);
  white-space: nowrap;
}

.btn-del-row {
  background: none;
  border: none;
  cursor: pointer;
  color: #ccc;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  transition: color 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-del-row:hover { color: #e74c3c; }

/* ---- 미리보기 패널 ---- */
.preview-panel {
  overflow-y: auto;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2.5rem 2rem;
}

.preview-panel__inner { width: 100%; max-width: 820px; }

/* ============================================================
   A4 견적서
   ============================================================ */
.a4 {
  background: #fff;
  width: 210mm;
  min-height: 297mm;
  padding: 16mm 18mm 14mm;
  box-shadow: 0 4px 32px rgba(0,0,0,0.12);
  font-size: 9pt;
  line-height: 1.6;
  color: #111;
  position: relative;
  display: flex;
  flex-direction: column;
}

.a4::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  top: 297mm;
  border-top: 2px dashed rgba(0,0,0,0.12);
  pointer-events: none;
}

/* ① 로고 + NO */
.a4__head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 7mm;
}

.a4__head-logo {
  height: 13mm;
  width: auto;
  display: block;
}

.a4__no {
  font-size: 8pt;
  color: #bbb;
  letter-spacing: 0.05em;
  line-height: 1.5;
  text-align: right;
}

/* ② 타이틀 */
.a4__title {
  font-size: 28pt;
  font-weight: 900;
  letter-spacing: 0.35em;
  color: #111;
  line-height: 1;
  margin-bottom: 4mm;
}

.a4__title-line {
  height: 2px;
  background: #111;
  margin-bottom: 6mm;
}

/* ③ 수신 정보 */
.a4__meta {
  display: flex;
  flex-direction: column;
  gap: 1.8mm;
  margin-bottom: 6mm;
}

.meta-row {
  display: flex;
  align-items: baseline;
  gap: 5mm;
  font-size: 9pt;
}

.meta-key {
  font-weight: 700;
  color: #111;
  white-space: nowrap;
  min-width: 16mm;
  letter-spacing: 0.05em;
}

/* ④ 안내문 */
.a4__lead {
  font-size: 8.5pt;
  color: #777;
  margin-bottom: 5mm;
}

/* ⑤ 항목 테이블 */
.a4__items {
  flex: 1;
  margin-bottom: 0;
}

.items-preview-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 8.5pt;
}

.items-preview-table thead th {
  padding: 2mm 2.5mm;
  font-weight: 700;
  font-size: 8pt;
  color: #333;
  border-top: 1.5px solid #111;
  border-bottom: 1.5px solid #111;
  text-align: right;
  letter-spacing: 0.03em;
}

.items-preview-table thead .col-no,
.items-preview-table thead .col-name { text-align: left; }

.items-preview-table tbody td {
  padding: 2mm 2.5mm;
  text-align: right;
  border-bottom: 1px solid #ebebeb;
  color: #222;
}

.items-preview-table tbody .col-no,
.items-preview-table tbody .col-name { text-align: left; }
.items-preview-table tbody .col-spec { color: #999; font-size: 8pt; }
.items-preview-table tbody .col-no   { color: #bbb; font-size: 8pt; }
.items-preview-table tbody .col-total { font-weight: 600; }

.items-preview-table tbody tr:last-child td { border-bottom: 1.5px solid #111; }

.items-preview-table .col-no    { width: 16px; }
.items-preview-table .col-spec  { width: 46px; }
.items-preview-table .col-qty   { width: 42px; white-space: nowrap; }
.items-preview-table .col-price { width: 62px; }
.items-preview-table .col-total { width: 66px; }

.items-preview-table .empty-row td {
  color: #ccc;
  text-align: center;
  padding: 6mm;
  border-top: 1.5px solid #111;
  border-bottom: 1.5px solid #111;
}

/* ⑥ 합계 */
.a4__totals {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  margin-top: 3mm;
  margin-bottom: 1mm;
  gap: 0;
}

.total-row {
  display: flex;
  justify-content: space-between;
  font-size: 8.5pt;
  width: 72mm;
  padding: 1.2mm 0;
  border-bottom: 1px solid #ebebeb;
}

.total-row:first-child { border-top: none; }
.total-row span:first-child { color: #666; }
.total-row span:last-child  { font-weight: 600; text-align: right; }

.total-row--vat {
  border-bottom: 1.5px solid #111;
}
.total-row--vat span:first-child { color: #aaa; }
.total-row--vat span:last-child  { font-weight: 400; color: #aaa; }

.total-row--final {
  background: #f5f5f3;
  padding: 2.5mm 3mm;
  font-size: 10pt;
  font-weight: 800;
  border-bottom: none;
  width: 72mm;
  margin-top: 1mm;
}
.total-row--final span:first-child { color: #111; }

/* ⑦ 한글 금액 */
.a4__amount-ko {
  font-size: 8pt;
  color: #888;
  text-align: right;
  margin-top: 1.5mm;
  margin-bottom: 6mm;
}

/* ⑧ 비고 */
.a4__note {
  border: 1px solid #ddd;
  padding: 3mm 3.5mm;
  min-height: 20mm;
  margin-bottom: 6mm;
}

.note-label {
  font-size: 7.5pt;
  font-weight: 700;
  color: #999;
  letter-spacing: 0.1em;
  margin-bottom: 1.5mm;
}

.note-body {
  font-size: 8.5pt;
  color: #444;
  line-height: 1.6;
}

/* ⑨ 공급자 + 도장 */
.a4__supplier {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: auto;
  padding-top: 5mm;
  border-top: 1px solid #ddd;
}

.supplier-label {
  font-size: 7.5pt;
  color: #bbb;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin-bottom: 1mm;
}

.supplier-name {
  font-size: 12pt;
  font-weight: 900;
  color: #111;
  margin-bottom: 2mm;
  letter-spacing: -0.01em;
}

.supplier-detail {
  font-size: 7pt;
  color: #777;
  line-height: 1.8;
}

.supplier-sign {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2mm;
  min-width: 36mm;
}

.supplier-sign__seal {
  width: 20mm;
  height: 20mm;
  position: relative;
}

.seal-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: none;
}

@media print {
  .seal-img { display: block; }
  body.no-seal .seal-img { display: none !important; }
}

.supplier-sign__text {
  font-size: 7pt;
  color: #888;
  text-align: center;
  line-height: 1.9;
}

.supplier-sign__text strong {
  font-size: 8.5pt;
  color: #111;
  font-weight: 800;
  letter-spacing: 0.08em;
  display: block;
}

/* ============================================================
   인쇄
   ============================================================ */
@media print {
  @page { size: A4 portrait; margin: 0; }

  /* 페이지를 정확히 A4 1장으로 제한 */
  html, body {
    height: 297mm !important;
    overflow: hidden !important;
    background: #fff;
  }

  /* cart.js 주입 요소 + 앱 UI 모두 숨김 */
  .float-menu, .cart-sidebar, .cart-overlay,
  .cart-toast, .cart-header-tip, .cart-import-banner,
  .app-header, .form-panel { display: none !important; }

  .workspace        { display: block; height: 297mm; overflow: hidden; }
  .preview-panel    { padding: 0; margin: 0; height: 297mm; overflow: hidden; }
  .preview-panel__inner { padding: 0; margin: 0; }

  .a4 {
    width: 210mm;
    height: 297mm;
    overflow: hidden;
    box-shadow: none;
    position: relative; /* 공급자 absolute 기준 */
    padding-bottom: 38mm; /* 하단 공급자 영역 확보 */
  }
  .a4::after { display: none; }

  /* 항목 테이블: 자연 높이 */
  .a4__items { flex: none; }

  /* 비고 축소 */
  .a4__note { min-height: 10mm; margin-bottom: 0; }

  /* 공급자: 페이지 하단 고정 */
  .a4__supplier {
    position: absolute;
    bottom: 14mm;
    left: 18mm;
    right: 18mm;
    margin-top: 0;
  }

  .items-preview-table thead { display: table-header-group; }
  .items-preview-table tbody tr { break-inside: avoid; page-break-inside: avoid; }
}

/* ============================================================
   반응형
   ============================================================ */
@media (max-width: 1100px) {
  .workspace { grid-template-columns: 440px 1fr; }
}
@media (max-width: 960px) {
  .workspace { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .form-panel { overflow: visible; }
  .preview-panel { padding: 1.5rem 0.5rem; }
  .a4 { font-size: 7pt; padding: 10mm 12mm; }
  .a4__title { font-size: 22pt; }
  .a4__head-logo { height: 10mm; }
}
