/* ========== 設計系統（沿用報價單原版配色）========== */
:root {
  --dark: #1e1e1e;
  --dark-2: #2a2a2a;
  --green: #16a34a;
  --green-light: #22c55e;
  --green-bg: #ecfdf5;
  --blue: #2563eb;
  --red: #dc2626;
  --yellow-bg: #fefce8;
  --yellow-border: #eab308;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
  --shadow: 0 2px 8px rgba(0,0,0,.08);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
  --radius: 8px;
}

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

body {
  font-family: "Noto Sans TC", "Noto Sans CJK TC", -apple-system, "Segoe UI", sans-serif;
  color: var(--gray-900);
  background: var(--gray-50);
  line-height: 1.5;
  font-size: 14px;
}

/* ========== SVG icons ========== */
.icon {
  width: 20px; height: 20px;
  stroke-width: 2;
  vertical-align: -4px;
  margin-right: 8px;
  color: var(--green);
  flex-shrink: 0;
}
.icon-sm {
  width: 16px; height: 16px;
  vertical-align: -3px;
  margin-right: 6px;
  flex-shrink: 0;
}
/* 按鈕內的 icon 用白色 */
.btn-primary .icon, .btn-primary .icon-sm { color: white; }
.close-btn .icon-sm { color: var(--gray-500); margin: 0; }
.chevron {
  width: 18px; height: 18px;
  color: var(--gray-500);
  transition: transform .2s ease;
  flex-shrink: 0;
}

/* ========== 導覽列 ========== */
.topnav {
  background: var(--dark);
  color: white;
  padding: 12px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 3px solid var(--green-light);
  position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 16px; letter-spacing: 1px; }
.brand .logo {
  width: 32px; height: 32px;
  background: var(--green-light);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 13px; letter-spacing: -1px;
}
.nav-links { display: flex; gap: 8px; }
.nav-links a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 14px;
  transition: all .2s;
}
.nav-links a:hover { background: rgba(255,255,255,.1); color: white; }
.nav-links a.active { background: var(--green); color: white; }

/* ========== 版面容器 ========== */
.container {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 20px;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.page-header h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--dark);
  letter-spacing: -0.3px;
}
.quote-no-display {
  background: var(--gray-100);
  border-left: 3px solid var(--green);
  padding: 6px 14px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--gray-700);
}
.quote-no-display strong { color: var(--dark); margin-left: 4px; font-family: monospace; font-size: 14px; }

/* ========== 卡片 ========== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 20px;
  margin-bottom: 16px;
  border: 1px solid var(--gray-200);
}
.card h2 {
  font-size: 16px;
  color: var(--dark);
  margin-bottom: 16px;
  font-weight: 700;
  letter-spacing: -0.2px;
  display: flex;
  align-items: center;
}
.card h2 .hint {
  font-weight: 400;
  color: var(--gray-500);
  font-size: 12px;
  margin-left: 6px;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.card-header h2 { margin-bottom: 0; }

/* 摺疊卡片 —— 整列可點擊 */
.collapsible { padding: 0; overflow: hidden; }
.collapsible .collapse-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  cursor: pointer;
  user-select: none;
  transition: background .15s;
}
.collapsible .collapse-toggle:hover { background: var(--gray-50); }
.collapsible .collapse-toggle:active { background: var(--gray-100); }
.collapsible .collapse-toggle h2 { margin-bottom: 0; }
.collapsible.expanded .chevron { transform: rotate(180deg); }
.collapsible .collapse-body { display: none; padding: 0 20px 20px 20px; }
.collapsible.expanded .collapse-body { display: block; }

/* ========== 表單元素 ========== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* 基本資訊三欄比例：日期較寬，兩個數字欄較窄 */
.grid-date {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.field:last-child { margin-bottom: 0; }
.field label {
  font-size: 12px;
  color: var(--gray-700);
  font-weight: 600;
  letter-spacing: 0.3px;
}
.field .required { color: var(--red); }
.field input, .field textarea, .field select {
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  background: white;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field textarea:focus, .field select:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(22,163,74,.12);
}
textarea {
  resize: vertical;
  min-height: 60px;
  font-family: inherit;
  padding: 10px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 14px;
  width: 100%;
}

/* ========== 產品明細列 ========== */
.item-row {
  border: 1px solid var(--gray-200);
  border-left: 4px solid var(--green-light);
  border-radius: 6px;
  padding: 14px;
  margin-bottom: 12px;
  background: var(--gray-50);
  position: relative;
}
.item-row .item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}
.item-row .item-title {
  font-weight: 700;
  color: var(--green);
  font-size: 13px;
  letter-spacing: 1px;
}
.item-row .item-remove {
  background: transparent;
  border: 1px solid var(--gray-300);
  color: var(--gray-500);
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
}
.item-row .item-remove:hover { border-color: var(--red); color: var(--red); }
.item-row .item-amount {
  color: var(--green);
  font-weight: 700;
  font-family: monospace;
  margin-left: 8px;
}

/* 品名 + 範本選擇器 (higher specificity to override .field select) */
.name-with-preset {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  align-items: stretch;
}
.field select.preset-select,
select.preset-select {
  min-width: 160px;
  color: var(--gray-500);
  cursor: pointer;
  font-size: 13px;
  font-style: italic;
  background: var(--gray-50) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>") no-repeat right 10px center;
  padding-right: 30px;
  border: 1px dashed var(--gray-300);
  transition: all .15s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}
