/* 晴天主題：天藍＋白底 */
:root {
  --sky: #2E8BC0;        /* 主色天藍 */
  --sky-dark: #1F6F9C;   /* 深一階，用在選中狀態 */
  --sky-light: #E8F4FB;  /* 淡天藍，用在背景區塊 */
  --bg: #FFFFFF;
  --text: #333333;
  --muted: #6B7785;
  --border: #D6E6F0;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

.layout { display: flex; min-height: 100vh; }

/* 左側選單 */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sky);
  color: #fff;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  padding: 24px 0;
}
.brand { font-size: 18px; font-weight: 700; padding: 0 24px 20px; }
.menu { list-style: none; }
.menu a {
  display: block;
  padding: 12px 24px;
  color: #fff;
  text-decoration: none;
  font-size: 15px;
}
.menu a:hover { background: rgba(255, 255, 255, 0.12); }
.menu a.active { background: var(--sky-dark); font-weight: 700; }

/* 右側主畫面 */
.main { margin-left: 220px; flex: 1; padding: 32px 40px; }
.main h1 { font-size: 24px; color: var(--sky-dark); margin-bottom: 20px; }
.card {
  background: var(--sky-light);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.placeholder { color: var(--muted); }

/* 手機寬度：選單收成上方橫列 */
@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar {
    position: sticky;
    width: 100%;
    padding: 12px 0 0;
    z-index: 10;
  }
  .brand { padding: 0 16px 8px; font-size: 16px; }
  .menu { display: flex; overflow-x: auto; white-space: nowrap; }
  .menu a { padding: 10px 14px; font-size: 14px; }
  .main { margin-left: 0; padding: 20px 16px; }
}

