/* ==========================================================================
   Calopic web chat — modern full-screen app layout
   Design: neutral graphite glass, restrained accent, generous rhythm.
   All ids / classes consumed by chat-app.js are preserved.
   ========================================================================== */

:root {
  --ca-side-w: 272px;
  --ca-side-w-collapsed: 64px;
  --ca-bg: #0b0d11;
  --ca-panel: #101318;
  --ca-panel-2: #171b21;
  --ca-panel-3: #1d2229;
  --ca-line: rgba(255, 255, 255, 0.08);
  --ca-line-strong: rgba(255, 255, 255, 0.14);
  --ca-hair: rgba(255, 255, 255, 0.07);
  --ca-hair-strong: rgba(255, 255, 255, 0.13);
  --ca-text: #edf0f5;
  --ca-dim: #9aa1ad;
  --ca-faint: #676e7a;
  --ca-accent: #dfe7f2;
  --ca-accent-ink: #0b0d11;
  --ca-accent-soft: rgba(223, 231, 242, 0.1);
  --ca-accent-line: rgba(223, 231, 242, 0.32);
  --ca-glass: rgba(16, 19, 24, 0.72);
  --ca-radius: 14px;
  --ca-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; overflow: hidden; }

.ca-body {
  background: var(--ca-bg);
  color: var(--ca-text);
  font: 15px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", Inter, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ------------------------------------------------------------------ gate */
.ca-gate {
  height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(900px 520px at 50% -14%, rgba(150, 172, 206, 0.12), transparent 70%),
    var(--ca-bg);
}
.ca-gate[hidden] { display: none; }

.ca-gate-card {
  width: min(410px, 100%);
  padding: 38px 32px 30px;
  border: 1px solid var(--ca-line-strong);
  border-radius: 22px;
  background: var(--ca-glass);
  backdrop-filter: blur(30px) saturate(140%);
  -webkit-backdrop-filter: blur(30px) saturate(140%);
  box-shadow: var(--ca-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.07);
}
.ca-gate-brand {
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 26px; color: var(--ca-text);
  font-size: 17px; font-weight: 650; letter-spacing: -0.01em;
  text-decoration: none;
}
.ca-gate-card h1 {
  font-size: 25px; line-height: 1.2; letter-spacing: -0.03em;
  margin: 0 0 7px; font-weight: 650;
}
.ca-gate-sub { margin: 0 0 24px; color: var(--ca-dim); font-size: 14px; }
.ca-field { display: block; margin-bottom: 15px; }
.ca-field > span { display: block; font-size: 12.5px; color: var(--ca-dim); margin-bottom: 7px; }
.ca-field input {
  width: 100%; height: 46px; padding: 0 14px;
  border: 1px solid var(--ca-line); border-radius: 12px;
  background: rgba(255, 255, 255, 0.035); color: var(--ca-text);
  font-family: inherit; font-size: 15px;
  transition: border-color 160ms, background 160ms, box-shadow 160ms;
}
.ca-field input:hover { background: rgba(255, 255, 255, 0.05); }
.ca-field input:focus {
  outline: none; border-color: var(--ca-accent-line);
  background: rgba(255, 255, 255, 0.055);
  box-shadow: 0 0 0 3px var(--ca-accent-soft);
}
.ca-submit {
  width: 100%; height: 47px; margin-top: 8px;
  border: 0; border-radius: 12px;
  background: var(--ca-accent); color: var(--ca-accent-ink);
  font-family: inherit; font-size: 15px; font-weight: 650;
  cursor: pointer; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  transition: background 160ms, transform 160ms;
}
.ca-submit:hover:not(:disabled) { background: #eef3fa; transform: translateY(-1px); }
.ca-submit:disabled { opacity: 0.55; cursor: default; }
.ca-link {
  display: block; width: 100%; margin-top: 16px; padding: 6px;
  border: 0; background: none; color: var(--ca-dim);
  font-family: inherit; font-size: 13px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 3px;
}
.ca-link:hover { color: var(--ca-text); }
.ca-error { margin: 4px 0 0; color: #e5786f; font-size: 13px; }
.ca-error[hidden] { display: none; }

/* ------------------------------------------------------------------- app */
.ca-app {
  display: grid;
  grid-template-columns: var(--ca-side-w) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  height: 100dvh; min-height: 0; overflow: hidden;
  transition: grid-template-columns 200ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.ca-app[hidden] { display: none; }
.ca-app.ca-collapsed { grid-template-columns: var(--ca-side-w-collapsed) minmax(0, 1fr); }

/* --------------------------------------------------------------- sidebar */
.ca-side {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--ca-glass);
  border-inline-end: 1px solid var(--ca-line);
  backdrop-filter: blur(28px) saturate(135%);
  -webkit-backdrop-filter: blur(28px) saturate(135%);
  overflow: hidden;
}
.ca-side-head {
  display: flex; align-items: center; gap: 8px;
  padding: 16px 12px 10px 16px;
}
.ca-logo {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; flex: 1; color: var(--ca-text);
  font-size: 15.5px; font-weight: 650; letter-spacing: -0.02em;
  text-decoration: none;
}
.ca-logo img { flex: none; }
.ca-logo span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ca-icon {
  display: grid; place-items: center;
  width: 32px; height: 32px; flex: none;
  border: 0; border-radius: 9px;
  background: transparent; color: var(--ca-dim); cursor: pointer;
  transition: background 140ms, color 140ms;
}
.ca-icon:hover { background: rgba(255, 255, 255, 0.07); color: var(--ca-text); }

.ca-new {
  display: flex; align-items: center; gap: 10px;
  margin: 4px 12px 12px; padding: 11px 13px;
  border: 1px solid var(--ca-line); border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--ca-text); font-family: inherit; font-size: 14px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background 160ms, border-color 160ms, transform 160ms;
}
.ca-new:hover {
  background: rgba(255, 255, 255, 0.075); border-color: var(--ca-accent-line);
  transform: translateY(-1px);
}
.ca-new svg { flex: none; }

.ca-threads { flex: 1; min-height: 0; overflow-y: auto; padding: 2px 8px 10px; }
.ca-group-label {
  padding: 12px 10px 5px; font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.1em; text-transform: uppercase; color: var(--ca-faint);
}
.ca-thread {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 9px 10px;
  border: 0; border-radius: 10px; background: transparent;
  color: var(--ca-dim); font-family: inherit; font-size: 13.5px;
  text-align: start; cursor: pointer;
  transition: background 140ms, color 140ms;
}
.ca-thread:hover { background: rgba(255, 255, 255, 0.05); color: var(--ca-text); }
.ca-thread.is-active {
  background: rgba(255, 255, 255, 0.075); color: #f4f7fb; font-weight: 550;
  box-shadow: inset 2px 0 0 var(--ca-accent);
}
.ca-thread-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-thread-del {
  flex: none; width: 20px; height: 20px; display: none; place-items: center;
  border: 0; border-radius: 5px; background: transparent;
  color: var(--ca-faint); cursor: pointer;
}
.ca-thread:hover .ca-thread-del { display: grid; }
.ca-thread-del:hover { background: rgba(229, 120, 111, 0.16); color: #e5786f; }

.ca-side-foot { padding: 8px; border-top: 1px solid var(--ca-line); }
.ca-user {
  display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0;
  padding: 8px 9px; border-radius: 10px;
  color: inherit; text-decoration: none; cursor: pointer;
  transition: background 120ms;
}
.ca-user:hover { background: rgba(255, 255, 255, 0.055); }
.ca-avatar {
  display: grid; place-items: center; width: 30px; height: 30px; flex: none;
  border-radius: 50%; background: var(--ca-accent-soft); color: var(--ca-accent);
  font-size: 12.5px; font-weight: 700; box-shadow: inset 0 0 0 1px var(--ca-line);
}
.ca-user-meta { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.28; }
.ca-user-name, .ca-user-email {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12.5px; color: var(--ca-text);
}
.ca-user-plan { font-size: 11px; color: var(--ca-faint); }
.ca-user-chev { flex: none; color: var(--ca-faint); opacity: 0; transition: opacity 120ms; }
.ca-user:hover .ca-user-chev { opacity: 1; }

/* collapsed rail — icons only, never let text wrap out of the rail */
.ca-app.ca-collapsed .ca-logo span,
.ca-app.ca-collapsed .ca-new span,
.ca-app.ca-collapsed .ca-threads,
.ca-app.ca-collapsed .ca-user-meta,
.ca-app.ca-collapsed .ca-user-chev,
.ca-app.ca-collapsed .ca-collapse { display: none !important; }
.ca-app.ca-collapsed .ca-side-head { justify-content: center; padding: 16px 6px 10px; }
.ca-app.ca-collapsed .ca-logo { flex: none; justify-content: center; }
.ca-app.ca-collapsed .ca-new { justify-content: center; padding: 11px; margin-inline: 9px; }
.ca-app.ca-collapsed .ca-side-foot { display: flex; justify-content: center; padding: 9px 6px; }
.ca-app.ca-collapsed .ca-user { flex: none; width: 38px; height: 38px; padding: 0; justify-content: center; }
.ca-app.ca-collapsed .ca-avatar { width: 30px; height: 30px; }

/* ------------------------------------------------------------------ main */
.ca-main {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0; overflow: hidden;
  background: transparent;
}
.ca-topbar {
  display: flex; align-items: center; gap: 10px;
  height: 56px; flex: none; padding: 0 20px;
  border-bottom: 1px solid var(--ca-line);
  background: linear-gradient(180deg, rgba(11, 13, 17, 0.66), rgba(11, 13, 17, 0));
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.ca-expand { display: none; }
.ca-app.ca-collapsed .ca-expand { display: grid; }
.ca-thread-title {
  margin: 0; font-size: 14px; font-weight: 550; color: var(--ca-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.ca-topbar-spacer { flex: 1; }
.ca-model-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border: 1px solid var(--ca-line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 11.5px; color: var(--ca-dim); white-space: nowrap;
}
.ca-model-badge i {
  width: 6px; height: 6px; border-radius: 50%; background: #7fb08a;
  box-shadow: 0 0 0 3px rgba(127, 176, 138, 0.14);
}

.ca-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }

/* welcome */
.ca-welcome {
  max-width: 780px; margin: 0 auto;
  padding: clamp(38px, 13vh, 132px) 22px 30px; text-align: center;
}
.ca-welcome[hidden] { display: none; }
.ca-welcome-mark {
  display: grid; place-items: center; width: 52px; height: 52px;
  margin: 0 auto 22px; border-radius: 16px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--ca-line-strong);
  box-shadow: 0 12px 34px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.09);
}
.ca-welcome h1 {
  font-size: clamp(26px, 3.4vw, 36px); font-weight: 620;
  letter-spacing: -0.04em; margin: 0 0 8px; color: #eef2f8;
}
.ca-welcome-sub { margin: 0 0 32px; color: var(--ca-faint); font-size: 14px; }
.ca-suggestions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.ca-sugg {
  display: grid; gap: 3px; padding: 15px 16px;
  border: 1px solid var(--ca-line); border-radius: 14px;
  background: rgba(255, 255, 255, 0.025);
  color: var(--ca-text); font-family: inherit; text-align: start; cursor: pointer;
  transition: background 160ms, border-color 160ms, transform 160ms, box-shadow 160ms;
}
.ca-sugg:hover {
  background: rgba(255, 255, 255, 0.06); border-color: var(--ca-line-strong);
  transform: translateY(-2px); box-shadow: 0 14px 32px rgba(0, 0, 0, 0.32);
}
.ca-sugg-title { font-size: 13.5px; font-weight: 600; letter-spacing: -0.01em; }
.ca-sugg-sub { font-size: 12.5px; color: var(--ca-faint); line-height: 1.5; }

/* messages */
.ca-messages {
  max-width: 780px; margin: 0 auto;
  padding: 26px 22px 12px;
  display: flex; flex-direction: column; gap: 26px;
}
.ca-msg { display: flex; gap: 14px; }
.ca-msg-user { justify-content: flex-end; }
.ca-msg-body {
  max-width: 100%; white-space: pre-wrap; word-break: break-word;
  font-size: 15px; line-height: 1.75;
}
.ca-msg-user .ca-msg-body {
  max-width: 78%; padding: 11px 16px; border-radius: 18px 18px 5px 18px;
  background: rgba(255, 255, 255, 0.075); border: 1px solid var(--ca-hair);
  backdrop-filter: blur(18px) saturate(130%); -webkit-backdrop-filter: blur(18px) saturate(130%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}
.ca-msg-assistant .ca-msg-body { flex: 1; min-width: 0; padding-top: 3px; }
.ca-msg-body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; padding: 1px 5px; border-radius: 5px;
  background: rgba(160, 176, 200, 0.13); border: 1px solid var(--ca-hair);
}
.ca-msg-body pre {
  margin: 12px 0; padding: 14px 16px; overflow-x: auto;
  background: rgba(8, 10, 14, 0.72); border: 1px solid var(--ca-hair);
  border-radius: 12px; white-space: pre;
}
.ca-msg-body pre code { background: none; border: 0; padding: 0; font-size: 12.5px; line-height: 1.65; }
.ca-msg-body .ca-li { display: block; padding-left: 4px; }
.ca-msg-avatar {
  width: 28px; height: 28px; flex: none; border-radius: 9px;
  display: grid; place-items: center; margin-top: 2px;
  background: var(--ca-accent-soft); box-shadow: inset 0 0 0 1px var(--ca-hair);
}
.ca-msg-avatar img { width: 16px; height: 16px; }

/* source citations */
.ca-sources { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.ca-source {
  display: inline-flex; align-items: center; max-width: 260px;
  padding: 6px 12px; border: 1px solid var(--ca-line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.035); color: var(--ca-dim);
  font-size: 11.5px; text-decoration: none;
  transition: background 140ms, color 140ms, border-color 140ms;
}
.ca-source:hover { background: rgba(255, 255, 255, 0.075); color: var(--ca-text); border-color: var(--ca-line-strong); }
.ca-source-host { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ca-sources-label {
  width: 100%; font-size: 10.5px; font-weight: 600; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--ca-faint); margin-bottom: 2px;
}

.ca-typing { display: inline-flex; gap: 5px; padding: 6px 0; }
.ca-typing i {
  width: 6px; height: 6px; border-radius: 50%; background: var(--ca-dim);
  animation: ca-bounce 1.1s infinite ease-in-out;
}
.ca-typing i:nth-child(2) { animation-delay: 0.15s; }
.ca-typing i:nth-child(3) { animation-delay: 0.3s; }
@keyframes ca-bounce {
  0%, 80%, 100% { opacity: 0.35; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* composer */
.ca-composer-wrap {
  flex: none; padding: 8px 22px calc(16px + env(safe-area-inset-bottom));
  background: linear-gradient(180deg, rgba(11, 13, 17, 0), rgba(11, 13, 17, 0.86) 42%);
}
.ca-composer {
  max-width: 780px; margin: 0 auto; padding: 12px 12px 10px 18px;
  border: 1px solid var(--ca-line-strong); border-radius: 22px;
  background: rgba(25, 29, 36, 0.6);
  backdrop-filter: blur(32px) saturate(150%); -webkit-backdrop-filter: blur(32px) saturate(150%);
  box-shadow: var(--ca-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
  transition: border-color 180ms, box-shadow 180ms;
}
.ca-composer:focus-within {
  border-color: var(--ca-accent-line);
  box-shadow: var(--ca-shadow), 0 0 0 3px var(--ca-accent-soft), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}
.ca-input {
  display: block; width: 100%; min-height: 26px; max-height: 220px;
  padding: 3px 0 8px; border: 0; background: transparent;
  color: var(--ca-text); font-family: inherit; font-size: 15px; line-height: 1.6;
  resize: none; outline: none;
}
.ca-input::placeholder { color: var(--ca-faint); }
.ca-composer-row { display: flex; align-items: center; gap: 8px; }
.ca-tool {
  display: inline-flex; align-items: center; gap: 7px; height: 32px; padding: 0 12px;
  border: 1px solid var(--ca-line); border-radius: 999px;
  background: rgba(255, 255, 255, 0.025); color: var(--ca-dim);
  font-family: inherit; font-size: 12.5px; cursor: pointer;
  transition: color 140ms, border-color 140ms, background 140ms;
}
.ca-tool:hover { color: var(--ca-text); border-color: var(--ca-line-strong); }
.ca-tool[aria-pressed="true"] {
  background: var(--ca-accent-soft); border-color: var(--ca-accent-line); color: var(--ca-accent);
}
.ca-tool svg { flex: none; }
.ca-spacer { flex: 1; }
.ca-send {
  display: grid; place-items: center; width: 34px; height: 34px;
  border: 0; border-radius: 50%; background: var(--ca-accent);
  color: var(--ca-accent-ink); cursor: pointer;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.38);
  transition: background 160ms, transform 160ms, box-shadow 160ms;
}
.ca-send:hover:not(:disabled) {
  background: #eef3fa; transform: scale(1.06); box-shadow: 0 10px 24px rgba(0, 0, 0, 0.45);
}
.ca-send:disabled { opacity: 0.4; cursor: default; }
.ca-disclaimer {
  max-width: 780px; margin: 9px auto 0; text-align: center;
  font-size: 11.5px; color: var(--ca-faint); letter-spacing: 0.01em;
}

.ca-scrim { display: none; }

/* scrollbars */
.ca-threads::-webkit-scrollbar, .ca-scroll::-webkit-scrollbar { width: 9px; }
.ca-threads::-webkit-scrollbar-thumb, .ca-scroll::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1); border: 2px solid transparent;
  background-clip: padding-box; border-radius: 6px;
}
.ca-threads::-webkit-scrollbar-thumb:hover, .ca-scroll::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.18); background-clip: padding-box;
}

/* ------------------------------------------------------------- phone */
@media (max-width: 760px) {
  .ca-app { grid-template-columns: minmax(0, 1fr); }
  .ca-side {
    position: fixed; inset: 0 auto 0 0; width: min(86vw, 310px); z-index: 40;
    transform: translateX(-100%); transition: transform 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
    background: rgba(15, 18, 23, 0.96); box-shadow: 0 0 60px rgba(0, 0, 0, 0.7);
  }
  .ca-app.ca-mobile-open .ca-side { transform: translateX(0); }
  .ca-app.ca-collapsed { grid-template-columns: minmax(0, 1fr); }
  .ca-app.ca-collapsed .ca-threads,
  .ca-app.ca-collapsed .ca-logo span,
  .ca-app.ca-collapsed .ca-new span,
  .ca-app.ca-collapsed .ca-user-meta,
  .ca-app.ca-collapsed .ca-user-chev { display: revert !important; }
  .ca-app.ca-collapsed .ca-user-meta { display: flex !important; }
  .ca-app.ca-collapsed .ca-side-head { justify-content: flex-start; }
  .ca-app.ca-collapsed .ca-new { justify-content: flex-start; }
  .ca-app.ca-collapsed .ca-side-foot { justify-content: flex-start; }
  .ca-app.ca-collapsed .ca-user { width: auto; height: auto; padding: 8px 9px; }
  .ca-expand { display: grid !important; }
  .ca-collapse { display: grid; }
  .ca-app.ca-mobile-open .ca-scrim {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, 0.5);
  }
  .ca-topbar { padding: 0 14px; }
  .ca-welcome { padding: 40px 18px 22px; }
  .ca-suggestions { grid-template-columns: 1fr; }
  .ca-messages { padding: 18px 16px 8px; gap: 22px; }
  .ca-msg-user .ca-msg-body { max-width: 88%; }
  .ca-composer-wrap { padding: 6px 12px calc(10px + env(safe-area-inset-bottom)); }
  .ca-composer { padding: 9px 9px 7px 14px; border-radius: 20px; }
  .ca-input { font-size: 16px; }
  .ca-tool span { display: none; }
  .ca-tool { width: 34px; justify-content: center; padding: 0; }
}
