:root {
  --bg: #0b0d10;
  --bg-soft: #11151a;
  --panel: #151a20;
  --panel-strong: #1b2129;
  --line: #2a313a;
  --text: #f4f7fb;
  --muted: #98a3b2;
  --muted-2: #697586;
  --accent: #ff705e;
  --accent-soft: rgba(255, 112, 94, 0.14);
  --gold: #ffc56c;
  --green: #64d59a;
  --danger: #ff6b6b;
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.4);
  --radius: 22px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "HarmonyOS Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 12% -10%, rgba(255, 112, 94, 0.12), transparent 35%),
    radial-gradient(circle at 105% 15%, rgba(255, 197, 108, 0.08), transparent 30%),
    var(--bg);
}

button, input, textarea { font: inherit; }
button { color: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: 0.69rem;
  font-weight: 750;
  letter-spacing: 0.16em;
}

.login-screen {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100dvh;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
  overflow: auto;
}
.login-glow {
  position: fixed;
  inset: 15% -30% auto;
  height: 55vh;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 112, 94, 0.18), transparent 66%);
  filter: blur(22px);
  pointer-events: none;
}
.login-card {
  position: relative;
  width: min(100%, 430px);
  padding: 32px 26px 26px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 30px;
  background: linear-gradient(155deg, rgba(28, 34, 43, 0.96), rgba(13, 16, 21, 0.96));
  box-shadow: var(--shadow);
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin-bottom: 24px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 19px;
  background: linear-gradient(145deg, #242b34, #101318);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.1), 0 18px 38px rgba(0, 0, 0, 0.34);
}
.brand-mark span {
  color: var(--accent);
  font: 700 1.35rem/1 ui-monospace, SFMono-Regular, Consolas, monospace;
  letter-spacing: -0.08em;
}
.login-card h1 { margin: 8px 0 10px; font-size: clamp(2rem, 9vw, 2.65rem); letter-spacing: -0.04em; }
.login-copy { margin: 0 0 26px; color: var(--muted); line-height: 1.65; font-size: 0.94rem; }
.login-form { display: grid; gap: 10px; }
.login-form label { color: var(--muted); font-size: 0.82rem; font-weight: 650; }
.token-row { position: relative; display: flex; gap: 8px; }
.token-row input { flex: 1; min-width: 0; padding-right: 72px; }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 15px;
  outline: none;
  background: rgba(8, 10, 13, 0.65);
  color: var(--text);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}
input { min-height: 50px; padding: 0 15px; }
textarea { resize: none; }
input:focus, textarea:focus { border-color: rgba(255, 112, 94, 0.62); box-shadow: 0 0 0 4px rgba(255, 112, 94, 0.1); }
.ghost-button {
  position: absolute;
  right: 6px;
  top: 6px;
  height: 38px;
  padding: 0 13px;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--muted);
  cursor: pointer;
}
.primary-button {
  min-height: 52px;
  margin-top: 7px;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent), #ff9a64);
  color: #180b08;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(255, 112, 94, 0.2);
}
.primary-button:disabled { opacity: 0.55; cursor: wait; }
.form-error { min-height: 1.3em; margin: 4px 2px 0; color: var(--danger); font-size: 0.82rem; }
.login-footnote { margin: 22px 0 0; color: var(--muted-2); font-size: 0.75rem; line-height: 1.55; }

