/* KED Family — 溫暖家居感,mobile-first */

:root {
  --bg: #faf6ef;
  --card: #ffffff;
  --text: #3a3226;
  --muted: #8a7f6d;
  --accent: #c9704a;
  --accent-soft: #f6e3d7;
  --danger: #c0392b;
  --danger-soft: #fdeae7;
  --ok: #4a8c5c;
  --ok-soft: #e5f2e9;
  --warn: #b8860b;
  --warn-soft: #fbf3d9;
  --border: #eadfce;
  --shadow: 0 2px 8px rgba(90, 70, 40, 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #201c16;
    --card: #2b261e;
    --text: #efe8db;
    --muted: #a89c88;
    --accent: #e08a5f;
    --accent-soft: #45301f;
    --danger: #e07060;
    --danger-soft: #452622;
    --ok: #7dbb8e;
    --ok-soft: #24382a;
    --warn: #d9b24a;
    --warn-soft: #3d3517;
    --border: #3a332a;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  }
}

/* 手動外觀切換(設定 → 外觀):顯式 data-theme 蓋過裝置設定;冇設(auto)就跟返上面 prefers-color-scheme */
html[data-theme="light"] {
  --bg: #faf6ef;
  --card: #ffffff;
  --text: #3a3226;
  --muted: #8a7f6d;
  --accent: #c9704a;
  --accent-soft: #f6e3d7;
  --danger: #c0392b;
  --danger-soft: #fdeae7;
  --ok: #4a8c5c;
  --ok-soft: #e5f2e9;
  --warn: #b8860b;
  --warn-soft: #fbf3d9;
  --border: #eadfce;
  --shadow: 0 2px 8px rgba(90, 70, 40, 0.08);
}

html[data-theme="dark"] {
  --bg: #201c16;
  --card: #2b261e;
  --text: #efe8db;
  --muted: #a89c88;
  --accent: #e08a5f;
  --accent-soft: #45301f;
  --danger: #e07060;
  --danger-soft: #452622;
  --ok: #7dbb8e;
  --ok-soft: #24382a;
  --warn: #d9b24a;
  --warn-soft: #3d3517;
  --border: #3a332a;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 15px; }

/* ── 離線橫幅 ─────────────────── */
#offline-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 60;
  background: var(--warn-soft);
  color: var(--warn);
  text-align: center;
  padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  font-size: 14px;
  font-weight: 600;
}

/* ── 首次使用畫面 ─────────────── */
.screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.onboard-card {
  width: 100%;
  max-width: 340px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 32px 24px;
  text-align: center;
}

.onboard-icon { font-size: 48px; margin-bottom: 8px; }
.onboard-card h1 { font-size: 24px; margin-bottom: 4px; }
.onboard-card .muted { margin-bottom: 20px; }

.onboard-card input {
  width: 100%;
  font-size: 20px;
  text-align: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 12px;
}

.onboard-card .error { margin-bottom: 12px; }

/* ── 掣 ───────────────────────── */
.btn-primary {
  width: 100%;
  min-height: 48px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
}

.btn-secondary {
  width: 100%;
  min-height: 48px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 17px;
  cursor: pointer;
}

.btn-danger {
  width: 100%;
  min-height: 48px;
  background: var(--danger-soft);
  color: var(--danger);
  border: none;
  border-radius: 12px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}

/* ── 主畫面 layout ────────────── */
#view {
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top));
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
  max-width: 560px;
  margin: 0 auto;
}

.page-title {
  font-size: 26px;
  font-weight: 800;
  margin-bottom: 14px;
}

.group-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--muted);
  margin: 18px 0 8px 4px;
}

.empty-note {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 16px;
}

/* ── 卡片 ─────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 12px 14px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-main { flex: 1; min-width: 0; cursor: pointer; }

.card-title {
  font-size: 17px;
  font-weight: 600;
  word-break: break-word;
}

.card-title.done-text {
  text-decoration: line-through;
  color: var(--muted);
}

.card-sub {
  font-size: 13px;
  color: var(--muted);
  margin-top: 3px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-once { background: var(--accent-soft); color: var(--accent); }
.badge-recur { background: var(--ok-soft); color: var(--ok); }
.badge-cat { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
.badge-need { background: var(--danger-soft); color: var(--danger); }

.due-overdue { color: var(--danger); font-weight: 700; }
.due-today { color: var(--warn); font-weight: 700; }

/* 完成 ✓ 掣 */
.check-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--card);
  color: var(--ok);
  font-size: 20px;
  cursor: pointer;
}

.check-btn:active { background: var(--ok-soft); }

.small-btn {
  min-height: 36px;
  padding: 4px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
}

