:root {
  --primary: #6c5ce7;
  --primary-light: #a29bfe;
  --primary-bg: #f4f2ff;
  --accent: #00cec9;
  --accent2: #ffa940;
  --bg: #f5f6fa;
  --surface: #ffffff;
  --ink: #1a1a2e;
  --ink-2: #4a4a6a;
  --muted: #9a9ab0;
  --line: #eeeef2;
  --danger: #e74c3c;
  --radius: 14px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.08);
  --shadow-primary: 0 4px 16px rgba(108,92,231,0.20);
  --font: -apple-system, "SF Pro Text", "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  font-family: var(--font); color: var(--ink); background: var(--bg);
  display: flex; justify-content: center; align-items: center; min-height: 100vh;
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.5;
}
.hidden { display: none !important; }
::-webkit-scrollbar { display: none; }
* { scrollbar-width: none; }

/* ---------- Buttons ---------- */
.btn { border: none; cursor: pointer; font-family: inherit; font-weight: 600; border-radius: 10px; transition: all .15s ease; background: none; }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--primary); color: #fff; padding: 0 16px; font-size: 13px; }
.btn.big { width: 100%; padding: 13px; font-size: 15px; border-radius: 12px; }
.btn.ghost { background: var(--surface); border: 1px solid var(--line); color: var(--primary); font-size: 12px; padding: 7px 12px; display: inline-flex; align-items: center; gap: 4px; box-shadow: var(--shadow-sm); }
.btn.ghost svg { width: 14px; height: 14px; }
.btn.submit { width: 100%; padding: 13px; font-size: 15px; margin-top: 4px; background: var(--primary); color: #fff; border-radius: 12px; }
.btn.full { width: 100%; padding: 11px; margin-top: 8px; color: var(--muted); }
.btn:disabled { opacity: 0.55; }

/* ---------- Auth ---------- */
.auth-screen {
  position: fixed; inset: 0; z-index: 90; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 20px; overflow: auto;
}
.auth-box { width: 100%; max-width: 380px; }
.auth-logo { display: flex; justify-content: center; }
.logo-mark {
  width: 60px; height: 60px; border-radius: 18px;
  background: var(--primary); color: #fff; font-size: 28px; font-weight: 800;
  display: grid; place-items: center; box-shadow: var(--shadow-primary);
}
.auth-title { text-align: center; font-size: 21px; font-weight: 800; margin-top: 14px; color: var(--ink); }
.auth-sub { text-align: center; font-size: 13px; color: var(--muted); margin: 6px 0 24px; line-height: 1.5; }
.auth-tabs { display: flex; background: #ecebf2; border-radius: 11px; padding: 3px; margin-bottom: 18px; }
.auth-tab { flex: 1; border: none; background: none; padding: 9px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; transition: all .15s ease; }
.auth-tab.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }
.auth-form .field { margin-bottom: 12px; }
.auth-form .field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; font-weight: 600; }
.auth-form .field input { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--ink); outline: none; transition: border-color .15s ease; }
.auth-form .field input:focus { border-color: var(--primary); }
.auth-tip { text-align: center; font-size: 12px; color: var(--danger); margin-top: 10px; min-height: 18px; }

/* ---------- App Shell ---------- */
.app {
  width: 100%; max-width: 460px; height: 100vh; height: 100dvh;
  background: var(--bg); display: flex; flex-direction: column; overflow: hidden; position: relative;
  box-shadow: 0 0 0 1px var(--line), 0 20px 60px rgba(0,0,0,0.10);
}
@media (min-width: 500px) { .app { height: min(94vh, 920px); border-radius: 22px; } }

.appbar {
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 12px 10px; display: flex; align-items: center; gap: 8px;
  position: relative; z-index: 5;
}
.appbar .back, .appbar .more { width: 34px; height: 34px; flex-shrink: 0; border: none; background: none; border-radius: 9px; display: grid; place-items: center; color: var(--muted); cursor: pointer; }
.appbar .back:active, .appbar .more:active { background: var(--primary-bg); }
.appbar .title { flex: 1; text-align: center; line-height: 1.2; }
.appbar .title .name { font-size: 15px; font-weight: 700; color: var(--ink); }
.appbar .title .sub { font-size: 11px; color: var(--muted); margin-top: 1px; }
.appbar svg { width: 20px; height: 20px; }

