/* 日報登載（手機優先；平板、電腦也能用） */
:root {
  --primary: #0067b8;
  --dark: #003f73;
  --success: #107c10;
  --danger: #c42b1c;
  --warning: #986f0b;
  --gray: #5f6b7a;
  --bg: #f3f6f9;
  --card: #ffffff;
  --border: #d6dee6;
  --label: #c9f6f4;
  --ink: #1f2328;
  --muted: #5f6b7a;
  --sheet-line: #111;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.6 -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px));
}
button, input, textarea, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }

/* 上方列 */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(135deg, #003f73, #005a9e);
  color: #fff;
  padding: calc(8px + env(safe-area-inset-top, 0px)) max(12px, env(safe-area-inset-right, 0px)) 8px max(12px, env(safe-area-inset-left, 0px));
  box-shadow: 0 2px 8px #0003;
}
.brand { display: flex; align-items: baseline; gap: 10px; font-weight: 800; font-size: 18px; }
.brand-user { font-weight: 400; font-size: 13px; opacity: .85; }
.brand-ver { font-weight: 600; font-size: 12px; opacity: .8; margin-left: -4px; }
.tabs { display: flex; gap: 6px; margin-top: 8px; }
.tabs button {
  flex: 1; min-height: 40px; border: 1px solid #ffffff55; border-radius: 8px;
  background: transparent; color: #fff; font-weight: 700; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.tabs button.active { background: #fff; color: var(--dark); }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #ffb900; color: #3b2a00; font-size: 12px; line-height: 20px; font-weight: 800; }

main { max-width: 980px; margin: 0 auto; padding: 12px max(12px, env(safe-area-inset-right, 0px)) 12px max(12px, env(safe-area-inset-left, 0px)); }
.view { display: none; }
.view.active { display: block; }

/* 按鈕 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--gray); color: #fff; font-weight: 700; font-size: 16px; cursor: pointer;
  text-decoration: none; -webkit-tap-highlight-color: transparent;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.warning { background: var(--warning); }
.btn.ghost { background: #fff; color: var(--dark); border-color: #b8c4d0; }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn:focus-visible, .tabs button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 3px solid #0067b866; outline-offset: 2px; }
.file-btn { position: relative; overflow: hidden; }
.file-btn input[type=file] { position: absolute; top: 0; right: 0; bottom: 0; left: 0; opacity: 0; cursor: pointer; font-size: 0; }

/* 填寫：表頭 */
.form-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.edit-info { font-size: 14px; color: var(--muted); }
.edit-info b { color: var(--ink); }
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 700; line-height: 1.6; white-space: nowrap; }
.chip.draft { background: #e8edf2; color: #394450; }
.chip.exported { background: #fff4ce; color: #5c4400; }
.chip.dirty { background: #fde7e9; color: #8a1c12; }
.chip.shared { background: #dff6dd; color: #0b5a0b; }

/* 工作日誌表格 */
.sheet { background: #fff; border: 3px solid var(--sheet-line); }
.sheet-title { display: flex; border-bottom: 1px solid var(--sheet-line); min-height: 54px; }
.sheet-name { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 800; letter-spacing: 8px; padding-left: 8px; }
.sheet-rows { display: grid; grid-template-columns: 1fr; }
.frow { display: grid; grid-template-columns: 96px 1fr; border-bottom: 1px solid var(--sheet-line); }
.frow:last-child { border-bottom: 0; }
.flabel { display: flex; align-items: center; padding: 8px; background: var(--label); border-right: 1px solid var(--sheet-line); font-weight: 800; font-size: 15px; line-height: 1.3; }
.flabel .req { color: var(--danger); margin-left: 2px; }
.fvalue { padding: 4px 6px; min-width: 0; }
.fvalue input, .fvalue textarea {
  width: 100%; border: 0; background: transparent; padding: 8px 4px; font-size: 16px; outline: none; border-radius: 4px;
}
.fvalue textarea { resize: none; min-height: 64px; overflow: hidden; line-height: 1.5; }
.fvalue input::placeholder, .fvalue textarea::placeholder { color: #8a949e; font-size: 14px; }
.fvalue input:focus, .fvalue textarea:focus { background: #f2f8fd; }
.fvalue select { width: 100%; margin: 3px 0; padding: 8px 6px; font-size: 16px; border: 1px solid #b8c4d0; border-radius: 6px; background: #fff; }
.fvalue select:focus { outline: 2px solid var(--primary); outline-offset: 0; }
.fvalue input.locked { background: #eef2f5; color: #333; cursor: default; }
.frow.has-error .fvalue { box-shadow: inset 0 0 0 2px var(--danger); }
.ferr { color: var(--danger); font-size: 13px; padding: 0 4px 6px; }
.quick { display: flex; flex-wrap: wrap; gap: 6px; padding: 2px 4px 8px; }
.quick button { min-height: 32px; padding: 2px 10px; border: 1px solid #b8c4d0; border-radius: 16px; background: #f8fafc; font-size: 14px; cursor: pointer; }
.quick button.on { background: #e6f2ff; border-color: var(--primary); color: var(--dark); font-weight: 700; }
.warn-text { color: var(--warning); font-size: 14px; margin: 8px 0 0; }

@media (min-width: 720px) {
  .sheet-rows { grid-template-columns: 1fr 1fr; }
  .frow.wide { grid-column: 1 / -1; }
  .frow.left { border-right: 1px solid var(--sheet-line); }
  .frow { grid-template-columns: 104px 1fr; }
}

/* 照片 */
.photos-section, .extra-fields .card-like { margin-top: 16px; }
.photos-section { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px; }
.photos-section h2 { margin: 0 0 10px; font-size: 18px; }
.photo-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.photo-buttons .btn { flex: 1; min-width: 130px; }
.help { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.status { font-weight: 700; color: var(--dark); margin: 6px 0 0; min-height: 1.6em; }
.photo-list { display: grid; grid-template-columns: 1fr; gap: 14px; margin-top: 10px; }
@media (min-width: 560px) { .photo-list { grid-template-columns: 1fr 1fr; } }
.pcard { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff; }
.pframe { position: relative; height: 0; padding-top: 75%; background: #eef1f4; } /* 4:3，舊瀏覽器也支援的寫法 */
.pframe img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: contain; cursor: zoom-in; }
.pframe .pno { position: absolute; left: 8px; bottom: 8px; background: #003f73e6; color: #fff; border-radius: 10px; padding: 0 8px; font-size: 13px; font-weight: 700; }
.ptools { position: absolute; top: 6px; left: 6px; right: 6px; display: flex; justify-content: space-between; }
.ptools .grp { display: flex; gap: 6px; }
.ptools button { width: 40px; height: 40px; border-radius: 50%; border: 0; background: #003f73d9; color: #fff; font-size: 18px; cursor: pointer; }
.ptools button.del { background: #c42b1ce6; }
.ptools button:disabled { opacity: .35; }
.pinfo { padding: 8px 10px 0; font-size: 13px; color: var(--muted); word-break: break-all; }
.pwarn { display: inline-block; margin-top: 4px; padding: 1px 8px; border-radius: 10px; background: #fff4ce; color: #5c4400; font-weight: 700; }
.pcap { padding: 8px 10px 10px; }
.pcap textarea { width: 100%; min-height: 64px; padding: 8px; border: 1px solid #aeb8c2; border-radius: 6px; font-size: 16px; resize: vertical; }
.pcount { text-align: right; font-size: 12px; color: var(--muted); }

.extra-fields { margin-top: 16px; background: #fff; border: 3px solid var(--sheet-line); }
.save-state { font-size: 13px; color: var(--muted); text-align: center; margin: 12px 0; }

/* 下方動作列 */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px max(12px, env(safe-area-inset-right, 0px)) calc(10px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  background: #ffffffee; border-top: 1px solid var(--border); box-shadow: 0 -2px 10px #0001;
  -webkit-backdrop-filter: blur(6px); backdrop-filter: blur(6px);
}
.actionbar .btn { min-width: 110px; }
.actionbar .btn.wide { flex: 1; max-width: 360px; }

/* 我的日報 */
.list-tools { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; margin: 4px 0 12px; font-size: 14px; }
.report-list { display: grid; gap: 12px; }
.rcard { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; display: grid; gap: 6px; }
.rcard.current { border-color: var(--primary); box-shadow: 0 0 0 2px #0067b833; }
.rhead { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.rtitle { font-weight: 800; font-size: 17px; }
.ritem { color: #333; white-space: pre-wrap; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.rmeta { font-size: 13px; color: var(--muted); }
.ractions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

/* 設定 */
.card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { margin: 0 0 8px; font-size: 18px; }
.card p { margin: 6px 0; }
.field-label { display: block; font-weight: 700; margin: 8px 0 4px; }
.card input[type=text] { width: 100%; padding: 10px 12px; border: 1px solid #aeb8c2; border-radius: 8px; font-size: 16px; margin-bottom: 10px; }
ul.plain { margin: 6px 0; padding-left: 1.2em; }
.steps { margin: 6px 0; padding-left: 1.4em; }

/* 提示列 */
.banner { padding: 10px 14px; border-radius: 10px; margin: 10px auto; max-width: 980px; display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; }
.banner.info { background: #e6f2ff; border: 1px solid #b6d7f3; color: #003f73; margin: 10px max(12px, env(safe-area-inset-left, 0px)); }
.banner.warn { background: #fff4ce; border: 1px solid #f0ce73; color: #5c4400; }

/* 對話框 */
.dialog { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 50; background: #0009; display: flex; align-items: flex-end; justify-content: center; padding: 0; }
.dialog-box {
  width: min(560px, 100%); max-height: 92vh; overflow: auto; background: #fff;
  border-radius: 16px 16px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom, 0px));
}
@media (min-width: 640px) { .dialog { align-items: center; padding: 20px; } .dialog-box { border-radius: 16px; } }
.dialog-box h2 { margin: 0 0 10px; font-size: 20px; color: var(--dark); }
.dialog-buttons { display: grid; gap: 10px; margin-top: 16px; }
.dialog-buttons .row { display: flex; gap: 10px; }
.dialog-buttons .row .btn { flex: 1; }
.filebox { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: #f8fafc; word-break: break-all; font-size: 14px; }
.note { font-size: 13px; color: #5c4400; background: #fff4ce; border-radius: 8px; padding: 8px 10px; margin-top: 10px; }
.errlist { margin: 0; padding-left: 1.2em; color: var(--danger); }

/* 處理中 */
.busy { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 60; background: #0008; display: flex; align-items: center; justify-content: center; }
.busy-box { background: #fff; border-radius: 14px; padding: 22px 26px; text-align: center; min-width: 220px; }
.busy-box p { margin: 10px 0 0; font-weight: 700; }
.spinner { width: 36px; height: 36px; margin: 0 auto; border: 4px solid #cfe3f5; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* 照片放大 */
.lightbox { position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 70; background: #000e; display: flex; align-items: center; justify-content: center; padding: 10px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox-close { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: calc(10px + env(safe-area-inset-right, 0px)); width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; font-size: 24px; cursor: pointer; }

/* 提示訊息 */
.toasts { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: #1f2328; color: #fff; border-radius: 10px; padding: 10px 14px; box-shadow: 0 4px 16px #0004; font-size: 15px; pointer-events: auto; }
.toast.ok { background: #0b5a0b; }
.toast.err { background: #8a1c12; }
