:root {
  color-scheme: dark;
  --bg: oklch(0.18 0.04 265);
  --bg-strong: oklch(0.12 0.035 265);
  --surface: color-mix(in oklch, oklch(0.24 0.04 265) 82%, transparent);
  --surface-solid: oklch(0.22 0.04 265);
  --surface-2: oklch(0.27 0.045 270);
  --border: oklch(0.38 0.05 270 / 0.72);
  --text: oklch(0.94 0.015 265);
  --muted: oklch(0.73 0.035 270);
  --faint: oklch(0.6 0.035 270);
  --primary: oklch(0.55 0.22 280);
  --primary-glow: oklch(0.68 0.18 285);
  --accent: oklch(0.7 0.18 295);
  --success: oklch(0.7 0.16 150);
  --warning: oklch(0.76 0.16 75);
  --danger: oklch(0.64 0.21 25);
  --app-height: 100dvh;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --shadow: 0 22px 60px oklch(0.08 0.04 265 / 0.5);
  --glow: 0 0 30px oklch(0.62 0.22 285 / 0.35);
  /* Semantic tokens for components */
  --sidebar-bg: oklch(0.14 0.035 265 / 0.88);
  --surface-input: oklch(0.16 0.035 265 / 0.8);
  --surface-card: oklch(0.16 0.035 265 / 0.68);
  --surface-hover: oklch(0.23 0.045 270 / 0.8);
  --surface-bubble: oklch(0.22 0.04 265 / 0.92);
  --surface-code: oklch(0.12 0.035 265 / 0.8);
  --surface-code-block: oklch(0.1 0.025 265 / 0.58);
  --bg-glow: oklch(0.58 0.18 285 / 0.22);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  min-height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background-color: var(--bg-strong);
  background:
    radial-gradient(circle at 50% -18%, var(--bg-glow), transparent 38rem),
    linear-gradient(135deg, var(--bg-strong), var(--bg));
  color: var(--text);
  overflow: hidden;
  overscroll-behavior: none;
}

#app {
  height: var(--app-height);
  min-height: var(--app-height);
}

#app:not(.auth-app):not(:has(.auth-page)) {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
}

#app.auth-app,
#app:has(.auth-page) {
  height: 100dvh;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scrollbar-gutter: stable;
}

.app-frame {
  height: var(--app-height);
  min-height: var(--app-height);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  overflow: hidden;
}

.app-frame .app-shell {
  grid-row: 2;
  height: 100%;
  min-height: 0;
}

.app-frame .main,
.app-frame .sidebar {
  height: 100%;
}

.site-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 18px;
  border-bottom: 1px solid color-mix(in oklch, var(--primary-glow), var(--border) 42%);
  background: linear-gradient(135deg, oklch(0.26 0.09 280 / 0.96), oklch(0.2 0.08 300 / 0.96));
  color: var(--text);
  font-weight: 700;
  text-align: center;
  box-shadow: 0 10px 28px oklch(0.08 0.04 265 / 0.28);
}

.site-banner svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.site-banner-content {
  min-width: 0;
  overflow-wrap: anywhere;
}

.site-banner-content > * {
  margin-top: 0;
  margin-bottom: 0;
}

