:root {
  --bg: #0e1013;
  --surface: #171a1f;
  --surface-2: #20242b;
  --line: #2b313a;
  --ink: #eef2f6;
  --muted: #93a0b0;
  --accent: #5eead4;
  --accent-deep: #14b8a6;
  --user: #134e4a;
  --user-ink: #ccfbf1;
  --danger: #fbbf24;
  --radius: 16px;
  --max: 520px;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}
body > p[data-aigc-mark] {
  margin: 0 !important;
  height: 0 !important;
  overflow: hidden !important;
  visibility: hidden !important;
  pointer-events: none !important;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: none; background: none; }
.hidden { display: none !important; }

.app {
  width: min(100%, var(--max));
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 400px at 50% -10%, rgba(20, 184, 166, 0.12), transparent 60%),
    var(--bg);
}

/* login */
.login-view:not(.hidden) {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(100%, 300px);
  text-align: center;
  background: rgba(23, 26, 31, 0.92);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 34px 22px 26px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-name { font-size: 22px; font-weight: 700; margin-top: 12px; }
.login-sub { color: var(--muted); font-size: 12px; margin: 4px 0 18px; letter-spacing: 0.08em; }
.login-card form { display: flex; flex-direction: column; gap: 12px; }
.login-card input {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 14px;
  padding: 12px 14px;
  outline: none;
  text-align: center;
}
.login-card input:focus { border-color: var(--accent-deep); }
.login-error { margin-top: 10px; color: var(--danger); font-size: 13px; }

.avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(145deg, #5eead4, #0f766e);
  color: #042f2e;
  display: grid; place-items: center;
  font-weight: 700; font-size: 15px; flex-shrink: 0;
}
.avatar-lg { width: 62px; height: 62px; font-size: 22px; margin: 0 auto; }

.main-view:not(.hidden) {
  flex: 1 1 auto;
  display: flex !important;
  flex-direction: column;
  min-height: 0;
  width: 100%;
  position: relative;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 16, 19, 0.88);
  backdrop-filter: blur(12px);
  z-index: 5;
  min-height: 58px;
}
.top-left { display: flex; align-items: center; gap: 10px; }
.app-name { font-weight: 700; font-size: 16px; line-height: 1.15; }
.app-status { font-size: 11px; color: var(--accent); }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  color: var(--muted); font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

.menu {
  position: absolute;
  right: 12px;
  top: 58px;
  min-width: 132px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px;
  z-index: 20;
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
}
.menu button {
  display: block; width: 100%; text-align: left;
  padding: 10px 12px; border-radius: 8px;
  color: var(--ink); font-size: 14px;
}
.menu button:hover { background: var(--surface-2); }

.chat-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  position: relative;
}
.chat-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  flex-shrink: 0;
  border: 1px solid transparent;
}
.bubble.assistant {
  align-self: flex-start;
  background: var(--surface);
  border-color: var(--line);
  border-bottom-left-radius: 6px;
  color: var(--ink);
}
.bubble.user {
  align-self: flex-end;
  background: var(--user);
  color: var(--user-ink);
  border-bottom-right-radius: 6px;
}
.bubble img {
  display: block;
  max-width: 100%;
  max-height: 220px;
  border-radius: 12px;
  margin-top: 6px;
  object-fit: cover;
}
.bubble strong { color: inherit; }

.typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-bottom-left-radius: 6px;
  flex-shrink: 0;
}
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.15s; }
.typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes blink {
  0%, 80%, 100% { opacity: 0.25; }
  40% { opacity: 1; }
}

.cite-row {
  margin-top: 6px;
  font-size: 11px;
  color: var(--muted);
}
.saved-line {
  margin-top: 6px;
  font-size: 12px;
  color: var(--accent);
}
.link-btn {
  display: inline-flex;
  margin: 6px 6px 0 0;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--accent-deep);
  color: #042f2e !important;
  text-decoration: none !important;
  font-weight: 600;
  font-size: 13px;
}

.suggestions {
  flex: 0 0 auto;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 12px 8px;
  scrollbar-width: none;
  max-height: 40px;
}
.suggestions::-webkit-scrollbar { display: none; }
.suggestions button {
  flex-shrink: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 999px;
  padding: 7px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.suggestions button:hover { border-color: var(--accent-deep); background: rgba(20,184,166,0.12); }

.img-preview {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 0 12px 6px;
  position: relative;
}
.img-preview img {
  max-height: 72px;
  max-width: 90px;
  border-radius: 10px;
  border: 1px solid var(--line);
  object-fit: cover;
}
.img-preview button {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface-2); color: var(--muted); font-size: 14px;
}

.composer {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--line);
  background: #0e1013;
  min-height: 58px;
  z-index: 6;
}
.composer input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 22px;
  padding: 11px 14px;
  outline: none;
  min-height: 42px;
}
.composer input[type="text"]:focus {
  border-color: var(--accent-deep);
  box-shadow: 0 0 0 3px rgba(20,184,166,0.15);
}
.send-btn {
  width: 42px; height: 42px; border-radius: 50%;
  background: var(--accent-deep); color: #042f2e;
  display: grid; place-items: center; flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.45; }

.panel {
  position: absolute; inset: 0;
  background: var(--bg); z-index: 10;
  display: flex; flex-direction: column;
}
.panel-top {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border-bottom: 1px solid var(--line);
}
.panel-title { font-weight: 700; font-size: 16px; flex: 1; }
.panel-body { flex: 1; overflow: auto; padding: 14px 12px 24px; }
.panel-desc { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.search-row { display: flex; gap: 8px; margin-bottom: 12px; }
.field-input, .panel textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 12px;
  padding: 10px 12px;
  outline: none;
  color: var(--ink);
}
.panel textarea { resize: vertical; margin-bottom: 10px; }
.field-label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.btn-primary {
  width: 100%; background: var(--accent-deep); color: #042f2e;
  font-weight: 600; border-radius: 12px; padding: 12px;
}
.btn-ghost {
  border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); border-radius: 10px; padding: 8px 12px; font-size: 13px;
}
.note-list { display: flex; flex-direction: column; gap: 8px; }
.note-card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px 14px;
}
.note-card h3 {
  margin: 0 0 6px; font-size: 14px;
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
}
.note-card p { margin: 0; color: var(--muted); font-size: 13px; }
.tag {
  font-size: 11px; color: var(--accent);
  background: rgba(94, 234, 212, 0.12);
  border-radius: 999px; padding: 2px 8px;
}
.inbox-summary {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 12px;
  font-size: 13px; color: var(--muted);
  white-space: pre-wrap; margin-bottom: 10px;
}
.brief-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty {
  color: var(--muted); font-size: 13px; text-align: center;
  padding: 24px 8px; border: 1px dashed var(--line); border-radius: 14px;
}
