/* ========== Design Tokens ========== */
:root {
  /* 背景層次 */
  --bg-base: #0f1117;
  --bg-elevated: #1a1d29;
  --bg-card: #21253a;
  --bg-card-hover: #2a2f47;
  --bg-input: #161924;

  /* 文字：muted 由 #6b7280 提亮到 #8b93a7，
     在 --bg-base 上對比度從 ~4.0:1 提升到 ~6.5:1（WCAG AA 小字達標） */
  --text-primary: #e6e8ee;
  --text-secondary: #aab2c3;
  --text-muted: #8b93a7;

  /* 邊框 */
  --border-subtle: #2a2f47;
  --border-strong: #3a4060;

  /* 強調色（仿 Studio 紫色 + 青綠） */
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --accent-dim: rgba(139, 92, 246, 0.15);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;

  /* 尺寸 */
  --sidebar-width: 240px;
  --topbar-height: 56px;
  --drawer-width: 540px;
  --radius: 10px;
  --radius-sm: 6px;

  /* 動效 */
  --ease: cubic-bezier(0.22, 0.8, 0.36, 1);
  --dur-fast: 0.14s;
  --dur: 0.22s;

  /* 字型 */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

/* ========== Reset ========== */
* { box-sizing: border-box; margin: 0; padding: 0; }
/*
 * HTML 的 hidden 屬性必須永遠勝過元件自己的 display:grid/flex。
 * 否則 Chrome 會讓已設 hidden 的載入骨架與詳細抽屜繼續顯示，
 * 造成畫面出現巨大空白卡片與右側空白面板。
 */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  font-family: var(--font-sans);
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  background: var(--bg-input);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
  max-width: 100%;
}
textarea { resize: vertical; min-height: 38px; }
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
::placeholder { color: var(--text-muted); opacity: 1; }
/* 移除 Chrome 內建的 search 清除鈕，改用自訂的 */
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }

/* 統一鍵盤焦點指示：只在鍵盤操作時出現，滑鼠點擊不干擾 */
:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* 螢幕閱讀器專用文字 */
.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -60px;
  z-index: 500; background: var(--accent); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-sm);
  text-decoration: none; font-size: 13px; font-weight: 600;
  transition: top var(--dur) var(--ease);
}
.skip-link:focus { top: 8px; }

/* ========== Topbar ========== */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand { font-size: 18px; font-weight: 700; white-space: nowrap; }
.brand-sub { color: var(--text-muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.sync-status {
  color: var(--success); font-size: 12px; padding: 4px 10px;
  background: rgba(52, 211, 153, 0.12); border-radius: 20px; white-space: nowrap;
}
.sync-status.syncing { color: var(--warning); background: rgba(251, 191, 36, 0.12); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 6px 10px; border-radius: var(--radius-sm);
  color: var(--text-secondary); transition: background var(--dur-fast), color var(--dur-fast);
}
/* 必須比 .icon-btn 更具體，否則桌機版的 display:none 會被上面的 inline-flex 覆蓋 */
.icon-btn.menu-btn { display: none; align-self: center; font-size: 18px; }
.icon-btn:hover { background: var(--bg-card); color: var(--text-primary); }

/* ========== Layout ========== */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  height: 100vh;
  height: 100dvh;
  padding-top: var(--topbar-height);
}

/* ========== Sidebar ========== */
.sidebar {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 149;
  animation: fadeIn var(--dur) var(--ease);
}
.sidebar-section { display: flex; flex-direction: column; gap: 6px; }
.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 0 8px 4px;
}
.category-nav { display: flex; flex-direction: column; gap: 2px; }

