/* ════════════════════════════════════════════════════════════
   James — warm, refined chat UI
   Type: Fraunces (display) + Hanken Grotesk (body) + JetBrains Mono
   Palette: ivory ground, warm ink, terracotta accent
   ════════════════════════════════════════════════════════════ */

:root {
  /* ground */
  --bg: #f3f0e8;
  --bg-deep: #ebe7dc;
  --surface: #fdfcf9;
  --surface-soft: #f8f6f0;

  /* ink */
  --ink: #2b2620;
  --ink-soft: #6e655a;
  --ink-faint: #a39a8c;

  /* accent */
  --terra: #c25e3d;
  --terra-deep: #a84e31;
  --terra-tint: #f4e3db;
  --terra-faint: rgba(194, 94, 61, 0.08);

  /* semantic */
  --green: #5d7d52;
  --green-tint: #e4eadf;
  --amber: #ad7e2e;
  --amber-tint: #f3ead7;
  --red: #b04a3a;
  --red-tint: #f3e0dc;

  --border: #ddd6c8;
  --border-soft: #e8e2d5;

  --shadow-sm: 0 1px 2px rgba(43, 38, 32, 0.05);
  --shadow-md: 0 2px 8px rgba(43, 38, 32, 0.07), 0 1px 2px rgba(43, 38, 32, 0.05);
  --shadow-lg: 0 12px 40px rgba(43, 38, 32, 0.13), 0 2px 8px rgba(43, 38, 32, 0.06);

  --serif: 'Fraunces', Georgia, 'Times New Roman', serif;
  --sans: 'Hanken Grotesk', -apple-system, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;

  --r-sm: 8px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-pill: 999px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.hidden { display: none !important; }

::selection { background: var(--terra-tint); color: var(--terra-deep); }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--ink-faint); }

/* ── Buttons ─────────────────────────────────────────────── */

.btn-primary {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #fdfcf9;
  background: var(--terra);
  border: none;
  border-radius: var(--r-pill);
  padding: 10px 22px;
  cursor: pointer;
  transition: background 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
  box-shadow: var(--shadow-sm);
}
.btn-primary:hover { background: var(--terra-deep); box-shadow: var(--shadow-md); }
.btn-primary:active { transform: scale(0.985); }
.btn-primary:disabled { opacity: 0.55; cursor: wait; transform: none; }

.btn-ghost {
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-soft);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 9px 18px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.btn-ghost:hover { border-color: var(--ink-faint); color: var(--ink); background: var(--surface); }

/* ════════════════════════════════════════════════════════════
   LOGIN
   ════════════════════════════════════════════════════════════ */

.login-page {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1100px 700px at 75% -10%, rgba(194, 94, 61, 0.10), transparent 60%),
    radial-gradient(900px 600px at 0% 110%, rgba(93, 125, 82, 0.07), transparent 55%),
    var(--bg);
  overflow: hidden;
}

/* subtle paper grain */
.login-grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: 0.5;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0.17 0 0 0 0 0.15 0 0 0 0 0.12 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 24px;
  padding: 48px 44px 40px;
  box-shadow: var(--shadow-lg);
  animation: rise 0.55s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}

.login-mark {
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 28px;
  font-weight: 600;
  color: #fdfcf9;
  background: var(--terra);
  border-radius: 16px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-md);
}

.login-title {
  font-family: var(--serif);
  font-size: 38px;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--ink-soft);
  font-size: 15px;
  margin-bottom: 32px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  font-family: var(--sans);
  font-size: 15px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.form-group input:focus {
  border-color: var(--terra);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--terra-faint);
}

#login-btn { width: 100%; padding: 12px; margin-top: 8px; font-size: 15px; }

.login-error {
  margin-top: 14px;
  min-height: 18px;
  font-size: 13.5px;
  color: var(--red);
  text-align: center;
}

/* ════════════════════════════════════════════════════════════
   APP SHELL
   ════════════════════════════════════════════════════════════ */

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

