/* ═══════════════════════════════════════════════════════════════
   Claude AI Harness — Dual Theme: Day (warm parchment) / Night (ink)
   Toggle via data-theme="light|dark" on <html>
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Newsreader:ital,opsz,wght@0,6..72,400;0,6..72,500;0,6..72,700;1,6..72,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&display=swap');

/* ─── Light Theme (Day) ─── */
:root,
[data-theme="light"] {
  --bg: #f4efe7;
  --sidebar: #ebe4d9;
  --paper: #fffbf4;
  --panel: #f9f5ed;
  --surface: #ffffff;
  --ink: #2a2118;
  --muted: #6d6054;
  --faint: #9c9083;
  --line: rgba(42, 33, 24, 0.09);
  --accent: #c05a32;
  --accent-glow: rgba(192, 90, 50, 0.1);
  --accent-dark: #96432a;
  --shadow: 0 14px 40px rgba(42, 33, 24, 0.1);
  --shadow-sm: 0 3px 10px rgba(42, 33, 24, 0.06);
  --user-bubble: #ebe3d5;
  --user-bubble-border: rgba(42, 33, 24, 0.06);
  --code-bg: #f0e8dc;
  --code-panel-bg: #1e1a16;
  --code-panel-text: #f0e8dc;
  --scrollbar: rgba(42, 33, 24, 0.12);
  color-scheme: light;
}

/* ─── Dark Theme (Night) ─── */
[data-theme="dark"] {
  --bg: #1a1512;
  --sidebar: #15120f;
  --paper: #221e19;
  --panel: #1e1a15;
  --surface: #2a2520;
  --ink: #e8dfd2;
  --muted: #998b7a;
  --faint: #6b5f52;
  --line: rgba(232, 223, 210, 0.08);
  --accent: #d4885c;
  --accent-glow: rgba(212, 136, 92, 0.15);
  --accent-dark: #b86d42;
  --shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
  --shadow-sm: 0 4px 12px rgba(0, 0, 0, 0.2);
  --user-bubble: rgba(212, 136, 92, 0.12);
  --user-bubble-border: rgba(212, 136, 92, 0.15);
  --code-bg: rgba(232, 223, 210, 0.06);
  --code-panel-bg: #0e0c0a;
  --code-panel-text: #c9bfb2;
  --scrollbar: rgba(232, 223, 210, 0.08);
  color-scheme: dark;
}

/* ─── Shared Variables ─── */
:root {
  --radius: 12px;
  --font-display: "Newsreader", Georgia, "Times New Roman", serif;
  --font-body: "DM Sans", ui-sans-serif, system-ui, -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

/* ═══════════════════════════════════════════════════════════════
   Base Reset
   ═══════════════════════════════════════════════════════════════ */

* {
  box-sizing: border-box;
  letter-spacing: 0;
}

html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.3s ease, color 0.2s ease;
}

/* Subtle grain texture (dark mode only) */
[data-theme="dark"] body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  opacity: 0.022;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.site-footer {
  position: fixed;
  right: 16px;
  bottom: 10px;
  z-index: 50;
  display: flex;
  gap: 14px;
  font-size: 11px;
}

.site-footer span,
.site-footer a {
  color: var(--faint);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--muted);
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* ═══════════════════════════════════════════════════════════════
   Layout Shell
   ═══════════════════════════════════════════════════════════════ */

.app-shell {
  display: grid;
  height: var(--vh, 100dvh);
  min-height: 0;
  grid-template-columns: 272px minmax(0, 1fr);
  background: var(--bg);
  transition: background 0.3s ease;
}

/* ═══════════════════════════════════════════════════════════════
   Sidebar
   ═══════════════════════════════════════════════════════════════ */

.sidebar {
  display: flex;
  min-height: 100dvh;
  min-width: 0;
  flex-direction: column;
  border-right: 1px solid var(--line);
  background: var(--sidebar);
  padding: 14px 10px;
  transition: background 0.3s ease, border-color 0.3s ease;
}

