:root {
  color-scheme: dark;
  --bg: #0a101b;
  --paper: #101a29;
  --surface: #111d2d;
  --raised: #172639;
  --line: #233347;
  --control-line: #65788d;
  --ink: #f4f6f7;
  --muted: #aab9ca;
  --teal: #76edda;
  --teal-soft: #173735;
  --on-accent: #10232a;
  --accent-hover: #9ff8ec;
  --red: #ffb0b4;
  --danger-surface: #3b222e;
  --success: #9ce8bf;
  --success-surface: #153628;
  --warning: #ffda88;
  --warning-surface: #392e1a;
  --info: #e5c5ff;
  --info-surface: #362446;
  --shadow: 0 18px 46px #0005;
  --radius-sm: .5rem;
  --radius: .75rem;
  --radius-lg: 1.125rem;
  --space-1: .5rem;
  --space-2: .75rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2rem;
  --text-small: .875rem;
  --text-title: clamp(1.75rem, 3.6vw, 2.5rem);
  --text-label: .75rem;
  --control-height: 2.75rem;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef3f7;
  --paper: #fff;
  --surface: #f3f7fa;
  --raised: #e6eef6;
  --line: #cbd7e2;
  --control-line: #697c91;
  --ink: #12243a;
  --muted: #46596d;
  --teal: #08716d;
  --teal-soft: #def3ef;
  --on-accent: #fff;
  --accent-hover: #075955;
  --red: #922b3b;
  --danger-surface: #fce7ec;
  --success: #185b3f;
  --success-surface: #dcf4e6;
  --warning: #714701;
  --warning-surface: #fff1ce;
  --info: #613581;
  --info-surface: #eee0f7;
  --shadow: 0 14px 35px #20385012;
}

:where(button, input, select, textarea, a, summary, [tabindex]):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 3px;
}
.skip-link {
  position: fixed;
  top: var(--space-1);
  left: var(--space-1);
  transform: translateY(-160%);
  z-index: 20;
}
.skip-link:focus { transform: none; }
.brand-logo { display: block; width: 8.75rem; max-width: 100%; height: auto; }
.brand-logo.light-logo, [data-theme="light"] .brand-logo.dark-logo { display: none; }
[data-theme="light"] .brand-logo.light-logo { display: block; }
.ui-icon { width: 1.15rem; height: 1.15rem; flex: none; vertical-align: middle; }
.theme-control { display: grid; gap: .25rem; color: var(--muted); font-size: var(--text-label); }
.theme-control select { min-height: var(--control-height); min-width: 6.5rem; }
.ui-empty, .ui-loading { padding: var(--space-4); color: var(--muted); }
.ui-empty { border: 1px dashed var(--line); border-radius: var(--radius); }
.ui-loading::before {
  content: '';
  display: block;
  width: min(14rem, 70%);
  height: .55rem;
  margin-bottom: var(--space-2);
  border-radius: var(--radius-sm);
  background: var(--raised);
  box-shadow: 0 .95rem 0 -.12rem var(--raised);
}
.ui-loading { display: grid; gap: .55rem; }
dialog { color: var(--ink); background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); max-width: min(36rem, calc(100% - 2rem)); }
dialog::backdrop { background: #060a12b5; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation: none !important; transition: none !important; }
}

/* Shared controls and operational surfaces */
h1 { font-size: var(--text-title); letter-spacing: -.045em; }
h2 { line-height: 1.25; }
input, select, textarea {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--control-line);
  border-radius: var(--radius-sm);
  min-height: var(--control-height);
  font: inherit;
}
input[type="checkbox"] { min-height: 1.2rem; accent-color: var(--teal); }
input[type="color"] { padding: .3rem; max-width: 5rem; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); }
button:disabled { cursor: default; }
.button { min-height: var(--control-height); border-radius: var(--radius-sm); text-align: center; }
.button.secondary { background: var(--surface); color: var(--ink); border-color: var(--control-line); }
.button.secondary:hover { background: var(--raised); }
.button.danger { color: var(--red); background: var(--paper); border-color: var(--red); }
.button.danger:hover { background: var(--danger-surface); }
.button:focus-visible, a:focus-visible { outline-color: var(--teal); }
.text-button { min-height: var(--control-height); }
a.text-button, a.quiet:hover { text-decoration: underline; text-underline-offset: .2em; }
.topbar { min-height: 4.5rem; height: auto; padding-block: var(--space-1); }
.topbar > :last-child { margin-left: auto; }
.auth-page .activation-card { width: min(100% - 2rem, 30rem); margin: clamp(2rem, 9vh, 7rem) auto; }
.activation-card h1 { margin-bottom: var(--space-3); }
.activation-card .error { margin-inline: 0; }
.error { overflow-wrap: anywhere; }
.status, .badge { align-items: center; gap: .3rem; }
.status:has(.ui-icon), .badge:has(.ui-icon) { display: inline-flex; }
.status .ui-icon, .badge .ui-icon { width: .85rem; height: .85rem; }
.review-summary { background: var(--surface); border-color: var(--line); }

