/* 78Pikmin — 行動優先，戶外單手操作為主 */

:root {
  --bg: #0f1419;
  --surface: #182029;
  --surface-2: #212c37;
  --line: #2e3b48;
  --text: #e8eef4;
  --muted: #93a4b5;
  --accent: #4ade80;
  --accent-ink: #062412;
  --danger: #f87171;
  --warn: #fbbf24;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom));
}

/* 主畫面撐滿一屏並排成直向 flex，讓底部的貼上列能用 margin-top: auto 推到底。
 * 沒有這段的話，紀錄還很少（頁面不需捲動）時 sticky 不會生效，
 * 貼上列會停在畫面中間——剛清空資料後看到的就是那個樣子。
 * dvh 而非 vh：手機瀏覽器網址列收合時 vh 會跳動。 */
#app-view {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  /* 底部留白改由貼上列自己的 padding 負責（它已含 safe-area），
     這裡再留 32px 會把貼上列頂離視窗底部 32px，看起來就沒「貼住」 */
  padding-bottom: 0;
}

[hidden] { display: none !important; }

/* ── 頭部 ────────────────────────────────────────────────── */

header.bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.brand {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: .02em;
  margin: 0;
  flex: 1;
}

.brand span { color: var(--accent); }

.dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.ok { background: var(--accent); }
.dot.busy { background: var(--warn); }
.dot.err { background: var(--danger); }

.sync-text { font-size: 12px; color: var(--muted); }

/* ── 按鈕 ────────────────────────────────────────────────── */

button {
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor: pointer;
  min-height: 44px;           /* 觸控最小命中區 */
}

button:hover { border-color: var(--muted); }
button:disabled { opacity: .5; cursor: not-allowed; }

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}

button.ghost { background: transparent; }
button.danger { color: var(--danger); }

button.big {
  width: 100%;
  min-height: 64px;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 10px;
}


/* 並排按鈕一律等寬、等高、同 padding / font-size / radius（ui-consistency） */
.row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.row-2 > button { width: 100%; min-height: 48px; padding: 10px 14px; font-size: 15px; border-radius: var(--radius); }

/* ── 表單 ────────────────────────────────────────────────── */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 15px;
  color: var(--muted);
  font-weight: 600;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 4px;
}

input[type="text"],
input[type="password"],
input[type="search"],
textarea,
select {
  width: 100%;
  font: inherit;
  font-size: 16px;             /* < 16px 會讓 iOS Safari 自動放大頁面 */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  margin-bottom: 12px;
  min-height: 44px;
}

textarea { resize: vertical; min-height: 72px; }

input:focus, textarea:focus, select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.hint { font-size: 12px; color: var(--muted); margin: -6px 0 12px; }

.msg {
  font-size: 14px;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 12px;
}
.msg.error { background: rgba(248,113,113,.12); color: var(--danger); border: 1px solid rgba(248,113,113,.35); }
.msg.info  { background: rgba(74,222,128,.10); color: var(--accent); border: 1px solid rgba(74,222,128,.30); }

/* ── 工具列 ──────────────────────────────────────────────── */

.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar input[type="search"] { margin-bottom: 0; flex: 1; }
.toolbar select { margin-bottom: 0; width: auto; flex: none; }

.count { font-size: 13px; color: var(--muted); margin-bottom: 8px; }

/* ── 清單 ────────────────────────────────────────────────── */

/* margin-bottom 給清單與底部貼上列之間的間距——貼上列用 margin-top: auto，
   內容夠長時那個 auto 會是 0，間距得由這裡出 */
.list { list-style: none; margin: 0 0 20px; padding: 0; display: grid; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.card.pending { border-color: var(--warn); }

.card-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.card-name { font-weight: 700; font-size: 16px; }
.card-name.untitled { color: var(--muted); font-weight: 400; }

.tag {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--line);
}
.tag.pending { color: var(--warn); border-color: var(--warn); }

