/* IXL web — Tauri-style bubbles + composer + desktop sidebar. */
:root {
  --bg:            #eef1f6;
  --surface:       #ffffff;
  --surface-2:     #f6f8fb;
  --border:        #e5e7ec;
  --border-strong: #d5d9e0;
  --text:          #0a0d14;
  --muted:         #6b7280;
  --dim:           #9ca3af;
  --accent:        #ccff00;
  --accent-hover:  #b8e600;
  --accent-soft:   #f5f6f8;
  --on-accent:     #000000;
  --success:       #10b981;
  --danger:        #ef4444;

  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Helvetica Neue", Arial, sans-serif;

  --radius: 14px;
  --pill:   999px;

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow:    0 8px 32px rgba(15, 23, 42, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  width: 100%; height: 100%;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body { overflow: hidden; }
button, textarea, input, select { font: inherit; color: inherit; background: transparent; border: 0; outline: 0; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; }

/* ================= LANDING ================= */
.landing { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg); overflow: auto; }
.landing-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; }
.brand-row { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: 0.04em; font-size: 12.5px; }
.brand-row img { width: 26px; height: 26px; border-radius: 6px; }
.ghost-btn { padding: 8px 16px; border-radius: var(--pill); border: 1px solid var(--border-strong); background: var(--surface); font-weight: 500; font-size: 12.5px; cursor: pointer; transition: background 0.15s; }
.ghost-btn:hover { background: var(--surface-2); }
.hero { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 56px 24px 32px; text-align: center; gap: 16px; }
.hero .eyebrow { color: var(--muted); font-size: 10.5px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 600; }
.hero h1 { font-size: clamp(30px, 5vw, 52px); font-weight: 600; line-height: 1.06; letter-spacing: -0.02em; max-width: 760px; }
.hero h1 em { font-style: normal; background: linear-gradient(120deg, var(--accent-hover), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { font-size: 13.5px; color: var(--muted); max-width: 560px; line-height: 1.55; }
.hero .cta { display: inline-flex; align-items: center; gap: 10px; padding: 11px 20px; border-radius: var(--pill); background: var(--surface); border: 1px solid var(--border-strong); font-size: 13px; font-weight: 500; margin-top: 6px; cursor: pointer; transition: background 0.15s, box-shadow 0.15s; }
.hero .cta:hover { background: var(--surface-2); box-shadow: var(--shadow-sm); }
.hero .cta svg { width: 18px; height: 18px; }
.features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; max-width: 900px; width: 100%; margin: 40px auto 0; padding: 0 24px; text-align: left; }
.feature { padding: 18px 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.feature h3 { font-size: 12.5px; font-weight: 600; margin-bottom: 4px; }
.feature p { font-size: 12px; color: var(--muted); }
.landing-footer { padding: 24px; text-align: center; color: var(--dim); font-size: 11px; margin-top: 48px; }

/* ================= CHAT ================= */
body.chat-body { display: flex; padding: 0; }

.app {
  flex: 1;
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  overflow: hidden;
}

/* -------- SIDEBAR -------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  min-width: 0;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 12px;
}
.topbar-brand { display: flex; align-items: center; gap: 12px; }
.topbar-brand img { width: 44px; height: 44px; border-radius: 10px; }
.topbar-brand span { font-weight: 700; font-size: 20px; letter-spacing: 0.06em; }

.new-chat-side {
  margin: 4px 8px 10px;
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  justify-content: flex-start;
  background: transparent; border: 0;
  border-radius: 8px;
  font-size: 14px; font-weight: 500;
  color: var(--text);
  cursor: pointer; transition: background 0.12s;
}
.new-chat-side:hover { background: var(--surface-2); }
.new-chat-side svg { color: var(--muted); flex-shrink: 0; width: 16px; height: 16px; }

.section-label {
  padding: 10px 18px 6px;
  font-size: 11px; font-weight: 700;
  letter-spacing: 0.12em; color: var(--dim);
  text-transform: uppercase;
}

.history-list {
  flex: 1; overflow-y: auto;
  padding: 0 8px 8px;
}
.history-item {
  position: relative;
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  padding: 9px 12px 9px 22px; border-radius: 8px; font-size: 12px;
  color: var(--text-muted, var(--muted)); cursor: pointer;
  transition: background 0.12s, color 0.12s; margin-bottom: 2px;
}
.history-item:hover { background: var(--surface-2); color: var(--text); }
.history-item.active { background: var(--surface-2); font-weight: 600; color: var(--text); }
.history-item::before {
  content: "";
  position: absolute;
  left: 9px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: transparent;
  transition: background 0.12s;
}
.history-item.active::before { background: var(--accent); }
.history-item .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.history-item .del {
  opacity: 0; width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 6px; color: var(--muted); font-size: 16px; line-height: 1;
  transition: opacity 0.12s, background 0.12s, color 0.12s; flex-shrink: 0;
}
.history-item:hover .del { opacity: 1; }
.history-item .del:hover { background: var(--border); color: var(--danger); }
.history-empty { padding: 14px 10px; color: var(--dim); font-size: 13px; text-align: center; }

.sidebar-footer { border-top: 1px solid var(--border); padding: 8px; }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 8px 10px; border-radius: 12px;
  background: transparent; cursor: pointer;
  transition: background 0.12s;
}
.user-chip:hover { background: var(--surface-2); }
.user-chip img {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); object-fit: cover; flex-shrink: 0;
}
.user-chip .name {
  flex: 1; min-width: 0; font-size: 14px; font-weight: 500; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip svg { color: var(--muted); flex-shrink: 0; }

/* -------- MAIN CARD -------- */
.card {
  display: flex; flex-direction: column;
  background: var(--surface);
  min-width: 0; min-height: 0;
  overflow: hidden;
}

.topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  min-height: 54px;
}
.chat-title {
  font-size: 14px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.topbar-spacer { flex: 1; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }

.chip-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--pill);
  background: var(--surface-2); color: var(--text);
  font-size: 11.5px; font-weight: 500;
  border: 1px solid var(--border);
  cursor: pointer; transition: background 0.12s;
}
.chip-btn:hover { background: #eef1f6; }

.only-mobile { display: none; }

/* -------- CHAT AREA -------- */
.chat {
  flex: 1; overflow-y: auto;
  padding: 20px 26px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scroll-behavior: smooth;
}
.chat::-webkit-scrollbar { width: 8px; }
.chat::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

/* user bubble — right */
.msg-user-wrap {
  align-self: flex-end;
  max-width: 78%;
  display: flex; flex-direction: column; gap: 6px; align-items: flex-end;
}
.msg.user {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 7px 12px;
  box-shadow: var(--shadow-xs);
  white-space: pre-wrap; word-wrap: break-word;
  font-size: 12px;
  line-height: 1.55;
}
.msg-attachments {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-end;
}
.msg-file-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px 6px 8px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; box-shadow: var(--shadow-xs);
  max-width: 280px;
}
.msg-file-chip .chip-icon {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--surface-2); color: var(--dim);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.msg-file-chip .chip-body {
  display: flex; flex-direction: column; min-width: 0; line-height: 1.25;
}
.msg-file-chip .chip-name {
  font-family: var(--mono); font-size: 11.5px; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-file-chip .chip-sub {
  font-size: 10.5px; color: var(--dim);
}

/* assistant — full width with dot */
.msg.assistant {
  align-self: stretch;
  display: flex; gap: 14px;
  padding: 0 2px;
  color: var(--text);
  font-size: 12px; line-height: 1.65;
}
.msg.assistant .dot {
  flex-shrink: 0; width: 10px; height: 10px; margin-top: 5px;
  border-radius: 50%;
  border: 1.5px dashed var(--dim);
  background: transparent;
}
.msg.assistant.thinking .dot {
  border-style: solid;
  border-color: var(--accent-soft);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.msg.assistant .content-wrap { flex: 1; min-width: 0; }
.msg.assistant .content { word-wrap: break-word; overflow-wrap: anywhere; }

/* Markdown rendering (assistant only) */
.prose > *:first-child { margin-top: 0; }
.prose > *:last-child { margin-bottom: 0; }
.prose p { margin: 0 0 12px; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 600; letter-spacing: -0.01em;
  margin: 20px 0 10px; line-height: 1.3;
}
.prose h1 { font-size: 22px; }
.prose h2 { font-size: 19px; }
.prose h3 { font-size: 17px; }
.prose h4 { font-size: 15px; color: var(--text); }
.prose strong { font-weight: 600; }
.prose em { font-style: italic; }
.prose ul, .prose ol { margin: 0 0 12px; padding-left: 24px; }
.prose li { margin: 4px 0; }
.prose li > p { margin: 0; }
.prose blockquote {
  border-left: 3px solid var(--border-strong);
  padding: 2px 12px; margin: 10px 0; color: var(--muted);
  background: var(--surface-2); border-radius: 0 8px 8px 0;
}
.prose code {
  font-family: var(--mono);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 0.9em;
}
.prose pre {
  background: #0d1117; color: #e6edf3;
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0 14px;
  font-size: 13px; line-height: 1.55;
}
.prose pre code {
  background: transparent; border: 0; padding: 0;
  color: inherit; font-size: inherit;
}
.prose a { color: #1d4ed8; text-decoration: underline; text-underline-offset: 2px; }
.prose a:hover { color: #1e3a8a; }
.prose hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.prose table {
  border-collapse: collapse; width: 100%; margin: 10px 0;
  font-size: 14px;
}
.prose th, .prose td {
  border: 1px solid var(--border); padding: 6px 10px; text-align: left;
}
.prose th { background: var(--surface-2); font-weight: 600; }
.msg.assistant .meta { margin-top: 8px; font-size: 12px; color: var(--dim); display: flex; gap: 10px; align-items: center; }
.msg.assistant .meta:empty { display: none; }
.reply-actions { display: inline-flex; gap: 2px; margin-left: auto; }
.reply-btn {
  width: 24px; height: 24px; border-radius: 6px;
  background: transparent; color: var(--dim); border: 0; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.12s, color 0.12s;
}
.reply-btn:hover { background: var(--surface-2); color: var(--text); }
.reply-btn.done { color: var(--accent-hover); }

/* -------- chunked-summary flow -------- */
.chunk-bar-wrap {
  display: flex; flex-direction: column; gap: 4px;
  margin: 0 0 10px 0; padding: 6px 10px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px;
}
.chunk-bar {
  height: 4px; background: var(--border); border-radius: 999px; overflow: hidden;
}
.chunk-bar-fill {
  height: 100%; background: var(--accent);
  transition: width 0.3s ease;
}
.chunk-bar-label {
  font-family: var(--mono); font-size: 10.5px; color: var(--dim);
}
.msg.assistant.thinking .chunk-bar-fill {
  animation: chunkPulse 1.4s ease-in-out infinite;
}
@keyframes chunkPulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.5; }
}
.chunk-actions {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin: 10px 0 0 0;
  align-items: flex-start;
  align-self: flex-start;
  justify-content: flex-start;
  width: fit-content;
  max-width: 100%;
}
.chunk-btn {
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
  align-self: flex-start;
  padding: 7px 14px;
  height: 30px;
  border-radius: 999px; cursor: pointer;
  font-size: 11.5px; font-weight: 600; line-height: 1;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text);
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  width: fit-content; max-width: 100%;
  white-space: nowrap;
}
.chunk-btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.chunk-btn:active { transform: scale(0.98); }
.chunk-btn.primary {
  background: var(--accent); color: var(--on-accent); border-color: var(--accent);
}
.chunk-btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.chunk-btn.ghost {
  background: transparent; color: var(--dim);
}
.chunk-btn.ghost:hover { background: var(--surface-2); color: var(--text); }

/* -------- PDF export container (offscreen render source) -------- */
/* Forces consistent block spacing regardless of what markdown produced. */
.pdf-export > * + * { margin-top: 16px !important; }
.pdf-export table   {
  margin: 18px 0 22px !important;
  table-layout: fixed !important;
  width: 100% !important;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.pdf-export th, .pdf-export td {
  word-wrap: break-word !important;
  overflow-wrap: anywhere !important;
  word-break: normal !important;
  hyphens: auto;
  vertical-align: top !important;
}
.pdf-export h1, .pdf-export h2, .pdf-export h3, .pdf-export h4 {
  margin-top: 22px !important; margin-bottom: 8px !important;
}
.pdf-export p       { margin: 0 0 12px !important; }
.pdf-export ul, .pdf-export ol { margin: 0 0 14px !important; padding-left: 26px !important; }
.pdf-export li      { margin: 4px 0 !important; }
.pdf-export pre     { margin: 12px 0 !important; }
.pdf-export blockquote { margin: 14px 0 !important; }

/* -------- drag & drop overlay -------- */
.drop-overlay {
  position: fixed; inset: 12px;
  z-index: 2000;
  background: rgba(204, 255, 0, 0.14);
  border: 3px dashed var(--accent);
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  animation: dropFade 0.12s ease-out;
}
.drop-overlay[hidden] { display: none; }
.drop-overlay-inner {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 24px 32px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow);
  color: var(--text);
}
.drop-overlay-inner svg { color: var(--accent-hover); }
.drop-overlay-title { font-size: 16px; font-weight: 700; }
.drop-overlay-sub   { font-size: 12px; color: var(--dim); font-family: var(--mono); }
@keyframes dropFade { from { opacity: 0; } to { opacity: 1; } }
.msg.assistant .meta .model { font-family: var(--mono); color: var(--muted); }

/* Quotation card (rendered from AI JSON) */
.quotation-card {
  margin: 12px 0 4px; padding: 14px 16px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2);
}
.quotation-card .qc-head {
  display: flex; justify-content: space-between; align-items: baseline;
  margin-bottom: 8px;
}
.quotation-card .qc-title { font-weight: 600; font-size: 14px; color: var(--text); }
.quotation-card .qc-date  { font-size: 12px; color: var(--muted); font-family: var(--mono); }
.quotation-card .qc-parties {
  display: flex; flex-direction: column; gap: 2px;
  font-size: 12.5px; color: var(--muted);
}
.quotation-card .qc-label {
  color: var(--dim); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600; margin-right: 6px;
}
.quotation-card .qc-summary {
  display: flex; justify-content: space-between; align-items: center;
  margin: 10px 0 12px; padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 13px; color: var(--muted);
}
.quotation-card .qc-total { font-weight: 600; font-size: 15px; color: var(--text); }
.quotation-card .qc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.quotation-card .qc-btn {
  padding: 6px 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 12.5px; font-weight: 500; color: var(--text); cursor: pointer;
  transition: background 0.15s;
}
.quotation-card .qc-btn:hover { background: var(--surface-2); }
.quotation-card .qc-btn-primary {
  background: var(--text); color: #fff; border-color: var(--text);
}
.quotation-card .qc-btn-primary:hover { background: #000; }

/* Quotation preview modal — Claude Code-style artifact preview */
.qp-modal {
  position: fixed; inset: 0; z-index: 900;
  display: flex; align-items: center; justify-content: center;
  padding: 24px; opacity: 0; pointer-events: none;
  transition: opacity 0.18s ease;
}
.qp-modal.open { opacity: 1; pointer-events: auto; }
.qp-modal.open .qp-container { transform: translateY(0) scale(1); }
.qp-backdrop {
  position: absolute; inset: 0;
  background: rgba(10, 13, 20, 0.55);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.qp-container {
  position: relative; z-index: 1;
  width: 100%; max-width: 780px;
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 24px 60px -12px rgba(15, 23, 42, 0.30), 0 0 0 1px rgba(15, 23, 42, 0.04);
  overflow: hidden;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Header — file badge + name + close */
.qp-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.qp-file-badge {
  flex-shrink: 0;
  width: 32px; height: 32px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.qp-header-text { flex: 1; min-width: 0; }
.qp-filename {
  font-family: var(--mono);
  font-size: 12.5px; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.qp-filemeta {
  font-size: 11px; color: var(--muted);
  margin-top: 1px;
}
.qp-icon-btn {
  flex-shrink: 0;
  width: 30px; height: 30px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.qp-icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* PDF viewer area */
.qp-scroll {
  flex: 1; overflow: hidden;
  background: #3d4046;
  display: flex; min-height: 0;
}
.qp-pdf {
  width: 100%; height: 100%; border: 0;
  background: transparent;
}

/* Footer */
.qp-footer {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface);
}
.qp-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: 8px;
  font-size: 12.5px; font-weight: 500;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.qp-btn-ghost {
  color: var(--text);
  border: 1px solid var(--border-strong);
  background: var(--surface);
}
.qp-btn-ghost:hover { background: var(--surface-2); }
.qp-btn-primary {
  color: #fff;
  background: var(--text);
  border: 1px solid var(--text);
}
.qp-btn-primary:hover { background: #000; }

/* Sizing */
@media (min-width: 641px) {
  .qp-container { height: min(90vh, 900px); }
}

@media (max-width: 640px) {
  .qp-modal { padding: 0; }
  .qp-container {
    max-width: 100%; height: 100vh;
    border-radius: 0; border: 0;
  }
  .qp-btn-ghost span, .qp-btn-primary span { display: inline; }
}

/* Passcode gate overlay */
.passcode-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: rgba(238, 241, 246, 0.92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  padding: 20px;
}
.passcode-overlay.active { display: flex; }
.passcode-box {
  width: 100%; max-width: 360px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  padding: 28px 24px 20px; text-align: center;
}
.passcode-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent); object-fit: cover; margin-bottom: 12px;
}
.passcode-box h2 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.passcode-box p  { font-size: 13px; color: var(--muted); margin-bottom: 18px; }
#passcode-form { display: flex; flex-direction: column; gap: 10px; }
#passcode-input {
  padding: 11px 14px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--surface);
  font-size: 15px; text-align: center; letter-spacing: 0.08em;
}
#passcode-input:focus { border-color: var(--text); }
.passcode-error {
  font-size: 12.5px; color: var(--danger);
  background: #fef2f2; border: 1px solid #fecaca;
  padding: 8px 10px; border-radius: 8px;
}
.passcode-submit {
  padding: 11px 14px; border-radius: 10px;
  background: var(--text); color: #fff;
  font-size: 14px; font-weight: 500; cursor: pointer;
  transition: opacity 0.15s;
}
.passcode-submit:hover { opacity: 0.9; }
.passcode-signout {
  margin-top: 14px; padding: 6px 10px;
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.passcode-signout:hover { color: var(--text); text-decoration: underline; }

.empty-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--muted); gap: 6px; text-align: center;
}
.empty-state h2 { color: var(--text); font-size: 30px; font-weight: 600; letter-spacing: -0.01em; }
.empty-state p { font-size: 15px; color: var(--muted); }

.banner {
  margin: 0 26px 4px; padding: 8px 12px; border-radius: 10px;
  background: #fff8e6; border: 1px solid #f0d976; color: #7a5c00;
  display: flex; align-items: center; gap: 10px; font-size: 12px;
}
.banner button {
  margin-left: auto; padding: 4px 10px; border-radius: 6px;
  border: 1px solid #d4a72c; background: transparent; color: #7a5c00; cursor: pointer;
  font-size: 11px; font-weight: 500;
}
.banner button:hover { background: rgba(212,167,44,0.1); }

/* -------- COMPOSER -------- */
.composer-wrap { padding: 8px 20px 16px; flex-shrink: 0; }
.composer {
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 20px; padding: 12px 16px 10px;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.15s, box-shadow 0.15s;
  max-width: 780px; margin: 0 auto;
}
.composer:focus-within { border-color: var(--border-strong); }
#input {
  width: 100%; resize: none; max-height: 200px;
  color: var(--text); font-size: 12px; line-height: 1.5;
  padding: 4px 0; caret-color: var(--accent);
}
#input::placeholder { color: var(--dim); }

