:root {
  color-scheme: light;
  --bg: #f5f6f7;
  --surface: #ffffff;
  --line: #e5e6eb;
  --text: #1d2129;
  --muted: #86909c;
  --green: #20b26b;
  --red: #e5484d;
  --radius: 16px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  position: relative; z-index: 10; height: 58px; background: #fff;
  display: flex; align-items: center; padding: 0 14px;
  border-bottom: 1px solid rgba(0,0,0,.05);
}
.icon-btn { border: 0; background: transparent; color: var(--text); width: 34px; height: 34px; padding: 4px; display: inline-flex; align-items: center; justify-content: center; }
.conn-state { position: absolute; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; white-space: nowrap; font-size: 15px; font-weight: 500; }
.conn-dot { width: 9px; height: 9px; border-radius: 50%; background: #b8bcc4; display: inline-block; flex: 0 0 auto; }
.conn-dot.ok { background: var(--green); }
.conn-dot.off { background: var(--red); }
.topbar-spacer { width: 34px; margin-left: auto; }

/* page layout */
#main { height: calc(100% - 58px); overflow: hidden; }
.page { display: none; height: 100%; overflow-y: auto; padding: 18px 16px 28px; }
.page.active { display: flex; flex-direction: column; }
#page-home.active { padding-bottom: 20px; }
.home-hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 300px; gap: 18px; }
.home-hero img { width: 78px; height: 78px; object-fit: contain; }
.home-brand { font-size: 34px; line-height: 1; font-weight: 700; letter-spacing: -1px; }
.composer { margin-top: auto; padding: 10px 0 0; }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
.chip {
  border: 1px solid var(--line); background: #fff; color: #4e5969;
  border-radius: 10px; padding: 8px 10px; display: inline-flex;
  align-items: center; gap: 6px; max-width: 45vw; font-size: 14px;
}
.chip span:not(.caret) { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .caret { color: #a9afb8; font-size: 11px; }
.chip:active { background: #f2f3f5; }
.input-row { display: flex; align-items: flex-end; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 18px; padding: 8px; box-shadow: 0 3px 14px rgba(0,0,0,.04); }
#goal { flex: 1; border: 0; outline: 0; resize: none; min-height: 42px; max-height: 130px; padding: 9px 8px; background: transparent; font-size: 16px; line-height: 1.4; color: var(--text); }
#goal::placeholder { color: #a9afb8; }
.send-btn { border: 0; border-radius: 13px; background: var(--green); color: #fff; padding: 12px 17px; font-weight: 600; min-width: 66px; }
.send-btn:disabled { opacity: .45; }

/* drawer */
.drawer-mask { position: fixed; inset: 0; background: rgba(0,0,0,.18); z-index: 30; }
.drawer {
  position: fixed; left: 0; top: 0; bottom: 0; z-index: 31; width: min(78vw, 330px);
  background: #f7f8f9; transform: translateX(-102%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding: 18px 12px 0; box-shadow: 5px 0 24px rgba(0,0,0,.12);
}
.drawer.open { transform: translateX(0); }
.drawer-brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 20px; font-weight: 700; font-size: 19px; }
.drawer-brand img { width: 30px; height: 30px; object-fit: contain; }
.drawer-close { margin-left: auto; font-size: 23px; color: #4e5969; }
.new-task-btn {
  width: calc(100% - 12px); margin: 0 6px 16px; border: 1px solid #eceef1;
  border-radius: 13px; background: #fff; color: #4e5969; text-align: center;
  padding: 12px 16px; font-size: 16px; font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.03);
}
.new-task-btn span { font-size: 21px; line-height: 1; font-weight: 400; color: #86909c; }
.new-task-btn:active { background: #f7f8f9; }
.drawer-nav { display: flex; flex-direction: column; gap: 2px; }
.drawer-nav button { border: 0; background: transparent; display: flex; align-items: center; gap: 14px; text-align: left; padding: 14px 8px; color: var(--text); font-size: 17px; }
.drawer-nav button svg { width: 22px; height: 22px; flex: 0 0 auto; }
.drawer-nav button:active, .drawer-nav button.active { background: #e9ebee; border-radius: 10px; }
.drawer-divider { height: 1px; background: var(--line); margin: 14px 6px 12px; }
.drawer-task-head { display: flex; justify-content: space-between; align-items: center; padding: 0 8px; color: #6b7280; font-size: 15px; }
.text-btn { border: 0; background: transparent; color: #6b7280; font-size: 14px; }
.task-search-wrap { display: flex; gap: 8px; align-items: center; margin: 10px 2px 8px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; color: #a9afb8; }
.task-search-wrap input { border: 0; outline: 0; padding: 0; flex: 1; background: transparent; font-size: 15px; color: var(--text); }
.drawer-task-list { flex: 1; overflow-y: auto; padding: 0 2px 22px; }
.task-row { display: flex; align-items: center; gap: 7px; padding: 14px 6px; border-bottom: 1px solid rgba(0,0,0,.045); cursor: pointer; }
.task-row:active { background: #eceef0; border-radius: 8px; }
.task-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); font-size: 15px; }
.task-state { flex: 0 0 auto; font-size: 12px; border-radius: 4px; padding: 2px 5px; background: #e8f7ef; color: #17945a; }
.task-state.failed, .task-state.error { background: #fff0f0; color: var(--red); }
.task-state.running { background: #eaf3ff; color: #2c6fd1; }
.task-time { flex: 0 0 auto; color: #a9afb8; font-size: 12px; }

/* pages */
.page-head { padding: 4px 2px 14px; }
.page-head h2 { margin: 0 0 6px; font-size: 23px; }
.page-head p { margin: 0; color: var(--muted); font-size: 13px; line-height: 1.5; }
.list-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.list-item { padding: 15px 15px; border-bottom: 1px solid #f0f1f3; display: flex; gap: 12px; align-items: center; }
.list-item:last-child { border-bottom: 0; }
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-size: 16px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item-sub { margin-top: 4px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .check { width: 21px; height: 21px; border-radius: 50%; border: 1.5px solid #c9ced6; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 13px; flex: 0 0 auto; }
.list-item.sel .check { background: var(--green); border-color: var(--green); }
.list-empty { padding: 24px 16px; color: var(--muted); text-align: center; font-size: 14px; }
.outline-btn { width: 100%; margin-top: 16px; border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 12px; color: var(--text); font-size: 15px; }
.profile-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.profile-row { display: flex; justify-content: space-between; gap: 12px; padding: 16px; border-bottom: 1px solid #f0f1f3; font-size: 15px; }
.profile-row:last-child { border-bottom: 0; }
.profile-row span { color: var(--muted); }
.profile-row strong { text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* task page */
.task-page-head { display: flex; gap: 6px; align-items: center; margin-bottom: 12px; }
.task-page-head h2 { margin: 0; font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-status { color: var(--muted); font-size: 14px; padding: 0 4px 10px; }
.task-steps { margin: 0; padding: 0 0 0 20px; background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.task-steps li { padding: 12px 12px; border-bottom: 1px solid #f0f1f3; line-height: 1.55; white-space: pre-wrap; word-break: break-word; font-size: 15px; }
.task-steps li:last-child { border-bottom: 0; }
.task-steps li.error { color: var(--red); }
.task-steps li.final { color: #17945a; font-weight: 600; }

/* login */
.login-wrap { position: fixed; inset: 0; z-index: 50; background: #fff; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: 100%; max-width: 360px; }
.login-brand { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 30px; font-weight: 700; letter-spacing: -1px; }
.login-brand img { width: 54px; height: 54px; object-fit: contain; }
.login-tip { text-align: center; color: var(--muted); margin: 12px 0 26px; }
.login-card input { width: 100%; padding: 14px 13px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 11px; outline: 0; background: #fff; font-size: 16px; }
.login-card form button { width: 100%; padding: 14px; margin-top: 4px; border: 0; border-radius: 11px; background: var(--text); color: #fff; font-size: 16px; font-weight: 600; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; margin-bottom: 10px; }
.code-row button { width: 112px; margin: 0 0 10px; padding: 0 8px; border: 1px solid var(--line); border-radius: 11px; background: #fff; color: #4e5969; font-size: 14px; font-weight: 500; }
.login-switch { text-align: center; margin: 16px 0 0; }
.login-switch button { border: 0; background: transparent; color: #4e5969; font-size: 14px; }
.login-error { color: var(--red); text-align: center; min-height: 20px; font-size: 14px; margin: 12px 0 0; }

/* chips popup */
.chip-menu { position: fixed; left: 12px; right: 12px; bottom: 88px; z-index: 40; max-height: 52vh; overflow-y: auto; background: #fff; border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 8px 30px rgba(0,0,0,.16); padding: 8px; }
.chip-menu .menu-title { padding: 10px 10px 7px; color: var(--muted); font-size: 12px; }
.chip-menu button { width: 100%; border: 0; background: transparent; text-align: left; padding: 13px 10px; border-radius: 9px; color: var(--text); font-size: 15px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chip-menu button:active, .chip-menu button.sel { background: #f2f3f5; }
.chip-menu button small { color: var(--muted); font-size: 12px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 108px; transform: translateX(-50%); z-index: 60; max-width: 82vw; background: rgba(29,33,41,.92); color: #fff; padding: 10px 14px; border-radius: 10px; font-size: 14px; line-height: 1.45; text-align: center; }

@media (min-width: 700px) {
  .drawer { width: 340px; }
  .composer { max-width: 760px; width: 100%; margin-left: auto; margin-right: auto; }
  .home-hero img { width: 90px; height: 90px; }
}
