*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #ffffff;
  --side: #f6f6f8;
  --fg: #1d1d1f;
  --fg-2: #86868b;
  --fg-3: #b4b4b9;
  --line: #ececef;
  --hover: #f4f4f6;
  --nav-on: #e6e6eb;
  --chip: #f2f2f5;
  --cb: #c7c7cc;
  --accent: #2f6fed;
  --c-today: #f2a900;
  --c-upcoming: #e5484d;
  --c-nodate: #2f6fed;
  --accent-fg: #ffffff;
  --red: #e5484d;
  --banner: #fdf3d8;
  --banner-btn: #f5b301;
  --banner-fg: #3d2c00;
  --card: #ffffff;
  --shadow: 0 0 0 1px var(--line), 0 8px 24px rgba(0, 0, 0, .08);
  --sheet-dim: rgba(0, 0, 0, .28);
  --tabbar: rgba(246, 246, 248, .92);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1c1e;
    --side: #161618;
    --fg: #f2f2f4;
    --fg-2: #98989f;
    --fg-3: #5d5d63;
    --line: #2c2c2f;
    --hover: #26262a;
    --nav-on: #2c2c30;
    --chip: #2a2a2e;
    --cb: #5d5d63;
    --accent: #4b83f0;
    --red: #ff6369;
    --banner: #3a3016;
    --banner-btn: #f5b301;
    --banner-fg: #2a1f00;
    --card: #232326;
    --shadow: 0 0 0 1px var(--line), 0 10px 30px rgba(0, 0, 0, .45);
    --sheet-dim: rgba(0, 0, 0, .55);
    --tabbar: rgba(32, 32, 35, .92);
    color-scheme: dark;
  }
}

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--fg);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }

/* ─── Layout ─── */
.app { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }

.side {
  background: var(--side);
  border-right: 1px solid var(--line);
  padding: 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.nav {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px;
  font-size: 14px; text-align: left; width: 100%;
}
.nav:hover { background: var(--hover); }
.nav.on { background: var(--nav-on); font-weight: 600; }
.nav .ico { width: 18px; display: inline-flex; justify-content: center; color: var(--fg-2); }
.nav .ico svg { width: 17px; height: 17px; }
.nav .ct { margin-left: auto; font-size: 12px; color: var(--fg-2); font-weight: 400; font-variant-numeric: tabular-nums; }
.nav .ct.late { color: var(--red); font-weight: 600; }
.side-gap { height: 18px; }
.side-label { font-size: 11px; font-weight: 600; color: var(--fg-2); padding: 4px 10px; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 2px; }
.side-foot .nav { font-size: 13px; color: var(--fg-2); }

.main { padding: 40px 56px 120px; max-width: 820px; width: 100%; }

.head { display: flex; align-items: flex-start; gap: 12px; }
.title { font-size: 28px; font-weight: 700; letter-spacing: -.02em; display: flex; align-items: center; gap: 10px; }
.subtitle { font-size: 13px; color: var(--fg-2); margin-top: 2px; }
.head-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }
.icon-btn {
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--fg-2); font-size: 16px;
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn.spin span { display: inline-block; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.scope { display: none; }

/* ─── Banners ─── */
.banner {
  display: flex; align-items: center; gap: 10px;
  background: var(--banner); border-radius: 10px;
  padding: 9px 10px 9px 14px; font-size: 13px; margin-top: 18px;
}
.banner .btn-banner {
  margin-left: auto; background: var(--banner-btn); color: var(--banner-fg);
  border-radius: 7px; padding: 5px 11px; font-weight: 600; font-size: 12px; white-space: nowrap;
}
.banner.err { background: rgba(229, 72, 77, .12); color: var(--red); }
.banner.info { background: var(--chip); }
.banner code { font-weight: 700; letter-spacing: .12em; font-size: 14px; }

/* ─── Sections & tasks ─── */
.list { margin-top: 22px; }
.sec {
  display: flex; align-items: center; gap: 8px;
  font-size: 15px; font-weight: 700;
  margin: 26px 0 4px; padding-bottom: 7px;
  border-bottom: 1px solid var(--line);
}
.sec:first-child { margin-top: 0; }
.sec small { font-weight: 500; color: var(--fg-2); font-size: 13px; }

.task {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 7px 10px; margin: 0 -10px; border-radius: 8px;
  cursor: pointer; transition: opacity .35s, transform .35s;
}
.task:hover { background: var(--hover); }
.task.done { opacity: .35; }
.task.leaving { opacity: 0; transform: translateX(8px); }

.cb {
  width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px;
  border: 1.5px solid var(--cb); border-radius: 5px;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
}
.cb:hover { border-color: var(--accent); }
.cb.checked { background: var(--accent); border-color: var(--accent); }
.cb.checked::after { content: ""; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: translateY(-1px) rotate(45deg); }
.cb.locked { border-style: dashed; cursor: default; }
.cb.locked:hover { border-color: var(--cb); }

.body { flex: 1; min-width: 0; }
.t { font-size: 14px; line-height: 1.35; overflow-wrap: anywhere; }
.sub { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--fg-2); margin-top: 2px; min-width: 0; }
.sub span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 13px; height: 13px; }
.src-n { border: 1.2px solid currentColor; border-radius: 3px; font-size: 8.5px; font-weight: 700; line-height: 1; }
.src-o svg { width: 13px; height: 13px; }
.when { font-size: 12px; color: var(--fg-2); white-space: nowrap; padding-left: 10px; margin-top: 2px; font-variant-numeric: tabular-nums; }
.when.late { color: var(--red); font-weight: 500; }