.brand {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 16px;
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

img.brand-logo {
  display: block;
  width: 26px !important;
  height: 26px !important;
  max-width: 26px !important;
  max-height: 26px !important;
  flex: 0 0 auto;
  border-radius: 50%;
  object-fit: contain;
}

[data-theme="dark"] img.brand-logo {
  filter: brightness(0.9);
}

img.brand-logo.large {
  width: 40px !important;
  height: 40px !important;
  max-width: 40px !important;
  max-height: 40px !important;
}

.primary-nav,
.thread-item,
.ghost-button,
.icon-button,
.tool-button,
.starter,
.artifact-tab {
  border: 0;
  color: var(--ink);
}

.primary-nav {
  display: flex;
  min-height: 40px;
  width: 100%;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  background: rgba(128, 128, 128, 0.06);
  border: 1px solid var(--line);
  padding: 10px 12px;
  font-weight: 500;
  text-align: left;
  transition: background 0.15s, border-color 0.15s;
}

.primary-nav:hover,
.ghost-button:hover,
.icon-button:hover,
.tool-button:hover,
.starter:hover {
  background: rgba(128, 128, 128, 0.08);
}

.primary-nav:hover {
  border-color: rgba(128, 128, 128, 0.15);
}

.nav-label {
  margin: 20px 10px 8px;
  color: var(--faint);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.thread-list {
  display: grid;
  align-content: start;
  gap: 2px;
  overflow: auto;
  padding-right: 4px;
}

.thread-list::-webkit-scrollbar {
  width: 4px;
}

.thread-list::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 2px;
}

.thread-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
  width: 100%;
  overflow: hidden;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 8px 10px;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.thread-item:hover {
  background: rgba(128, 128, 128, 0.06);
  color: var(--ink);
}

.thread-item.active {
  background: var(--accent-glow);
  color: var(--ink);
  border: 1px solid rgba(192, 90, 50, 0.12);
}

.thread-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.thread-more-btn {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 2px;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 0 2px;
  color: var(--muted);
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

.thread-item:hover .thread-more-btn {
  display: flex;
}

.thread-more-btn:hover {
  background: rgba(128, 128, 128, 0.12);
  color: var(--ink);
}

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 100;
  min-width: 130px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
  padding: 4px;
  animation: ctx-in 0.14s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes ctx-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.ctx-menu-item {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  padding: 8px 12px;
  font-size: 13px;
  text-align: left;
  cursor: pointer;
  transition: background 0.1s;
}

.ctx-menu-item:hover {
  background: rgba(128, 128, 128, 0.08);
}

.ctx-menu-item.danger {
  color: #d84040;
}

[data-theme="dark"] .ctx-menu-item.danger {
  color: #e06050;
}

.ctx-menu-item.danger:hover {
  background: rgba(216, 64, 64, 0.08);
}

.thread-item.archived {
  opacity: 0.5;
}

.archive-toggle {
  color: var(--faint);
  font-size: 12px;
  margin-top: 8px;
  justify-content: center;
}

.document-list .thread-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px;
  white-space: normal;
  align-items: center;
}

.document-list small {
  color: var(--faint);
  font-size: 11px;
  grid-column: 1;
}

/* ═══════════════════════════════════════════════════════════════
   Workspace
   ═══════════════════════════════════════════════════════════════ */

.workspace {
  display: flex;
  min-width: 0;
  height: 100dvh;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 20px;
  border-bottom: 1px solid var(--line);
}

.model-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  padding: 5px 0;
  font-size: 13px;
  font-weight: 500;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.ghost-button,
.icon-button,
.tool-button {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
  font-size: 13px;
  transition: background 0.12s, color 0.12s;
}

.icon-button,
.tool-button {
  width: 34px;
  padding: 0;
}

#themeToggle {
  font-size: 16px;
  width: 34px;
}

.mobile-only {
  display: none;
}

/* ═══════════════════════════════════════════════════════════════
   Login
   ═══════════════════════════════════════════════════════════════ */

.login-view {
  display: grid;
  flex: 1;
  place-items: center;
  padding: 28px;
}

.login-card {
  width: min(380px, 100%);
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: var(--shadow);
  padding: 32px;
  text-align: center;
}

.login-card h1 {
  margin: 16px 0 8px;
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 500;
}

.login-card p {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 14px;
}

.login-form {
  display: grid;
  gap: 14px;
  text-align: left;
}

.login-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.login-form input:focus,
.composer textarea:focus {
  border-color: rgba(192, 90, 50, 0.4);
}

.submit-button,
.send-button {
  border: 0;
  background: var(--accent);
  color: #fff;
}

[data-theme="dark"] .submit-button,
[data-theme="dark"] .send-button {
  color: #1a1512;
}

.submit-button {
  min-height: 44px;
  border-radius: 10px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
}

.send-button:hover,
.submit-button:hover {
  background: var(--accent-dark);
}

.submit-button:active {
  transform: scale(0.98);
}

.form-error {
  min-height: 18px;
  color: #c03030;
  font-size: 13px;
  text-align: center;
}

.auth-switch {
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

.auth-switch a {
  color: var(--accent);
  text-decoration: none;
  font-weight: 500;
}

.auth-switch a:hover {
  text-decoration: underline;
}

/* Bug report modal */
.bug-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  animation: ctx-in 0.15s ease-out;
}