/* 分類列：主按鈕 + 編輯按鈕（button 不可巢狀，故拆成兩個兄弟節點） */
.category-row { position: relative; display: flex; align-items: center; border-radius: var(--radius-sm); }
.category-row:hover { background: var(--bg-card); }
.category-row:has(.category-btn.active) { background: var(--accent-dim); }
.category-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 14px;
  color: var(--text-secondary);
  transition: color var(--dur-fast);
  flex: 1;
  min-width: 0;
}
.category-btn .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.category-row:hover .category-btn { color: var(--text-primary); }
.category-btn.active { color: var(--text-primary); font-weight: 600; }
.category-btn .icon { font-size: 16px; flex-shrink: 0; }
.category-btn .count { margin-left: auto; color: var(--text-muted); font-size: 12px; padding-left: 6px; }
.category-btn.active .count { color: var(--accent-hover); }
.category-edit {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 13px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  opacity: 0;
  transition: opacity var(--dur-fast), color var(--dur-fast);
}
.category-row:hover .category-edit,
.category-edit:focus-visible { opacity: 1; }
.category-edit:hover { color: var(--text-primary); background: var(--bg-card-hover); }

.status-nav { display: flex; flex-direction: column; gap: 2px; }
.status-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text-secondary);
  text-align: left;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.status-pill:hover { background: var(--bg-card); color: var(--text-primary); }
.status-pill.active { background: var(--bg-card); color: var(--text-primary); font-weight: 600; box-shadow: inset 2px 0 0 var(--accent); }
.status-pill .count { margin-left: auto; color: var(--text-muted); font-size: 12px; }
/* 該狀態在目前分類下沒有項目時淡化，但仍可點 */
.status-pill.is-zero { opacity: 0.5; }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-subtle); }
.footer-line { font-size: 12px; color: var(--text-secondary); padding: 2px 8px; }
.footer-line.muted { color: var(--text-muted); }

/* ========== Main ========== */
.main {
  overflow-y: auto;
  padding: 20px 28px 48px;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.search-wrap { position: relative; flex: 1; min-width: 200px; max-width: 400px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.search-wrap input { width: 100%; padding-left: 32px; padding-right: 32px; }
.search-clear {
  position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 12px; padding: 4px 8px; border-radius: var(--radius-sm);
}
.search-clear:hover { color: var(--text-primary); background: var(--bg-card); }

.filter-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 16px; }
.filter-tags:empty { display: none; }
.filter-tag {
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 20px;
  font-size: 12px;
  color: var(--text-secondary);
  transition: background var(--dur-fast), border-color var(--dur-fast), color var(--dur-fast);
}
.filter-tag:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.filter-tag.active { background: var(--accent-dim); border-color: var(--accent); color: var(--accent-hover); }
/* 目前分類內沒有這個標籤，但仍被選取中 → 標示成「會篩掉全部」 */
.filter-tag.stale { border-style: dashed; opacity: 0.7; }

.content-header { margin-bottom: 16px; }
.content-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.muted { color: var(--text-muted); font-size: 13px; }

/* ========== Card Grid ========== */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: background var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast), box-shadow var(--dur-fast);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 180px;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
  animation: cardIn var(--dur) var(--ease) backwards;
}
.card:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-strong);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.28);
}
.card:active { transform: translateY(0); }
@keyframes cardIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.card-header { display: flex; align-items: center; gap: 8px; }
.card-code { font-size: 12px; font-weight: 700; color: var(--accent-hover); padding: 2px 8px; background: var(--accent-dim); border-radius: 4px; }
.card-status { font-size: 12px; padding: 2px 8px; border-radius: 4px; margin-left: auto; white-space: nowrap; }
.status-todo { background: rgba(251, 191, 36, 0.15); color: var(--warning); }
.status-doing { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.status-done { background: rgba(52, 211, 153, 0.15); color: var(--success); }
.status-paused { background: rgba(139, 147, 167, 0.15); color: var(--text-muted); }

.card-title { font-size: 16px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.card-goal { font-size: 13px; color: var(--text-secondary); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-meta { display: flex; align-items: center; gap: 12px; font-size: 12px; color: var(--text-muted); margin-top: auto; flex-wrap: wrap; }
.card-meta span { display: inline-flex; align-items: center; gap: 4px; }
.card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.card-tags:empty { display: none; }
.card-tag { font-size: 11px; padding: 2px 8px; background: var(--bg-base); border-radius: 10px; color: var(--text-secondary); }
.card-progress { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); flex: 1; min-width: 120px; }
.progress-bar { flex: 1; height: 4px; background: var(--bg-base); border-radius: 2px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 2px; transition: width 0.35s var(--ease); }
.card-progress.is-complete .progress-fill { background: var(--success); }
.priority-high { color: var(--danger); }
.priority-medium { color: var(--warning); }
.priority-low { color: var(--success); }
/* 逾期的截止日 */
.due-overdue { color: var(--danger); font-weight: 600; }
.due-soon { color: var(--warning); }

/* ========== Loading Skeleton ========== */
/* 刻意不用 .card class，避免骨架被卡片的選擇器/事件處理誤抓 */
.skeleton-card {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  min-height: 180px;
  pointer-events: none;
  background: linear-gradient(100deg, var(--bg-card) 30%, var(--bg-card-hover) 50%, var(--bg-card) 70%);
  background-size: 220% 100%;
  animation: shimmer 1.2s linear infinite;
}
@keyframes shimmer { from { background-position: 180% 0; } to { background-position: -20% 0; } }

/* ========== Empty State ========== */
.empty-state {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-muted);
  animation: fadeIn var(--dur) var(--ease);
}
.empty-icon { font-size: 44px; margin-bottom: 12px; }
.empty-text { font-size: 14px; margin-bottom: 16px; color: var(--text-secondary); }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* ========== Buttons ========== */
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  transition: background var(--dur-fast), transform var(--dur-fast);
  white-space: nowrap;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: scale(0.97); }
