/* ==========================================================================
   Bakiza AI — rewritten stylesheet
   Palette: deep ink + jade.  Type: Instrument Serif (display) × Instagram Sans.
   ========================================================================== */

:root {
  --font-sans: "Instagram Sans", "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Instrument Serif", "Iowan Old Style", Georgia, serif;

  --bg: #0a0f0d;
  --bg-soft: #0e1512;
  --surface: #111917;
  --surface-2: #16201d;
  --surface-3: #1c2824;
  --line: rgba(255, 255, 255, .08);
  --line-strong: rgba(255, 255, 255, .14);

  --text: #edf4f0;
  --text-soft: #a9bbb3;
  --text-faint: #788b83;

  --accent: #4fe3a3;
  --accent-strong: #2fcf8b;
  --accent-ink: #04140d;
  --accent-soft: rgba(79, 227, 163, .12);
  --accent-ring: rgba(79, 227, 163, .32);

  --user-bubble: #1f6f52;
  --user-text: #f2fff9;

  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, .12);

  --radius: 18px;
  --radius-sm: 12px;
  --rail-w: 272px;
  --maxw: 780px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .28), 0 6px 18px -12px rgba(0, 0, 0, .5);
  --shadow-md: 0 18px 50px -24px rgba(0, 0, 0, .7);
  --ease: cubic-bezier(.22, .61, .36, 1);

  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f4ee;
  --bg-soft: #efede5;
  --surface: #ffffff;
  --surface-2: #f4f2eb;
  --surface-3: #ebe8df;
  --line: rgba(22, 33, 28, .1);
  --line-strong: rgba(22, 33, 28, .16);

  --text: #14201b;
  --text-soft: #4d5f57;
  --text-faint: #7c8b84;

  --accent: #0f8a62;
  --accent-strong: #0b7150;
  --accent-ink: #ffffff;
  --accent-soft: rgba(15, 138, 98, .09);
  --accent-ring: rgba(15, 138, 98, .25);

  --user-bubble: #0f8a62;
  --user-text: #f4fffa;

  --shadow-sm: 0 1px 2px rgba(20, 32, 27, .06), 0 6px 18px -12px rgba(20, 32, 27, .22);
  --shadow-md: 0 22px 50px -30px rgba(20, 32, 27, .45);

  color-scheme: light;
}

/* ───────────────────────────── Base ───────────────────────────── */

*, *::before, *::after { box-sizing: border-box; }

/* `hidden` must win over the `display` rules below (flex/grid elements). */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15.5px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior: none;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(60% 45% at 85% -10%, var(--accent-soft), transparent 70%),
    radial-gradient(50% 40% at 0% 110%, rgba(47, 207, 139, .06), transparent 70%);
}

svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

button { font: inherit; color: inherit; cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 10px;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 12px; top: -60px; z-index: 60;
  padding: 10px 16px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink);
  font-weight: 600; text-decoration: none;
  transition: top .2s var(--ease);
}
.skip-link:focus { top: 12px; }

/* ───────────────────────────── Shell ───────────────────────────── */

.app {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: var(--rail-w) minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ───────────────────────────── Rail ───────────────────────────── */

.rail {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
  padding: 18px 14px;
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
}

.rail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 6px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  text-decoration: none;
  color: inherit;
  letter-spacing: -.02em;
}

.brand-mark {
  display: grid; place-items: center;
  width: 30px; height: 30px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
}
.brand-mark svg { width: 18px; height: 18px; }

.brand-word { font-size: 19px; font-weight: 700; }
.brand-badge {
  font-size: 10px; font-weight: 700; letter-spacing: .08em;
  padding: 2px 6px; border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}

.rail-close { display: none; }

.new-chat {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 11px 14px;
  border-radius: 12px;
  border: 1px dashed var(--line-strong);
  background: transparent;
  color: var(--text);
  font-weight: 600; font-size: 14px;
  transition: background .18s var(--ease), border-color .18s var(--ease), transform .18s var(--ease);
}
.new-chat svg { width: 17px; height: 17px; }
.new-chat:hover { background: var(--surface); border-color: var(--accent-ring); }
.new-chat:active { transform: scale(.985); }

