/* ============ 基础变量 ============ */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --border: #e6e8ec;
  --border-strong: #d5d8de;
  --text: #1b1f27;
  --text-2: #626b7a;
  --text-3: #98a1b0;
  --primary: #3355ff;
  --primary-dark: #2843e0;
  --primary-soft: #eef1ff;
  --danger: #e0384a;
  --danger-soft: #fff1f2;
  --success: #17a673;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow: 0 4px 16px rgba(16, 24, 40, .07);
  --shadow-lg: 0 16px 48px rgba(16, 24, 40, .16);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

button, input, select { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }
.page { min-height: 100vh; min-height: 100dvh; }

/* ============ 通用按钮 ============ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 18px; border-radius: var(--radius-sm);
  font-weight: 600; font-size: 15px; letter-spacing: .3px;
  transition: background .16s, transform .1s, box-shadow .16s;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 2px 8px rgba(51, 85, 255, .24); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { background: #b9c2d6; box-shadow: none; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 16px; font-size: 14px; }

.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 17px; color: var(--text-2); transition: background .15s;
}
.icon-btn:hover { background: #eef0f4; }

.link-btn {
  background: none; color: var(--primary); font-weight: 600;
  font-size: 13px; padding: 4px 6px; border-radius: 6px;
}
.link-btn:hover { background: var(--primary-soft); }
.link-btn.danger { color: var(--danger); }
.link-btn.danger:hover { background: var(--danger-soft); }

.form-error {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid #ffd4d8; border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13.5px; margin-bottom: 12px;
}

.field { display: block; margin-bottom: 15px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 7px; }
.field input, .field select {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); outline: none;
  transition: border-color .15s, box-shadow .15s; font-size: 16px;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(51, 85, 255, .13); }

.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 46px; }
.pw-toggle {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 8px; font-size: 15px; opacity: .5;
}
.pw-toggle:hover { opacity: .9; background: #eef0f4; }

/* ============ 登录页 ============ */
.login-page {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px 18px calc(24px + var(--safe-b));
  background:
    radial-gradient(1000px 500px at 15% -10%, #e4e9ff 0%, transparent 55%),
    radial-gradient(800px 460px at 100% 105%, #e3f5ee 0%, transparent 55%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  padding: 34px 28px 26px; box-shadow: var(--shadow-lg);
  animation: rise .35s cubic-bezier(.2, .8, .3, 1);
}
@keyframes rise { from { opacity: 0; transform: translateY(14px); } }

.login-brand { text-align: center; margin-bottom: 26px; }
.brand-mark {
  width: 52px; height: 52px; margin: 0 auto 14px; border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), #6b8bff);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(51, 85, 255, .3);
}
.brand-mark.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 17px; margin: 0; box-shadow: none; }
.login-brand h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; letter-spacing: .5px; }
.login-brand p { margin: 0; color: var(--text-3); font-size: 13.5px; }
.login-tip { text-align: center; color: var(--text-3); font-size: 12.5px; margin: 18px 0 0; }

/* ============ 顶栏 ============ */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: rgba(255, 255, 255, .88);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 680px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 11px; min-width: 0; }
.topbar-title { min-width: 0; }
.topbar-title strong {
  display: block; font-size: 15.5px; font-weight: 650; line-height: 1.25;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-title small { display: block; font-size: 12px; color: var(--text-3); }
.topbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }

