:root {
  --bg: #f2f3f5;
  --bg-white: #ffffff;
  --hairline: rgba(17,24,39,.07);
  --text: #1c2128;
  --text-mid: #646c76;
  --text-dim: #9aa1a9;
  --accent: #07c160;
  --accent-dark: #06a854;
  --accent-soft: #e6f8ee;
  --bubble-me: #93eb67;
  --danger: #e0452c;
  --amber-bg: #fff9e8;
  --amber-line: #f0dc9a;
  --amber-text: #8a6d1a;
  --shadow-xs: 0 1px 2px rgba(16,24,40,.05);
  --shadow-sm: 0 1px 3px rgba(16,24,40,.07);
  --shadow-md: 0 6px 20px rgba(16,24,40,.10);
  --shadow-lg: 0 14px 44px rgba(16,24,40,.16);
  --ease: cubic-bezier(.25,.9,.3,1);
  --chev: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 width=%2710%27 height=%276%27%3E%3Cpath d=%27M1 1l4 4 4-4%27 stroke=%27%23646c76%27 stroke-width=%271.6%27 fill=%27none%27 stroke-linecap=%27round%27/%3E%3C/svg%3E");
}
* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: -apple-system, "PingFang SC", "HarmonyOS Sans SC", "MiSans", "Source Han Sans SC", "Microsoft YaHei", sans-serif;
  font-size: 16px; line-height: 1.7; overflow: hidden;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
