/*
 * Tick Chat premium interface layer
 * A quiet, product-led system that replaces the former polish/corporate stacks.
 */

:root {
  --primary: #2563eb;
  --primary-light: #4f7ff0;
  --primary-dark: #1d4ed8;
  --primary-glow: rgba(37, 99, 235, 0.12);

  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef1f5;
  --surface-200: rgba(18, 24, 38, 0.055);
  --elevated: #ffffff;

  --text: #16181d;
  --text-2: #555b66;
  --text-3: #7d8490;
  --border: #e2e5ea;
  --border-2: #d3d7de;

  --sidebar-bg: #f5f6f8;
  --topbar-bg: #fbfbfc;
  --chat-bg: #ffffff;
  --bot-bubble: transparent;
  --user-bubble: #f4f6f8;
  --user-bubble-border: #dce2e9;
  --user-avatar-bg: #e8effa;
  --user-avatar-border: #d3deed;
  --user-avatar-icon: #2563eb;
  --code-bg: #11151d;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.07);
  --shadow-lg: 0 20px 48px rgba(16, 24, 40, 0.12);
  --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.18);

  --radius-sm: 8px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --transition-fast: 140ms ease;
  --transition-normal: 220ms var(--ease-out);
}

html.dark {
  --primary: #6ea8fe;
  --primary-light: #8bb8ff;
  --primary-dark: #4d8ef7;
  --primary-glow: rgba(110, 168, 254, 0.14);

  --surface: #15171c;
  --surface-2: #191c22;
  --surface-3: #20242c;
  --surface-200: rgba(255, 255, 255, 0.065);
  --elevated: #1a1d23;

  --text: #f3f5f7;
  --text-2: #b0b5be;
  --text-3: #7d8490;
  --border: rgba(255, 255, 255, 0.085);
  --border-2: rgba(255, 255, 255, 0.14);

  --sidebar-bg: #101216;
  --topbar-bg: #111318;
  --chat-bg: #0d0f12;
  --bot-bubble: transparent;
  --user-bubble: #1b1f26;
  --user-bubble-border: rgba(255, 255, 255, 0.085);
  --user-avatar-bg: #20242c;
  --user-avatar-border: rgba(255, 255, 255, 0.1);
  --user-avatar-icon: #b0b5be;
  --code-bg: #090b0f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 24px 56px rgba(0, 0, 0, 0.42);
  --focus-ring: 0 0 0 3px rgba(110, 168, 254, 0.2);
}

html {
  color-scheme: light;
  background: var(--chat-bg);
}

html.dark { color-scheme: dark; }

body.chat-app {
  font-family: Inter, "Segoe UI Variable", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  letter-spacing: -0.006em;
  background: var(--chat-bg);
  color: var(--text);
  transition: none;
  text-rendering: optimizeLegibility;
}

body.chat-app button,
body.chat-app input,
body.chat-app textarea,
body.chat-app select {
  font: inherit;
}

body.chat-app button,
body.chat-app a,
body.chat-app select {
  -webkit-tap-highlight-color: transparent;
}

body.chat-app button:focus-visible,
body.chat-app a:focus-visible,
body.chat-app input:focus-visible,
body.chat-app textarea:focus-visible,
body.chat-app select:focus-visible,
body.chat-app [tabindex]:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

body.chat-app ::selection {
  background: rgba(37, 99, 235, 0.22);
  color: inherit;
}

/* Layout */
body.chat-app main,
body.chat-app #chat-container {
  height: 100dvh;
  min-height: 0;
}

body.chat-app #chat-container > div:last-child {
  container: chat-shell / inline-size;
  background: var(--chat-bg);
}

/* Sidebar */
body.chat-app #sidebar {
  width: 284px;
  flex: 0 0 284px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  box-shadow: none;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  will-change: transform;
}

body.chat-app .glass-sidebar {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.chat-app #sidebar > .p-5 {
  padding: 18px 14px 10px;
}

body.chat-app #sidebar > .p-5 > .flex:first-child {
  min-height: 40px;
  margin-bottom: 18px !important;
  padding-inline: 4px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  box-shadow: var(--shadow-sm);
  flex: none;
}

.brand-copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 1px;
  line-height: 1.15;
}

.brand-copy strong {
  color: var(--text);
  font-size: 13.5px;
  font-weight: 680;
  letter-spacing: -0.015em;
}

.brand-copy small {
  color: var(--text-3);
  font-size: 10.5px;
  font-weight: 500;
  letter-spacing: 0.015em;
}

body.chat-app #sidebar-close {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  padding: 0;
  border-radius: 9px;
  border: 1px solid transparent;
  color: var(--text-3);
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app #sidebar-close:hover {
  color: var(--text);
  background: var(--surface-200);
  border-color: var(--border);
}