.site-banner-content a {
  color: inherit;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

button {
  cursor: pointer;
}

button:disabled,
input:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

a {
  color: inherit;
}

.app-loading {
  min-height: 100dvh;
  display: grid;
  place-items: center;
}

.boot-card,
.brand-row,
.auth-brand,
.user-chip,
.quota-pill,
.icon-row,
.message-head,
.composer-actions,
.preview-list,
.admin-tabs,
.table-actions,
.form-row,
.filter-row,
.settings-actions {
  display: flex;
  align-items: center;
}

.chat-actions,
.message-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.boot-card {
  gap: 14px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.boot-card span {
  display: block;
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: transparent;
  box-shadow: none;
  flex: none;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: inherit;
  object-fit: contain;
}

.auth-page {
  min-height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(360px, 480px);
  gap: clamp(24px, 5vw, 80px);
  align-items: center;
  padding: clamp(24px, 6vw, 88px);
  overflow: visible;
}

.mobile-login-link {
  display: none;
}

.auth-copy {
  max-width: 860px;
}

.auth-brand {
  gap: 12px;
  margin-bottom: 42px;
}

.auth-brand strong {
  font-size: 2.2rem;
  line-height: 1;
}

.legal-brand-link {
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.legal-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 18px;
}

.legal-links button {
  border: 0;
  padding: 0;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font: inherit;
}

.legal-links button:hover {
  color: var(--text);
}

.settings-legal {
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.settings-legal h3 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.settings-legal .legal-links {
  margin-top: 12px;
}

.settings-memory {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.settings-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.settings-section-head h3 {
  margin: 0;
  font-size: 0.92rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.settings-section-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.memory-list {
  display: grid;
  gap: 8px;
  max-height: min(380px, 44dvh);
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.memory-item,
.memory-empty {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.18 0.035 265 / 0.72);
}

.memory-item {
  padding: 9px 10px;
}

.memory-empty {
  padding: 11px 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.memory-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.memory-item-head strong {
  min-width: 0;
  color: var(--text);
  font-size: 0.94rem;
  overflow-wrap: anywhere;
}

.memory-value {
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  line-height: 1.38;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.memory-meta {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
}

.hero-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  width: fit-content;
  padding: 8px 13px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  background: oklch(0.22 0.04 265 / 0.7);
  backdrop-filter: blur(16px);
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--success);
  box-shadow: 0 0 18px var(--success);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.55;
    transform: scale(0.72);
  }
}

.auth-title {
  margin: 24px 0 18px;
  max-width: 880px;
  font-size: clamp(3rem, 7vw, 6.8rem);
  line-height: 0.95;
  letter-spacing: 0;
}

.gradient-text {
  background: linear-gradient(110deg, var(--primary-glow), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.auth-subtitle {
  margin: 0;
  max-width: 680px;
  color: var(--muted);
  font-size: 1.1rem;
  line-height: 1.7;
}

.feature-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 42px;
  max-width: 760px;
}

.feature-tile,
.auth-panel,
.settings-panel,
.admin-panel,
.empty-card,
.modal {
  border: 1px solid var(--border);
  background: var(--surface);
  backdrop-filter: blur(18px);
  box-shadow: var(--shadow);
}

.feature-tile {
  min-height: 112px;
  padding: 16px;
  border-radius: var(--radius-md);
}

.feature-tile svg {
  color: var(--primary-glow);
  width: 22px;
  height: 22px;
}

.feature-tile strong {
  display: block;
  margin: 14px 0 6px;
}

.feature-tile span {
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.auth-popular-tools {
  margin-top: 18px;
}

.auth-popular-tools.home-tools {
  width: min(100%, 760px);
  margin: 18px 0 0;
}

.auth-panel {
  padding: 24px;
  border-radius: var(--radius-lg);
  scroll-margin: 24px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.auth-panel.is-highlighted {
  border-color: color-mix(in oklch, var(--primary-glow), white 10%);
  box-shadow: var(--shadow), 0 0 0 3px oklch(0.7 0.18 295 / 0.18), 0 0 40px oklch(0.55 0.22 280 / 0.26);
  animation: auth-panel-highlight 1.15s ease;
}

@keyframes auth-panel-highlight {
  0% {
    transform: translateY(0);
  }
  35% {
    transform: translateY(-4px);
  }
  100% {
    transform: translateY(0);
  }
}

.auth-panel h2,
.settings-panel h2,
.admin-panel h2 {
  margin: 0 0 8px;
  font-size: 1.35rem;
}

.legal-panel {
  max-height: min(760px, calc(100dvh - 96px));
  overflow: auto;
}

.legal-view-head {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 18px;
}

.legal-article h1 {
  margin: 0 0 10px;
  font-size: clamp(2rem, 5vw, 4rem);
  line-height: 0.95;
}

.legal-article section {
  padding-top: 18px;
  border-top: 1px solid var(--border);
  margin-top: 18px;
}

.legal-article h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.legal-article p {
  margin: 0;
}

.auth-panel p,
.settings-panel p,
.admin-panel p {
  margin: 0 0 22px;
  color: var(--muted);
  line-height: 1.5;
}

.onboarding-submit {
  margin-top: 10px;
}

.field {
  display: grid;
  gap: 8px;
  margin-bottom: 16px;
}

.field label {
  color: var(--muted);
  font-size: 0.88rem;
}

.input,
.textarea,
.select {
  width: 100%;
  color: var(--text);
  background: var(--surface-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  padding: 12px 13px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
}

.textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.5;
}

.input:focus,
.textarea:focus,
.select:focus {
  border-color: var(--primary-glow);
  box-shadow: 0 0 0 3px oklch(0.55 0.22 280 / 0.18);
}

.compact-select {
  min-width: 140px;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.24 0.04 265 / 0.82);
  color: var(--text);
  transition: transform 0.16s ease, border-color 0.16s ease, background 0.16s ease, box-shadow 0.16s ease;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: color-mix(in oklch, var(--primary-glow), white 10%);
}

.btn-primary {
  border: 0;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  box-shadow: var(--glow);
}

.btn-danger {
  border-color: oklch(0.55 0.18 25 / 0.7);
  color: oklch(0.86 0.08 25);
}

.btn-icon {
  width: 40px;
  height: 40px;
  padding: 0;
  flex: none;
}

.btn-small {
  min-height: 34px;
  padding: 7px 10px;
  border-radius: 12px;
  font-size: 0.86rem;
}

.btn svg,
.btn-icon svg {
  width: 18px;
  height: 18px;
}

.btn-small svg {
  width: 15px;
  height: 15px;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.88rem;
}

.hidden {
  display: none !important;
}

.app-shell {
  height: var(--app-height);
  min-height: var(--app-height);
  display: grid;
  grid-template-columns: 304px minmax(0, 1fr);
  background: linear-gradient(145deg, oklch(0.11 0.035 265 / 0.62), transparent);
  overflow: hidden;
}

.sidebar-backdrop {
  display: none;
}

.sidebar {
  height: var(--app-height);
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--sidebar-bg);
  backdrop-filter: blur(18px);
  overflow: hidden;
}

.sidebar-head {
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-close {
  display: none;
}

.brand-row {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

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

.brand-home-link {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.brand-home-link:hover strong {
  color: var(--primary-glow);
}

.brand-lockup strong {
  display: block;
}

.brand-lockup span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.sidebar-actions {
  display: grid;
  gap: 10px;
}

.quota-pill {
  justify-content: space-between;
  gap: 12px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.19 0.04 265 / 0.8);
  color: var(--muted);
  font-size: 0.86rem;
}

.quota-pill strong {
  color: var(--text);
}

.sidebar-nav {
  padding: 10px 10px 6px;
  border-bottom: 1px solid var(--border);
}

.sidebar-nav .conversation-item strong {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  line-height: 1.2;
}

.sidebar-nav .conversation-item strong svg,
.sidebar-nav .conversation-item strong i {
  width: 16px;
  height: 16px;
  flex: none;
}

.sidebar-history {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-history-section {
  display: flex;
  flex-direction: column;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
  flex: 0 0 auto;
}

.sidebar-history-section:last-child {
  border-bottom: 0;
}

.sidebar-history-section.open {
  flex: 1 1 0;
  min-height: 0;
}

.sidebar-section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 9px 18px 6px;
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  background: none;
  border: none;
  cursor: pointer;
  flex: none;
  text-align: left;
}

.sidebar-section-toggle svg {
  width: 13px;
  height: 13px;
  color: var(--text-muted);
  transition: transform 0.28s ease;
  flex: none;
}

.sidebar-history-section.open .sidebar-section-toggle svg {
  transform: rotate(90deg);
}

.sidebar-section-body {
  display: none;
  flex: 1;
  min-height: 0;
  flex-direction: column;
}

.sidebar-history-section.open .sidebar-section-body {
  display: flex;
}

.conversation-list {
  min-height: 0;
  flex: 1;
  overflow: auto;
  padding: 0 10px 10px;
}

.sidebar-history-sentinel {
  height: 1px;
  flex: none;
}

.date-group {
  margin: 12px 0 6px;
  padding: 0 8px;
  color: var(--faint);
  font-size: 0.73rem;
  text-transform: uppercase;
}

.conversation-item {
  width: 100%;
  display: grid;
  gap: 4px;
  margin: 3px 0;
  padding: 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  text-align: left;
}

.conversation-item.active,
.conversation-item:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--border);
}

.conversation-item strong,
.conversation-item span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-item span {
  color: var(--faint);
  font-size: 0.8rem;
}

.history-title-line {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
}

.history-title-text {
  min-width: 0;
  flex: 1;
  color: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.history-preview-image-icon {
  width: 0.8rem;
  height: 0.8rem;
  vertical-align: middle;
  flex: none;
}

.history-favorite-star {
  width: 13px;
  height: 13px;
  flex: none;
  color: var(--warning);
  fill: currentColor;
}

.history-personality {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.2;
}

.history-personality svg {
  width: 12px;
  height: 12px;
  flex: none;
}

.history-personality span {
  min-width: 0;
  color: inherit;
  font-size: inherit;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.user-chip {
  gap: 10px;
  width: 100%;
  min-width: 0;
}

.user-profile-link {
  min-width: 0;
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.user-profile-link:hover,
.user-profile-link:focus-visible {
  border-color: var(--border);
  background: oklch(0.23 0.045 270 / 0.72);
}

.avatar,
.avatar-sm {
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--surface-2), var(--primary));
  color: var(--text);
}

.avatar {
  width: 38px;
  height: 38px;
}

.avatar-sm {
  width: 28px;
  height: 28px;
}

.avatar img,
.avatar-sm img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rawchat-avatar img {
  object-fit: contain;
}

.rawchat-avatar {
  background: transparent;
  border-radius: 0;
}

.rawchat-avatar img {
  border-radius: 0;
}

.user-meta {
  min-width: 0;
  flex: 1;
}

.user-meta strong,
.user-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-meta span {
  color: var(--muted);
  font-size: 0.78rem;
}

.main {
  min-width: 0;
  min-height: 0;
  height: var(--app-height);
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

#main-view {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

.mobile-topbar {
  display: none;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  background: oklch(0.13 0.035 265 / 0.9);
}

.chat-view {
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.chat-header {
  position: relative;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: space-between;
  padding: 10px clamp(14px, 3vw, 28px);
  border-bottom: 1px solid var(--border);
  background: oklch(0.15 0.035 265 / 0.72);
  backdrop-filter: blur(16px);
}

.chat-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.chat-title-block {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: 4px;
}

.conversation-personality-pill,
.badge-link {
  width: fit-content;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-card);
  color: var(--muted);
  padding: 3px 8px;
  font-size: 0.78rem;
  line-height: 1.2;
}

.conversation-personality-pill img {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
}

.conversation-personality-pill svg,
.badge-link svg {
  width: 14px;
  height: 14px;
}

.conversation-personality-pill:hover,
.badge-link:hover {
  color: var(--text);
  border-color: var(--accent);
}

.chat-actions-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-action-menu {
  position: relative;
  z-index: 35;
  display: none;
}

.chat-action-menu[open] {
  z-index: 80;
}

.chat-action-menu summary {
  list-style: none;
}

.chat-action-menu summary::-webkit-details-marker {
  display: none;
}

.chat-action-menu-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 90;
  min-width: 190px;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  box-shadow: var(--shadow);
}

.chat-menu-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 9px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  text-align: left;
}

.chat-menu-item:hover,
.chat-menu-item.active {
  background: oklch(0.23 0.045 270 / 0.82);
}

.chat-menu-item.danger {
  color: color-mix(in oklch, var(--danger), white 16%);
}

.chat-menu-item svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.title-edit {
  width: min(600px, 62vw);
  color: var(--text);
  border: 1px solid transparent;
  background: transparent;
  outline: 0;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-size: 1rem;
  font-weight: 700;
}

.title-edit:focus {
  border-color: var(--border);
  background: var(--surface-input);
}

.message-scroller {
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(16px, 3vw, 28px);
  scrollbar-gutter: stable;
}

.message-stack {
  min-width: 0;
  width: min(100%, 980px);
  margin: 0 auto;
  display: grid;
  gap: 18px;
}

.message {
  min-width: 0;
  max-width: 100%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.message.user {
  flex-direction: row-reverse;
}

.bubble {
  min-width: 0;
  max-width: min(760px, 82%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 13px 15px;
  background: var(--surface-bubble);
  box-shadow: 0 14px 28px oklch(0.08 0.04 265 / 0.22);
  overflow-wrap: anywhere;
}

.message.user .bubble {
  background: linear-gradient(135deg, oklch(0.43 0.2 280), oklch(0.5 0.17 292));
  border-color: oklch(0.62 0.18 285 / 0.7);
}

.message.error .bubble,
.message.blocked .bubble {
  border-color: oklch(0.58 0.18 25 / 0.8);
}

.message-head {
  gap: 8px;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 0.78rem;
}

.msg-copy-btn {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 4px;
  color: var(--faint);
  opacity: 0.35;
  transition: opacity 0.15s, color 0.15s;
  display: flex;
  align-items: center;
}

.msg-copy-btn svg {
  width: 12px;
  height: 12px;
}

.msg-copy-btn:hover,
.msg-copy-btn:focus-visible {
  opacity: 1;
  color: var(--muted);
}

.message.user .msg-copy-btn {
  color: oklch(1 0 0 / 0.6);
}

.message.user .msg-copy-btn:hover {
  color: oklch(1 0 0 / 1);
}

.message-tools {
  margin-left: auto;
}

.message-tools .mini-btn {
  width: 28px;
  height: 28px;
  min-height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
}

.message-tools svg {
  width: 14px;
  height: 14px;
}

.flag-badge,
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 24px;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

.status-active {
  color: var(--success);
}

.status-suspended {
  color: var(--warning);
}

.status-banned,
.status-error {
  color: var(--danger);
}

.markdown {
  min-width: 0;
  max-width: 100%;
  line-height: 1.65;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown > :last-child {
  margin-bottom: 0;
}

.markdown h1,
.markdown h2,
.markdown h3 {
  line-height: 1.2;
  margin: 1.2em 0 0.55em;
}

.markdown p,
.markdown ul,
.markdown ol,
.markdown table,
.markdown pre,
.markdown blockquote {
  margin: 0.75em 0;
}

.markdown table {
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--radius-sm);
}

.markdown th,
.markdown td {
  border: 1px solid var(--border);
  padding: 8px 10px;
}

.markdown th {
  background: oklch(0.18 0.04 265);
}

.markdown img {
  display: block;
  width: auto;
  max-width: min(100%, 520px);
  max-height: min(560px, 58dvh);
  object-fit: contain;
  margin: 0.75em 0;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: oklch(0.1 0.025 265 / 0.5);
}

.markdown-image {
  cursor: zoom-in;
  transition: border-color 0.18s ease, transform 0.18s ease;
}

.markdown-image:hover,
.markdown-image:focus-visible {
  border-color: var(--primary-glow);
  transform: translateY(-1px);
}

.markdown-image:focus-visible {
  outline: 2px solid var(--primary-glow);
  outline-offset: 3px;
}

.markdown code:not(pre code) {
  padding: 2px 5px;
  border-radius: 6px;
  background: var(--surface-code);
}

.code-wrap {
  position: relative;
  z-index: 0;
  min-width: 0;
  max-width: 100%;
  margin: 0.75em 0;
  overflow: visible;
}

.code-scroll {
  min-width: 0;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.markdown pre {
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

.code-wrap pre {
  min-width: 100%;
  width: max-content;
  margin: 0;
  overflow: visible;
}

.code-wrap--svg {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.1 0.025 265 / 0.58);
  overflow: hidden;
}

.code-wrap--svg .code-scroll {
  border-top: 1px solid var(--border);
}

.code-wrap--svg .code-scroll[hidden] {
  display: none;
}

.svg-code-preview {
  min-height: 180px;
  max-height: min(420px, 52dvh);
  margin: 0;
  padding: 54px 14px 14px;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, oklch(0.16 0.025 265 / 0.78) 25%, transparent 25%),
    linear-gradient(-45deg, oklch(0.16 0.025 265 / 0.78) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, oklch(0.16 0.025 265 / 0.78) 75%),
    linear-gradient(-45deg, transparent 75%, oklch(0.16 0.025 265 / 0.78) 75%);
  background-color: oklch(0.12 0.025 265 / 0.9);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.svg-code-preview img {
  display: block;
  max-width: 100%;
  max-height: calc(min(420px, 52dvh) - 56px);
  object-fit: contain;
}

.svg-code-toggle {
  position: absolute;
  top: 10px;
  left: 12px;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 30px;
  padding: 5px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: oklch(0.18 0.035 265 / 0.9);
  color: var(--text);
  font-size: 0.82rem;
  line-height: 1;
}

.svg-code-toggle:hover {
  border-color: color-mix(in oklch, var(--primary), var(--border) 45%);
  color: white;
}

.markdown pre code {
  white-space: pre;
  overflow-wrap: normal;
  word-break: normal;
}

.code-copy {
  position: absolute;
  top: 10px;
  right: 12px;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  width: max-content;
  height: 30px;
  min-height: 30px;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: oklch(0.18 0.035 265 / 0.9);
  color: var(--muted);
}

.typing-cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  border-radius: 2px;
  background: var(--primary-glow);
  vertical-align: text-bottom;
  animation: blink 0.9s steps(2, start) infinite;
}

.stream-waiting {
  display: inline-block;
  color: var(--muted);
  animation: waitingFade 1.45s ease-in-out infinite;
}

.upload-bubble {
  border-color: color-mix(in oklch, var(--primary-glow), var(--border) 42%);
}

.upload-indicator {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  animation: waitingFade 1.28s ease-in-out infinite;
}

.upload-spinner {
  width: 19px;
  height: 19px;
  flex: none;
  border: 2px solid oklch(0.55 0.22 280 / 0.22);
  border-top-color: var(--primary-glow);
  border-radius: 999px;
  animation: uploadSpin 0.8s linear infinite;
}

@keyframes blink {
  to {
    visibility: hidden;
  }
}

@keyframes waitingFade {
  0%,
  100% {
    opacity: 0.45;
  }
  50% {
    opacity: 1;
  }
}

@keyframes uploadSpin {
  to {
    transform: rotate(360deg);
  }
}

.attachment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 180px));
  gap: 10px;
  margin-bottom: 10px;
}

.attachment-thumb,
.attachment-grid img,
.preview-thumb img {
  width: 100%;
  height: 112px;
}

.attachment-thumb {
  display: block;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.attachment-thumb:focus-visible {
  outline: 2px solid var(--primary-glow);
  outline-offset: 3px;
}

.attachment-grid img,
.preview-thumb img {
  width: 100%;
  height: 112px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.attachment-thumb:hover img {
  transform: scale(1.025);
  border-color: var(--primary-glow);
}

.image-lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 44px);
}

.image-lightbox__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: oklch(0.06 0.03 265 / 0.86);
  backdrop-filter: blur(14px);
}

.image-lightbox__figure {
  position: relative;
  z-index: 1;
  margin: 0;
  max-width: min(100%, 1180px);
  max-height: 90dvh;
  display: grid;
  gap: 10px;
}

.image-lightbox__figure img {
  max-width: 100%;
  max-height: calc(90dvh - 34px);
  object-fit: contain;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.image-lightbox__figure figcaption {
  color: var(--muted);
  text-align: center;
  font-size: 0.9rem;
}

.image-lightbox__actions {
  position: fixed;
  z-index: 2;
  top: 18px;
  right: 18px;
  display: inline-flex;
  gap: 8px;
}

.json-modal {
  position: fixed;
  inset: 0;
  z-index: 110;
  display: grid;
  place-items: center;
  padding: clamp(16px, 4vw, 44px);
}

.json-modal__backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: oklch(0.06 0.03 265 / 0.82);
  backdrop-filter: blur(14px);
}

.json-modal__panel {
  position: relative;
  z-index: 1;
  width: min(920px, 100%);
  max-height: 86dvh;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.json-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.json-modal__header h3 {
  margin: 0;
}

.json-modal__header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.json-modal__body {
  margin: 0;
  padding: 16px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  background: oklch(0.1 0.025 265 / 0.78);
  font-size: 0.86rem;
  line-height: 1.55;
}

.json-modal__panel--details {
  width: min(760px, 100%);
}

.admin-user-detail-modal {
  width: min(860px, 100%);
}

.admin-user-detail {
  display: grid;
  gap: 14px;
  padding: 14px;
  overflow: auto;
}

.admin-user-detail-section {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid color-mix(in oklch, var(--border), transparent 24%);
  border-radius: var(--radius-sm);
  background: oklch(0.11 0.03 265 / 0.58);
}

.admin-user-detail-section h4,
.admin-user-section-head h4 {
  margin: 0;
}

.admin-user-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.admin-memory-form {
  display: grid;
  grid-template-columns: minmax(140px, 0.8fr) minmax(220px, 1.6fr) auto;
  gap: 8px;
  align-items: center;
}

.admin-memory-list {
  display: grid;
  gap: 9px;
  max-height: min(420px, 44dvh);
  overflow-y: auto;
  padding-right: 4px;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
}

.admin-memory-item {
  display: grid;
  gap: 8px;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-card);
}

.admin-memory-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.admin-log-details {
  padding: 16px;
  overflow: auto;
  background: oklch(0.1 0.025 265 / 0.42);
}

.admin-log-detail-grid {
  display: grid;
  gap: 9px;
}

.admin-log-detail-row {
  display: grid;
  grid-template-columns: minmax(108px, 0.28fr) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: oklch(0.16 0.035 265 / 0.72);
}

.admin-log-detail-row span {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.admin-log-detail-row strong,
.admin-log-detail-row code {
  min-width: 0;
  overflow-wrap: anywhere;
}

.admin-log-detail-row strong {
  font-weight: 650;
}

.admin-log-detail-row code {
  display: block;
  color: var(--text);
  white-space: pre-wrap;
}

.admin-log-metadata {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: oklch(0.14 0.03 265 / 0.72);
}

.admin-log-metadata h4 {
  margin: 0 0 10px;
}

.admin-log-metadata-body {
  max-height: 320px;
  border-radius: 8px;
}

.empty-state {
  min-height: 100%;
  display: grid;
  align-content: center;
  gap: 12px;
}

.empty-copy {
  text-align: center;
  margin: 0 auto;
  max-width: 680px;
}

.empty-copy h1 {
  margin: 0 0 6px;
  font-size: clamp(1.55rem, 3.5vw, 2.8rem);
  line-height: 1;
  letter-spacing: 0;
}

.empty-copy p {
  margin: 0;
  color: var(--muted);
}

.prompt-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  width: min(100%, 760px);
  margin: 0 auto;
}

.empty-card {
  min-height: 74px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  grid-template-areas:
    "icon title"
    ". text";
  column-gap: 10px;
  row-gap: 3px;
  align-items: start;
  padding: 10px;
  border-radius: var(--radius-md);
  text-align: left;
  color: var(--text);
}

.empty-card svg {
  grid-area: icon;
  width: 16px;
  height: 16px;
  margin-top: 1px;
}

.empty-card strong {
  grid-area: title;
  min-width: 0;
  line-height: 1.2;
}

.empty-card span {
  grid-area: text;
  display: block;
  margin-top: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.3;
}

.home-tools {
  width: min(100%, 760px);
  display: grid;
  gap: 7px;
  margin: 0 auto;
}

.home-tools-title {
  width: max-content;
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  text-align: left;
  text-transform: uppercase;
  cursor: pointer;
}

.home-tools-title:hover {
  color: var(--primary-glow);
}

.home-tools-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.home-tool-card {
  min-width: 0;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  color: var(--text);
  text-align: left;
}

.home-tool-card:hover {
  border-color: color-mix(in oklch, var(--primary-glow), var(--border) 32%);
  background: oklch(0.22 0.055 275 / 0.78);
}

.home-tool-card strong {
  display: -webkit-box;
  overflow: hidden;
  white-space: normal;
  line-height: 1.18;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.home-tool-card span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.home-tool-logo {
  width: 38px;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface-2), oklch(0.34 0.12 285));
}

.home-tool-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.composer-shell {
  position: relative;
  z-index: 5;
  padding: 12px clamp(14px, 3vw, 28px) 18px;
  background: linear-gradient(180deg, transparent, oklch(0.12 0.035 265 / 0.94) 35%);
}

.composer {
  width: min(100%, 980px);
  margin: 0 auto;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: oklch(0.16 0.035 265 / 0.94);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.admin-readonly-note {
  width: min(100%, 980px);
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 15px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
  color: var(--muted);
}

.admin-readonly-note svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--primary-glow);
}

.preview-list {
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px 0;
}

.preview-list:empty {
  display: none;
  padding: 0;
}

.preview-thumb {
  position: relative;
  width: 122px;
}

.preview-thumb button {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 28px;
  height: 28px;
}

.composer-input-row {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: center;
  padding: 8px;
}

.composer-textarea {
  width: 100%;
  max-height: 220px;
  min-height: 42px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 10px 4px;
  background: transparent;
  color: var(--text);
  line-height: 1.5;
}

.composer-inline-btn {
  width: 40px;
  height: 40px;
  align-self: center;
  border-radius: 14px;
}

.drop-active .composer {
  border-color: var(--primary-glow);
  box-shadow: var(--glow);
}

.settings-layout,
.admin-layout,
.tools-layout,
.favorites-view,
.blocked-screen {
  height: 100%;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: clamp(18px, 4vw, 34px);
  scrollbar-gutter: stable;
}

.settings-panel,
.admin-panel,
.tools-panel {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 22px;
  border-radius: var(--radius-lg);
}

.tools-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 18px;
}

