:root {
  --bg: #f3f5f8;
  --sidebar: #eef2f6;
  --rail: #e8edf3;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #8b95a5;
  --line: #d7dee8;
  --accent: #6b5cff;
  --accent-soft: #eef0ff;
  --btn-blue: #3b82f6;
  --btn-blue-bg: #eaf2ff;
  --danger: #94a3b8;
  --shadow: 0 4px 18px rgba(15, 23, 42, 0.06);
  --radius: 14px;
  --font: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --app-height: 100dvh;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  font-family: var(--font);
  color: var(--text);
  background: #dfe5ee;
  overscroll-behavior-x: none;
  overscroll-behavior-y: none;
}

button,
input,
textarea {
  font: inherit;
}

.rail,
.rail *,
.sidebar-head,
.new-chat-btn,
.composer-toolbar,
.round-tool,
.send-btn {
  user-select: none;
  -webkit-user-select: none;
}

#app {
  height: var(--app-height);
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  background: var(--bg);
  display: flex;
  position: relative;
  overflow: hidden;
  overscroll-behavior-x: none;
  touch-action: pan-y;
}

/* 手机：全宽，不变 */

/* 平板：居中中等窗口 */
@media (min-width: 768px) {
  body {
    background: #dfe5ee;
  }

  #app {
    width: 100%;
    max-width: 720px;
    height: min(var(--app-height), calc(100dvh - 32px));
    margin: 16px auto;
    border-radius: 18px;
    box-shadow: 0 0 40px rgba(15, 23, 42, 0.12);
  }

  .auth-gate {
    padding: 32px;
  }

  .bubble {
    max-width: min(480px, calc(100% - 42px));
  }
}

/* 电脑：第一版大窗口尺寸 */
@media (min-width: 1024px) {
  #app {
    max-width: 920px;
    height: calc(100dvh - 48px);
    margin: 24px auto;
  }

  .bubble {
    max-width: min(560px, calc(100% - 42px));
  }
}

/* Left icon rail — collapses when history sidebar pushes open */
.rail {
  width: 56px;
  min-width: 0;
  flex-shrink: 0;
  background: var(--rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 0 16px;
  gap: 14px;
  overflow: hidden;
  transition: width 0.22s ease, padding 0.22s ease, opacity 0.18s ease;
}

#app.sidebar-open .rail {
  width: 0;
  padding-left: 0;
  padding-right: 0;
  opacity: 0;
  pointer-events: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, #7a6bff, #5b4dff);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 6px 14px rgba(91, 77, 255, 0.28);
}

.brand-icon svg {
  width: 22px;
  height: 22px;
}

.rail-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #64748b;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.rail-btn:hover {
  background: rgba(255, 255, 255, 0.7);
}

.rail-btn.active {
  background: #fff;
  color: var(--accent);
  box-shadow: var(--shadow);
}

.rail-spacer {
  flex: 1;
}

.avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: #3b82f6;
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

/* History sidebar — in flex flow, pushes main content instead of overlay */
.sidebar {
  width: 0;
  min-width: 0;
  flex-shrink: 0;
  background: var(--sidebar);
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
  transition: width 0.22s ease, padding 0.22s ease, opacity 0.18s ease;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid transparent;
  position: relative;
}