.bug-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.bug-modal-card {
  position: relative;
  width: min(420px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.bug-modal-card h3 {
  margin: 0 0 4px;
  font-size: 16px;
  font-weight: 600;
}

.bug-modal-card p {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.bug-modal-card textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 13px;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

.bug-modal-card textarea:focus {
  border-color: rgba(192, 90, 50, 0.4);
}

.bug-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 12px;
}

.bug-cancel,
.bug-submit {
  border: 0;
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.12s;
}

.bug-cancel {
  background: transparent;
  color: var(--muted);
}

.bug-cancel:hover {
  background: rgba(128, 128, 128, 0.08);
}

.bug-submit {
  background: var(--accent);
  color: #fff;
}

[data-theme="dark"] .bug-submit {
  color: #1a1512;
}

.bug-submit:hover {
  background: var(--accent-dark);
}

.bug-submit:disabled {
  opacity: 0.6;
  cursor: default;
}

.bug-images {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.bug-image-thumb {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.bug-image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bug-image-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  border-radius: 50%;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  cursor: pointer;
}

.bug-upload-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.bug-upload-btn {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
}

.bug-upload-btn:hover {
  background: rgba(128,128,128,0.06);
}

.bug-upload-hint {
  font-size: 11px;
  color: var(--muted);
}

.bug-modal-card.drag-over {
  border-color: var(--accent);
  background: rgba(192,90,50,0.03);
}

.bug-msg {
  margin-top: 8px;
  font-size: 12px;
  min-height: 16px;
}

#bugReportBtn {
  font-size: 13px;
  width: auto;
  padding: 0 8px;
}

[data-theme="dark"] .form-error {
  color: #e06050;
}

/* ═══════════════════════════════════════════════════════════════
   Chat View Layout
   ═══════════════════════════════════════════════════════════════ */

.chat-view {
  display: grid;
  flex: 1;
  min-height: 0;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 44vw);
  gap: 12px;
  overflow: hidden;
  padding: 0 14px max(14px, calc(env(safe-area-inset-bottom) + 12px));
}

.chat-view.doc-closed {
  grid-template-columns: minmax(0, 1fr);
}

.chat-column {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: minmax(0, 1fr) auto;
  row-gap: 12px;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════
   Hero / Empty State
   ═══════════════════════════════════════════════════════════════ */

.hero {
  grid-area: 1 / 1;
  align-self: center;
  width: min(700px, 100%);
  max-height: calc(100dvh - 210px);
  margin: 0 auto;
  overflow: auto;
  padding: 18px 0 42px;
  text-align: center;
}

.hero > img,
.hero .brand-logo {
  display: none !important;
}

.hero h1 {
  margin: 0 0 12px;
  font-family: var(--font-display);
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 500;
  line-height: 1.1;
  color: var(--ink);
  letter-spacing: -0.02em;
}

.hero p {
  margin: 0 auto;
  max-width: 540px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 15px;
}

.starter-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-top: 28px;
}

.starter {
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(128, 128, 128, 0.03);
  padding: 14px;
  text-align: left;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.starter:hover {
  background: rgba(128, 128, 128, 0.06);
  border-color: rgba(128, 128, 128, 0.14);
  transform: translateY(-1px);
}

.starter strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 600;
}

.starter span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

/* ═══════════════════════════════════════════════════════════════
   Messages
   ═══════════════════════════════════════════════════════════════ */

.messages {
  grid-area: 1 / 1;
  display: grid;
  min-height: 0;
  align-content: start;
  gap: 24px;
  overflow: auto;
  padding: 20px min(44px, 5vw) 16px;
}

.messages::-webkit-scrollbar {
  width: 5px;
}

.messages::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.message {
  width: min(780px, 100%);
  margin: 0 auto;
  animation: msg-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.assistant {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  align-items: start;
  column-gap: 12px;
}

.message-avatar {
  width: 24px;
  height: 24px;
  margin-top: 3px;
  border-radius: 50%;
}

[data-theme="dark"] .message-avatar {
  opacity: 0.85;
}

.message-body {
  min-width: 0;
}

.message.user {
  display: flex;
  justify-content: flex-end;
}

.message-bubble {
  max-width: 740px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  padding: 0;
  line-height: 1.72;
  white-space: pre-wrap;
  font-size: 14.5px;
}

.message.user .message-bubble {
  max-width: min(620px, 82%);
  border-radius: 18px 18px 4px 18px;
  background: var(--user-bubble);
  border: 1px solid var(--user-bubble-border);
  padding: 12px 16px;
  color: var(--ink);
}

.message.assistant .message-bubble {
  max-width: 720px;
}

/* ═══════════════════════════════════════════════════════════════
   Tool Call Cards
   ═══════════════════════════════════════════════════════════════ */

.tool-calls {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 720px;
  margin-bottom: 12px;
}

.tool-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: rgba(128, 128, 128, 0.03);
  font-size: 13px;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.tool-card.interactive {
  cursor: pointer;
}

.tool-card.interactive:hover {
  background: rgba(128, 128, 128, 0.06);
  border-color: rgba(128, 128, 128, 0.15);
  box-shadow: var(--shadow-sm);
}

.tool-card.completed {
  border-color: rgba(192, 90, 50, 0.15);
  background: var(--accent-glow);
}

.tool-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tool-icon {
  font-size: 11px;
  flex-shrink: 0;
  color: var(--accent);
  font-weight: 700;
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  background: var(--accent-glow);
}

.tool-label {
  color: var(--ink);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.tool-spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid var(--accent);
  border-top-color: transparent;
  border-radius: 50%;
  animation: tool-spin 0.7s linear infinite;
  margin-left: auto;
  flex-shrink: 0;
}

@keyframes tool-spin {
  to { transform: rotate(360deg); }
}

.tool-check {
  margin-left: auto;
  flex-shrink: 0;
  color: #4d9950;
  font-size: 12px;
  font-weight: 700;
  animation: tool-check-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

[data-theme="dark"] .tool-check {
  color: #6db070;
}

@keyframes tool-check-in {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Long doc progress bar */
.longdoc-progress {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--line);
}

.longdoc-bar {
  height: 4px;
  background: var(--line);
  border-radius: 2px;
  overflow: hidden;
}

.longdoc-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s ease;
}

.longdoc-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.longdoc-elapsed {
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.longdoc-tip {
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
  opacity: 0.6;
  font-style: italic;
  animation: tip-fade 8s ease infinite;
}

@keyframes tip-fade {
  0%, 90%, 100% { opacity: 0.6; }
  10%, 80% { opacity: 0.6; }
  5%, 95% { opacity: 0; }
}

.longdoc-log-toggle {
  margin-top: 6px;
  font-size: 11px;
  color: var(--accent);
  cursor: pointer;
  opacity: 0.7;
}

.longdoc-log-toggle:hover {
  opacity: 1;
}

/* Streaming waiting indicator */
.stream-waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  color: var(--muted);
  font-size: 13px;
}

.stream-waiting-dot {
  width: 8px;
  height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: waiting-pulse 1.5s ease-in-out infinite;
}

@keyframes waiting-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.1); }
}