.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 60;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  width: 296px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-deep);
  border-right: 1px solid var(--border-soft);
}

.sidebar-header { padding: 20px 18px 14px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-size: 18px;
  font-weight: 600;
  color: #fdfcf9;
  background: var(--terra);
  border-radius: 10px;
}

.brand-name {
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 500;
  letter-spacing: -0.01em;
}

.btn-new-ticket {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: var(--sans);
  font-size: 14px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 11px;
  cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
  box-shadow: var(--shadow-sm);
}
.btn-new-ticket:hover { border-color: var(--terra); color: var(--terra-deep); box-shadow: var(--shadow-md); }
.btn-new-ticket:active { transform: scale(0.99); }

.tickets-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px 12px;
}

.empty-state {
  text-align: center;
  color: var(--ink-faint);
  font-size: 13.5px;
  padding: 36px 12px;
}

.ticket-item {
  padding: 12px 13px;
  border-radius: var(--r-md);
  border: 1px solid transparent;
  cursor: pointer;
  margin-bottom: 4px;
  transition: background 0.13s ease, border-color 0.13s ease;
}
.ticket-item:hover { background: rgba(253, 252, 249, 0.65); }
.ticket-item.active {
  background: var(--surface);
  border-color: var(--border-soft);
  box-shadow: var(--shadow-sm);
}

.ticket-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.ticket-item-key {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
}

.mini-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  padding: 2.5px 8px;
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--border-soft);
  white-space: nowrap;
}
.mini-badge.gathering   { color: var(--ink-soft); }
.mini-badge.ready       { color: var(--amber); background: var(--amber-tint); border-color: transparent; }
.mini-badge.confirmed,
.mini-badge.in_progress { color: var(--terra-deep); background: var(--terra-tint); border-color: transparent; }
.mini-badge.in_review   { color: var(--amber); background: var(--amber-tint); border-color: transparent; }
.mini-badge.completed   { color: var(--green); background: #e4eadf; border-color: transparent; }
.mini-badge.closed      { color: var(--ink-soft); background: var(--bg-deep); border-color: transparent; }
.mini-badge.failed      { color: var(--red); background: var(--red-tint); border-color: transparent; }

.ticket-item-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ticket-item-preview {
  font-size: 12.5px;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-footer {
  border-top: 1px solid var(--border-soft);
  padding: 12px 16px 14px;
}

.agent-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-soft);
  padding: 4px 2px 10px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ink-faint);
  flex-shrink: 0;
}
.status-dot.running { background: var(--green); box-shadow: 0 0 0 3px rgba(93, 125, 82, 0.18); animation: breathe 2.4s ease-in-out infinite; }
.status-dot.paused  { background: var(--amber); }
.status-dot.error   { background: var(--red); }

@keyframes breathe {
  0%, 100% { box-shadow: 0 0 0 3px rgba(93, 125, 82, 0.18); }
  50%      { box-shadow: 0 0 0 5px rgba(93, 125, 82, 0.08); }
}

.admin-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.admin-avatar {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink-soft);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 50%;
  text-transform: uppercase;
}

.admin-name {
  flex: 1;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-logout {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.btn-logout:hover { color: var(--red); background: var(--red-tint); }

/* ════════════════════════════════════════════════════════════
   CHAT AREA
   ════════════════════════════════════════════════════════════ */

.chat-area {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

/* ── Welcome ─────────────────────────────────────────────── */

.welcome-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
}

.welcome-inner {
  max-width: 480px;
  text-align: center;
  animation: rise 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.welcome-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin: 0 auto 24px;
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 600;
  color: #fdfcf9;
  background: var(--terra);
  border-radius: 20px;
  box-shadow: var(--shadow-md);
}

.welcome-title {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 500;
  letter-spacing: -0.015em;
  margin-bottom: 12px;
}

.welcome-sub {
  color: var(--ink-soft);
  font-size: 15.5px;
  line-height: 1.65;
  margin-bottom: 28px;
}

/* ── Header ──────────────────────────────────────────────── */

.active-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: rgba(243, 240, 232, 0.85);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-soft);
}