body.chat-app .sidebar-section {
  margin: 0 2px 15px;
}

body.chat-app .sidebar-section-heading {
  margin: 0 7px 7px;
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.085em;
  line-height: 1.3;
  text-transform: uppercase;
}

body.chat-app .sidebar-section-head {
  min-height: 27px;
}

body.chat-app .sidebar-create-btn {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  color: var(--text-3);
  transition: color var(--transition-fast), background var(--transition-fast);
}

body.chat-app .sidebar-create-btn:hover {
  color: var(--text);
  background: var(--surface-200);
}

body.chat-app .sidebar-general-card,
body.chat-app .project-row {
  min-height: 42px;
  padding: 7px 8px;
  gap: 9px;
  border: 1px solid transparent !important;
  border-radius: 9px !important;
  background: transparent;
  color: var(--text-2) !important;
  box-shadow: none;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app .sidebar-general-card:hover,
body.chat-app .project-row:hover {
  color: var(--text) !important;
  background: var(--surface-200);
  border-color: var(--border) !important;
}

body.chat-app .sidebar-item-icon,
body.chat-app .project-row-icon {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--surface-3);
  color: var(--text-2);
}

body.chat-app .sidebar-item-title,
body.chat-app .project-row-title {
  font-size: 12px;
  font-weight: 620;
  color: inherit;
}

body.chat-app .sidebar-item-meta,
body.chat-app .project-row-meta {
  color: var(--text-3);
  font-size: 9.5px;
}

body.chat-app #project-list {
  scrollbar-width: thin;
  scrollbar-color: color-mix(in srgb, var(--text-3) 38%, transparent) transparent;
  scrollbar-gutter: stable;
  transition: max-height 180ms var(--ease-out);
}

body.chat-app #project-list:has(.project-overflow[open]) {
  max-height: min(44dvh, 320px);
}

body.chat-app #project-list::-webkit-scrollbar { width: 4px; }
body.chat-app #project-list::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-3) 38%, transparent);
}

body.chat-app .project-overflow {
  margin-top: 4px;
}

body.chat-app .project-overflow-summary {
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 8px;
  list-style: none;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text-3);
  cursor: pointer;
  user-select: none;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app .project-overflow-summary::-webkit-details-marker { display: none; }

body.chat-app .project-overflow-summary:hover,
body.chat-app .project-overflow-summary:focus-visible {
  color: var(--text);
  background: var(--surface-200);
  border-color: var(--border);
  outline: none;
}

body.chat-app .project-overflow-summary__label {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  gap: 7px;
  font-size: 10.5px;
  font-weight: 650;
}

body.chat-app .project-overflow-chevron {
  flex: none;
  transition: transform 160ms var(--ease-out);
}

body.chat-app .project-overflow[open] .project-overflow-chevron {
  transform: rotate(180deg);
}

body.chat-app .project-overflow-count {
  min-width: 22px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding-inline: 6px;
  border-radius: 999px;
  background: var(--surface-3);
  color: var(--text-2);
  font-size: 9.5px;
  font-weight: 700;
}

body.chat-app .project-overflow-panel {
  display: grid;
  gap: 3px;
  padding-top: 3px;
}

body.chat-app .project-overflow:not([open]) > .project-overflow-panel {
  display: none;
}

body.chat-app .sidebar-primary-action {
  width: calc(100% - 4px) !important;
  height: 40px !important;
  min-height: 40px !important;
  margin: 4px 2px 0 !important;
  padding: 0 12px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: flex-start !important;
  gap: 9px !important;
  border: 1px solid #2563eb !important;
  border-radius: 10px !important;
  background: #2563eb !important;
  color: #fff !important;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.18) !important;
  font-size: 12px !important;
  font-weight: 650 !important;
  transition: background var(--transition-fast), border-color var(--transition-fast), transform 90ms ease !important;
}

/* The premium rule above intentionally owns the button layout. Its
   !important display must never override the semantic hidden state. */
body.chat-app .sidebar-primary-action.hidden,
body.chat-app .sidebar-primary-action[hidden] {
  display: none !important;
}

body.chat-app .sidebar-primary-action:hover {
  background: #1f58cf !important;
  border-color: #1f58cf !important;
}

body.chat-app .sidebar-primary-action:active { transform: scale(0.985); }

body.chat-app .sidebar-primary-action__icon {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.13);
  color: #fff;
}

body.chat-app .sidebar-project-form {
  margin: 7px 0 4px;
  padding: 11px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
  box-shadow: var(--shadow-md);
}

body.chat-app .sidebar-project-input {
  border-radius: 8px;
  background: var(--surface-2);
  border-color: var(--border);
}

