/* 三閤工程 線上估價單系統 - 全域樣式 */
:root {
  --primary: #2563eb;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --text: #1e293b;
  --border: #e2e8f0;
  --paper-width: 210mm;
  --paper-height: 297mm;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "PingFang TC", "Heiti TC", "Microsoft JhengHei", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

#app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* 導覽列 */
.nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  background: var(--card-bg);
  padding: 1rem 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.nav-brand { font-size: 1.25rem; font-weight: bold; color: var(--primary); }
.nav-actions { display: flex; gap: 1rem; }

/* 按鈕 */
.btn {
  padding: 0.5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { opacity: 0.9; }
.btn-outline { border-color: var(--border); background: white; }
.btn-outline:hover { background: var(--bg); }
.btn-danger { color: #ef4444; border-color: #fecaca; background: #fef2f2; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.875rem; }

/* 儀表板 - 列表 */
.search-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.input {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
}
.table-container {
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  overflow: hidden;
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 1rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: #f1f5f9; font-weight: 600; font-size: 0.875rem; }
.status-badge {
  padding: 0.25rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.status-draft { background: #e2e8f0; color: #475569; }
.status-confirmed { background: #dcfce7; color: #166534; }

/* 編輯器 */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr;   /* 上下堆疊：明細表吃滿整個寬度，設定區移到下方 */
  gap: 2rem;
}
/* 下方設定卡：日期/分類/稅金等欄位自動橫向排列換行，條款與金額橫跨整列 */
.settings-card {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0 1.5rem;
  align-items: start;
}
.settings-card .form-group:has(textarea),
.settings-card .totals-area {
  grid-column: 1 / -1;
}
.editor-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.875rem; font-weight: 500; margin-bottom: 0.25rem; }
.items-table { margin-top: 1.5rem; }
.items-table th { font-size: 0.75rem; text-transform: uppercase; color: #64748b; }
.items-table input, .items-table textarea { border: none; background: transparent; padding: 0.5rem; width: 100%; font: inherit; }
.items-table input:focus, .items-table textarea:focus { outline: 2px solid var(--primary); border-radius: 4px; }
.items-table textarea { resize: vertical; min-height: 2.2em; line-height: 1.4; vertical-align: top; }
.totals-area {
  margin-top: 2rem;
  border-top: 2px solid var(--border);
  padding-top: 1rem;
  text-align: right;
}
.grand-total { font-size: 1.5rem; font-weight: bold; color: var(--primary); }

/* 圖片管理元件 */
.image-manager {
  margin-top: 1.5rem;
  padding: 1.5rem;
  border: 2px dashed var(--border);
  border-radius: 8px;
}
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.image-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: #f1f5f9;
}
.image-toolbar {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 2;
  display: flex;
  gap: 4px;
}
.image-action-btn {
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.78);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
}
.image-action-btn:disabled {
  cursor: default;
  opacity: 0.35;
}
.image-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.image-caption-chip {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 4px 6px;
  background: rgba(15, 23, 42, 0.72);
  color: white;
  font-size: 0.7rem;
  line-height: 1.3;
}
.image-item .delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  z-index: 2;
  background: rgba(239, 68, 68, 0.9);
  color: white;
  border: none;
  border-radius: 4px;
  width: 24px;
  height: 24px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}
.image-item .delete-btn:hover { background: #ef4444; }

/* 列印版型 (Paper-First) */
@media screen {
  .print-container {
    background: #525659;
    padding: 40px 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    min-height: 100vh;
  }
  .paper {
    background: white;
    width: var(--paper-width);
    height: var(--paper-height);
    padding: 20mm;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
    position: relative;
    overflow: hidden;
  }
}

@media print {
  @page { size: A4; margin: 0; }
  body { background: white; margin: 0; }
  #app, .nav, .nav-actions, .btn, .search-bar, .editor-actions { display: none !important; }
  .print-container { padding: 0 !important; background: white !important; display: block !important; }
  .paper {
    width: var(--paper-width) !important;
    height: var(--paper-height) !important;
    padding: 15mm 20mm !important;
    box-shadow: none !important;
    page-break-after: always;
    margin: 0 !important;
  }
}

/* 報價單內容風格 - 模擬傳統 Excel 格式 */
.quote-header { text-align: center; margin-bottom: 20px; }
.quote-header h1 { font-size: 24pt; margin: 0; letter-spacing: 5pt; border-bottom: 2pt solid black; display: inline-block; padding-bottom: 5pt; }
.quote-header .company-info { margin-top: 5pt; font-size: 10pt; }

.quote-info { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 10px; font-size: 11pt; border: 1pt solid black; padding: 10pt; }
.info-row { display: flex; border-bottom: 0.5pt solid #ccc; padding: 2pt 0; }
.info-label { width: 70pt; font-weight: bold; }
.info-value { flex: 1; }

.quote-items-table {
  width: 100%;
  border-collapse: collapse;
  border: 1.5pt solid black;
  font-size: 11pt;
}
.quote-items-table th, .quote-items-table td {
  border: 0.5pt solid black;
  padding: 4pt;
}
.quote-items-table th { background: #f2f2f2; text-align: center; }
.quote-items-table td { height: 26pt; vertical-align: middle; white-space: pre-wrap; }

.text-center { text-align: center; }
.text-right { text-align: right; }

.quote-footer { margin-top: 15px; font-size: 10pt; }
.quote-terms { border: 1pt solid black; padding: 8pt; margin-bottom: 10px; min-height: 100pt; }
.terms-title { font-weight: bold; text-decoration: underline; margin-bottom: 5pt; }
.terms-content { white-space: pre-wrap; line-height: 1.4; }

.quote-signatures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 40px;
  margin-top: 20px;
}
.sig-box { height: 80pt; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; }
.sig-line { border-top: 1pt solid black; width: 100%; text-align: center; padding-top: 5pt; }

.pagination-info {
  position: absolute;
  bottom: 10mm;
  right: 20mm;
  font-size: 9pt;
}
.col-no { width: 40pt; }
.col-desc { width: 280pt; }
.col-unit { width: 40pt; }
.col-qty { width: 50pt; }
.col-price { width: 70pt; }
.col-amount { width: 80pt; }
.col-remark { width: 80pt; }

/* 報價單附圖頁 */
.image-page-content {
  display: flex;
  flex-direction: column;
  gap: 20px;
  height: 100%;
}
.image-page-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
  flex: 1;
}
.image-page-item {
  border: 1pt solid black;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #fff;
}
.image-page-item img {
  max-width: 100%;
  max-height: 220mm; /* 留給標題和頁碼空間 */
  object-fit: contain;
}
.image-caption {
  margin-top: 10px;
  font-size: 11pt;
  font-weight: bold;
}
