html, body.chat-page { height: 100%; overflow: hidden; }

.chat-page { background: var(--chat-bg); }

.app-shell { display: flex; height: 100vh; overflow: hidden; }


.chat-sidebar {
  width: 268px; flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column;
  transition: margin-left .2s cubic-bezier(0.4,0,0.2,1);
}

.sidebar-top { display: flex; align-items: center; gap: 8px; padding: 14px 12px 8px; }
.sidebar-brand { display: flex; align-items: center; gap: 9px; text-decoration: none; flex: 1; min-width: 0; }
.sidebar-brand-mark { width: 30px; height: 30px; border-radius: 9px; object-fit: cover; flex-shrink: 0; display: block; }
.sidebar-brand-text { font-family: 'Fraunces', serif; font-weight: 700; font-size: 1.02rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-close-btn { display: none; }

.btn-new-chat-full {
  display: flex; align-items: center; gap: 8px;
  margin: 6px 12px 10px; padding: 9px 12px;
  border-radius: 10px; border: 1.5px solid var(--sidebar-border);
  background: var(--bg-card); color: var(--text);
  font-family: 'DM Sans', sans-serif; font-size: .84rem; font-weight: 600;
  cursor: pointer; transition: var(--transition);
}
.btn-new-chat-full:hover { border-color: var(--navy); color: var(--navy); }

.sidebar-conversations { flex: 1; overflow-y: auto; padding: 4px 8px 12px; }
.conv-group-label {
  font-family: 'DM Mono', monospace; font-size: .62rem; letter-spacing: .1em;
  text-transform: uppercase; color: var(--text-3);
  padding: 12px 8px 5px;
}
.conv-item {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 8px 8px; border-radius: 8px; margin-bottom: 1px;
  cursor: pointer; transition: background .12s;
}
.conv-item:hover { background: var(--sidebar-hover); }
.conv-item.active { background: var(--navy-pale); }
.conv-item.active .conv-title { color: var(--navy-dark); font-weight: 600; }
.conv-title {
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: .82rem; color: var(--text-2);
  border: none; background: none; outline: none; font-family: inherit; padding: 0;
}
.conv-title[contenteditable="true"] {
  white-space: normal; overflow: visible; text-overflow: clip;
  color: var(--text); cursor: text;
}
.conv-actions { display: none; align-items: center; gap: 2px; flex-shrink: 0; }
.conv-item:hover .conv-actions { display: flex; }
.conv-action-btn {
  width: 22px; height: 22px; border-radius: 5px; border: none; background: none;
  color: var(--text-3); cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.conv-action-btn:hover { background: var(--white); color: var(--text); }
.conv-action-btn.danger:hover { background: var(--red-bg); color: var(--crimson); }

.sidebar-empty { padding: 18px 10px; font-size: .78rem; color: var(--text-3); line-height: 1.6; text-align: center; }

.sidebar-bottom { border-top: 1px solid var(--sidebar-border); padding: 8px; position: relative; }
.sidebar-secondary-link {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 8px; border-radius: 8px;
  color: var(--text-3); font-size: .78rem; font-weight: 500;
  text-decoration: none; transition: background .12s;
  margin-bottom: 2px;
}
.sidebar-secondary-link:hover { background: var(--sidebar-hover); color: var(--text); }

.profile-chip {
  width: 100%; display: flex; align-items: center; gap: 9px;
  padding: 7px 8px; border-radius: 8px; border: none;
  background: none; cursor: pointer; transition: background .12s;
  text-align: left;
}
.profile-chip:hover { background: var(--sidebar-hover); }
.profile-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  background: var(--navy); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-family: 'DM Sans', sans-serif; font-weight: 700; font-size: .72rem;
  object-fit: cover; overflow: hidden;
}
.profile-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-size: .8rem; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-sub { font-size: .68rem; color: var(--text-3); }
.profile-chevron { color: var(--text-3); flex-shrink: 0; transition: transform .15s; }
.profile-chip[aria-expanded="true"] .profile-chevron { transform: rotate(180deg); }

.profile-menu {
  position: absolute; bottom: calc(100% + 6px); left: 8px; right: 8px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-lg);
  padding: 6px; display: none; flex-direction: column; z-index: 60;
}
.profile-menu.open { display: flex; }
.profile-menu-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 9px; border-radius: 7px; border: none; background: none;
  color: var(--text-2); font-size: .82rem; font-weight: 500;
  cursor: pointer; text-align: left; width: 100%;
  font-family: 'DM Sans', sans-serif; transition: background .12s;
}
.profile-menu-item:hover { background: var(--surface); color: var(--text); }
.profile-menu-item.danger:hover { background: var(--red-bg); color: var(--crimson); }

