/* ToDoList 网页版 — 美化样式
   桌面 max-width 960px，390px 手机自适应。
   青绿主操作 #0f766e / 蓝色筛选 #2563eb / 红色删除。
   间距体系 8/16/24/32px。 */

/* ── CSS 变量 ────────────────────────────── */
:root {
  --bg-page: #f5f5f5;
  --bg-surface: #ffffff;
  --text-primary: #1a1a1a;
  --text-tertiary: #6b7280;
  --text-quaternary: #9ca3af;
  --accent: #0f766e;
  --accent-hover: #0d6b63;
  --filter-active: #2563eb;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --stroke: #e5e7eb;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", sans-serif;
  --transition: 150ms ease;
}

/* ── 基础重置 ────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

body {
  background: var(--bg-page);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
}

/* ── 布局容器 ────────────────────────────── */
.app-shell {
  max-width: 960px;
  margin: 24px auto;
  padding: 32px 24px 40px;
  background: var(--bg-surface);
  border-radius: var(--radius);
}

/* ── 标题 ────────────────────────────────── */
.app-title {
  font-size: 30px;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--text-primary);
  padding-bottom: 20px;
}

/* ── 统计 ────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  padding-bottom: 16px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 64px;
}

.stat-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-tertiary);
}

/* ── 分割线 ──────────────────────────────── */
.divider {
  border: none;
  border-top: 1px solid var(--stroke);
  margin: 0;
}

/* ── 输入行 ──────────────────────────────── */
.input-row {
  display: flex;
  gap: 8px;
  padding: 16px 0;
}

.task-input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--stroke);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px;
  font-family: inherit;
  background: var(--bg-surface);
  color: var(--text-primary);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.task-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.task-input.invalid {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.12);
}

.task-input:disabled {
  background: #f9fafb;
  color: var(--text-tertiary);
  cursor: not-allowed;
}

.error-text {
  color: var(--danger);
  font-size: 14px;
  padding-top: 4px;
}

/* ── 按钮基础 ────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 6px;
  padding: 10px 20px;
  font-size: 16px;
  font-family: inherit;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition),
    opacity var(--transition);
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn:focus-visible {
  outline: none;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:focus-visible {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.3);
}

.btn-secondary {
  background: var(--bg-page);
  color: var(--text-primary);
  border: 1px solid var(--stroke);
}

.btn-secondary:hover:not(:disabled) {
  border-color: var(--text-tertiary);
}

.btn-secondary:focus-visible {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--stroke);
}

.btn-ghost:hover:not(:disabled) {
  background: #f9fafb;
}

.btn-ghost:focus-visible {
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.15);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
}

.btn-danger:focus-visible {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.25);
}

/* ── 筛选 Pill ──────────────────────────── */
.filter-row {
  display: flex;
  gap: 8px;
  padding: 8px 0 16px;
}

.filter-pill {
  padding: 4px 14px;
  border-radius: 16px;
  font-size: 14px;
  font-family: inherit;
  border: 1px solid var(--stroke);
  background: transparent;
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition),
    color var(--transition);
}

.filter-pill:hover {
  background: #f3f4f6;
}

.filter-pill:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.filter-pill.active {
  background: var(--filter-active);
  border-color: var(--filter-active);
  color: #fff;
}

.filter-pill:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* ── 任务列表 ────────────────────────────── */
.task-list {
  list-style: none;
  padding: 8px 0;
}

.task {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--stroke);
}

.task:last-child {
  border-bottom: none;
}

/* 自定义复选框 */
.task-check {
  appearance: none;
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  flex: none;
  border: 2px solid var(--stroke);
  border-radius: 4px;
  background: var(--bg-surface);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  position: relative;
}

.task-check:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.task-check:checked::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 1px;
  width: 6px;
  height: 10px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.task-check:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.2);
}

/* 任务完成态 */
.task.done .task-title {
  color: var(--text-tertiary);
  text-decoration: line-through;
}

.task-title {
  flex: 1;
  min-width: 0;
  font-size: 16px;
  word-break: break-word;
  overflow-wrap: break-word;
}

/* 删除按钮 */
.task-del {
  background: transparent;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  padding: 4px 8px;
  border-radius: 4px;
  flex: none;
  transition: background var(--transition);
}

.task-del:hover {
  background: #fef2f2;
}

.task-del:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2);
}

/* ── 空状态 ──────────────────────────────── */
.empty-tip {
  color: var(--text-tertiary);
  text-align: center;
  padding: 32px 0 16px;
  font-size: 15px;
}

/* ── 持久化警告 ──────────────────────────── */
.persist-warn {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
  padding: 10px 14px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  background: #fef2f2;
  color: var(--danger);
  font-size: 14px;
}

.persist-warn span {
  flex: 1;
  min-width: 180px;
}

/* ── 底部区域 ────────────────────────────── */
.footer-area {
  padding-top: 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: stretch;
}

.footer-area .btn-secondary {
  width: 100%;
}

.footer-note {
  font-size: 12px;
  color: var(--text-tertiary);
  text-align: center;
}

/* ── 删除确认对话框 ──────────────────────── */
.modal-dialog {
  border: 1px solid var(--stroke);
  border-radius: 12px;
  padding: 24px;
  max-width: 380px;
  width: calc(100% - 32px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  background: var(--bg-surface);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 16px;
}

.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.3);
}

.modal-dialog p {
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── 加载遮罩 ────────────────────────────── */
.loader {
  position: fixed;
  inset: 0;
  background: rgba(245, 245, 245, 0.97);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.loader-card {
  text-align: center;
  max-width: 360px;
}

.spinner {
  width: 34px;
  height: 34px;
  margin: 0 auto 16px;
  border-radius: 50%;
  border: 4px solid var(--stroke);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
}

.spinner.hide {
  display: none;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

#loader-msg {
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.6;
}

#loader-msg.fail {
  color: var(--danger);
  white-space: pre-wrap;
}

#btn-retry {
  margin-top: 14px;
}

/* ── 响应式：390px 窄屏 ──────────────────── */
@media (max-width: 420px) {
  .app-shell {
    margin: 0;
    border-radius: 0;
    padding: 24px 16px 32px;
  }

  .app-title {
    font-size: 26px;
    padding-bottom: 16px;
  }

  .stats-row {
    gap: 16px;
    padding-bottom: 12px;
  }

  .stat-item {
    min-width: 56px;
  }

  .input-row {
    flex-direction: column;
    padding: 12px 0;
  }

  .input-row .btn-primary {
    width: 100%;
  }

  .filter-row {
    padding: 4px 0 12px;
  }

  .task {
    padding: 12px 0;
    gap: 10px;
  }
}