:root {
  color-scheme: light;
  --font-body: "DM Sans", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: "Manrope", var(--font-body);
  --bg: #f8f3eb;
  --bg-rgb: 248, 243, 235;
  --surface: rgba(255, 252, 247, 0.78);
  --surface-solid: #fffaf3;
  --surface-soft: #f1e8dc;
  --surface-hover: #ebe0d2;
  --sidebar: rgba(238, 227, 213, 0.76);
  --border: rgba(102, 73, 48, 0.13);
  --border-strong: rgba(102, 73, 48, 0.22);
  --text: #34271e;
  --text-soft: #766556;
  --text-faint: #9b8c7f;
  --accent: #9a6845;
  --accent-strong: #75482f;
  --accent-soft: #e8d2bf;
  --accent-pale: #f1e2d4;
  --glow-a: rgba(205, 157, 116, 0.30);
  --glow-b: rgba(229, 194, 161, 0.34);
  --glow-c: rgba(177, 125, 91, 0.16);
  --shadow-sm: 0 8px 24px rgba(78, 53, 34, 0.08);
  --shadow-md: 0 20px 60px rgba(78, 53, 34, 0.12);
  --shadow-lg: 0 30px 90px rgba(78, 53, 34, 0.16);
  --sidebar-width: 278px;
  --topbar-height: 72px;
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

body[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1b1714;
  --bg-rgb: 27, 23, 20;
  --surface: rgba(43, 36, 31, 0.78);
  --surface-solid: #2b241f;
  --surface-soft: #352c26;
  --surface-hover: #40342c;
  --sidebar: rgba(36, 30, 26, 0.82);
  --border: rgba(238, 211, 184, 0.10);
  --border-strong: rgba(238, 211, 184, 0.19);
  --text: #f3e8dc;
  --text-soft: #c1ad9c;
  --text-faint: #8f7b6d;
  --accent: #d2a17d;
  --accent-strong: #e5b994;
  --accent-soft: #5b4434;
  --accent-pale: #443328;
  --glow-a: rgba(159, 96, 60, 0.22);
  --glow-b: rgba(109, 76, 55, 0.28);
  --glow-c: rgba(213, 158, 116, 0.10);
  --shadow-sm: 0 8px 24px rgba(0, 0, 0, 0.20);
  --shadow-md: 0 20px 60px rgba(0, 0, 0, 0.30);
  --shadow-lg: 0 30px 90px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  transition: background-color 0.45s var(--ease), color 0.35s var(--ease);
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 38%, transparent);
  outline-offset: 2px;
}

svg {
  width: 20px;
  height: 20px;
  stroke-width: 1.9;
}

.app-shell {
  display: flex;
  width: 100%;
  height: 100dvh;
  min-height: 560px;
  position: relative;
  overflow: hidden;
}

.sidebar {
  position: relative;
  z-index: 30;
  display: flex;
  flex: 0 0 var(--sidebar-width);
  flex-direction: column;
  width: var(--sidebar-width);
  height: 100%;
  padding: 19px 14px 14px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  backdrop-filter: blur(26px) saturate(120%);
  -webkit-backdrop-filter: blur(26px) saturate(120%);
  transition: transform 0.45s var(--ease), background-color 0.45s var(--ease), border-color 0.35s var(--ease);
}

.sidebar::after {
  position: absolute;
  inset: 0;
  z-index: -1;
  content: "";
  pointer-events: none;
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.20), transparent 38%);
}

body[data-theme="dark"] .sidebar::after {
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.035), transparent 38%);
}

.sidebar-head,
.topbar,
.composer-actions,
.topbar-actions,
.topbar-left {
  display: flex;
  align-items: center;
}

.sidebar-head {
  justify-content: space-between;
  min-height: 43px;
  padding: 0 7px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  text-decoration: none;
}

.brand-mark {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, 8px);
  grid-template-rows: repeat(2, 8px);
  gap: 2px;
  width: 22px;
  height: 22px;
  transform: rotate(45deg);
}

.brand-mark span {
  display: block;
  border-radius: 3px 8px 3px 8px;
  background: linear-gradient(135deg, var(--accent-strong), #d5a37b);
  box-shadow: 0 2px 8px rgba(122, 76, 45, 0.18);
}

.brand-mark span:nth-child(2),
.brand-mark span:nth-child(3) {
  opacity: 0.62;
}

.brand-name {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.7px;
}

.icon-button,
.composer-tool,
.send-button,
.theme-toggle,
.personality-selector,
.nav-item,
.new-chat-button,
.suggestion-card,
.history-item,
.personality-menu button,
.message-action {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button {
  display: inline-grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  border-radius: 12px;
  background: transparent;
  transition: transform 0.25s var(--ease), background-color 0.25s ease;
}

.icon-button:hover {
  background: var(--surface-hover);
}

.icon-button:active {
  transform: scale(0.94);
}

.icon-button.compact {
  width: 34px;
  height: 34px;
}

.sidebar-close {
  display: none;
}

.new-chat-button {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  margin: 20px 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-solid) 60%, transparent);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
  text-align: left;
  transition: transform 0.3s var(--ease), background-color 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
}

.new-chat-button:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--surface-solid);
  box-shadow: 0 12px 30px rgba(89, 60, 38, 0.12);
}

.new-chat-icon {
  display: grid;
  width: 33px;
  height: 33px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 10px;
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.new-chat-icon svg {
  width: 18px;
  height: 18px;
}

.primary-nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 42px;
  padding: 9px 12px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 500;
  text-align: left;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease);
}

.nav-item svg {
  width: 19px;
  height: 19px;
}

.nav-item:hover,
.nav-item.active {
  background: color-mix(in srgb, var(--surface-solid) 58%, transparent);
  color: var(--text);
}

.nav-item:active {
  transform: scale(0.985);
}

.history-section {
  min-height: 0;
  margin-top: 22px;
  flex: 1;
  overflow: hidden;
}

