:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #232a38;
  --muted: #6b7488;
  --line: #e5e9f2;
  --accent: #4f6bfa;
  --accent-dark: #3c54d8;
  --accent-soft: #e6ecff;
  --danger: #d64545;
  --ok: #2ea86f;
  --field: #ffffff;
  --field-line: #dfe4ee;
  --btn-bg: #ffffff;
  --tabbar-bg: #eef1f8;
  --ghost-hover: rgba(20, 30, 60, .06);
  --overlay: rgba(18, 24, 38, .45);
  --toast-bg: #232a38;
  --toast-text: #ffffff;
  --focus-ring: rgba(79, 107, 250, .14);
  --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 6px 20px rgba(20, 30, 60, .05);
  --shadow-lg: 0 4px 12px rgba(20, 30, 60, .10), 0 20px 50px rgba(20, 30, 60, .16);
  --radius: 12px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1117;
  --surface: #181c25;
  --text: #e7eaf1;
  --muted: #8b94a8;
  --line: #262c3a;
  --accent: #6c84ff;
  --accent-dark: #8da0ff;
  --accent-soft: #23305e;
  --danger: #f26d6d;
  --ok: #46c189;
  --field: #10141c;
  --field-line: #2c3343;
  --btn-bg: #1e2431;
  --tabbar-bg: #1a2030;
  --ghost-hover: rgba(255, 255, 255, .07);
  --overlay: rgba(0, 0, 0, .55);
  --toast-bg: #2a3142;
  --toast-text: #eef1f7;
  --focus-ring: rgba(108, 132, 255, .30);
  --shadow: 0 1px 3px rgba(0, 0, 0, .30), 0 6px 20px rgba(0, 0, 0, .28);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, .40), 0 20px 50px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  transition: background .2s, color .2s;
}

.hidden { display: none !important; }
.flex-spacer { flex: 1; }

/* ---------------- 通用 ---------------- */
.view { min-height: 100vh; }