body.chat-app .sidebar-project-input:focus {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

body.chat-app .sidebar-conversation-section {
  display: flex;
  min-height: 0;
  flex: 1 1 auto;
  flex-direction: column;
  padding-top: 7px;
  border-top: 1px solid var(--border);
}

body.chat-app .sidebar-conversation-heading {
  margin: 4px 20px 8px;
}

body.chat-app .conversation-search {
  min-height: 38px;
  margin: 0 14px 9px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

body.chat-app .conversation-search:focus-within {
  border-color: var(--primary);
  box-shadow: var(--focus-ring);
}

body.chat-app .conversation-search input {
  font-size: 11.5px;
  color: var(--text);
}

body.chat-app #chat-list {
  padding: 0 10px 10px;
  scrollbar-gutter: stable;
}

body.chat-app #chat-list > [data-chat-id] {
  position: relative;
  min-height: 38px;
  margin: 1px 0;
  border: 1px solid transparent;
  border-radius: 9px;
  color: var(--text-2);
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app #chat-list > [data-chat-id]:hover {
  color: var(--text);
  background: var(--surface-200);
  border-color: var(--border);
}

body.chat-app #chat-list > [data-chat-id][data-current-chat],
body.chat-app #chat-list > [data-chat-id].is-current-chat {
  color: var(--text);
  background: var(--surface);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

body.chat-app #chat-list > [data-chat-id][data-current-chat]::before,
body.chat-app #chat-list > [data-chat-id].is-current-chat::before {
  content: "";
  position: absolute;
  inset-block: 9px;
  inset-inline-start: 0;
  width: 2px;
  border-radius: 999px;
  background: var(--primary);
}

body.chat-app .sidebar-inline-state {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  gap: 8px;
  padding: 9px;
  border: 1px solid rgba(210, 75, 75, .16);
  border-radius: 9px;
  background: rgba(210, 75, 75, .055);
}

body.chat-app .sidebar-inline-state__icon {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 7px;
  background: rgba(210, 75, 75, .1);
  color: #d65353;
  font-size: 11px;
  font-weight: 750;
}

body.chat-app .sidebar-inline-state__copy {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 2px;
}

body.chat-app .sidebar-inline-state__copy strong { color: var(--text-2); font-size: 10px; font-weight: 650; }
body.chat-app .sidebar-inline-state__copy small { color: var(--text-3); font-size: 8.5px; line-height: 1.35; }

body.chat-app .sidebar-inline-state button {
  grid-column: 2;
  justify-self: start;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--primary);
  font-size: 9.5px;
  font-weight: 650;
}

body.chat-app .sidebar-history-actions {
  flex: none;
  padding: 9px 12px 10px;
  border-top: 1px solid var(--border);
}

body.chat-app #clear-history {
  min-height: 34px;
  border-radius: 9px;
  background: transparent;
  border-color: transparent !important;
  color: var(--text-3) !important;
  font-size: 11px;
}

body.chat-app #clear-history:hover {
  background: rgba(220, 38, 38, 0.07);
  border-color: rgba(220, 38, 38, 0.13) !important;
  color: #dc4c4c !important;
}

body.chat-app #sidebar-theme { display: none; }

/* Top bar */
body.chat-app #topbar {
  height: 58px;
  padding-inline: clamp(12px, 2vw, 24px);
  gap: 14px;
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border);
  box-shadow: none;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.chat-app #topbar > .flex:first-child { gap: 10px; }

body.chat-app #sidebar-open,
body.chat-app #quota-toggle-btn,
body.chat-app .topbar-icon-button,
body.chat-app #project-settings-btn,
body.chat-app #topbar-about {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app #sidebar-open:hover,
body.chat-app #quota-toggle-btn:hover,
body.chat-app .topbar-icon-button:hover,
body.chat-app #project-settings-btn:hover,
body.chat-app #topbar-about:hover {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-2);
}

body.chat-app #current-project-name {
  color: var(--text-3) !important;
  font-size: 9.5px;
  font-weight: 550;
  line-height: 1.2;
}

body.chat-app #current-chat-title {
  color: var(--text) !important;
  font-size: 13px;
  font-weight: 660;
  letter-spacing: -0.015em;
  line-height: 1.25;
}

body.chat-app #rename-chat-btn { color: var(--text-3); }

body.chat-app #topbar > .flex:last-child {
  gap: 7px;
  max-width: min(68%, 760px);
  padding-block: 4px;
}

body.chat-app #user-settings-btn,
body.chat-app #logout-btn,
body.chat-app #topbar-about,
body.chat-app #admin-link { display: none !important; }

body.chat-app #user-menu-btn {
  gap: 7px;
  max-width: 164px;
}

body.chat-app #user-menu-btn > svg { flex: 0 0 auto; }