.avatar-btn {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  transition: filter .15s;
}
.avatar-btn:hover { filter: brightness(.95); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); width: 186px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); overflow: hidden;
  animation: rise .16s ease;
}
.menu-head { padding: 12px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.menu-head strong { display: block; font-size: 14px; }
.menu-head small { color: var(--text-3); font-size: 12px; }
.menu-item {
  display: block; width: 100%; text-align: left;
  padding: 11px 14px; font-size: 14px; transition: background .13s;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item.danger { color: var(--danger); border-top: 1px solid var(--border); }
.menu-item.danger:hover { background: var(--danger-soft); }

/* ============ 主体 ============ */
.container {
  max-width: 680px; margin: 0 auto;
  padding: 18px 16px calc(40px + var(--safe-b));
}


.banner {
  background: #fff8e6; border: 1px solid #ffe6a8; color: #8a6206;
  border-radius: var(--radius-sm); padding: 10px 13px;
  font-size: 13.5px; margin-bottom: 14px;
}
.banner .link-btn { color: #8a6206; text-decoration: underline; }

.add-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow-sm);
  margin-bottom: 22px; transition: box-shadow .2s, border-color .2s;
}
.add-card:focus-within { border-color: #c3ccf5; box-shadow: var(--shadow); }
#add-input {
  width: 100%; border: none; outline: none; background: transparent;
  font-size: 16px; padding: 4px 2px 10px;
}
#add-input::placeholder { color: var(--text-3); }
.add-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.urgent-toggle { cursor: pointer; user-select: none; }
.urgent-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.urgent-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  background: #f1f3f7; color: var(--text-2);
  border: 1px solid transparent; transition: all .16s;
}
.urgent-toggle input:checked + .urgent-chip {
  background: var(--danger-soft); color: var(--danger); border-color: #ffc9cf;
}

.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 2px 11px;
}
.section-head h2 {
  margin: 0; font-size: 15px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; gap: 9px; letter-spacing: .3px;
}
.section-head h2::before {
  content: ''; width: 4px; height: 16px; border-radius: 3px;
  background: var(--primary); display: inline-block; flex-shrink: 0;
}
.done-head { margin-top: 26px; }
.count {
  display: inline-block; min-width: 20px; padding: 1px 7px; margin-left: 4px;
  background: #e9ecf2; color: var(--text-2); border-radius: 999px;
  font-size: 11.5px; font-weight: 700; letter-spacing: 0; text-align: center;
}
.toggle-done {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 700; color: var(--text-3);
  letter-spacing: 1.1px; text-transform: uppercase;
  padding: 4px 8px 4px 4px; border-radius: 8px; transition: color .15s;
}
.toggle-done:hover { color: var(--text-2); }
.chev { display: inline-block; transition: transform .2s; font-size: 11px; }
.toggle-done[aria-expanded="true"] .chev { transform: rotate(90deg); }

/* ============ 待办列表 ============ */
.todo-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 9px; }
.done-list { gap: 7px; animation: fade .2s ease; }

.todo {
  display: flex; align-items: flex-start; gap: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s, border-color .18s, opacity .18s, transform .18s;
  animation: pop .22s cubic-bezier(.2, .8, .3, 1);
}
@keyframes pop { from { opacity: 0; transform: translateY(-5px); } }
.todo:hover { box-shadow: var(--shadow); }

