:root {
  --bg: #f1f4f2;
  --surface: #ffffff;
  --surface-2: #f7faf8;
  --surface-3: #eef3f0;
  --ink: #0f231c;
  --ink-2: #33483f;
  --muted: #6a7d75;
  --line: #e2eae6;
  --line-2: #d2ded8;
  --brand: #0d7a5b;
  --brand-strong: #0a6047;
  --brand-soft: #e9f6f0;
  --brand-ring: rgba(13, 122, 91, 0.16);
  --navy: #11303e;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a6100;
  --shadow-1: 0 1px 2px rgba(12, 38, 30, 0.06);
  --shadow-2: 0 20px 44px -30px rgba(12, 38, 30, 0.55);
  --shadow-3: 0 10px 30px -18px rgba(12, 38, 30, 0.5);
  --sidebar-w: 286px;
  --radius: 16px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1210;
    --surface: #111a17;
    --surface-2: #15201c;
    --surface-3: #1a2622;
    --ink: #e9f1ed;
    --ink-2: #c2d2cb;
    --muted: #89a096;
    --line: #223029;
    --line-2: #2d4038;
    --brand: #43bd93;
    --brand-strong: #64d0aa;
    --brand-soft: #10291f;
    --brand-ring: rgba(67, 189, 147, 0.2);
    --navy: #14323f;
    --danger: #f97066;
    --danger-soft: #2a1614;
    --warn: #e0b341;
    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 22px 50px -30px rgba(0, 0, 0, 0.9);
    --shadow-3: 0 12px 34px -20px rgba(0, 0, 0, 0.8);
    color-scheme: dark;
  }
}

html[data-theme='light'] {
  color-scheme: light;
}
html[data-theme='dark'] {
  --bg: #0b1210;
  --surface: #111a17;
  --surface-2: #15201c;
  --surface-3: #1a2622;
  --ink: #e9f1ed;
  --ink-2: #c2d2cb;
  --muted: #89a096;
  --line: #223029;
  --line-2: #2d4038;
  --brand: #43bd93;
  --brand-strong: #64d0aa;
  --brand-soft: #10291f;
  --brand-ring: rgba(67, 189, 147, 0.2);
  --navy: #14323f;
  --danger: #f97066;
  --danger-soft: #2a1614;
  --warn: #e0b341;
  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 22px 50px -30px rgba(0, 0, 0, 0.9);
  --shadow-3: 0 12px 34px -20px rgba(0, 0, 0, 0.8);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
}

a {
  color: var(--brand);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

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

.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;
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-thumb {
  background: var(--line-2);
  border-radius: 20px;
  border: 3px solid transparent;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: content-box;
}
::-webkit-scrollbar-track {
  background: transparent;
}

/* ---------------------------------------------------------------- boot */
.boot {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
  z-index: 50;
}
.boot-logo {
  color: var(--brand);
  animation: breathe 1.6s ease-in-out infinite;
}
@keyframes breathe {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.94);
  }
  50% {
    opacity: 1;
    transform: scale(1);
  }
}

/* ---------------------------------------------------------------- auth */
.auth {
  min-height: 100dvh;
  display: grid;
  grid-template-columns: 1.02fr 0.98fr;
  overflow: hidden;
}

.auth-panel {
  display: contents;
}

