/* ==========================================================================
   AI 견적서 자동 완성 시스템 스타일시트
   ========================================================================== */

:root {
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-light: #eff6ff;
  --bg-dark: #0f172a;
  --panel-bg: #1e293b;
  --panel-border: rgba(255, 255, 255, 0.08);
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --danger: #ef4444;
  --success: #10b981;
  --warning: #f59e0b;

  /* 견적서 양식 팔레트 (원본 견적서 서식 완벽 재현) */
  --sheet-border-main: #262626;
  --sheet-border-cell: #555555;
  --sheet-bg-header: #dbe5f1;      /* 연한 블루그레이 (헤더/합계) */
  --sheet-bg-supp: #dce6f1;        /* 공급자 타이틀 연청색 */
  --sheet-bg-amount: #fde9d9;      /* 견적금액 배너 살구/피치색 */
  --sheet-text: #111827;
  --sheet-font: "Pretendard", -apple-system, BlinkMacSystemFont, system-ui, Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--sheet-font);
  background: #0b0f19;
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
}

/* ==========================================================================
   메인 레이아웃: 좌측 컨트롤 패널 + 우측 견적서 뷰포트
   ========================================================================== */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* 좌측 사이드 패널 */
.control-panel {
  width: 440px;
  min-width: 420px;
  background: var(--panel-bg);
  border-right: 1px solid var(--panel-border);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  overflow-y: auto;
  max-height: 100vh;
  position: sticky;
  top: 0;
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
  z-index: 10;
}

.panel-header .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #60a5fa;
}

.panel-header .brand i {
  font-size: 26px;
  color: #93c5fd;
}

.panel-header h2 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.5px;
  color: #fff;
}

.panel-header .subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* 패널 섹션 공통 */
.panel-section {
  background: rgba(15, 23, 42, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  color: #e2e8f0;
}

.section-title i {
  color: #60a5fa;
  font-size: 16px;
}

.badge-secure {
  margin-left: auto;
  font-size: 11px;
  color: #34d399;
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  padding: 3px 8px;
  border-radius: 12px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}

.section-title .btn-text-toggle {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}

.section-title .btn-text-toggle:hover {
  color: #fff;
}

/* 폼 인풋 & 셀렉트 */
.input-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.input-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.input-group input[type="password"],
.input-group input[type="text"],
.input-group select {
  width: 100%;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 8px;
  padding: 10px 12px;
  color: #f8fafc;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: all 0.2s ease;
}

.input-group input:focus,
.input-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.25);
}

.input-group .help-text {
  font-size: 11px;
  color: #64748b;
}

.hidden {
  display: none !important;
}

/* 마이크 버튼 및 음성 인식 헤더 */
.btn-mic {
  margin-left: auto;
  background: #1e3a8a;
  border: 1px solid #3b82f6;
  color: #bfdbfe;
  padding: 5px 10px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-mic:hover {
  background: #2563eb;
  color: #fff;
}

.btn-mic.listening {
  background: #dc2626;
  border-color: #ef4444;
  color: #fff;
  animation: pulseMic 1.5s infinite;
}

@keyframes pulseMic {
  0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  70% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
  100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* 아무말 텍스트 입력창 */
.textarea-wrapper {
  position: relative;
}

.textarea-wrapper textarea {
  width: 100%;
  height: 200px;
  background: #0f172a;
  border: 1px solid #334155;
  border-radius: 10px;
  padding: 12px;
  color: #f1f5f9;
  font-size: 13.5px;
  line-height: 1.55;
  font-family: inherit;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}

.textarea-wrapper textarea:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96, 165, 250, 0.2);
}

.mic-wave {
  position: absolute;
  bottom: 12px;
  left: 12px;
  right: 12px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(239, 68, 68, 0.4);
  padding: 10px 14px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  z-index: 5;
}

.mic-wave span:not(.wave-label) {
  width: 4px;
  height: 14px;
  background: #ef4444;
  border-radius: 2px;
  animation: waveAnim 1s ease-in-out infinite;
}

.mic-wave span:nth-child(2) { animation-delay: 0.15s; }
.mic-wave span:nth-child(3) { animation-delay: 0.3s; }
.mic-wave span:nth-child(4) { animation-delay: 0.45s; }
.mic-wave span:nth-child(5) { animation-delay: 0.6s; }

.mic-wave .wave-label {
  margin-left: 8px;
  font-size: 12px;
  color: #fca5a5;
  font-weight: 500;
}

@keyframes waveAnim {
  0%, 100% { height: 6px; }
  50% { height: 22px; }
}

