/* ===== 设计变量 ===== */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e6e8ec;
  --text: #1f2329;
  --text-2: #6a7076;
  --text-3: #9aa0a6;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-bg: #eef3ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-bg: #fef2f2;
  --success: #16a34a;
  --success-hover: #15803d;
  --success-bg: #f0fdf4;
  --warning: #d97706;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-lg: 0 4px 16px rgba(16, 24, 40, 0.08);
  --radius: 10px;
  --radius-lg: 14px;
  --header-h: 64px;
  --font: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

/* ===== 基础 ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: #d3d6db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #b8bcc4; }

/* ===== 顶部栏 ===== */
.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  position: relative;
  z-index: 10;
}
.topbar__brand { display: flex; align-items: center; gap: 12px; }
.topbar__logo {
  width: 36px; height: 36px;
  border-radius: 9px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.3);
}
.topbar__title h1 { font-size: 17px; font-weight: 700; line-height: 1.2; }
.topbar__subtitle { font-size: 11px; color: var(--text-3); letter-spacing: 0.5px; text-transform: uppercase; }

.topbar__stats { display: flex; gap: 10px; margin-left: 8px; }
.stat-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 6px 16px;
  text-align: center;
  min-width: 76px;
  border: 1px solid var(--border);
}
.stat-card--done { background: var(--success-bg); border-color: #bbf7d0; }
.stat-card__num { font-size: 20px; font-weight: 800; line-height: 1.1; }
.stat-card--todo .stat-card__num { color: var(--primary); }
.stat-card--done .stat-card__num { color: var(--success); }
.stat-card__label { font-size: 11px; color: var(--text-2); }

.topbar__actions { margin-left: auto; display: flex; gap: 10px; align-items: center; }

/* 云同步状态胶囊 */
.sync-chip {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600; color: var(--text-2);
  padding: 7px 12px; border-radius: 999px;
}
.sync-chip:hover { border-color: var(--primary); }
.sync-chip__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-3); }
.sync-chip--online .sync-chip__dot { background: #22c55e; }
.sync-chip--offline .sync-chip__dot { background: #ef8b32; }
.sync-chip--syncing .sync-chip__dot { background: var(--primary); animation: sync-pulse 0.8s ease-in-out infinite; }
@keyframes sync-pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: none; cursor: pointer;
  font-family: inherit;
  font-size: 14px; font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  transition: background 0.15s, transform 0.05s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn__icon { font-size: 15px; line-height: 1; }
.btn--primary { background: var(--primary); color: #fff; box-shadow: var(--shadow); }
.btn--primary:hover { background: var(--primary-hover); }
.btn--new-day { background: var(--primary-bg); color: var(--primary); }
.btn--new-day:hover { background: #dfe8ff; }
.btn--ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--bg); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--danger:hover { background: var(--danger-hover); }
.btn--success { background: var(--success); color: #fff; }
.btn--success:hover { background: var(--success-hover); }
.btn--sm { padding: 5px 10px; font-size: 13px; border-radius: 7px; }
.btn--block { flex: 1; justify-content: center; }

/* ===== 主体布局 ===== */
.layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  padding: 16px;
  height: calc(100% - var(--header-h));
}
.panel {
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  min-height: 0;
}
.panel__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.panel__title { font-size: 15px; font-weight: 700; }
.panel__count { font-size: 12px; color: var(--text-3); font-weight: 500; }
.panel__header-right { display: flex; align-items: center; gap: 10px; }
.important-filter { display: flex; align-items: center; gap: 6px; }
.important-filter input[type="date"] {
  font-family: inherit; font-size: 13px; font-weight: 500;
  color: var(--primary); background: var(--primary-bg);
  border: 1px solid transparent; border-radius: 7px;
  padding: 5px 9px; outline: none; cursor: pointer;
}
.important-filter input[type="date"]:hover { border-color: #c3c8d0; }
.important-filter input[type="date"]:focus { border-color: var(--primary); }
.panel__body { flex: 1; overflow-y: auto; padding: 14px 16px; min-height: 0; }

.panel__tabs { display: flex; gap: 4px; padding: 10px 16px 0; border-bottom: 1px solid var(--border); }
.tab {
  border: none; background: none; cursor: pointer;
  font-family: inherit; font-size: 13px; font-weight: 600;
  color: var(--text-2);
  padding: 8px 14px;
  border-bottom: 2px solid transparent;
  transition: color 0.15s;
}
.tab--active { color: var(--primary); border-bottom-color: var(--primary); }
.tab__badge {
  background: var(--danger-bg); color: var(--danger);
  font-size: 11px; font-weight: 700;
  border-radius: 10px; padding: 1px 7px; margin-left: 4px;
}
.tab:not(.tab--active) .tab__badge { background: var(--bg); color: var(--text-2); }

/* ===== 左区：事项列表 ===== */
.date-group { margin-bottom: 20px; }
.date-group:last-child { margin-bottom: 6px; }
.date-group__head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.date-group__tag {
  font-size: 12px; font-weight: 700;
  color: var(--primary);
  background: var(--primary-bg);
  padding: 3px 10px; border-radius: 6px;
}
.date-group__date { font-size: 13px; font-weight: 600; color: var(--text-2); }
.item {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.item:hover { border-color: #c3c8d0; box-shadow: var(--shadow); }
.item__content { flex: 1; font-size: 14px; word-break: break-word; }
.item__time { font-size: 11px; color: var(--text-3); white-space: nowrap; margin-left: auto; }
.item__actions { display: flex; gap: 6px; }

.item--editing { outline: 2px solid var(--primary); outline-offset: 2px; background: #fff; }
.item__edit-input {
  flex: 1; border: 1px solid var(--border); outline: none; background: #fff;
  font-family: inherit; font-size: 14px; color: var(--text); border-radius: 6px;
  padding: 4px 8px; min-width: 0;
}
.item__edit-input:focus { border-color: var(--primary); }
.item--editing .item__time { display: none; }

/* 日期分隔的输入条 */
.composer { margin-top: 4px; }
.composer__label { font-size: 12px; font-weight: 700; color: var(--primary); margin-bottom: 6px; }
.composer__input-wrap {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg);
  border: 1px dashed #c3c8d0;
  border-radius: var(--radius);
  padding: 10px 12px;
}
.composer__input { flex: 1; border: none; outline: none; background: transparent; font-family: inherit; font-size: 14px; }
.composer__input::placeholder { color: var(--text-3); }

/* ===== 右区：待办列表 ===== */
.todo {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.todo:hover { border-color: #c3c8d0; box-shadow: var(--shadow); }
.todo__main { display: flex; align-items: flex-start; gap: 10px; }
.todo__content { flex: 1; font-size: 14px; word-break: break-word; }
.todo--done .todo__content { color: var(--text-3); text-decoration: line-through; }
.todo__meta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.todo__date {
  font-size: 12px; font-weight: 500;
  display: inline-flex; align-items: center; gap: 5px;
  color: var(--text-2);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px; padding: 4px 8px;
}
.todo__date--overdue { color: var(--danger); border-color: #fca5a5; background: var(--danger-bg); }
.todo__date input { border: none; background: none; outline: none; font-family: inherit; font-size: 12px; color: inherit; }

.todo__actions { display: flex; gap: 6px; }
.todo__edit-input {
  flex: 1; border: 1px solid var(--border); outline: none; background: #fff;
  font-family: inherit; font-size: 14px; color: var(--text); border-radius: 6px;
  padding: 4px 8px; min-width: 0;
}
.todo__edit-input:focus { border-color: var(--primary); }
.todo--editing { outline: 2px solid var(--primary); outline-offset: 2px; }
.todo__due-badge {
  font-size: 11px; font-weight: 700;
  color: var(--warning);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: 6px; padding: 2px 8px;
  display: inline-flex; align-items: center; gap: 3px;
}
.todo__empty {
  text-align: center; color: var(--text-3);
  font-size: 13px; padding: 40px 0;
}
.todo__empty-icon { font-size: 32px; display: block; margin-bottom: 8px; opacity: 0.6; }

/* 新建待办快速入口 */
.btn__block-quick {
  width: 100%;
  justify-content: center;
  padding: 12px;
  border-style: dashed;
  margin-top: 4px;
}

/* 次日到期提醒横幅 */
.reminder {
  margin: 10px 16px 0;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  color: var(--warning);
  background: #fff7ed;
  border: 1px solid #fed7aa;
  display: flex; align-items: center; gap: 6px;
}
.reminder[hidden] { display: none; }
.reminder b { font-weight: 800; }

/* 已完成组头 */
.done-group__head {
  font-size: 12px; font-weight: 700; color: var(--text-2);
  margin: 4px 0 10px;
  display: flex; align-items: center; gap: 8px;
}
.done-group__head::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ===== 弹窗 ===== */
.modal-mask {
  position: fixed; inset: 0;
  background: rgba(15, 20, 30, 0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
/* 确保 hidden 属性优先，否则 display:flex 会覆盖它导致弹窗常显 */
.modal-mask[hidden] { display: none; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: min(420px, 90vw);
  box-shadow: var(--shadow-lg);
}
.modal__text { font-size: 15px; margin-bottom: 18px; line-height: 1.6; }
.modal__actions { display: flex; gap: 10px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(30, 35, 42, 0.92);
  color: #fff; font-size: 13px;
  padding: 10px 18px; border-radius: 8px;
  z-index: 200;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 响应式：窄屏(手机竖屏)下左右堆叠 ===== */
@media (max-width: 860px) {
  body { overflow: auto; }
  .layout { grid-template-columns: 1fr; height: auto; gap: 12px; padding: 12px; }
  .panel--todo { min-height: 50vh; }
  .topbar { flex-wrap: wrap; height: auto; padding: 10px 12px; gap: 8px; }
  .topbar__brand { gap: 8px; }
  .topbar__logo { width: 30px; height: 30px; font-size: 15px; }
  .topbar__title h1 { font-size: 15px; }
  .topbar__subtitle { display: none; }
  .topbar__stats { margin-left: 0; gap: 6px; }
  .stat-card { min-width: 60px; padding: 4px 10px; }
  .stat-card__num { font-size: 16px; }
  .stat-card__label { font-size: 10px; }
  .topbar__actions { margin-left: 0; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
  .btn__text { display: none; }
  .btn { padding: 6px 10px; font-size: 13px; }
  .sync-chip { padding: 5px 10px; font-size: 12px; }
  .topbar__user { font-size: 12px; }
  .panel__header { padding: 10px 12px; flex-wrap: wrap; gap: 6px; }
  .panel__title { font-size: 14px; }
  .panel__body { padding: 10px 12px; }
  .important-filter input[type="date"] { font-size: 12px; padding: 4px 6px; }
  .composer__input-wrap { padding: 8px 10px; }
  .item { padding: 8px 10px; }
  .todo { padding: 10px 12px; }
  .auth-card { padding: 20px 16px; }
  .modal { padding: 18px; width: min(380px, 92vw); }
}

@media (max-width: 480px) {
  .topbar { padding: 8px 10px; gap: 6px; }
  .topbar__brand { gap: 6px; }
  .topbar__logo { width: 26px; height: 26px; font-size: 13px; border-radius: 7px; }
  .topbar__title h1 { font-size: 13px; }
  .topbar__stats { gap: 4px; }
  .stat-card { min-width: 50px; padding: 3px 8px; }
  .stat-card__num { font-size: 14px; }
  .topbar__actions { gap: 4px; }
  .btn { padding: 5px 8px; font-size: 12px; }
  .sync-chip { padding: 4px 8px; font-size: 11px; }
  .layout { padding: 8px; gap: 8px; }
  .panel__header { padding: 8px 10px; }
  .panel__body { padding: 8px 10px; }
  .item { padding: 6px 8px; margin-bottom: 6px; }
  .item__content { font-size: 13px; }
  .todo { padding: 8px 10px; margin-bottom: 8px; }
  .todo__content { font-size: 13px; }
  .composer__input-wrap { padding: 6px 8px; }
  .composer__input { font-size: 13px; }
  .auth-card { padding: 16px 12px; }
  .auth-card__brand h2 { font-size: 17px; }
}

/* ===== 登录 / 注册界面 ===== */
.auth-mask {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #eef2ff 0%, #f5f6f8 60%, #ffffff 100%);
  padding: 20px;
}
.auth-mask[hidden] { display: none; }
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 10px 40px rgba(31, 35, 41, 0.08);
  padding: 28px 24px;
}
.auth-card__brand { text-align: center; margin-bottom: 20px; }
.auth-card__logo {
  width: 56px; height: 56px;
  margin: 0 auto 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary); color: #fff;
  font-size: 24px; font-weight: 700;
  border-radius: 14px;
}
.auth-card__brand h2 { font-size: 20px; margin: 0; color: var(--text); }
.auth-card__brand p { margin: 4px 0 0; font-size: 12px; color: var(--text-3); }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; background: var(--bg); padding: 4px; border-radius: 10px; }
.auth-tab {
  flex: 1; padding: 8px 0; border: none; background: transparent;
  color: var(--text-2); font-size: 14px; font-weight: 500; border-radius: 7px; cursor: pointer;
  transition: all .15s;
}
.auth-tab.is-active { background: var(--surface); color: var(--primary); box-shadow: 0 1px 3px rgba(31,35,41,.08); font-weight: 600; }
.auth-form { display: flex; flex-direction: column; gap: 14px; }
/* 确保 hidden 属性优先，否则 display:flex 会覆盖它导致登录/注册表单同时显示 */
.auth-form[hidden] { display: none; }
.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field__label { font-size: 13px; color: var(--text-2); }
.auth-field__label em { font-style: normal; color: var(--text-3); font-size: 11px; }
.auth-field__input {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; color: var(--text); background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
}
.auth-field__input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-bg); }
.auth-error { font-size: 12px; color: var(--danger); margin: -4px 0 0; }
.btn--block { width: 100%; }

/* 用户栏 */
.topbar__user { display: inline-flex; align-items: center; gap: 6px; }
.topbar__username { font-size: 13px; color: var(--text-2); font-weight: 600; }