.auth-brand {
  position: relative;
  padding: 56px clamp(32px, 5vw, 72px);
  color: #eaf6f0;
  background:
    radial-gradient(900px 500px at 12% 8%, rgba(67, 189, 147, 0.28), transparent 62%),
    radial-gradient(600px 420px at 88% 88%, rgba(20, 90, 120, 0.5), transparent 65%),
    linear-gradient(158deg, #0a2a24 0%, #0c3329 46%, #0a2230 100%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 26px;
  overflow: hidden;
}
.auth-brand::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 46px 46px;
  mask-image: radial-gradient(circle at 30% 30%, #000 0%, transparent 72%);
  pointer-events: none;
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: #7fe3bd;
  position: relative;
  z-index: 1;
}
.auth-logo div {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}
.auth-logo strong {
  font-size: 15px;
  letter-spacing: 0.01em;
  color: #f2fbf6;
}
.auth-logo span {
  font-size: 12.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(226, 246, 237, 0.62);
}

.auth-headline {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 15ch;
  font-size: clamp(30px, 3.4vw, 44px);
  line-height: 1.14;
  letter-spacing: -0.025em;
  font-weight: 640;
}

.auth-copy {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: 46ch;
  color: rgba(228, 246, 238, 0.76);
  font-size: 15.5px;
}

.auth-points {
  position: relative;
  z-index: 1;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 12px;
  max-width: 44ch;
}
.auth-points li {
  position: relative;
  padding-left: 26px;
  color: rgba(230, 248, 240, 0.84);
  font-size: 14.5px;
}
.auth-points li::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 7px;
  width: 12px;
  height: 7px;
  border-left: 2px solid #6fe0b4;
  border-bottom: 2px solid #6fe0b4;
  transform: rotate(-45deg);
}

.auth-form-side {
  display: grid;
  place-items: center;
  padding: 40px clamp(22px, 4vw, 56px);
  background: var(--bg);
}

.auth-card {
  width: min(400px, 100%);
  display: grid;
  gap: 16px;
}
.auth-card h2 {
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.02em;
}
.auth-sub {
  margin: -8px 0 6px;
  color: var(--muted);
  font-size: 14px;
}

.field {
  display: grid;
  gap: 7px;
}
.field span {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  letter-spacing: 0.01em;
}
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--line-2);
  border-radius: 11px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.field input::placeholder {
  color: var(--muted);
  opacity: 0.7;
}
.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring);
}

.primary-btn {
  margin-top: 4px;
  padding: 12px 18px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-weight: 620;
  letter-spacing: 0.01em;
  box-shadow: var(--shadow-1);
  transition: background 0.15s, transform 0.1s;
}
.primary-btn:hover {
  background: var(--brand-strong);
}
.primary-btn:active {
  transform: translateY(1px);
}
.primary-btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.auth-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
}

.auth-note {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------------------------------------------------------------- app shell */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar-head {
  padding: 18px 16px 12px;
  display: grid;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 4px;
}
.brand-mark {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(150deg, #17a273, #0a4f42 85%);
  box-shadow: 0 4px 12px -6px rgba(10, 79, 66, 0.9);
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  min-width: 0;
}
.brand-text strong {
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.brand-text span {
  font-size: 11.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.new-chat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 11px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-weight: 600;
  font-size: 14px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s;
}
.new-chat:hover {
  border-color: var(--brand);
}

.conv-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 6px 10px 12px;
}
.conv-label {
  margin: 6px 8px 8px;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--muted);
}
.conv-list {
  display: grid;
  gap: 2px;
}
.conv-item {
  position: relative;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 6px;
  padding: 9px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background 0.12s;
}
.conv-item:hover {
  background: var(--surface-3);
}
.conv-item.is-active {
  background: var(--brand-soft);
}
.conv-item.is-active .conv-title {
  color: var(--brand-strong);
  font-weight: 600;
}
.conv-main {
  min-width: 0;
  display: grid;
  gap: 1px;
}
.conv-title {
  font-size: 13.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-time {
  font-size: 11.5px;
  color: var(--muted);
}
.conv-del {
  opacity: 0;
  padding: 5px;
  border-radius: 7px;
  color: var(--muted);
  transition: opacity 0.12s, background 0.12s, color 0.12s;
}
.conv-item:hover .conv-del,
.conv-del:focus-visible {
  opacity: 1;
}
.conv-del:hover {
  background: var(--danger-soft);
  color: var(--danger);
}
.conv-empty {
  padding: 16px 10px;
  color: var(--muted);
  font-size: 13px;
}

.sidebar-foot {
  border-top: 1px solid var(--line);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.account {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
  flex: 1;
}
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 12.5px;
  font-weight: 650;
  flex: none;
}
.avatar-user {
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line);
  text-transform: uppercase;
}
.account-text {
  min-width: 0;
  display: grid;
  line-height: 1.25;
}
.account-name {
  font-size: 12.5px;
  color: var(--ink-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.account-sub {
  font-size: 11px;
  color: var(--muted);
}
.foot-actions {
  display: flex;
  gap: 2px;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 9px;
  color: var(--muted);
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover {
  background: var(--surface-3);
  color: var(--ink-2);
}

/* ---------------------------------------------------------------- chat */
.chat {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(900px 380px at 78% -8%, rgba(13, 122, 91, 0.06), transparent 70%),
    var(--bg);
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(8px);
  z-index: 5;
}
.chat-heading {
  min-width: 0;
  flex: 1;
}
.chat-heading h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 620;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-heading p {
  margin: 1px 0 0;
  font-size: 12px;
  color: var(--muted);
}
.head-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px 5px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.head-badge .pulse {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-ring);
}
.head-badge.is-busy .pulse {
  animation: pulse 1.3s ease-in-out infinite;
}
.head-badge.is-error .pulse {
  background: var(--danger);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 20%, transparent);
}
@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.45;
    transform: scale(0.8);
  }
}
.menu-btn {
  display: none;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px clamp(16px, 3vw, 34px) 18px;
  scroll-behavior: smooth;
}
.messages-inner {
  max-width: 860px;
  margin: 0 auto;
  min-height: 100%;
}
.messages-inner.is-empty {
  display: grid;
  align-content: center;
  padding-bottom: 24px;
}
@media (min-width: 1180px) {
  .messages-inner {
    max-width: 900px;
  }
}