.sidebar-overlay-bg {
  display: none; position: fixed; inset: 0;
  background: rgba(30,26,18,.45); z-index: 55;
}
.sidebar-overlay-bg.open { display: block; }


.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100vh; background: var(--chat-bg); }

.chat-topbar {
  flex-shrink: 0; height: 56px;
  display: flex; align-items: center; gap: 10px;
  padding: 0 18px; border-bottom: 1px solid var(--border);
  background: var(--chat-bg);
}
.sidebar-open-btn { display: none; }
.chat-title-wrap { flex: 1; min-width: 0; }
.chat-title {
  font-family: 'Fraunces', serif; font-size: .98rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  outline: none; cursor: text; border-radius: 5px; padding: 3px 6px; margin: -3px -6px;
}
.chat-title:hover, .chat-title:focus { background: var(--surface); }
.chat-topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.chat-scroll { flex: 1; overflow-y: auto; }
.chat-column { max-width: var(--chat-max-w); margin: 0 auto; padding: 24px 20px 12px; min-height: 100%; display: flex; flex-direction: column; }

.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 40px 12px;
}
.chat-empty-mark { width: 56px; height: 56px; border-radius: 50%; margin-bottom: 18px; object-fit: cover; }
.chat-empty h1 { font-family: 'Fraunces', serif; font-size: 1.55rem; font-weight: 700; color: var(--text); margin-bottom: 8px; }
.chat-empty p { font-size: .88rem; color: var(--text-3); max-width: 420px; line-height: 1.6; margin-bottom: 28px; }

.prompt-chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; max-width: 560px; }
.prompt-chip {
  padding: 9px 14px; border-radius: 999px;
  border: 1.5px solid var(--border); background: var(--bg-card);
  color: var(--text-2); font-size: .8rem; font-weight: 500;
  cursor: pointer; transition: var(--transition); text-align: left;
}
.prompt-chip:hover { border-color: var(--navy); color: var(--navy); }

.msg-row { display: flex; margin-bottom: 22px; gap: 12px; }
.msg-row.msg-user { justify-content: flex-end; }
.msg-row.msg-assistant { justify-content: flex-start; }

.msg-avatar {
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  object-fit: cover; margin-top: 2px;
}

.msg-user .msg-bubble {
  background: var(--bubble-user-bg); color: var(--bubble-user-text);
  padding: 10px 15px; border-radius: 16px 16px 3px 16px;
  max-width: 75%; font-size: .9rem; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word;
}

.msg-assistant-body { max-width: calc(100% - 38px); min-width: 0; }
.msg-assistant .msg-bubble {
  font-size: .9rem; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.msg-assistant .msg-bubble p { margin-bottom: 10px; }
.msg-assistant .msg-bubble p:last-child { margin-bottom: 0; }
.msg-assistant .msg-bubble strong { font-weight: 700; }

.msg-citations { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.citation-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card);
  color: var(--text-2); font-size: .74rem; font-weight: 500;
  text-decoration: none; transition: var(--transition); max-width: 260px;
}
.citation-chip:hover { border-color: var(--navy); color: var(--navy); }
.citation-chip .cc-num {
  width: 15px; height: 15px; border-radius: 4px; flex-shrink: 0;
  background: var(--navy-pale); color: var(--navy-dark);
  font-family: 'DM Mono', monospace; font-size: .62rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.citation-chip .cc-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.citation-chip-superseded { border-color: rgba(166,106,30,.35); }
.cc-superseded {
  display: inline-flex; align-items: center; gap: 3px;
  color: var(--amber); font-size: .68rem; font-weight: 600;
  white-space: nowrap;
}
a.inline-citation-superseded, span.inline-citation-superseded {
  background: var(--amber-bg); color: var(--amber);
}
a.inline-citation-superseded:hover { background: var(--amber); color: #fff; }
.resource-card-superseded {
  display: flex; align-items: center; gap: 5px;
  margin-top: 4px; font-size: .7rem; font-weight: 600; color: var(--amber);
}

a.inline-citation, span.inline-citation {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 15px; height: 15px; padding: 0 3px; margin: 0 1px;
  border-radius: 4px; background: var(--navy-pale); color: var(--navy-dark);
  font-family: 'DM Mono', monospace; font-size: .62rem; font-weight: 700;
  text-decoration: none; vertical-align: super; line-height: 1;
  transition: var(--transition);
}
a.inline-citation:hover { background: var(--navy); color: #fff; }

.msg-actions { display: flex; gap: 4px; margin-top: 8px; }
.msg-action-btn {
  width: 26px; height: 26px; border-radius: 6px; border: none; background: none;
  color: var(--text-3); cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.msg-action-btn:hover { background: var(--surface); color: var(--text); }

.tester-only { display: none; }
html.is-tester .tester-only { display: flex; }

.admin-only { display: none; }
html.is-admin .admin-only { display: flex; }

.msg-no-info {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 13px; border-radius: var(--radius);
  background: var(--amber-bg); border: 1px solid rgba(166,106,30,.18);
  font-size: .82rem; color: var(--amber); margin-top: 4px;
}

.msg-thinking { display: flex; align-items: center; gap: 8px; padding: 6px 0; }
.msg-thinking-label {
  font-size: .88rem; color: var(--text-3); font-weight: 500;
  background: linear-gradient(90deg, var(--text-3) 0%, var(--text-3) 40%, var(--text) 50%, var(--text-3) 60%, var(--text-3) 100%);
  background-size: 200% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: thinkingShimmer 1.6s linear infinite;
}
@keyframes thinkingShimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.msg-typing { display: flex; gap: 4px; }
.msg-typing span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--text-3);
  animation: typingBounce 1.1s infinite ease-in-out;
}
.msg-typing span:nth-child(2) { animation-delay: .15s; }
.msg-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); opacity:.4; } 30% { transform: translateY(-4px); opacity:1; } }

