:root {
  --green: #1f6f43;
  --green-dark: #17553a;
  --green-light: #e7f3ec;
  --bg: #f2f4f3;
  --card: #fff;
  --text: #1c1c1c;
  --muted: #6b7280;
  --line: #dde2df;
  --red: #c0392b;
  --yellow: #b7791f;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: normal; font-size: 14px; }

/* 頂部 */
.topbar {
  position: sticky; top: 0; z-index: 10; background: var(--green); color: #fff;
  padding: 10px 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar .title {
  font-weight: bold; font-size: 18px; flex: 1; min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar .back {
  border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 26px; line-height: 1;
  width: 40px; height: 40px; border-radius: 10px; flex: none;
}
.save-status { font-size: 13px; white-space: nowrap; opacity: .9; flex: none; }
.save-status.error { background: #fff; color: var(--red); padding: 2px 8px; border-radius: 10px; opacity: 1; }

.seg { display: flex; border-radius: 10px; padding: 3px; }
.seg.light { background: #edf1ee; margin-bottom: 14px; }
.seg button {
  flex: 1; border: 0; background: transparent; color: var(--muted); padding: 10px 12px; border-radius: 8px;
  font-size: 16px; font-family: inherit;
}
.seg button.on { background: #fff; color: var(--green); font-weight: bold; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* 案件列表 */
.case-item {
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; margin-bottom: 10px; cursor: pointer;
}
.case-item:active { background: var(--green-light); }
.case-name { font-size: 18px; font-weight: bold; margin-bottom: 4px; }
.case-meta { font-size: 14px; color: var(--muted); }
.small-note { font-size: 13px; margin: 8px 0 0; }

main { padding: 12px 12px 150px; max-width: 720px; margin: 0 auto; }
.card { background: var(--card); border-radius: 12px; padding: 16px; margin-bottom: 12px; box-shadow: 0 1px 3px rgba(0,0,0,.06); }
.card h2 { font-size: 17px; margin: 0 0 12px; }
.row { display: flex; gap: 8px; margin-bottom: 12px; }
.row .btn { flex: 1; }

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 10px;
  padding: 11px 14px; font-size: 16px; font-family: inherit; cursor: pointer; min-height: 46px;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; font-weight: bold; }
.btn.primary:disabled { background: #9db5a7; border-color: #9db5a7; }
.btn.big { font-size: 18px; min-height: 54px; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 15px; }
.btn.block { display: flex; width: 100%; }
.btn.danger-ghost { color: var(--red); border-color: #f0c9c4; }

/* 欄位 */
.field-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field.wide { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .desc-input {
  width: 100%; border: 1px solid var(--line); border-radius: 8px; padding: 10px;
  font-size: 16px; font-family: inherit; background: #fff;
}
.field input:focus, .desc-input:focus { outline: 2px solid var(--green); border-color: transparent; }

/* 照片格 */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin-top: 12px; }
.ph { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: #ddd; }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .num {
  position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.6); color: #fff;
  font-size: 12px; padding: 1px 6px; border-radius: 10px;
}
.ph .del {
  position: absolute; top: 2px; right: 2px; width: 30px; height: 30px; border: 0; border-radius: 50%;
  background: rgba(0,0,0,.55); color: #fff; font-size: 16px; line-height: 1;
}
.ph.used img { opacity: .35; }
.ph.used::after {
  content: "已使用"; position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  background: var(--green); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 10px;
  white-space: nowrap;
}
.ph .portrait {
  position: absolute; bottom: 4px; left: 4px; background: var(--yellow); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 10px;
}
.ph .where {
  position: absolute; bottom: 4px; right: 4px; background: rgba(31,111,67,.92); color: #fff;
  font-size: 11px; padding: 1px 6px; border-radius: 10px; white-space: nowrap;
}
.ph.current { outline: 3px solid var(--green); outline-offset: -3px; }
.ph.current img { opacity: .5; }
.picker-group { grid-column: 1 / -1; font-size: 14px; color: var(--muted); margin-top: 6px; }
.upload-status { font-size: 14px; color: var(--green); margin-top: 8px; min-height: 1em; }
.empty-hint { color: var(--muted); font-size: 14px; text-align: center; padding: 16px 0; grid-column: 1 / -1; }

/* 頁面卡片 */
.page { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.page-head b { font-size: 16px; }
.page-head .tools { display: flex; gap: 4px; }
.page-head .tools button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px; width: 38px; height: 34px; font-size: 15px;
}
.slot { margin-bottom: 12px; }
.slot:last-child { margin-bottom: 0; }
.slot-label { font-size: 14px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.slot-frame {
  width: 100%; border: 2px dashed #b9c4be; border-radius: 8px; background: #f7f9f8;
  display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted); font-size: 15px;
}
.slot-frame.filled { border: 1px solid var(--line); background: #000; }
.slot-frame canvas { width: 100%; height: 100%; display: block; }
.desc-input { margin-top: 6px; }

.clarity { font-size: 13px; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.clarity.good { background: var(--green-light); color: var(--green); }
.clarity.ok { background: #fdf3e1; color: var(--yellow); }
.clarity.bad { background: #fbe6e3; color: var(--red); }

/* 底部 */
.bottom-bar {
  position: fixed; left: 0; right: 0; bottom: 0; background: #fff; border-top: 1px solid var(--line);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); z-index: 20;
}
.bottom-bar > * { max-width: 720px; margin-left: auto; margin-right: auto; }
.gen-result { margin-bottom: 8px; font-size: 15px; }
.gen-result:empty { display: none; }
.gen-result a {
  display: flex; justify-content: center; padding: 12px; border-radius: 10px;
  background: var(--green-light); color: var(--green); font-weight: bold; text-decoration: none;
}

/* 底部抽屜 */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; background: #fff;
  border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.25);
  max-height: 80vh; overflow-y: auto; padding: 12px 12px calc(16px + env(safe-area-inset-bottom));
}
.sheet.small { display: flex; flex-direction: column; gap: 8px; }
.sheet-head { display: flex; justify-content: space-between; align-items: center; font-weight: bold; position: sticky; top: -12px; background: #fff; padding: 4px 0 8px; }

/* 裁切編輯器 */
.editor { position: fixed; inset: 0; z-index: 50; background: #111; display: flex; flex-direction: column; color: #fff; }
.editor-top, .editor-bottom, .editor-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; }
.editor-tools { justify-content: center; }
.editor-tools .btn { background: #2a2a2a; border-color: #444; color: #fff; flex: 1; }
.editor-bottom { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
.editor-stage { flex: 1; min-height: 0; position: relative; }
.editor-stage img { display: block; max-width: 100%; }
.toggle { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.toggle input { width: 22px; height: 22px; accent-color: var(--green); }

/* 大圖 */
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.92); display: flex; align-items: center; justify-content: center; }
.viewer img { max-width: 100%; max-height: 100%; }

/* 忙碌遮罩、提示 */
.busy { position: fixed; inset: 0; z-index: 80; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; }
.busy-box { background: #fff; padding: 20px 28px; border-radius: 12px; font-size: 17px; }
.toast {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%); z-index: 90;
  background: rgba(0,0,0,.85); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 15px;
  opacity: 0; pointer-events: none; transition: opacity .2s; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

/* 登入 */
.login-body { display: flex; min-height: 100vh; align-items: center; justify-content: center; padding: 16px; }
.login-card { background: #fff; padding: 28px 22px; border-radius: 14px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { margin: 0; color: var(--green); }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-size: 18px; }
.err { color: var(--red); margin: 0; min-height: 1em; }

@media (max-width: 380px) {
  .topbar .title { font-size: 16px; }
  .seg button { padding: 7px 8px; font-size: 14px; }
}
