/* ===== 主題變數 ===== */
:root {
  --bg:         #0f1419;
  --bg2:        #161c25;
  --bg3:        #1f2733;
  --border:     #2a3441;
  --border2:    #3a4555;
  --text:       #e5ecf3;
  --text-mid:   #a5b3c4;
  --text-dim:   #6e7d92;
  --accent:     #c8a96e;
  --accent-dim: #b8995e;
  --accent-bg:  rgba(200, 169, 110, 0.14);
  --success:    #10b981;
  --warn:       #f59e0b;
  --error:      #ef4444;
  --shadow:     0 4px 16px rgba(0,0,0,0.3);

  --radius:     12px;
  --radius-sm:  8px;
  --space:      16px;
  --header-h:   56px;
  --bottom-h:   64px;
}

/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: 'Noto Sans TC', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}
button, input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }

/* ===== App shell ===== */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
  padding-bottom: var(--bottom-h);
}

/* ===== 頂部 header ===== */
.header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 var(--space);
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header h1 {
  font-size: 17px;
  font-weight: 500;
  flex: 1;
}
.header .back-btn {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  color: var(--text-mid);
  margin-left: -8px;
}
.header .back-btn:hover { background: var(--bg3); }
.header .right-btn {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 14px;
}

/* ===== 內容區 ===== */
.content {
  padding: var(--space);
}

/* ===== 搜尋列 ===== */
.search-box {
  position: relative;
  margin-bottom: var(--space);
}
.search-box input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px 12px 40px;
  outline: none;
  transition: border-color 0.15s;
}
.search-box input:focus { border-color: var(--accent); }
.search-box::before {
  content: '🔍';
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  opacity: 0.6;
}

/* ===== 客戶清單 ===== */
.customer-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.customer-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  gap: 14px;
  align-items: center;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
}
.customer-item:active { transform: scale(0.98); }
.customer-item:hover { border-color: var(--border2); }
.customer-avatar {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 500;
  font-size: 16px;
}
.customer-info {
  flex: 1;
  min-width: 0;
}
.customer-name {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 2px;
}
.customer-meta {
  font-size: 13px;
  color: var(--text-dim);
  display: flex;
  gap: 10px;
}
.customer-meta span:not(:first-child)::before {
  content: '·';
  margin-right: 10px;
  color: var(--border2);
}

/* ===== 空狀態 ===== */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
}
.empty-icon { font-size: 48px; margin-bottom: 16px; opacity: 0.4; }
.empty-text { font-size: 14px; }

/* ===== Loading ===== */
.loading {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-dim);
  font-size: 14px;
}
.spinner {
  display: inline-block;
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== FAB（浮動新增按鈕） ===== */
.fab {
  position: fixed;
  right: max(calc((100vw - 480px) / 2 + 20px), 20px);
  bottom: calc(var(--bottom-h) + 16px);
  width: 56px; height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow);
  z-index: 5;
  transition: transform 0.1s;
}
.fab:active { transform: scale(0.92); }

/* ===== 底部 tab bar ===== */
.bottom-bar {
  position: fixed;
  bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px;
  height: var(--bottom-h);
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  z-index: 6;
}
.tab-btn {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  gap: 3px;
  transition: color 0.1s;
}
.tab-btn.active { color: var(--accent); }
.tab-icon { font-size: 20px; line-height: 1; }

/* ===== 表單 ===== */
.form {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-size: 13px;
  color: var(--text-mid);
  display: flex;
  align-items: center;
  gap: 4px;
}
.form-label .required { color: var(--error); }
.form-input,
.form-textarea,
.form-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  outline: none;
  transition: border-color 0.15s;
  width: 100%;
}
.form-input:focus,
.form-textarea:focus,
.form-select:focus { border-color: var(--accent); }
.form-textarea { min-height: 90px; resize: vertical; font-family: inherit; }
.form-actions {
  display: flex;
  gap: 12px;
  margin-top: 8px;
}

/* ===== 按鈕 ===== */
.btn {
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 500;
  transition: opacity 0.1s, transform 0.05s;
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
}
.btn:active { transform: scale(0.98); }
.btn:hover { opacity: 0.92; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-secondary {
  background: var(--bg3);
  color: var(--text);
}
.btn-secondary:hover { background: var(--border); opacity: 1; }
.btn-danger { background: var(--error); }

/* ===== 詳情頁 ===== */
.detail-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--space);
}
.detail-header {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--border);
}
.detail-header .customer-avatar {
  width: 56px; height: 56px;
  font-size: 20px;
}
.detail-name {
  font-size: 20px;
  font-weight: 500;
}
.detail-id {
  font-size: 12px;
  color: var(--text-dim);
  font-family: 'Courier New', monospace;
  margin-top: 2px;
}

.field-row {
  display: flex;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 16px;
}
.field-row:last-child { border-bottom: none; }
.field-label {
  width: 80px;
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.field-value {
  flex: 1;
  font-size: 15px;
  word-break: break-word;
  white-space: pre-wrap;
}
.field-value.empty-value { color: var(--text-dim); font-style: italic; }

/* ===== Tabs（Phase 1 暫只有基本資料 tab） ===== */
.tabs {
  display: flex;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space);
  overflow: hidden;
}
.tab {
  flex: 1;
  padding: 11px 8px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  border-right: 1px solid var(--border);
  transition: all 0.15s;
}
.tab:last-child { border-right: none; }
.tab.active { background: var(--accent-bg); color: var(--accent); }
.tab:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: calc(var(--bottom-h) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error   { border-color: var(--error);   color: var(--error); }

/* ===== Password gate ===== */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gate-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.gate-card h2 { font-weight: 500; margin-bottom: 8px; }
.gate-card p  { color: var(--text-dim); font-size: 13px; margin-bottom: 22px; }
.gate-card input { margin-bottom: 14px; }

/* ===== Phase 2: 療程 / 照片相關 ===== */

/* 詳情頁頂部卡片（客戶頭像區）獨立卡 */
.detail-header-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: var(--space);
}
.detail-header-card .detail-header {
  border-bottom: none;
  padding-bottom: 0;
  margin-bottom: 0;
}