.tools-head h2,
.tools-head h3 {
  margin: 0 0 6px;
}

.tools-title-link {
  display: inline;
  margin: 0 0 6px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0;
  cursor: pointer;
}

.tools-title-link:hover,
.tools-title-link:focus-visible {
  color: var(--accent);
}

.tools-head p {
  margin: 0;
  color: var(--muted);
}

.tool-filter-bar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(150px, 220px) minmax(150px, 220px) minmax(220px, auto);
  gap: 10px;
  align-items: center;
  margin: 4px 0 18px;
}

.tool-filter-bar > .segmented-control {
  grid-column: 1 / -1;
  justify-content: flex-start;
}

.tool-filter-toggle {
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.12 0.028 265 / 0.58);
}

.segmented-control {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

.favorites-filter {
  justify-content: flex-start;
  margin: 0 0 16px;
}

.tool-section-title {
  margin: 22px 0 12px;
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.tool-runs-scope-tabs {
  display: flex;
  gap: 6px;
  margin: 22px 0 12px;
}

.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.tool-card,
.tool-run-item,
.tool-output,
.tool-builder-section,
.tool-inputs-spoiler {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
}

.tool-card {
  width: 100%;
  min-height: 220px;
  display: grid;
  gap: 9px;
  align-content: start;
  padding: 14px;
  color: var(--text);
  text-align: left;
}

.tool-card.is-deleted,
.tool-detail.is-deleted .tool-detail-hero {
  border-color: color-mix(in oklch, var(--danger), var(--border) 55%);
}

.tool-card.is-deleted {
  opacity: 0.82;
}

.tool-card span,
.tool-run-item span {
  color: var(--muted);
  line-height: 1.45;
}

.tool-name-line {
  min-width: 0;
  max-width: 100%;
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  overflow-wrap: anywhere;
}

.favorites-grid {
  display: grid;
  gap: 10px;
}

.favorite-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: stretch;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
}

.favorite-card-main {
  min-width: 0;
  display: grid;
  gap: 7px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.favorite-card-main small {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--primary-glow);
  font-size: 0.76rem;
  text-transform: uppercase;
}

.favorite-card-main small svg {
  width: 14px;
  height: 14px;
}

.favorite-card-main strong,
.favorite-card-main span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.favorite-card-main span {
  color: var(--muted);
  font-size: 0.9rem;
}

.favorite-card-star {
  align-self: center;
}

.tool-quality-mark {
  display: inline-grid;
  place-items: center;
  flex: none;
  color: color-mix(in oklch, var(--warning), white 16%);
  filter: drop-shadow(0 0 8px oklch(0.78 0.15 82 / 0.32));
}

.tool-card .tool-quality-mark,
.tool-run-item .tool-quality-mark,
.tool-detail .tool-quality-mark,
.tool-result-title .tool-quality-mark {
  color: color-mix(in oklch, var(--warning), white 16%);
}

.tool-quality-mark svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 3;
}