/* 샘플 칩 */
.sample-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.chips-label {
  font-size: 11px;
  color: #64748b;
}

.chip-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-size: 11.5px;
  padding: 4px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.chip-btn:hover {
  background: #334155;
  color: #fff;
  border-color: #64748b;
}

/* 메인 실행 버튼 */
.btn-primary {
  width: 100%;
  background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
  border: none;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  padding: 14px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
  transition: all 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(37, 99, 235, 0.55);
  background: linear-gradient(135deg, #60a5fa 0%, #1d4ed8 100%);
}

.btn-primary:active {
  transform: translateY(1px);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

/* 상태 메시지 */
.status-msg {
  font-size: 12.5px;
  padding: 8px 12px;
  border-radius: 6px;
  line-height: 1.4;
}

.status-msg.info {
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.status-msg.error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.status-msg.success {
  background: rgba(16, 185, 129, 0.15);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

/* 액션 버튼 그룹 */
.action-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.action-buttons .btn-danger {
  grid-column: span 2;
}

.btn-action {
  background: #1e293b;
  border: 1px solid #334155;
  color: #e2e8f0;
  padding: 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-action:hover {
  background: #334155;
  color: #fff;
  border-color: #64748b;
}

.btn-action.btn-danger {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-action.btn-danger:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
  color: #fca5a5;
}

.panel-footer {
  margin-top: auto;
  font-size: 11.5px;
  color: #64748b;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.panel-footer .credit {
  font-size: 10.5px;
  color: #475569;
}

/* ==========================================================================
   우측 메인 뷰포트 & 견적서 시트 (종이 양식 완벽 재현)
   ========================================================================== */
.sheet-viewport {
  flex: 1;
  background: #334155;
  padding: 40px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* A4 규격 시트 (210mm x 297mm 비율) */
.sheet-paper {
  width: 794px; /* A4 96DPI 기준 (210mm approx 794px) */
  min-height: 1123px; /* A4 96DPI 기준 (297mm approx 1123px) */
  background: #ffffff;
  color: var(--sheet-text);
  padding: 44px 44px 38px 44px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.45);
  position: relative;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--sheet-border-main);
  box-sizing: border-box;
}

/* 직접 편집 가능한 셀/필드 스타일 */
.editable-field {
  outline: none;
  min-height: 18px;
  padding: 1px 3px;
  border-radius: 2px;
  transition: background 0.15s;
}

.editable-field:hover {
  background: rgba(59, 130, 246, 0.08);
}

.editable-field:focus {
  background: #e0f2fe;
  box-shadow: 0 0 0 1px #0284c7;
}

/* 문서 번호 */
.sheet-doc-no {
  font-size: 12.5px;
  font-weight: 600;
  color: #333;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
}

#docNoField {
  display: inline-block;
  min-width: 100px;
  margin-left: 4px;
}

/* 문서 제목 */
.sheet-title {
  text-align: center;
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 20px;
  padding-left: 20px; /* letter-spacing 보정 */
  color: #111;
  margin: 10px 0 24px 0;
  font-family: var(--sheet-font);
}

/* 메타 그리드 (좌측 날짜/수신처 vs 우측 공급자 표) */
.sheet-meta-grid {
  display: grid;
  grid-template-columns: 1fr 340px;
  gap: 16px;
  margin-bottom: 14px;
  align-items: end;
}

/* 좌측 메타 */
.meta-left {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding-bottom: 6px;
}

.meta-date {
  font-size: 13.5px;
  font-weight: 600;
  color: #222;
  border-bottom: 1.5px solid #222;
  padding-bottom: 4px;
  width: 85%;
}

.meta-client {
  display: flex;
  align-items: flex-end;
  border-bottom: 1.5px solid #222;
  width: 85%;
  padding-bottom: 4px;
}

.client-name {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  color: #111;
}

.client-suffix {
  font-size: 14px;
  font-weight: 600;
  color: #222;
  margin-left: 8px;
  white-space: nowrap;
}

.meta-greeting {
  font-size: 13px;
  font-weight: 500;
  color: #333;
  padding-left: 2px;
}

/* 우측 공급자 정보 표 */
.supplier-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  border: 1.5px solid var(--sheet-border-main);
}

.supplier-table col.col-supp-badge { width: 32px; }
.supplier-table col.col-supp-lbl { width: 78px; }
.supplier-table col.col-supp-val { width: 100px; }
.supplier-table col.col-supp-lbl-sub { width: 44px; }
.supplier-table col.col-supp-val-sub { width: 86px; }

.supplier-table th,
.supplier-table td {
  border: 1px solid var(--sheet-border-cell);
  padding: 4px 6px;
  height: 24px;
  line-height: 1.3;
}

.supplier-table .th-supp-badge {
  background: var(--sheet-bg-supp);
  font-weight: 700;
  text-align: center;
  vertical-align: middle;
  font-size: 12px;
  color: #111;
  letter-spacing: 2px;
  padding: 4px 0;
}

.supplier-table .th-label {
  background: #f8fafc;
  font-weight: 600;
  text-align: center;
  color: #333;
  white-space: nowrap;
}

.supplier-table .val-center {
  text-align: center;
}

/* 견적금액 배너 (살구색) */
.amount-banner {
  background: var(--sheet-bg-amount);
  border: 1.5px solid var(--sheet-border-main);
  border-bottom: none;
  display: grid;
  grid-template-columns: 120px 1fr 180px;
  height: 42px;
  align-items: center;
  margin-top: 10px;
}

.amount-title {
  text-align: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: 3px;
  border-right: 1px solid var(--sheet-border-cell);
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.amount-korean {
  padding: 0 16px;
  font-size: 14px;
  font-weight: 700;
  color: #111;
  letter-spacing: 0.5px;
}

.amount-number {
  text-align: right;
  padding-right: 14px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.5px;
  color: #111;
}

/* 품목 상세 테이블 */
.items-table-container {
  width: 100%;
}

.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  border: 1.5px solid var(--sheet-border-main);
}

.items-table col.col-item-name { width: 170px; }
.items-table col.col-item-spec { width: 85px; }
.items-table col.col-item-qty { width: 50px; }
.items-table col.col-item-price { width: 95px; }
.items-table col.col-item-supply { width: 105px; }
.items-table col.col-item-tax { width: 95px; }
.items-table col.col-item-remarks { width: 104px; }

.items-table th,
.items-table td {
  border: 1px solid var(--sheet-border-cell);
  height: 25px;
  padding: 3px 6px;
  vertical-align: middle;
}

.items-table thead th {
  background: var(--sheet-bg-header);
  font-weight: 700;
  text-align: center;
  color: #111;
  font-size: 12.5px;
  letter-spacing: 1px;
}

.items-table tbody tr:hover td {
  background: rgba(241, 245, 249, 0.7);
}

.items-table .val-center {
  text-align: center;
}

.items-table .val-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: inherit;
}

.items-table .val-dash {
  text-align: center;
  color: #888;
}

/* 합계 행 */
.items-table tfoot tr.total-row {
  background: var(--sheet-bg-header);
  font-weight: 700;
}

.items-table tfoot .total-label {
  text-align: center;
  font-size: 13px;
  letter-spacing: 6px;
  padding-left: 6px;
}

/* 하단 특이사항 / 비고 박스 */
.sheet-notes-box {
  border: 1.5px solid var(--sheet-border-main);
  border-top: none;
  min-height: 80px;
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
  color: #222;
  margin-bottom: 12px;
}

.notes-content {
  min-height: 60px;
  outline: none;
}

/* 품목 툴바 (화면 전용) */
.sheet-row-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px dashed #cbd5e1;
  margin-top: 4px;
}