/* Public chat. Custom colors tint surfaces while all text retains sufficient contrast. */
.chat-body {
  --chat-brand: var(--tenant-primary, var(--teal));
  --chat-secondary: var(--tenant-secondary, var(--paper));
  --chat-header: color-mix(in srgb, var(--paper) 94%, var(--chat-secondary));
  --chat-customer: color-mix(in srgb, var(--teal-soft) 91%, var(--chat-brand));
  --chat-avatar: color-mix(in srgb, var(--chat-brand) 38%, #0a101b);
}
.chat-body .chat-layout { width: min(100% - 2rem, 58rem); margin: clamp(1rem, 4vh, 3rem) auto; padding: 0; display: block; }
.chat-body .chat-card {
  height: min(55rem, calc(100dvh - 2 * clamp(1rem, 4vh, 3rem)));
  min-height: 25rem;
  border-radius: var(--radius-lg);
  overflow: visible;
  border-top: 3px solid var(--chat-brand);
}
.chat-body .chat-heading { position: relative; background: var(--chat-header); border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding: var(--space-3) var(--space-4); }
.chat-identity { min-width: 0; overflow-wrap: anywhere; }
.chat-body .chat-heading h1 { font-size: clamp(1.1rem, 4vw, 1.45rem); }
.chat-body .chat-heading p.muted { font-size: var(--text-small); }
.chat-body .avatar { background: var(--chat-avatar); color: #fff; }
.chat-body .avatar img { width: 100%; height: 100%; max-width: 3rem; max-height: 3rem; object-fit: contain; }
.chat-body .avatar img[src="/static/evoluta.svg"] { padding: .45rem; }
.chat-menu { position: relative; margin-inline-start: auto; }
.chat-menu > summary { display: grid; place-items: center; list-style: none; width: var(--control-height); height: var(--control-height); border: 1px solid var(--line); border-radius: var(--radius-sm); }
.chat-menu > summary::-webkit-details-marker { display: none; }
.chat-menu-panel { position: absolute; z-index: 2; inset: calc(100% + .35rem) 0 auto auto; width: min(17rem, 75vw); display: grid; gap: var(--space-2); padding: var(--space-3); border: 1px solid var(--line); border-radius: var(--radius); background: var(--paper); box-shadow: var(--shadow); }
.chat-body .history {
  flex: 1; min-height: 4rem; max-height: none;
  padding: clamp(.85rem, 3vw, 1.65rem);
  background: var(--bg);
}
.chat-body .message { font-size: .9375rem; max-width: min(91%, 43rem); min-width: 0; }
.chat-body .message.customer { background: var(--chat-customer); }
.chat-body .message time { font-size: var(--text-label); color: var(--muted); }
.chat-body .message a { color: var(--teal); text-decoration: underline; text-underline-offset: .16em; }
.chat-body .flow-controls { max-height: min(32dvh, 18rem); overflow: auto; }
.chat-body .composer { padding: var(--space-2) var(--space-4); align-items: center; }
.chat-body .composer input { font-size: 1rem; }
.chat-body .icon-button { width: var(--control-height); height: var(--control-height); }
.chat-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem var(--space-3);
  padding: 0 var(--space-4) var(--space-2);
  color: var(--muted);
  font-size: var(--text-label);
}
.chat-footer #connection { margin: 0; flex: 1; min-width: 10rem; }
.chat-footer #powered-by { font-size: inherit; margin-left: auto; }
.chat-footer details { flex-basis: 100%; }
.chat-footer summary { cursor: pointer; color: var(--ink); }
.chat-footer .summary { margin: .35rem 0; padding: var(--space-2); }
.chat-footer .summary p { margin: .15rem 0; }
@media (max-width: 640px) {
  .chat-body .chat-layout { width: 100%; margin: 0; }
  .chat-body .chat-card { height: 100dvh; min-height: 0; border-inline: 0; border-radius: 0; }
  .chat-body .chat-heading { border-radius: 0; padding: var(--space-2) var(--space-3); }
  .chat-body .composer { padding: var(--space-1) var(--space-3); }
  .chat-footer { padding: 0 var(--space-3) max(var(--space-1), env(safe-area-inset-bottom)); }
}