h3 .tool-quality-mark svg {
  width: 18px;
  height: 18px;
}

.tool-card-image {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface-2), oklch(0.34 0.12 285));
}

.tool-card-image.large {
  width: min(220px, 100%);
}

.tool-card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tool-result-title {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.tool-result-title:hover h3 {
  color: var(--primary-glow);
}

.tool-result .tools-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  justify-items: start;
  gap: 10px;
  margin-bottom: 14px;
}

.tool-result-logo {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  flex: none;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--surface-2), oklch(0.34 0.12 285));
}

.tool-result-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tool-result-logo svg {
  width: 22px;
  height: 22px;
}

.tag-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.tag-row em {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-style: normal;
  font-size: 0.78rem;
}

.tag-editor {
  min-height: 46px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-input);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.tag-editor:focus-within {
  border-color: var(--primary-glow);
  box-shadow: 0 0 0 3px oklch(0.55 0.22 280 / 0.18);
}

.tag-editor-chips {
  display: contents;
}

.tag-editor-input {
  min-width: 110px;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  padding: 6px;
}

.tag-chip {
  max-width: 100%;
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 8px 5px 10px;
  border: 1px solid oklch(0.48 0.12 282 / 0.65);
  border-radius: 999px;
  background: oklch(0.32 0.1 282 / 0.72);
  color: var(--text);
}

.tag-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag-chip svg {
  width: 14px;
  height: 14px;
  flex: none;
}

.tool-card-meta {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.tool-card-shell {
  position: relative;
  min-width: 0;
}

.tool-card-shell .tool-card {
  height: 100%;
}

.tool-card-favorite {
  position: absolute;
  top: 9px;
  right: 9px;
  z-index: 2;
}

.detail-meta {
  margin: 10px 0 12px;
}

.tool-run-badges {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.tool-card-meta small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: oklch(0.24 0.05 270 / 0.75);
  color: var(--muted);
  font-size: 0.72rem;
}

.tool-card-meta small svg {
  width: 12px;
  height: 12px;
}

.tool-card-meta small.tool-quality-label {
  border: 1px solid oklch(0.74 0.15 82 / 0.42);
  background: oklch(0.25 0.08 82 / 0.46);
  color: color-mix(in oklch, var(--warning), white 12%);
}

.tool-card-meta small.tool-quality-label svg {
  stroke: currentColor;
  stroke-width: 3;
}

.tool-card-meta small.deleted-badge {
  border: 1px solid color-mix(in oklch, var(--danger), transparent 42%);
  background: color-mix(in oklch, var(--danger), transparent 82%);
  color: color-mix(in oklch, var(--danger), white 22%);
}

.favorite-btn.active {
  border-color: oklch(0.74 0.15 82 / 0.55);
  color: color-mix(in oklch, var(--warning), white 8%);
  background: oklch(0.25 0.08 82 / 0.46);
}

.favorite-btn.active svg {
  fill: currentColor;
}

.tool-origin-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border: 1px solid oklch(0.54 0.13 282 / 0.45);
  border-radius: 999px;
  background: oklch(0.23 0.07 282 / 0.48);
  color: var(--primary-glow);
  font-size: 0.72rem;
}

.tool-origin-badge svg {
  width: 12px;
  height: 12px;
}

.tool-run-badges small {
  padding: 3px 7px;
  border: 1px solid oklch(0.72 0.16 75 / 0.38);
  border-radius: 999px;
  background: oklch(0.23 0.08 75 / 0.38);
  color: color-mix(in oklch, var(--warning), white 8%);
  font-size: 0.72rem;
}

.tool-run-item.is-deleted {
  border-color: color-mix(in oklch, var(--danger), var(--border) 55%);
  opacity: 0.82;
}

.tool-run-item.is-deleted .tool-run-badges small {
  border-color: color-mix(in oklch, var(--danger), transparent 42%);
  background: color-mix(in oklch, var(--danger), transparent 82%);
  color: color-mix(in oklch, var(--danger), white 22%);
}

.tool-run-list {
  display: grid;
  gap: 8px;
}

.tool-run-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px;
  color: var(--text);
  text-align: left;
}

.tool-run-item > div {
  min-width: 0;
  display: grid;
  gap: 7px;
}

.tool-run-primary {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tool-run-primary-image {
  width: 54px;
  height: 42px;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.tool-run-primary-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tool-run-primary-image.output {
  width: auto;
  height: auto;
  max-width: 72px;
  max-height: 56px;
  overflow: visible;
  border: 0;
  background: transparent;
}

.tool-run-primary-image.output img {
  width: auto;
  height: auto;
  max-width: 72px;
  max-height: 56px;
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.tool-run-primary-text {
  max-width: min(100%, 360px);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
}

.tool-run-primary-text b {
  color: var(--text);
  font-weight: 600;
}

.tool-run-primary-text.output {
  border-color: oklch(0.56 0.16 285 / 0.72);
  background: oklch(0.28 0.095 285 / 0.62);
}

.tool-run-primary-text.output small {
  color: var(--muted);
  font-size: 0.72rem;
}

.tool-run-primary-text.output b {
  color: var(--text);
}


.tool-detail-hero {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  margin-bottom: 20px;
}

.tool-detail-hero > :nth-child(2) {
  min-width: 0;
}

.tool-detail-hero h3,
.tool-result h3 {
  margin: 0 0 8px;
  overflow-wrap: anywhere;
}

.tool-detail-hero p {
  margin: 0 0 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.tool-detail-hero .table-actions {
  grid-column: 1 / -1;
  justify-content: flex-start;
  align-self: start;
  margin-top: -4px;
}

.tool-actions {
  gap: 6px;
}

.tool-actions .btn {
  min-height: 32px;
  padding: 6px 9px;
  border-radius: 9px;
  font-size: 0.82rem;
}

.tool-actions .btn svg {
  width: 15px;
  height: 15px;
}

.tool-actions .btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
}

.personality-use-row {
  margin: 4px 0 22px;
}

.personality-use-main {
  width: 100%;
  min-height: 54px;
  justify-content: center;
  font-size: 1.06rem;
  font-weight: 800;
}

.personality-conversation-list {
  display: grid;
  gap: 8px;
}

.personality-conversation-item strong,
.personality-conversation-item span {
  overflow-wrap: anywhere;
}

.personality-conversation-date {
  flex-shrink: 0;
  align-self: flex-start;
  white-space: nowrap;
  color: var(--muted);
  font-size: 0.8rem;
}

.tool-validation-note {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 16px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.18 0.05 270 / 0.78);
  color: var(--muted);
  line-height: 1.45;
}

.tool-validation-note.ready {
  border-color: oklch(0.62 0.14 150 / 0.55);
  color: color-mix(in oklch, var(--success), white 8%);
}

.tool-validation-note svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.tool-run-form,
.tool-builder {
  display: grid;
  gap: 14px;
}

.tool-use-card {
  display: grid;
  gap: 14px;
  margin: 0 0 18px;
  padding: 20px 18px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: oklch(0.16 0.035 265 / 0.74);
  box-shadow: inset 0 1px 0 oklch(1 0 0 / 0.03);
}

.tool-use-card legend {
  padding: 0 8px;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 800;
  text-transform: uppercase;
}

.tool-use-card > .btn {
  width: fit-content;
}

.tool-run-fields-shell {
  display: grid;
  grid-template-rows: 1fr;
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition:
    grid-template-rows 0.36s ease,
    opacity 0.22s ease,
    transform 0.36s ease;
}

.tool-run-fields {
  min-height: 0;
  overflow: hidden;
  display: grid;
  gap: 14px;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.22s ease,
    transform 0.28s ease;
}

.tool-image-picker {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.13 0.03 265 / 0.58);
}

.tool-image-picker > span {
  color: var(--muted);
  font-size: 0.9rem;
}

.tool-image-add {
  width: fit-content;
}

.tool-image-preview-list {
  padding: 0;
}

.tool-run-form.is-processing .tool-run-fields-shell {
  grid-template-rows: 0fr;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.tool-run-form.is-processing .tool-run-fields {
  opacity: 0;
  transform: translateY(-8px);
}

.tool-run-form.is-processing .tool-use-card {
  display: none;
}

.ai-form-controls-shell,
.manual-form-controls-shell {
  display: grid;
  grid-template-rows: 1fr;
  overflow: hidden;
  opacity: 1;
  transform: translateY(0);
  transition:
    grid-template-rows 0.36s ease,
    opacity 0.22s ease,
    transform 0.36s ease;
}

.ai-form-controls,
.manual-form-controls {
  min-height: 0;
  overflow: hidden;
  display: grid;
  gap: 14px;
  opacity: 1;
  transform: translateY(0);
  transition:
    opacity 0.22s ease,
    transform 0.28s ease;
}

.tool-builder.is-processing .ai-form-controls-shell,
.tool-builder.is-processing .manual-form-controls-shell {
  grid-template-rows: 0fr;
  opacity: 0;
  transform: translateY(-10px);
  pointer-events: none;
}

.tool-builder.is-processing .ai-form-controls,
.tool-builder.is-processing .manual-form-controls {
  opacity: 0;
  transform: translateY(-8px);
}

.tool-processing {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 14px;
  align-items: center;
  margin: 14px 0 18px;
  padding: 16px;
  border: 1px solid color-mix(in oklch, var(--primary-glow), var(--border) 58%);
  border-radius: var(--radius-md);
  background:
    linear-gradient(90deg, transparent, oklch(0.68 0.18 285 / 0.08), transparent),
    oklch(0.16 0.04 265 / 0.82);
  box-shadow: 0 0 28px oklch(0.55 0.22 280 / 0.14);
}

.tool-processing::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 0%, oklch(0.8 0.18 295 / 0.12) 42%, transparent 72%);
  transform: translateX(-100%);
  animation: toolSweep 1.8s ease-in-out infinite;
}