body.chat-app .user-menu-name {
  min-width: 0;
  max-width: 104px;
  overflow: hidden;
  color: var(--text-2);
  font-size: 11px;
  font-weight: 650;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.chat-app .select-pill {
  min-width: 132px;
  height: 34px;
  padding: 0 7px 0 9px;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

body.chat-app .select-pill:hover,
body.chat-app .select-pill:focus-within {
  background: var(--surface-2);
  border-color: var(--border-2);
  box-shadow: none;
}

body.chat-app .select-pill:focus-within { box-shadow: var(--focus-ring); }

body.chat-app .select-pill select {
  min-width: 0;
  flex: 1;
  font-size: 10.5px;
  font-weight: 600;
  color: var(--text);
}

body.chat-app .usage-wrap,
body.chat-app #user-menu-wrap { position: relative; }

body.chat-app #usage-pill:not(.hidden) {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
  font-size: 10.5px;
  font-weight: 620;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

body.chat-app #usage-pill:hover,
body.chat-app #usage-pill[aria-expanded="true"] {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border-2);
}

body.chat-app .usage-pill__bar {
  width: 24px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-3);
}

body.chat-app .usage-pill__bar > span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
  transition: width 320ms var(--ease-out);
}

body.chat-app .usage-popover,
body.chat-app .tc-menu {
  position: absolute;
  top: calc(100% + 8px);
  inset-inline-end: 0;
  z-index: 80;
  border: 1px solid var(--border);
  border-radius: 13px;
  background: var(--elevated);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

body.chat-app .usage-popover {
  width: min(360px, calc(100vw - 24px));
  max-height: min(520px, calc(100dvh - 90px));
  padding: 14px;
  overflow: auto;
  scrollbar-gutter: stable;
}

body.chat-app .usage-popover__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1px 2px 11px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 660;
}

body.chat-app .usage-popover__head span:last-child {
  color: #17845b;
  font-size: 9.5px;
  font-weight: 650;
}

body.chat-app .usage-popover__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

body.chat-app .usage-stat {
  display: flex;
  min-height: 66px;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
}

body.chat-app .usage-stat span,
body.chat-app .usage-model-row span,
body.chat-app .usage-model-empty {
  color: var(--text-3);
  font-size: 9.5px;
}

body.chat-app .usage-stat strong,
body.chat-app .usage-model-row strong {
  color: var(--text);
  font-size: 12px;
  font-weight: 680;
}

body.chat-app .usage-models {
  display: grid;
  gap: 5px;
  margin-top: 10px;
}

body.chat-app .usage-model-row,
body.chat-app .usage-model-empty {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 34px;
  padding: 7px 9px;
  border-radius: 8px;
  background: var(--surface-2);
}

body.chat-app .tc-menu {
  width: 220px;
  padding: 6px;
}

body.chat-app .user-menu-identity {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  padding: 7px 8px 8px;
}

body.chat-app .user-menu-identity__avatar {
  display: inline-flex;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text-2);
}

body.chat-app .user-menu-identity__copy {
  display: grid;
  min-width: 0;
  gap: 3px;
}

body.chat-app .user-menu-identity__copy strong,
body.chat-app .user-menu-identity__copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

body.chat-app .user-menu-identity__copy strong {
  color: var(--text);
  font-size: 11.5px;
  font-weight: 680;
}

body.chat-app .user-menu-identity__copy small {
  color: var(--text-3);
  font-size: 9.5px;
  font-weight: 560;
}

body.chat-app .tc-menu.hidden,
body.chat-app .tc-menu-item.hidden,
body.chat-app .tc-menu-item[hidden] { display: none; }

body.chat-app .tc-menu-item {
  display: flex;
  width: 100%;
  min-height: 36px;
  align-items: center;
  gap: 9px;
  padding: 0 9px;
  border-radius: 8px;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 560;
  text-decoration: none;
  transition: background var(--transition-fast), color var(--transition-fast);
}

body.chat-app .tc-menu-item svg { color: var(--text-3); }

body.chat-app .tc-menu-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

body.chat-app .tc-menu-item--danger:hover { color: #dc4c4c; background: rgba(220, 38, 38, 0.08); }
body.chat-app .tc-menu-sep { height: 1px; margin: 5px 2px; background: var(--border); }

/* Quota panel */
@media (min-width: 768px) {
  body.chat-app #quota-panel,
  body.chat-app #quota-toggle-btn { display: none !important; }
}

body.chat-app #quota-panel {
  min-height: 42px;
  padding: 6px 16px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

body.chat-app #quota-panel .w-7.h-7 {
  background: var(--surface-3) !important;
  border: 1px solid var(--border);
}

body.chat-app #quota-panel .w-7.h-7 svg { color: var(--text-2) !important; }

body.chat-app #quota-fill { background: var(--primary); transition: width 320ms var(--ease-out); }

