/* =============================================
   style.css — 克里斯個人事業管理 APP
   大地色系 / 手機優先
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+TC:wght@300;400;500;600;700&display=swap');

:root {
  --cream:      #FAF7F2;
  --white:      #FFFFFF;
  --primary:    #6B4F3E;
  --primary-h:  #533C2E;
  --tan:        #C4A882;
  --tan-light:  #EDE0D0;
  --tan-bg:     #F5EEE3;
  --border:     #E2D4C5;
  --text:       #2C1F17;
  --muted:      #9B8675;
  --green:      #5E9E6C;
  --green-bg:   #EEF7F0;
  --red:        #C75050;
  --red-bg:     #FBEDED;
  --amber:      #B8860B;
  --amber-bg:   #FBF5DC;
  --shadow:     0 2px 16px rgba(107,79,62,.10);
  --shadow-lg:  0 4px 24px rgba(107,79,62,.08), 0 1px 4px rgba(107,79,62,.06);
  --r:          14px;
  --r-sm:       8px;
}

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

body {
  font-family: 'Noto Sans TC', sans-serif;
  background: var(--cream);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--primary); text-decoration: none; }

.container { max-width: 720px; margin: 0 auto; padding: 0 16px; }

h1 { font-size: 1.35rem; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
h2 { font-size: 1.05rem; font-weight: 600; color: var(--primary); margin-bottom: 14px; }
h3 { font-size: .95rem; font-weight: 600; margin-bottom: 8px; }

.hidden { display: none !important; }
.muted  { color: var(--muted); }
.center { text-align: center; }
.row    { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.section-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 18px 18px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-lg);
}

/* ── HEADER ─────────────────────────────── */
.site-header {
  background: linear-gradient(160deg, #422A1C 0%, var(--primary) 55%, #7A5A48 100%);
  padding: 22px 16px 18px;
  text-align: center;
  color: #fff;
}
.site-title { font-size: 1.15rem; font-weight: 700; letter-spacing: .05em; }
.site-sub   { font-size: .78rem; color: rgba(255,255,255,.7); margin-top: 4px; letter-spacing: .04em; }

/* ── 表單元件 ───────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group > label.field-label {
  display: block;
  font-size: .85rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 6px;
}
.form-group .hint { font-size: .75rem; color: var(--muted); margin-top: 4px; }

input[type=text], input[type=tel], input[type=email],
input[type=number], input[type=date], input[type=password],
select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--white);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--tan);
  box-shadow: 0 0 0 3px rgba(196,168,130,.18);
}
textarea { resize: vertical; min-height: 80px; }

/* 多選/單選 chip 風格 */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 7px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--white);
  font-size: .85rem;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: all .15s;
}
.chip:hover { border-color: var(--tan); }
.chip.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.chip input { display: none; }

.toggle-group { display: flex; gap: 6px; flex-wrap: wrap; }

/* 行內輸入：「歲開始掉髮，持續幾年」這種 */
.inline-input {
  display: inline-block;
  width: auto;
  min-width: 60px;
  max-width: 90px;
  padding: 4px 8px;
  margin: 0 4px;
}

/* ── 按鈕 ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 18px;
  border: none;
  border-radius: var(--r-sm);
  background: var(--primary);
  color: #fff;
  font-size: .95rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-h); }
.btn:active { transform: scale(.98); }
.btn:disabled { background: var(--muted); cursor: not-allowed; }

.btn-block { width: 100%; }
.btn-secondary {
  background: var(--white);
  color: var(--primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--tan-bg); }

.btn-danger { background: var(--red); }
.btn-danger:hover { background: #A03E3E; }

.btn-sm { padding: 6px 12px; font-size: .85rem; }
.btn-icon { padding: 6px 10px; }

/* ── 提示 ───────────────────────────────── */
.alert {
  padding: 10px 14px;
  border-radius: var(--r-sm);
  font-size: .85rem;
  margin-bottom: 12px;
}
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #cde6d3; }
.alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #f0d2d2; }
.alert-info    { background: var(--tan-bg);   color: var(--primary); border: 1px solid var(--border); }