.composer-tools {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px; user-select: none;
}
.composer-tools .spacer { flex: 1; }

/* attach button */
.icon-tool {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-tool:hover { background: #eef1f6; border-color: var(--border-strong); }
.icon-tool:active { transform: scale(0.95); }
.icon-tool:disabled { opacity: 0.4; cursor: not-allowed; }

/* attachments row (chips above textarea) */
.attachments {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 2px 0 8px;
}
.attach-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 6px 4px 10px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 11.5px; color: var(--text); max-width: 240px;
}
.attach-chip .name {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--mono);
}
.attach-chip .status { color: var(--dim); font-size: 10.5px; }
.attach-chip.working { border-color: var(--accent); }
.attach-chip .x {
  width: 18px; height: 18px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--dim); cursor: pointer; flex-shrink: 0;
}
.attach-chip .x:hover { background: var(--border); color: var(--text); }
.attach-warn {
  font-size: 11px; color: #b45309; margin: 2px 0 6px;
  padding: 6px 8px; background: #fef3c7; border-radius: 8px;
  border: 1px solid #fde68a;
}

/* model chip */
.model-chip { position: relative; display: inline-flex; }
.model-trigger {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; border-radius: var(--pill);
  background: var(--surface-2); color: var(--text);
  font-family: var(--mono); font-weight: 600; font-size: 12.5px;
  border: 1px solid var(--border); cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.model-trigger:hover { background: #eef1f6; border-color: var(--border-strong); }
.model-trigger .sparkle { color: var(--dim); flex-shrink: 0; }
.model-trigger .chev { color: var(--dim); opacity: 0.7; margin-left: 2px; transition: transform 0.15s; }
.model-trigger[aria-expanded="true"] .chev { transform: rotate(180deg); }

.model-menu {
  position: absolute; bottom: calc(100% + 6px); left: 0;
  min-width: 220px; max-height: 280px; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 4px; z-index: 20;
  animation: menuInBottom 0.14s ease-out;
}
@keyframes menuInBottom { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.model-menu-header {
  padding: 6px 8px 4px; font-size: 9.5px; font-weight: 700;
  letter-spacing: 0.14em; color: var(--dim);
}
.model-menu ul { display: flex; flex-direction: column; gap: 1px; }
.model-menu li {
  padding: 6px 8px; border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; gap: 8px; font-size: 12px;
}
.model-menu li:hover { background: var(--surface-2); }
.model-menu li.active { background: var(--accent-soft); color: var(--accent-hover); font-weight: 600; }
.model-menu li .check { margin-left: auto; opacity: 0; color: var(--accent-hover); }
.model-menu li.active .check { opacity: 1; }
.model-menu li.empty { color: var(--muted); font-style: italic; cursor: default; }

/* send / stop */
.send-btn {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: var(--on-accent); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background 0.15s, transform 0.1s, opacity 0.15s;
}
.send-btn svg { width: 16px; height: 16px; }
.send-btn.stop svg { width: 12px; height: 12px; }
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:active:not(:disabled) { transform: scale(0.95); }
.send-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.send-btn.stop { background: var(--text); color: var(--surface); }
.send-btn.stop:hover { background: #1f2937; }

/* -------- MODAL -------- */
.modal-root {
  position: fixed; inset: 0; z-index: 100;
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
}
.modal-root.open { display: flex; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.4);
  animation: fadeIn 0.15s ease;
}
.modal {
  position: relative; z-index: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px 22px 16px;
  min-width: 280px; max-width: 420px; width: 100%;
  animation: modalIn 0.16s cubic-bezier(0.4,0,0.2,1);
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(6px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.modal-body { font-size: 14px; color: var(--muted); line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-btn {
  padding: 8px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s;
  border: 1px solid transparent;
}
.modal-btn.ghost {
  background: transparent; color: var(--text-2, var(--text));
  border-color: var(--border-strong);
}
.modal-btn.ghost:hover { background: var(--surface-2); }
.modal-btn.danger {
  background: var(--danger); color: #fff;
}
.modal-btn.danger:hover { background: #b91c1c; }
.modal-btn.primary {
  background: var(--text); color: var(--surface);
}
.modal-btn.primary:hover { background: #1f2937; }

/* -------- MOBILE DRAWER -------- */
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 30; }
.sidebar-backdrop.show { display: block; }

@media (max-width: 767px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0;
    width: 280px; z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: var(--shadow);
    border-right: 1px solid var(--border);
  }
  .sidebar.open { transform: translateX(0); }
  .only-mobile { display: inline-flex; }
  .topbar { padding: 8px 10px; }
  .chat { padding: 14px 14px 8px; }
  .banner { margin: 0 14px 4px; }
  .composer-wrap { padding: 6px 12px 12px; }
}

/* ===================== PROJECT WORKSPACE (coding agent) ===================== */
.project-label { display: flex; align-items: center; justify-content: space-between; padding-right: 12px; }
.project-label[hidden], .ws-panel[hidden], .ws-tree[hidden], .ws-auto[hidden], .ws-mini[hidden] { display: none !important; }
.ws-mini {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; border-radius: 6px; border: 0; background: transparent;
  color: var(--dim); cursor: pointer;
}
.ws-mini:hover { background: var(--border); color: var(--danger); }
.ws-panel { padding: 0 8px 6px; display: flex; flex-direction: column; gap: 6px; }
.ws-open {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px; border-radius: 10px; border: 1px dashed var(--border-strong);
  background: transparent; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer;
  text-align: left;
}
.ws-open:hover { background: var(--surface-2); color: var(--text); }
.ws-open.open { border-style: solid; border-color: var(--border); background: var(--surface-2); color: var(--text); font-weight: 600; }
.ws-open.needs-permission { border-color: var(--accent); }
.ws-open span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ws-note { font-size: 11.5px; color: var(--dim); padding: 0 4px; }
.ws-tree {
  max-height: 34vh; overflow: auto; padding: 2px 0;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.6; color: var(--muted);
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
}
.ws-tree .n { display: flex; align-items: center; gap: 4px; padding: 0 6px; white-space: nowrap; cursor: default; }
.ws-tree .n.dir { cursor: pointer; }
.ws-tree .n:hover { background: var(--surface-2); color: var(--text); }
.ws-tree .n .tw { width: 10px; flex-shrink: 0; color: var(--dim); font-size: 9px; }
.ws-tree .n.file .tw { visibility: hidden; }
.ws-tree .kids { display: none; }
.ws-tree .kids.open { display: block; }
.ws-tree .empty { padding: 6px 8px; color: var(--dim); }
.ws-auto { display: flex; align-items: center; gap: 6px; padding: 0 6px; font-size: 12px; color: var(--muted); cursor: pointer; user-select: none; }
.ws-auto input { accent-color: var(--accent); }

/* tool call cards inside an assistant reply */
.tool-cards { display: flex; flex-direction: column; gap: 6px; margin: 4px 0 8px; }
.tool-card {
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  font-size: 12.5px; overflow: hidden;
}
.tool-card > summary {
  display: flex; align-items: center; gap: 8px; padding: 7px 10px;
  cursor: pointer; list-style: none; color: var(--muted); user-select: none;
}
.tool-card > summary::-webkit-details-marker { display: none; }
.tool-card > summary .tc-name { font-family: var(--mono); font-weight: 600; color: var(--text); }
.tool-card > summary .tc-arg { font-family: var(--mono); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-card > summary .tc-state { font-size: 11px; flex-shrink: 0; }
.tool-card.running > summary .tc-state { color: var(--muted); }
.tool-card.ok > summary .tc-state { color: var(--success); }
.tool-card.error > summary .tc-state { color: var(--danger); }
.tool-card.denied > summary .tc-state { color: var(--dim); }
.tool-card.running > summary .tc-state::after { content: "…"; }
.tool-card .tc-body { border-top: 1px solid var(--border); background: var(--surface-2); }
.tool-card pre {
  margin: 0; padding: 8px 10px; max-height: 320px; overflow: auto;
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5; color: var(--text);
  white-space: pre; tab-size: 4;
}
.tool-card .tc-label { padding: 5px 10px 0; font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }

/* unified diff colouring (tool cards + permission modal) */
.diff .add { color: #067647; background: rgba(16, 185, 129, 0.10); display: block; }
.diff .del { color: #b42318; background: rgba(239, 68, 68, 0.10); display: block; }
.diff .hunk { color: var(--dim); display: block; }
.modal-diff {
  margin: 4px 0 0; padding: 8px 10px; max-height: 45vh; overflow: auto;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.5; color: var(--text); white-space: pre;
}
.modal.wide { max-width: min(760px, 92vw); }
.modal-btn.primary { background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); }
.modal-btn.primary:hover { background: var(--accent-hover); }

/* model menu: capability tag */
.model-menu li .tag {
  margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}

/* idle composer: keep the hidden Stop button hidden (class rule was overriding the attribute) */
.send-btn[hidden] { display: none !important; }
