/* 手機優先的版面：先設計窄螢幕，寬螢幕再放大 */
:root {
  --green: #2f6b3a;
  --green-2: #4c9a5a;
  --green-bg: #eef5ec;
  --ink: #1d2a1f;
  --muted: #5d6b60;
  --line: #d6e0d4;
  --card: #ffffff;
  --bg: #f6f8f3;
  --warn: #b26a00;
  --warn-bg: #fff4e0;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --radius: 14px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
  padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
}
main { max-width: 960px; margin: 0 auto; padding: 16px; }
h1 { font-size: 1.35rem; margin: 4px 0 14px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
a { color: var(--green); }
.muted { color: var(--muted); font-size: .9rem; }
.small { font-size: .85rem; }

/* 上方標題列與分頁 */
/* 綠色標題列和分頁按鈕一起固定在最上面 */
.sticky-top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--green); color: #fff; padding: 10px 16px;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.logout { display: flex; align-items: center; gap: 8px; margin: 0; }
.who { opacity: .85; font-size: .9rem; }
.btn-link { background: none; border: 0; color: #fff; text-decoration: underline; font: inherit; cursor: pointer; padding: 4px; }
.tabs {
  display: flex; gap: 4px; overflow-x: auto; background: #fff; border-bottom: 1px solid var(--line);
  padding: 6px 12px; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 8px 14px; border-radius: 999px; text-decoration: none; color: var(--ink);
  white-space: nowrap; font-size: .95rem;
}
.tabs a.on { background: var(--green); color: #fff; }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: .75rem; text-align: center; }

/* 卡片與格線 */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 640px) { .grid.two { grid-template-columns: 1fr 1fr; } .grid.three { grid-template-columns: repeat(3, 1fr); } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 12px; }
.grid .card { margin-bottom: 0; }
.big { font-size: 2.4rem; font-weight: 700; line-height: 1.1; }
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spread { justify-content: space-between; }

/* 狀態標籤 */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .85rem; background: #eceeea; color: var(--muted); }
.pill.ok { background: var(--green-bg); color: var(--green); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.danger { background: var(--danger-bg); color: var(--danger); }

/* 按鈕與表單 */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1px solid var(--green);
  background: var(--green); color: #fff; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn.secondary { background: #fff; color: var(--green); }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.small { min-height: 36px; padding: 4px 12px; font-size: .9rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
label { display: block; font-weight: 600; margin: 10px 0 4px; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; min-height: 44px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; background: #fff; color: var(--ink);
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 6px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--green); }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0 12px; }
.help { color: var(--muted); font-size: .85rem; margin: 2px 0 8px; }
.inline-form { display: inline; margin: 0; }

.flash { max-width: 960px; margin: 10px auto; padding: 10px 14px; border-radius: 10px; background: var(--green-bg); color: var(--green); }
.flash.error { background: var(--danger-bg); color: var(--danger); }
main .flash { margin: 0 0 12px; }

/* 表格（太寬時可以左右滑） */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; white-space: nowrap; }

/* 浮動緊急停止鈕：每一頁都在右下角 */
.estop {
  position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); z-index: 20;
  width: 72px; height: 72px; border-radius: 50%; border: 4px solid #fff;
  background: var(--danger); color: #fff; font: 700 1rem/1 inherit; cursor: pointer;
  box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.estop:active { transform: scale(.94); }

/* 遙控方向鍵 */
.pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 340px; margin: 8px auto; touch-action: none; }
.pad button {
  aspect-ratio: 1; border-radius: 18px; border: 0; background: var(--green); color: #fff;
  font-size: 2rem; cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.pad button.active { background: var(--green-2); transform: scale(.95); }
.pad button.stop { background: #555; font-size: 1.1rem; font-weight: 700; }
.pad .blank { visibility: hidden; }
input[type=range] { width: 100%; accent-color: var(--green); height: 32px; }

/* 照片 */
.photo { width: 100%; border-radius: 10px; display: block; background: #ddd; aspect-ratio: 4/3; object-fit: cover; }
.photos { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
video.preview { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }

/* 圖表 */
.chart { width: 100%; height: 220px; display: block; }
.chart text { font-size: 11px; fill: var(--muted); }

/* 巡邏步驟 */
.steps { list-style: none; padding: 0; margin: 8px 0; counter-reset: step; }
.steps li { display: flex; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 6px; background: #fff; }
.steps li::before { counter-increment: step; content: counter(step); flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--green-bg); color: var(--green); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }
.steps li .grow { flex: 1; }
.steps li input { width: 80px; min-height: 36px; }

/* 登入頁 */
.login-box { max-width: 380px; margin: 10vh auto 0; }
