:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1c2333;
  --muted: #7a8294;
  --primary: #4f6ef7;
  --primary-dark: #3d59d9;
  --ok: #26a269;
  --danger: #d64541;
  --warn: #e67e22;
  --radius: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC",
    "PingFang TC", "Microsoft JhengHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.hidden { display: none !important; }

/* --- 登入 --- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 340px;
}
.login-title {
  font-size: 1.3rem;
  font-weight: 700;
  text-align: center;
  margin-bottom: 18px;
}

/* --- 卡片 --- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

/* --- 頂欄 --- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
}
.tabs {
  display: flex;
  gap: 6px;
  flex: 1;
}
.tab {
  padding: 8px 16px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 20px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  transition: .15s;
}
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* --- 內容容器 --- */
.tab-pane {
  max-width: 860px;
  margin: 0 auto;
  padding: 16px;
}

/* --- 工具列 --- */
.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}
.filters {
  display: flex;
  align-items: center;
  gap: 8px;
}
.filters label {
  font-size: .9rem;
  color: var(--muted);
  font-weight: 600;
}
.select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  font-size: .95rem;
  cursor: pointer;
}

/* --- 使用說明 --- */
.help {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 14px;
}
.help summary {
  cursor: pointer;
  font-weight: 600;
  font-size: .92rem;
}
.help ul { margin: 10px 0 4px; padding-left: 18px; }
.help li { margin-bottom: 5px; font-size: .9rem; color: var(--text); }
code {
  background: #eef1f6;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: .85em;
}

/* --- 待辦清單 --- */
.list { display: flex; flex-direction: column; gap: 8px; }
.todo-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
}
.todo-check {
  width: 20px;
  height: 20px;
  accent-color: var(--ok);
  cursor: pointer;
  flex-shrink: 0;
}
.todo-body { flex: 1; min-width: 0; }
.todo-title {
  font-weight: 600;
  word-break: break-word;
}
.todo-title.done { text-decoration: line-through; color: var(--muted); }
.todo-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 4px;
  font-size: .82rem;
  color: var(--muted);
}
.badge {
  border-radius: 20px;
  padding: 1px 9px;
  font-size: .75rem;
  font-weight: 700;
}
.badge.pub { background: #e3ecff; color: #2f54d0; }
.badge.pri { background: #ffe9e3; color: #d64541; }
.due { font-weight: 600; }
.due.overdue { color: var(--danger); }
.due.today { color: var(--warn); }
.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1.05rem;
  padding: 4px 6px;
  border-radius: 6px;
  color: var(--muted);
}
.icon-btn:hover { background: var(--bg); }

/* --- 筆記網格 --- */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 12px;
}
.note-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0,0,0,.03);
  position: relative;
}
.note-card.pinned { border-color: #ffd98a; background: #fffdf5; }
.note-pin-mark {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 1rem;
}
.note-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 8px;
  word-break: break-word;
  padding-right: 22px;
}
.note-preview {
  color: var(--text);
  font-size: .92rem;
  word-break: break-word;
  max-height: 150px;
  overflow: hidden;
}
.note-preview p { margin: 0 0 6px; }
.note-preview h1,.note-preview h2,.note-preview h3 {
  font-size: 1rem;
  margin: 8px 0 4px;
}
.note-preview ul { margin: 4px 0; padding-left: 18px; }
.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}
.tag {
  background: #eef1f6;
  border-radius: 20px;
  padding: 2px 10px;
  font-size: .75rem;
  color: var(--muted);
  font-weight: 600;
}
.note-actions {
  display: flex;
  gap: 4px;
  margin-top: 10px;
  justify-content: flex-end;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 0;
  font-size: .95rem;
}

/* --- 按鈕 --- */
.btn {
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  font-size: .95rem;
  font-weight: 600;
  background: var(--card);
  color: var(--text);
  transition: .15s;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.ghost { border-color: transparent; color: var(--muted); background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.block { width: 100%; margin-top: 14px; }

/* --- 表單 --- */
.field {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
  margin-bottom: 10px;
  background: var(--card);
}
textarea.field { resize: vertical; }
.row { display: flex; gap: 10px; }
.row .field { margin-bottom: 10px; }

/* --- 彈窗 --- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}
.modal-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 22px;
  width: 100%;
  max-width: 460px;
  box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin-bottom: 14px;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #2b3245;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: .9rem;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}

/* --- 訊息 --- */
.msg { margin-top: 12px; font-size: .9rem; text-align: center; }
.msg.error { color: var(--danger); }

@media (max-width: 480px) {
  .toolbar { flex-direction: column; align-items: stretch; }
  .app-title { font-size: 1rem; }
  .tab { padding: 7px 12px; font-size: .88rem; }
  .row { flex-direction: column; }
}