.skip-thinking-btn {
  display: inline-flex; align-items: center;
  margin-top: 10px; padding: 6px 13px;
  border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--bg-card); color: var(--text-2);
  font-family: 'DM Sans', sans-serif; font-size: .78rem; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.skip-thinking-btn:hover:not(:disabled) { border-color: var(--navy); color: var(--navy); }
.skip-thinking-btn:disabled { opacity: .6; cursor: default; }

.msg-fast-note {
  display: flex; align-items: center; gap: 5px;
  font-size: .7rem; color: var(--text-3); margin-bottom: 6px;
}

.tw-word { opacity: 0; transition: opacity .12s ease-out; }
.tw-word.visible { opacity: 1; }
.msg-assistant-body.pending-reveal .msg-citations,
.msg-assistant-body.pending-reveal .msg-no-info,
.msg-assistant-body.pending-reveal .msg-actions { display: none; }

.composer-wrap {
  flex-shrink: 0; padding: 8px 20px 14px;
  background: linear-gradient(0deg, var(--chat-bg) 55%, transparent);
}
.composer-inner { max-width: var(--chat-max-w); margin: 0 auto; }
.composer-box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--composer-bg); border: 1.5px solid var(--composer-border);
  border-radius: 20px; padding: 8px 8px 8px 16px;
  box-shadow: var(--shadow-sm); transition: var(--transition);
}
.composer-box:focus-within { border-color: var(--navy); box-shadow: 0 0 0 3px rgba(0,163,228,.12); }
.composer-textarea {
  flex: 1; border: none; outline: none; background: none; resize: none;
  font-family: 'DM Sans', sans-serif; font-size: .9rem; color: var(--text);
  line-height: 1.5; max-height: 160px; padding: 6px 0;
}
.composer-textarea::placeholder { color: var(--text-3); }
.composer-send {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: var(--navy); color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.composer-send:hover:not(:disabled) { background: var(--navy-dark); }
.composer-send:disabled { opacity: .4; cursor: not-allowed; }

.composer-disclaimer {
  text-align: center; font-size: .7rem; color: var(--text-3);
  margin-top: 10px; line-height: 1.5;
}
.composer-disclaimer .sb-mark {
  font-family: 'DM Mono', monospace; letter-spacing: .04em;
}


.resources-panel {
  width: 300px; flex-shrink: 0;
  background: var(--resources-bg);
  border-left: 1px solid var(--sidebar-border);
  display: flex; flex-direction: column;
}
.resources-header {
  flex-shrink: 0; height: 56px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--sidebar-border);
}
.resources-header span { font-family: 'Fraunces', serif; font-weight: 600; font-size: .92rem; color: var(--text); }
.resources-close-btn { display: none; }
.resources-list { flex: 1; overflow-y: auto; padding: 14px; }
.resources-empty { padding: 24px 8px; text-align: center; color: var(--text-3); font-size: .8rem; line-height: 1.6; }
.resource-card {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 11px 13px; border-radius: 10px;
  background: var(--bg-card); border: 1px solid var(--border);
  margin-bottom: 9px; text-decoration: none; transition: var(--transition);
  position: relative;
}
.resource-card:hover { border-color: var(--navy); box-shadow: var(--shadow-sm); }
.resource-card-icon {
  width: 30px; height: 30px; border-radius: 8px; flex-shrink: 0;
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.resource-card-icon svg { display: block; }
.resource-card-body { flex: 1; min-width: 0; padding-right: 18px; }
.resource-card-title {
  font-size: .82rem; font-weight: 600; color: var(--text); line-height: 1.4; margin-bottom: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.resource-card-meta-line {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
  font-size: .72rem; color: var(--text-3); margin-bottom: 6px;
}
.resource-card-dot { opacity: .6; }
.resource-card-num {
  position: absolute; top: 10px; right: 10px;
  display: flex; align-items: center; justify-content: center;
  width: 16px; height: 16px; border-radius: 5px;
  background: var(--navy-pale); color: var(--navy-dark);
  font-family: 'DM Mono', monospace; font-size: .6rem; font-weight: 600;
}


@media (max-width: 1200px) {
  .resources-panel {
    position: fixed; top: 0; right: 0; bottom: 0; z-index: 65;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%); transition: transform .2s cubic-bezier(0.4,0,0.2,1);
  }
  .resources-panel.open { transform: translateX(0); }
  .resources-close-btn { display: flex; }
}

@media (max-width: 960px) {
  .chat-sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 65; width: 280px;
    transform: translateX(-100%); transition: transform .2s cubic-bezier(0.4,0,0.2,1);
  }
  .chat-sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }
  .sidebar-open-btn { display: flex; }
}