/* ── 存貨 +/− ─────────────────── */
.qty-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.qty-btn {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
}

.qty-btn:active { background: var(--accent-soft); }

.qty-num {
  min-width: 52px;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
}

.qty-unit { font-size: 12px; color: var(--muted); display: block; }

/* ── 補貨清單 ─────────────────── */
.shop-check {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  border: 2px solid var(--accent);
  background: var(--card);
  color: var(--accent);
  font-size: 20px;
  cursor: pointer;
}

/* ── Tab bar(含中間 FAB slot)──── */
#tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  min-height: 60px;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
}

.tab.active { color: var(--accent); }
.tab-icon { font-size: 20px; }

.tab-fab-slot {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

.tab-fab {
  width: 54px;
  height: 54px;
  min-width: 54px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(90, 70, 40, 0.3);
  cursor: pointer;
  position: relative;
  top: -14px;
  transition: transform 150ms ease;
}

.tab-fab:active { transform: scale(0.92) translateY(-14px); }

/* ── 家居 sub-tab(要處理/存貨/補貨)── */
.subtab-row {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.subtab {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.subtab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Modal 表單 ───────────────── */
#modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

#modal {
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}

#modal h2 { font-size: 20px; margin-bottom: 14px; }

.form-row { margin-bottom: 14px; }

.form-row label {
  display: block;
  font-size: 14px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="date"],
.form-row textarea {
  width: 100%;
  min-height: 44px;
  font-size: 17px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.chip {
  min-height: 40px;
  padding: 6px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  cursor: pointer;
}

.chip.selected {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 700;
}

.recur-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.recur-inline input[type="number"] { width: 80px; }

.modal-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 18px;
}

/* ── 設定頁 ───────────────────── */
.settings-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
}

.settings-block h3 { font-size: 16px; margin-bottom: 10px; }

.settings-block input[type="text"],
.settings-block input[type="password"] {
  width: 100%;
  min-height: 44px;
  font-size: 17px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  margin-bottom: 10px;
}

.settings-block .field-label {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 6px;
}

.settings-block .hint-text {
  font-size: 13px;
  margin-bottom: 10px;
}

.settings-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

.settings-block .btn-secondary,
.settings-block .btn-danger {
  margin-top: 4px;
}

.widget-pref-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  padding: 6px 0;
  cursor: pointer;
}

.widget-pref-row input { accent-color: var(--accent); width: 18px; height: 18px; }

/* ── 設定頁:個人資料頭 ─────────── */
.profile-header-block {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 16px;
}

.profile-avatar {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 24px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-name { font-size: 19px; font-weight: 700; }

/* ── 首頁 widget 框架 ─────────── */
.home-greet { margin-bottom: 16px; }

.widget-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.widget-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 16px;
  cursor: pointer;
}

.widget-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  margin-bottom: 6px;
}

.widget-icon { font-size: 20px; }
.widget-title { font-size: 15px; }
.widget-num { font-size: 34px; font-weight: 800; line-height: 1.1; }
.widget-sub { font-size: 13px; margin-top: 2px; }
.widget-link { font-size: 13px; color: var(--accent); font-weight: 700; margin-top: 8px; }

/* ── 揀選模式 / 拖曳排序 / 批量工具列 ── */
.list-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.select-mode-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.select-mode-btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.drag-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  min-width: 22px;
  flex-shrink: 0;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.drag-handle:active { cursor: grabbing; }

.bulk-checkbox {
  width: 22px;
  height: 22px;
  min-width: 22px;
  accent-color: var(--accent);
  cursor: pointer;
}

.bulk-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dragsort-dragging { opacity: 0.55; }

.dragsort-group-placeholder {
  border: 2px dashed var(--accent);
  border-radius: 16px;
  min-height: 54px;
  margin-bottom: 10px;
  background: var(--accent-soft);
}

.bulk-toolbar {
  position: fixed;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 528px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  padding: 10px 14px;
  z-index: 45;
}

.bulk-toolbar-count {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}

.bulk-toolbar-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.bulk-toolbar-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.bulk-toolbar-delete { border-color: var(--danger); color: var(--danger); }

.bulk-toolbar-hint { font-size: 11px; color: var(--muted); white-space: nowrap; }

.bulk-toolbar-spacer { flex: 1; }

.bulk-toolbar-cancel { background: none; border-color: transparent; color: var(--muted); }

/* ── FAB 快速新增 action sheet(共用 modal 排版)── */
.action-sheet-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 8px;
}

.action-sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}

.action-sheet-item:active { background: var(--accent-soft); }

/* ── Toast ────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 80;
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
  box-shadow: var(--shadow);
}