.chat-header-info {
  display: flex;
  align-items: baseline;
  gap: 12px;
  min-width: 0;
}

.chat-ticket-key {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--terra-deep);
  background: var(--terra-tint);
  padding: 3px 9px;
  border-radius: var(--r-pill);
  white-space: nowrap;
}
.chat-ticket-key:empty { display: none; }

.chat-title {
  font-family: var(--serif);
  font-size: 17px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-status-badge {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: var(--r-pill);
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border-soft);
}
.chat-status-badge.ready       { color: var(--amber); background: var(--amber-tint); border-color: transparent; }
.chat-status-badge.confirmed,
.chat-status-badge.in_progress { color: var(--terra-deep); background: var(--terra-tint); border-color: transparent; }
.chat-status-badge.in_review   { color: var(--amber); background: var(--amber-tint); border-color: transparent; }
.chat-status-badge.completed   { color: var(--green); background: #e4eadf; border-color: transparent; }
.chat-status-badge.closed      { color: var(--ink-soft); background: var(--bg-deep); border-color: transparent; }
.chat-status-badge.failed      { color: var(--red); background: var(--red-tint); border-color: transparent; }

/* ── Stage bar ───────────────────────────────────────────── */

.stage-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 28px;
  font-size: 13px;
  font-weight: 600;
  color: var(--terra-deep);
  background: linear-gradient(90deg, var(--terra-tint), rgba(244, 227, 219, 0.4));
  border-bottom: 1px solid var(--border-soft);
}
.stage-bar.completed { color: var(--green); background: #e4eadf; }
.stage-bar.failed    { color: var(--red); background: var(--red-tint); }
.stage-bar.question_pending { color: var(--amber); background: var(--amber-tint); }

.stage-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: pulse-dot 1.4s ease-in-out infinite;
}

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

/* ── Messages ────────────────────────────────────────────── */