@media (max-width: 640px) {
  .chat-column { padding: 16px 14px 8px; }
  .composer-wrap { padding: 6px 12px 12px; }
  .msg-user .msg-bubble, .msg-assistant-body { max-width: 88%; }
  .chat-title { font-size: .88rem; }
  .resources-panel { width: 100%; }
}


.appearance-section { margin-bottom: 22px; }
.appearance-section:last-child { margin-bottom: 0; }
.appearance-label {
  font-size: .75rem; font-weight: 600; color: var(--text-2);
  margin-bottom: 10px; letter-spacing: .02em;
}

.mode-switch { display: flex; gap: 8px; }
.mode-switch-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 10px 12px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--white);
  color: var(--text-2); font-family: 'DM Sans', sans-serif; font-size: .84rem; font-weight: 500;
  cursor: pointer; transition: var(--transition);
}
.mode-switch-btn:hover { border-color: var(--navy-light); color: var(--text); }
.mode-switch-btn.active {
  border-color: var(--navy); background: var(--navy-pale); color: var(--navy-dark);
}

.palette-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.palette-swatch {
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 6px; border-radius: var(--radius);
  border: 1.5px solid var(--border); background: var(--white);
  cursor: pointer; transition: var(--transition);
}
.palette-swatch:hover { border-color: var(--navy-light); }
.palette-swatch.active { border-color: var(--navy); background: var(--navy-pale); }
.palette-swatch-color {
  width: 28px; height: 28px; border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.5), 0 1px 3px rgba(0,0,0,.15);
}
.palette-swatch-label { font-size: .72rem; font-weight: 500; color: var(--text-2); }
.palette-swatch.active .palette-swatch-label { color: var(--navy-dark); font-weight: 600; }

@media (max-width: 480px) {
  .palette-grid { grid-template-columns: repeat(2, 1fr); }
}

.share-page {
  min-height: 100vh; display: flex; align-items: flex-start; justify-content: center;
  background: var(--chat-bg); padding: 60px 20px;
}
.share-card {
  width: 100%; max-width: 640px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  padding: 32px 28px;
}
.share-header { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.share-badge { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.share-brand { font-family: 'Fraunces', serif; font-weight: 700; font-size: 1rem; color: var(--text); }
.share-sub { font-size: .74rem; color: var(--text-3); }
.share-question {
  font-size: .84rem; font-weight: 600; color: var(--text-2);
  padding: 12px 14px; border-left: 3px solid var(--navy); border-radius: 0 8px 8px 0;
  background: var(--surface); margin-bottom: 18px; line-height: 1.5;
}
.share-footer { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); text-align: center; }
.share-footer p { font-size: .72rem; color: var(--text-3); line-height: 1.6; margin-bottom: 16px; }
.share-footer .sb-mark { font-family: 'DM Mono', monospace; letter-spacing: .04em; }

@media (max-width: 640px) {
  .share-page { padding: 30px 14px; }
  .share-card { padding: 22px 18px; }
}
