/* ===========================================================
   子彈筆記 PWA — 「紙張」主題
   書中原則：少，卻更好。功能永遠大於形式。
   =========================================================== */

:root {
  --paper: #f7f3ea;
  --paper-2: #fffdf7;
  --ink: #23201b;
  --ink-soft: #5d564c;
  --ink-faint: #8c857a;
  --line: #ddd5c6;
  --line-soft: #eae3d6;
  --accent: #b4472f;
  --accent-soft: #f3e2dc;
  --ok: #3f6b45;
  --ok-soft: #e3ecdf;
  --warn: #8a6a1f;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(35, 32, 27, .06), 0 4px 14px rgba(35, 32, 27, .05);
  --font: -apple-system, BlinkMacSystemFont, "PingFang TC", "PingFang SC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
  --nav-h: 58px;
  --side-w: 208px;
}

[data-surface="grid"] {
  --rule: repeating-linear-gradient(to bottom, transparent 0 27px, var(--line-soft) 27px 28px);
}
[data-surface="lines"] {
  --rule: repeating-linear-gradient(to bottom, transparent 0 19px, var(--line) 19px 20px);
}
[data-surface="dot"] {
  --rule: radial-gradient(var(--line) 1px, transparent 1px);
}

[data-theme="dark"] {
  --paper: #1d1b18;
  --paper-2: #26231f;
  --ink: #ece6da;
  --ink-soft: #b8afa0;
  --ink-faint: #8d8375;
  --line: #3a362f;
  --line-soft: #322e28;
  --accent: #e08163;
  --accent-soft: #3b2a23;
  --ok: #8fbf94;
  --ok-soft: #26332a;
  --warn: #d8b566;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 18px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a.tag { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; }

/* ---------- 版面 ---------- */

#app {
  display: flex;
  min-height: 100%;
}

.side {
  display: none;
  width: var(--side-w);
  flex-shrink: 0;
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand { font-weight: 700; font-size: 17px; padding: 0 10px 16px; letter-spacing: .02em; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: var(--ink-faint); letter-spacing: 0; }
.side a.navitem {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--ink-soft);
  font-size: 14.5px;
}
.side a.navitem .ico { width: 18px; text-align: center; font-size: 15px; }
.side a.navitem.active { background: var(--paper-2); color: var(--ink); font-weight: 600; box-shadow: var(--shadow); }

main {
  flex: 1;
  min-width: 0;
  padding: 18px 16px calc(var(--nav-h) + 28px);
  max-width: 760px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .side { display: block; }
  .tabbar { display: none !important; }
  main { padding-bottom: 60px; }
}