.tool-processing > * {
  position: relative;
  z-index: 1;
}

.tool-processing-orb {
  position: relative;
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: radial-gradient(circle, oklch(0.48 0.18 285), oklch(0.22 0.08 270));
  box-shadow: 0 0 28px oklch(0.62 0.22 285 / 0.42);
}

.tool-processing-orb span {
  position: absolute;
  inset: -5px;
  border: 1px solid oklch(0.72 0.2 295 / 0.38);
  border-top-color: var(--accent);
  border-radius: 999px;
  animation: spin 1.05s linear infinite;
}

.tool-processing-orb svg {
  width: 22px;
  height: 22px;
}

.tool-processing strong {
  display: block;
  margin-bottom: 5px;
}

.tool-processing p {
  margin: 0 0 10px;
  color: var(--muted);
}

.tool-processing-name {
  display: inline-flex;
  max-width: min(100%, 260px);
  align-items: center;
  vertical-align: baseline;
  margin: 0 4px;
  padding: 2px 8px;
  border: 1px solid color-mix(in oklch, var(--primary-glow), var(--border) 45%);
  border-radius: 999px;
  background: oklch(0.24 0.09 280 / 0.72);
  color: var(--text);
  font-size: 0.9em;
  font-weight: 750;
  overflow-wrap: anywhere;
}

.tool-processing-steps {
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
}

.tool-processing-steps span {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  animation: waitingFade 1.4s ease-in-out infinite;
}

.tool-processing-steps span:nth-child(2) {
  animation-delay: 0.18s;
}

.tool-processing-steps span:nth-child(3) {
  animation-delay: 0.36s;
}

.lucide-loader {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes toolSweep {
  0% {
    transform: translateX(-100%);
  }
  55%,
  100% {
    transform: translateX(100%);
  }
}

.builder-helper-row {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.tool-create-choice {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.tool-mode-card {
  min-height: 210px;
  display: grid;
  gap: 12px;
  align-content: start;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, oklch(0.18 0.045 265 / 0.86), oklch(0.14 0.035 265 / 0.76));
  color: var(--text);
  text-align: left;
  transition:
    border-color 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

.tool-mode-card:hover,
.tool-mode-card:focus-visible {
  transform: translateY(-2px);
  border-color: color-mix(in oklch, var(--primary-glow), var(--border) 42%);
  box-shadow: var(--glow);
}

.tool-mode-card svg {
  width: 32px;
  height: 32px;
  color: var(--accent);
}

.tool-mode-card strong {
  font-size: 1.1rem;
}

.tool-mode-card span {
  max-width: 42rem;
  color: var(--muted);
  line-height: 1.55;
}

.tool-copy-list {
  display: grid;
  gap: 12px;
}

.tool-copy-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: color-mix(in oklch, var(--panel), transparent 22%);
}

.tool-copy-item .tool-card-image {
  width: 58px;
  height: 58px;
}

.tool-copy-item p {
  margin: 4px 0 8px;
  color: var(--muted);
}

.assisted-tool-form .textarea[name="instruction"] {
  min-height: 180px;
}

.textarea[name="prompt"],
.textarea[name="default_system_prompt"] {
  height: 350px;
}

.ai-edit-form .btn-primary {
  margin-top: 12px;
}

.edit-actions-row {
  margin-bottom: 14px;
}

.ai-edit-form + .tool-builder {
  margin-top: 18px;
}

.tool-guide {
  display: grid;
  gap: 18px;
}

.tool-guide-hero {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, oklch(0.2 0.055 270 / 0.88), oklch(0.15 0.04 265 / 0.72));
}

.tool-guide-hero span {
  color: var(--accent);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.tool-guide-hero h3 {
  margin: 6px 0 8px;
  font-size: clamp(1.5rem, 3vw, 2.25rem);
}

.tool-guide-hero p {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.tool-guide-diagram {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: oklch(0.14 0.035 265 / 0.72);
}

.tool-guide-diagram h4 {
  margin: 0 0 12px;
  font-size: 1.08rem;
}

.tool-guide-diagram img {
  display: block;
  width: 100%;
  max-height: 520px;
  object-fit: contain;
  border-radius: var(--radius-sm);
}

.tool-guide-diagram figcaption {
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.45;
}

.guide-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
}

.guide-section {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
}

.guide-section h4 {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 0 0 10px;
}

.guide-section h4 svg {
  width: 18px;
  height: 18px;
  color: var(--accent);
}

.guide-section p,
.guide-section li {
  color: var(--muted);
  line-height: 1.55;
}

.guide-section p {
  margin: 0 0 10px;
}

.guide-section ul {
  margin: 0;
  padding-left: 18px;
}

.guide-section pre {
  overflow: auto;
  margin: 12px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: oklch(0.11 0.03 265 / 0.92);
}

.guide-section code {
  color: var(--text);
}

.tool-builder-section {
  padding: 16px;
}

.tool-builder-section .tools-head {
  margin-bottom: 16px;
}

#input-fields,
#output-fields {
  display: grid;
  gap: 22px;
}

.builder-add-button {
  margin-top: 14px;
}

.tool-output-grid {
  display: grid;
  gap: 12px;
}

.tool-output,
.tool-inputs-spoiler {
  padding: 14px;
}

.tool-output h4 {
  margin: 0 0 8px;
  color: var(--muted);
}

.tool-output p {
  margin: 0;
  line-height: 1.55;
}

.tool-output.primary-featured {
  background: linear-gradient(135deg, oklch(0.25 0.09 280 / 0.86), oklch(0.18 0.05 265 / 0.76));
}

.tool-output.primary-featured p {
  color: var(--text);
  font-weight: 800;
  letter-spacing: 0;
}

.tool-output.primary-int p,
.tool-output.primary-float p {
  font-size: clamp(3rem, 9vw, 6.5rem);
  line-height: 0.95;
}

.tool-output.primary-text p {
  font-size: clamp(2.1rem, 6vw, 4.5rem);
  line-height: 1.08;
  overflow-wrap: anywhere;
}

.tool-output-image-button {
  width: min(100%, 420px);
  display: grid;
  gap: 8px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}

.tool-output-image-button:disabled {
  cursor: default;
  opacity: 0.72;
}

.tool-output-image-button img {
  width: auto;
  max-width: 100%;
  max-height: min(72vh, 720px);
  object-fit: contain;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

.tool-output.primary-image .tool-output-image-button {
  width: min(100%, 560px);
}

.rating-output {
  display: grid;
  gap: 8px;
}

.rating-gauge {
  width: min(100%, 360px);
  display: grid;
  justify-items: center;
  gap: 4px;
  margin: 0 auto;
}

.rating-gauge-svg {
  width: 100%;
  height: auto;
  margin-bottom: -18px;
  overflow: visible;
}

.rating-gauge-track,
.rating-gauge-segment {
  fill: none;
  stroke-linecap: round;
}

.rating-gauge-track {
  stroke: oklch(0.74 0.02 265 / 0.35);
  stroke-width: 11;
}

.rating-gauge-segment {
  stroke-width: 24;
  filter: drop-shadow(0 8px 16px oklch(0.08 0.02 265 / 0.24));
}

.rating-gauge-needle {
  stroke: oklch(0.9 0.02 265);
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 5px 10px oklch(0.05 0.02 265 / 0.55));
}

.rating-gauge-hub {
  fill: oklch(0.18 0.035 265);
  stroke: oklch(0.88 0.02 265);
  stroke-width: 7;
}

.rating-gauge-hub-inner {
  fill: oklch(0.88 0.02 265);
}

.rating-gauge-value {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
}

.rating-gauge-value strong {
  color: var(--text);
  font-size: clamp(2rem, 7vw, 4.4rem);
  line-height: 0.9;
}

.rating-gauge-value span,
.rating-gauge-range {
  color: var(--muted);
}

.rating-gauge-range {
  width: min(100%, 300px);
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
}

.rating-gauge-range + .rating-gauge-value {
  margin-top: 6px;
}

.tool-inputs-spoiler {
  margin-top: 14px;
}

.tool-inputs-spoiler summary {
  cursor: pointer;
  color: var(--muted);
}

.tool-inputs-readonly {
  display: grid;
  gap: 12px;
  margin-top: 12px;
}

.builder-row {
  position: relative;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) minmax(0, 1fr) 130px auto 40px;
  gap: 14px;
  align-items: start;
  padding: 16px;
  border: 1px solid color-mix(in oklch, var(--border), transparent 8%);
  border-left: 3px solid oklch(0.62 0.2 285 / 0.72);
  border-radius: var(--radius-md);
  background:
    linear-gradient(135deg, oklch(0.2 0.05 272 / 0.5), transparent 55%),
    oklch(0.125 0.032 265 / 0.86);
  box-shadow: 0 14px 32px oklch(0.08 0.02 265 / 0.26);
}

.builder-row[data-builder-output] {
  grid-template-columns: 120px minmax(0, 1fr) minmax(0, 1fr) 130px 40px;
  border-left-color: oklch(0.68 0.17 165 / 0.66);
  background:
    linear-gradient(135deg, oklch(0.18 0.05 165 / 0.34), transparent 58%),
    oklch(0.125 0.032 265 / 0.86);
}

.builder-row-title {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid color-mix(in oklch, var(--border), transparent 28%);
}

.builder-row-title span {
  color: var(--text);
  font-weight: 700;
}

.builder-row-title em {
  padding: 4px 9px;
  border: 1px solid color-mix(in oklch, var(--primary-glow), var(--border) 55%);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.76rem;
  font-style: normal;
  line-height: 1;
}

.builder-row[data-image-field="true"] [name="field_id"] {
  display: none;
}

.builder-config {
  grid-column: 1 / -1;
  min-width: 0;
  padding-top: 12px;
  border-top: 1px solid color-mix(in oklch, var(--border), transparent 32%);
}

.builder-config-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.builder-config-grid .field {
  margin-bottom: 0;
}

.builder-config-title,
.builder-config-empty,
.builder-hint {
  color: var(--muted);
  font-size: 0.86rem;
}

.builder-config-empty,
.builder-hint {
  margin: 0;
}

.option-editor {
  display: grid;
  gap: 10px;
}

.option-rows {
  display: grid;
  gap: 8px;
}