/* empty state */
.empty {
  padding: clamp(24px, 6vh, 60px) 4px 20px;
  max-width: 660px;
  margin: 0 auto;
}
.empty-kicker {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 11.5px;
  font-weight: 620;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.empty h2 {
  margin: 16px 0 10px;
  font-size: clamp(24px, 3vw, 30px);
  line-height: 1.2;
  letter-spacing: -0.025em;
  font-weight: 640;
}
.empty > p {
  margin: 0 0 24px;
  color: var(--ink-2);
  font-size: 15px;
  max-width: 58ch;
}
.empty-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.empty-card {
  text-align: left;
  padding: 14px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color 0.15s, transform 0.12s, box-shadow 0.15s;
  display: grid;
  gap: 4px;
  align-content: start;
}
.empty-card:hover {
  border-color: var(--brand);
  transform: translateY(-1px);
  box-shadow: var(--shadow-3);
}
.empty-card strong {
  font-size: 13.5px;
  font-weight: 620;
}
.empty-card span {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.45;
}

/* ---------------------------------------------------------------- messages */
.msg {
  display: flex;
  gap: 11px;
  margin-bottom: 26px;
  animation: rise 0.22s ease-out;
}
@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.msg.user {
  justify-content: flex-end;
  padding-left: 40px;
}
.bubble {
  max-width: 640px;
  padding: 11px 15px;
  border-radius: 15px 15px 4px 15px;
  background: var(--navy);
  color: #f2f8f6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14.5px;
  line-height: 1.55;
  box-shadow: var(--shadow-1);
}
.msg.assistant {
  padding-right: 8px;
}
.msg-avatar {
  width: 30px;
  height: 30px;
  flex: none;
  margin-top: 2px;
  border-radius: 9px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(150deg, #17a273, #0a4f42 85%);
  box-shadow: 0 3px 10px -5px rgba(10, 79, 66, 0.9);
}
.msg-body {
  min-width: 0;
  flex: 1;
}
.msg-body > * + * {
  margin-top: 10px;
}

.reply-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  overflow: hidden;
  max-width: 100%;
}

.sec {
  padding: 16px 18px;
}
.sec + .sec {
  border-top: 1px solid var(--line);
}
.sec-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
}
.sec-title {
  margin: 0;
  font-size: 11px;
  font-weight: 680;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
}
.sec-draft {
  background: linear-gradient(180deg, var(--brand-soft), color-mix(in srgb, var(--brand-soft) 55%, var(--surface)));
  box-shadow: inset 3px 0 0 var(--brand);
  padding-left: 20px;
}
.sec-draft .sec-title {
  color: var(--brand-strong);
}
.sec-notes .sec-title,
.sec-refs .sec-title {
  color: var(--muted);
}