.btn-row-tool {
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 5px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.15s;
}

.btn-row-tool:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.row-tool-hint {
  font-size: 11px;
  color: #64748b;
  margin-left: auto;
}

/* ==========================================================================
   인쇄(Print) 전용 최적화 (@media print)
   - 사이드바 숨김
   - A4 한 장에 완벽 1:1 출력
   ========================================================================== */
@media print {
  @page {
    size: A4 portrait;
    margin: 10mm 8mm;
  }

  body {
    background: #fff !important;
    color: #000 !important;
    overflow: visible !important;
  }

  .no-print {
    display: none !important;
  }

  .app-container {
    display: block !important;
  }

  .sheet-viewport {
    background: transparent !important;
    padding: 0 !important;
    display: block !important;
    overflow: visible !important;
  }

  .sheet-paper {
    width: 100% !important;
    min-height: auto !important;
    box-shadow: none !important;
    border: 2px solid #000 !important;
    padding: 20px 25px !important;
    margin: 0 auto !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .amount-banner {
    background: #fde9d9 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .supplier-table .th-supp-badge,
  .items-table thead th,
  .items-table tfoot tr.total-row {
    background: #dbe5f1 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .editable-field:hover,
  .editable-field:focus {
    background: transparent !important;
    box-shadow: none !important;
  }
}