/* Chat canvas and empty state */
body.chat-app #chat-box {
  padding: 24px clamp(16px, 4vw, 48px) 10px !important;
  background: var(--chat-bg);
  scroll-behavior: auto;
  scrollbar-gutter: stable;
  overscroll-behavior-y: contain;
}

body.chat-app #chat-box::-webkit-scrollbar { width: 9px; }
body.chat-app #chat-box::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background: color-mix(in srgb, var(--text-3) 42%, transparent);
  background-clip: padding-box;
}

body.chat-app #empty-state {
  min-height: 100%;
  padding: 40px 18px 72px;
}

body.chat-app #empty-state > .relative:first-child {
  margin-bottom: 22px;
}

body.chat-app #empty-state > .relative:first-child > .absolute { display: none; }

body.chat-app #empty-state > .relative:first-child > .relative {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--border) !important;
  border-radius: 16px;
  background: var(--surface) !important;
  box-shadow: var(--shadow-md) !important;
}

body.chat-app #empty-state > .relative:first-child svg {
  width: 23px;
  height: 23px;
  color: var(--primary) !important;
}

body.chat-app #empty-state h2 {
  max-width: 620px;
  margin: 0;
  color: var(--text) !important;
  font-size: clamp(24px, 3.2vw, 34px);
  font-weight: 660;
  letter-spacing: -0.035em;
  line-height: 1.12;
  text-align: center;
  text-wrap: balance;
}

body.chat-app .empty-state-copy {
  max-width: 460px;
  margin: 11px auto 28px;
  color: var(--text-3);
  font-size: 13px;
  line-height: 1.55;
  text-align: center;
  text-wrap: pretty;
}

body.chat-app .suggest-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 620px);
  gap: 9px;
}

body.chat-app .suggest-card {
  min-width: 0;
  min-height: 68px;
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 11px;
  padding: 12px 13px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: var(--text);
  text-align: start;
  transform: none;
  transition: background var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast), transform 100ms ease;
}

body.chat-app .suggest-card:hover {
  background: var(--surface-2);
  border-color: var(--border-2);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

body.chat-app .suggest-card:active { transform: translateY(0) scale(0.99); }

body.chat-app .suggest-icon {
  width: 32px;
  height: 32px;
  padding: 7px;
  border-radius: 9px;
  background: var(--surface-3);
  color: var(--text-2);
}

body.chat-app .suggest-title {
  color: var(--text);
  font-size: 12px;
  font-weight: 660;
  line-height: 1.25;
}

body.chat-app .suggest-desc {
  margin-top: 3px;
  color: var(--text-3);
  font-size: 10.5px;
  line-height: 1.35;
}

/* Composer */
body.chat-app #chat-box + div {
  padding: 12px clamp(14px, 3vw, 28px) max(14px, env(safe-area-inset-bottom)) !important;
  border-top: 0 !important;
  background: linear-gradient(to top, var(--chat-bg) 72%, color-mix(in srgb, var(--chat-bg) 92%, transparent)) !important;
}

body.chat-app #chat-box + div > div { max-width: 860px; }

body.chat-app #composer {
  min-height: 58px;
  display: flex;
  align-items: flex-end;
  gap: 4px !important;
  padding: 7px 8px !important;
  border: 1px solid var(--border) !important;
  border-radius: 17px !important;
  background: var(--surface) !important;
  box-shadow: 0 10px 32px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.05) !important;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast) !important;
}

html.dark body.chat-app #composer {
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.34), 0 1px 0 rgba(255, 255, 255, 0.035) !important;
}

body.chat-app #composer:focus-within {
  border-color: color-mix(in srgb, var(--primary) 68%, var(--border)) !important;
  box-shadow: var(--focus-ring), 0 12px 34px rgba(16, 24, 40, 0.09) !important;
}

body.chat-app #composer textarea,
body.chat-app #user-in {
  min-height: 42px !important;
  max-height: 160px !important;
  padding: 10px 9px !important;
  color: var(--text) !important;
  font-size: 13px !important;
  line-height: 1.55 !important;
  caret-color: var(--primary);
}

body.chat-app #user-in::placeholder { color: var(--text-3); opacity: 0.8; }

body.chat-app #attach-btn,
body.chat-app #voice-btn,
body.chat-app #search-toggle-btn,
body.chat-app #scientific-toggle-btn,
body.chat-app #code-interpreter-toggle-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 10px;
  color: var(--text-3) !important;
  opacity: 1 !important;
  transition: color var(--transition-fast), background var(--transition-fast), border-color var(--transition-fast), transform 90ms ease;
}

body.chat-app #attach-btn:hover,
body.chat-app #voice-btn:hover,
body.chat-app #search-toggle-btn:hover,
body.chat-app #scientific-toggle-btn:hover,
body.chat-app #code-interpreter-toggle-btn:hover {
  color: var(--text) !important;
  background: var(--surface-2);
  border-color: var(--border);
}