.btn-ghost {
  background: var(--bg-card);
  color: var(--text-secondary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  border: 1px solid var(--border-subtle);
  transition: background var(--dur-fast), color var(--dur-fast);
  white-space: nowrap;
}
.btn-ghost:hover { background: var(--bg-card-hover); color: var(--text-primary); }
.btn-small { padding: 4px 8px; font-size: 12px; }
.btn-block { width: 100%; margin-top: 4px; }
.btn-self-start { align-self: flex-start; }
.btn-danger {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  transition: background var(--dur-fast);
}
.btn-danger:hover { background: rgba(248, 113, 113, 0.28); }

/* ========== Drawer ========== */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  animation: fadeIn var(--dur) var(--ease);
}
.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: var(--drawer-width);
  max-width: 90vw;
  background: var(--bg-elevated);
  border-left: 1px solid var(--border-subtle);
  z-index: 201;
  display: flex;
  flex-direction: column;
  animation: slideIn var(--dur) var(--ease);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.3);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideIn { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes slideInLeft { from { transform: translateX(-100%); } to { transform: translateX(0); } }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  flex-shrink: 0;
}
.drawer-code { font-weight: 700; color: var(--accent-hover); font-size: 13px; }
.drawer-close { margin-left: auto; font-size: 18px; color: var(--text-muted); padding: 4px 10px; }
.drawer-close:hover { color: var(--text-primary); }
.drawer-body { padding: 20px; overflow-y: auto; flex: 1; }
.drawer-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; word-break: break-word; }
.drawer-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.meta-pill { font-size: 12px; padding: 3px 10px; border-radius: 12px; background: var(--bg-card); color: var(--text-secondary); }
.drawer-section { margin-bottom: 20px; }
.drawer-section-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); margin-bottom: 8px; }
.drawer-section-content { font-size: 14px; color: var(--text-primary); line-height: 1.6; white-space: pre-wrap; word-break: break-word; }
.subtask-list { display: flex; flex-direction: column; gap: 6px; }
.subtask-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; background: var(--bg-card);
  border-radius: var(--radius-sm); cursor: pointer;
  transition: background var(--dur-fast);
}
.subtask-item:hover { background: var(--bg-card-hover); }
.subtask-item:focus-within { box-shadow: 0 0 0 2px var(--accent-hover); }
.subtask-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.subtask-text { transition: color var(--dur-fast); }
.subtask-item.done .subtask-text { text-decoration: line-through; color: var(--text-muted); }
.drawer-progress { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.drawer-progress .progress-bar { height: 6px; }
.link-list { display: flex; flex-direction: column; gap: 4px; }
.link-item { color: var(--accent-hover); text-decoration: none; font-size: 13px; padding: 4px 0; word-break: break-all; }
.link-item:hover { text-decoration: underline; }
.drawer-actions {
  display: flex; gap: 8px; padding-top: 16px;
  border-top: 1px solid var(--border-subtle); flex-wrap: wrap;
}

/* ========== Modal ========== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn var(--dur) var(--ease);
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  width: 560px;
  max-width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  animation: modalIn var(--dur) var(--ease);
}
.modal-narrow { width: 420px; }
.modal-header { display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-subtle); flex-shrink: 0; }
.modal-header h3 { font-size: 18px; font-weight: 600; }
.modal-header .drawer-close { margin-left: auto; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 14px; }
.form-row { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.form-row label, .form-label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.req { color: var(--danger); }
.form-error { font-size: 12px; color: var(--danger); background: rgba(248, 113, 113, 0.1); padding: 8px 10px; border-radius: var(--radius-sm); }
.form-row-double { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.subtask-inputs { display: flex; flex-direction: column; gap: 6px; }
.subtask-inputs:empty { display: none; }
.subtask-input-row { display: flex; gap: 6px; align-items: center; }
.subtask-input-row input[type="text"] { flex: 1; min-width: 0; }
.subtask-input-row input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.subtask-input-row button { padding: 4px 10px; }
.modal-footer {
  display: flex; justify-content: flex-end; gap: 8px;
  padding-top: 12px; border-top: 1px solid var(--border-subtle);
  margin-top: 8px; flex-wrap: wrap;
}
.modal-footer-start { margin-right: auto; }

/* ========== Toast ========== */
.toast-host {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 400;
  display: flex; flex-direction: column; gap: 8px;
  align-items: center;
  pointer-events: none;
  width: max-content;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  color: var(--text-primary);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  animation: toastIn var(--dur) var(--ease);
}
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); }
.toast.leaving { animation: toastOut 0.18s var(--ease) forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(8px); } }