.section-label {
  padding: 0 12px 8px;
  color: var(--text-faint);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.history-list {
  display: grid;
  gap: 3px;
  max-height: 100%;
  padding-right: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  min-width: 0;
  padding: 9px 8px 9px 12px;
  border-radius: 11px;
  background: transparent;
  color: var(--text-soft);
  text-align: left;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.history-item:hover,
.history-item.active {
  background: color-mix(in srgb, var(--surface-solid) 55%, transparent);
  color: var(--text);
}

.history-item > svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  opacity: 0.75;
}

.history-title {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-delete {
  display: grid;
  width: 27px;
  height: 27px;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.2s ease, background-color 0.2s ease, color 0.2s ease;
}

.history-item:hover .history-delete,
.history-item.active .history-delete,
.history-delete:focus-visible {
  opacity: 1;
}

.history-delete:hover {
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.history-delete svg {
  width: 15px;
  height: 15px;
}

.empty-history {
  padding: 10px 12px;
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.45;
}


.main-panel {
  position: relative;
  display: flex;
  min-width: 0;
  height: 100%;
  flex: 1;
  flex-direction: column;
  isolation: isolate;
  overflow: hidden;
}

.topbar {
  position: relative;
  z-index: 20;
  justify-content: space-between;
  height: var(--topbar-height);
  padding: 0 24px;
  flex: 0 0 auto;
}

.topbar-left,
.topbar-actions {
  gap: 10px;
}

.mobile-menu {
  display: none;
}

.personality-selector-wrap {
  position: relative;
}

.personality-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 12px 7px 10px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-weight: 600;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.personality-selector:hover,
.personality-selector[aria-expanded="true"] {
  background: var(--surface);
  color: var(--text);
}

.personality-selector svg {
  width: 16px;
  height: 16px;
  transition: transform 0.25s var(--ease);
}

.personality-selector[aria-expanded="true"] svg {
  transform: rotate(180deg);
}

.personality-dot {
  width: 9px;
  height: 9px;
  border: 2px solid color-mix(in srgb, var(--accent) 55%, transparent);
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
}

.selector-label {
  color: var(--text-faint);
  font-size: 12px;
  font-weight: 500;
}

#selectedPersonality {
  color: var(--text);
  font-weight: 700;
}

.personality-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 50;
  display: grid;
  width: min(330px, calc(100vw - 36px));
  max-height: min(420px, calc(100vh - 92px));
  padding: 7px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
  box-shadow: var(--shadow-md);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-6px) scale(0.98);
  transform-origin: top left;
  backdrop-filter: blur(20px);
  transition: opacity 0.2s ease, visibility 0.2s ease, transform 0.25s var(--ease);
}

.personality-menu.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.personality-menu button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 58px;
  padding: 10px 11px;
  border-radius: 11px;
  background: transparent;
  text-align: left;
}

.personality-menu button:hover,
.personality-menu button.selected {
  background: var(--surface-soft);
}

.personality-menu button span {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.personality-menu strong {
  font-size: 13px;
}

.personality-menu small {
  color: var(--text-faint);
  font-size: 11px;
  line-height: 1.35;
}

.personality-menu button > svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
  opacity: 0;
}

.personality-menu button.selected > svg {
  opacity: 1;
}

.theme-toggle {
  display: inline-flex;
  padding: 0;
  border-radius: 999px;
  background: transparent;
}

.theme-track {
  position: relative;
  display: block;
  width: 52px;
  height: 30px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  background: var(--surface-soft);
  box-shadow: inset 0 2px 5px rgba(81, 54, 36, 0.06);
  transition: background-color 0.35s ease, border-color 0.35s ease;
}

.theme-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border-radius: 50%;
  background: var(--surface-solid);
  box-shadow: 0 3px 9px rgba(61, 43, 29, 0.18);
  transition: transform 0.4s var(--ease), background-color 0.35s ease;
}

.theme-thumb svg {
  position: absolute;
  width: 13px;
  height: 13px;
  transition: opacity 0.25s ease, transform 0.4s var(--ease);
}

.sun-icon {
  color: #a66d34;
  opacity: 1;
}

.moon-icon {
  color: #d9c2ae;
  opacity: 0;
  transform: rotate(-40deg) scale(0.6);
}

body[data-theme="dark"] .theme-thumb {
  transform: translateX(22px);
}

body[data-theme="dark"] .sun-icon {
  opacity: 0;
  transform: rotate(45deg) scale(0.6);
}

body[data-theme="dark"] .moon-icon {
  opacity: 1;
  transform: rotate(0) scale(1);
}


.ambient-background {
  position: absolute;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  overflow: hidden;
}

.ambient-background::before {
  position: absolute;
  inset: 0;
  content: "";
  background-image: linear-gradient(var(--border) 1px, transparent 1px), linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 52px 52px;
  mask-image: radial-gradient(circle at 50% 38%, #000 0%, transparent 64%);
  opacity: 0.22;
}

.ambient-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(2px);
  opacity: 0.9;
  animation: floatOrb 14s ease-in-out infinite alternate;
}

.orb-one {
  top: 8%;
  left: 21%;
  width: 420px;
  height: 420px;
  background: radial-gradient(circle, var(--glow-b) 0%, transparent 68%);
}

.orb-two {
  right: 0;
  bottom: 9%;
  width: 510px;
  height: 510px;
  background: radial-gradient(circle, var(--glow-a) 0%, transparent 70%);
  animation-delay: -6s;
  animation-duration: 18s;
}

.orb-three {
  top: 42%;
  left: 45%;
  width: 260px;
  height: 260px;
  background: radial-gradient(circle, var(--glow-c) 0%, transparent 70%);
  animation-delay: -9s;
}

.noise-layer {
  position: absolute;
  inset: 0;
  opacity: 0.025;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.9'/%3E%3C/svg%3E");
}

@keyframes floatOrb {
  0% { transform: translate3d(-2%, -2%, 0) scale(0.96); }
  50% { transform: translate3d(3%, 2%, 0) scale(1.04); }
  100% { transform: translate3d(-1%, 5%, 0) scale(1); }
}

.chat-scroll {
  position: relative;
  z-index: 2;
  min-height: 0;
  flex: 1;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.welcome-screen {
  display: grid;
  min-height: 100%;
  place-items: center;
  padding: 44px 28px 180px;
}

.welcome-screen.hidden {
  display: none;
}

.welcome-content {
  width: min(780px, 100%);
  text-align: center;
}

.spark-badge {
  display: grid;
  width: 49px;
  height: 49px;
  margin: 0 auto 22px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 20%, transparent);
  border-radius: 17px;
  background: linear-gradient(145deg, color-mix(in srgb, var(--surface-solid) 88%, transparent), color-mix(in srgb, var(--accent-pale) 72%, transparent));
  box-shadow: 0 15px 35px rgba(111, 72, 44, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.55);
  color: var(--accent-strong);
  transform: rotate(-5deg);
}