.rail-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 2px;
  margin: 0 -2px;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.rail-label {
  margin: 6px 6px 8px;
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-faint);
}

.chat-list { display: flex; flex-direction: column; gap: 2px; }

.chat-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  font-size: 14px;
  text-align: left;
  transition: background .16s var(--ease), color .16s var(--ease);
}
.chat-item:hover { background: var(--surface); color: var(--text); }
.chat-item[aria-current="true"] { background: var(--surface); color: var(--text); box-shadow: inset 2px 0 0 var(--accent); }
.chat-item .ci-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .ci-del {
  display: grid; place-items: center;
  width: 24px; height: 24px;
  border: 0; border-radius: 7px;
  background: transparent; color: var(--text-faint);
  opacity: 0; transition: opacity .15s, background .15s, color .15s;
}
.chat-item .ci-del svg { width: 14px; height: 14px; }
.chat-item:hover .ci-del, .chat-item .ci-del:focus-visible { opacity: 1; }
.chat-item .ci-del:hover { background: var(--danger-soft); color: var(--danger); }

.rail-empty { margin: 6px 8px; font-size: 13px; color: var(--text-faint); }

.rail-foot { display: flex; flex-direction: column; gap: 8px; }

.rail-note {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12.5px; color: var(--text-faint); line-height: 1.45;
}
.rail-note .lock { color: var(--accent); flex: none; }
.rail-note svg { width: 15px; height: 15px; }

.rail-tools { display: flex; gap: 6px; }

.tool {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--text-soft);
  font-size: 13px;
}
.tool:hover { background: var(--surface); color: var(--text); }
.tool svg { width: 16px; height: 16px; }

.i-sun, .i-moon { display: none; }
:root[data-theme="dark"] .i-sun { display: block; }
:root[data-theme="light"] .i-moon { display: block; }

/* ───────────────────────────── Main ───────────────────────────── */

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(14px, 4vw, 28px);
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 3;
}

/* Displayed only by the mobile layout below (same specificity, later wins). */
.topbar .rail-open { display: none; }

.agent { display: flex; align-items: center; gap: 11px; min-width: 0; }

.mark {
  display: grid; place-items: center;
  width: 38px; height: 38px; flex: none;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}
.mark svg { width: 21px; height: 21px; }