#app.sidebar-open .sidebar,
.sidebar.open {
  width: 280px;
  min-width: 280px;
  max-width: none;
  padding: 16px 14px;
  opacity: 1;
  pointer-events: auto;
  border-right-color: rgba(148, 163, 184, 0.25);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sidebar-title {
  font-size: 16px;
  font-weight: 700;
}

.new-chat-btn {
  width: 100%;
  border: 1px solid #93c5fd;
  background: var(--btn-blue-bg);
  color: var(--btn-blue);
  border-radius: 10px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
}

.new-chat-btn:hover {
  background: #dbeafe;
}

.history-head {
  margin-top: 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #475569;
  font-size: 14px;
  font-weight: 600;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--danger);
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-btn:hover {
  background: rgba(148, 163, 184, 0.18);
  color: #ef4444;
}

.history-list {
  margin-top: 8px;
  overflow: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-height: 0;
}

.key-box {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid rgba(148, 163, 184, 0.35);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.key-label {
  font-size: 13px;
  font-weight: 600;
  color: #475569;
}

.key-status {
  font-size: 12px;
  color: #94a3b8;
}

.key-status.ok {
  color: #16a34a;
}

.key-input {
  width: 100%;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  padding: 8px 10px;
  background: #fff;
  outline: none;
}

.key-input:focus {
  border-color: #93c5fd;
}

.key-save-btn {
  border: none;
  border-radius: 8px;
  padding: 9px 10px;
  background: #3b82f6;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}

.key-save-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.key-link {
  font-size: 12px;
  color: #3b82f6;
  text-decoration: none;
}

.key-mode {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.key-mode-btn {
  border: 1px solid #dbe3ee;
  background: #f8fafc;
  color: #64748b;
  border-radius: 8px;
  padding: 7px 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.key-mode-btn.active {
  background: #eaf3ff;
  border-color: #93c5fd;
  color: #2563eb;
}

.key-mode-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.key-link-btn {
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 12px;
  text-align: left;
  padding: 0;
  cursor: pointer;
}

.key-link-btn:hover {
  color: #2563eb;
}

.history-empty {
  padding: 12px 10px;
  color: #94a3b8;
  font-size: 13px;
}

.history-row {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
}

.history-row:hover,
.history-row.active {
  background: rgba(255, 255, 255, 0.85);
}

.history-item {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  text-align: left;
  padding: 10px 8px 10px 10px;
  border-radius: 8px;
  cursor: pointer;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-del {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  margin-right: 4px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  display: grid;
  place-items: center;
  opacity: 0.7;
}

.history-del:hover {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
  opacity: 1;
}

.collapse-fab {
  position: absolute;
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid var(--line);
  background: #fff;
  color: #64748b;
  display: none;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 2;
}

#app.sidebar-open .collapse-fab {
  display: grid;
}

/* 收起过程中立刻隐藏凸出按钮，避免左侧残留一条侧栏+箭头 */
#app:not(.sidebar-open) .collapse-fab {
  display: none !important;
  opacity: 0;
  pointer-events: none;
}

.sidebar:not(.open) {
  border-right-color: transparent;
}

.backdrop {
  display: none;
}

/* Main chat — keep full readable width; sidebar push clips overflow, never squeezes text */
.main {
  flex: 0 0 calc(100% - 56px);
  width: calc(100% - 56px);
  min-width: calc(100% - 56px);
  max-width: none;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  position: relative;
}

#app.sidebar-open .expand-hint {
  visibility: hidden;
}

.topbar {
  height: 52px;
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  align-items: center;
  column-gap: 4px;
  padding: 0 10px 0 8px;
  background: rgba(243, 245, 248, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid transparent;
}

.chat-title-wrap {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar h1,
.topbar .chat-title {
  margin: 0;
  max-width: 100%;
  min-width: 0;
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  cursor: pointer;
  border-radius: 8px;
  padding: 4px 6px;
}

.topbar .chat-title:hover {
  background: rgba(255, 255, 255, 0.7);
}

.topbar .chat-title[hidden] {
  display: none !important;
}

.chat-title-input {
  width: min(100%, 280px);
  min-width: 0;
  box-sizing: border-box;
  margin: 0 auto;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 4px 8px;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  outline: none;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.chat-title-input[hidden] {
  display: none !important;
}

.history-rename {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #94a3b8;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

.history-rename:hover {
  background: rgba(148, 163, 184, 0.15);
  color: var(--accent);
}

.history-item-input {
  flex: 1;
  min-width: 0;
  box-sizing: border-box;
  border: 1px solid #93c5fd;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.topbar-new {
  width: 34px;
  height: 34px;
  justify-self: end;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: #64748b;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.topbar-new:hover {
  background: rgba(255, 255, 255, 0.85);
  color: var(--accent);
}

.expand-hint {
  border: none;
  background: transparent;
  color: #94a3b8;
  width: 28px;
  height: 28px;
  justify-self: start;
  display: grid;
  place-items: center;
  cursor: pointer;
  border-radius: 8px;
}

.messages {
  flex: 1;
  overflow: auto;
  padding: 10px 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  user-select: text;
  -webkit-user-select: text;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
  user-select: text;
  -webkit-user-select: text;
}

.msg.user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: linear-gradient(145deg, #7a6bff, #5b4dff);
  color: #fff;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.msg.user .msg-avatar {
  background: #3b82f6;
}

.bubble {
  background: var(--panel);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  line-height: 1.55;
  font-size: 14px;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: min(320px, calc(100% - 42px));
  min-width: 0;
  cursor: text;
  user-select: text;
  -webkit-user-select: text;
  -webkit-touch-callout: default;
}

.bubble:has(.md-table-wrap) {
  max-width: min(100%, calc(100% - 42px));
}

.msg.user .bubble {
  background: #eef4ff;
}

.bubble img.thumb,
.md-body img {
  display: block;
  max-width: min(260px, 100%);
  max-height: 220px;
  border-radius: 8px;
  margin: 8px 0;
  object-fit: contain;
  background: #f1f5f9;
  cursor: zoom-in;
}

.md-img-missing {
  margin: 8px 0 0;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff7ed;
  color: #c2410c;
  font-size: 12px;
  line-height: 1.45;
}

.md-img-missing p {
  margin: 0 0 6px;
}

.md-img-missing p:last-of-type {
  margin-bottom: 8px;
}

.md-img-fill {
  display: inline-block;
  border: 1px solid #fdba74;
  background: #fff;
  color: #c2410c;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  line-height: 1.2;
  cursor: pointer;
}

.md-img-fill:active {
  background: #ffedd5;
}

.md-body {
  white-space: normal;
}

.md-body > :first-child {
  margin-top: 0;
}

.md-body > :last-child {
  margin-bottom: 0;
}

.md-body p {
  margin: 0 0 0.65em;
}

.md-body p:last-child {
  margin-bottom: 0;
}

.md-body h1,
.md-body h2,
.md-body h3,
.md-body h4 {
  margin: 0.8em 0 0.4em;
  font-weight: 700;
  line-height: 1.3;
}

.md-body h1 { font-size: 1.2em; }
.md-body h2 { font-size: 1.1em; }
.md-body h3 { font-size: 1.05em; }

.md-body ul,
.md-body ol {
  margin: 0.4em 0 0.65em;
  padding-left: 1.35em;
}

.md-body li {
  margin: 0.2em 0;
}

.md-body li > p {
  margin: 0;
}

.md-body blockquote {
  margin: 0.5em 0;
  padding: 0.25em 0 0.25em 0.75em;
  border-left: 3px solid #cbd5e1;
  color: #64748b;
}

.md-body code {
  font-family: ui-monospace, Consolas, "Courier New", monospace;
  font-size: 0.9em;
  background: rgba(15, 23, 42, 0.06);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

.md-body pre {
  margin: 0.55em 0;
  padding: 10px 12px;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 12px;
  line-height: 1.45;
}

.md-body pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  font-size: inherit;
}

.md-body hr {
  border: none;
  border-top: 1px solid #e2e8f0;
  margin: 0.8em 0;
}

.md-body strong {
  font-weight: 700;
}

.md-table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 0.55em 0;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  -webkit-overflow-scrolling: touch;
}

.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  line-height: 1.4;
  min-width: 220px;
}

.md-table th,
.md-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #eef2f7;
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
}

.md-table th {
  background: #f8fafc;
  font-weight: 700;
  color: #334155;
}

.md-table tr:last-child td {
  border-bottom: none;
}

.md-table tr:nth-child(even) td {
  background: #fcfdff;
}

.msg.user .md-table-wrap {
  border-color: #dbe7ff;
}

.msg.user .md-table th {
  background: #e8f0ff;
}

.md-plain {
  margin: 0;
  white-space: pre-wrap;
}

.typing {
  color: var(--muted);
  font-size: 13px;
}

.composer-wrap {
  flex-shrink: 0;
  padding: 8px 12px calc(10px + var(--safe-bottom));
  background: var(--bg);
}

.preview-row {
  display: none;
  gap: 8px;
  overflow-x: auto;
  padding: 0 2px 2px;
  -webkit-overflow-scrolling: touch;
}

.preview-row.show {
  display: flex;
}

.preview-item {
  position: relative;
  flex: 0 0 auto;
  width: min(220px, 72vw);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 28px 8px 8px;
  background: #f3f5f8;
  border-radius: 14px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  cursor: pointer;
}

.preview-item .preview-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  flex-shrink: 0;
  background: #e5e9f0;
}

.preview-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.preview-name {
  font-size: 13px;
  font-weight: 600;
  color: #1f2937;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
}

.preview-size {
  font-size: 12px;
  color: #94a3b8;
}

.preview-item .preview-remove {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: #1f2937;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}

.preview-item .preview-remove svg {
  width: 12px;
  height: 12px;
  display: block;
}

.composer {
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 2px 14px rgba(15, 23, 42, 0.06);
  border: 1px solid rgba(148, 163, 184, 0.18);
  display: flex;
  flex-direction: column;
  padding: 12px 12px 10px;
  gap: 10px;
}

.composer textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  min-height: 28px;
  max-height: 120px;
  padding: 2px 4px;
  background: transparent;
  line-height: 1.45;
  font-size: 15px;
}

.composer textarea::placeholder {
  color: #b0b8c4;
}

.composer-toolbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.round-tool {
  width: 34px;
  height: 34px;
  border: 1.5px solid #cfd6e0;
  border-radius: 50%;
  background: #fff;
  color: #334155;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.round-tool.active {
  border-color: #2f7cf6;
  color: #2f7cf6;
  background: #eaf3ff;
}

.send-btn {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  display: none;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  background: var(--accent);
  color: #fff;
}

.send-btn.show {
  display: grid;
}

.send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

body.keyboard-open .composer-wrap {
  padding-bottom: 8px;
}

.error-toast {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  background: #1e293b;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.45;
  width: max-content;
  max-width: min(86%, 360px);
  text-align: center;
  word-break: break-word;
  z-index: 80;
  display: none;
  box-sizing: border-box;
  pointer-events: none;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.22);
}

.error-toast.show {
  display: block;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(15, 23, 42, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 52px 16px 96px;
}

.lightbox[hidden] {
  display: none !important;
}

.lightbox-img {
  max-width: min(100%, 920px);
  max-height: 100%;
  object-fit: contain;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.lightbox-meta {
  position: absolute;
  top: max(12px, env(safe-area-inset-top, 0px));
  left: 12px;
  right: 56px;
  z-index: 2;
  padding: 7px 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.72);
  color: #f8fafc;
  font-size: 12px;
  line-height: 1.35;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
  width: max-content;
  max-width: calc(100% - 72px);
}

.lightbox-nav {
  position: absolute;
  top: calc(50% - 28px);
  transform: translateY(-50%);
  z-index: 2;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.28);
}

.lightbox-nav.prev {
  left: 10px;
}

.lightbox-nav.next {
  right: 10px;
}

.lightbox-nav[hidden] {
  display: none !important;
}

.lightbox-close {
  position: absolute;
  top: max(10px, env(safe-area-inset-top, 0px));
  right: 12px;
  z-index: 3;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  line-height: 0;
}

.lightbox-close svg {
  width: 18px;
  height: 18px;
  display: block;
}

.lightbox-filmstrip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 12px max(12px, env(safe-area-inset-bottom, 0px));
  background: linear-gradient(to top, rgba(15, 23, 42, 0.72), rgba(15, 23, 42, 0.28) 70%, transparent);
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}

.lightbox-filmstrip[hidden] {
  display: none !important;
}

.lightbox-thumb {
  flex: 0 0 auto;
  width: 56px;
  height: 56px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.55);
  overflow: hidden;
  cursor: pointer;
  opacity: 0.72;
}