/* ---------- 底部導覽（手機） ---------- */

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: color-mix(in srgb, var(--paper-2) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--line);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--ink-faint); font-size: 10.5px; padding-top: 6px;
}
.tabbar a .ico { font-size: 18px; line-height: 1; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

/* ---------- 標題 ---------- */

.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
h1 { font-size: 22px; margin: 0; letter-spacing: .01em; }
h1 .sub { display: block; font-size: 12px; font-weight: 400; color: var(--ink-faint); margin-top: 3px; }
h2 { font-size: 15px; margin: 26px 0 10px; color: var(--ink-soft); font-weight: 600; display: flex; align-items: center; gap: 8px; }
h2 .count { font-size: 12px; font-weight: 400; color: var(--ink-faint); }
.quote { font-size: 12px; color: var(--ink-faint); font-style: italic; margin-top: 2px; }

/* ---------- 按鈕 ---------- */

.btn {
  border: 1px solid var(--line); background: var(--paper-2); color: var(--ink);
  border-radius: 8px; padding: 7px 12px; font-size: 14px;
}
.btn:hover { border-color: var(--ink-faint); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.icon { padding: 6px 9px; line-height: 1; }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- 子彈清單 ---------- */

.bullets { list-style: none; margin: 0; padding: 0; }
.bullet {
  display: grid;
  grid-template-columns: 30px 1fr auto;
  align-items: start;
  gap: 8px;
  padding: 7px 4px 7px 0;
  border-bottom: 1px dashed var(--line-soft);
  position: relative;
}
.bullet:focus-within { background: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.bullet.child { margin-left: 22px; border-left: 2px solid var(--line-soft); padding-left: 8px; grid-template-columns: 26px 1fr auto; }

.marker {
  background: none; border: 0; padding: 0; width: 26px; height: 26px;
  font-size: 17px; line-height: 26px; text-align: center; color: var(--ink); border-radius: 6px;
  font-family: var(--mono);
}
.marker:hover { background: var(--line-soft); }
.marker.done { color: var(--ok); }
.marker.migrated, .marker.scheduled { color: var(--warn); }
.marker.dropped { color: var(--ink-faint); }

.btext { font-size: 15.5px; word-break: break-word; padding-top: 2px; min-width: 0; }
.btext .sign { color: var(--accent); font-weight: 700; margin-right: 2px; font-family: var(--mono); }
.bullet[data-status="done"] .btext { color: var(--ink-faint); }
.bullet[data-status="done"] .btext .txt { text-decoration: line-through; text-decoration-thickness: 1px; }
.bullet[data-status="dropped"] .btext .txt { color: var(--ink-faint); text-decoration: line-through; }
.bullet[data-status="migrated"] .btext .txt, .bullet[data-status="scheduled"] .btext .txt { color: var(--ink-faint); }

.bmeta { font-size: 11px; color: var(--ink-faint); margin-top: 1px; }
.bmeta .rel { color: var(--warn); }

.bactions { display: flex; gap: 2px; opacity: .55; transition: opacity .15s; }
.bullet:hover .bactions, .bullet:focus-within .bactions { opacity: 1; }
.bactions button {
  border: 0; background: none; color: var(--ink-faint); font-size: 14px;
  padding: 4px 6px; border-radius: 6px; line-height: 1;
}
.bactions button:hover { background: var(--line-soft); color: var(--ink); }

.empty { color: var(--ink-faint); font-size: 14px; padding: 14px 2px; }

/* ---------- 快速記錄輸入列 ---------- */

.composer {
  position: sticky; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 6px);
  margin-top: 18px; z-index: 20;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 8px;
}
@media (min-width: 900px) { .composer { bottom: 14px; } }

.composer .types { display: flex; gap: 4px; margin-bottom: 6px; }
.composer .types button {
  border: 1px solid transparent; background: transparent; color: var(--ink-faint);
  border-radius: 7px; padding: 3px 9px; font-size: 14px; font-family: var(--mono);
  display: flex; align-items: center; gap: 5px;
}
.composer .types button small { font-family: var(--font); font-size: 11.5px; }
.composer .types button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 30%, transparent); }
.composer .types .spacer { flex: 1; }
.composer .types button.sign[aria-pressed="true"] { background: var(--accent); color: #fff; }

.composer .inputrow { display: flex; gap: 6px; }
.composer textarea, .composer input[type="text"] {
  flex: 1; border: 1px solid var(--line); background: var(--paper);
  border-radius: 8px; padding: 9px 11px; resize: none; min-height: 42px; max-height: 40vh;
  font-size: 16px; /* 避免 iOS 聚焦縮放 */
}
.composer textarea:focus, .composer input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: -1px; border-color: var(--accent); }
.composer .send { align-self: stretch; padding: 0 14px; }

/* ---------- 卡片 / 面板 ---------- */

.card {
  background: var(--paper-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
}
.card + .card { margin-top: 12px; }
.card h3 { font-size: 14px; margin: 0 0 8px; color: var(--ink-soft); }
.card textarea {
  width: 100%; border: 1px solid var(--line); background: var(--paper); border-radius: 8px;
  padding: 10px; min-height: 76px; resize: vertical; font-size: 15px; line-height: 1.55;
}
.card textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); outline-offset: -1px; }
.muted { color: var(--ink-faint); font-size: 13px; }

details.card > summary {
  cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-soft);
  list-style: none; display: flex; align-items: center; gap: 8px;
}
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::before { content: "▸"; color: var(--ink-faint); transition: transform .15s; }
details.card[open] > summary::before { transform: rotate(90deg); }
details.card > summary .fill { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--ok); }
details.card > .body { margin-top: 10px; }

/* ---------- 月曆頁 ---------- */

.month-grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
@media (min-width: 700px) { .month-grid { grid-template-columns: 1fr 1fr; } }

