/* 元承五金行送貨紀錄 — 青綠 #0f766e，淺色／深色模式 */
:root {
  --brand: #0f766e;
  --brand-strong: #0b5e58;
  --brand-soft: #e3f2ef;
  --on-brand: #ffffff;
  --bg: #f1f3f2;
  --surface: #ffffff;
  --surface-2: #f6f8f7;
  --text: #15201e;
  --muted: #5b6b68;
  --line: #d9e1df;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fff4e0;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 8px rgb(0 0 0 / .05);
  --radius: 14px;
  --tap: 48px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --brand: #2dd4bf;
    --brand-strong: #5eead4;
    --brand-soft: #123532;
    --on-brand: #04201d;
    --bg: #0b1513;
    --surface: #13201e;
    --surface-2: #182826;
    --text: #e6efed;
    --muted: #9db0ac;
    --line: #2a3d3a;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --warn: #fbbf24;
    --warn-soft: #3a2a0c;
    --ok: #4ade80;
    --ok-soft: #12301c;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }

/* ---------- 按鈕 ---------- */
.btn {
  min-height: var(--tap);
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  text-decoration: none;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.warn { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 40px; padding: 6px 12px; font-size: 15px; }
.btn.big { min-height: 54px; font-size: 18px; width: 100%; }
.icon-btn {
  width: var(--tap); height: var(--tap);
  border: 0; background: transparent; color: inherit; border-radius: 12px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
}
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 6px 12px; min-height: 40px; cursor: pointer; font-size: 15px;
  max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ---------- 表單 ---------- */
input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--surface);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .chip:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 1px;
}
label { display: block; font-weight: 600; margin: 12px 0 4px; }
label > input, label > textarea, label > select { margin-top: 4px; font-weight: 400; }
.req { color: var(--danger); }
.error { color: var(--danger); min-height: 1.5em; margin: 8px 0; }
.hint { color: var(--muted); font-size: 15px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 500; margin: 14px 0; }
.check input { width: 24px; height: 24px; min-height: 0; flex: none; }

/* ---------- 登入 ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-box {
  width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px;
  padding: 28px 22px; box-shadow: var(--shadow); text-align: left;
}
.login-logo { display: block; margin: 0 auto 4px; width: 112px; height: 112px; }
.login h1 { text-align: center; font-size: 22px; margin: 4px 0 12px; color: var(--brand); }

/* ---------- 頂端 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar .logo { width: 36px; height: 36px; flex: none; }
.topbar h1 { font-size: 18px; margin: 0; flex: 1; min-width: 0; color: var(--brand); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar h1 span { margin-left: 4px; color: var(--text); }
.net { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.net.on { background: var(--ok); }
.net.off { background: var(--danger); }
@media (max-width: 420px) { .topbar h1 span { display: none; } }

.pending-bar {
  background: var(--warn-soft); color: var(--warn); padding: 8px 16px; font-weight: 600;
  border-bottom: 1px solid var(--line); display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}

/* ---------- 篩選 ---------- */
.filters { padding: 10px 12px 4px; display: grid; gap: 8px; max-width: 1400px; margin: 0 auto; }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filter-row select { width: auto; flex: 1 1 130px; min-height: 40px; padding: 6px 10px; font-size: 15px; }
.custom-range { display: flex; align-items: center; gap: 6px; flex: 1 1 100%; }
.custom-range input { min-height: 40px; padding: 6px 8px; font-size: 15px; }
.wide-only { display: none; }
@media (min-width: 768px) { .wide-only { display: inline-flex; } }
body:not(.is-admin) .admin-only { display: none !important; }