.lightbox-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.lightbox-thumb:hover {
  opacity: 0.92;
}

.lightbox-thumb.active {
  border-color: #fff;
  opacity: 1;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.35);
}

.bubble a.msg-link {
  color: #2563eb;
  text-decoration: underline;
  text-underline-offset: 2px;
  word-break: break-all;
  cursor: pointer;
}

.msg.user .bubble a.msg-link {
  color: #1d4ed8;
}

.link-sheet {
  position: absolute;
  inset: 0;
  z-index: 32;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.link-sheet[hidden] {
  display: none;
}

.link-sheet-card {
  width: min(100%, 420px);
  background: #fff;
  border-radius: 16px;
  padding: 16px 16px 14px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.2);
  margin: 0;
}

.link-sheet-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.link-sheet-host {
  font-size: 13px;
  color: var(--accent);
  margin-bottom: 6px;
}

.link-sheet-url {
  font-size: 12px;
  color: #64748b;
  word-break: break-all;
  line-height: 1.45;
  max-height: 4.5em;
  overflow: auto;
  margin-bottom: 14px;
}

.link-sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.link-sheet-btn {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  background: #fff;
  color: #334155;
  font-size: 14px;
  cursor: pointer;
}

.link-sheet-btn.primary {
  background: var(--btn-blue);
  border-color: var(--btn-blue);
  color: #fff;
  font-weight: 600;
}