/* Inline editor (desktop) */
.task.open {
  background: var(--card); box-shadow: var(--shadow); cursor: default;
  padding: 12px 14px; margin: 8px -14px; border-radius: 12px;
}
.task.open:hover { background: var(--card); }
.edit-title {
  width: 100%; border: 0; outline: 0; background: transparent;
  font-size: 14px; font-weight: 600; padding: 0; line-height: 1.35;
}
.edit-title[readonly] { cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; border-radius: 7px; padding: 5px 10px;
  background: var(--chip); white-space: nowrap; position: relative;
}
.chip:hover { filter: brightness(.96); }
.chip.on { background: var(--accent); color: var(--accent-fg); }
.chip input[type="date"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.open-link { display: inline-flex; align-items: center; gap: 3px; margin-left: auto; font-size: 12px; color: var(--accent); text-decoration: none; padding: 5px 2px; white-space: nowrap; }
.open-link:hover { text-decoration: underline; }
.hint { font-size: 12px; color: var(--fg-2); margin-top: 10px; }

.empty { text-align: center; color: var(--fg-2); padding: 70px 20px; }
.empty .big { font-size: 34px; margin-bottom: 8px; }
.empty b { display: block; color: var(--fg); font-size: 15px; margin-bottom: 2px; }

.skel { height: 34px; border-radius: 8px; margin: 6px 0; background: linear-gradient(90deg, var(--hover) 25%, var(--line) 50%, var(--hover) 75%); background-size: 200% 100%; animation: shimmer 1.4s infinite; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ─── Toast ─── */
.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 12px);
  background: #1d1d1f; color: #fff; border-radius: 12px; padding: 10px 12px 10px 16px;
  font-size: 13px; display: flex; gap: 14px; align-items: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button { color: #8fb4ff; font-weight: 600; font-size: 13px; padding: 2px 4px; }
@media (prefers-color-scheme: dark) { .toast { background: #3a3a3e; } }

/* ─── Bottom sheet (mobile editor + menu) ─── */
.dim { position: fixed; inset: 0; background: var(--sheet-dim); z-index: 40; opacity: 0; transition: opacity .2s; }
.dim.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41;
  background: var(--card); border-radius: 18px 18px 0 0;
  padding: 10px 20px calc(18px + env(safe-area-inset-bottom));
  transform: translateY(100%); transition: transform .25s cubic-bezier(.2, .8, .2, 1);
  max-height: 85vh; overflow-y: auto;
}
.sheet.show { transform: translateY(0); }
.grab { width: 36px; height: 5px; border-radius: 3px; background: var(--cb); margin: 0 auto 14px; }
.sheet .edit-title { font-size: 17px; }
.sheet .sub { margin: 4px 0 10px; }
.opt {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 15px; text-align: left;
  position: relative; text-decoration: none;
}
.opt:last-child { border-bottom: 0; }
.opt .r { margin-left: auto; color: var(--fg-2); font-size: 13px; }
.opt.on .r::after { content: " ✓"; color: var(--accent); }
.opt.link { color: var(--accent); }
.opt.danger { color: var(--red); }
.opt input[type="date"] { position: absolute; inset: 0; opacity: 0; width: 100%; }

/* ─── Tab bar (mobile) ─── */
.tabbar { display: none; }

/* ─── Mobile ─── */
@media (max-width: 760px) {
  .app { display: block; }
  .side { display: none; }
  .main { padding: calc(14px + env(safe-area-inset-top)) 20px calc(110px + env(safe-area-inset-bottom)); }
  .title { font-size: 30px; }
  .head-actions .desk-only { display: none; }

  .scope {
    display: flex; gap: 2px; background: var(--chip); border-radius: 9px; padding: 2px; margin-top: 14px;
  }
  .scope button { flex: 1; font-size: 13px; padding: 6px 0; border-radius: 7px; color: var(--fg-2); }
  .scope button.on { background: var(--bg); color: var(--fg); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .1); }

  .task { padding: 9px 4px; margin: 0 -4px; }
  .task:hover { background: none; }
  .t { font-size: 15px; }
  .cb { width: 20px; height: 20px; }

  .tabbar {
    display: flex; position: fixed; z-index: 30;
    left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom));
    height: 58px; border-radius: 29px; background: var(--tabbar);
    -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
    box-shadow: 0 2px 16px rgba(0, 0, 0, .12);
    justify-content: space-around; align-items: center;
  }
  .tabbar button { display: flex; flex-direction: column; align-items: center; gap: 1px; font-size: 10px; color: var(--fg-2); min-width: 64px; padding: 6px 0; }
  .tabbar button .ico svg { width: 22px; height: 22px; margin-bottom: 2px; }
  .tabbar button.on { color: var(--fg); font-weight: 600; }
  .tabbar button.on .ico-today { color: var(--c-today); }
  .tabbar button.on .ico-upcoming { color: var(--c-upcoming); }
  .tabbar button.on .ico-nodate { color: var(--c-nodate); }
  .tabbar .badge { color: var(--red); }

  .toast { bottom: calc(84px + env(safe-area-inset-bottom)); }
}