.container { max-width: 980px; margin: 0 auto; padding: 28px 16px 60px; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2 { margin: 0 0 12px; font-size: 16px; font-weight: 600; }

.btn {
  border: 1px solid var(--field-line);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 9px;
  padding: 8px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { background: var(--ghost-hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.primary:disabled { opacity: .55; cursor: default; }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.btn.small { padding: 4px 10px; font-size: 13px; border-radius: 7px; }
.btn.block { width: 100%; margin-top: 6px; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--ghost-hover); color: var(--text); }

.input, .tag-select {
  width: 100%;
  border: 1px solid var(--field-line);
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--field);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.input:focus, .tag-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--focus-ring); }
textarea.input { resize: vertical; font-family: inherit; }
.tag-select { width: auto; padding: 8px 10px; }

.msg { min-height: 60px; }

.row { display: flex; gap: 10px; margin-top: 10px; align-items: center; flex-wrap: wrap; }
.row .input { flex: 1; min-width: 200px; }
.row.right { justify-content: flex-end; }

.error { color: var(--danger); font-size: 13px; min-height: 1em; margin: 8px 0 0; }
.status { color: var(--muted); font-size: 13px; }
.hint { color: var(--muted); font-size: 13px; margin: 12px 0 0; text-align: center; }
.hint.left { text-align: left; margin: 6px 0 10px; }

/* ---------------- 登录页 ---------------- */
.auth-center { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card { width: 380px; max-width: 100%; padding: 28px 28px 20px; }
.auth-card .brand { text-align: center; font-size: 26px; margin: 0; }
.auth-card .subtitle { text-align: center; color: var(--muted); margin: 6px 0 18px; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; background: var(--tabbar-bg); border-radius: 9px; padding: 4px; }
.tab { flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 7px; cursor: pointer; color: var(--muted); font-size: 14px; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.auth-card form { display: flex; flex-direction: column; gap: 10px; }

/* ---------------- 顶栏 ---------------- */
.topbar-wrap { position: sticky; top: 0; z-index: 20; }
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar .brand { font-size: 18px; font-weight: 700; }
.userbox { display: flex; align-items: center; gap: 10px; }
.who { color: var(--muted); font-size: 14px; }

/* ---------------- 视图标签栏 ---------------- */
.viewtabs {
  display: flex; gap: 4px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 20px;
}
.viewtab {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 14px; font-family: inherit;
  padding: 11px 14px 9px;
  border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 7px;
  margin-bottom: -1px;
}
.viewtab:hover { color: var(--text); }
.viewtab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.viewtab .pill { background: var(--accent-soft); color: var(--accent-dark); }
.viewtab:not(.active) .pill { background: var(--tabbar-bg); color: var(--muted); }

/* ---------------- 操作栏 ---------------- */
.actionbar { margin-bottom: 22px; }
.actionline { display: flex; align-items: center; gap: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; align-items: center; }
.chips-label { color: var(--muted); font-size: 13px; margin-right: 2px; }
.chip {
  border: 1px solid var(--field-line);
  background: var(--surface);
  color: var(--text);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform .06s, background .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); }
.chip.active { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.chip.tag-chip { color: var(--text); }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

/* ---------------- 任务列表 ---------------- */
.list-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 18px 18px;
}

.col-head { display: flex; align-items: center; gap: 8px; font-size: 15px; margin: 2px 0 10px; }
.col-head > span:first-child { display: inline-flex; align-items: center; gap: 8px; }
.pill {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-radius: 999px;
  padding: 1px 10px;
  font-size: 12px;
  font-weight: 600;
}

.tasklist { display: flex; flex-direction: column; gap: 8px; min-height: 60px; }

.empty {
  color: var(--muted); font-size: 13px; text-align: center; padding: 18px 0;
  border: 1px dashed var(--line); border-radius: 9px;
}

.task {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  transition: opacity .15s, background .15s;
}
.task.done { opacity: .66; background: color-mix(in srgb, var(--surface) 70%, var(--bg)); }
.task.done .task-title { text-decoration: line-through; color: var(--muted); }

.task-title { font-size: 14.5px; font-weight: 500; word-break: break-word; }
.task-note { font-size: 13px; color: var(--muted); margin-top: 2px; word-break: break-word; white-space: pre-line; }
.task-meta { font-size: 12px; color: var(--muted); }

/* 底部一行：左侧元信息，右侧标签 + 原文/编辑/删除 */
.task-footer { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.task-footer .task-meta { flex: 1; min-width: 0; }
.task-tools { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.task-edit-ops { display: flex; gap: 6px; margin-top: 8px; }

.task-time { margin-top: 6px; }
.time-chip {
  border: 1px solid var(--field-line);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  padding: 2px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.time-chip:hover { border-color: var(--accent); }
.time-chip:disabled { cursor: default; opacity: .9; }
.time-chip:disabled:hover { border-color: var(--field-line); }
.time-chip.empty { border-style: dashed; color: var(--muted); }
.time-chip.empty:hover { color: var(--accent); }

.tag-pick {
  font-family: inherit;
  font-size: 12px;
  line-height: 1.9;
  height: auto;
  width: 72px;
  max-width: 72px;
  text-overflow: ellipsis;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 1px 2px 1px 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.tag-pick:hover { border-color: var(--accent); }
.tag-pick option { color: var(--text); background: var(--surface); }

.due-overdue { color: var(--danger); font-weight: 700; }
.due-near { color: var(--accent-dark); }

.task-body { flex: 1; min-width: 0; }
.cb { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }

.task-title-input { margin-bottom: 6px; }
.task-note-input { font-size: 13px; color: var(--muted); }
.edit-extra { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.edit-extra label { font-size: 13px; color: var(--muted); }
.edit-extra input[type="date"] { width: auto; flex: 0 0 148px; padding: 6px 10px; }
.edit-extra input[type="time"] { width: auto; flex: 0 0 108px; padding: 6px 10px; }
.edit-extra .tag-select { flex: 0 0 auto; padding: 6px 10px; }

/* ---------------- 弹框 ---------------- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px; z-index: 60; overflow-y: auto;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  padding: 18px 20px;
  margin-bottom: 6vh;
  animation: pop .16s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(-6px) scale(.99); } }
#add-modal .modal { max-width: 640px; }

.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { font-size: 17px; font-weight: 700; }

.source-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  max-height: 55vh;
  overflow: auto;
}

/* 手动添加：标题 / 描述 / 到期日 / 标签 */
#pane-manual { padding-top: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; min-width: 0; }
.field label { font-size: 13px; color: var(--muted); }
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1; }
.field-row .field:first-child { flex: 1.4; }

/* 解析预览：每条结果一张卡片 */
.preview { margin-top: 6px; border-top: 1px solid var(--line); padding-top: 12px; }
.preview-title { font-size: 13px; color: var(--muted); margin: 0 0 10px; }
.preview-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
  background: color-mix(in srgb, var(--surface) 55%, var(--bg));
}
.p-head { display: flex; align-items: center; gap: 8px; }
.preview-check { width: 18px; height: 18px; accent-color: var(--accent); flex-shrink: 0; cursor: pointer; }
.p-head .p-title { flex: 1; min-width: 0; font-weight: 600; }
.p-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.p-field > label { font-size: 12px; color: var(--muted); }
.preview-row .p-note { width: 100%; line-height: 1.5; }
.p-fields { display: flex; gap: 10px; flex-wrap: wrap; }
.p-fields input[type="date"] { width: 152px; }
.p-fields input[type="time"] { width: 118px; }
.preview-foot { display: flex; gap: 10px; margin-top: 4px; align-items: center; }

/* ---------------- 标签管理 ---------------- */
.tag-item {
  display: flex; gap: 8px; align-items: center;
  padding: 8px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
}
.tag-item input[type="color"] { width: 30px; height: 28px; border: 1px solid var(--field-line); border-radius: 6px; padding: 1px; background: transparent; cursor: pointer; flex-shrink: 0; }
.tag-item .input { min-width: 0; }
.tag-ops { display: flex; gap: 4px; flex-shrink: 0; }
.tag-add-row { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.tag-add-row input[type="color"] { width: 38px; height: 36px; border: 1px solid var(--field-line); border-radius: 8px; padding: 2px; background: transparent; cursor: pointer; }

/* ---------------- 管理后台 ---------------- */
.admin-sec { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.admin-sec:first-of-type { border-top: 0; margin-top: 4px; padding-top: 0; }
.admin-h { font-size: 14px; font-weight: 600; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.admin-invite-row { display: flex; gap: 8px; align-items: center; }
.admin-invite-row .input { flex: 1; min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.admin-check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.admin-check input { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

.admin-user {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 8px;
}
.admin-user-info { flex: 1; min-width: 0; }
.admin-user-name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; }
.admin-user-sub { font-size: 12px; color: var(--muted); margin-top: 1px; }
.admin-user-ops { display: flex; gap: 4px; flex-shrink: 0; }
.admin-badge {
  font-size: 11px; font-weight: 600; color: var(--accent-dark);
  background: var(--accent-soft); border-radius: 999px; padding: 0 8px;
}

/* ---------------- 轻提示 toast ---------------- */
.toast-wrap {
  position: fixed; top: 16px; left: 0; right: 0;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  z-index: 120; pointer-events: none; padding: 0 16px;
}
.toast {
  pointer-events: auto;
  background: var(--toast-bg); color: var(--toast-text);
  padding: 9px 14px; border-radius: 10px;
  font-size: 14px; display: flex; align-items: center; gap: 12px;
  box-shadow: var(--shadow-lg); max-width: 90vw;
  animation: slideDown .18s ease;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-8px); } }
.toast-msg { word-break: break-word; }
.toast-action {
  border: 0; background: var(--accent); color: #fff; border-radius: 7px;
  padding: 4px 12px; font-size: 13px; cursor: pointer; flex-shrink: 0;
}
.toast-action:hover { background: var(--accent-dark); }