.agent-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.agent-id strong {
  font-size: 15px; font-weight: 600; letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.agent-state {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; color: var(--text-faint);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.agent-state i {
  width: 6px; height: 6px; border-radius: 50%; flex: none;
  background: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.agent-state[data-state="busy"] i { animation: breathe 1.4s var(--ease) infinite; }
.agent-state[data-state="live"] i { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.agent-state[data-state="error"] i { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

@keyframes breathe { 50% { opacity: .35; transform: scale(.7); } }

.top-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }

.icon-button {
  display: grid; place-items: center;
  width: 38px; height: 38px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-soft);
  transition: background .16s var(--ease), color .16s var(--ease), border-color .16s var(--ease), transform .16s var(--ease);
}
.icon-button svg { width: 18px; height: 18px; }
.icon-button:hover { color: var(--text); border-color: var(--line-strong); }
.icon-button:active { transform: scale(.94); }
.icon-button.ghost { background: transparent; border-color: transparent; }
.icon-button.ghost:hover { background: var(--surface); }

.pill {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px; font-weight: 600;
  white-space: nowrap;
}
.pill svg { width: 16px; height: 16px; }

/* ───────────────────────────── Thread ───────────────────────────── */

.scroller {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.thread {
  width: min(100%, var(--maxw));
  margin: 0 auto;
  padding: 26px clamp(16px, 4vw, 28px) 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* Messages */
.msg { display: flex; gap: 12px; align-items: flex-start; animation: rise .35s var(--ease) both; }
.msg.user { justify-content: flex-end; }

.msg .avatar {
  display: grid; place-items: center; flex: none;
  width: 30px; height: 30px; margin-top: 2px;
  border-radius: 9px;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-ring);
}
.msg .avatar svg { width: 16px; height: 16px; }

.bubble {
  position: relative;
  max-width: min(100%, 62ch);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 15.5px;
  overflow-wrap: anywhere;
}

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

.msg.user .bubble {
  background: var(--user-bubble);
  color: var(--user-text);
  border-top-right-radius: 6px;
}

.msg.pending .bubble { opacity: .62; }

.bubble > *:first-child { margin-top: 0; }
.bubble > *:last-child { margin-bottom: 0; }
.bubble p { margin: 0 0 .7em; }
.bubble ul, .bubble ol { margin: .2em 0 .8em; padding-left: 1.25em; }
.bubble li { margin: .2em 0; }
.bubble li::marker { color: var(--accent); }
.bubble strong { font-weight: 600; }
.bubble em { font-style: italic; }
.bubble code {
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: .88em;
  padding: .12em .38em;
  border-radius: 6px;
  background: var(--surface-3);
  border: 1px solid var(--line);
}
.bubble a { color: var(--accent); text-underline-offset: 2px; }

.msg-foot {
  display: flex; align-items: center; gap: 6px;
  margin-top: 6px;
  font-size: 11.5px; color: var(--text-faint);
}
.msg.user .msg-foot { justify-content: flex-end; color: var(--text-faint); }

/* A message still being answered shows a quiet typing hint under its timestamp. */
.msg-foot[data-thinking]::after {
  content: "";
  width: 12px; height: 3px; border-radius: 2px;
  background: var(--accent);
  opacity: .55;
  animation: breathe 1.4s var(--ease) infinite;
}

.copy-btn {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px;
  border: 0; border-radius: 6px;
  background: transparent; color: var(--text-faint);
  opacity: 0; transition: opacity .15s, background .15s, color .15s;
}
.copy-btn svg { width: 13px; height: 13px; }
.msg:hover .copy-btn, .copy-btn:focus-visible { opacity: 1; }
.copy-btn:hover { background: var(--surface-3); color: var(--text); }

.listen-btn {
  display: inline-flex; align-items: center; gap: 5px;
  min-height: 26px; padding: 3px 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-2); color: var(--accent);
  font: inherit; font-size: 11px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.listen-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.listen-btn:hover { border-color: var(--accent); background: var(--surface-3); }

.typing { display: inline-flex; gap: 5px; padding: 14px 16px; }
.typing i {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-faint);
  animation: blink 1.2s infinite var(--ease);
}
.typing i:nth-child(2) { animation-delay: .15s; }
.typing i:nth-child(3) { animation-delay: .3s; }

@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ───────────────────────────── Dock ───────────────────────────── */

.dock {
  width: 100%;
  padding: 0 clamp(12px, 4vw, 28px) max(14px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 62%, transparent);
}

.dock > * { width: min(100%, var(--maxw)); margin-inline: auto; }

.call-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 10px;
  padding: 9px 10px 9px 14px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--accent-ring);
  box-shadow: var(--shadow-sm);
  animation: rise .3s var(--ease) both;
}
.call-live { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.call-label { font-size: 13.5px; font-weight: 600; }
.call-timer { font-variant-numeric: tabular-nums; font-size: 13px; color: var(--text-faint); }

.eq { display: inline-flex; align-items: flex-end; gap: 2px; height: 16px; }
.eq i { width: 3px; height: 100%; border-radius: 2px; background: var(--accent); transform-origin: bottom; animation: eq 1s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: .18s; }
.eq i:nth-child(3) { animation-delay: .36s; }
@keyframes eq { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }

.call-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: transparent;
  font-size: 13px; font-weight: 600;
  color: var(--text-soft);
}
.call-toggle svg { width: 15px; height: 15px; }
.call-toggle:hover { background: var(--surface-2); color: var(--text); }
.call-toggle.danger { border-color: transparent; background: var(--danger); color: #fff; }
.call-toggle.danger:hover { background: color-mix(in srgb, var(--danger) 88%, #000); }
.call-toggle .i-mute { display: none; }
.call-toggle[aria-pressed="true"] { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }
.call-toggle[aria-pressed="true"] .i-mic { display: none; }
.call-toggle[aria-pressed="true"] .i-mute { display: block; }

.composer {
  display: flex;
  flex-direction: column;
  padding: 10px 10px 8px 16px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-md);
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease);
}
.composer:focus-within { border-color: var(--accent-ring); box-shadow: var(--shadow-md), 0 0 0 3px var(--accent-soft); }

#message-input {
  width: 100%;
  min-height: 24px;
  max-height: 168px;
  padding: 4px 0;
  resize: none;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15.5px;
  line-height: 1.55;
  scrollbar-width: thin;
}
#message-input::placeholder { color: var(--text-faint); }

.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.composer-start { display: flex; align-items: center; gap: 10px; min-width: 0; }
.composer-start .icon-button { width: 34px; height: 34px; border-radius: 10px; }
.composer-start .icon-button svg { width: 17px; height: 17px; }

.composer-hint { font-size: 11.5px; color: var(--text-faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
kbd {
  font-family: inherit; font-size: 10.5px; font-weight: 600;
  padding: 1px 5px; border-radius: 5px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
  color: var(--text-soft);
}

.send {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px;
  border: 0; border-radius: 11px;
  background: var(--accent);
  color: var(--accent-ink);
  transition: transform .16s var(--ease), background .16s var(--ease), opacity .16s var(--ease);
}
.send svg { width: 18px; height: 18px; stroke-width: 2.1; flex: none; }
.send:hover:not(:disabled) { background: var(--accent-strong); }
.send:active:not(:disabled) { transform: scale(.92); }
.send:disabled { opacity: .38; cursor: not-allowed; }

.call-toggle:disabled { opacity: .45; cursor: not-allowed; }

.disclaimer {
  margin: 9px 0 0;
  text-align: center;
  font-size: 11.5px;
  color: var(--text-faint);
}
.powered { opacity: .8; }
.disclaimer .powered::before { content: "·"; margin: 0 6px; }

/* ───────────────────────────── Toast ───────────────────────────── */

.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, calc(env(safe-area-inset-bottom) + 16px));
  transform: translate(-50%, 16px);
  max-width: min(92vw, 460px);
  padding: 11px 16px;
  border-radius: 12px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .2s var(--ease);
  z-index: 50;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

.scrim {
  position: fixed; inset: 0;
  display: none;
  border: 0;
  background: rgba(0, 0, 0, .45);
  z-index: 15;
  cursor: default;
}

/* The rail is fixed in the mobile layout only; on desktop it is a grid column. */
@media (min-width: 881px) {
  .scrim { display: none !important; }
  /* The rail is always visible here, so a close button would do nothing. */
  .rail-close { display: none; }
}

/* ───────────────────────────── Responsive ───────────────────────────── */

@media (max-width: 880px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .topbar .rail-open { display: grid; }

  .topbar {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    column-gap: 4px;
    row-gap: 6px;
  }
  .rail-open { grid-area: 1 / 1; }
  .agent { grid-area: 1 / 2; }
  .top-actions { grid-area: 1 / 3; margin-left: 0; }
  /* A live call needs a full-width row: the label would otherwise be clipped. */
  .end-pill { grid-area: 2 / 1 / 3 / -1; justify-self: stretch; justify-content: center; }
  .agent-id { min-width: 0; }
  .agent-id strong { font-size: 14.5px; }
  .mark { width: 34px; height: 34px; border-radius: 11px; }
  .icon-button { width: 34px; height: 34px; }
  .top-actions { gap: 2px; }

  .rail {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 20;
    transform: translateX(-102%);
    transition: transform .28s var(--ease);
    box-shadow: var(--shadow-md);
    padding-top: max(18px, env(safe-area-inset-top));
  }
  .app.nav-open .rail { transform: none; }
  .app.nav-open .scrim { display: block; }

  .rail-close, .rail-open { display: grid; }
  .tool-text { display: none; }
  .tool { padding: 8px 10px; }
}

@media (max-width: 560px) {
  body { font-size: 15px; }
  .thread { padding-top: 18px; gap: 18px; }
  .composer-hint { display: none; }
  .bubble { font-size: 15px; padding: 11px 14px; }
  .disclaimer { font-size: 11px; }
  .end-pill span { display: none; }
  .call-label { display: none; }
  .disclaimer .powered { display: none; }
}

@media (max-width: 380px) {
  .brand-badge { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }
}
