/* =========================================================
   styles.css — 待辦總覽
   ========================================================= */

:root {
  --bg: #0b0f17;
  --bg-2: #0f1420;
  --panel: #141a28;
  --panel-2: #1a2233;
  --line: #243049;
  --text: #e8edf7;
  --text-dim: #93a1bd;
  --muted: #6c7a99;
  --accent: #54d1c0;
  --accent-2: #4aa3ff;
  --accent-ink: #06231f;
  --warn: #f0b429;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --shadow: 0 10px 30px rgba(0, 0, 0, .45);
  --radius: 14px;
  --radius-sm: 10px;
}

html[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-2: #ffffff;
  --panel: #ffffff;
  --panel-2: #f2f5fb;
  --line: #e2e8f3;
  --text: #17203a;
  --text-dim: #526080;
  --muted: #8693ac;
  --accent: #14a892;
  --accent-2: #2f80ed;
  --accent-ink: #ffffff;
  --shadow: 0 8px 24px rgba(23, 32, 58, .10);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: radial-gradient(1200px 700px at 12% -10%, #16203a 0%, var(--bg) 55%) no-repeat, var(--bg);
  color: var(--text);
  font-family: "PingFang HK", "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

html[data-theme="light"] body {
  background: radial-gradient(1200px 700px at 12% -10%, #e8eefc 0%, var(--bg) 55%) no-repeat, var(--bg);
}

button, input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: .2px; }
.muted { color: var(--muted); }
.tiny { font-size: 12px; }

/* ---------- 版面 ---------- */
.app {
  display: grid;
  grid-template-columns: 288px minmax(0, 1fr);
  height: 100vh;
}

/* ---------- 側欄 ---------- */
.sidebar {
  background: linear-gradient(180deg, var(--bg-2), var(--bg));
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 16px 16px 10px;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand h1 { font-size: 17px; }
.brand p { margin: 0; }

.logo {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 11px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: var(--accent-ink);
  font-weight: 800;
  box-shadow: 0 6px 16px rgba(84, 209, 192, .28);
}

.side-actions { padding: 4px 16px 12px; display: grid; gap: 8px; }
.side-actions .row { display: flex; gap: 8px; }

.project-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.proj-item {
  display: grid;
  grid-template-columns: 26px 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
}
.proj-item:hover { background: var(--panel); }
.proj-item.active {
  background: var(--panel-2);
  border-color: var(--line);
  box-shadow: inset 3px 0 0 var(--accent);
}
.proj-item .p-emoji { font-size: 17px; text-align: center; }
.proj-item .p-name {
  font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.proj-item .p-meta { display: block; font-size: 11.5px; color: var(--muted); font-weight: 400; }
.proj-item .p-count {
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 7px;
  white-space: nowrap;
}

.side-foot {
  border-top: 1px solid var(--line);
  padding: 10px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-start;
}

/* ---------- 按鈕 ---------- */
.btn {
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  cursor: pointer;
  font-weight: 600;
  font-size: 13.5px;
  transition: transform .08s ease, background .15s ease, border-color .15s ease, opacity .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(140deg, var(--accent), #3fb8e8);
  color: var(--accent-ink);
  border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; color: var(--text-dim); }
.btn.ghost:hover { color: var(--text); background: var(--panel-2); }
.btn.danger { background: transparent; border-color: rgba(255, 107, 107, .45); color: var(--danger); }
.btn.danger:hover { background: rgba(255, 107, 107, .12); border-color: var(--danger); }
.btn.block { width: 100%; }
.btn.grow { flex: 1; }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-dim);
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); background: var(--panel-2); }
.icon-btn.small { width: 28px; height: 28px; font-size: 13px; }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.link-btn {
  background: none; border: 0; padding: 2px 0;
  color: var(--muted); cursor: pointer; font-size: 12.5px;
}
.link-btn:hover { color: var(--accent); }
.danger-text:hover { color: var(--danger) !important; }

.emoji-btn {
  font-size: 20px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 38px; height: 38px;
  cursor: pointer;
}

/* ---------- 主區 ---------- */
.main {
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: 18px 24px 10px;
}

.title-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.proj-title {
  font-size: 22px;
  cursor: text;
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px dashed transparent;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 46vw;
}
.proj-title:hover { border-color: var(--line); background: var(--panel); }
.proj-title-input {
  font-size: 22px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--accent);
  border-radius: 8px; padding: 2px 6px; outline: none;
  width: min(420px, 46vw);
}

.head-tools { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.head-btns { display: flex; gap: 6px; }

.stat { text-align: center; min-width: 52px; }
.stat span { display: block; font-size: 19px; font-weight: 700; line-height: 1.2; }
.stat small { color: var(--muted); font-size: 11px; }
.stat.half span { color: var(--warn); }

.progress {
  height: 6px;
  margin: 0 24px 12px;
  background: var(--panel);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.progress .bar {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s ease;
}

.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 0 24px 10px;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.tool-right { display: flex; gap: 8px; }

.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-dim);
  padding: 5px 12px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active { background: var(--accent); border-color: transparent; color: var(--accent-ink); }

/* ---------- 批量貼上 ---------- */
.bulk-panel {
  margin: 0 24px 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.bulk-panel .hint { margin: 0 0 10px; color: var(--text-dim); font-size: 12.5px; }
.bulk-panel code {
  background: var(--bg-2); border: 1px solid var(--line);
  padding: 1px 5px; border-radius: 5px; font-size: 12px;
}
#bulk-text {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  resize: vertical;
  outline: none;
  font-family: ui-monospace, "SFMono-Regular", Consolas, "Microsoft JhengHei", monospace;
  font-size: 13px;
  line-height: 1.7;
}
#bulk-text:focus { border-color: var(--accent); }
.bulk-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.file-btn { cursor: pointer; }
.bulk-preview { margin-top: 8px; }

/* ---------- 新增列 ---------- */
.add-bar {
  display: flex; gap: 8px; padding: 0 24px 12px; flex-wrap: wrap;
}
.add-bar input, .add-bar select {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
}
.add-bar #new-item { flex: 1; min-width: 200px; }
.add-bar #new-item:focus, .add-bar #new-qty:focus { border-color: var(--accent); }
.qty-input { width: 92px; }
.select { cursor: pointer; max-width: 170px; }

/* ---------- 清單 ---------- */
.item-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 24px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.group {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  overflow: hidden;
}
.group-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--panel-2);
  border-bottom: 1px solid var(--line);
}
.group-head h3 { font-size: 14.5px; }
.group-head .g-count {
  font-size: 11px; color: var(--text-dim);
  border: 1px solid var(--line); border-radius: 999px; padding: 0 8px;
}
.group-tools { margin-left: auto; display: flex; gap: 4px; }
.group-tools .icon-btn { width: 28px; height: 28px; font-size: 12.5px; }
.group-body { padding: 6px; }