.draft-text {
  max-width: 74ch;
  font-size: 14.8px;
  line-height: 1.62;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.draft-text p {
  margin: 0 0 10px;
}
.draft-text p:last-child {
  margin-bottom: 0;
}
.draft-text ul,
.draft-text ol {
  margin: 0 0 10px;
  padding-left: 20px;
}
.draft-text li {
  margin: 3px 0;
}
.draft-text strong {
  font-weight: 640;
}
.draft-text a {
  word-break: break-word;
}
.draft-text h4 {
  margin: 14px 0 6px;
  font-size: 14.5px;
}
.draft-text code {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 0.9em;
}
.draft-text table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  margin: 8px 0 12px;
}
.draft-text th,
.draft-text td {
  border: 1px solid var(--line);
  padding: 7px 9px;
  text-align: left;
  vertical-align: top;
}
.draft-text th {
  background: color-mix(in srgb, var(--ink) 4%, transparent);
  font-weight: 620;
}

.notes-text {
  font-size: 13.8px;
  color: var(--ink-2);
}
.notes-text p {
  margin: 0 0 8px;
}
.notes-text p:last-child {
  margin-bottom: 0;
}
.notes-text ul {
  margin: 6px 0;
  padding-left: 18px;
}

.refs-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ref-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 9px;
  align-items: start;
  padding: 9px 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.ref-icon {
  color: var(--brand);
  margin-top: 1px;
}
.ref-link {
  font-size: 13.2px;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.35;
}
.ref-fact {
  font-size: 12.8px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.45;
}
.ref-host {
  display: inline-block;
  margin-left: 5px;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--surface-3);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  vertical-align: 1px;
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  transition: all 0.14s;
  flex: none;
}
.copy-btn:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
  background: var(--surface);
}
.copy-btn.is-done {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}
.copy-btn svg {
  flex: none;
}

.msg-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11.5px;
  color: var(--muted);
  padding-left: 2px;
  flex-wrap: wrap;
}
.meta-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

/* tool trace */
.trace {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: 100%;
}
.trace-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 11.8px;
  color: var(--ink-2);
  max-width: 100%;
}
.trace-chip .t-label {
  font-weight: 600;
  white-space: nowrap;
}
.trace-chip .t-detail {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 240px;
}
.trace-chip.is-ok .dot {
  background: var(--brand);
}
.trace-chip.is-error .dot {
  background: var(--danger);
}
.trace-chip .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.trace-chip.is-running .dot {
  background: var(--warn);
  animation: pulse 1.1s ease-in-out infinite;
}

/* thinking / streaming */
.thinking {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 11px 15px;
  border-radius: 13px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  box-shadow: var(--shadow-1);
}
.dots {
  display: inline-flex;
  gap: 4px;
}
.dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--brand);
  animation: bounce 1.2s ease-in-out infinite;
}
.dots i:nth-child(2) {
  animation-delay: 0.15s;
}
.dots i:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

.stream-text {
  font-size: 14.8px;
  line-height: 1.62;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.stream-text::after {
  content: '▍';
  color: var(--brand);
  animation: caret 1s steps(2, start) infinite;
  margin-left: 1px;
}
@keyframes caret {
  50% {
    opacity: 0;
  }
}

.error-card {
  display: flex;
  gap: 10px;
  padding: 13px 15px;
  border-radius: 13px;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.8px;
  max-width: 640px;
}
.error-card strong {
  display: block;
  margin-bottom: 2px;
  font-size: 13px;
}

/* ---------------------------------------------------------------- composer */
.composer-wrap {
  flex: none;
  padding: 6px clamp(16px, 3vw, 34px) 14px;
  background: linear-gradient(to top, var(--bg) 62%, color-mix(in srgb, var(--bg) 0%, transparent));
}
.quick-row {
  max-width: 860px;
  margin: 0 auto 8px;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
  padding-bottom: 2px;
}
.quick-row::-webkit-scrollbar {
  display: none;
}
.quick {
  flex: none;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line-2);
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  transition: all 0.14s;
  white-space: nowrap;
}
.quick:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
  background: var(--surface);
}
.quick[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}