.messages-scroll {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.messages {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 24px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-row {
  display: flex;
  gap: 12px;
  padding: 8px 0;
  animation: msg-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}

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

.msg-row.admin { flex-direction: row-reverse; }

.msg-avatar {
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  border-radius: 50%;
  margin-top: 2px;
}
.msg-avatar.agent {
  font-family: var(--serif);
  font-size: 16px;
  color: #fdfcf9;
  background: var(--terra);
}
.msg-avatar.admin {
  color: var(--ink-soft);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  text-transform: uppercase;
}

.msg-body { max-width: 82%; min-width: 0; }
.msg-row.admin .msg-body { display: flex; flex-direction: column; align-items: flex-end; }

.msg-bubble {
  padding: 12px 16px;
  border-radius: var(--r-lg);
  font-size: 15px;
  line-height: 1.6;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.msg-row.agent .msg-bubble {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-top-left-radius: 6px;
  box-shadow: var(--shadow-sm);
}

.msg-row.admin .msg-bubble {
  background: #e9e2d2;
  border-top-right-radius: 6px;
  color: var(--ink);
}

.msg-time {
  font-size: 11px;
  color: var(--ink-faint);
  padding: 4px 6px 0;
}

/* system + question rows: centered, quiet */
.msg-row.system {
  justify-content: center;
  padding: 4px 0;
}
.msg-row.system .msg-bubble {
  max-width: 90%;
  font-size: 13px;
  color: var(--ink-soft);
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  padding: 8px 14px;
  text-align: left;
}

.msg-row.question .msg-bubble {
  background: var(--amber-tint);
  border: 1px solid rgba(173, 126, 46, 0.25);
  border-top-left-radius: 6px;
}
.msg-row.question .msg-avatar { background: var(--amber); color: #fdfcf9; font-family: var(--serif); }

/* ── Markdown inside bubbles ─────────────────────────────── */

.msg-bubble p { margin: 0 0 10px; }
.msg-bubble p:last-child { margin-bottom: 0; }

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.3;
  margin: 14px 0 6px;
}
.msg-bubble h1:first-child, .msg-bubble h2:first-child, .msg-bubble h3:first-child { margin-top: 0; }
.msg-bubble h1 { font-size: 19px; }
.msg-bubble h2 { font-size: 17px; }
.msg-bubble h3 { font-size: 15.5px; }

.msg-bubble ul, .msg-bubble ol { margin: 6px 0 10px; padding-left: 22px; }
.msg-bubble li { margin: 3px 0; }

.msg-bubble a { color: var(--terra-deep); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.msg-bubble a:hover { color: var(--terra); }

.msg-bubble blockquote {
  margin: 8px 0;
  padding: 4px 14px;
  border-left: 3px solid var(--terra);
  color: var(--ink-soft);
}

.msg-bubble code {
  font-family: var(--mono);
  font-size: 0.86em;
  background: rgba(43, 38, 32, 0.06);
  border-radius: 5px;
  padding: 1.5px 6px;
}

.msg-bubble pre {
  margin: 10px 0;
  background: #2b2620;
  border-radius: 12px;
  overflow: hidden;
}
.msg-bubble pre .code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: var(--mono);
  font-size: 11px;
  color: #a39a8c;
  background: rgba(253, 252, 249, 0.06);
  padding: 7px 14px;
}
.msg-bubble pre .code-copy {
  font-family: var(--sans);
  font-size: 11px;
  font-weight: 600;
  color: #a39a8c;
  background: none;
  border: none;
  cursor: pointer;
}
.msg-bubble pre .code-copy:hover { color: #fdfcf9; }
.msg-bubble pre code {
  display: block;
  background: none;
  color: #ece7dc;
  font-size: 13px;
  line-height: 1.6;
  padding: 12px 14px;
  overflow-x: auto;
}

.msg-bubble hr { border: none; border-top: 1px solid var(--border-soft); margin: 12px 0; }

.msg-bubble strong { font-weight: 700; }

/* ── Attachments in messages ─────────────────────────────── */

.msg-attachment-file,
.msg-attachment-img {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: rgba(43, 38, 32, 0.05);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 6px 11px;
  margin: 0 6px 8px 0;
  word-break: break-all;
}

.msg-attachment-img { display: block; padding: 0; border: none; background: none; }
.msg-img-preview {
  max-width: 320px;
  max-height: 240px;
  border-radius: 12px;
  border: 1px solid var(--border-soft);
  display: block;
  margin-bottom: 8px;
  box-shadow: var(--shadow-sm);
}

/* ── Typing indicator ────────────────────────────────────── */

.typing-indicator {
  max-width: 760px;
  margin: 0 auto;
  padding: 4px 24px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.typing-dots {
  display: inline-flex;
  gap: 5px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  border-top-left-radius: 6px;
  padding: 14px 18px;
  box-shadow: var(--shadow-sm);
}
.typing-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%           { transform: translateY(-5px); opacity: 1; }
}

/* ── Composer ────────────────────────────────────────────── */

.composer-zone {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 8px 24px 14px;
}

.question-hint {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--amber);
  background: var(--amber-tint);
  border: 1px solid rgba(173, 126, 46, 0.25);
  border-radius: var(--r-md);
  padding: 10px 14px;
  margin-bottom: 10px;
  animation: rise 0.3s ease both;
}
.hint-icon {
  width: 20px;
  height: 20px;
  display: grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 600;
  color: #fdfcf9;
  background: var(--amber);
  border-radius: 50%;
  flex-shrink: 0;
}

.confirm-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--terra);
  border-radius: var(--r-lg);
  padding: 16px 20px;
  margin-bottom: 10px;
  box-shadow: var(--shadow-md);
  animation: rise 0.35s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.confirm-eyebrow {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--terra-deep);
  margin-bottom: 3px;
}

.confirm-copy { flex: 1; min-width: 200px; }
.confirm-copy p { font-size: 14.5px; font-weight: 500; }

.confirm-actions { display: flex; gap: 8px; }

.pending-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 4px 8px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 5px 7px 5px 12px;
  animation: rise 0.25s ease both;
}
.attachment-chip .chip-remove {
  display: grid;
  place-items: center;
  width: 18px;
  height: 18px;
  font-size: 13px;
  line-height: 1;
  color: var(--ink-faint);
  background: var(--bg);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}