.option-row {
  display: grid;
  grid-template-columns: 160px minmax(0, 1fr) minmax(0, 1fr) 40px;
  gap: 8px;
  align-items: start;
  padding: 10px;
  border: 1px solid color-mix(in oklch, var(--border), transparent 35%);
  border-radius: var(--radius-sm);
  background: oklch(0.12 0.028 265 / 0.6);
}

.checkbox-field {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--muted);
}

.checkbox-field.compact {
  min-width: 100px;
}

.settings-grid {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 22px;
}

.avatar-uploader {
  display: grid;
  place-items: center;
  gap: 12px;
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
}

.avatar-preview {
  width: 96px;
  height: 96px;
  border-radius: 999px;
  overflow: hidden;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--surface-2), var(--primary));
}

.avatar-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.settings-actions {
  gap: 10px;
  justify-content: flex-end;
  margin-top: 18px;
}

.admin-tabs {
  gap: 8px;
  flex-wrap: wrap;
  margin: 20px 0;
}

.tab-btn {
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
}

.tab-btn.active {
  color: var(--text);
  background: linear-gradient(135deg, oklch(0.38 0.15 280), oklch(0.35 0.12 295));
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
}

.kpi,
.chart,
.data-table-wrap,
.form-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-card);
}

.kpi {
  padding: 14px;
}

.kpi span {
  color: var(--muted);
  font-size: 0.84rem;
}

.kpi strong {
  display: block;
  margin-top: 8px;
  font-size: 1.8rem;
}

.chart {
  height: 220px;
  margin-top: 14px;
  padding: 16px;
  display: flex;
  align-items: end;
  gap: 10px;
}

.bar {
  flex: 1;
  min-width: 18px;
  border-radius: 8px 8px 3px 3px;
  background: linear-gradient(180deg, var(--accent), var(--primary));
  box-shadow: 0 0 18px oklch(0.6 0.2 285 / 0.25);
  position: relative;
}

.bar span {
  position: absolute;
  left: 50%;
  bottom: -24px;
  transform: translateX(-50%);
  color: var(--faint);
  font-size: 0.72rem;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 14px 0;
}

.toolbar .input,
.toolbar .select {
  max-width: 260px;
}

.data-table-wrap {
  overflow: auto;
}

.data-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

.data-table th,
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: top;
}

.data-table th {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
}

.data-table td {
  color: var(--text);
}

.admin-logs-table {
  min-width: 0;
  table-layout: fixed;
}

.admin-logs-table .log-col-when {
  width: 178px;
}

.admin-logs-table .log-col-action {
  width: 34%;
}

.admin-logs-table .log-col-actor {
  width: auto;
}

.admin-logs-table .log-col-details {
  width: 110px;
}

.admin-logs-table th,
.admin-logs-table td {
  overflow: hidden;
}