/* ── 登入頁 ────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-box {
  background: var(--white);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
}
.login-logo { font-size: 2.2rem; margin-bottom: 8px; }
.login-title { font-size: 1.05rem; font-weight: 700; color: var(--primary); margin-bottom: 4px; }
.login-sub { font-size: .82rem; color: var(--muted); margin-bottom: 22px; }
.pin-input {
  text-align: center;
  font-size: 1.5rem;
  letter-spacing: .8rem;
  padding: 14px 12px;
  margin-bottom: 14px;
}

/* ── 後台分頁 ─────────────────────────── */
.admin-header {
  background: linear-gradient(160deg, #422A1C 0%, var(--primary) 100%);
  color: #fff;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.admin-header-title { font-weight: 600; font-size: 1rem; flex: 1; }
.btn-logout {
  background: rgba(255,255,255,.15);
  color: #fff;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: .8rem;
  cursor: pointer;
}
.btn-logout:hover { background: rgba(255,255,255,.25); }

.admin-tabs {
  display: flex;
  background: var(--white);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 0;
  z-index: 10;
  -webkit-overflow-scrolling: touch;
}
.tab-btn {
  flex: 0 0 auto;
  padding: 12px 16px;
  border: none;
  background: none;
  font-size: .9rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-family: inherit;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}
.tab-content { display: none; padding: 14px 16px; }
.tab-content.active { display: block; }

/* ── 列表卡片（客戶/營收/產品） ─────── */
.list-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .1s;
  border: 1px solid transparent;
}
.list-card:hover { border-color: var(--tan); }
.list-card:active { transform: scale(.99); }

.lc-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.lc-name { font-weight: 600; font-size: 1rem; flex: 1; }
.lc-meta { font-size: .8rem; color: var(--muted); }
.lc-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 500;
  background: var(--tan-bg);
  color: var(--primary);
}
.lc-badge.green { background: var(--green-bg); color: var(--green); }
.lc-badge.amber { background: var(--amber-bg); color: var(--amber); }
.lc-badge.red   { background: var(--red-bg);   color: var(--red); }