/* ---------- 狀態分頁 ---------- */
.tabs {
  position: sticky; top: calc(env(safe-area-inset-top) + 53px); z-index: 15;
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px;
  padding: 8px 12px; background: var(--bg); max-width: 1400px; margin: 0 auto;
}
.tab {
  min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  font-weight: 700; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.2;
}
.tab .count { font-size: 14px; font-weight: 600; color: var(--muted); }
.tab.active { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.tab.active .count { color: inherit; opacity: .9; }

.date-tabs {
  display: flex; gap: 8px; overflow-x: auto; padding: 2px 12px 8px; scroll-snap-type: x proximity;
  max-width: 1400px; margin: 0 auto; scrollbar-width: thin;
}
.date-tabs:empty { display: none; }
.date-tab {
  flex: none; scroll-snap-align: start; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); padding: 6px 14px; min-height: 40px; cursor: pointer; font-size: 15px; white-space: nowrap;
}
.date-tab b { font-weight: 600; color: var(--muted); margin-left: 4px; }
.date-tab.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-strong); font-weight: 700; }
.date-tab.active b { color: inherit; }

/* ---------- 卡片 ---------- */
.list { padding: 4px 12px calc(env(safe-area-inset-bottom) + 96px); max-width: 1400px; margin: 0 auto; }
.cards { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); }
@media (max-width: 400px) { .cards { grid-template-columns: 1fr; } }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; display: flex; flex-direction: column; gap: 8px; border-left: 5px solid var(--line);
}
.card.st-todo { border-left-color: var(--brand); }
.card.st-done { border-left-color: var(--ok); }
.card.st-absent { border-left-color: var(--warn); }
.card.pending { outline: 2px dashed var(--warn); }
/* 剛新增／剛修改的那一筆閃一下 */
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 55%, transparent); } 100% { box-shadow: var(--shadow); } }
.card.flash { animation: flash 3s ease-out; }
.grid tr.flash td { animation: rowflash 3s ease-out; }
@keyframes rowflash { 0%, 60% { background: var(--brand-soft); } 100% { background: transparent; } }
.card-head { display: flex; align-items: flex-start; gap: 8px; }
.card-head .name { font-size: 20px; font-weight: 700; flex: 1; word-break: break-word; }
.ship-no { font-size: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; color: var(--muted); white-space: nowrap; }
.addr-link { display: inline-flex; gap: 6px; align-items: flex-start; text-decoration: none; font-size: 16px; }
.addr-link svg { flex: none; margin-top: 3px; }
.tel-row { display: flex; gap: 8px; flex-wrap: wrap; }
.tel-row .btn { flex: 1 1 auto; }
.note { white-space: pre-wrap; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 16px; }
.meta { color: var(--muted); font-size: 15px; display: flex; flex-wrap: wrap; gap: 4px 14px; }
.meta b { color: var(--text); font-weight: 600; }
.badge { display: inline-block; border-radius: 999px; padding: 1px 10px; font-size: 13px; font-weight: 700; white-space: nowrap; }
.badge.todo { background: var(--brand-soft); color: var(--brand-strong); }
.badge.done { background: var(--ok-soft); color: var(--ok); }
.badge.absent { background: var(--warn-soft); color: var(--warn); }
.badge.pend { background: var(--warn-soft); color: var(--warn); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb {
  width: 96px; height: 96px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  padding: 0; overflow: hidden; cursor: zoom-in; position: relative;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb.sign { background: #fff; }
.thumb.sign img { object-fit: contain; }
.thumb small { position: absolute; left: 0; right: 0; bottom: 0; background: rgb(0 0 0 / .55); color: #fff; font-size: 12px; text-align: center; }
.missing { color: var(--warn); font-size: 14px; font-weight: 600; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.actions .btn { flex: 1 1 auto; }
.actions.secondary .btn { min-height: 42px; font-size: 15px; font-weight: 500; }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- 表格 ---------- */
.table-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; align-items: center; }
.table-tools select { width: auto; min-height: 40px; padding: 6px 10px; font-size: 15px; }
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
table.grid { border-collapse: collapse; width: 100%; font-size: 15px; }
.grid th, .grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.grid th { position: sticky; top: 0; background: var(--surface-2); white-space: nowrap; font-weight: 700; z-index: 1; }
.grid td.note-cell { white-space: pre-wrap; min-width: 180px; max-width: 320px; }
.grid td.nowrap { white-space: nowrap; }
.grid .thumb { width: 56px; height: 56px; }
.grid .btn.small { min-height: 34px; padding: 4px 10px; font-size: 14px; }
.grid tr:hover td { background: var(--surface-2); }

/* ---------- 新增按鈕 ---------- */
.fab {
  position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 16px); z-index: 25;
  min-height: 56px; padding: 0 22px; border-radius: 999px; border: 0;
  background: var(--brand); color: var(--on-brand); font-size: 18px; font-weight: 700;
  box-shadow: 0 6px 18px rgb(0 0 0 / .25); cursor: pointer;
}

/* ---------- 視窗 ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; background: rgb(0 0 0 / .5);
  display: flex; align-items: flex-end; justify-content: center;
}
@media (min-width: 640px) { .overlay { align-items: center; padding: 24px; } }
.modal {
  background: var(--surface); width: 100%; max-width: 560px; max-height: 92dvh;
  border-radius: 20px 20px 0 0; display: flex; flex-direction: column; overflow: hidden;
}
@media (min-width: 640px) { .modal { border-radius: 20px; } }
.modal.wide { max-width: 820px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; }
.modal-head h2 { margin: 0; font-size: 20px; flex: 1; }
.modal-body { padding: 4px 16px 16px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.modal-foot {
  display: flex; gap: 10px; padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  border-top: 1px solid var(--line); background: var(--surface);
}
.modal-foot .btn { flex: 1; min-height: 52px; }
.confirm-name { font-size: 20px; font-weight: 700; margin: 6px 0; }

.menu-list { display: grid; gap: 8px; }
.menu-list .btn { justify-content: flex-start; min-height: 52px; }

/* 拍照區 */
.photo-box { display: grid; gap: 8px; margin: 8px 0; }
.photo-preview { width: 100%; max-height: 280px; object-fit: contain; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.slip-row { display: flex; gap: 10px; align-items: center; }
.slip-row img { width: 72px; height: 72px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.ocr-status { font-size: 15px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); }
.ocr-status.err { background: var(--danger-soft); color: var(--danger); }
.ocr-status.ok { background: var(--ok-soft); color: var(--ok); }

/* 簽名 */
.sign-box {
  width: 100%; height: 150px; border: 2px dashed var(--line); border-radius: 12px; background: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; color: #6b7280; overflow: hidden;
}
.sign-box img { max-width: 92%; max-height: 88%; object-fit: contain; }
.sign-box.has { border-style: solid; border-color: var(--brand); }
.sign-full {
  position: fixed; inset: 0; z-index: 80; background: #fff; color: #111;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.sign-full .bar { display: flex; gap: 8px; padding: 10px; align-items: center; border-bottom: 1px solid #ddd; }
.sign-full .bar .title { flex: 1; font-weight: 700; font-size: 18px; }
.sign-full .bar .btn { background: #fff; color: #111; border-color: #ccc; }
.sign-full .bar .btn.primary { background: #0f766e; color: #fff; border-color: #0f766e; }
.sign-full .pad { flex: 1; position: relative; }
.sign-full canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sign-full .baseline { position: absolute; left: 8%; right: 8%; bottom: 22%; border-bottom: 2px solid #cbd5e1; pointer-events: none; }
.sign-full .baseline span { position: absolute; left: 0; bottom: 4px; color: #94a3b8; font-size: 15px; }

/* 照片檢視 */
.viewer { position: fixed; inset: 0; z-index: 90; background: rgb(0 0 0 / .92); display: flex; flex-direction: column; color: #fff; }
.viewer .img-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 12px; min-height: 0; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; background: #fff; border-radius: 6px; }
.viewer .cap { padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px); display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.viewer .cap span { flex: 1; }
.viewer .btn { background: #fff; color: #111; }

/* 使用者管理 */
.user-row { display: flex; gap: 8px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.user-row .who { flex: 1 1 160px; }
.user-row .who small { color: var(--muted); display: block; }
.user-row.inactive .who { opacity: .5; }

/* 提示訊息 */
.toast {
  position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 88px); transform: translateX(-50%) translateY(20px);
  background: #1f2937; color: #fff; padding: 12px 18px; border-radius: 12px; z-index: 100;
  max-width: calc(100vw - 32px); opacity: 0; pointer-events: none; transition: .2s; font-size: 16px; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: #b42318; }

body.lock { overflow: hidden; }