.field select.preset-select:hover,
select.preset-select:hover {
  background: var(--green-bg);
  color: var(--green);
  border: 1px solid var(--green);
  border-style: solid;
}
select.preset-select option { color: var(--gray-900); font-style: normal; }
select.preset-select option:first-child { color: var(--gray-500); font-style: italic; }

.spec-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 8px;
  padding: 10px;
  background: white;
  border-radius: 4px;
  border: 1px dashed var(--gray-200);
}

/* ========== 按鈕 ========== */
.btn-primary, .btn-secondary, .btn-add {
  padding: 10px 20px;
  border-radius: 6px;
  border: none;
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  transition: all .15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  font-family: inherit;
}
.btn-primary {
  background: var(--green);
  color: white;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: #15803d; box-shadow: var(--shadow); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }

.btn-primary.btn-lg { font-size: 16px; padding: 14px 40px; }
.btn-primary.btn-lg .icon { width: 22px; height: 22px; }

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover { border-color: var(--gray-500); background: var(--gray-50); }

.btn-add {
  background: white;
  color: var(--green);
  border: 1px solid var(--green);
  padding: 6px 14px;
  font-size: 13px;
}
.btn-add:hover { background: var(--green); color: white; }
.btn-add .icon-sm { color: currentColor; }

.link-btn {
  background: transparent; border: none; cursor: pointer;
  font-size: 15px; padding: 4px 6px;
  color: var(--gray-500);
}
.link-btn:hover { color: var(--red); }

/* ========== 金額試算區 ========== */
.totals-preview {
  background: linear-gradient(135deg, var(--gray-50), white);
  border: 1px solid var(--gray-200);
}
.totals-preview .totals-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 14px;
  color: var(--gray-700);
  border-bottom: 1px solid var(--gray-100);
  font-family: monospace;
}
.totals-preview .totals-row:last-child { border-bottom: none; }
.totals-preview .totals-row.grand {
  background: var(--gray-50);
  border: 2px solid var(--gray-200);
  border-radius: 6px;
  padding: 14px 16px;
  margin-top: 10px;
  font-size: 22px;
  font-weight: 800;
  color: var(--gray-500);
  transition: all .2s ease;
}
/* 有金額才亮綠 */
.totals-preview .totals-row.grand.has-value {
  background: var(--green-bg);
  border-color: var(--green);
  color: var(--green);
}

/* 金額為 0 時淡化 */
.totals-preview .totals-row .amount-zero {
  color: var(--gray-400, #9ca3af);
  font-weight: 400;
}

.submit-bar {
  text-align: center;
  padding: 24px 0;
}

/* ========== Modal ========== */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(3px);
}
.modal-content {
  background: white;
  border-radius: var(--radius);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 { font-size: 18px; color: var(--dark); display: flex; align-items: center; margin: 0; }
.close-btn {
  background: transparent; border: none; cursor: pointer;
  width: 32px; height: 32px; border-radius: 4px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--gray-500);
}
.close-btn:hover { background: var(--gray-100); color: var(--dark); }
.modal-body { padding: 20px; overflow-y: auto; }
.result-info {
  background: var(--green-bg);
  border: 1px solid var(--green);
  border-radius: 6px;
  padding: 12px 16px;
  margin-bottom: 14px;
}
.result-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.result-row strong { color: var(--green); font-family: monospace; font-size: 15px; }
.pdf-preview {
  width: 100%;
  height: 500px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  margin-bottom: 14px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* ========== 歷史頁 ========== */
.search-form {
  display: flex;
  gap: 8px;
  align-items: center;
}
.search-form input {
  padding: 8px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 14px;
  width: 240px;
}
.search-form input:focus { outline: none; border-color: var(--green); }

.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.history-table thead th {
  background: var(--gray-100);
  padding: 10px 12px;
  text-align: left;
  font-weight: 700;
  color: var(--gray-700);
  border-bottom: 2px solid var(--gray-300);
  letter-spacing: 0.3px;
}
.history-table tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--gray-100);
}
.history-table tbody tr:hover { background: var(--gray-50); }
.history-table .num { text-align: right; font-variant-numeric: tabular-nums; font-family: monospace; }
.history-table .muted { color: var(--gray-500); font-size: 12px; }
.history-table .actions-col { text-align: center; }
.history-table .actions-col a, .history-table .actions-col button {
  display: inline-block;
  margin: 0 2px;
  font-size: 16px;
  text-decoration: none;
}
.empty-state {
  text-align: center;
  padding: 40px 20px;
}
.empty-state p {
  color: var(--gray-500);
  font-size: 16px;
  margin-bottom: 16px;
}

/* ========== 響應式 ========== */
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-date, .spec-grid, .name-with-preset { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .topnav { padding: 10px 16px; }
  .brand span:last-child { display: none; }
  .container { padding: 0 12px; margin: 12px auto; }
  .history-table { font-size: 12px; }
  .history-table thead th, .history-table tbody td { padding: 6px 8px; }
  .btn-primary.btn-lg { width: 100%; }
}