body.chat-app #search-toggle-btn[aria-pressed="true"],
body.chat-app #scientific-toggle-btn[aria-pressed="true"],
body.chat-app #code-interpreter-toggle-btn[aria-pressed="true"] {
  color: var(--primary) !important;
  background: var(--primary-glow);
  border-color: color-mix(in srgb, var(--primary) 28%, transparent);
}

body.chat-app #send-btn {
  width: 38px;
  min-width: 38px;
  height: 38px;
  min-height: 38px;
  margin-inline-start: 2px;
  border: 1px solid #2563eb;
  border-radius: 11px;
  background: #2563eb;
  color: #fff;
  box-shadow: 0 2px 6px rgba(37, 99, 235, 0.2);
  transition: background var(--transition-fast), border-color var(--transition-fast), transform 90ms ease;
}

body.chat-app #send-btn:hover { background: #1f58cf; border-color: #1f58cf; transform: none; }
body.chat-app #send-btn:active { transform: scale(0.94); }
body.chat-app #send-btn:disabled { opacity: 0.42; cursor: not-allowed; box-shadow: none; }
body.chat-app #send-btn.stop-btn { background: #d14343 !important; border-color: #d14343 !important; box-shadow: none !important; }

body.chat-app #file-preview,
body.chat-app #quote-preview {
  border: 1px solid var(--border) !important;
  border-radius: 13px !important;
  background: var(--elevated) !important;
  box-shadow: var(--shadow-lg) !important;
}

/* Messages */
body.chat-app .message-row {
  width: min(100%, 860px);
  margin-inline: auto;
  margin-bottom: 26px !important;
  gap: 12px !important;
  content-visibility: auto;
  contain-intrinsic-block-size: auto 150px;
}

body.chat-app .message-row:has(.ai-typing-indicator),
body.chat-app .message-row:has(.thinking-indicator) { content-visibility: visible; }

body.chat-app .msg-avatar {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  margin-top: 2px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text-2);
  box-shadow: var(--shadow-sm);
}

body.chat-app .msg-avatar svg { width: 14px; height: 14px; }
body.chat-app .msg-avatar img { width: 30px; height: 30px; border-radius: 9px; }

body.chat-app .msg-avatar-user {
  border-color: var(--user-avatar-border);
  background: var(--user-avatar-bg);
  color: var(--user-avatar-icon);
}

body.chat-app .msg-avatar-user svg {
  stroke: currentColor !important;
}

body.chat-app .bubble-wrapper {
  display: flex;
  min-width: 0;
  max-width: calc(100% - 44px);
  flex-direction: column;
  align-items: flex-start;
}

body.chat-app .message-row--user .bubble-wrapper { align-items: flex-end; }

body.chat-app .msg-bubble {
  min-width: 0 !important;
  max-width: 100%;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
}

body.chat-app .msg-bubble.msg-user {
  max-width: min(720px, 100%);
  padding: 10px 13px !important;
  border: 1px solid var(--user-bubble-border) !important;
  border-radius: 14px 14px 4px 14px !important;
  background: var(--user-bubble) !important;
}

body.chat-app .msg-bubble.msg-bot,
html.dark body.chat-app .msg-bubble.msg-bot {
  background: transparent !important;
  border-color: transparent !important;
}

body.chat-app .prose {
  color: var(--text) !important;
  font-size: 14px !important;
  line-height: 1.72 !important;
}

body.chat-app .prose p,
body.chat-app .prose li { text-wrap: pretty; }

body.chat-app .prose h1,
body.chat-app .prose h2,
body.chat-app .prose h3,
body.chat-app .prose h4 {
  color: var(--text);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

body.chat-app .prose a {
  color: var(--primary);
  text-decoration-color: color-mix(in srgb, var(--primary) 40%, transparent);
  text-underline-offset: 3px;
}

body.chat-app .prose blockquote {
  border-inline-start: 2px solid var(--border-2);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}

body.chat-app .prose table {
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: none;
}

body.chat-app .prose thead { background: var(--surface-2); }

body.chat-app .code-wrap {
  border: 1px solid var(--border) !important;
  border-radius: 12px !important;
  box-shadow: none !important;
}

body.chat-app .code-wrap pre {
  margin: 0 !important;
  border: 0 !important;
  border-radius: 0 !important;
  box-shadow: none !important;
}

body.chat-app .msg-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  min-height: 28px;
  margin-top: 5px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

body.chat-app .message-row:hover .msg-actions,
body.chat-app .message-row:focus-within .msg-actions { opacity: 1; }

body.chat-app .msg-actions > button,
body.chat-app .msg-actions > .export-menu-wrap > button {
  width: 28px !important;
  height: 28px !important;
  display: inline-grid !important;
  place-items: center !important;
  padding: 0 !important;
  border: 0 !important;
  border-radius: 7px !important;
  background: transparent !important;
  color: var(--text-3) !important;
  transition: color var(--transition-fast), background var(--transition-fast) !important;
}

body.chat-app .msg-actions > button:hover,
body.chat-app .msg-actions > .export-menu-wrap > button:hover {
  color: var(--text) !important;
  background: var(--surface-200) !important;
}


body.chat-app .thinking-indicator,
body.chat-app .ai-typing-indicator {
  min-height: 28px;
  color: var(--text-3);
}

body.chat-app .kimi-reasoning-details {
  width: 100%;
  margin: 0 0 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface-2);
}