.attachment-chip .chip-remove:hover { color: #fdfcf9; background: var(--red); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 8px 8px 8px 6px;
  box-shadow: var(--shadow-md);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.composer:focus-within {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px var(--terra-faint), var(--shadow-md);
}

.btn-attach {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.btn-attach:hover { color: var(--terra-deep); background: var(--terra-faint); }
.btn-attach:disabled { opacity: 0.5; cursor: wait; }

#chat-input {
  flex: 1;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: none;
  border: none;
  outline: none;
  resize: none;
  padding: 8px 4px;
  max-height: 200px;
}
#chat-input::placeholder { color: var(--ink-faint); }

.btn-send {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  color: #fdfcf9;
  background: var(--terra);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease, opacity 0.15s ease;
}
.btn-send:hover { background: var(--terra-deep); }
.btn-send:active { transform: scale(0.94); }
.btn-send:disabled { opacity: 0.4; cursor: default; }

.composer-note {
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-faint);
  padding-top: 8px;
}

/* ── Drag & drop overlay ─────────────────────────────────── */

.drop-overlay {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(243, 240, 232, 0.88);
  backdrop-filter: blur(3px);
}
.drop-inner {
  font-family: var(--serif);
  font-size: 22px;
  color: var(--terra-deep);
  border: 2px dashed var(--terra);
  border-radius: var(--r-lg);
  padding: 36px 56px;
  background: var(--surface);
}

/* ── Toasts ──────────────────────────────────────────────── */

.toast-stack {
  position: fixed;
  bottom: 22px;
  right: 22px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--terra);
  border-radius: var(--r-md);
  padding: 12px 18px;
  box-shadow: var(--shadow-lg);
  max-width: 340px;
  animation: toast-in 0.3s cubic-bezier(0.22, 1, 0.36, 1) both;
}
.toast.error { border-left-color: var(--red); }
.toast.leaving { animation: toast-out 0.25s ease forwards; }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateX(24px); }
}

/* ── Day divider ─────────────────────────────────────────── */

.day-divider {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.day-divider::before,
.day-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border-soft);
}

/* ════════════════════════════════════════════════════════════
   RESPONSIVE
   ════════════════════════════════════════════════════════════ */

@media (max-width: 820px) {
  .sidebar-toggle { display: flex; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.22, 1, 0.36, 1);
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }

  .chat-header { padding: 14px 16px 14px 62px; }
  .messages { padding: 20px 14px 8px; }
  .composer-zone { padding: 8px 12px 12px; }
  .msg-body { max-width: 88%; }
  .stage-bar { padding: 8px 16px 8px 62px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ── Draft delete button ─────────────────────────────────── */
.ticket-item-right {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.ticket-delete {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, background 0.12s ease;
}
.ticket-item:hover .ticket-delete { opacity: 1; }
.ticket-delete:hover { color: var(--red); background: var(--red-tint); }

/* ── Thinking state — fluid breathing ────────────────────── */
.thinking-avatar {
  animation: avatar-breathe 2.4s ease-in-out infinite;
}
@keyframes avatar-breathe {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(194, 94, 61, 0.32); }
  50%      { transform: scale(1.08); box-shadow: 0 0 0 9px rgba(194, 94, 61, 0); }
}

.thinking-bubble {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-lg);
  border-top-left-radius: 6px;
  padding: 12px 18px;
  box-shadow: var(--shadow-sm);
  animation: bubble-breathe 2.4s ease-in-out infinite;
}
@keyframes bubble-breathe {
  0%, 100% { border-color: var(--border-soft); }
  50%      { border-color: rgba(194, 94, 61, 0.35); }
}