.log-cell-nowrap {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-cell-details {
  text-align: right;
}

.admin-conversation-link {
  max-width: min(52vw, 560px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.admin-conversation-link:hover {
  color: var(--primary-glow);
}

.table-actions {
  gap: 7px;
  flex-wrap: wrap;
}

.mini-btn {
  min-height: 30px;
  padding: 5px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: oklch(0.22 0.04 265);
  color: var(--text);
}

.mini-btn.btn-danger {
  border-color: oklch(0.55 0.18 25 / 0.7);
  background: oklch(0.24 0.06 25 / 0.7);
  color: oklch(0.86 0.08 25);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.86rem;
}

.form-card {
  padding: 14px;
  margin-top: 14px;
}

.form-card-subsection {
  display: grid;
  gap: 10px;
  padding: 12px;
  margin: 12px 0;
  border: 1px solid color-mix(in oklch, var(--border), transparent 24%);
  border-radius: var(--radius-sm);
  background: oklch(0.13 0.035 265 / 0.42);
}

.form-card-subsection h3 {
  margin: 0;
  font-size: 1rem;
}

.compact-textarea {
  min-height: 74px;
}

.form-row,
.filter-row {
  gap: 10px;
  flex-wrap: wrap;
}

.form-row > *,
.filter-row > * {
  flex: 1;
  min-width: 180px;
}

.blocked-screen {
  display: grid;
  place-items: center;
}

.blocked-card {
  width: min(520px, 100%);
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
  text-align: center;
}

.blocked-card svg {
  color: var(--danger);
}

.toast-root {
  position: fixed;
  top: 18px;
  left: 50%;
  z-index: 220;
  display: grid;
  gap: 10px;
  width: min(560px, calc(100vw - 36px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  width: 100%;
  padding: 15px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: oklch(0.16 0.035 265 / 0.96);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 1rem;
  font-weight: 650;
  line-height: 1.4;
  text-align: center;
  animation: toastSlowPulse 1.35s ease-in-out infinite;
  pointer-events: auto;
}

.toast.error {
  border-color: oklch(0.58 0.18 25 / 0.8);
  animation-name: toastSlowPulseError;
}

@keyframes toastSlowPulse {
  0%,
  100% {
    border-color: var(--border);
    box-shadow: var(--shadow);
  }
  50% {
    border-color: color-mix(in oklch, var(--primary-glow), white 10%);
    box-shadow: var(--shadow), 0 0 0 2px oklch(0.68 0.18 285 / 0.14), 0 0 26px oklch(0.68 0.18 285 / 0.24);
  }
}

@keyframes toastSlowPulseError {
  0%,
  100% {
    border-color: oklch(0.58 0.18 25 / 0.8);
    box-shadow: var(--shadow);
  }
  50% {
    border-color: color-mix(in oklch, var(--danger), white 20%);
    box-shadow: var(--shadow), 0 0 0 2px oklch(0.64 0.21 25 / 0.13), 0 0 26px oklch(0.64 0.21 25 / 0.24);
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast {
    animation: none;
  }
}

@media (max-width: 980px) {
  .empty-state.input-focused .home-tools {
    display: none;
  }

  body:has(#app.auth-app),
  body:has(.auth-page) {
    overflow: auto;
  }

  #app.auth-app,
  #app:has(.auth-page) {
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .auth-page {
    min-height: auto;
    grid-template-columns: 1fr;
    padding: 72px 24px 24px;
  }

  .mobile-login-link {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 20;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 42px;
    padding: 0 16px;
    border: 1px solid color-mix(in oklch, var(--primary-glow), var(--border) 36%);
    border-radius: 999px;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: var(--glow);
    color: white;
    font-weight: 700;
  }

  .feature-strip,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 130;
    transform: translateX(-104%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 120;
    display: block;
    border: 0;
    background: oklch(0.08 0.035 265 / 0.46);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .sidebar-backdrop.open {
    opacity: 1;
    pointer-events: auto;
  }

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

  .sidebar-close {
    display: inline-flex;
  }

  .mobile-topbar {
    display: flex;
    padding: 7px;
  }

  .mobile-topbar .brand-mark {
    width: 30px;
    height: 30px;
    border-radius: 0;
  }

  .sidebar-head {
    padding: 10px;
  }

  .brand-row {
    margin-bottom: 10px;
  }

  .sidebar-actions {
    display: flex;
    align-items: stretch;
    gap: 7px;
  }

  .sidebar-actions .btn {
    min-width: 0;
    flex: 1;
    padding-inline: 10px;
  }

  .sidebar-actions #new-chat {
    min-width: 42px;
    flex: 1 1 auto;
    padding-inline: 0;
  }

  .sidebar-actions #new-chat span {
    display: none;
  }

  .sidebar-actions .quota-pill {
    min-width: 84px;
    flex: 0 0 auto;
    padding: 7px 8px;
    gap: 6px;
  }

  .sidebar-nav {
    padding: 6px;
  }

  .sidebar-nav .conversation-item {
    margin: 2px 0;
    padding: 7px 8px;
  }

  .sidebar-section-toggle {
    padding: 7px 10px 4px;
  }

  .conversation-list {
    padding: 0 6px 6px;
  }

  .date-group {
    margin: 8px 0 4px;
    padding: 0 6px;
  }

  .conversation-item {
    margin: 2px 0;
    padding: 7px 8px;
    gap: 2px;
  }

  .main {
    grid-template-rows: auto minmax(0, 1fr);
    min-height: 0;
  }

  .main,
  .sidebar {
    height: var(--app-height);
  }

  #main-view,
  .chat-view {
    min-height: 0;
    height: 100%;
  }

  .title-edit {
    width: min(100%, 58vw);
  }

  .tool-filter-bar,
  .tool-detail-hero,
  .tool-create-choice,
  .tool-copy-item,
  .builder-row,
  .builder-row[data-builder-output],
  .option-row {
    grid-template-columns: 1fr;
  }

  .tool-copy-item {
    justify-items: stretch;
  }

  .tool-guide-hero {
    flex-direction: column;
  }

  .tool-detail-hero .table-actions,
  .segmented-control {
    justify-content: flex-start;
  }

  .tool-detail-hero .table-actions {
    grid-column: 1 / -1;
  }

  .tool-grid {
    grid-template-columns: 1fr;
    gap: 9px;
  }

  .tool-card {
    min-height: 0;
    grid-template-columns: 72px minmax(0, 1fr);
    gap: 7px 11px;
    padding: 10px 40px 10px 10px;
  }

  .tool-card .tool-card-image {
    width: 72px;
    height: 72px;
    aspect-ratio: auto;
    grid-row: 1 / span 4;
  }

  .tool-card > span {
    line-height: 1.3;
  }

  .tool-detail-hero {
    grid-template-columns: 76px minmax(0, 1fr);
    gap: 12px;
    align-items: start;
  }

  .tool-detail-hero .tool-card-image.large {
    width: 76px;
    height: 76px;
    aspect-ratio: auto;
  }

  .home-tools-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .auth-title {
    font-size: 3.2rem;
  }

  .feature-strip,
  .prompt-grid,
  .home-tools-grid,
  .settings-grid {
    grid-template-columns: 1fr;
  }

  .empty-state .prompt-grid {
    display: none;
  }

  .bubble {
    max-width: 88%;
  }

  .chat-header .quota-pill {
    display: none;
  }

  .chat-header {
    padding: 8px 10px;
    gap: 7px;
  }

  .title-edit {
    width: 100%;
    min-width: 0;
    padding: 5px 7px;
    font-size: 0.94rem;
  }

  .chat-actions {
    flex: none;
    gap: 4px;
  }

  .chat-actions-inline {
    display: none;
  }

  .chat-action-menu {
    display: block;
  }

  .message-scroller {
    padding: 12px 10px;
  }

  .settings-panel,
  .admin-panel,
  .tools-panel {
    padding: 16px;
  }

  .settings-section-head,
  .memory-item-head {
    align-items: stretch;
    flex-direction: column;
  }

  .settings-section-head .btn,
  .memory-item-head .btn {
    width: fit-content;
  }

  .admin-memory-form {
    grid-template-columns: 1fr;
  }

  .tools-layout {
    padding: 14px;
  }

  .tools-head {
    align-items: stretch;
    flex-direction: column;
  }

  .personalities-detail-subtitle {
    display: none;
  }

  .tool-filter-bar {
    gap: 7px;
    margin: 2px 0 12px;
  }

  .tool-filter-bar .select {
    min-height: 34px;
    padding: 7px 9px;
    font-size: 0.84rem;
  }

  .tool-filter-toggle {
    min-height: 34px;
    padding: 0 8px;
    gap: 7px;
    font-size: 0.82rem;
  }

  .tool-filter-toggle input {
    width: 14px;
    height: 14px;
  }

  .tool-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .tool-card {
    min-height: 0;
    grid-template-columns: 58px minmax(0, 1fr);
    gap: 6px 10px;
    padding: 9px 38px 9px 9px;
  }

  .tool-card .tool-card-image {
    width: 58px;
    height: 58px;
    aspect-ratio: auto;
    grid-row: 1 / span 4;
  }

  .tool-card .tool-name-line {
    align-self: end;
  }

  .tool-card > span {
    font-size: 0.86rem;
    line-height: 1.25;
  }

  .tool-card-meta {
    gap: 4px;
  }

  .tool-card-meta small,
  .tag-row em {
    padding: 2px 5px;
    font-size: 0.68rem;
  }

  .tool-card-favorite {
    top: 8px;
    right: 8px;
  }

  .tool-detail-hero {
    grid-template-columns: 62px minmax(0, 1fr);
    gap: 10px;
    margin-bottom: 12px;
  }

  .tool-detail-hero .tool-card-image.large {
    width: 62px;
    height: 62px;
    aspect-ratio: auto;
  }

  .tool-detail-hero h3 {
    margin-bottom: 4px;
    font-size: 1.05rem;
  }

  .tool-detail-hero p {
    margin-bottom: 7px;
    font-size: 0.86rem;
    line-height: 1.35;
  }

  .tool-detail-hero .detail-meta {
    margin: 7px 0;
  }

  .tool-detail-hero .tag-row {
    gap: 4px;
  }

  .tool-detail-hero .table-actions {
    grid-column: 1 / -1;
    gap: 6px;
  }

  .tool-actions .btn {
    min-height: 30px;
    padding: 5px 8px;
    font-size: 0.78rem;
  }

  .tool-actions .btn-icon {
    width: 30px;
    height: 30px;
  }

  .toast-root {
    top: 10px;
    width: min(100vw - 20px, 460px);
  }

  .toast {
    padding: 12px 14px;
    font-size: 0.92rem;
  }

  .personality-conversation-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .personality-conversation-date {
    order: -1;
    font-size: 0.75rem;
  }

  .data-table-wrap {
    overflow: visible;
    border: none;
    border-radius: 0;
    background: none;
  }

  .data-table {
    min-width: 0;
    display: block;
  }

  .data-table thead {
    display: none;
  }

  .data-table tbody {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .data-table tr {
    display: block;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--surface-card);
    padding: 10px 12px;
  }

  .data-table td {
    display: block;
    border: none;
    padding: 3px 0;
  }

  .data-table td:empty {
    display: none;
  }

  .admin-conversation-link {
    max-width: 100%;
  }

  .data-table .table-actions {
    margin-top: 6px;
  }

  .admin-logs-table {
    table-layout: auto;
  }

  .msg-copy-btn {
    opacity: 1;
  }
}

/* ─── Light theme ──────────────────────────────────────────────────── */

html[data-theme="light"] {
  color-scheme: light;
  --bg: oklch(0.96 0.006 265);
  --bg-strong: oklch(0.91 0.01 265);
  --surface: color-mix(in oklch, oklch(0.99 0.003 265) 88%, transparent);
  --surface-solid: oklch(0.97 0.005 265);
  --surface-2: oklch(0.93 0.008 270);
  --border: oklch(0.81 0.02 270 / 0.65);
  --text: oklch(0.2 0.02 265);
  --muted: oklch(0.46 0.025 270);
  --faint: oklch(0.62 0.02 270);
  --primary: oklch(0.52 0.22 280);
  --primary-glow: oklch(0.62 0.18 285);
  --accent: oklch(0.55 0.18 295);
  --success: oklch(0.5 0.16 150);
  --warning: oklch(0.55 0.16 75);
  --danger: oklch(0.52 0.21 25);
  --shadow: 0 22px 60px oklch(0.72 0.02 265 / 0.16);
  --glow: 0 0 30px oklch(0.62 0.22 285 / 0.14);
  --sidebar-bg: oklch(0.93 0.008 265 / 0.92);
  --surface-input: oklch(0.98 0.004 265 / 0.9);
  --surface-card: oklch(0.97 0.005 265 / 0.85);
  --surface-hover: oklch(0.9 0.012 270 / 0.8);
  --surface-bubble: oklch(0.99 0.003 265 / 0.95);
  --surface-code: oklch(0.92 0.01 265 / 0.9);
  --surface-code-block: oklch(0.91 0.01 265 / 0.95);
  --bg-glow: oklch(0.75 0.1 285 / 0.1);
}

html[data-theme="light"] body {
  background-color: var(--bg-strong);
  background:
    radial-gradient(circle at 50% -18%, var(--bg-glow), transparent 38rem),
    linear-gradient(135deg, var(--bg-strong), var(--bg));
}

html[data-theme="light"] .app-shell {
  background: linear-gradient(145deg, oklch(0.88 0.015 265 / 0.3), transparent);
}

/* Buttons — light surfaces */
html[data-theme="light"] .btn {
  background: oklch(0.97 0.005 265 / 0.9);
}

html[data-theme="light"] .btn:hover {
  background: oklch(0.93 0.008 265 / 0.95);
}

html[data-theme="light"] .mini-btn {
  background: oklch(0.93 0.008 265);
}

html[data-theme="light"] .mini-btn:hover {
  background: oklch(0.88 0.012 265);
}

/* Sidebar */
html[data-theme="light"] .sidebar-actions .btn#new-chat {
  background: linear-gradient(135deg, var(--primary), var(--accent));
}

/* Quota pill */
html[data-theme="light"] .quota-pill {
  background: oklch(0.91 0.01 265 / 0.85);
}

/* Memory items */
html[data-theme="light"] .memory-item,
html[data-theme="light"] .memory-empty {
  background: oklch(0.96 0.006 265 / 0.9);
}

/* Scroll-to-bottom */
html[data-theme="light"] .scroll-to-bottom {
  background: oklch(0.94 0.008 265 / 0.9);
}

/* Global banner */
html[data-theme="light"] .global-banner {
  background: linear-gradient(135deg, oklch(0.75 0.09 280 / 0.92), oklch(0.7 0.08 300 / 0.92));
}

/* Tabs — keep readable in light mode */
html[data-theme="light"] .tab-btn.active {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: oklch(0.99 0.003 265);
}

/* Favorite button active */
html[data-theme="light"] .favorite-btn.active {
  background: oklch(0.93 0.05 82 / 0.5);
  border-color: oklch(0.72 0.14 82 / 0.55);
}

/* Admin form subsections (Bannière, Redirection, Images en conv.) */
html[data-theme="light"] .form-card-subsection {
  background: oklch(0.95 0.007 265 / 0.6);
}

/* Tooltip / popover */
html[data-theme="light"] .tooltip,
html[data-theme="light"] .popover {
  background: oklch(0.98 0.004 265 / 0.98);
  box-shadow: 0 10px 28px oklch(0.72 0.02 265 / 0.18);
}

/* Mobile topbar */
html[data-theme="light"] .mobile-topbar {
  background: oklch(0.93 0.009 265 / 0.94);
  backdrop-filter: blur(16px);
}

html[data-theme="light"] .mobile-menu-backdrop,
html[data-theme="light"] .chat-menu {
  background: oklch(0.96 0.006 265 / 0.97);
}

html[data-theme="light"] .chat-menu-item.active,
html[data-theme="light"] .chat-menu-item:hover {
  background: var(--surface-hover);
}

html[data-theme="light"] .title-edit:focus {
  background: var(--surface-input);
}

/* Message bubbles */
html[data-theme="light"] .message .bubble {
  background: var(--surface-bubble);
  box-shadow: 0 14px 28px oklch(0.75 0.02 265 / 0.12);
}

html[data-theme="light"] .message.user .msg-copy-btn {
  color: var(--muted);
}

html[data-theme="light"] .message.user .msg-copy-btn:hover {
  color: var(--text);
}

/* Markdown tables */
html[data-theme="light"] .markdown th {
  background: oklch(0.9 0.01 265);
}

/* Code blocks — kept dark intentionally */
html[data-theme="light"] .markdown pre,
html[data-theme="light"] .code-wrap {
  background: oklch(0.16 0.04 265 / 0.95);
}

html[data-theme="light"] .code-wrap--svg {
  background: oklch(0.94 0.006 265 / 0.92);
}

/* File upload / lightbox */
html[data-theme="light"] .upload-area,
html[data-theme="light"] .lightbox-image-entry {
  background: oklch(0.94 0.008 265 / 0.9);
}

html[data-theme="light"] .image-lightbox__backdrop {
  background: oklch(0.94 0.007 265 / 0.92);
}

html[data-theme="light"] .json-modal__backdrop {
  background: oklch(0.94 0.007 265 / 0.9);
}

html[data-theme="light"] .json-modal,
html[data-theme="light"] .admin-user-detail-section {
  background: oklch(0.96 0.006 265 / 0.92);
}

/* Tool option rows (enum inputs) */
html[data-theme="light"] .option-row {
  background: oklch(0.94 0.008 265 / 0.7);
}

html[data-theme="light"] .admin-log-details {
  background: oklch(0.94 0.008 265 / 0.7);
}

html[data-theme="light"] .admin-log-metadata {
  background: oklch(0.93 0.008 265 / 0.8);
}

/* Composer / input area */
html[data-theme="light"] .composer-shell {
  background: linear-gradient(180deg, transparent, oklch(0.93 0.009 265 / 0.96) 35%);
}

html[data-theme="light"] .composer {
  background: oklch(0.97 0.005 265 / 0.97);
}

html[data-theme="light"] .message-input-inner {
  background: oklch(0.98 0.004 265 / 0.97);
}

/* Tools */
html[data-theme="light"] .tool-filter-toggle {
  background: oklch(0.93 0.008 265 / 0.75);
}

html[data-theme="light"] .tool-card-meta small {
  background: oklch(0.92 0.01 270 / 0.8);
}

html[data-theme="light"] .tool-run-primary-text.output {
  border-color: oklch(0.55 0.14 285 / 0.5);
  background: oklch(0.92 0.012 285 / 0.5);
}

html[data-theme="light"] .tool-detail-hero,
html[data-theme="light"] .tool-run-detail-hero {
  background: linear-gradient(135deg, oklch(0.95 0.01 265 / 0.88), oklch(0.97 0.006 265 / 0.78));
}

html[data-theme="light"] .tool-run-form .tool-use-card,
html[data-theme="light"] .tool-output {
  background: linear-gradient(135deg, oklch(0.95 0.01 270 / 0.86), oklch(0.97 0.006 265 / 0.72));
}

html[data-theme="light"] .tool-guide-diagram {
  background: oklch(0.94 0.008 265 / 0.85);
}

html[data-theme="light"] .guide-section pre {
  background: oklch(0.16 0.04 265 / 0.95);
}

html[data-theme="light"] .builder-row {
  background: oklch(0.96 0.006 265 / 0.9);
  box-shadow: 0 14px 32px oklch(0.72 0.01 265 / 0.12);
}

html[data-theme="light"] .tool-output.primary-featured {
  background: linear-gradient(135deg, oklch(0.91 0.018 280 / 0.86), oklch(0.95 0.009 265 / 0.78));
}

html[data-theme="light"] .tool-image-picker {
  background: oklch(0.94 0.008 265 / 0.72);
}

html[data-theme="light"] .tool-processing {
  background: oklch(0.96 0.006 265 / 0.94);
}

/* Tables */
html[data-theme="light"] .data-table-wrap,
html[data-theme="light"] .admin-table-wrap {
  background: var(--surface-card);
}

/* Toast */
html[data-theme="light"] .toast {
  background: oklch(0.98 0.004 265 / 0.99);
}

html[data-theme="light"] .user-profile-link:focus-visible {
  background: var(--surface-hover);
}

html[data-theme="light"] .home-tool-card:hover {
  background: oklch(0.91 0.015 275 / 0.7);
}

html[data-theme="light"] .chat-header {
  background: oklch(0.95 0.008 265 / 0.88);
}

html[data-theme="light"] .tool-validation-note {
  background: oklch(0.94 0.01 270 / 0.7);
  color: var(--muted);
}

html[data-theme="light"] .btn-danger {
  border-color: oklch(0.6 0.2 25 / 0.7);
  color: oklch(0.52 0.22 25);
}

html[data-theme="light"] .mini-btn.btn-danger {
  border-color: oklch(0.6 0.2 25 / 0.7);
  background: oklch(0.95 0.04 25 / 0.7);
  color: oklch(0.52 0.22 25);
}

html[data-theme="light"] .user-profile-link:hover,
html[data-theme="light"] .user-profile-link:focus-visible {
  background: oklch(0.9 0.012 270 / 0.7);
}

html[data-theme="light"] .tool-detail-hero,
html[data-theme="light"] .tool-run-detail-hero {
  background: transparent;
}

/* btn-primary keeps gradient in light mode */
html[data-theme="light"] .btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: oklch(0.99 0.003 265);
  border: 0;
}

html[data-theme="light"] .tag-chip {
  border-color: oklch(0.7 0.1 282 / 0.6);
  background: oklch(0.9 0.04 282 / 0.55);
  color: oklch(0.3 0.12 282);
}

html[data-theme="light"] .tool-guide-hero {
  background: linear-gradient(135deg, oklch(0.93 0.015 270 / 0.88), oklch(0.95 0.01 265 / 0.72));
}

html[data-theme="light"] .guide-section code:not(pre code) {
  background: oklch(0.92 0.01 265 / 0.9);
  color: var(--text);
}

html[data-theme="light"] .tool-processing-name {
  background: oklch(0.91 0.025 280 / 0.72);
  border-color: color-mix(in oklch, var(--primary-glow), var(--border) 45%);
  color: oklch(0.35 0.15 280);
}

html[data-theme="light"] .btn-primary:hover {
  background: linear-gradient(135deg, oklch(0.48 0.22 280), oklch(0.52 0.18 295));
}

html[data-theme="light"] .tool-mode-card {
  background: linear-gradient(135deg, oklch(0.96 0.009 265 / 0.9), oklch(0.94 0.007 265 / 0.8));
}

html[data-theme="light"] .tool-processing-orb {
  background: radial-gradient(circle, oklch(0.99 0.005 285), oklch(0.93 0.015 270));
  box-shadow: 0 0 28px oklch(0.62 0.22 285 / 0.2);
}

html[data-theme="light"] .tool-processing-orb {
  background: radial-gradient(circle, oklch(0.48 0.18 285), oklch(0.22 0.08 270));
  box-shadow: 0 0 28px oklch(0.62 0.22 285 / 0.42);
}

html[data-theme="light"] .tool-processing-orb svg {
  color: oklch(0.99 0.003 265);
}

html[data-theme="light"] .tool-validation-note.ready {
  background: oklch(0.93 0.04 150 / 0.5);
  border-color: oklch(0.55 0.14 150 / 0.6);
  color: oklch(0.38 0.14 150);
}

html[data-theme="light"] .admin-log-detail-row {
  background: oklch(0.96 0.006 265 / 0.85);
}

html[data-theme="light"] .admin-log-metadata-body {
  background: oklch(0.95 0.007 265 / 0.8);
}

html[data-theme="light"] .site-banner {
  background: linear-gradient(135deg, oklch(0.52 0.18 280 / 0.92), oklch(0.46 0.16 300 / 0.92));
  color: oklch(0.99 0.005 265);
}

html[data-theme="light"] .tool-card-meta small {
  background: oklch(0.88 0.015 270 / 0.85);
  color: var(--muted);
}

html[data-theme="light"] .tool-card-meta small.tool-quality-label {
  border-color: oklch(0.7 0.14 82 / 0.5);
  background: oklch(0.92 0.05 82 / 0.7);
  color: oklch(0.45 0.14 82);
}

html[data-theme="light"] .tool-origin-badge {
  border-color: oklch(0.65 0.12 282 / 0.5);
  background: oklch(0.9 0.04 282 / 0.6);
  color: oklch(0.4 0.16 282);
}

html[data-theme="light"] .svg-code-preview {
  background:
    linear-gradient(45deg, oklch(0.84 0.012 265 / 0.9) 25%, transparent 25%),
    linear-gradient(-45deg, oklch(0.84 0.012 265 / 0.9) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, oklch(0.84 0.012 265 / 0.9) 75%),
    linear-gradient(-45deg, transparent 75%, oklch(0.84 0.012 265 / 0.9) 75%);
  background-color: oklch(0.96 0.005 265 / 0.95);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

/* Banner icon white */
html[data-theme="light"] .site-banner svg {
  color: oklch(0.99 0.005 265);
}

/* Code block buttons */
html[data-theme="light"] .code-copy,
html[data-theme="light"] .svg-code-toggle {
  background: oklch(0.92 0.008 265 / 0.95);
  color: var(--muted);
  border-color: var(--border);
}

html[data-theme="light"] .svg-code-toggle:hover,
html[data-theme="light"] .code-copy:hover {
  background: oklch(0.86 0.012 265);
  color: var(--text);
}

/* Code blocks — GitHub Light syntax highlighting */
html[data-theme="light"] .hljs {
  color: #24292f;
  background: #f6f8fa;
}

html[data-theme="light"] .markdown pre,
html[data-theme="light"] .code-wrap pre {
  background: #f6f8fa;
}

html[data-theme="light"] .hljs-doctag,
html[data-theme="light"] .hljs-keyword,
html[data-theme="light"] .hljs-meta .hljs-keyword,
html[data-theme="light"] .hljs-template-tag,
html[data-theme="light"] .hljs-template-variable,
html[data-theme="light"] .hljs-type,
html[data-theme="light"] .hljs-variable.language_ {
  color: #cf222e;
}

html[data-theme="light"] .hljs-title,
html[data-theme="light"] .hljs-title.class_,
html[data-theme="light"] .hljs-title.class_.inherited__,
html[data-theme="light"] .hljs-title.function_ {
  color: #8250df;
}

html[data-theme="light"] .hljs-attr,
html[data-theme="light"] .hljs-attribute,
html[data-theme="light"] .hljs-literal,
html[data-theme="light"] .hljs-meta,
html[data-theme="light"] .hljs-number,
html[data-theme="light"] .hljs-operator,
html[data-theme="light"] .hljs-selector-attr,
html[data-theme="light"] .hljs-selector-class,
html[data-theme="light"] .hljs-selector-id,
html[data-theme="light"] .hljs-variable {
  color: #0550ae;
}

html[data-theme="light"] .hljs-meta .hljs-string,
html[data-theme="light"] .hljs-regexp,
html[data-theme="light"] .hljs-string {
  color: #0a3069;
}

html[data-theme="light"] .hljs-built_in,
html[data-theme="light"] .hljs-symbol {
  color: #953800;
}

html[data-theme="light"] .hljs-code,
html[data-theme="light"] .hljs-comment,
html[data-theme="light"] .hljs-formula {
  color: #6e7781;
}

html[data-theme="light"] .hljs-name,
html[data-theme="light"] .hljs-quote,
html[data-theme="light"] .hljs-selector-pseudo,
html[data-theme="light"] .hljs-selector-tag {
  color: #116329;
}

html[data-theme="light"] .hljs-subst {
  color: #24292f;
}

html[data-theme="light"] .hljs-section {
  color: #0550ae;
  font-weight: 700;
}

html[data-theme="light"] .hljs-bullet {
  color: #3b2300;
}

html[data-theme="light"] .hljs-addition {
  color: #116329;
  background-color: #dafbe1;
}

html[data-theme="light"] .hljs-deletion {
  color: #82071e;
  background-color: #ffebe9;
}

.auth-lang-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-lang-row .select {
  flex: 1;
}

.auth-theme-toggle {
  flex: none;
  min-width: 0;
}

html[data-theme="light"] .hero-pill {
  background: oklch(0.94 0.01 265 / 0.85);
}

.message-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.message-btn {
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.message-btn:hover {
  border-color: var(--primary-glow);
  background: color-mix(in oklch, var(--primary) 15%, var(--surface-2));
  transform: translateY(-1px);
}

.message-btn:active {
  transform: translateY(0);
}

.message-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

html[data-theme="light"] .message-btn {
  background: oklch(0.96 0.01 265);
  border-color: oklch(0.82 0.03 265);
}

html[data-theme="light"] .message-btn:hover {
  border-color: var(--primary);
  background: oklch(0.92 0.04 280);
}