.spark-badge svg {
  width: 23px;
  height: 23px;
}

.welcome-content h1 {
  max-width: 720px;
  margin: 0 auto;
  font-family: var(--font-display);
  font-size: clamp(38px, 5.3vw, 67px);
  font-weight: 700;
  letter-spacing: -0.055em;
  line-height: 1.08;
}

.welcome-content h1 span {
  display: inline-block;
  background: linear-gradient(100deg, var(--accent-strong) 10%, #c08d66 52%, var(--accent-strong) 92%);
  background-size: 220% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  animation: titleShimmer 8s linear infinite;
}

@keyframes titleShimmer {
  to { background-position: -220% 0; }
}

.welcome-content > p {
  max-width: 560px;
  margin: 20px auto 0;
  color: var(--text-soft);
  font-size: 16px;
  line-height: 1.7;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 42px;
}

.suggestion-card {
  position: relative;
  display: flex;
  align-items: center;
  gap: 13px;
  min-width: 0;
  min-height: 82px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  box-shadow: 0 9px 25px rgba(75, 49, 31, 0.055);
  text-align: left;
  backdrop-filter: blur(14px);
  transition: transform 0.35s var(--ease), border-color 0.25s ease, background-color 0.25s ease, box-shadow 0.3s ease;
}

.suggestion-card::before {
  position: absolute;
  inset: 0;
  content: "";
  border-radius: inherit;
  background: linear-gradient(120deg, rgba(255, 255, 255, 0.20), transparent 45%);
  pointer-events: none;
}

.suggestion-card:hover {
  transform: translateY(-4px);
  border-color: color-mix(in srgb, var(--accent) 28%, transparent);
  background: color-mix(in srgb, var(--surface-solid) 90%, transparent);
  box-shadow: 0 18px 38px rgba(82, 53, 33, 0.10);
}

.suggestion-card:active {
  transform: translateY(-1px) scale(0.99);
}

.suggestion-icon {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 14px;
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.suggestion-icon svg {
  width: 20px;
  height: 20px;
}

.suggestion-card > span:nth-child(2) {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 3px;
}

.suggestion-card strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-card small {
  overflow: hidden;
  color: var(--text-faint);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-arrow {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--text-faint);
  opacity: 0;
  transform: translate(-5px, 5px);
  transition: opacity 0.25s ease, transform 0.3s var(--ease);
}

.suggestion-card:hover .card-arrow {
  opacity: 1;
  transform: translate(0, 0);
}

.messages {
  display: none;
  width: min(850px, calc(100% - 40px));
  margin: 0 auto;
  padding: 28px 0 205px;
}

.messages.active {
  display: block;
}

.message-row {
  display: flex;
  width: 100%;
  margin-bottom: 28px;
  opacity: 0;
  transform: translateY(14px);
}

.message-row.visible {
  opacity: 1;
  transform: translateY(0);
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.assistant {
  justify-content: flex-start;
}

.user-bubble {
  max-width: min(76%, 650px);
  padding: 13px 17px;
  border: 1px solid var(--border);
  border-radius: 21px 21px 5px 21px;
  background: color-mix(in srgb, var(--surface-solid) 82%, var(--accent-pale));
  box-shadow: var(--shadow-sm);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.assistant-message {
  width: min(100%, 760px);
}

.assistant-heading {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.assistant-personality {
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-size: 10px;
  letter-spacing: 0.04em;
}

.mini-brand {
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--accent-strong);
}

.mini-brand svg {
  width: 14px;
  height: 14px;
}

.assistant-body {
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.76;
}

.assistant-body p {
  margin: 0 0 13px;
}

.assistant-body p:last-child {
  margin-bottom: 0;
}

.assistant-body ul {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
  padding-left: 22px;
}

.assistant-body strong {
  font-weight: 700;
}

.assistant-actions {
  display: flex;
  gap: 4px;
  margin-top: 14px;
  opacity: 0;
  transform: translateY(3px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.message-row.assistant:hover .assistant-actions,
.assistant-actions:focus-within,
.assistant-actions.visible {
  opacity: 1;
  transform: translateY(0);
}

.message-action {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  padding: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-faint);
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease);
}

.message-action:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.message-action:active {
  transform: scale(0.92);
}

.message-action svg {
  width: 16px;
  height: 16px;
}

.thinking-shell {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 15px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text-soft);
  box-shadow: var(--shadow-sm);
}

.thinking-shell > span:first-child {
  font-size: 13px;
}

.thinking-dots,
.send-loader {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.thinking-dots i,
.send-loader i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: dotWave 1.15s ease-in-out infinite;
}

.thinking-dots i:nth-child(2),
.send-loader i:nth-child(2) { animation-delay: 0.14s; }
.thinking-dots i:nth-child(3),
.send-loader i:nth-child(3) { animation-delay: 0.28s; }

@keyframes dotWave {
  0%, 65%, 100% { transform: translateY(0) scale(0.78); opacity: 0.42; }
  30% { transform: translateY(-4px) scale(1); opacity: 1; }
}

.composer-region {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 15;
  padding: 34px 24px 13px;
  pointer-events: none;
  background: linear-gradient(to top, var(--bg) 27%, rgba(var(--bg-rgb), 0.87) 58%, rgba(var(--bg-rgb), 0));
  transition: background 0.45s var(--ease);
}

.composer-region > * {
  pointer-events: auto;
}

.composer {
  width: min(790px, 100%);
  margin: 0 auto;
  padding: 13px 13px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 26px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  box-shadow: 0 18px 55px rgba(75, 50, 31, 0.12), inset 0 1px 1px rgba(255, 255, 255, 0.42);
  backdrop-filter: blur(24px) saturate(120%);
  -webkit-backdrop-filter: blur(24px) saturate(120%);
  transition: border-color 0.25s ease, box-shadow 0.3s ease, transform 0.35s var(--ease), background-color 0.35s ease;
}

.composer:focus-within {
  border-color: color-mix(in srgb, var(--accent) 42%, transparent);
  box-shadow: 0 23px 65px rgba(75, 50, 31, 0.15), 0 0 0 4px color-mix(in srgb, var(--accent) 8%, transparent);
  transform: translateY(-2px);
}

.composer.loading {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
}

.composer textarea {
  display: block;
  width: 100%;
  max-height: 180px;
  min-height: 38px;
  padding: 6px 7px 8px;
  resize: none;
  overflow-y: auto;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 15.5px;
  line-height: 1.55;
}

.composer textarea::placeholder {
  color: var(--text-faint);
}

.composer textarea:disabled {
  opacity: 0.65;
}

.composer-actions {
  justify-content: space-between;
  margin-top: 4px;
}

.composer-actions-left,
.composer-actions-right {
  display: flex;
  align-items: center;
  gap: 5px;
}

.composer-tool {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 10px;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 600;
  transition: background-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease);
}

.composer-tool:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.composer-tool:active {
  transform: scale(0.94);
}

.composer-tool svg {
  width: 18px;
  height: 18px;
}

.voice-ring {
  position: absolute;
  inset: 2px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  opacity: 0;
}

.voice-button.listening {
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.voice-button.listening .voice-ring {
  animation: voicePulse 1.3s ease-out infinite;
}

@keyframes voicePulse {
  0% { transform: scale(0.75); opacity: 0.65; }
  100% { transform: scale(1.35); opacity: 0; }
}

.send-button {
  position: relative;
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  padding: 0;
  border-radius: 13px;
  background: var(--accent-strong);
  box-shadow: 0 7px 18px color-mix(in srgb, var(--accent-strong) 28%, transparent);
  color: #fff9f4;
  transition: transform 0.25s var(--ease), box-shadow 0.25s ease, opacity 0.2s ease, background-color 0.25s ease;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 10px 24px color-mix(in srgb, var(--accent-strong) 35%, transparent);
}

.send-button:active:not(:disabled) {
  transform: scale(0.92);
}

.send-button:disabled {
  background: var(--surface-hover);
  box-shadow: none;
  color: var(--text-faint);
  cursor: not-allowed;
  opacity: 0.7;
}

.send-button svg {
  width: 19px;
  height: 19px;
  stroke-width: 2.2;
}

.send-loader {
  display: none;
  color: #fff8f1;
}

.send-loader i {
  width: 4px;
  height: 4px;
}

.composer.loading .send-icon {
  display: none;
}

.composer.loading .send-loader {
  display: inline-flex;
}

.composer.loading .send-button {
  background: var(--accent-strong);
  opacity: 1;
}

.composer-note {
  margin: 8px auto 0;
  color: var(--text-faint);
  font-size: 10.5px;
  text-align: center;
}

.attachment-preview {
  align-items: center;
  gap: 8px;
  width: min(790px, 100%);
  margin: 0 auto 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-sm);
  color: var(--text-soft);
  font-size: 12px;
}

.attachment-preview:not([hidden]) {
  display: flex;
}

.attachment-preview > svg {
  width: 17px;
  height: 17px;
  color: var(--accent);
}

.attachment-preview span {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview button {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.attachment-preview button:hover {
  background: var(--surface-soft);
  color: var(--text);
}

.attachment-preview button svg {
  width: 14px;
  height: 14px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(390px, calc(100% - 36px));
  padding: 12px 15px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
  box-shadow: var(--shadow-md);
  color: var(--text-soft);
  font-size: 12px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.97);
  backdrop-filter: blur(20px);
  transition: opacity 0.25s ease, visibility 0.25s ease, transform 0.3s var(--ease);
}

.toast.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.toast svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--accent);
}

.sidebar-overlay {
  display: none;
}

.icon-fallback {
  display: inline-grid;
  place-items: center;
  width: 1em;
  height: 1em;
  font-style: normal;
  line-height: 1;
}

@media (max-width: 960px) {
  :root { --sidebar-width: 268px; }

  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    box-shadow: var(--shadow-lg);
    transform: translateX(-102%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-close,
  .mobile-menu {
    display: inline-grid;
  }

  .sidebar-overlay {
    position: absolute;
    inset: 0;
    z-index: 25;
    display: block;
    background: rgba(28, 20, 15, 0.34);
    opacity: 0;
    visibility: hidden;
    backdrop-filter: blur(3px);
    transition: opacity 0.3s ease, visibility 0.3s ease;
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  .topbar {
    padding: 0 18px;
  }

  .messages {
    width: min(820px, calc(100% - 34px));
  }
}

@media (max-width: 680px) {
  :root { --topbar-height: 64px; }

  .topbar {
    padding: 0 12px;
  }

  .topbar-actions {
    gap: 5px;
  }

  .personality-selector {
    max-width: 205px;
    padding-right: 8px;
  }

  .selector-label {
    display: none;
  }

  #selectedPersonality {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .theme-track {
    width: 48px;
    height: 28px;
  }

  .theme-thumb {
    width: 20px;
    height: 20px;
  }

  body[data-theme="dark"] .theme-thumb {
    transform: translateX(20px);
  }

  .welcome-screen {
    padding: 26px 16px 172px;
  }

  .spark-badge {
    width: 44px;
    height: 44px;
    margin-bottom: 18px;
    border-radius: 15px;
  }

  .welcome-content h1 {
    font-size: clamp(34px, 10vw, 47px);
  }

  .welcome-content > p {
    margin-top: 15px;
    font-size: 14px;
    line-height: 1.6;
  }

  .suggestion-grid {
    grid-template-columns: 1fr;
    gap: 9px;
    margin-top: 30px;
  }

  .suggestion-card {
    min-height: 70px;
    padding: 10px 12px;
    border-radius: 17px;
  }

  .suggestion-icon {
    width: 39px;
    height: 39px;
    border-radius: 12px;
  }

  .suggestion-grid .suggestion-card:nth-child(n+4) {
    display: none;
  }

  .messages {
    width: calc(100% - 28px);
    padding-top: 16px;
    padding-bottom: 184px;
  }

  .message-row {
    margin-bottom: 22px;
  }

  .user-bubble {
    max-width: 88%;
    font-size: 14px;
  }

  .assistant-body {
    font-size: 14.5px;
    line-height: 1.7;
  }

  .composer-region {
    padding: 28px 10px 9px;
  }

  .composer {
    padding: 10px 10px 8px;
    border-radius: 22px;
  }

  .composer textarea {
    min-height: 34px;
    padding: 5px 6px 7px;
    font-size: 15px;
  }

  .tools-button span {
    display: none;
  }

  .composer-tool {
    width: 36px;
    height: 36px;
    padding: 0;
  }

  .send-button {
    width: 38px;
    height: 38px;
  }

  .composer-note {
    font-size: 9.5px;
  }

  .attachment-preview {
    width: 100%;
  }

  .toast {
    right: 12px;
    bottom: 12px;
  }
}

@media (max-height: 720px) and (min-width: 681px) {
  .welcome-screen {
    padding-top: 18px;
  }

  .spark-badge {
    margin-bottom: 12px;
  }

  .welcome-content h1 {
    font-size: clamp(38px, 5vw, 54px);
  }

  .welcome-content > p {
    margin-top: 12px;
  }

  .suggestion-grid {
    margin-top: 24px;
  }
}

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

/* Login por senha e integração com o backend */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 18%, var(--glow-a), transparent 34%),
    radial-gradient(circle at 82% 78%, var(--glow-b), transparent 34%),
    color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(22px) saturate(115%);
  -webkit-backdrop-filter: blur(22px) saturate(115%);
  opacity: 1;
  visibility: visible;
  transition: opacity 0.42s var(--ease), visibility 0.42s ease;
}