/* ── 搜尋/工具列 ─────────────────────── */
.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.search-box {
  flex: 1;
  min-width: 200px;
}
.search-box input { padding: 9px 12px 9px 36px; background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%239B8675' viewBox='0 0 16 16'><path d='M11.742 10.344a6.5 6.5 0 1 0-1.397 1.398h-.001c.03.04.062.078.098.115l3.85 3.85a1 1 0 0 0 1.415-1.414l-3.85-3.85a1.007 1.007 0 0 0-.115-.1zM12 6.5a5.5 5.5 0 1 1-11 0 5.5 5.5 0 0 1 11 0z'/></svg>") no-repeat 12px center var(--white); background-size: 14px; }

/* ── 統計卡片 ─────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.stat-label { font-size: .75rem; color: var(--muted); margin-bottom: 4px; }
.stat-value { font-size: 1.4rem; font-weight: 700; color: var(--primary); }
.stat-sub { font-size: .7rem; color: var(--muted); margin-top: 2px; }

/* ── Modal ────────────────────────────── */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(44,31,23,.55);
  z-index: 100;
  display: flex; align-items: flex-end;
  justify-content: center;
  animation: fadeIn .15s;
}
.modal-mask.center { align-items: center; padding: 16px; }
.modal-box {
  background: var(--white);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  border-radius: var(--r) var(--r) 0 0;
  display: flex; flex-direction: column;
  animation: slideUp .2s;
}
.modal-mask.center .modal-box { border-radius: var(--r); }
.modal-header {
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.modal-header h2 { margin: 0; flex: 1; }
.modal-close {
  border: none; background: none;
  font-size: 1.4rem; cursor: pointer; color: var(--muted);
  width: 32px; height: 32px; border-radius: 50%;
}
.modal-close:hover { background: var(--tan-bg); }
.modal-body { padding: 16px 18px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  display: flex; gap: 8px; justify-content: flex-end;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── 諮詢表分節 ───────────────────────── */
.form-section {
  background: var(--tan-bg);
  border-radius: var(--r-sm);
  padding: 14px 14px 12px;
  margin: 18px 0 10px;
}
.form-section-title {
  font-size: .9rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 10px;
}

/* 客戶端諮詢表完成頁 */
.thanks-screen {
  text-align: center;
  padding: 60px 24px;
}
.thanks-icon { font-size: 3rem; margin-bottom: 14px; }
.thanks-title { font-size: 1.2rem; font-weight: 700; color: var(--primary); margin-bottom: 8px; }
.thanks-sub { color: var(--muted); }

/* ── QR Code ─────────────────────────── */
.qr-wrap {
  text-align: center;
  padding: 18px;
  background: var(--white);
  border-radius: var(--r);
}
.qr-wrap canvas, .qr-wrap img {
  max-width: 240px;
  width: 100%;
  height: auto;
}
.qr-url {
  font-size: .82rem;
  color: var(--muted);
  margin-top: 12px;
  word-break: break-all;
  background: var(--tan-bg);
  padding: 8px 12px;
  border-radius: var(--r-sm);
}

/* ── 表格（手機友善） ─────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
.data-table th, .data-table td {
  padding: 10px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.data-table th {
  font-weight: 600;
  color: var(--muted);
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover { background: var(--tan-bg); }

/* ── Stock badge ───────────────────── */
.stock-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-weight: 600;
  font-size: .85rem;
}
.stock-ok   { background: var(--green-bg); color: var(--green); }
.stock-low  { background: var(--amber-bg); color: var(--amber); }
.stock-zero { background: var(--red-bg);   color: var(--red); }

/* ── Loading ───────────────────────── */
.loading {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty {
  text-align: center;
  padding: 50px 20px;
  color: var(--muted);
}
.empty-icon { font-size: 2.5rem; margin-bottom: 8px; opacity: .5; }

/* ── RWD ─────────────────────────────── */
@media (min-width: 720px) {
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── 客戶詳情頁 ─────────────────────── */
.modal-wide .modal-box { max-width: 760px; }

.cd-info {
  padding: 4px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.cd-name { font-size: 1.35rem; font-weight: 700; color: var(--text); }
.cd-meta {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  margin-top: 6px; font-size: .9rem;
}
.cd-meta a { color: var(--primary); }
.cd-note {
  background: var(--tan-bg);
  padding: 8px 12px;
  border-radius: var(--r-sm);
  margin-top: 10px;
  font-size: .85rem;
  color: var(--text);
  line-height: 1.5;
}
.cd-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px;
}

.cd-history-wrap h3 {
  font-size: 1rem; font-weight: 600; color: var(--primary);
  margin-bottom: 10px;
}

/* 歷史照片矩陣（每列 = 一次 session） */
.ph-row {
  display: grid;
  grid-template-columns: minmax(76px, 110px) 1fr;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 12px;
}
.ph-row-th { margin-bottom: 6px; }
.ph-row-th .ph-row-cells { padding-top: 0; padding-bottom: 0; }
.ph-row-head {
  position: relative;
  padding: 4px 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.ph-row-date {
  font-size: .85rem; font-weight: 600; color: var(--primary);
}
.ph-row-note {
  font-size: .72rem; color: var(--muted); line-height: 1.3;
  word-break: break-word;
}
.ph-row-del {
  position: absolute; top: 0; right: 0;
  background: transparent; border: none; cursor: pointer;
  font-size: .85rem; color: var(--muted); padding: 2px 4px;
  border-radius: 4px;
}
.ph-row-del:hover { background: var(--red-bg); color: var(--red); }
.ph-row-cells {
  display: grid;
  grid-template-columns: repeat(var(--cols, 5), 1fr);
  gap: 4px;
}
.ph-cell {
  aspect-ratio: 1;
  background: var(--tan-bg);
  border-radius: 6px;
  overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; color: var(--muted);
}
.ph-th {
  background: transparent;
  font-weight: 600; color: var(--primary);
  font-size: .8rem;
  aspect-ratio: auto;
  padding: 0;
}
.ph-empty { background: var(--cream); }
.ph-thumb {
  width: 100%; height: 100%;
  object-fit: cover;
  cursor: zoom-in;
  transition: transform .15s;
}
.ph-thumb:hover { transform: scale(1.04); }

/* 上傳照片 grid */
.ph-upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
}
.ph-slot {
  display: block;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.ph-slot-inner {
  position: relative;
  aspect-ratio: 1;
  border: 2px dashed var(--border);
  border-radius: var(--r-sm);
  background: var(--cream);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  overflow: hidden;
}
.ph-slot.filled .ph-slot-inner {
  border-style: solid;
  border-color: var(--primary);
  background: #000;
}
.ph-slot-label {
  position: absolute; top: 4px; left: 4px;
  background: rgba(255,255,255,.92);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .78rem; font-weight: 600;
  color: var(--primary);
  z-index: 2;
  pointer-events: none;
}
.ph-slot.filled .ph-slot-label {
  background: rgba(255,255,255,.85);
}
.ph-slot-preview { position: absolute; inset: 0; }
.ph-slot-preview img {
  width: 100%; height: 100%; object-fit: cover;
}
.ph-slot-hint {
  font-size: .75rem; color: var(--muted);
  z-index: 1;
}
.ph-slot.filled .ph-slot-hint {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,.55); color: #fff;
  padding: 3px 4px;
  text-align: center;
  font-size: .7rem;
  z-index: 2;
}

/* ── 燈箱 ────────────────────────────── */
.lightbox-mask {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  z-index: 300;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  cursor: zoom-out;
  animation: fadeIn .15s;
}
.lightbox-mask img {
  max-width: 100%; max-height: 100%;
  object-fit: contain;
  border-radius: 6px;
}
.lightbox-hint {
  position: absolute; bottom: 20px; left: 0; right: 0;
  text-align: center; color: rgba(255,255,255,.6);
  font-size: .8rem;
}

/* ── 馬賽克編輯器 ─────────────────────── */
.mos-canvas-wrap {
  background: #1a1208;
  padding: 6px;
  border-radius: var(--r-sm);
  text-align: center;
  overflow: auto;
  max-height: 60vh;
}
.mos-canvas-wrap canvas {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  touch-action: none;
  cursor: crosshair;
  user-select: none;
}