/* 療程清單 */
.treatment-list { display: flex; flex-direction: column; gap: 8px; }
.treatment-item {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.05s;
}
.treatment-item:active { transform: scale(0.98); }
.treatment-item:hover  { border-color: var(--border2); }
.treatment-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.treatment-item-name { font-size: 15px; font-weight: 500; }
.treatment-price {
  color: var(--accent);
  font-weight: 500;
  font-family: 'Courier New', monospace;
  font-size: 14px;
}
.treatment-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  gap: 4px;
}

/* 表單：兩欄並排 */
.form-row { display: flex; gap: 12px; }

/* 分隔標題 */
.section-divider {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.section-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-mid);
  letter-spacing: 0.05em;
}
.btn-link {
  color: var(--accent);
  font-size: 13px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}
.btn-link:hover { background: var(--accent-bg); }

/* 成本明細列 */
.cost-row {
  display: grid;
  grid-template-columns: 90px 1fr 90px 28px;
  gap: 8px;
  margin-top: 8px;
  align-items: center;
}
.cost-row .form-select,
.cost-row .form-input {
  padding: 9px 10px;
  font-size: 14px;
}
.cost-row .cost-type   { padding-right: 4px; font-size: 13px; }
.cost-row .cost-amount { text-align: right; font-family: 'Courier New', monospace; }
.btn-icon-del {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg3);
  color: var(--text-dim);
  font-size: 16px;
  line-height: 1;
  display: flex; align-items: center; justify-content: center;
}
.btn-icon-del:hover { background: var(--error); color: #fff; }
.cost-empty {
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  padding: 14px 0;
}

/* 回診日期列 */
.followup-row {
  display: grid;
  grid-template-columns: 56px 1fr 28px;
  gap: 10px;
  align-items: center;
  margin-top: 8px;
}
.followup-label {
  font-size: 13px;
  color: var(--text-mid);
}
.followup-line {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.followup-line:last-of-type { border-bottom: none; }
.followup-num {
  font-size: 12px;
  color: var(--text-dim);
  width: 50px;
  flex-shrink: 0;
}
.followup-date { flex: 1; }
.followup-status {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg3);
  color: var(--text-mid);
  flex-shrink: 0;
}
.followup-status.done {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success);
}

/* 照片區 */
.photo-section { margin-top: 12px; }
.photo-side-label {
  font-size: 13px;
  color: var(--text-mid);
  margin-bottom: 8px;
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.photo-thumb {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg3);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
}
.photo-thumb img {
  width: 100%; height: 100%;
  object-fit: cover;
}
.photo-del {
  position: absolute;
  top: 4px; right: 4px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.photo-buttons {
  display: flex;
  gap: 10px;
}
.photo-btn {
  flex: 1;
  cursor: pointer;
  padding: 10px 12px;
  font-size: 14px;
}

/* 進度遮罩 */
.progress-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
}
.progress-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 32px;
  text-align: center;
  min-width: 240px;
  max-width: 340px;
}
.progress-card .spinner {
  margin-bottom: 12px;
  width: 28px; height: 28px;
  border-width: 3px;
  display: block;
  margin-left: auto; margin-right: auto;
}
.progress-bar {
  height: 4px;
  background: var(--accent);
  border-radius: 2px;
  width: 0;
  transition: width 0.3s ease;
}
#progress-bar-wrap {
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}

/* 療程詳情頁 */
.treatment-title {
  font-size: 22px;
  font-weight: 500;
  margin-bottom: 4px;
}
.treatment-sub {
  font-size: 13px;
  color: var(--text-mid);
  margin-bottom: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-mid);
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.card-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}
.card-title-inline {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-mid);
  flex: 1;
}
.photo-add-btn {
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  color: var(--accent);
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent-bg);
}
.photo-add-btn:hover {
  background: var(--accent-bg);
}
.empty-line { color: var(--text-dim); font-size: 13px; padding: 6px 0; }

.cost-line {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px dashed var(--border);
  font-size: 14px;
}
.cost-line:last-of-type { border-bottom: none; }
.cost-type-tag {
  background: var(--bg3);
  color: var(--text-mid);
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  flex-shrink: 0;
}
.cost-item-name { flex: 1; }
.cost-amount-text {
  font-family: 'Courier New', monospace;
  color: var(--text-mid);
}

.cost-summary {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.cost-summary > div {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  font-size: 14px;
}
.cost-summary > div span:last-child {
  font-family: 'Courier New', monospace;
  font-weight: 500;
}
.cost-summary .profit { font-size: 16px; margin-top: 4px; }
.cost-summary .profit.positive span:last-child { color: var(--success); }
.cost-summary .profit.negative span:last-child { color: var(--error); }

/* ===== 響應式：較大螢幕加邊框 ===== */
@media (min-width: 500px) {
  body { background: #0a0d12; }
  .app {
    background: var(--bg);
    border-left: 1px solid var(--border);
    border-right: 1px solid var(--border);
  }
}