.authenticated .login-screen {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.auth-loading .app-shell,
.auth-required .app-shell {
  pointer-events: none;
  transform: scale(0.988);
  filter: blur(8px);
  opacity: 0.66;
}

.app-shell {
  transition: transform 0.5s var(--ease), filter 0.45s ease, opacity 0.45s ease;
}

.login-ambient,
.login-ambient span {
  position: absolute;
  pointer-events: none;
}

.login-ambient {
  inset: 0;
}

.login-ambient span {
  width: 260px;
  height: 260px;
  border: 1px solid color-mix(in srgb, var(--accent) 16%, transparent);
  border-radius: 46% 54% 62% 38%;
  animation: login-float 11s ease-in-out infinite alternate;
}

.login-ambient span:nth-child(1) {
  top: -80px;
  left: 8%;
  rotate: 18deg;
}

.login-ambient span:nth-child(2) {
  right: 4%;
  bottom: -110px;
  width: 330px;
  height: 330px;
  animation-delay: -3.5s;
  rotate: -24deg;
}

.login-ambient span:nth-child(3) {
  top: 38%;
  right: 17%;
  width: 110px;
  height: 110px;
  animation-delay: -6s;
}

.login-card {
  position: relative;
  width: min(440px, 100%);
  padding: 38px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 30px;
  background: color-mix(in srgb, var(--surface-solid) 90%, transparent);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(28px) saturate(125%);
  -webkit-backdrop-filter: blur(28px) saturate(125%);
  animation: login-card-in 0.72s var(--ease) both;
}

.login-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  content: "";
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  opacity: 0.7;
}