/* ========== Step 3：客人列表、編輯表單、暫訂名單 ========== */
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.error-text { color: #C0392B; font-weight: 600; }
.overdue { color: #C0392B; font-weight: 700; }

/* 按鈕 */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
  cursor: pointer;
}
.btn.primary { background: var(--sky); border-color: var(--sky); color: #fff; }
.btn.primary:hover { background: var(--sky-dark); }
.btn.danger { color: #C0392B; border-color: #E8B4AE; margin-left: auto; }

/* 篩選列 */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; align-items: center; }
.toolbar input[type="search"] { flex: 1 1 260px; }
.toolbar input, .toolbar select, .field input, .field select, .field textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
  font-family: inherit;
}
#list-count { margin-bottom: 8px; font-size: 13px; }

/* 表格 */
.data-table { width: 100%; border-collapse: collapse; background: #fff; font-size: 14px; }
.data-table th, .data-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
.data-table th { background: var(--sky-light); color: var(--sky-dark); white-space: nowrap; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: #F3F9FD; }

/* 小標籤 */
.badge { display: inline-block; font-size: 12px; padding: 1px 6px; border-radius: 4px; margin-right: 4px; }
.badge.ok { background: #E3F4E8; color: #2E7D46; }
.badge.warn { background: #FCE8E6; color: #B03A2E; }
.status { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.status.tentative { background: #FFF4D6; color: #8A6200; }
.status.booked { background: var(--sky-light); color: var(--sky-dark); }
.status.departed { background: #E3F4E8; color: #2E7D46; }
.status.cancelled { background: #EEEEEE; color: #777; }

/* 手機卡片 */
.card-list { display: flex; flex-direction: column; gap: 10px; }
.customer-card {
  display: block;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  color: var(--text);
  text-decoration: none;
}
.cc-top { margin-bottom: 4px; }
.mobile-only { display: none; }

/* 編輯表單 */
.section { border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 16px; margin: 14px 0; }
.section legend { padding: 0 6px; font-weight: 700; color: var(--sky-dark); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px 16px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field.wide { grid-column: 1 / -1; }
.field input, .field select, .field textarea { color: var(--text); width: 100%; }
.field input[hidden] { display: none; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; padding-top: 18px; }
.actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.companion-row { border-top: 1px dashed var(--border); padding-top: 10px; margin-bottom: 10px; }
.pay-batch { margin-top: 12px; }
.pay-batch .batch-amt { width: 120px; text-align: right; }

/* 付款紀錄／費用試算 */
.sub-title { font-size: 15px; color: var(--sky-dark); margin: 4px 0 10px; }
.sum-table { border-collapse: collapse; margin-bottom: 14px; font-size: 14px; }
.sum-table th { text-align: left; font-weight: 400; color: var(--muted); padding: 4px 24px 4px 0; white-space: nowrap; }
.sum-table td { text-align: right; padding: 4px 0; font-variant-numeric: tabular-nums; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.btn.small-btn { padding: 2px 8px; font-size: 12px; }
.danger-text { color: #C0392B; }
.check.inline { padding-top: 0; }
#pay-form { margin-top: 0; }
#pay-list, #balance-section { overflow-x: auto; }
.btn[hidden] { display: none; }

/* ========== Step 6：業績與薪水 ========== */
.stat-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 24px; font-weight: 700; color: var(--sky-dark); font-variant-numeric: tabular-nums; margin: 2px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }
.perf-scroll { overflow-x: auto; }
.perf-table { font-size: 13px; }
.perf-table th, .perf-table td { padding: 6px 8px; white-space: nowrap; }
.perf-table tbody th { background: #fff; color: var(--text); font-weight: 600; position: sticky; left: 0; }
.perf-table thead th:first-child { position: sticky; left: 0; z-index: 1; }
.perf-table .month-th button { border: none; background: none; color: var(--sky-dark); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline dotted; }
.perf-table .open { background: #FFF8E6; }
.perf-table thead th.open { background: #FFE9B3; }
.perf-table td.editable { cursor: pointer; color: var(--sky-dark); }
.perf-table td.editable:hover { background: #E8F4FB; outline: 1px dashed var(--sky); }
.perf-table .total { font-weight: 700; background: #F7FBFE; }
.perf-table tr.strong th, .perf-table tr.strong td { font-weight: 700; border-top: 2px solid var(--border); }
.perf-table tr.minor th, .perf-table tr.minor td { color: var(--muted); font-size: 12px; }
.perf-table td.quarter { text-align: center; }
.edit-hint { color: var(--sky); font-weight: 400; font-size: 12px; }
.cell-input { width: 80px; padding: 2px 4px; font-size: 13px; text-align: right; border: 1px solid var(--sky); border-radius: 4px; }
tr.not-counted td { color: #999; text-decoration: line-through; }
tr.not-counted td:last-child { text-decoration: none; }
#perf-month .section { margin-top: 14px; }
@media (max-width: 900px) {
  .stat-cards { grid-template-columns: repeat(2, 1fr); }
  .stat-value { font-size: 20px; }
}

/* ========== Step 7：今日待辦 ========== */
.stat-cards.three { grid-template-columns: repeat(3, 1fr); }
.todo-list { list-style: none; display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.todo-item {
  display: flex; align-items: center; gap: 12px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; cursor: pointer;
}
.todo-item:hover { background: #F3F9FD; }
.todo-main { flex: 1; min-width: 0; }
.todo-title { font-weight: 600; overflow-wrap: anywhere; }
.todo-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.todo-members { margin-top: 6px; font-size: 13px; display: block; overflow-x: auto; }
.todo-members td, .todo-members th { white-space: nowrap; }

/* 設定頁：每日提醒規則（手機寬改成一條一張卡，不用左右滑） */
.rule-notes { margin: 0 0 10px; padding-left: 20px; line-height: 1.7; }
.rule-table td { vertical-align: top; font-size: 13px; }
.rule-table td:first-child, .rule-table td:nth-child(2), .rule-table td:last-child { white-space: nowrap; }
@media (max-width: 767px) {
  .rule-table thead { display: none; }
  .rule-table, .rule-table tbody, .rule-table tr, .rule-table td { display: block; width: 100%; }
  .rule-table tr { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 10px; padding: 6px 10px; }
  .rule-table td { border: none; padding: 3px 0; white-space: normal !important; }
  .rule-table td::before { content: attr(data-label) "："; color: var(--muted); }
  .rule-table td:first-child::before, .rule-table td:nth-child(2)::before { content: ""; }
  .rule-table td:first-child, .rule-table td:nth-child(2) { display: inline; width: auto; font-size: 15px; }
  .rule-table td:first-child { margin-right: 6px; }
}
.rule-no { color: var(--sky-dark); }
.urgency { flex-shrink: 0; font-size: 12px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.urgency.u1 { background: #FCE8E6; color: #B03A2E; }
.urgency.u2 { background: #FFF4D6; color: #8A6200; }
.urgency.u3 { background: var(--sky-light); color: var(--sky-dark); }
.todo-done { flex-shrink: 0; display: flex; align-items: center; gap: 4px; font-size: 14px; cursor: pointer; white-space: nowrap; }
#today-msg { margin-top: 6px; }
@media (max-width: 767px) {
  .stat-cards.three { grid-template-columns: 1fr; gap: 8px; }
  .stat-cards.three .stat-card { padding: 10px 14px; }
  .todo-item { flex-wrap: wrap; gap: 6px 10px; }
  .todo-done { margin-left: auto; }
  .todo-main { flex-basis: 100%; order: 3; }
}

/* ========== Step 5：尾款單與切結書（A4 正式文件：黑白為主，只有標題列用天藍）========== */
.doc-toolbar input[type="search"] { flex: 1 1 280px; }
.seg { display: inline-flex; gap: 0; }
.seg .btn { border-radius: 0; }
.seg .btn:first-child { border-radius: 6px 0 0 6px; }
.seg .btn:last-child { border-radius: 0 6px 6px 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
#doc-msg p { margin-bottom: 6px; }

/* 螢幕預覽：灰底上放一張白色 A4（210mm 寬；內距 12mm 等同列印邊界） */
.doc-preview { background: #E9EDF0; padding: 20px; border-radius: 8px; overflow-x: auto; }
.doc-sheet {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 12mm;
  background: #fff;
  color: #000;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
  font-size: 9.5pt;
  line-height: 1.35;
}
.doc-head {
  text-align: center;
  border-bottom: 2.5pt solid var(--sky);
  padding-bottom: 2mm;
  margin-bottom: 3mm;
}
.doc-head h2 { font-size: 15pt; color: var(--sky-dark); letter-spacing: 0.5pt; }
.doc-sub { white-space: pre-wrap; font-size: 10pt; margin-top: 1mm; }
.doc-brand { font-size: 10pt; letter-spacing: 2pt; margin-bottom: 1mm; }
.doc-lead { margin: 2mm 0; }
.doc-table { width: 100%; border-collapse: collapse; margin-bottom: 2mm; }
.doc-table th, .doc-table td { border: 0.75pt solid #000; padding: 0.7mm 2mm; text-align: left; vertical-align: middle; }
.doc-table th { background: #F2F2F2; font-weight: 600; white-space: nowrap; }
.doc-info th { width: 26mm; }
.doc-fee th:first-child { width: 44mm; }
.doc-fee thead th { text-align: center; }
.doc-fee .num { text-align: right; width: 34mm; font-variant-numeric: tabular-nums; }
.doc-fee tr.strong th, .doc-fee tr.strong td { font-weight: 700; font-size: 11pt; }
.doc-fee tr.pay-line td { font-size: 9pt; color: #444; padding-top: 1px; padding-bottom: 1px; }
.doc-fee tr.pay-line td:not(.num) { padding-left: 6mm; }
.doc-fee tr.pay-sum td { font-weight: 600; color: inherit; }
.doc-sec { font-size: 10.5pt; margin: 2.5mm 0 1mm; }
.doc-form col.c-th { width: 26mm; }
.doc-form td { height: 6.5mm; }
.doc-form tr.tall td { height: 10mm; }
.doc-small { font-size: 8.5pt; }
.blank { display: inline-block; width: 60mm; }
.doc-end { margin-top: 4mm; text-align: center; }
.doc-terms p { white-space: pre-wrap; margin-bottom: 1.5mm; }
.doc-terms .t-title { font-weight: 700; font-size: 11pt; margin-top: 3mm; }
.doc-terms .t-item { padding-left: 4mm; text-indent: -4mm; }
.doc-terms .t-sign { margin: 12mm 0 8mm; }
.doc-terms .t-note { font-weight: 700; margin-top: 4mm; border-top: 0.75pt solid #000; padding-top: 2mm; }
.doc-cut { border: none; border-top: 0.75pt dashed #000; margin: 4mm 0; }

/* 列印：只印單據，選單、標題、操作列都藏起來 */
@page { size: A4; margin: 12mm; }
@media print {
  body { background: #fff; }
  .sidebar, .main > h1, .doc-toolbar, #doc-msg { display: none !important; }
  .main { margin: 0; padding: 0; }
  #page-body.card { background: none; border: none; padding: 0; border-radius: 0; }
  .doc-preview { background: none; padding: 0; overflow: visible; }
  /* 左右留 0.5mm：表格外框線有一半畫在表格外，貼齊邊界會被裁掉 */
  .doc-sheet { width: auto; min-height: 0; padding: 0 0.5mm; margin: 0; box-shadow: none; }
  .doc-sheet, .doc-sheet * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

@media (max-width: 767px) {
  .desktop-only { display: none; }
  .mobile-only { display: flex; }
  .card { padding: 14px; }
  .grid { grid-template-columns: 1fr; }
  .check { padding-top: 0; }
}