.link-sheet-btn.ghost {
  border-color: transparent;
  background: #f8fafc;
}

.link-embed {
  position: absolute;
  inset: 0;
  z-index: 34;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.link-embed[hidden] {
  display: none;
}

.link-embed-panel {
  width: 80%;
  height: 80%;
  max-width: 960px;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 50px rgba(15, 23, 42, 0.28);
}

.link-embed-bar {
  flex-shrink: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 10px 0 14px;
  border-bottom: 1px solid var(--line);
  background: #f8fafc;
}

.link-embed-host {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 600;
  color: #334155;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.link-embed-actions {
  display: flex;
  gap: 4px;
}

.link-embed-icon {
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: #64748b;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.link-embed-icon:hover {
  background: #e2e8f0;
  color: #0f172a;
}

.link-embed-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

.link-embed-fallback {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 24px;
  color: #64748b;
  font-size: 14px;
  text-align: center;
}

.link-embed-fallback[hidden] {
  display: none !important;
}

.link-embed-fallback .link-sheet-btn {
  min-width: 180px;
}

.app-hidden {
  display: none !important;
}

.auth-gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(180deg, #e8edf5 0%, #f3f5f8 100%);
}

.auth-gate.hidden {
  display: none;
}

.auth-card {
  width: min(100%, 360px);
  background: #fff;
  border-radius: 20px;
  padding: 22px 20px 18px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.12);
}

.auth-brand {
  text-align: center;
  margin-bottom: 16px;
}

.auth-brand .brand-icon {
  margin: 0 auto 10px;
}

.auth-brand h2 {
  margin: 0;
  font-size: 20px;
}

.auth-brand p {
  margin: 6px 0 0;
  color: #94a3b8;
  font-size: 13px;
}

.auth-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #475569;
}

.auth-field input {
  border: 1px solid #dbe3ee;
  border-radius: 10px;
  padding: 11px 12px;
  outline: none;
}

.auth-field input:focus {
  border-color: #93c5fd;
}

.auth-error {
  margin: 10px 0 0;
  padding: 8px 10px;
  border-radius: 10px;
  background: #fef2f2;
  color: #b91c1c;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
}

.auth-error[hidden] {
  display: none !important;
}

.auth-field.invalid input {
  border-color: #fca5a5;
  background: #fff7f7;
}

.auth-submit {
  width: 100%;
  border: none;
  border-radius: 12px;
  padding: 12px;
  background: #5b4dff;
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}

.auth-submit:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.auth-tip {
  margin-top: 10px;
  text-align: center;
  font-size: 12px;
  color: #94a3b8;
}