.login-brand {
  display: grid;
  width: 54px;
  height: 54px;
  margin-bottom: 26px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--accent-pale);
  box-shadow: var(--shadow-sm);
}

.login-brand .brand-mark {
  transform: rotate(45deg) scale(1.1);
}

.login-kicker {
  margin: 0 0 9px;
  color: var(--accent);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.16em;
}

.login-card h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(28px, 5vw, 36px);
  line-height: 1.12;
  letter-spacing: -1.4px;
}

.login-description {
  margin: 12px 0 28px;
  color: var(--text-soft);
  line-height: 1.6;
}

.login-form {
  display: grid;
  gap: 10px;
}

.login-form > label {
  padding-left: 3px;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
}

.password-field {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 54px;
  padding: 0 10px 0 16px;
  border: 1px solid var(--border-strong);
  border-radius: 16px;
  background: var(--surface);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s var(--ease);
}

.password-field:focus-within {
  border-color: color-mix(in srgb, var(--accent) 64%, var(--border));
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--accent) 12%, transparent);
  transform: translateY(-1px);
}

.password-field > svg {
  width: 18px;
  color: var(--text-faint);
}

.password-field input {
  min-width: 0;
  height: 100%;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.password-field input::placeholder {
  color: var(--text-faint);
}

.password-field button {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.password-field button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.password-field button svg {
  width: 17px;
}

.login-error {
  min-height: 20px;
  margin: 0;
  padding: 0 3px;
  color: #a84a3f;
  font-size: 12px;
  line-height: 1.45;
}

body[data-theme="dark"] .login-error {
  color: #f0a49c;
}

.login-submit {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  height: 52px;
  margin-top: 2px;
  overflow: hidden;
  border: 0;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--accent-strong), var(--accent));
  color: #fffaf4;
  font-weight: 800;
  box-shadow: 0 12px 30px color-mix(in srgb, var(--accent) 24%, transparent);
  cursor: pointer;
  transition: transform 0.25s var(--ease), box-shadow 0.25s ease, opacity 0.2s ease;
}

.login-submit:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 16px 36px color-mix(in srgb, var(--accent) 32%, transparent);
}

.login-submit:active:not(:disabled) {
  transform: translateY(0) scale(0.99);
}

.login-submit:disabled {
  cursor: wait;
  opacity: 0.72;
}

.login-submit > svg {
  width: 18px;
}

.login-loader {
  display: none;
  align-items: center;
  gap: 4px;
}

.login-loader i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: thinking-bounce 0.9s ease-in-out infinite;
}

.login-loader i:nth-child(2) { animation-delay: 0.12s; }
.login-loader i:nth-child(3) { animation-delay: 0.24s; }

.login-form.loading .login-submit > span:first-child,
.login-form.loading .login-submit > svg {
  display: none;
}

.login-form.loading .login-loader {
  display: inline-flex;
}

.login-security {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin: 22px 0 0;
  color: var(--text-faint);
  font-size: 11px;
  text-align: center;
}

.login-security svg {
  width: 15px;
}