/* ─── Login ─── */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 340px; text-align: center; }
.login-card img { width: 72px; height: 72px; border-radius: 17px; box-shadow: 0 4px 18px rgba(0, 0, 0, .12); }
.login-card h1 { font-size: 24px; margin: 16px 0 4px; letter-spacing: -.01em; }
.login-card p { color: var(--fg-2); font-size: 14px; }
.btn-primary {
  display: block; width: 100%; margin-top: 26px; padding: 13px; border-radius: 12px;
  background: var(--fg); color: var(--bg); font-weight: 600; font-size: 15px;
}
.btn-primary:disabled { opacity: .5; }
.btn-text { margin-top: 14px; font-size: 13px; color: var(--fg-2); text-decoration: underline; }
.field {
  display: block; width: 100%; margin-top: 22px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--side); font-size: 16px;
}
.msg { margin-top: 14px; font-size: 13px; min-height: 18px; color: var(--fg-2); }
.msg.err { color: var(--red); }

.mobile-menu { display: none; }
@media (max-width: 760px) { .mobile-menu { display: inline-flex; } }

/* ─── Lucide icons ─── */
.lucide { display: block; width: 1em; height: 1em; flex-shrink: 0; }
.nav .ico-today, .title-ico.ico-today { color: var(--c-today); }
.nav .ico-upcoming, .title-ico.ico-upcoming { color: var(--c-upcoming); }
.nav .ico-nodate, .title-ico.ico-nodate { color: var(--c-nodate); }
.title-ico svg { width: 26px; height: 26px; }
.icon-btn svg { width: 17px; height: 17px; }
.sec-ico { width: 16px; height: 16px; color: var(--fg-2); }
.banner-ico svg { width: 16px; height: 16px; color: #c08a00; }
.empty .big { display: flex; justify-content: center; color: var(--fg-3); }
.empty .big svg { width: 40px; height: 40px; stroke-width: 1.5; }
.chip-ico { width: 13px; height: 13px; }
.link-ico { width: 13px; height: 13px; }
.opt > .lucide { width: 19px; height: 19px; color: var(--fg-2); }
.opt.link > .lucide { color: var(--accent); }
.opt.danger > .lucide { color: var(--red); }
.src-o .lucide { width: 13px; height: 13px; }
@media (max-width: 760px) { .title-ico svg { width: 28px; height: 28px; } }