.composer {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 8px 8px 14px;
  border: 1px solid var(--line-2);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px var(--brand-ring), var(--shadow-2);
}
.composer textarea {
  width: 100%;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  padding: 8px 4px 6px;
  min-height: 26px;
  max-height: 220px;
  line-height: 1.55;
  font-size: 14.8px;
}
.composer textarea::placeholder {
  color: var(--muted);
  opacity: 0.85;
}
.composer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 2px;
}
.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 6px 9px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
  transition: background 0.12s, color 0.12s;
}
.ghost-btn:hover {
  background: var(--surface-3);
  color: var(--ink-2);
}
.composer-hint {
  flex: 1;
  text-align: right;
  font-size: 11.5px;
  color: var(--muted);
}
.send-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 13px;
  border-radius: 11px;
  background: var(--brand);
  color: #fff;
  font-size: 13.5px;
  font-weight: 620;
  transition: background 0.14s, opacity 0.14s;
}
.send-btn:hover {
  background: var(--brand-strong);
}
.send-btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
}
.send-btn.is-stop {
  background: var(--surface-3);
  color: var(--ink-2);
  border: 1px solid var(--line-2);
}
.send-btn.is-stop:hover {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
}
.send-btn.is-stop .send-label::before {
  content: 'Hentikan';
}
.send-btn.is-stop .send-label {
  font-size: 0;
}
.send-btn.is-stop .send-label::before {
  font-size: 13.5px;
}
.composer-foot {
  max-width: 860px;
  margin: 8px auto 0;
  text-align: center;
  font-size: 11.2px;
  color: var(--muted);
}

/* ---------------------------------------------------------------- toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translate(-50%, 14px);
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  font-weight: 550;
  box-shadow: var(--shadow-3);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 60;
  max-width: min(92vw, 460px);
  text-align: center;
}
.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.backdrop {
  display: none;
}

/* ---------------------------------------------------------------- responsive */
@media (max-width: 980px) {
  .auth {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
  .auth-brand {
    padding: 36px 24px 30px;
    gap: 18px;
  }
  .auth-headline {
    font-size: 27px;
    max-width: 20ch;
  }
  .auth-copy,
  .auth-points {
    display: none;
  }
  .auth-form-side {
    padding: 30px 22px 48px;
    align-items: start;
  }
}

@media (max-width: 880px) {
  .app {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, 86vw);
    z-index: 40;
    transform: translateX(-102%);
    transition: transform 0.22s ease;
    box-shadow: var(--shadow-3);
  }
  .app.nav-open .sidebar {
    transform: none;
  }
  .backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(6, 20, 16, 0.42);
    z-index: 35;
    opacity: 0;
    transition: opacity 0.22s;
  }
  .app.nav-open .backdrop {
    opacity: 1;
  }
  .menu-btn {
    display: grid;
  }
  .empty-cards {
    grid-template-columns: 1fr;
  }
  .msg.user {
    padding-left: 8px;
  }
  .bubble {
    max-width: 88%;
  }
  .head-badge {
    display: none;
  }
  .composer-hint {
    display: none;
  }
}

@media (max-width: 560px) {
  .composer textarea {
    min-height: 58px;
    padding-top: 6px;
    overflow-y: hidden;
  }
  .composer {
    padding-left: 12px;
  }
  .trace-chip .t-detail {
    max-width: 150px;
  }
  .messages {
    padding: 18px 14px 4px;
  }
  .composer-wrap {
    padding: 4px 12px 12px;
  }
  .sec {
    padding: 14px 14px;
  }
  .sec-draft {
    padding-left: 16px;
  }
  .msg {
    gap: 8px;
  }
  .msg-avatar {
    width: 26px;
    height: 26px;
  }
  .ref-fact {
    font-size: 12.2px;
  }
}

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