/* ---------- AI Card (only gradient element) ---------- */
.ai-card {
  background: linear-gradient(135deg, #6c5ce7 0%, #8e7ff5 100%);
  margin: 10px 12px 0; border-radius: 16px; padding: 12px 14px; border: none;
  box-shadow: var(--shadow-primary); color: #fff;
}
.ai-row { display: flex; gap: 8px; }
.ai-input { flex: 1; display: flex; align-items: center; background: #fff; border-radius: 11px; }
.ai-input input { flex: 1; border: none; background: none; outline: none; padding: 11px 8px 11px 14px; font-size: 14px; font-family: inherit; color: var(--ink); }
.ai-input input::placeholder { color: #b8b8c8; }
.ai-mic { color: #b8b8c8; padding: 0 8px; width: 32px; display: grid; place-items: center; position: relative; }
.ai-mic svg { width: 18px; height: 18px; }
.ai-mic .dot { position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: #2dd4bf; border: 1.5px solid #fff; }
.ai-row .btn.primary { background: rgba(255,255,255,0.22); color: #fff; padding: 0 18px; font-size: 14px; box-shadow: none; backdrop-filter: blur(4px); }
.ai-row .btn.primary:active { background: rgba(255,255,255,0.35); }
.chips { display: flex; gap: 6px; overflow-x: auto; margin-top: 8px; align-items: center; transition: all .25s ease; }
.chips-label { font-size: 10px; color: rgba(255,255,255,0.70); flex: none; margin-right: 2px; }
.chip { flex: none; border: 1px solid rgba(255,255,255,0.20); background: rgba(255,255,255,0.10); color: rgba(255,255,255,0.95); font-size: 11px; padding: 5px 10px; border-radius: 999px; cursor: pointer; white-space: nowrap; font-family: inherit; }
.chip:active { background: rgba(255,255,255,0.25); }
.chip.collapse-btn { margin-left: auto; background: rgba(255,255,255,0.06); border: none; font-size: 10px; color: rgba(255,255,255,0.60); padding: 5px 8px; }
.chips.collapsed { max-height: 0; margin-top: 0; overflow: hidden; opacity: 0; }
.chips.collapsible { max-height: 40px; overflow: hidden; transition: max-height .25s ease, opacity .2s ease, margin .2s ease; }

/* ---------- Week Tabs ---------- */
.week-tabs { display: flex; gap: 8px; overflow-x: auto; padding: 12px 12px 4px; }
.wt { flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; padding: 7px 14px; border-radius: 999px; cursor: pointer; font-family: inherit; display: flex; align-items: center; gap: 5px; box-shadow: var(--shadow-sm); }
.wt b { font-weight: 700; color: var(--ink-2); }
.wt.active { background: var(--primary); color: #fff; border-color: transparent; box-shadow: var(--shadow-primary); }
.wt.active b { color: #fff; }

/* ---------- Views ---------- */
.view { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.view-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 8px; }
.view-head .t { font-size: 14px; font-weight: 700; color: var(--ink); }
.view-head .light { font-size: 11px; color: var(--muted); font-weight: 400; margin-left: 4px; }

/* ---------- Schedule Grid ---------- */
.sched-scroll { flex: 1; overflow: auto; padding: 0 12px 12px; }
.sched { min-width: 720px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
.srow { display: grid; grid-template-columns: 66px repeat(7, 1fr); }
.srow + .srow { border-top: 1px solid #f5f5fa; }
.scell { padding: 8px 6px; min-height: 88px; position: relative; }
.scell + .scell { border-left: 1px solid #f5f5fa; }
.scell.member, .scell.hd { position: sticky; left: 0; z-index: 3; background: var(--surface); }
.srow.head .scell { min-height: 42px; padding: 8px 6px; font-size: 11px; color: var(--muted); text-align: center; position: sticky; top: 0; background: #fbfbfe; z-index: 2; }
.srow.head .scell:first-child { z-index: 5; }
.srow.head .scell .d { font-size: 14px; font-weight: 700; color: var(--ink); }
.srow.head .scell.today { background: var(--primary-bg); }
.srow.head .scell.today .d { color: var(--primary); }
.scell.member { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; padding-top: 12px; gap: 4px; }
.ava { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 12px; font-weight: 700; flex-shrink: 0; }
.scell.member .nm { font-size: 11px; font-weight: 700; color: var(--ink); }
.scell.member .rl { font-size: 9px; color: var(--muted); transform: scale(0.92); }

.task { border-radius: 8px; padding: 6px 7px; font-size: 11px; margin-bottom: 5px; position: relative; cursor: pointer; box-shadow: var(--shadow-sm); }
.task .tm { font-weight: 700; font-size: 10px; margin-bottom: 2px; }
.task .tt { color: var(--ink); font-weight: 500; line-height: 1.3; word-break: break-word; }
.task .lc { color: var(--muted); font-size: 9px; margin-top: 2px; display: flex; align-items: center; gap: 3px; }
.task .del { position: absolute; top: 3px; right: 3px; width: 14px; height: 14px; border: none; border-radius: 50%; background: var(--surface); color: var(--muted); font-size: 9px; line-height: 1; display: none; align-items: center; justify-content: center; cursor: pointer; box-shadow: var(--shadow-sm); }
.task:active .del, .task:hover .del { display: flex; }
.task .ai-tag { display: inline-block; font-size: 8px; color: #fff; background: var(--accent); border-radius: 3px; padding: 0 3px; margin-left: 3px; vertical-align: 1px; }
.add-slot { border: 1.5px dashed #e8e8f0; border-radius: 8px; height: 32px; margin-top: auto; display: grid; place-items: center; color: #c8c8d8; cursor: pointer; font-size: 15px; transition: all .12s ease; }
.add-slot:active { color: var(--primary); border-color: var(--primary); background: var(--primary-bg); }

/* ---------- Empty State ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 50px 20px; text-align: center; }
.empty-state .icon { width: 56px; height: 56px; border-radius: 16px; background: var(--primary-bg); display: grid; place-items: center; margin-bottom: 14px; }
.empty-state .icon svg { width: 28px; height: 28px; color: var(--primary-light); }
.empty-state .text { font-size: 14px; color: var(--ink-2); font-weight: 600; margin-bottom: 4px; }
.empty-state .hint { font-size: 12px; color: var(--muted); line-height: 1.5; max-width: 260px; }
.empty-state .try-btn { margin-top: 16px; background: var(--primary-bg); color: var(--primary); border: none; padding: 9px 18px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; display: flex; align-items: center; gap: 5px; }
.empty-state .try-btn:active { transform: scale(0.96); }
.empty-state .try-btn svg { width: 14px; height: 14px; }

/* Schedule empty state (no schedules) */
.sched-empty { background: var(--surface); border-radius: 14px; padding: 36px 24px; text-align: center; box-shadow: var(--shadow-sm); }
.sched-empty .se-icon { width: 48px; height: 48px; border-radius: 14px; background: var(--primary-bg); display: grid; place-items: center; margin: 0 auto 14px; }
.sched-empty .se-icon svg { width: 24px; height: 24px; color: var(--primary-light); }
.sched-empty .se-text { font-size: 14px; font-weight: 600; color: var(--ink-2); margin-bottom: 6px; }
.sched-empty .se-hint { font-size: 12px; color: var(--muted); line-height: 1.6; max-width: 240px; margin: 0 auto; }
.sched-empty .se-btns { margin-top: 18px; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.sched-empty .se-btn { border: none; padding: 10px 20px; border-radius: 999px; font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit; display: inline-flex; align-items: center; gap: 5px; }
.sched-empty .se-btn.primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-primary); }
.sched-empty .se-btn.ghost { background: var(--primary-bg); color: var(--primary); }
.sched-empty .se-btn:active { transform: scale(0.96); }
.sched-empty .se-btn svg { width: 15px; height: 15px; }

/* ---------- Todo ---------- */
.todo-list { flex: 1; overflow: auto; padding: 6px 14px 14px; }
.todo-group { font-size: 11px; color: var(--muted); font-weight: 700; margin: 12px 2px 6px; }
.todo { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 11px 12px; display: flex; align-items: center; gap: 10px; margin-bottom: 8px; box-shadow: var(--shadow-sm); }
.todo .chk { width: 22px; height: 22px; border-radius: 50%; border: 2px solid #d4d4e0; flex-shrink: 0; cursor: pointer; display: grid; place-items: center; color: transparent; transition: all .12s ease; }
.todo.done .chk { background: var(--primary); border-color: transparent; color: #fff; }
.todo .body { flex: 1; min-width: 0; }
.todo .tt { font-size: 14px; font-weight: 500; color: var(--ink); }
.todo.done .tt { color: var(--muted); text-decoration: line-through; }
.todo .meta { font-size: 11px; color: var(--muted); margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.pri { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.pri.high { background: #e74c3c; }
.pri.mid { background: #ffa940; }
.pri.low { background: #2ed573; }
.todo .owner { font-size: 11px; color: var(--muted); text-align: right; flex-shrink: 0; }

/* ---------- Mine ---------- */
.mine { flex: 1; overflow: auto; padding: 14px; }
.ws-card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 18px; margin-bottom: 14px; box-shadow: var(--shadow-md); }
.ws-card .wsn { font-size: 17px; font-weight: 800; color: var(--ink); }
.ws-card .wsm { font-size: 12px; color: var(--muted); margin-top: 3px; }
.invite-row { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.invite-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.invite-code { font-size: 18px; font-weight: 800; letter-spacing: 2px; color: var(--primary); background: var(--primary-bg); padding: 4px 12px; border-radius: 8px; font-family: 'SF Mono', 'Menlo', monospace; }
.invite-btn { background: var(--primary); color: #fff; border: none; font-size: 12px; padding: 7px 14px; border-radius: 8px; box-shadow: var(--shadow-primary); }
.sec-title { font-size: 12px; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.member-list { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-sm); }
.member-row { display: flex; align-items: center; gap: 10px; padding: 11px 12px; }
.member-row + .member-row { border-top: 1px solid #f5f5fa; }
.member-row.clickable { cursor: pointer; }
.member-row.clickable:active { background: var(--primary-bg); }
.member-row .nm { font-size: 13px; font-weight: 600; color: var(--ink); }
.member-row .rl { font-size: 11px; color: var(--muted); }
.member-row .role-tag { margin-left: auto; font-size: 10px; color: var(--primary); background: var(--primary-bg); padding: 2px 8px; border-radius: 999px; font-weight: 600; }
.member-row .role-tag:empty { display: none; }
.invite-status { margin-top: 10px; }
.invite-tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 10px; border-radius: 999px; }
.invite-tag.on { color: #0d9f6e; background: #e6f7ef; }
.invite-tag.off { color: #c0392b; background: #fdecea; }
.invite-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.invite-actions .btn.invite-btn { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); box-shadow: none; font-weight: 600; }
.invite-actions .btn.invite-btn.danger { border-color: var(--danger); color: var(--danger); }
.member-ops { margin-left: auto; display: flex; gap: 6px; }
.mini { border: none; background: var(--primary-bg); color: var(--primary); font-size: 11px; font-weight: 600; padding: 4px 10px; border-radius: 8px; cursor: pointer; font-family: inherit; }
.mini.danger { background: #fdecea; color: var(--danger); }
.mi { flex: 1; min-width: 0; }
.mph { font-size: 11px; color: var(--muted); margin-top: 1px; }
.note-real { font-size: 11px; color: var(--muted); font-weight: 400; }
.curtag { font-size: 10px; color: var(--primary); background: var(--primary-bg); padding: 1px 7px; border-radius: 999px; margin-left: 4px; }
.logout-btn { background: #fdecea; color: var(--danger); border: none; font-size: 11px; font-weight: 600; padding: 6px 12px; border-radius: 8px; }
.about { font-size: 11px; color: #c0c0d0; margin-top: 16px; text-align: center; line-height: 1.6; }

/* ---------- Tabbar ---------- */
.tabbar { background: var(--surface); border-top: 1px solid var(--line); display: flex; padding: 6px 0 calc(env(safe-area-inset-bottom, 0px) + 6px); }
.tab { flex: 1; border: none; background: none; cursor: pointer; font-family: inherit; display: flex; flex-direction: column; align-items: center; gap: 3px; color: var(--muted); font-size: 10px; padding: 4px 0; position: relative; }
.tab svg { width: 20px; height: 20px; }
.tab.active { color: var(--primary); }
.tab.active svg { stroke: var(--primary); }
.tab.active::before { content: ""; position: absolute; top: -6px; width: 20px; height: 3px; border-radius: 0 0 4px 4px; background: var(--primary); }

/* ---------- Overlay / Sheet ---------- */
.overlay { position: fixed; inset: 0; background: rgba(20,20,40,0.40); z-index: 50; display: flex; align-items: flex-end; justify-content: center; opacity: 0; pointer-events: none; transition: opacity .25s ease; }
.overlay.show { opacity: 1; pointer-events: auto; }
.sheet { background: var(--surface); width: 100%; max-width: 460px; border-radius: 20px 20px 0 0; padding: 18px 18px calc(env(safe-area-inset-bottom, 0px) + 18px); transform: translateY(100%); transition: transform .28s cubic-bezier(.4,0,.2,1); max-height: 88vh; overflow-y: auto; }
.overlay.show .sheet { transform: translateY(0); }
.sheet .handle { width: 40px; height: 4px; background: #e8e8f0; border-radius: 2px; margin: 0 auto 14px; }
.sheet h3 { font-size: 16px; font-weight: 800; margin-bottom: 14px; display: flex; align-items: center; gap: 8px; color: var(--ink); }

/* AI parsed result header */
.ai-result-header { background: var(--primary-bg); border-radius: 12px; padding: 12px 14px; margin-bottom: 14px; display: flex; align-items: flex-start; gap: 10px; }
.ai-result-header .ai-icon { width: 32px; height: 32px; border-radius: 9px; background: var(--primary); display: grid; place-items: center; color: #fff; flex-shrink: 0; font-size: 14px; }
.ai-result-header .ai-info { flex: 1; min-width: 0; }
.ai-result-header .ai-label { font-size: 12px; font-weight: 700; color: var(--primary); display: flex; align-items: center; gap: 4px; }
.ai-result-header .ai-label .check { width: 14px; height: 14px; }
.ai-result-header .ai-text { font-size: 13px; color: var(--ink-2); margin-top: 4px; line-height: 1.4; word-break: break-word; }

/* Form fields */
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; color: var(--ink-2); margin-bottom: 5px; font-weight: 600; }
.field input, .field select { width: 100%; border: 1.5px solid var(--line); border-radius: 11px; padding: 11px 12px; font-size: 14px; font-family: inherit; background: #fbfbfe; color: var(--ink); outline: none; transition: border-color .15s ease; }
.field input:focus, .field select:focus { border-color: var(--primary); background: #fff; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.time-row { display: flex; align-items: center; gap: 8px; }
.time-row input { flex: 1; }
.time-row span { color: var(--muted); font-size: 13px; flex-shrink: 0; }
.allday { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 8px; cursor: pointer; }
.allday input { width: auto; margin: 0; }

/* AI preview editable rows */
.ai-pill { font-size: 10px; font-weight: 600; color: var(--accent); background: #e4fbff; padding: 2px 8px; border-radius: 999px; }
.ai-preview-box { border: 1.5px solid var(--primary-bg); border-radius: 12px; padding: 10px 12px; background: #fbfbfe; margin-bottom: 14px; }
.pv-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid #f2f2f8; font-size: 14px; }
.pv-row:last-child { border-bottom: none; }
.pv-row b { color: var(--muted); font-weight: 600; font-size: 12px; flex-shrink: 0; width: 48px; }
.pv-row input, .pv-row select { border: 1.5px solid var(--line); border-radius: 9px; padding: 8px 10px; font-size: 14px; font-family: inherit; background: var(--surface); color: var(--ink); outline: none; flex: 1; max-width: 66%; }
.pv-row input:focus, .pv-row select:focus { border-color: var(--primary); }
.pv-row .time-row { max-width: 66%; flex: 1; }
.pv-row .seg { max-width: 66%; flex: 1; }
.seg { display: flex; background: #f0f0f8; border-radius: 9px; padding: 3px; }
.seg button { flex: 1; border: none; background: none; padding: 7px 14px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; font-family: inherit; transition: all .12s ease; }
.seg button.active { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }

/* ---------- Toast ---------- */
.toast { position: fixed; top: 60px; left: 50%; transform: translate(-50%, -80px); background: var(--ink); color: #fff; font-size: 13px; padding: 9px 16px; border-radius: 999px; display: flex; align-items: center; gap: 7px; z-index: 60; transition: transform .3s ease; box-shadow: 0 8px 24px rgba(0,0,0,0.20); max-width: 90vw; }
.toast.show { transform: translate(-50%, 0); }
.toast .dot { width: 7px; height: 7px; border-radius: 50%; background: #2ed573; flex-shrink: 0; }
.toast.err .dot { background: #e74c3c; }