.logout-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-soft);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, transform 0.2s var(--ease);
}

.logout-button:hover {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
  transform: translateY(-1px);
}

.logout-button svg {
  width: 16px;
}

.error-message .assistant-message {
  padding: 14px 16px;
  border: 1px solid color-mix(in srgb, #a84a3f 24%, var(--border));
  border-radius: 16px;
  background: color-mix(in srgb, #a84a3f 6%, var(--surface));
}

@keyframes login-card-in {
  from { opacity: 0; transform: translateY(24px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes login-float {
  from { transform: translate3d(-12px, -8px, 0) rotate(-4deg); }
  to { transform: translate3d(18px, 20px, 0) rotate(8deg); }
}

@media (max-width: 680px) {
  .login-screen {
    padding: 14px;
  }

  .login-card {
    padding: 28px 22px;
    border-radius: 24px;
  }

  .login-brand {
    margin-bottom: 22px;
  }

  .logout-button {
    width: 38px;
    padding: 0;
    justify-content: center;
  }

  .logout-button span {
    display: none;
  }
}

.assistant-body ol {
  display: grid;
  gap: 8px;
  margin: 8px 0 14px;
  padding-left: 24px;
}

.assistant-body h3,
.assistant-body h4,
.assistant-body h5 {
  margin: 20px 0 8px;
  font-family: var(--font-display);
  line-height: 1.35;
  letter-spacing: -0.25px;
}

.assistant-body h3 { font-size: 18px; }
.assistant-body h4 { font-size: 16.5px; }
.assistant-body h5 { font-size: 15.5px; }

.assistant-body pre {
  max-width: 100%;
  margin: 14px 0;
  padding: 16px;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: color-mix(in srgb, var(--surface-soft) 76%, #17120f);
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12.5px;
  line-height: 1.65;
  tab-size: 2;
}

body:not([data-theme="dark"]) .assistant-body pre {
  background: #2a211b;
  color: #f6eadf;
}

.assistant-body :not(pre) > code {
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-soft);
  color: var(--accent-strong);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
}

.assistant-body blockquote {
  margin: 14px 0;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  border-radius: 0 12px 12px 0;
  background: var(--surface-soft);
  color: var(--text-soft);
}

/* Recursos de arquivo e personalidades dinâmicas */
.personality-loading {
  padding: 14px 12px;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.attachment-preview .attachment-info {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
  overflow: hidden;
  white-space: normal;
}

.attachment-preview .attachment-info strong,
.attachment-preview .attachment-info small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-preview .attachment-info strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.attachment-preview .attachment-info small {
  color: var(--text-faint);
  font-size: 10.5px;
}

.user-bubble {
  display: grid;
  gap: 9px;
}

.user-message-text:empty {
  display: none;
}

.message-attachment {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  max-width: 100%;
  padding: 7px 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, var(--border));
  border-radius: 11px;
  background: color-mix(in srgb, var(--surface-soft) 88%, var(--accent-pale));
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 600;
}

.message-attachment svg {
  width: 14px;
  height: 14px;
  flex: 0 0 auto;
  color: var(--accent-strong);
}

.message-attachment span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Ferramentas de geração */
.tools-wrap {
  position: relative;
}

.tools-button.active {
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.tools-popover {
  position: absolute;
  bottom: calc(100% + 12px);
  left: 0;
  z-index: 45;
  display: grid;
  width: min(330px, calc(100vw - 40px));
  padding: 7px;
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface-solid) 94%, transparent);
  box-shadow: 0 22px 60px rgba(61, 42, 29, 0.2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px) scale(0.98);
  transform-origin: left bottom;
  backdrop-filter: blur(22px) saturate(125%);
  -webkit-backdrop-filter: blur(22px) saturate(125%);
  transition: opacity 0.2s ease, transform 0.25s var(--ease), visibility 0.2s ease;
}

.tools-popover.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.tools-popover > button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  width: 100%;
  padding: 10px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  margin-bottom: 5px;
  border-radius: 13px;
  color: var(--text);
  text-align: left;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.tools-popover > button:hover {
  background: var(--surface-hover);
  transform: translateX(2px);
}

.tool-menu-icon {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: 13px;
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.tool-menu-icon svg {
  width: 20px;
  height: 20px;
}

.tools-popover button > span:last-child {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.tools-popover strong {
  font-size: 13px;
  font-weight: 750;
}

.tools-popover small {
  color: var(--text-faint);
  font-size: 10.5px;
  line-height: 1.35;
}

.active-tool-panel {
  position: relative;
  align-items: center;
  gap: 10px;
  margin: -2px -2px 9px;
  padding: 8px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 24%, var(--border));
  border-radius: 16px;
  background: color-mix(in srgb, var(--accent-pale) 65%, var(--surface-soft));
}

.active-tool-panel:not([hidden]) {
  display: flex;
}

.active-tool-icon {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 11px;
  background: var(--surface-solid);
  box-shadow: var(--shadow-sm);
  color: var(--accent-strong);
}

.active-tool-icon svg {
  width: 17px;
  height: 17px;
}

.active-tool-copy {
  display: grid;
  min-width: 130px;
  flex: 1;
  gap: 2px;
}

.active-tool-copy strong {
  color: var(--text);
  font-size: 12px;
}

.active-tool-copy small {
  overflow: hidden;
  color: var(--text-faint);
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-option {
  display: grid;
  flex: 0 0 auto;
  gap: 2px;
}

.tool-option span {
  padding-left: 3px;
  color: var(--text-faint);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

.tool-option select {
  min-width: 108px;
  height: 32px;
  padding: 0 28px 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  outline: none;
  background: var(--surface-solid);
  color: var(--text);
  font: inherit;
  font-size: 11px;
  font-weight: 650;
  cursor: pointer;
}

.tool-option select:focus {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--border));
}

.active-tool-close {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 9px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  color: var(--text-faint);
}

.active-tool-close:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.active-tool-close svg {
  width: 15px;
  height: 15px;
}

.message-tool-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  width: fit-content;
  padding: 6px 9px;
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--accent-pale) 72%, var(--surface-soft));
  color: var(--accent-strong);
  font-size: 10.5px;
  font-weight: 750;
}

.message-tool-chip svg {
  width: 13px;
  height: 13px;
}

.generated-artifact {
  width: min(610px, 100%);
  margin: 15px 0 6px;
  overflow: hidden;
  border: 1px solid var(--border-strong);
  border-radius: 19px;
  background: var(--surface-solid);
  box-shadow: 0 12px 34px rgba(68, 45, 30, 0.1);
}

.generated-artifact.image {
  display: grid;
}

.generated-image-shell {
  position: relative;
  display: grid;
  min-height: 260px;
  overflow: hidden;
  place-items: center;
  background:
    radial-gradient(circle at 22% 18%, color-mix(in srgb, var(--accent-pale) 85%, transparent), transparent 38%),
    linear-gradient(135deg, var(--surface-soft), color-mix(in srgb, var(--surface-solid) 65%, var(--accent-pale)));
}

.generated-image-shell img {
  display: block;
  width: 100%;
  max-height: 620px;
  object-fit: contain;
  background: #17120f;
}

.artifact-loading {
  display: flex;
  align-items: center;
  gap: 5px;
  color: var(--accent-strong);
}

.artifact-loading span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  animation: dotWave 1.15s ease-in-out infinite;
}

.artifact-loading span:nth-child(2) { animation-delay: 0.14s; }
.artifact-loading span:nth-child(3) { animation-delay: 0.28s; }

.artifact-loading small {
  margin-left: 6px;
  color: var(--text-faint);
  font-size: 11px;
}

.artifact-footer,
.generated-artifact.file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
}