.card-meta { font-size: 13px; color: var(--muted); margin-top: 6px; }
.coord { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 13px; }
.card-note { margin-top: 6px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }

.card-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.card-actions button, .card-actions a {
  font-size: 13px;
  min-height: 38px;
  padding: 7px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.empty { text-align: center; color: var(--muted); padding: 32px 16px; }

/* ── 登入 ────────────────────────────────────────────────── */

#login-view .panel { max-width: 380px; margin: 12vh auto 0; }
#login-view .brand { text-align: center; font-size: 24px; margin-bottom: 4px; }
#login-view .hint { text-align: center; margin: 0 0 18px; }

@media (prefers-reduced-motion: no-preference) {
  .card { transition: border-color .15s ease; }
}

/* ── 貼上與預覽 ──────────────────────────────────────────── */

textarea#paste {
  /* 不設 min-height：收合高度交給 rows="2"，展開高度由 :focus-within 那條給。
     這裡要壓過通用 textarea 的 min-height: 72px，否則收不到兩行那麼窄。 */
  min-height: 0;
  /* 必須 ≥16px：低於 16px 時 iOS Safari 一聚焦就自動放大頁面。
     這個框是貼上的主要落點，原本的 15px 會讓 iPhone 每次貼上都先縮放一次。 */
  font-size: 16px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, "Microsoft JhengHei", monospace;
  line-height: 1.6;
}

/* ── 固定在視窗底部的貼上列 ──────────────────────────────
 * 用 sticky 而非 fixed：元素仍留在文件流裡，捲到最底時會自然回到清單後面，
 * 不必替 .wrap 手算一個等於面板高度的 padding-bottom 去避免最後一張卡片被蓋住
 * （面板高度會隨展開／收合變動，那個數字算不準）。
 * 底部 padding 加 safe-area：iPhone 的 home indicator 會蓋住最後那幾 px。
 */
.paste-panel {
  position: sticky;
  bottom: 0;
  z-index: 5;
  margin-top: auto;   /* 內容不滿一屏時推到底；內容夠長時解析為 0，改由 sticky 接手 */
  margin-bottom: 0;
  padding-bottom: calc(14px + env(safe-area-inset-bottom));
  box-shadow: 0 -10px 24px rgba(0, 0, 0, .5);
}

/* 聊天輸入列：輸入框佔滿剩餘寬度，送出鈕靠右固定寬。
   align-items: flex-end 讓按鈕在輸入框聚焦變高時仍貼齊底部，不會被拉長。 */
.paste-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}
.paste-row textarea { flex: 1; min-width: 0; margin-bottom: 0; }
.paste-row button { flex: none; }

/* 收合狀態只留輸入列（約兩行高），聚焦才展開說明——永久釘著整塊會吃掉手機三成畫面。
 *
 * 這裡只藏「說明文字」這種不可互動的元素，**絕不藏按鈕**：
 * 用 :focus-within 控制互動元素的可見性是個陷阱——真實點擊的順序是
 * mousedown → 焦點轉移 → mouseup → click，若 mousedown 讓輸入框失焦而焦點沒落回
 * 面板內，按鈕會在 mouseup 之前就 display: none，那一下點擊便無從產生。
 * （2026-08-23 原本的「解析框內文字」按鈕就是這樣掛掉的。送出鈕因此永遠可見。） */
/* 通用 .hint 有 margin-top: -6px（用來貼近上方 margin-bottom:12px 的輸入框），
   但輸入列的 margin-bottom 是 0，沿用那個負值會貼到輸入框上，故改為正的間距 */
.paste-panel .hint { display: none; margin: 10px 0 0; }

.paste-panel:focus-within .hint { display: block; }
.paste-panel:focus-within textarea { min-height: 132px; }

.card-addr { font-size: 13px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }

/* execCommand 複製備援用的暫時元素；CSP 是 style-src 'self'，故用 class 不用 inline style */
.copy-helper {
  position: fixed;
  top: -1000px;
  left: -1000px;
  opacity: 0;
  pointer-events: none;
}