.app-screen { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: 46px 1fr auto;
  align-items: center;
  gap: 9px;
  min-height: calc(64px + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(11, 13, 16, 0.86);
  backdrop-filter: blur(20px);
}
.icon-button, .composer-icon, .send-button {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 14px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-button:active, .composer-icon:active { background: rgba(255, 255, 255, 0.07); }
.icon-button svg, .composer-icon svg, .send-button svg, .upload-button svg {
  width: 21px;
  height: 21px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.topbar-title { min-width: 0; line-height: 1.15; }
.title-row { display: flex; align-items: center; gap: 7px; }
.topbar-title strong { font-size: 1.02rem; letter-spacing: -0.01em; }
.topbar-title > span { display: block; margin-top: 3px; color: var(--muted-2); font-size: 0.72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted-2); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.04); }
.status-dot.online { background: var(--green); box-shadow: 0 0 0 3px rgba(100, 213, 154, 0.1); }
.status-dot.working { background: var(--gold); box-shadow: 0 0 0 3px rgba(255, 197, 108, 0.12); animation: pulse 1.4s infinite; }
.status-dot.offline { background: var(--danger); }
.topbar-actions { display: flex; gap: 1px; }

.chat-scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior-contain;
  scroll-behavior: smooth;
}
.welcome-panel {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: clamp(42px, 11vh, 86px) 22px 28px;
}
.welcome-orb {
  width: 48px;
  height: 48px;
  margin-bottom: 25px;
  border-radius: 16px;
  background: conic-gradient(from 210deg, var(--accent), var(--gold), #6aa2ff, var(--accent));
  box-shadow: 0 0 46px rgba(255, 112, 94, 0.22);
  animation: breathe 5s ease-in-out infinite;
}
.welcome-panel h2 { max-width: 560px; margin: 9px 0 12px; font-size: clamp(1.85rem, 7vw, 3rem); line-height: 1.13; letter-spacing: -0.04em; }
.welcome-panel > p:not(.eyebrow) { max-width: 620px; margin: 0; color: var(--muted); line-height: 1.7; font-size: 0.95rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 24px; }
.quick-actions button {
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  color: #cbd3dd;
  font-size: 0.8rem;
  cursor: pointer;
}
.quick-actions button:active { background: var(--accent-soft); border-color: rgba(255, 112, 94, 0.25); }

.messages { width: min(100%, 860px); margin: 0 auto; padding: 18px 16px 0; }
.message { display: flex; gap: 10px; margin: 0 0 22px; animation: rise 220ms ease both; }
.message.user { flex-direction: row-reverse; }
.message-avatar {
  flex: 0 0 29px;
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.67rem;
  font-weight: 800;
}
.message.user .message-avatar { background: linear-gradient(145deg, var(--accent), #ff9d68); border-color: transparent; color: #1b0c09; }
.message-body { max-width: min(86%, 720px); min-width: 0; }
.message.user .message-body { display: flex; flex-direction: column; align-items: flex-end; }
.bubble {
  overflow-wrap: anywhere;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 18px;
  background: rgba(23, 28, 35, 0.9);
  padding: 12px 14px;
  color: #e9edf3;
  line-height: 1.68;
  font-size: 0.94rem;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.09);
}
.message.user .bubble { border-color: rgba(255, 112, 94, 0.16); border-bottom-right-radius: 6px; background: rgba(255, 112, 94, 0.12); color: #fff0ec; }
.message.assistant .bubble { border-bottom-left-radius: 6px; }
.bubble p { margin: 0 0 0.72em; }
.bubble p:last-child { margin-bottom: 0; }
.bubble h1, .bubble h2, .bubble h3 { margin: 0.9em 0 0.42em; line-height: 1.3; letter-spacing: -0.02em; }
.bubble h1:first-child, .bubble h2:first-child, .bubble h3:first-child { margin-top: 0; }
.bubble h1 { font-size: 1.28rem; } .bubble h2 { font-size: 1.14rem; } .bubble h3 { font-size: 1.02rem; }
.bubble ul, .bubble ol { margin: 0.35em 0 0.8em; padding-left: 1.35em; }
.bubble li { margin: 0.2em 0; }
.bubble blockquote { margin: 0.7em 0; padding: 0.15em 0 0.15em 0.85em; border-left: 2px solid var(--accent); color: var(--muted); }
.bubble code {
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.28);
  padding: 0.08em 0.35em;
  font: 0.85em/1.5 ui-monospace, SFMono-Regular, Consolas, monospace;
  color: #ffd0c8;
}
.code-block { position: relative; margin: 0.8em 0; }
.code-block pre {
  overflow-x: auto;
  margin: 0;
  padding: 13px 13px 14px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 13px;
  background: #090b0e;
  color: #d5deea;
  font: 0.78rem/1.62 ui-monospace, SFMono-Regular, Consolas, monospace;
}
.code-copy {
  position: absolute;
  top: 7px;
  right: 7px;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(28, 33, 41, 0.9);
  color: var(--muted);
  font-size: 0.66rem;
  cursor: pointer;
}
.message-time { margin-top: 5px; color: var(--muted-2); font-size: 0.64rem; }
.activity-panel { width: min(100%, 860px); margin: 0 auto 16px; padding: 0 16px; }
.activity-heading { display: flex; align-items: center; gap: 9px; margin: 0 2px 8px; color: var(--muted); font-size: 0.76rem; }
.tool-list { display: grid; gap: 7px; }
.tool-card { overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.07); border-radius: 13px; background: rgba(18, 22, 27, 0.78); }
.tool-card summary { display: flex; align-items: center; gap: 9px; padding: 10px 11px; color: var(--muted); font-size: 0.75rem; cursor: pointer; list-style: none; }
.tool-card summary::-webkit-details-marker { display: none; }
.tool-card summary code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #c4ceda; font: 0.72rem ui-monospace, SFMono-Regular, Consolas, monospace; }
.tool-state { flex: 0 0 auto; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); }
.tool-state.completed { background: var(--green); }
.tool-state.failed { background: var(--danger); }
.tool-card pre { max-height: 240px; overflow: auto; margin: 0; padding: 10px 12px 12px; border-top: 1px solid rgba(255, 255, 255, 0.06); background: rgba(0, 0, 0, 0.18); color: var(--muted); white-space: pre-wrap; font: 0.69rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.notice-card { padding: 10px 12px; border: 1px solid rgba(255, 197, 108, 0.13); border-radius: 12px; background: rgba(255, 197, 108, 0.06); color: #d8c49c; font-size: 0.75rem; line-height: 1.55; }
.bottom-spacer { height: 176px; }

.composer-shell { z-index: 30; flex: 0 0 auto; padding: 7px 12px calc(9px + var(--safe-bottom)); background: linear-gradient(180deg, rgba(11, 13, 16, 0), rgba(11, 13, 16, 0.92) 24%); }
.activity-mini { display: flex; align-items: center; gap: 8px; width: min(100%, 860px); margin: 0 auto 7px; padding: 8px 10px; border: 1px solid rgba(255, 197, 108, 0.13); border-radius: 12px; background: rgba(34, 29, 20, 0.82); color: #dcc89f; font-size: 0.71rem; backdrop-filter: blur(12px); }
.activity-mini span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-mini button { border: 0; border-radius: 8px; background: rgba(255, 255, 255, 0.07); color: #e9d5ad; padding: 5px 9px; font-size: 0.68rem; }
.composer { display: flex; align-items: flex-end; gap: 4px; width: min(100%, 860px); margin: 0 auto; padding: 6px; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 22px; background: rgba(24, 29, 36, 0.95); box-shadow: 0 15px 46px rgba(0, 0, 0, 0.33), inset 0 1px rgba(255, 255, 255, 0.04); backdrop-filter: blur(18px); }
.composer textarea { flex: 1; min-height: 44px; max-height: 142px; padding: 11px 7px; border: 0; background: transparent; line-height: 1.45; font-size: 0.94rem; }
.composer textarea:focus { box-shadow: none; }
.composer-icon { flex: 0 0 44px; width: 44px; height: 44px; }
.composer-icon.listening { color: var(--accent); background: var(--accent-soft); animation: pulse 1.2s infinite; }
.send-button { flex: 0 0 44px; width: 44px; height: 44px; border: 0; background: linear-gradient(145deg, var(--accent), #ff9b66); color: #1d0b08; }
.send-button:disabled { opacity: 0.4; cursor: default; }
.composer-hint { margin: 6px auto 0; color: var(--muted-2); text-align: center; font-size: 0.62rem; }
.mini-spinner { flex: 0 0 auto; width: 12px; height: 12px; border: 1.5px solid rgba(255, 197, 108, 0.25); border-top-color: var(--gold); border-radius: 50%; animation: spin 0.8s linear infinite; }
.sheet { position: fixed; z-index: 80; inset: 0; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.62); backdrop-filter: blur(4px); animation: fade 180ms ease; }
.sheet-panel { position: absolute; inset: calc(20px + var(--safe-top)) 0 0; display: flex; flex-direction: column; overflow: hidden; border: 1px solid rgba(255, 255, 255, 0.1); border-bottom: 0; border-radius: 26px 26px 0 0; background: #101419; box-shadow: 0 -24px 80px rgba(0, 0, 0, 0.55); animation: sheetUp 240ms cubic-bezier(.2,.8,.2,1) both; }
.sheet-header { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 12px; }
.sheet-header h2 { margin: 5px 0 0; font-size: 1.42rem; letter-spacing: -0.03em; }
.root-tabs { display: flex; gap: 6px; padding: 0 18px 13px; overflow-x: auto; scrollbar-width: none; }
.root-tabs::-webkit-scrollbar { display: none; }
.root-tab { flex: 0 0 auto; padding: 8px 12px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--muted); font-size: 0.75rem; }
.root-tab.active { border-color: rgba(255, 112, 94, 0.28); background: var(--accent-soft); color: #ffd9d2; }
.file-toolbar { display: flex; align-items: center; gap: 8px; padding: 0 18px 11px; border-bottom: 1px solid rgba(255, 255, 255, 0.07); }
.breadcrumb { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow-x: auto; scrollbar-width: none; color: var(--muted-2); font-size: 0.72rem; white-space: nowrap; }
.breadcrumb::-webkit-scrollbar { display: none; }
.breadcrumb button { flex: 0 0 auto; padding: 4px 2px; border: 0; background: transparent; color: var(--muted); font-size: inherit; }
.breadcrumb span { opacity: 0.45; }
.upload-button { display: flex; align-items: center; gap: 5px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); font-size: 0.72rem; }
.upload-button input { display: none; }
.upload-button svg { width: 16px; height: 16px; }
.file-list { flex: 1; min-height: 0; overflow-y: auto; padding: 9px 9px calc(18px + var(--safe-bottom)); }
.file-row { display: flex; align-items: center; gap: 11px; width: 100%; min-height: 55px; padding: 7px 10px; border: 0; border-radius: 13px; background: transparent; color: var(--text); text-align: left; }
.file-row:active { background: rgba(255, 255, 255, 0.05); }
.file-icon { display: grid; place-items: center; flex: 0 0 36px; width: 36px; height: 36px; border-radius: 11px; background: rgba(255, 255, 255, 0.05); color: var(--muted); font-size: 0.65rem; font-weight: 800; }
.file-icon.dir { color: var(--gold); background: rgba(255, 197, 108, 0.08); }
.file-meta { flex: 1; min-width: 0; }
.file-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.83rem; font-weight: 600; }
.file-meta span { display: block; margin-top: 3px; color: var(--muted-2); font-size: 0.66rem; }
.file-arrow { color: var(--muted-2); font-size: 1rem; }
.empty-state { padding: 42px 20px; color: var(--muted-2); text-align: center; font-size: 0.8rem; line-height: 1.6; }

.toast { position: fixed; z-index: 120; left: 50%; bottom: calc(88px + var(--safe-bottom)); max-width: min(88vw, 520px); padding: 10px 14px; border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 13px; background: rgba(30, 35, 43, 0.96); color: #e9edf3; font-size: 0.78rem; line-height: 1.5; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 8px); transition: opacity 180ms ease, transform 180ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { border-color: rgba(255, 107, 107, 0.25); color: #ffd5d5; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }
@keyframes breathe { 0%, 100% { transform: scale(1); filter: saturate(1); } 50% { transform: scale(1.06); filter: saturate(1.22); } }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheetUp { from { transform: translateY(22px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }

@media (min-width: 760px) {
  .topbar { padding-left: 20px; padding-right: 20px; }
  .chat-scroller { padding-top: 8px; }
  .messages { padding-left: 24px; padding-right: 24px; }
  .activity-panel { padding-left: 24px; padding-right: 24px; }
  .sheet-panel { inset: 6vh auto auto 50%; width: min(680px, 88vw); max-height: 86vh; transform: translateX(-50%); border-radius: 26px; border-bottom: 1px solid rgba(255, 255, 255, 0.1); animation-name: sheetUpDesktop; }
  @keyframes sheetUpDesktop { from { transform: translate(-50%, 18px); opacity: 0.6; } to { transform: translate(-50%, 0); opacity: 1; } }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}