body.chat-app .kimi-reasoning-summary {
  padding: 9px 12px;
  cursor: pointer;
  color: var(--text-2);
  font-size: 11.5px;
  font-weight: 650;
  list-style: none;
  user-select: none;
}

body.chat-app .kimi-reasoning-summary::-webkit-details-marker { display: none; }

body.chat-app .kimi-reasoning-body {
  max-height: 300px;
  margin: 0 !important;
  padding: 0 12px 12px !important;
  overflow: auto !important;
  border: 0 !important;
  border-radius: 0 !important;
  background: transparent !important;
  color: var(--text-3) !important;
  font: 11.5px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace !important;
  white-space: pre-wrap !important;
  word-break: break-word !important;
}

body.chat-app .tool-activity,
body.chat-app .reasoning-status {
  width: min(100%, 860px);
  margin-inline: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  box-shadow: none;
}

body.chat-app .chat-scroll-toggle {
  right: 22px;
  bottom: 92px;
  width: 38px;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--elevated);
  color: var(--text-2);
  box-shadow: var(--shadow-md);
  transform: none;
}

body.chat-app .chat-scroll-toggle:hover { color: var(--text); background: var(--surface-2); transform: translateY(-1px); }

/* Dialogs and shared feedback */
body.chat-app .confirm-overlay,
body.chat-app #project-settings-modal,
body.chat-app #user-settings-modal,
body.chat-app .rename-modal {
  background: rgba(8, 10, 14, 0.56) !important;
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

body.chat-app .confirm-modal,
body.chat-app #project-settings-modal > div,
body.chat-app #user-settings-modal > div,
body.chat-app .rename-dialog {
  border: 1px solid var(--border) !important;
  border-radius: 16px !important;
  background: var(--elevated) !important;
  box-shadow: var(--shadow-lg) !important;
}

body.chat-app .rename-field input,
body.chat-app #project-settings-modal input,
body.chat-app #project-settings-modal textarea,
body.chat-app #user-settings-modal input {
  border-radius: 10px;
  border-color: var(--border) !important;
  background: var(--surface-2) !important;
}

body.chat-app .rename-field input:focus,
body.chat-app #project-settings-modal input:focus,
body.chat-app #project-settings-modal textarea:focus,
body.chat-app #user-settings-modal input:focus {
  border-color: var(--primary) !important;
  box-shadow: var(--focus-ring) !important;
}

body.chat-app .toast {
  border-radius: 13px;
  border-color: var(--border);
  background: var(--elevated);
  box-shadow: var(--shadow-lg);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Mobile controls */
body.chat-app #mobile-strip {
  min-height: 44px;
  background: var(--topbar-bg) !important;
  border-color: var(--border) !important;
}

body.chat-app .strip-pill {
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
}

body.chat-app .strip-pill select { color: var(--text); }

@media (min-width: 768px) {
  body.chat-app #sidebar {
    transition:
      width 220ms ease,
      flex-basis 220ms ease,
      opacity 160ms ease,
      transform 220ms ease,
      border-color 160ms ease;
  }

  body.chat-app.sidebar-collapsed #sidebar {
    width: 0 !important;
    min-width: 0 !important;
    flex-basis: 0 !important;
    overflow: hidden;
    border-right-width: 0;
    border-right-color: transparent;
    opacity: 0;
    pointer-events: none;
    transform: translateX(-16px) !important;
  }
}

@container chat-shell (max-width: 760px) {
  body.chat-app .suggest-grid { width: min(100%, 520px); }
  body.chat-app #thinking-pill { display: none; }
  body.chat-app .select-pill { min-width: 112px; }
}

@media (max-width: 1024px) {
  body.chat-app #topbar > .flex:last-child { max-width: 58%; }
  body.chat-app #usage-mini-text { display: none; }
  body.chat-app #usage-pill:not(.hidden) { width: 34px; padding: 0; justify-content: center; }
  body.chat-app .usage-pill__bar { width: 18px; }
  body.chat-app .select-pill { min-width: 112px; }
}