.hidden { display: none !important; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
button:active { opacity: .72; }
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-thumb { background: rgba(16,24,40,.16); border-radius: 2px; }

/* ---------- auth ---------- */
.auth { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 50; }
.auth-card { width: min(330px, 86vw); text-align: center; }
.auth-logo { width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 18px; background: linear-gradient(140deg, #0cd572, #05a050); color: #fff; font-size: 33px; font-weight: 700; display: flex; align-items: center; justify-content: center; box-shadow: 0 8px 22px rgba(7,193,96,.32); }
.auth-card h1 { font-size: 21px; margin-bottom: 8px; letter-spacing: 0; }
.auth-card p { color: var(--text-dim); font-size: 14px; margin-bottom: 20px; }
.auth-card input { width: 100%; padding: 13px 15px; border-radius: 13px; border: 1px solid var(--hairline); background: var(--bg-white); color: var(--text); margin-bottom: 12px; font-size: 16px; outline: none; transition: border-color .15s var(--ease), box-shadow .15s var(--ease); }
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(7,193,96,.15); }
.auth-card button { width: 100%; padding: 13px; border-radius: 13px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 14px rgba(7,193,96,.28); }

/* ---------- layout ---------- */
.app { display: flex; height: 100dvh; }
#sidebar {
  width: 302px; min-width: 302px; background: var(--bg-white); border-right: 1px solid var(--hairline);
  display: flex; flex-direction: column; height: 100%;
}
#main { flex: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; position: relative; }
.drawer-mask { position: fixed; inset: 0; background: rgba(15,18,22,.42); z-index: 19; transition: opacity .26s var(--ease); }
@media (max-width: 767px) {
  #sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 20; transform: translateX(-100%); width: 82vw; min-width: 82vw; will-change: transform; }
  #sidebar.open { transform: translateX(0); box-shadow: 8px 0 32px rgba(16,24,40,.16); }
  #sidebar.anim { transition: transform .26s var(--ease); }
}

/* ---------- sidebar ---------- */
.sb-head { display: flex; align-items: center; gap: 4px; padding: 18px 16px 12px; }
.sb-title { font-weight: 700; font-size: 20px; flex: 1; letter-spacing: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; margin: 0 6px; }
.dot-on { background: var(--accent); box-shadow: 0 0 0 3px rgba(7,193,96,.14); }
.dot-off { background: var(--danger); box-shadow: 0 0 0 3px rgba(224,69,44,.14); }
.sb-head .icon-btn { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 10px; color: var(--text-mid); font-size: 16px; }
.sb-head .icon-btn:active { background: #f0f1f3; }

.version-banner { margin: 0 14px 8px; padding: 9px 11px; border-radius: 11px; background: var(--amber-bg); border: 1px solid var(--amber-line); color: var(--amber-text); font-size: 12px; line-height: 1.55; }

.projects { flex: 1; overflow-y: auto; padding: 2px 10px 22px; }
.sb-empty { padding: 22px 14px; color: var(--text-dim); font-size: 14px; }
.proj-head { display: flex; align-items: center; gap: 4px; padding: 13px 8px 6px; cursor: pointer; user-select: none; border-radius: 10px; }
.proj-head:active { background: #f3f4f6; }
.proj-chevron { color: #b7bcc2; font-size: 10px; width: 14px; text-align: center; transition: transform .18s var(--ease); }
.proj-head.collapsed .proj-chevron { transform: rotate(-90deg); }
.proj-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; color: var(--text-mid); font-size: 12.5px; }
.proj-add { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; color: var(--accent-dark); font-size: 19px; font-weight: 500; border-radius: 50%; }
.proj-add:active { background: var(--accent-soft); }

.thread-item { display: flex; align-items: center; gap: 6px; padding: 10px 10px 10px 22px; cursor: pointer; border-radius: 12px; margin: 2px 0; transition: background .12s var(--ease); }
.thread-item:active { background: #f3f4f6; }
.thread-item.active { background: #eceef1; box-shadow: inset 3px 0 0 var(--accent); }
.thread-item .t-main { flex: 1; min-width: 0; }
.thread-item .t-prev { font-size: 14.5px; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.thread-item .t-time { font-size: 11.5px; color: var(--text-dim); margin-top: 2px; }
.thread-item.unread .t-prev { font-weight: 700; }
.t-status { width: 16px; display: inline-flex; justify-content: center; flex-shrink: 0; }
.spin { width: 13px; height: 13px; border: 2px solid #cdebda; border-top-color: var(--accent); border-radius: 50%; animation: rot .75s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }
.unread-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px rgba(7,193,96,.14); }

/* bottom action row: ghost project button left, primary new-thread right */
.sb-new-row { display: flex; gap: 10px; padding: 12px 14px; border-top: 1px solid var(--hairline); align-items: center; }
.new-thread-btn {
  flex: 1; padding: 13px 12px; border-radius: 14px; background: var(--accent); color: #fff;
  font-size: 14.5px; font-weight: 600; box-shadow: 0 4px 14px rgba(7,193,96,.26);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.new-project-btn {
  padding: 13px 16px; border-radius: 14px; background: #f0f1f4; color: var(--text-mid);
  font-size: 13.5px; font-weight: 600; flex-shrink: 0;
}
.usage-bar { display: flex; align-items: center; justify-content: space-between; padding: 13px 16px; border-top: 1px solid var(--hairline); background: var(--bg-white); }
.usage-label { font-size: 13.5px; color: var(--text-mid); font-weight: 600; }
.usage-mini { font-size: 12px; color: var(--text-dim); }

/* ---------- header ---------- */
#chat-header {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--hairline);
  background: rgba(255,255,255,.86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  min-height: 56px; z-index: 5;
}
#chat-header .icon-btn { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 11px; color: var(--text-mid); font-size: 17px; }
#chat-header .icon-btn:active { background: #f0f1f3; }
.th-title { flex: 1; min-width: 0; font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker {
  appearance: none; -webkit-appearance: none;
  background: #f0f1f4 var(--chev) no-repeat right 10px center;
  color: #37404a; border: 1px solid rgba(17,24,39,.05); border-radius: 999px;
  padding: 7px 26px 7px 12px; font-size: 13px; font-weight: 500; max-width: 138px; outline: none;
}

/* ---------- messages ---------- */
.messages { flex: 1; overflow-y: auto; padding: 18px 13px 12px; background: var(--bg); }
@media (min-width: 900px) {
  .messages { padding: 24px calc(50% - 372px) 14px; }
  .composer-row { max-width: 744px; margin: 0 auto; }
}
.empty { position: absolute; inset: 56px 0 0; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--text-dim); text-align: center; pointer-events: none; font-size: 14px; line-height: 1.8; }
.empty::before { content: "C"; width: 62px; height: 62px; border-radius: 18px; background: #e6e9ec; color: #b8bfc6; font-size: 30px; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.msg-user {
  margin: 12px 0 12px auto; max-width: 80%; background: var(--bubble-me); color: #14210a;
  border-radius: 17px 17px 5px 17px; padding: 11px 14px; white-space: pre-wrap; word-break: break-word; width: fit-content;
  box-shadow: 0 1px 2px rgba(24,60,12,.10); font-size: 16px; line-height: 1.65;
}
.msg-agent {
  margin: 12px 0; max-width: 94%; background: var(--bg-white); border-radius: 17px 17px 17px 5px;
  padding: 13px 15px; word-break: break-word; box-shadow: var(--shadow-xs); border: 1px solid rgba(17,24,39,.05);
  font-size: 16px; line-height: 1.75; color: #242b33;
}
.msg-agent.md p { margin: 0 0 10px; }
.msg-agent.md p:last-child { margin-bottom: 0; }
.msg-agent.md strong { font-weight: 650; }
.msg-agent.md code { background: #f1f3f5; border-radius: 5px; padding: 1.5px 6px; font-size: 13.5px; font-family: ui-monospace, "SF Mono", Consolas, monospace; color: #33404f; word-break: break-all; }
.msg-agent.md pre { background: #20242b; color: #e8ebef; border-radius: 12px; padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.6; margin: 10px 0; }
.msg-agent.md pre code { background: transparent; color: inherit; padding: 0; font-size: inherit; }
.msg-agent.md ul, .msg-agent.md ol { padding-left: 22px; margin: 8px 0; }
.msg-agent.md li { margin: 3px 0; }
.msg-agent.md a { color: #4f6b96; text-decoration: none; border-bottom: 1px solid rgba(79,107,150,.35); }
.msg-time { font-size: 11px; color: var(--text-dim); margin-top: 4px; }
.msg-img { max-width: min(264px, 68vw); border-radius: 12px; display: block; margin-top: 8px; border: 1px solid rgba(17,24,39,.06); }
.msg-video { max-width: min(300px, 75vw); border-radius: 12px; display: block; margin-top: 8px; }

details.tool-card { margin: 10px 0; max-width: 94%; border: 1px solid var(--hairline); border-radius: 13px; background: var(--bg-white); box-shadow: var(--shadow-xs); overflow: hidden; }
details.tool-card > summary { padding: 10px 13px; font-size: 13px; color: var(--text-mid); cursor: pointer; list-style: none; display: flex; align-items: center; gap: 7px; }
details.tool-card > summary::before { content: "\25B8"; color: #b7bcc2; font-size: 11px; transition: transform .15s var(--ease); }
details.tool-card[open] > summary::before { content: "\25BE"; }
details.tool-card .tool-body { padding: 2px 13px 12px; font-size: 13px; line-height: 1.65; color: var(--text-mid); white-space: pre-wrap; word-break: break-word; max-height: 300px; overflow-y: auto; }

.plan-card { margin: 10px 0; max-width: 94%; border: 1px solid var(--hairline); border-radius: 13px; background: var(--bg-white); padding: 11px 13px; font-size: 14px; box-shadow: var(--shadow-xs); }
.plan-step { display: flex; gap: 8px; padding: 3px 0; color: var(--text-mid); line-height: 1.5; }
.plan-step.done { color: var(--text); }

.working { display: flex; align-items: center; gap: 9px; color: var(--text-mid); font-size: 13.5px; padding: 10px 2px; }
.working .wdots { display: inline-flex; gap: 4px; }
.working .wdots i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); animation: wdot 1.2s infinite ease-in-out; }
.working .wdots i:nth-child(2) { animation-delay: .15s; }
.working .wdots i:nth-child(3) { animation-delay: .3s; }
@keyframes wdot { 0%,100% { opacity: .25; transform: scale(.8); } 40% { opacity: 1; transform: scale(1); } }

/* ---------- file card ---------- */
.file-card {
  display: flex; align-items: center; gap: 11px; margin: 10px 0; max-width: 94%;
  background: var(--bg-white); border: 1px solid var(--hairline); border-radius: 13px; padding: 11px 13px;
  text-decoration: none; color: var(--text); box-shadow: var(--shadow-xs);
}
.file-card .fc-icon { width: 40px; height: 40px; border-radius: 11px; background: var(--accent-soft); color: var(--accent-dark); display: flex; align-items: center; justify-content: center; font-size: 19px; flex-shrink: 0; }
.file-card .fc-name { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-card .fc-act { color: var(--accent-dark); font-size: 13px; font-weight: 600; flex-shrink: 0; }

/* ---------- approvals ---------- */
.approval { margin: 12px 0; max-width: 94%; border: 1px solid var(--amber-line); border-radius: 14px; background: #fffdf4; padding: 13px; box-shadow: var(--shadow-xs); }
.approval .ap-title { font-weight: 650; font-size: 14.5px; margin-bottom: 7px; }
.approval .ap-detail { font-size: 13px; line-height: 1.6; color: var(--text-mid); white-space: pre-wrap; word-break: break-word; margin-bottom: 11px; max-height: 160px; overflow-y: auto; }
.approval .ap-btns { display: flex; flex-wrap: wrap; gap: 8px; }
.approval .ap-btns button { padding: 9px 17px; border-radius: 999px; font-size: 14px; font-weight: 600; }
.ap-ok { background: var(--accent); color: #fff; box-shadow: 0 3px 10px rgba(7,193,96,.25); }
.ap-session { background: var(--bg-white); color: var(--text); border: 1px solid var(--hairline); }
.ap-no { background: transparent; color: var(--danger); border: 1px solid rgba(224,69,44,.55); }
.approval input.ap-input { width: 100%; padding: 11px; border-radius: 11px; border: 1px solid var(--hairline); background: var(--bg-white); color: var(--text); margin-bottom: 8px; font-size: 14px; outline: none; }
.approval input.ap-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(7,193,96,.13); }

/* ---------- composer ---------- */
.composer { padding: 9px 11px calc(11px + env(safe-area-inset-bottom)); background: transparent; }
.composer-row {
  display: flex; align-items: flex-end; gap: 4px; background: var(--bg-white);
  border-radius: 24px; padding: 5px 5px 5px 6px; box-shadow: var(--shadow-md); border: 1px solid rgba(17,24,39,.05);
}
#btn-attach { width: 38px; height: 38px; border-radius: 50%; color: var(--text-mid); font-size: 18px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
#btn-attach:active { background: #f0f1f3; }
#input {
  flex: 1; resize: none; border: none; background: transparent; color: var(--text);
  padding: 9px 6px; font: inherit; font-size: 16px; line-height: 1.5; max-height: 120px; outline: none;
}
#input::placeholder { color: var(--text-dim); }
.send-btn { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; font-size: 16px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; box-shadow: 0 3px 10px rgba(7,193,96,.32); }
.send-btn:disabled { opacity: .4; box-shadow: none; }
.attach-row { display: flex; gap: 8px; padding: 2px 4px 9px; overflow-x: auto; }
.attach-item { position: relative; flex-shrink: 0; }
.attach-item img { width: 58px; height: 58px; object-fit: cover; border-radius: 12px; border: 1px solid var(--hairline); }
.attach-item .doc-chip { width: 58px; height: 58px; border-radius: 12px; border: 1px solid var(--hairline); background: var(--bg-white); display: flex; align-items: center; justify-content: center; font-size: 23px; }
.attach-item .rm { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: rgba(15,18,22,.7); color: #fff; font-size: 12px; line-height: 20px; text-align: center; }

/* ---------- menu popover ---------- */
.menu-pop { position: fixed; top: 58px; right: 12px; background: var(--bg-white); border-radius: 14px; z-index: 30; overflow: hidden; box-shadow: var(--shadow-lg); border: 1px solid rgba(17,24,39,.05); padding: 5px; min-width: 168px; }
.menu-pop button { display: block; width: 100%; text-align: left; padding: 12px 16px; font-size: 15px; border-radius: 10px; }
.menu-pop button:active { background: #f3f4f6; }
.menu-pop button.danger { color: var(--danger); }

/* ---------- modals ---------- */
.modal { position: fixed; inset: 0; background: rgba(15,18,22,.45); z-index: 40; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-card { width: min(368px, 92vw); background: var(--bg-white); border-radius: 20px; padding: 22px; max-height: 82dvh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal-title { font-size: 18px; font-weight: 700; margin-bottom: 14px; }
.modal-sec { font-size: 14.5px; font-weight: 650; margin-bottom: 5px; }
.modal-desc { font-size: 12.5px; color: var(--text-dim); margin-bottom: 13px; line-height: 1.6; word-break: break-all; }
.modal-lab { display: block; font-size: 13px; color: var(--text-mid); margin: 12px 0 5px; font-weight: 500; }
.modal-select {
  width: 100%; padding: 12px 34px 12px 13px; border-radius: 12px; border: 1px solid var(--hairline);
  background: #f4f5f7 var(--chev) no-repeat right 13px center; font-size: 15px; outline: none;
  appearance: none; -webkit-appearance: none;
}
.modal-select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(7,193,96,.13); }
.modal-btns { display: flex; gap: 10px; margin-top: 20px; }
.modal-ok { flex: 1; padding: 12.5px; border-radius: 13px; background: var(--accent); color: #fff; font-weight: 600; box-shadow: 0 4px 12px rgba(7,193,96,.25); }
.modal-cancel { flex: 1; padding: 12.5px; border-radius: 13px; background: #f0f1f4; color: #37404a; font-weight: 600; }
.push-btns { display: flex; gap: 10px; }
.push-btns button { flex: 1; padding: 12px; border-radius: 13px; font-weight: 600; }
.qr-wrap { text-align: center; margin: 8px 0 4px; }
.qr-wrap img { width: 200px; height: 200px; border-radius: 12px; border: 1px solid var(--hairline); }
.usage-body { font-size: 14.5px; }
.usage-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #f1f2f4; }
.usage-row:last-child { border-bottom: none; }
.usage-row .u-lab { color: var(--text-mid); }
.usage-row .u-val { font-weight: 650; }
.usage-progress { height: 6px; border-radius: 3px; background: #eceef0; margin: 12px 0 5px; overflow: hidden; }
.usage-progress > div { height: 100%; border-radius: 3px; background: linear-gradient(90deg, #0cd572, var(--accent)); }

/* ---------- toast / misc ---------- */
.toast { position: fixed; left: 50%; bottom: 104px; transform: translateX(-50%); background: rgba(18,22,26,.86); backdrop-filter: blur(10px); color: #fff; padding: 11px 19px; border-radius: 999px; font-size: 14px; z-index: 60; max-width: 86vw; box-shadow: var(--shadow-md); }
#boot-error { position: fixed; left: 12px; right: 12px; bottom: 12px; background: #fff; border: 1px solid var(--danger); color: var(--danger); padding: 12px 14px; border-radius: 13px; z-index: 99; font-size: 13px; line-height: 1.5; white-space: pre-wrap; box-shadow: var(--shadow-md); }
.conn-banner { background: var(--amber-bg); color: var(--amber-text); border-bottom: 1px solid var(--amber-line); font-size: 12px; text-align: center; padding: 6px 8px; }
.push-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 12px; background: #fff8e5; color: #775510; border-bottom: 1px solid #f0d891; font-size: 13px; }
.push-banner button { flex: 0 0 auto; border: 0; border-radius: 6px; padding: 7px 14px; background: #07c160; color: #fff; font-weight: 600; }
.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(10,12,14,.94); display: flex; align-items: center; justify-content: center; }
.lightbox.hidden { display: none; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 6px; }