.todo.urgent {
  border-color: #ffc9cf;
  background: linear-gradient(90deg, #fff6f7 0%, var(--surface) 42%);
  box-shadow: 0 1px 2px rgba(224, 56, 74, .09);
}
.todo.urgent .todo-title { color: var(--danger); font-weight: 620; }

.todo.done { opacity: .62; background: var(--surface-2); }
.todo.done .todo-title { text-decoration: line-through; color: var(--text-3); font-weight: 400; }
.todo.removing { opacity: 0; transform: translateX(14px); }

.check {
  flex-shrink: 0; width: 22px; height: 22px; margin-top: 1px;
  border: 2px solid var(--border-strong); border-radius: 50%;
  background: var(--surface); position: relative;
  transition: all .16s;
}
.check:hover { border-color: var(--primary); background: var(--primary-soft); }
.todo.urgent .check { border-color: #f4a3ad; }
.todo.urgent .check:hover { border-color: var(--danger); background: var(--danger-soft); }
.todo.done .check { background: var(--success); border-color: var(--success); }
.check::after {
  content: ''; position: absolute; left: 6px; top: 2px;
  width: 5px; height: 10px; border: solid #fff;
  border-width: 0 2px 2px 0; transform: rotate(45deg) scale(0);
  transition: transform .16s;
}
.todo.done .check::after { transform: rotate(45deg) scale(1); }

.todo-main { flex: 1; min-width: 0; }
.todo-title {
  font-size: 15px; line-height: 1.45; word-break: break-word;
  white-space: pre-wrap; cursor: text;
}
.todo-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.tag-urgent {
  display: inline-flex; align-items: center; gap: 3px;
  background: var(--danger); color: #fff; border-radius: 5px;
  font-size: 10.5px; font-weight: 700; padding: 2px 6px; letter-spacing: .5px;
}
.todo-time { font-size: 11.5px; color: var(--text-3); }

.todo-actions { display: flex; gap: 2px; flex-shrink: 0; align-items: center; }
.act {
  width: 32px; height: 32px; border-radius: 8px; font-size: 14px;
  display: flex; align-items: center; justify-content: center;
  opacity: .42; transition: all .15s;
}
.act:hover { opacity: 1; background: #eef0f4; }
.act.on { opacity: 1; }
.act.del:hover { background: var(--danger-soft); }

.empty { text-align: center; padding: 34px 20px; color: var(--text-3); }
.empty-icon { font-size: 34px; margin-bottom: 8px; }
.empty p { margin: 0; font-size: 14px; }

/* ============ 弹层 ============ */
.modal-mask {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 24, 40, .42);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  width: 100%; max-width: 400px; background: var(--surface);
  border-radius: 18px; box-shadow: var(--shadow-lg);
  max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column;
  animation: rise .22s cubic-bezier(.2, .8, .3, 1);
}
.modal-lg { max-width: 560px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px 14px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 16.5px; font-weight: 650; }
.modal-body { padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.create-user {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; margin-bottom: 18px;
}
.cu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 11px; }
.cu-grid input, .cu-grid select {
  padding: 10px 12px; border: 1px solid var(--border-strong);
  border-radius: 9px; background: var(--surface); outline: none;
  width: 100%; font-size: 15px;
}
.cu-grid input:focus, .cu-grid select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(51, 85, 255, .13);
}

.user-list { display: flex; flex-direction: column; gap: 9px; }
.user-row {
  display: flex; align-items: center; gap: 11px;
  border: 1px solid var(--border); border-radius: var(--radius); padding: 11px 13px;
}
.user-row.inactive { opacity: .55; background: var(--surface-2); }
.u-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  background: var(--primary-soft); color: var(--primary);
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 14px;
}
.u-avatar.admin { background: #fff0e4; color: #d97416; }
.u-info { flex: 1; min-width: 0; }
.u-name { font-size: 14.5px; font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.u-sub { font-size: 12px; color: var(--text-3); }
.badge {
  font-size: 10.5px; font-weight: 700; padding: 1.5px 6px; border-radius: 5px;
  background: #fff0e4; color: #d97416; letter-spacing: .3px;
}
.badge.me { background: var(--primary-soft); color: var(--primary); }
.badge.off { background: #f0f1f4; color: var(--text-3); }
.u-actions { display: flex; gap: 2px; flex-shrink: 0; }

/* ============ Toast ============ */
.toast {
  position: fixed; left: 50%; bottom: calc(28px + var(--safe-b));
  transform: translateX(-50%);
  background: #1b1f27; color: #fff; padding: 11px 20px;
  border-radius: 999px; font-size: 14px; z-index: 200;
  box-shadow: var(--shadow-lg); animation: toastIn .22s cubic-bezier(.2, .8, .3, 1);
  max-width: calc(100vw - 40px); text-align: center;
}
.toast.err { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } }

/* ============ 移动端适配 ============ */
@media (max-width: 560px) {
  .container { padding: 14px 12px calc(36px + var(--safe-b)); }
  .cu-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; border-radius: 16px; }
  .modal-body { padding: 16px; }
  .todo { padding: 12px 12px; gap: 11px; }
  .act { width: 34px; height: 34px; opacity: .55; }
  .topbar-inner { padding: 9px 12px; }
  .login-card { padding: 30px 22px 22px; }
}

@media (hover: none) {
  .act { opacity: .6; }
}