@media (max-width: 767px) {
  body.chat-app #sidebar {
    width: min(88vw, 318px);
    flex-basis: min(88vw, 318px);
    box-shadow: 18px 0 54px rgba(0, 0, 0, 0.22);
  }

  body.chat-app .project-row-action { opacity: 1; }

  body.chat-app #sidebar-overlay {
    background: rgba(8, 10, 14, 0.52);
    backdrop-filter: none !important;
  }

  body.chat-app #topbar {
    height: 52px !important;
    padding: 0 10px !important;
    gap: 7px;
  }

  body.chat-app #topbar > .flex:last-child {
    max-width: none !important;
    gap: 5px !important;
    overflow: visible !important;
  }

  body.chat-app #chat-search-toggle,
  body.chat-app #usage-pill,
  body.chat-app #project-settings-btn { display: none !important; }

  body.chat-app #chat-box {
    padding: 16px 12px 8px !important;
  }

  body.chat-app #empty-state {
    justify-content: flex-start;
    padding-top: clamp(40px, 10vh, 82px);
    padding-bottom: 36px;
  }

  body.chat-app #empty-state > .relative:first-child { margin-bottom: 17px; }
  body.chat-app #empty-state > .relative:first-child > .relative { width: 48px; height: 48px; border-radius: 14px; }
  body.chat-app #empty-state h2 { font-size: clamp(22px, 7vw, 29px); }
  body.chat-app .empty-state-copy { margin: 8px auto 22px; font-size: 12px; }

  body.chat-app .suggest-grid {
    grid-template-columns: 1fr;
    width: min(100%, 410px);
  }

  body.chat-app .suggest-card { min-height: 58px; }

  body.chat-app #chat-box + div {
    padding: 8px 8px max(8px, env(safe-area-inset-bottom)) !important;
  }

  body.chat-app #composer {
    min-height: 50px;
    padding: 5px !important;
    border-radius: 14px !important;
  }

  body.chat-app #composer textarea,
  body.chat-app #user-in {
    min-height: 38px !important;
    padding: 8px 6px !important;
    font-size: 16px !important;
  }

  body.chat-app #attach-btn,
  body.chat-app #voice-btn,
  body.chat-app #search-toggle-btn,
  body.chat-app #scientific-toggle-btn,
  body.chat-app #code-interpreter-toggle-btn {
    width: 32px !important;
    min-width: 32px !important;
    height: 32px !important;
    min-height: 32px !important;
    padding: 0 !important;
    border-radius: 9px !important;
  }

  body.chat-app #scientific-toggle-btn,
  body.chat-app #code-interpreter-toggle-btn { display: none; }

  body.chat-app #send-btn {
    width: 34px !important;
    min-width: 34px !important;
    height: 34px !important;
    min-height: 34px !important;
    border-radius: 10px !important;
  }

  body.chat-app .message-row {
    margin-bottom: 21px !important;
    gap: 8px !important;
  }

  body.chat-app .msg-avatar {
    width: 26px;
    height: 26px;
    flex-basis: 26px;
    border-radius: 8px;
  }

  body.chat-app .msg-avatar img { width: 26px; height: 26px; border-radius: 8px; }
  body.chat-app .bubble-wrapper { max-width: calc(100% - 34px); }
  body.chat-app .msg-bubble.msg-user { padding: 8px 10px !important; border-radius: 12px 12px 3px 12px !important; }
  body.chat-app .prose { font-size: 13.5px !important; line-height: 1.68 !important; }
  body.chat-app .msg-actions { opacity: 1; }
  body.chat-app .chat-scroll-toggle { right: 14px; bottom: 76px; width: 34px; height: 34px; }

  body.chat-app .usage-popover {
    position: fixed;
    top: 58px;
    right: 10px;
    left: 10px;
    width: auto;
  }
}

@media (max-width: 390px) {
  body.chat-app #voice-btn { display: none; }
  body.chat-app #current-project-name { display: none; }
  body.chat-app #topbar > .flex:first-child { gap: 6px; }
  body.chat-app #current-chat-title { max-width: 42vw; }
  body.chat-app .user-menu-name { max-width: 54px; }
}

@media (hover: none) {
  body.chat-app .msg-actions { opacity: 1; }
  body.chat-app .project-row-action { opacity: 1; }
  body.chat-app .suggest-card:hover { transform: none; box-shadow: var(--shadow-sm); }
}

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

@media (prefers-contrast: more) {
  body.chat-app { --border: color-mix(in srgb, currentColor 28%, transparent); }
  body.chat-app button:focus-visible,
  body.chat-app input:focus-visible,
  body.chat-app textarea:focus-visible,
  body.chat-app select:focus-visible { outline-width: 3px; }
}