.thinking-label {
  font-size: 13.5px;
  font-weight: 600;
  background: linear-gradient(90deg,
    var(--ink-faint) 0%, var(--ink-faint) 35%,
    var(--terra) 50%,
    var(--ink-faint) 65%, var(--ink-faint) 100%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: label-shimmer 2.2s linear infinite;
}
@keyframes label-shimmer {
  0%   { background-position: 110% 0; }
  100% { background-position: -110% 0; }
}

/* dots inside the bubble lose their own bubble styling */
.thinking-bubble .typing-dots {
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
  animation: none;
}

/* ════════════════════════════════════════════════════════════
   KNOWLEDGE (read-only overlay)
   ════════════════════════════════════════════════════════════ */

.btn-knowledge {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 9px 12px;
  margin-bottom: 8px;
  font-family: var(--sans);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.btn-knowledge:hover { color: var(--terra-deep); border-color: var(--terra); box-shadow: var(--shadow-md); }
.btn-knowledge svg { flex-shrink: 0; }

.knowledge-overlay {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 28px;
  background: rgba(43, 38, 32, 0.32);
  backdrop-filter: blur(6px);
}

.knowledge-modal {
  display: flex;
  flex-direction: column;
  width: min(1040px, 100%);
  height: min(760px, 92vh);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.knowledge-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-soft);
}
.knowledge-head-titles { display: flex; align-items: baseline; gap: 12px; margin-right: auto; }
.knowledge-title { font-family: var(--serif); font-size: 21px; font-weight: 600; }
.knowledge-sub { font-size: 12.5px; color: var(--ink-faint); }

.knowledge-head-actions { display: flex; align-items: center; gap: 8px; margin-right: 8px; }
.kb-action-btn {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--ink-faint);
  background: none;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  padding: 6px 11px;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.kb-action-btn:hover { color: var(--ink); background: var(--bg-deep); border-color: var(--border); }
.kb-action-btn:disabled { opacity: 0.5; cursor: default; }

.knowledge-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--ink-faint);
  background: none;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: color 0.15s ease, background 0.15s ease;
}
.knowledge-close:hover { color: var(--ink); background: var(--bg-deep); }

.knowledge-body { display: flex; flex: 1; min-height: 0; }

.knowledge-list-pane {
  display: flex;
  flex-direction: column;
  width: 290px;
  flex-shrink: 0;
  border-right: 1px solid var(--border-soft);
  background: var(--surface-soft);
}

.knowledge-search {
  margin: 12px;
  padding: 9px 12px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  outline: none;
}
.knowledge-search:focus { border-color: var(--terra); }

.knowledge-list { flex: 1; overflow-y: auto; padding: 0 8px 12px; }

.knowledge-group-head {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-faint);
  padding: 12px 10px 5px;
}

.knowledge-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  font-family: var(--sans);
  font-size: 13.5px;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.knowledge-item:hover { background: var(--bg); color: var(--ink); }
.knowledge-item.active { background: var(--terra-faint); color: var(--terra-deep); font-weight: 600; }
.knowledge-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.knowledge-badge {
  flex-shrink: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--green);
  background: var(--green-tint);
  border-radius: var(--r-pill);
}

.knowledge-doc-pane { flex: 1; overflow-y: auto; padding: 26px 32px; min-width: 0; }

.knowledge-empty, .knowledge-empty-list {
  color: var(--ink-faint);
  font-size: 13.5px;
  text-align: center;
  padding: 40px 16px;
}
.knowledge-empty-list { padding: 24px 10px; }

/* Reuse the chat markdown element styles, drop the bubble chrome */
.knowledge-doc-content { font-size: 14.5px; line-height: 1.6; }
.knowledge-doc-content.msg-bubble {
  max-width: none;
  background: none;
  border: none;
  border-radius: 0;
  padding: 0;
  box-shadow: none;
}

@media (max-width: 720px) {
  .knowledge-overlay { padding: 0; }
  .knowledge-modal { height: 100vh; width: 100%; border-radius: 0; }
  .knowledge-list-pane { width: 200px; }
  .knowledge-doc-pane { padding: 18px; }
}