.calendar { border-top: 1px solid var(--line); }
.calrow {
  display: grid; grid-template-columns: 46px 1fr; gap: 10px; align-items: baseline;
  padding: 6px 2px; border-bottom: 1px solid var(--line-soft); min-height: 34px;
}
.calrow.today { background: var(--accent-soft); border-radius: 6px; }
.calrow .d { font-family: var(--mono); font-size: 13px; color: var(--ink-soft); cursor: pointer; }
.calrow .d b { font-size: 15px; color: var(--ink); font-weight: 600; }
.calrow .d span { color: var(--ink-faint); margin-left: 4px; }
.calrow.weekend .d span { color: var(--accent); }
.calrow .items { font-size: 13.5px; color: var(--ink-soft); min-width: 0; }
.calrow .items .it { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.calrow .items .it .m { font-family: var(--mono); margin-right: 5px; color: var(--ink-faint); }
.calrow .items .it.done .m { color: var(--ok); }
.calrow .items .more { color: var(--ink-faint); font-size: 12px; }

/* ---------- 追蹤器 ---------- */

.tracker { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tracker table { border-collapse: collapse; font-size: 12px; width: max-content; min-width: 100%; }
.tracker table th:first-child { width: 112px; min-width: 112px; }
.tracker th, .tracker td { border: 1px solid var(--line-soft); padding: 0; text-align: center; }
.tracker th.habit { text-align: left; padding: 6px 8px; font-weight: 600; font-size: 13px; position: sticky; left: 0; background: var(--paper-2); min-width: 108px; }
.tracker thead th { color: var(--ink-faint); font-weight: 500; font-family: var(--mono); padding: 4px 0; font-size: 10.5px; width: 26px; min-width: 26px; }
.tracker .scrollhint { font-size: 11.5px; color: var(--ink-faint); margin: 0 0 6px; }
@media (min-width: 700px) { .tracker .scrollhint { display: none; } }
.tracker thead th.weekend { color: var(--accent); }
.tracker td { height: 30px; padding: 0; width: 26px; min-width: 26px; }
.tracker td button { width: 100%; height: 100%; border: 0; background: transparent; font-size: 13px; color: transparent; }
.tracker td.on button { background: var(--ok-soft); color: var(--ok); }
.tracker td.today { box-shadow: inset 0 0 0 2px var(--accent); }
.tracker td.future button { color: var(--line); }
.streak { font-size: 11.5px; color: var(--ink-faint); display: block; font-weight: 400; }

/* ---------- 索引 ---------- */

.idx { list-style: none; margin: 0; padding: 0; }
.idx li {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
  padding: 11px 2px; border-bottom: 1px dashed var(--line-soft);
}
.idx a.t { font-size: 15.5px; color: var(--ink); font-weight: 500; }
.idx .kind { font-size: 10.5px; padding: 1px 6px; border-radius: 4px; background: var(--line-soft); color: var(--ink-soft); margin-right: 6px; vertical-align: 1px; }
.idx .meta { font-size: 11.5px; color: var(--ink-faint); }

/* ---------- 審視 ---------- */

.review-step { border-left: 3px solid var(--line); padding: 2px 0 2px 14px; margin: 0 0 22px; }
.review-step.active { border-left-color: var(--accent); }
.review-step h3 { margin: 0 0 8px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.stepno { display: inline-flex; width: 22px; height: 22px; border-radius: 50%; align-items: center; justify-content: center; font-size: 12px; background: var(--line-soft); color: var(--ink-soft); }
.review-step.done .stepno { background: var(--ok-soft); color: var(--ok); }
.review-item { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line-soft); }
.review-item .acts { display: flex; gap: 4px; flex-wrap: wrap; }

/* ---------- 表單／設定 ---------- */

.field { display: block; margin-bottom: 14px; }
.field span.lbl { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.field input[type="text"], .field input[type="date"], .field select {
  width: 100%; border: 1px solid var(--line); background: var(--paper-2); border-radius: 8px; padding: 9px 11px; font-size: 15px;
}
.switchrow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line-soft); }
.switchrow:last-child { border-bottom: 0; }

/* ---------- 提示訊息 ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px);
  background: var(--ink); color: var(--paper); padding: 9px 16px; border-radius: 999px;
  font-size: 13.5px; z-index: 100; box-shadow: var(--shadow); max-width: 90vw;
  animation: toastIn .18s ease-out;
}
@media (min-width: 900px) { .toast { bottom: 24px; } }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 6px); } to { opacity: 1; transform: translate(-50%, 0); } }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(20, 18, 15, .38); z-index: 60;
  display: flex; align-items: flex-end; justify-content: center;
}
.sheet {
  background: var(--paper-2); width: 100%; max-width: 520px; border-radius: 16px 16px 0 0;
  padding: 18px 18px calc(18px + env(safe-area-inset-bottom)); box-shadow: var(--shadow);
  animation: sheetIn .2s ease-out;
}
@media (min-width: 900px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 16px; margin-bottom: 10vh; } }
@keyframes sheetIn { from { transform: translateY(14px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet h3 { margin: 0 0 4px; font-size: 17px; }
.sheet .hint { font-size: 13px; color: var(--ink-faint); margin: 0 0 14px; }

/* ---------- 其他 ---------- */

.pill { display: inline-block; font-size: 11.5px; padding: 2px 8px; border-radius: 999px; background: var(--line-soft); color: var(--ink-soft); }
.pill.warn { background: var(--accent-soft); color: var(--accent); }
.hint-box { font-size: 12.5px; color: var(--ink-soft); background: var(--paper-2); border: 1px dashed var(--line); border-radius: 8px; padding: 9px 12px; margin: 10px 0; }
.hint-box b { color: var(--ink); }
.offline-badge { position: fixed; top: 8px; right: 10px; z-index: 50; font-size: 11px; background: var(--warn); color: #fff; border-radius: 999px; padding: 2px 9px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media print {
  .side, .tabbar, .composer, .bactions { display: none !important; }
}