.items { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }

.item {
  display: grid;
  grid-template-columns: 24px 24px minmax(0, 1fr) auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  transition: background .12s ease;
}
.item:hover { background: var(--panel-2); }
.item:hover .row-tools { opacity: 1; }

.chk, .partner {
  width: 22px; height: 22px;
  border-radius: 7px;
  border: 1.5px solid var(--line);
  background: transparent;
  cursor: pointer;
  display: grid; place-items: center;
  font-size: 12px; color: transparent;
  transition: all .15s ease;
  flex: none;
}
.chk:hover, .partner:hover { border-color: var(--accent); }
.chk.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.partner { font-size: 13px; color: var(--muted); }
.partner.on {
  border-color: var(--warn);
  background: rgba(240, 180, 41, .16);
  color: var(--warn);
}

.item .name {
  min-width: 0;
  word-break: break-word;
  cursor: text;
  border-radius: 6px;
  padding: 1px 4px;
  border: 1px dashed transparent;
}
.item .name:hover { border-color: var(--line); }
.item .name:focus, .item .note:focus, .item .qty:focus {
  outline: none; border-color: var(--accent); background: var(--bg-2);
}
.item .qty {
  font-size: 12px; font-weight: 700;
  color: var(--accent);
  background: rgba(84, 209, 192, .10);
  border: 1px solid rgba(84, 209, 192, .28);
  border-radius: 999px;
  padding: 1px 9px;
  cursor: text;
  white-space: nowrap;
  min-width: 34px;
  text-align: center;
}
.item .qty.q-unknown { color: var(--warn); background: rgba(240, 180, 41, .12); border-color: rgba(240, 180, 41, .35); }
.item .qty[data-type="num"]::before { content: "*"; opacity: .75; margin-right: 1px; }
.item .qty[data-type="unknown"] { color: var(--warn); background: rgba(240, 180, 41, .12); border-color: rgba(240, 180, 41, .35); }
.item .qty[data-type="infinite"] { color: var(--accent-2); background: rgba(74, 163, 255, .12); border-color: rgba(74, 163, 255, .32); }
.item .note { font-size: 12px; color: var(--muted); cursor: text; border-radius: 6px; padding: 1px 4px; border: 1px dashed transparent; white-space: nowrap; }
.item .note:hover { border-color: var(--line); }

.item.done .name { text-decoration: line-through; color: var(--muted); }
.item.me-item .name { color: var(--accent); }
.item.partner-item .name { color: var(--warn); }

.row-tools { display: flex; gap: 3px; opacity: .35; transition: opacity .15s ease; }
.row-tools .icon-btn { width: 26px; height: 26px; font-size: 12px; background: transparent; border-color: transparent; }
.row-tools .icon-btn:hover { background: var(--panel); border-color: var(--line); }

.empty {
  padding: 40px 24px 60px;
  text-align: center;
  color: var(--muted);
}

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(3, 6, 14, .6);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  z-index: 50;
  padding: 20px;
}
.modal {
  width: min(460px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  animation: pop .16s ease;
}
@keyframes pop { from { transform: translateY(6px) scale(.98); opacity: 0; } }
.modal h3 { font-size: 16px; margin-bottom: 12px; }
.modal .field { margin-bottom: 12px; }
.modal label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.modal input, .modal textarea {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  outline: none;
}
.modal input:focus, .modal textarea:focus { border-color: var(--accent); }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; }
.modal .hint { font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.modal .hint code { background: var(--bg-2); border: 1px solid var(--line); padding: 1px 5px; border-radius: 5px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%; bottom: 26px;
  transform: translate(-50%, 20px);
  background: var(--panel-2);
  border: 1px solid var(--accent);
  color: var(--text);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
  z-index: 80;
  max-width: 86vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }

/* ---------- 手機 ---------- */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  .sidebar {
    border-right: 0; border-bottom: 1px solid var(--line);
    max-height: 42vh;
  }
  .project-list { flex-direction: row; overflow-x: auto; overflow-y: hidden; padding-bottom: 10px; }
  .proj-item { grid-template-columns: 24px auto; min-width: 150px; }
  .proj-item .p-count { display: none; }
  .main-head, .toolbar, .add-bar, .item-list, .progress, .bulk-panel { padding-left: 14px; padding-right: 14px; }
  .item { grid-template-columns: 24px 24px minmax(0, 1fr) auto; }
  .item .qty { grid-column: 3; justify-self: start; }
  .item .note { grid-column: 3; justify-self: start; white-space: normal; }
  .row-tools { opacity: 1; }
  .proj-title { max-width: 60vw; }
}