.stream-waiting-text {
  font-variant-numeric: tabular-nums;
}

.tool-chevron {
  width: 0;
  height: 0;
  margin-left: 6px;
  flex-shrink: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--faint);
  transition: transform 0.2s ease;
}

.tool-chevron.expanded {
  transform: rotate(180deg);
}

.tool-card-result {
  color: var(--faint);
  font-size: 12px;
  margin-top: 4px;
  padding-left: 28px;
}

/* Expandable search sources */
.tool-sources {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), margin-top 0.3s ease;
  margin-top: 0;
  padding-left: 28px;
}

.tool-sources.expanded {
  max-height: 500px;
  margin-top: 8px;
}

.tool-source-item {
  display: block;
  padding: 7px 10px;
  border-radius: 7px;
  text-decoration: none;
  color: var(--ink);
  transition: background 0.12s;
  margin-bottom: 2px;
}

.tool-source-item:hover {
  background: rgba(128, 128, 128, 0.07);
}

.source-title {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.source-snippet {
  display: block;
  font-size: 11px;
  color: var(--faint);
  line-height: 1.4;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Code execution output */
.tool-code-output {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s cubic-bezier(0.16, 1, 0.3, 1), margin-top 0.3s ease;
  margin-top: 0;
  padding-left: 28px;
}

.tool-code-output.expanded {
  max-height: 600px;
  overflow-y: auto;
  margin-top: 8px;
}

.tool-code-output.has-images.expanded {
  max-height: none;
}

.tool-code-output pre {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--code-panel-bg);
  color: var(--code-panel-text);
  font-size: 12px;
  font-family: var(--font-mono);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 280px;
  overflow: auto;
  border: 1px solid var(--line);
}

.tool-code-output pre.error {
  color: #e07060;
}

/* File artifact preview in doc panel */
.file-artifact-preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 320px;
  gap: 12px;
  padding: 40px 20px;
  text-align: center;
}
.file-artifact-icon { font-size: 64px; }
.file-artifact-name { font-size: 18px; font-weight: 650; color: var(--ink); word-break: break-all; }
.file-artifact-meta { font-size: 13px; color: var(--muted); }
.file-artifact-download {
  display: inline-flex;
  align-items: center;
  margin-top: 8px;
  padding: 10px 28px;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 650;
  font-size: 15px;
  text-decoration: none;
  transition: background 0.15s;
}
.file-artifact-download:hover { background: var(--accent, #bd5d3a); text-decoration: none; }

.code-output-files {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.file-download-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  color: var(--ink);
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  cursor: pointer;
}
.file-download-btn:hover {
  border-color: var(--accent, #bd5d3a);
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  text-decoration: none;
}
.file-icon { font-size: 22px; flex-shrink: 0; }
.file-info { display: flex; flex-direction: column; gap: 1px; flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-size { font-size: 11px; color: var(--muted); }
.file-dl-icon { font-size: 18px; font-weight: 700; color: var(--muted); flex-shrink: 0; }

.code-output-images {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}

.code-output-images img {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

/* Regenerate button */
.icon-regen {
  display: inline-block;
  font-size: 14px;
  font-weight: 600;
  line-height: 1;
}

/* Version navigation */
.version-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: 10px;
}

.version-btn {
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  transition: background 0.12s, border-color 0.12s;
}

.version-btn:hover:not(:disabled) {
  background: rgba(128, 128, 128, 0.1);
  border-color: rgba(128, 128, 128, 0.2);
}

.version-btn:disabled {
  opacity: 0.3;
  cursor: default;
}

.version-label {
  font-size: 11px;
  color: var(--faint);
  font-weight: 500;
  min-width: 38px;
  text-align: center;
}

/* ═══════════════════════════════════════════════════════════════
   Message Content & Actions
   ═══════════════════════════════════════════════════════════════ */

.message-text {
  white-space: pre-wrap;
}

.sent-files {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border-radius: 8px;
  background: rgba(128, 128, 128, 0.08);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.sent-images {
  display: flex;
  max-width: min(520px, 100%);
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
  white-space: normal;
}

.sent-image {
  overflow: hidden;
  width: min(200px, 100%);
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(128, 128, 128, 0.04);
}

.sent-image img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.message-actions {
  display: flex;
  gap: 4px;
  min-height: 28px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity 0.15s ease;
}

.message.assistant:hover .message-actions,
.message.assistant:focus-within .message-actions,
.message.assistant.streaming .message-actions {
  opacity: 1;
}

.message-action {
  display: inline-flex;
  height: 26px;
  align-items: center;
  gap: 5px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--faint);
  padding: 0 8px;
  font-size: 12px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
}

.message-action:hover {
  background: rgba(128, 128, 128, 0.08);
  color: var(--ink);
}

.message-action:disabled {
  opacity: 0.35;
  cursor: default;
}

.message.assistant.streaming .message-bubble::after {
  content: "";
  display: inline-block;
  width: 2px;
  height: 1.1em;
  margin-left: 2px;
  border-radius: 1px;
  background: var(--accent);
  vertical-align: -0.15em;
  animation: stream-caret 1s steps(2, start) infinite;
}

@keyframes stream-caret {
  50% { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════
   Composer
   ═══════════════════════════════════════════════════════════════ */

.composer {
  position: relative;
  z-index: 5;
  grid-area: 2 / 1;
  width: min(740px, calc(100% - 16px));
  margin: 0 auto;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  padding: 10px;
  transition: border-color 0.2s, box-shadow 0.2s, background 0.3s;
}

.composer:focus-within {
  border-color: rgba(192, 90, 50, 0.25);
  box-shadow: var(--shadow), 0 0 0 1px rgba(192, 90, 50, 0.06);
}

.composer textarea {
  display: block;
  width: 100%;
  height: 36px;
  min-height: 36px;
  max-height: 154px;
  resize: none;
  border: 0;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px 5px;
  line-height: 1.55;
  outline: none;
  overflow-y: auto;
}

.composer textarea::placeholder {
  color: var(--faint);
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
}

.send-button {
  display: inline-flex;
  width: 34px;
  height: 34px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 0.12s, transform 0.1s;
}

.send-button:active {
  transform: scale(0.92);
}

.send-button.stop-mode {
  background: #dc3545;
}

.send-button.stop-mode:hover {
  background: #c82333;
}

[data-theme="dark"] .send-button.stop-mode {
  background: #e04050;
  color: #fff;
}

.icon.stop-icon {
  display: block;
  width: 12px;
  height: 12px;
  border-radius: 2px;
  background: currentColor;
}

.icon-edit {
  font-style: normal;
  font-size: 14px;
}

.options-card {
  margin-top: 12px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary, #faf7f2);
}

[data-theme="dark"] .options-card {
  background: var(--bg-secondary, #252118);
}

.options-question {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}

.options-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.option-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light, #f0e8de);
}

.option-btn:active {
  transform: scale(0.98);
}

[data-theme="dark"] .option-btn {
  background: var(--bg, #1a1512);
}

[data-theme="dark"] .option-btn:hover {
  background: var(--accent-dark, #3a3025);
  border-color: var(--accent);
}

.option-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.option-desc {
  font-size: 12.5px;
  color: var(--text-secondary, #8b7e6f);
  line-height: 1.4;
}

.options-group {
  margin-bottom: 14px;
}

.options-group:last-of-type {
  margin-bottom: 0;
}

.option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-light, #f0e8de);
  box-shadow: 0 0 0 2px var(--accent);
}

[data-theme="dark"] .option-btn.selected {
  background: var(--accent-dark, #3a3025);
  box-shadow: 0 0 0 2px var(--accent);
}

.options-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.options-counter {
  font-size: 12.5px;
  color: var(--text-secondary, #8b7e6f);
}

.options-submit {
  padding: 6px 20px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.options-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.options-submit:not(:disabled):hover {
  background: var(--accent-dark);
}

[data-theme="dark"] .options-submit {
  color: #1a1512;
}

@media (max-width: 720px) {
  .options-card {
    padding: 12px;
  }
  .option-btn {
    padding: 10px 14px;
  }
}

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding: 2px 0;
}

.suggestion-chip {
  display: inline-block;
  padding: 8px 16px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  max-width: 100%;
  text-align: left;
}

.suggestion-chip:hover {
  background: var(--accent-light, #f0e8de);
  border-color: var(--accent);
}

.suggestion-chip:active {
  transform: scale(0.97);
}

[data-theme="dark"] .suggestion-chip {
  background: var(--bg-secondary, #2a2520);
  border-color: var(--border);
}

[data-theme="dark"] .suggestion-chip:hover {
  background: var(--accent-dark, #4a3f34);
  border-color: var(--accent);
}

@media (max-width: 720px) {
  .options-card {
  margin-top: 12px;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-secondary, #faf7f2);
}

[data-theme="dark"] .options-card {
  background: var(--bg-secondary, #252118);
}

.options-question {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 12px;
  color: var(--text);
}

.options-choices {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.option-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.1s;
}

.option-btn:hover {
  border-color: var(--accent);
  background: var(--accent-light, #f0e8de);
}

.option-btn:active {
  transform: scale(0.98);
}

[data-theme="dark"] .option-btn {
  background: var(--bg, #1a1512);
}

[data-theme="dark"] .option-btn:hover {
  background: var(--accent-dark, #3a3025);
  border-color: var(--accent);
}

.option-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.option-desc {
  font-size: 12.5px;
  color: var(--text-secondary, #8b7e6f);
  line-height: 1.4;
}

.options-group {
  margin-bottom: 14px;
}

.options-group:last-of-type {
  margin-bottom: 0;
}

.option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-light, #f0e8de);
  box-shadow: 0 0 0 2px var(--accent);
}

[data-theme="dark"] .option-btn.selected {
  background: var(--accent-dark, #3a3025);
  box-shadow: 0 0 0 2px var(--accent);
}

.options-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.options-counter {
  font-size: 12.5px;
  color: var(--text-secondary, #8b7e6f);
}

.options-submit {
  padding: 6px 20px;
  border-radius: 8px;
  border: 0;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.options-submit:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.options-submit:not(:disabled):hover {
  background: var(--accent-dark);
}

[data-theme="dark"] .options-submit {
  color: #1a1512;
}

@media (max-width: 720px) {
  .options-card {
    padding: 12px;
  }
  .option-btn {
    padding: 10px 14px;
  }
}

.suggestions {
    gap: 6px;
  }
  .suggestion-chip {
    padding: 8px 14px;
    font-size: 13px;
  }
}

/* User message actions */
.message.user .message-actions {
  justify-content: flex-end;
  opacity: 0;
  transition: opacity 0.15s;
}

.message.user:hover .message-actions {
  opacity: 1;
}

/* Always show on touch devices */
@media (hover: none) {
  .message.user .message-actions {
    opacity: 1;
  }
}

.tool-button input {
  display: none;
}

.text-tool {
  width: auto;
  min-width: 44px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
}

.tool-button.active {
  background: var(--accent-glow);
  color: var(--accent);
}

.attachment-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.attachment-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(128, 128, 128, 0.05);
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
}

.attachment-pill.image-pill {
  align-items: flex-start;
  max-width: 180px;
  border-radius: 12px;
  background: var(--surface);
  padding: 6px;
}

.image-pill img {
  width: 60px;
  height: 60px;
  border-radius: 8px;
  object-fit: cover;
}

.image-pill span {
  max-width: 100px;
  overflow: hidden;
  padding-top: 2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-pill button {
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
}

/* ═══════════════════════════════════════════════════════════════
   Document Panel
   ═══════════════════════════════════════════════════════════════ */

.doc-panel {
  display: flex;
  min-width: 0;
  min-height: 0;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  transition: background 0.3s, border-color 0.3s;
}

.doc-panel.collapsed {
  display: none;
}

.doc-panel-header {
  display: flex;
  min-height: 52px;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 14px;
}

.doc-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  flex-wrap: wrap;
}

.doc-panel-header strong,
.doc-panel-header span {
  display: block;
}

.doc-panel-header strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
}

.doc-panel-header span {
  margin-top: 2px;
  color: var(--faint);
  font-size: 11px;
}

.artifact-tabs {
  display: inline-flex;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(128, 128, 128, 0.04);
}

.artifact-tab {
  min-height: 28px;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--faint);
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  transition: background 0.12s, color 0.12s;
}

.artifact-tab:last-child {
  border-right: 0;
}

.artifact-tab.active {
  background: rgba(128, 128, 128, 0.1);
  color: var(--ink);
}

.artifact-tab:disabled {
  opacity: 0.35;
  cursor: default;
}

/* Doc tabs (multi-document) */
.doc-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  flex-shrink: 0;
}

.doc-tabs::-webkit-scrollbar {
  height: 0;
}

.doc-tab {
  flex-shrink: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s, color 0.12s;
}

.doc-tab:hover {
  background: rgba(128, 128, 128, 0.08);
}

.doc-tab.active {
  background: var(--accent-glow);
  color: var(--accent);
  font-weight: 600;
}

.doc-preview {
  flex: 1;
  min-height: 0;
  overflow: auto;
  margin: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
  padding: 28px;
  line-height: 1.72;
  transition: background 0.3s;
}

.doc-preview::-webkit-scrollbar {
  width: 5px;
}

.doc-preview::-webkit-scrollbar-thumb {
  background: var(--scrollbar);
  border-radius: 3px;
}

.doc-preview.html-preview {
  display: flex;
  padding: 0;
  background: #fff;
}

.doc-preview iframe {
  width: 100%;
  min-height: 100%;
  flex: 1;
  border: 0;
  background: #fff;
}

.doc-preview.source-preview {
  padding: 0;
  background: var(--code-panel-bg);
}

.doc-preview.source-preview pre {
  min-height: 100%;
  margin: 0;
  border-radius: 0;
  background: transparent;
  border: none;
  color: var(--code-panel-text);
  padding: 20px;
  white-space: pre-wrap;
  font-family: var(--font-mono);
  font-size: 13px;
}

.doc-preview.source-preview code {
  background: transparent;
  color: inherit;
}

.doc-preview h1,
.doc-preview h2,
.doc-preview h3 {
  color: var(--ink);
  line-height: 1.25;
  font-family: var(--font-display);
}

.doc-preview h1 {
  margin-top: 0;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  font-size: 26px;
  font-weight: 500;
}

.doc-preview h2 {
  margin-top: 28px;
  font-size: 20px;
  font-weight: 500;
}

.doc-preview h3 {
  margin-top: 20px;
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-body);
}

.doc-preview p,
.doc-preview li {
  color: var(--muted);
}

.doc-preview blockquote {
  margin: 18px 0;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: var(--accent-glow);
  color: var(--muted);
  padding: 12px 16px;
}

.doc-preview table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0;
  border: 1px solid var(--line);
  font-size: 13px;
}

.doc-preview th,
.doc-preview td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: top;
}

.doc-preview th {
  background: rgba(128, 128, 128, 0.06);
  color: var(--ink);
  font-weight: 600;
}

.doc-preview pre,
.doc-preview code {
  border-radius: 6px;
  background: var(--code-bg);
  font-family: var(--font-mono);
  font-size: 13px;
}

.doc-preview code {
  padding: 2px 5px;
}

.doc-preview pre {
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--line);
}

.doc-preview pre code {
  padding: 0;
  background: none;
}

.empty-doc {
  color: var(--faint);
}

/* ═══════════════════════════════════════════════════════════════
   Icons (CSS-only)
   ═══════════════════════════════════════════════════════════════ */

.icon {
  display: inline-block;
  width: 17px;
  height: 17px;
  position: relative;
}

.icon.plus::before,
.icon.plus::after,
.icon.menu::before,
.icon.menu::after,
.icon.logout::before,
.icon.logout::after,
.icon.attach::before,
.icon.attach::after,
.icon.copy::before,
.icon.copy::after,
.icon.arrow-up::before,
.icon.arrow-up::after {
  content: "";
  position: absolute;
  background: currentColor;
}

.icon.plus::before {
  inset: 8px 2px auto;
  height: 1.5px;
}

.icon.plus::after {
  left: 7.6px;
  top: 2px;
  width: 1.5px;
  height: 13px;
}

.icon.menu::before {
  left: 2px;
  right: 2px;
  top: 4px;
  height: 1.5px;
  box-shadow: 0 5px 0 currentColor, 0 10px 0 currentColor;
}

.icon.logout::before {
  left: 3px;
  top: 3px;
  width: 8px;
  height: 11px;
  border: 1.5px solid currentColor;
  border-right: 0;
  background: transparent;
}

.icon.logout::after {
  right: 2px;
  top: 8px;
  width: 9px;
  height: 1.5px;
  box-shadow: 3px -3px 0 -1px currentColor, 3px 3px 0 -1px currentColor;
}

.icon.attach::before {
  left: 5px;
  top: 2px;
  width: 7px;
  height: 12px;
  border: 1.5px solid currentColor;
  border-radius: 6px;
  background: transparent;
  transform: rotate(24deg);
}

.icon.copy::before,
.icon.copy::after {
  width: 9px;
  height: 10px;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  background: transparent;
}

.icon.copy::before {
  left: 3px;
  top: 5px;
}

.icon.copy::after {
  left: 6px;
  top: 2px;
  background: var(--paper);
}

.icon.arrow-up::before {
  left: 7.6px;
  top: 4px;
  width: 1.5px;
  height: 10px;
}

.icon.arrow-up::after {
  left: 4px;
  top: 4px;
  width: 8px;
  height: 8px;
  border-left: 1.5px solid currentColor;
  border-top: 1.5px solid currentColor;
  background: transparent;
  transform: rotate(45deg);
}

/* ═══════════════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════════════ */

@media (max-width: 1020px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    z-index: 20;
    inset: 0 auto 0 0;
    width: 272px;
    transform: translateX(-100%);
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 10px 0 36px rgba(0, 0, 0, 0.25);
  }

  body.sidebar-open .sidebar {
    transform: translateX(0);
  }

  .mobile-only {
    display: inline-flex;
  }

  .chat-view {
    grid-template-columns: 1fr;
  }

  .doc-panel {
    position: fixed;
    z-index: 30;
    inset: 52px 0 0;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.3);
  }
}

@media (max-height: 760px) {
  .topbar {
    min-height: 48px;
    padding-block: 6px;
  }

  .hero {
    align-self: start;
    padding-top: 6px;
  }

  .hero h1 {
    font-size: 32px;
  }

  .starter {
    min-height: 72px;
    padding: 10px 12px;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding-inline: 10px;
    min-height: 48px;
  }

  .ghost-button {
    display: none;
  }

  .model-pill {
    font-size: 12px;
  }

  .chat-view {
    padding: 0 6px max(8px, calc(env(safe-area-inset-bottom) + 6px));
  }

  .starter-grid {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 16px;
  }

  .starter {
    min-height: 56px;
    padding: 10px 14px;
    font-size: 13px;
  }

  .hero h1 {
    font-size: 28px;
  }

  .hero p {
    font-size: 13px;
    padding-inline: 8px;
  }

  .messages {
    padding-inline: 2px;
  }

  .message {
    width: 100%;
  }

  .message.user .message-bubble {
    max-width: 88%;
    padding: 10px 14px;
    font-size: 14px;
  }

  .message.assistant .message-bubble {
    font-size: 14px;
  }

  .composer {
    width: 100%;
    border-radius: 16px;
  }

  .composer textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 10px 12px 6px;
    max-height: 120px;
  }

  .message.assistant {
    grid-template-columns: 22px minmax(0, 1fr);
    column-gap: 8px;
  }

  .message-avatar {
    width: 20px;
    height: 20px;
  }

  /* Tool cards */
  .tool-card {
    padding: 8px 10px;
    font-size: 12px;
  }

  /* Composer actions */
  .composer-actions {
    padding-top: 2px;
  }

  .send-button {
    width: 36px;
    height: 36px;
  }

  .tool-button,
  .icon-button {
    width: 36px;
    min-height: 36px;
  }

  .text-tool {
    min-width: 40px;
    padding: 0 8px;
  }

  /* Attachment pills */
  .attachment-pill {
    font-size: 11px;
    padding: 4px 8px;
  }

  /* Document panel: full-screen overlay on mobile */
  .doc-panel {
    position: fixed;
    z-index: 30;
    inset: 48px 0 0;
    border-radius: 0;
    border: 0;
    border-top: 1px solid var(--line);
  }

  .doc-panel-header {
    min-height: 48px;
    padding: 8px 12px;
  }

  .doc-actions button {
    min-height: 34px;
    min-width: 34px;
    font-size: 12px;
  }

  /* Messages actions (copy/regen) always visible on mobile */
  .message-actions {
    opacity: 1;
  }

  .message-action {
    min-height: 32px;
    padding: 4px 8px;
  }

  /* Login view */
  .login-card {
    width: 92%;
    padding: 24px 20px;
  }

  /* Thread context menu */
  .context-menu {
    min-width: 140px;
  }

  .context-menu button {
    min-height: 40px;
    font-size: 13px;
  }

  /* Code blocks */
  .code-block-wrapper {
    border-radius: 10px;
    font-size: 12px;
  }

  /* Site footer */
  .site-footer {
    display: none;
  }
}

/* Extra small screens (iPhone SE, etc) */
@media (max-width: 380px) {
  .topbar {
    padding-inline: 8px;
  }

  .chat-view {
    padding: 0 4px max(6px, calc(env(safe-area-inset-bottom) + 4px));
  }

  .message.user .message-bubble {
    max-width: 92%;
    padding: 8px 12px;
  }

  .composer textarea {
    padding: 8px 10px 4px;
  }

  .hero h1 {
    font-size: 24px;
  }

  .starter {
    min-height: 48px;
    padding: 8px 12px;
  }
}



/* ─── Touch & Mobile Enhancements ─── */
@supports (padding: env(safe-area-inset-bottom)) {
  .composer {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
  }
}

/* Floating document button (mobile) */
.doc-fab {
  display: none;
  position: fixed;
  bottom: 90px;
  right: 16px;
  z-index: 15;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 28px;
  padding: 10px 16px 10px 12px;
  font-size: 13px;
  font-family: var(--font-sans);
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  align-items: center;
  gap: 6px;
  max-width: 200px;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.doc-fab:active {
  transform: scale(0.95);
}
.doc-fab-icon {
  font-size: 16px;
}
.doc-fab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 1020px) {
  .doc-fab { display: inline-flex; }
}

/* Prevent pull-to-refresh on mobile */
.messages {
  overscroll-behavior: contain;
}

/* Smooth scrolling on iOS */
.messages,
.thread-list,
.doc-preview-wrapper {
  -webkit-overflow-scrolling: touch;
}

/* Tap highlight for interactive elements */
@media (hover: none) and (pointer: coarse) {
  .thread-item:active,
  .primary-nav:active,
  .starter:active {
    background: rgba(128, 128, 128, 0.12);
    transition: none;
  }

  .message-actions {
    opacity: 1;
  }

  /* Larger touch targets */
  .thread-item {
    min-height: 44px;
    padding: 10px 12px;
  }

  .icon-button,
  .tool-button {
    min-width: 36px;
    min-height: 36px;
  }

  .context-menu button {
    min-height: 44px;
  }
}

/* ─── Long Document Generation ─── */
.long-doc-btn {
  background: var(--accent-glow) !important;
  border: 1px solid var(--accent) !important;
  color: var(--accent) !important;
  font-size: 13px;
  margin-top: 4px;
}
.long-doc-btn:hover {
  background: var(--accent) !important;
  color: white !important;
}

.long-doc-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.long-doc-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(4px);
}
.long-doc-card {
  position: relative;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 32px;
  width: 90%;
  max-width: 560px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.long-doc-card h2 {
  margin: 0 0 4px;
  font-size: 22px;
  color: var(--ink);
}
.long-doc-card .subtitle {
  color: var(--muted);
  font-size: 14px;
  margin-bottom: 20px;
}
.long-doc-card label {
  display: block;
  margin-bottom: 14px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.long-doc-card input,
.long-doc-card textarea,
.long-doc-card select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  font-family: inherit;
  box-sizing: border-box;
}
.long-doc-card textarea {
  min-height: 80px;
  resize: vertical;
}
.long-doc-card .row {
  display: flex;
  gap: 12px;
}
.long-doc-card .row > label {
  flex: 1;
}
.long-doc-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}
.long-doc-actions button {
  padding: 10px 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  cursor: pointer;
}
.long-doc-actions .primary {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
  font-weight: 600;
}
.long-doc-actions .primary:hover {
  background: var(--accent-dark);
}
.long-doc-actions .primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Progress panel inside modal */
.long-doc-progress {
  margin-top: 16px;
  padding: 16px;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--line);
}
.long-doc-progress .stage-label {
  font-weight: 600;
  color: var(--accent);
  font-size: 14px;
  margin-bottom: 8px;
}
.long-doc-progress .progress-bar {
  height: 6px;
  background: var(--line);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 8px;
}
.long-doc-progress .progress-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s ease;
}
.long-doc-progress .progress-log {
  font-size: 12px;
  color: var(--muted);
  max-height: 120px;
  overflow-y: auto;
  line-height: 1.6;
}
.long-doc-progress .progress-log .done {
  color: #4d9950;
}
.long-doc-progress .progress-log .error {
  color: var(--accent);
}

/* Export buttons */
#exportDocx, #exportPdf {
  font-size: 12px;
  padding: 4px 10px;
}

/* Share button: hidden by default, JS shows it when navigator.share is available */
.share-btn { display: none !important; }
.share-btn.visible { display: inline-flex !important; }

/* Share modal */
.share-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.share-modal {
  background: var(--paper);
  border-radius: 12px;
  padding: 24px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow);
}
.share-modal h3 {
  margin: 0 0 8px;
  color: var(--ink);
  font-size: 16px;
}
.share-link-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-family: var(--font-mono);
  margin: 12px 0;
  box-sizing: border-box;
}
.share-modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}
.share-copy-btn, .share-close-btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
}
.share-copy-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.share-copy-btn:hover { opacity: 0.9; }
.share-close-btn:hover { background: var(--bg); }