.generated-file-icon {
  display: grid;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid color-mix(in srgb, var(--accent) 22%, var(--border));
  border-radius: 13px;
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.generated-file-icon svg {
  width: 21px;
  height: 21px;
}

.artifact-info {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 3px;
}

.artifact-info strong {
  overflow: hidden;
  color: var(--text);
  font-size: 12px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-info small {
  color: var(--text-faint);
  font-size: 10.5px;
}

.artifact-download {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 35px;
  padding: 0 12px;
  border-radius: 11px;
  background: var(--accent-strong);
  color: #fff9f4;
  font-size: 11px;
  font-weight: 750;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.artifact-download:hover:not(:disabled) {
  transform: translateY(-1px);
}

.artifact-download:disabled {
  cursor: wait;
  opacity: 0.45;
}

.artifact-download svg {
  width: 15px;
  height: 15px;
}

.artifact-unavailable {
  opacity: 0.72;
}

@media (max-width: 680px) {
  .active-tool-panel {
    flex-wrap: wrap;
  }

  .active-tool-copy {
    min-width: calc(100% - 88px);
  }

  .tool-option {
    flex: 1 1 140px;
    margin-left: 44px;
  }

  .tool-option select {
    width: 100%;
  }

  .active-tool-close {
    position: absolute;
    top: 9px;
    right: 20px;
  }

  .tools-popover {
    position: fixed;
    right: 16px;
    bottom: 88px;
    left: 16px;
    width: auto;
    transform-origin: center bottom;
  }

  .generated-image-shell {
    min-height: 210px;
  }

  .artifact-download span {
    display: none;
  }

  .artifact-download {
    width: 38px;
    padding: 0;
  }
}

/* Busca no histórico */
.nav-badge {
  display: inline-grid;
  min-width: 23px;
  height: 21px;
  place-items: center;
  margin-left: auto;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent-pale);
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
}

.history-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0 5px 14px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: color-mix(in srgb, var(--surface-solid) 62%, transparent);
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
}

.history-search:focus-within {
  border-color: color-mix(in srgb, var(--accent) 52%, var(--border));
  background: var(--surface-solid);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 10%, transparent);
}

.history-search > svg {
  width: 15px;
  height: 15px;
  flex: 0 0 auto;
  color: var(--text-faint);
}

.history-search input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 12px;
}

.history-search input::placeholder {
  color: var(--text-faint);
}

.history-search button {
  display: grid;
  width: 25px;
  height: 25px;
  place-items: center;
  flex: 0 0 auto;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
}

.history-search button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.history-search button svg {
  width: 13px;
  height: 13px;
}


/* Tabelas Markdown */
.assistant-body .table-scroll {
  width: 100%;
  margin: 15px 0 18px;
  overflow-x: auto;
  border: 1px solid var(--border-strong);
  border-radius: 15px;
  background: var(--surface-solid);
  box-shadow: 0 8px 24px rgba(68, 45, 30, 0.06);
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.assistant-body table {
  width: 100%;
  min-width: 560px;
  border-collapse: collapse;
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

.assistant-body th,
.assistant-body td {
  padding: 11px 13px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.assistant-body th:last-child,
.assistant-body td:last-child {
  border-right: 0;
}

.assistant-body tr:last-child td {
  border-bottom: 0;
}

.assistant-body th {
  background: color-mix(in srgb, var(--accent-pale) 70%, var(--surface-soft));
  color: var(--accent-strong);
  font-weight: 800;
}

.assistant-body tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-soft) 48%, transparent);
}

/* Fontes da pesquisa */
.research-sources {
  width: min(690px, 100%);
  margin: 16px 0 5px;
  padding: 13px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface-soft) 58%, transparent);
}

.research-sources-title {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  color: var(--text);
  font-size: 12px;
  font-weight: 800;
}

.research-sources-title svg {
  width: 16px;
  height: 16px;
  color: var(--accent-strong);
}

.research-source-list {
  display: grid;
  gap: 8px;
}

.research-source {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) 18px;
  gap: 9px;
  align-items: center;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text);
  text-decoration: none;
  transition: transform 0.2s var(--ease), border-color 0.2s ease, background-color 0.2s ease;
}

.research-source:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--surface-solid);
}

.research-source-index {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-pale);
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 800;
}

.research-source-copy {
  display: grid;
  min-width: 0;
  gap: 2px;
}

.research-source-copy strong,
.research-source-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.research-source-copy strong {
  font-size: 11.5px;
}

.research-source-copy small {
  color: var(--text-faint);
  font-size: 9.5px;
}

.research-source > svg {
  width: 15px;
  height: 15px;
  color: var(--text-faint);
}


@media (max-width: 920px) {
  .active-tool-panel:not([hidden]) {
    flex-wrap: wrap;
  }

}