/* ========== Responsive ========== */
/* 桌機版永遠不允許行動側欄遮罩攔截操作；即使舊狀態殘留也直接隱藏。 */
@media (min-width: 769px) {
  .sidebar-backdrop { display: none !important; }
}

@media (max-width: 900px) {
  .card-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}

@media (max-width: 768px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .brand-sub { display: none; }
  .sync-status { display: none; }
  .btn-label { display: none; }   /* 手機版按鈕只留 icon，省空間 */
  .icon-btn.menu-btn { display: inline-flex; }

  .layout { grid-template-columns: 1fr; }

  /* 側欄改成從左側滑出的抽屜，不再直接隱藏 —— 手機上仍能切分類 */
  .sidebar {
    position: fixed;
    top: var(--topbar-height); left: 0; bottom: 0;
    width: min(280px, 82vw);
    z-index: 150;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.35);
  }
  .sidebar.open { transform: translateX(0); }
  /* 觸控裝置沒有 hover，編輯鈕常駐顯示 */
  .category-edit { opacity: 1; }

  .main { padding: 16px 14px 40px; }
  .toolbar { gap: 8px; }
  .search-wrap { max-width: none; }
  .content-header h2 { font-size: 19px; }
  .card { min-height: 0; padding: 14px; }
  .card-grid { grid-template-columns: 1fr; gap: 10px; }

  .drawer { width: 100vw; max-width: 100vw; }
  .drawer-body { padding: 16px; }
  .drawer-actions { position: sticky; bottom: 0; background: var(--bg-elevated); padding-bottom: 8px; }

  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal, .modal-narrow {
    width: 100%; max-width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius) var(--radius) 0 0;
    animation: slideUp var(--dur) var(--ease);
  }
  .form-row-double { grid-template-columns: 1fr; }
  .modal-footer button { flex: 1; }
  .modal-footer-start { margin-right: 0; flex-basis: 100%; }
  /* iOS 上字級 < 16px 會觸發自動放大，這裡拉到 16px 避開 */
  .modal-body input, .modal-body select, .modal-body textarea { font-size: 16px; }
}
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

@media (max-width: 380px) {
  .topbar-right { gap: 4px; }
  .btn-ghost { padding: 6px 8px; }
}

/* 觸控裝置：hover 效果不套用，避免點完卡在 hover 態 */
@media (hover: none) {
  .card:hover { transform: none; box-shadow: none; background: var(--bg-card); }
  .category-edit { opacity: 1; }
}

/* 尊重系統的「減少動態效果」設定 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
