[hidden] { display: none !important; }
:root {
  --ink: #142033;
  --muted: #6d7789;
  --accent: #1677ff;
  --accent-strong: #075fd7;
  --surface: rgba(255, 255, 255, 0.72);
  --surface-solid: #ffffff;
  --line: rgba(20, 32, 51, 0.1);
  --shadow: 0 24px 70px rgba(56, 83, 122, 0.14);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", "Cambria Math", "Segoe UI Symbol", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(160deg, #f9fbff 0%, #eef5ff 48%, #f8f7ff 100%);
  -webkit-font-smoothing: antialiased;
}
button, textarea, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }

.ambient {
  position: fixed;
  width: 420px;
  height: 420px;
  border-radius: 50%;
  filter: blur(90px);
  opacity: .3;
  pointer-events: none;
  z-index: -1;
}
.ambient-one { top: -160px; left: -100px; background: #b8d8ff; }
.ambient-two { right: -170px; bottom: -180px; background: #d9caff; }
.glass {
  background: var(--surface);
  border: 1px solid rgba(255, 255, 255, .78);
  box-shadow: var(--shadow);
  backdrop-filter: blur(24px) saturate(145%);
  -webkit-backdrop-filter: blur(24px) saturate(145%);
}
.app-shell { width: min(1120px, calc(100% - 32px)); margin: 0 auto; }
.topbar {
  position: sticky;
  top: 16px;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 74px;
  padding: 0 22px;
  margin: 16px 0 22px;
  border-radius: 24px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  color: white;
  font-size: 20px;
  font-weight: 700;
  border-radius: 14px;
  background: linear-gradient(145deg, #2988ff, #075ed2);
  box-shadow: 0 10px 26px rgba(22, 119, 255, .28);
}
.brand strong, .brand small { display: block; }
.brand strong { font-size: 18px; letter-spacing: .04em; }
.brand small { color: var(--muted); font-size: 10px; letter-spacing: .12em; text-transform: uppercase; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  color: var(--muted);
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.55);
}
.status-pill i, .loading-state i { width: 8px; height: 8px; border-radius: 50%; background: #ffb020; box-shadow: 0 0 0 4px rgba(255,176,32,.13); }
.status-pill.ok i { background: #20b26b; box-shadow: 0 0 0 4px rgba(32,178,107,.13); }
.status-pill.error i { background: #ff4d5e; box-shadow: 0 0 0 4px rgba(255,77,94,.13); }
.icon-link {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255,255,255,.62);
}
.icon-link svg, .drop-zone svg, .composer #send-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.text-link { color: var(--accent); font-size: 14px; font-weight: 600; }

.chat-layout { display: flex; min-height: calc(100vh - 140px); flex-direction: column; padding: 20px 0 132px; }
.welcome { width: min(760px, 100%); margin: 5vh auto 32px; text-align: center; transition: .3s ease; }
.welcome.compact { margin-top: 8px; transform: scale(.96); opacity: .62; }
.welcome-badge, .eyebrow { color: var(--accent); font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; }
.welcome h1 { margin: 18px 0 14px; font-size: clamp(38px, 6vw, 66px); line-height: 1.06; letter-spacing: -.045em; }
.welcome p { max-width: 620px; margin: 0 auto; color: var(--muted); font-size: 17px; line-height: 1.8; }
.suggestions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 28px; }
.suggestions button, .ghost-button {
  padding: 11px 16px;
  color: #33445e;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255,255,255,.7);
  cursor: pointer;
  transition: transform .2s, border-color .2s, color .2s;
}
.suggestions button:hover, .ghost-button:hover { transform: translateY(-2px); color: var(--accent); border-color: rgba(22,119,255,.32); }

.conversation { width: min(860px, 100%); margin: 0 auto; }
.message { display: flex; gap: 14px; margin: 28px 0; animation: rise .36s ease both; }
.message.user { flex-direction: row-reverse; }
.message-avatar { flex: 0 0 38px; width: 38px; height: 38px; border-radius: 13px; background: linear-gradient(145deg,#2c8cff,#0b63dc); box-shadow: 0 8px 22px rgba(22,119,255,.22); }
.message.user .message-avatar { background: linear-gradient(145deg,#aeb9cc,#7c899f); }
.message-body { max-width: min(740px, calc(100% - 54px)); }
.message.user .message-body { display: flex; justify-content: flex-end; }
.message-content {
  padding: 16px 20px;
  line-height: 1.8;
  white-space: pre-wrap;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 8px 22px 22px 22px;
  background: rgba(255,255,255,.78);
  box-shadow: 0 14px 45px rgba(56,83,122,.1);
}
.message.user .message-content { color: white; border-radius: 22px 8px 22px 22px; background: linear-gradient(145deg,#2584ff,#0864de); }
.message.pending .message-content::after { content:""; display:inline-block; width:16px; height:8px; margin-left:6px; background:radial-gradient(circle,var(--muted) 2px,transparent 2.5px) 0 0/8px 8px repeat-x; animation:pulse .9s infinite; }
.citation-list { display: grid; gap: 10px; margin-top: 12px; }
.citation-card {
  display: block;
  padding: 14px 16px;
  border: 1px solid rgba(22,119,255,.14);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  background: rgba(255,255,255,.66);
  transition: .2s ease;
}
.citation-card:hover { transform: translateY(-2px); background: white; box-shadow: 0 12px 28px rgba(56,83,122,.12); }
.citation-card strong { display: block; margin-bottom: 5px; font-size: 14px; }
.citation-card span { display: -webkit-box; overflow: hidden; color: var(--muted); font-size: 13px; line-height: 1.55; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.citation-sup { color: var(--accent); font-size: .72em; font-weight: 700; vertical-align: super; margin-left: 1px; }

.composer {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 30;
  display: grid;
  width: min(860px, calc(100% - 32px));
  padding: 10px 11px 8px 18px;
  border-radius: 24px;
  transform: translateX(-50%);
}
.composer textarea { width: 100%; max-height: 140px; padding: 8px 50px 8px 0; color: var(--ink); border: 0; outline: 0; resize: none; background: transparent; font-size: 16px; line-height: 1.6; }
.composer #send-button { position: absolute; right: 11px; bottom: 30px; display: grid; place-items: center; width: 42px; height: 42px; color: white; border: 0; border-radius: 14px; background: linear-gradient(145deg,#2788ff,#0960d5); cursor: pointer; }
.composer #send-button:disabled { opacity: .45; cursor: wait; }
.composer-hint { grid-column: 1/-1; margin: 0 0 4px; color: #8b95a5; font-size: 11px; }

.manage-layout { display: grid; grid-template-columns: minmax(280px, .78fr) minmax(420px, 1.45fr); gap: 22px; padding-bottom: 46px; }
.panel { padding: 28px; border-radius: var(--radius-xl); }
.upload-panel h1 { margin: 10px 0; font-size: 34px; letter-spacing: -.035em; }
.upload-panel p, .panel-heading p { color: var(--muted); line-height: 1.7; }
.drop-zone { display: grid; place-items: center; gap: 8px; min-height: 230px; margin-top: 26px; padding: 28px; color: var(--accent); text-align: center; border: 1.5px dashed rgba(22,119,255,.34); border-radius: 22px; background: rgba(236,245,255,.7); cursor: pointer; transition: .2s; }
.drop-zone:hover, .drop-zone.dragging { border-color: var(--accent); background: rgba(225,239,255,.95); transform: scale(1.01); }
.drop-zone svg { width: 36px; }
.drop-zone strong { font-size: 17px; }
.drop-zone span { color: var(--muted); font-size: 13px; }
.upload-progress { display: flex; align-items: center; gap: 10px; margin-top: 18px; color: var(--muted); font-size: 13px; }
.upload-progress i, .loading-state i { display:block; width:18px; height:18px; border:2px solid #cfe3ff; border-top-color:var(--accent); border-radius:50%; background:none; animation:spin .8s linear infinite; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.panel-heading h2 { margin: 8px 0 0; font-size: 25px; }
.document-list { display: grid; gap: 12px; }
.document-card { display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center; padding: 16px; border: 1px solid var(--line); border-radius: 18px; background: rgba(255,255,255,.66); }
.file-icon { display: grid; place-items: center; width: 48px; height: 48px; color: var(--accent); font-size: 11px; font-weight: 800; border-radius: 15px; background: #eaf3ff; text-transform: uppercase; }
.document-meta { min-width: 0; }
.document-meta strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.document-meta span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; }
.document-actions { display: flex; gap: 7px; }
.document-actions button { padding: 8px 11px; border: 1px solid var(--line); border-radius: 11px; background: white; cursor: pointer; }
.document-actions .danger { color: #d92d42; }
.status-tag { display: inline-flex; padding: 3px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eef1f5; }
.status-tag.ready { color: #087d49; background: #e5f8ee; }
.status-tag.failed { color: #bd2336; background: #ffeaed; }
.status-tag.indexing, .status-tag.parsing, .status-tag.updating { color: #9a6400; background: #fff3d6; }
.empty-state { padding: 60px 20px; color: var(--muted); text-align: center; }

body.viewer-page { overflow: hidden; }
.viewer-topbar { position: sticky; top: 0; z-index: 10; display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 12px; height: 70px; padding: 0 20px; border-radius: 0 0 20px 20px; }
.viewer-title { min-width: 0; text-align: center; }
.viewer-title strong, .viewer-title span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-title span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.viewer-layout { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 18px; height: calc(100vh - 88px); padding: 18px 20px; }
.quote-card { overflow: auto; padding: 22px; border-radius: 24px; }
blockquote { margin: 14px 0; padding: 16px; font-size: 15px; line-height: 1.8; border-left: 3px solid var(--accent); border-radius: 0 14px 14px 0; background: #eef5ff; }
.quote-card p { color: var(--muted); font-size: 13px; line-height: 1.7; }
.document-stage { position: relative; overflow: auto; border-radius: 24px; }
.loading-state { display: flex; align-items: center; justify-content: center; gap: 10px; height: 100%; color: var(--muted); }
.pdf-stage { min-width: 100%; padding: 28px; text-align: center; }
.pdf-fallback { display:block; width:100%; height:100%; min-height:70vh; border:0; border-radius:20px; background:white; }
.pdf-page-wrap { position: relative; display: inline-block; box-shadow: 0 14px 44px rgba(23,38,61,.16); background: white; }
.pdf-page-wrap canvas { display: block; max-width: 100%; }
.textLayer { position: absolute; inset: 0; overflow: hidden; line-height: 1; opacity: .78; }
.textLayer span { position: absolute; color: transparent; white-space: pre; transform-origin: 0 0; cursor: text; }
.textLayer span::selection { background: rgba(22,119,255,.25); }
.textLayer span.hit, .textLayer span.hit-fragment { color: transparent; border-radius: 3px; background: rgba(255,214,66,.72); box-shadow: 0 0 0 2px rgba(255,214,66,.72); }
.source-html { padding: 34px clamp(24px, 5vw, 72px); font-size: 16px; line-height: 1.9; }
.source-block { margin: 9px 0; padding: 10px 14px; border-radius: 12px; transition: .4s; }
.source-heading { margin-top: 26px; font-size: 22px; font-weight: 750; }
.source-target, .source-block:target { background: #fff0a8; box-shadow: 0 0 0 4px #fff0a8; }
.table-view { padding: 28px; }
.table-view h3 { margin: 20px 4px 10px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; overflow: hidden; font-size: 14px; border: 1px solid var(--line); border-radius: 15px; background: white; }
.data-table th, .data-table td { padding: 11px 13px; text-align: left; border-bottom: 1px solid var(--line); }
.data-table tr.target-row td { background: #fff0a8; font-weight: 700; }
.error-box { margin: 40px auto; max-width: 520px; padding: 24px; color: #b42339; text-align: center; border: 1px solid #ffcbd2; border-radius: 18px; background: #fff4f6; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .35; } }
@media (max-width: 800px) {
  .app-shell { width: min(100% - 20px, 1120px); }
  .topbar { top: 10px; margin-top: 10px; padding: 0 14px; }
  .status-pill { display: none; }
  .welcome { margin-top: 3vh; }
  .welcome h1 { font-size: 42px; }
  .manage-layout, .viewer-layout { grid-template-columns: 1fr; height: auto; }
  .viewer-layout { padding: 12px; }
  .quote-card { max-height: 32vh; }
  .document-stage { min-height: 55vh; }
  .document-card { grid-template-columns: 44px 1fr; }
  .document-actions { grid-column: 1/-1; justify-content: flex-end; }
}


.auth-shell { display:grid; grid-template-columns:1.1fr minmax(360px,.75fr); gap:48px; align-items:center; width:min(1120px,calc(100% - 32px)); min-height:100vh; margin:0 auto; padding:40px 0; }
.auth-hero h1 { margin:26px 0 16px; font-size:clamp(38px,5vw,64px); line-height:1.08; letter-spacing:-.045em; }
.auth-hero p { max-width:580px; color:var(--muted); font-size:17px; line-height:1.8; }
.auth-panel { padding:28px; border-radius:28px; }
.auth-tabs { display:grid; grid-template-columns:1fr 1fr; gap:6px; padding:5px; margin-bottom:24px; border-radius:15px; background:rgba(20,32,51,.06); }
.auth-tabs button { padding:10px; color:var(--muted); border:0; border-radius:11px; background:transparent; cursor:pointer; }
.auth-tabs button.active { color:var(--ink); background:white; box-shadow:0 5px 16px rgba(56,83,122,.12); }
.auth-form,.stack-form { display:grid; gap:16px; }
.auth-form label,.stack-form label { display:grid; gap:7px; color:var(--muted); font-size:13px; }
.auth-form input,.stack-form input,.inline-form input { width:100%; padding:12px 14px; color:var(--ink); border:1px solid var(--line); border-radius:13px; background:rgba(255,255,255,.84); outline:none; }
.auth-form input:focus,.stack-form input:focus,.inline-form input:focus { border-color:rgba(22,119,255,.5); box-shadow:0 0 0 4px rgba(22,119,255,.1); }
.primary-button { padding:12px 18px; color:white; font-weight:700; border:0; border-radius:13px; background:linear-gradient(145deg,#2788ff,#0960d5); box-shadow:0 10px 24px rgba(22,119,255,.22); cursor:pointer; }
.text-button { color:var(--muted); border:0; background:none; cursor:pointer; }
.small-button { display:inline-flex; justify-content:center; padding:10px 14px; color:var(--accent); border:1px solid rgba(22,119,255,.22); border-radius:12px; background:rgba(236,245,255,.8); cursor:pointer; }
.auth-message,.form-message { min-height:20px; margin:14px 0 0; color:var(--muted); font-size:13px; }
.user-chip { display:inline-flex; align-items:center; gap:8px; padding:5px 10px 5px 5px; border:1px solid var(--line); border-radius:999px; background:rgba(255,255,255,.68); }
.user-chip img { width:30px; height:30px; border-radius:50%; object-fit:cover; }
.user-chip span { max-width:100px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:13px; }
.user-chip.compact span { display:none; }
.account-layout { display:grid; grid-template-columns:280px 1fr; gap:22px; padding-bottom:48px; }
.profile-card { display:flex; flex-direction:column; align-items:center; align-self:start; padding:28px; text-align:center; }
.profile-avatar { width:132px; height:132px; margin-bottom:16px; border-radius:36px; object-fit:cover; box-shadow:0 14px 36px rgba(56,83,122,.18); }
.muted-copy { margin-top:10px; color:var(--muted); font-size:12px; }
.account-meta { display:grid; gap:12px; width:100%; margin:24px 0 0; padding-top:20px; border-top:1px solid var(--line); text-align:left; }
.account-meta div { display:flex; justify-content:space-between; gap:12px; }
.account-meta dt { color:var(--muted); font-size:12px; }
.account-meta dd { margin:0; font-size:13px; font-weight:650; }
.account-content { display:grid; gap:18px; }
.account-content .panel { padding:24px; border-radius:24px; }
.account-content h2,.admin-layout h2 { margin:8px 0 18px; }
.inline-form { display:flex; gap:10px; }
.password-grid { display:grid; grid-template-columns:1fr 1fr auto; }
.admin-layout { display:grid; grid-template-columns:minmax(300px,.72fr) 1.28fr; gap:22px; padding-bottom:48px; }
.admin-layout .panel { padding:26px; border-radius:24px; }
.invite-box { display:grid; gap:10px; margin-top:18px; padding:16px; border:1px solid rgba(22,119,255,.2); border-radius:15px; background:#eef5ff; }
.invite-box strong { padding:10px; font-family:ui-monospace,monospace; font-size:14px; word-break:break-all; border-radius:10px; background:white; }
.compact-list { display:grid; gap:9px; }
.compact-row { display:grid; grid-template-columns:auto 1fr auto; align-items:center; gap:12px; padding:13px 14px; border:1px solid var(--line); border-radius:14px; background:rgba(255,255,255,.6); }
.compact-row > div:first-child { min-width:0; }
.compact-row strong,.compact-row span { display:block; }
.compact-row strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-size:14px; }
.compact-row span { margin-top:3px; color:var(--muted); font-size:12px; line-height:1.45; }
.compact-row time { color:var(--muted); font-size:11px; white-space:nowrap; }
.compact-row img { width:38px; height:38px; border-radius:50%; object-fit:cover; }
.empty-compact { padding:25px; color:var(--muted); text-align:center; font-size:13px; }
.row-actions { display:flex; gap:7px; }
.row-actions button { padding:7px 9px; border:1px solid var(--line); border-radius:9px; background:white; cursor:pointer; }
.status-tag.active { color:#087d49; background:#e5f8ee; }
.status-tag.pending { color:#9a6400; background:#fff3d6; }
.status-tag.disabled { color:#6d7789; background:#eef1f5; }
@media (max-width:820px) {
  .auth-shell,.account-layout,.admin-layout { grid-template-columns:1fr; }
  .auth-hero { text-align:center; }
  .auth-hero .brand { justify-content:center; }
  .inline-form,.password-grid { grid-template-columns:1fr; display:grid; }
  .compact-row { grid-template-columns:auto 1fr; }
  .compact-row .row-actions,.compact-row time { grid-column:1/-1; justify-content:flex-end; }
}


.message-avatar.has-image { background: transparent; box-shadow: none; }
.message-avatar img { display:block; width:100%; height:100%; border-radius:inherit; object-fit:cover; }
.history-content { min-width:0; }
.history-citations { display:flex; flex-wrap:wrap; gap:7px; margin-top:9px; }
.history-citation { padding:5px 8px; color:var(--accent); font-size:11px; border:1px solid rgba(22,119,255,.18); border-radius:8px; background:#eef5ff; }

.panel-heading-actions { display:flex; align-items:center; gap:14px; }