@media (max-width: 680px) {

  .assistant-body .table-scroll {
    margin-right: -8px;
  }

}

/* Fórmulas matemáticas com KaTeX */
.assistant-body .katex {
  color: var(--text);
  font-size: 1.06em;
}

.assistant-body .katex-display {
  width: 100%;
  margin: 16px 0;
  padding: 13px 15px;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface-soft) 62%, transparent);
  text-align: center;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

.assistant-body .katex-display > .katex {
  display: inline-block;
  min-width: max-content;
  margin: 0 auto;
}

.assistant-body td .katex-display,
.assistant-body th .katex-display {
  margin: 6px 0;
  padding: 8px;
  border: 0;
  background: transparent;
}

@media (max-width: 680px) {
  .assistant-body .katex-display {
    margin-right: -8px;
    padding: 11px 12px;
  }
}

/* Gráficos de respostas e carregamento progressivo do histórico */
.load-older-messages {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  align-self: center;
  margin: 2px auto 18px;
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface-solid) 82%, transparent);
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .2s var(--ease), border-color .2s ease, background-color .2s ease;
}

.load-older-messages:hover {
  transform: translateY(-1px);
  border-color: var(--border-strong);
  background: var(--surface-solid);
}

.load-older-messages svg {
  width: 15px;
  height: 15px;
}

.response-charts {
  display: grid;
  gap: 14px;
  margin: 18px 0 4px;
}

.response-chart {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: color-mix(in srgb, var(--surface-solid) 86%, transparent);
  box-shadow: 0 14px 34px rgba(74, 49, 38, .07);
}

.response-chart-heading {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
  color: var(--text);
}

.response-chart-heading > span {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border-radius: 10px;
  background: var(--accent-pale);
  color: var(--accent-strong);
}

.response-chart-heading svg {
  width: 16px;
  height: 16px;
}

.response-chart-heading strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.response-chart-canvas {
  position: relative;
  width: 100%;
  height: clamp(250px, 36vw, 390px);
  min-height: 250px;
}

.response-chart-canvas canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-faint);
  font-size: 12px;
  text-align: center;
}

.response-chart-note {
  margin: 9px 2px 0;
  color: var(--text-faint);
  font-size: 10.5px;
}

.chart-data-details {
  margin-top: 10px;
  color: var(--text-muted);
  font-size: 11px;
}

.chart-data-details summary {
  width: fit-content;
  cursor: pointer;
  font-weight: 700;
}

.chart-data-table {
  margin-top: 9px;
  max-height: 300px;
  overflow: auto;
}

.chart-data-table table {
  min-width: 480px;
}

@media (max-width: 680px) {
  .response-chart {
    padding: 11px;
    border-radius: 15px;
  }

  .response-chart-canvas {
    height: 270px;
    min-height: 240px;
  }
}

/* Garante que controles ocultados pela lógica de ferramentas não reapareçam por regras de layout. */
#attachButton[hidden] {
  display: none !important;
}

/* Ajustes da interface restaurada sobre o backend reconstruído */
.reasoning-selector {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 40px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  color: var(--text-soft);
  background: transparent;
  transition: background-color .2s ease, border-color .2s ease;
}

.reasoning-selector:hover,
.reasoning-selector:focus-within {
  border-color: var(--border);
  background: color-mix(in srgb, var(--surface-solid) 58%, transparent);
}

.reasoning-selector > svg {
  width: 16px;
  height: 16px;
  color: var(--accent);
}

.reasoning-selector select {
  max-width: 106px;
  padding: 2px 20px 2px 0;
  border: 0;
  outline: 0;
  appearance: auto;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}

.reasoning-selector select option {
  background: var(--surface-solid);
  color: var(--text);
}

.attachment-preview {
  z-index: 2;
}

.assistant-body .table-scroll {
  margin: 16px 0;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
  box-shadow: 0 10px 28px rgba(74, 49, 38, .06);
}

.assistant-body table {
  width: 100%;
  min-width: 520px;
  border-collapse: separate;
  border-spacing: 0;
}

.assistant-body th,
.assistant-body td {
  padding: 11px 13px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}

.assistant-body th:last-child,
.assistant-body td:last-child { border-right: 0; }
.assistant-body tr:last-child td { border-bottom: 0; }
.assistant-body th {
  background: var(--accent-pale);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
}
.assistant-body tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--surface-soft) 45%, transparent);
}

.assistant-body .katex-display {
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: color-mix(in srgb, var(--surface-soft) 58%, transparent);
}

.error-message .assistant-body {
  padding: 13px 15px;
  border: 1px solid color-mix(in srgb, #c75b46 45%, var(--border));
  border-radius: 15px;
  background: color-mix(in srgb, #c75b46 9%, var(--surface));
}

@media (max-width: 760px) {
  .topbar-left { gap: 4px; }
  .reasoning-selector .selector-label { display: none; }
  .reasoning-selector { padding: 0 7px; }
  .reasoning-selector select { max-width: 88px; font-size: 11px; }
}

@media (max-width: 520px) {
  .reasoning-selector > svg { display: none; }
  .reasoning-selector select { max-width: 76px; }
  .personality-selector .selector-label { display: none; }
}

/* O seletor de arquivos só existe no chat comum. A regra visual complementa
   a proteção do JavaScript e impede flashes durante troca de ferramenta. */
.composer[data-tool-mode="research"] #attachButton,
.composer[data-tool-mode="file"] #attachButton {
  display: none !important;
}

.attachment-preview.attachment-list {
  flex-wrap: wrap;
  padding: 7px;
  gap: 7px;
  background: color-mix(in srgb, var(--surface-solid) 88%, transparent);
}

.attachment-list .attachment-item {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: min(230px, 100%);
  max-width: 100%;
  flex: 1 1 230px;
  padding: 8px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-solid);
}

.attachment-list .attachment-item > svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
  color: var(--accent);
}

.attachment-list .attachment-info {
  display: grid;
  min-width: 0;
  flex: 1;
}

.attachment-list .attachment-info strong,
.attachment-list .attachment-info small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-list .attachment-info strong {
  color: var(--text);
  font-size: 12px;
}

.attachment-list .attachment-info small {
  color: var(--text-faint);
  font-size: 10px;
}

[hidden] {
  display: none !important;
}
