/* App preference only: customer widgets and their configured previews stay independent. */
:root {
  --menu-hover: #f3f4f6;
}
body:not(.widget-page) .profile-menu button:hover,
body:not(.widget-page) .profile-menu button:focus-visible {
  background: var(--menu-hover);
}
html[data-theme="dark"]:not(:has(> body.widget-page)),
html[data-theme="dark"] > body:not(.widget-page) {
  color-scheme: dark;
  --bg: #000000;
  --surface: #111111;
  --soft: #242424;
  --ink: #ededed;
  --muted: #b5b5b5;
  --line: #333333;
  --blue: #8cadff;
  --blue-soft: #223252;
  --green: #76c9ac;
  --danger: #ffaaa3;
  --warning: #ff922b;
  --shadow: 0 8px 28px #00000026;
  --menu-hover: #262626;
  --theme-raised: #181818;
  --theme-faint: #a0a0a0;
  --theme-primary: #365edb;
  --theme-primary-hover: #416ce8;
  --theme-info-line: #383838;
  --theme-danger-bg: #352427;
  --theme-danger-line: #704347;
  --theme-warning-bg: #2e1c10;
  --theme-warning-line: #7a3d14;
}
html[data-theme="dark"] body:not(.widget-page) {
  background: var(--bg);
  color: var(--ink);
  scrollbar-color: #626262 var(--surface);
}
html[data-theme="dark"] body:not(.widget-page) ::selection {
  background: #395286;
  color: #fff;
}
/* Preserve brand color while lifting the existing blue artwork off black. */
html[data-theme="dark"] body:not(.widget-page) .brand > img,
html[data-theme="dark"] body:not(.widget-page) .auth-assurance > img {
  filter: brightness(1.45);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(
    .panel-surface,
    .modal,
    .toast,
    .docs-header,
    .skip-link,
    .overview-stat,
    .timezone-trigger,
    .website-input,
    .usecase-card,
    .platform-card,
    .installation-card,
    .composer-box,
    .conversation-row,
    .customer-details
  ) {
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(.profile-menu, .timezone-popover) {
  background: var(--theme-raised);
  border-color: var(--line);
  box-shadow: 0 12px 36px #00000040;
}
html[data-theme="dark"] body:not(.widget-page) .modal {
  box-shadow: 0 25px 90px #00000066;
}
html[data-theme="dark"] body:not(.widget-page) .modal::backdrop {
  background: #000000b3;
}
html[data-theme="dark"] body:not(.widget-page) .drawer-backdrop {
  background: #0000009c;
}
html[data-theme="dark"] body:not(.widget-page) :is(input, select, textarea) {
  border-color: var(--line);
  color: var(--ink);
}
html[data-theme="dark"]
  body:not(.widget-page)
  input:not([type="checkbox"], [type="radio"], [type="range"]),
html[data-theme="dark"] body:not(.widget-page) select,
html[data-theme="dark"] body:not(.widget-page) textarea {
  background-color: var(--surface);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(input, textarea)::placeholder {
  color: var(--theme-faint);
  opacity: 1;
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(input:not([type="checkbox"], [type="radio"]), textarea, select):focus {
  border-color: #858585;
  box-shadow: 0 0 0 3px #ffffff12;
}
html[data-theme="dark"] body:not(.widget-page) input[aria-invalid="true"] {
  border-color: var(--danger);
}
html[data-theme="dark"] body:not(.widget-page) option {
  color: var(--ink);
  background: var(--surface);
}
html[data-theme="dark"] body:not(.widget-page) .button:hover,
html[data-theme="dark"] body:not(.widget-page) .icon-button:hover {
  background: var(--menu-hover);
  border-color: #555555;
}
html[data-theme="dark"] body:not(.widget-page) .button.primary,
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .button.primary {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
  color: #fff;
  box-shadow: 0 2px 3px #0000001f;
}
html[data-theme="dark"] body:not(.widget-page) .button.primary:hover,
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .button.primary:hover {
  background: var(--theme-primary-hover);
  border-color: var(--theme-primary-hover);
}
html[data-theme="dark"] body:not(.widget-page) .button.danger {
  border-color: var(--theme-danger-line);
}
html[data-theme="dark"] body:not(.widget-page) :is(.form-error, .chip.danger) {
  color: var(--danger);
  background: var(--theme-danger-bg);
  border-color: var(--theme-danger-line);
}
html[data-theme="dark"] body:not(.widget-page) .toast {
  background: var(--theme-raised);
  box-shadow: 0 14px 40px #00000059;
}
html[data-theme="dark"] body:not(.widget-page) .toast.error {
  border-color: var(--theme-danger-line);
}
html[data-theme="dark"] body:not(.widget-page) .notice {
  background: var(--theme-raised);
  color: var(--muted);
  border-color: var(--line);
}
html[data-theme="dark"] body:not(.widget-page) .auth-check {
  background: #1b1e23;
  color: #88a8f7;
  border-color: #3b404a;
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(.notice.warning, .chip.warning) {
  background: var(--theme-warning-bg);
  color: var(--warning);
  border-color: var(--theme-warning-line);
}
html[data-theme="dark"] body:not(.widget-page) .chip {
  background: var(--soft);
  color: var(--muted);
  border-color: var(--line);
}
html[data-theme="dark"] body:not(.widget-page) .chip.blue {
  background: var(--blue-soft);
  color: #b4c9fc;
}
html[data-theme="dark"] body:not(.widget-page) .chip.warning {
  background: var(--theme-warning-bg);
  color: var(--warning);
}
html[data-theme="dark"] body:not(.widget-page) .chip.danger {
  background: var(--theme-danger-bg);
  color: var(--danger);
}
html[data-theme="dark"] body:not(.widget-page) .chip.success {
  background: color-mix(in srgb, var(--green) 16%, transparent);
  color: var(--green);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(.code-block, #ready-widget-script) {
  background: #0c0c0c;
  border-color: var(--line);
  color: #cccccc;
}
html[data-theme="dark"] body:not(.widget-page) .skeleton {
  background: linear-gradient(100deg, #181818 20%, #242424 45%, #181818 65%);
  background-size: 200% 100%;
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(
    .auth-divider,
    .empty-state .empty-icon,
    .plan-card del
  ) {
  color: var(--theme-faint);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(.docs-layout p, .docs-layout li) {
  color: var(--muted);
}
html[data-theme="dark"] body:not(.widget-page) .docs-layout nav a.active {
  background: var(--blue-soft);
  color: var(--blue);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(th, .thread-subbar, .overview-methodology) {
  background: #181818;
  color: var(--muted);
  border-color: var(--line);
}
html[data-theme="dark"]
  body:not(.widget-page)
  :is(
    td,
    .surface-header,
    .table-wrap,
    .overview-response-row,
    .overview-member,
    .overview-team-link,
    .profile-footer,
    .thread-composer,
    .brand-summary,
    .installation-heading
  ) {
  border-color: var(--line);
}
html[data-theme="dark"] body:not(.widget-page) .billing-cycle button.active {
  background: #333333;
  box-shadow: 0 1px 4px #00000026;
}

/* Dashboard chrome and both navigation sizes. */
html[data-theme="dark"] .dashboard-page .app-shell.is-setup,
html[data-theme="dark"] .dashboard-page .app-shell:not(.is-setup) .sidebar {
  background: var(--bg);
}
html[data-theme="dark"] .dashboard-page .app-shell.is-setup .workspace-main {
  background: transparent;
}
html[data-theme="dark"] .dashboard-page .app-shell:not(.is-setup) .topbar {
  border-color: var(--line);
}
html[data-theme="dark"] .dashboard-page .app-shell:not(.is-setup) .nav-link {
  color: var(--muted);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .nav-link:hover,
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .sidebar-help
  a:hover,
html[data-theme="dark"]
  .dashboard-page
  :is(.sidebar-project-action, .sidebar-collapse):hover {
  background: var(--menu-hover);
  color: var(--ink);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .nav-link.active {
  background: var(--blue-soft);
  color: #b2c9ff;
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .nav-link.active
  svg {
  color: #b2c9ff;
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .workspace-switch
  select,
html[data-theme="dark"] .dashboard-page .availability-label select {
  background-color: transparent;
  color: var(--ink);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .workspace-switch
  select:hover {
  background-color: var(--menu-hover);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  :is(.notification-trigger, .sound-toggle),
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .topbar-title
  h1,
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .page-heading
  p,
html[data-theme="dark"]
  .dashboard-page
  :is(
    .sidebar-section-label,
    .sidebar-project-action,
    .sidebar-collapse,
    .view-label,
    .workspace-switch label,
    .profile-chevron,
    .overview-stat-heading,
    .overview-stat p,
    .overview-response-label,
    .overview-response-value small,
    .overview-member-copy small,
    .overview-member-status,
    .overview-contributions p
  ) {
  color: var(--muted);
}
html[data-theme="dark"] .dashboard-page :is(.view-label, .project-avatar) {
  border-color: var(--line);
}
html[data-theme="dark"] .dashboard-page .project-avatar {
  background: var(--soft);
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .avatar {
  color: #cccccc;
  background: #262626;
  border-color: #404040;
}
html[data-theme="dark"] .dashboard-page .topbar-separator {
  color: #626262;
}
html[data-theme="dark"] .dashboard-page .overview-eyebrow {
  color: var(--theme-faint) !important;
}
html[data-theme="dark"]
  .dashboard-page
  :is(.overview-stat-heading svg, .overview-response-label svg) {
  color: var(--theme-faint);
}
html[data-theme="dark"] .dashboard-page .overview-stat.needs-attention {
  background: #202c43;
  border-color: var(--theme-info-line);
}
html[data-theme="dark"]
  .dashboard-page
  :is(
    .overview-stat.needs-attention .overview-stat-value,
    .overview-team-link
  ) {
  color: #b0c7ff;
}

/* Inbox messages deliberately distinguish customer, agent and private notes. */
html[data-theme="dark"] .dashboard-page .conversation-row:hover {
  background: var(--menu-hover);
}
html[data-theme="dark"] .dashboard-page .conversation-row.active {
  background: var(--blue-soft);
  border-left-color: #88a8f7;
}
html[data-theme="dark"] .dashboard-page .conversation-row + .conversation-row {
  border-top-color: var(--line);
}
html[data-theme="dark"]
  .dashboard-page
  :is(
    .conversation-row .meta,
    .message-footer,
    .timeline-event,
    .composer-tab,
    .composer-tools .icon-button,
    .keyboard-hint
  ) {
  color: var(--theme-faint);
}
html[data-theme="dark"] .dashboard-page .message-bubble {
  background: #262626;
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .message.staff .message-bubble {
  background: #263754;
  color: #d3e0ff;
}
html[data-theme="dark"] .dashboard-page .message.private_note .message-bubble {
  background: color-mix(in srgb, #8b74ef 12%, var(--surface));
  border-color: color-mix(in srgb, #8b74ef 40%, var(--line));
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .message.private_note .message-author {
  color: #b9a9ff;
}
html[data-theme="dark"] .dashboard-page .message.th-msg .message-bubble {
  background: #2a2a2e;
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .message.th-msg.staff:not(.private_note) .message-bubble {
  background: var(--theme-primary);
  color: #fff;
}
html[data-theme="dark"] .dashboard-page .message.th-msg.staff.is-auto .message-bubble {
  background: color-mix(in srgb, var(--theme-primary) 16%, var(--surface));
  border-color: color-mix(in srgb, var(--theme-primary) 45%, var(--line));
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .message.th-msg.private_note .message-bubble {
  background: color-mix(in srgb, #8b74ef 14%, var(--surface));
  border-color: color-mix(in srgb, #8b74ef 55%, var(--line));
}
html[data-theme="dark"] .dashboard-page .composer-box textarea {
  background: transparent;
}
html[data-theme="dark"] body:not(.widget-page) .composer-box {
  --composer-accent: #7794e9;
}
html[data-theme="dark"] body:not(.widget-page) .composer-box.note-mode {
  --composer-accent: #9b87f5;
  background: color-mix(in srgb, #8b74ef 7%, var(--surface));
  border-color: color-mix(in srgb, #8b74ef 30%, var(--line));
}
html[data-theme="dark"] body:not(.widget-page) .composer-box:focus-within {
  border-color: var(--composer-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--composer-accent) 20%, transparent);
}
html[data-theme="dark"] .dashboard-page .composer-seg {
  background: color-mix(in srgb, var(--ink) 7%, transparent);
}
html[data-theme="dark"] .dashboard-page .composer-seg-thumb {
  background: color-mix(in srgb, var(--ink) 13%, var(--surface));
  box-shadow: 0 1px 2px rgb(0 0 0 / 40%);
}
html[data-theme="dark"] .dashboard-page .composer-tab.active {
  color: var(--ink);
}
html[data-theme="dark"] .dashboard-page .note-mode .composer-audience {
  color: #b9a9ff;
}
html[data-theme="dark"] .dashboard-page .app-shell .composer-box.note-mode .composer-send {
  background: #7357e6;
  border-color: #7357e6;
}
html[data-theme="dark"] .dashboard-page .app-shell .composer-box.note-mode .composer-send:hover {
  background: #6446dc;
  border-color: #6446dc;
}

/* Guided setup uses the same palette without changing geometry or transitions. */
html[data-theme="dark"] .onboarding-wizard {
  --wizard-ink: var(--ink);
  --wizard-muted: var(--muted);
  --wizard-line: var(--line);
}
html[data-theme="dark"]
  .onboarding-wizard
  :is(
    .wizard-step,
    .wizard-kicker,
    .wizard-heading > p,
    .field-help,
    .wizard-fineprint,
    .wizard-skip,
    .wizard-back,
    .website-prefix,
    .website-site-icon,
    .brand-upload-row small,
    .timezone-trigger > svg,
    .timezone-empty,
    .usecase-card small,
    .theme-options label,
    .brand-summary small,
    .brand-summary > span:last-child,
    .installation-card > p,
    .installation-heading svg,
    .setup-recommendation p
  ) {
  color: var(--muted);
}
html[data-theme="dark"]
  .onboarding-wizard
  .website-input
  input:not([type="radio"], [type="color"], [type="file"]) {
  background: transparent;
}
html[data-theme="dark"] .onboarding-wizard .website-input:focus-within {
  border-color: #858585;
  box-shadow: 0 0 0 3px #ffffff12;
}
html[data-theme="dark"] .onboarding-wizard .website-input input:focus {
  box-shadow: none;
}
html[data-theme="dark"] .onboarding-wizard .upload-brand {
  background: var(--soft);
  border-color: var(--theme-info-line);
}
html[data-theme="dark"]
  .onboarding-wizard
  :is(.choice-check, .brand-summary > span:last-child) {
  border-color: var(--line);
}
html[data-theme="dark"]
  body:not(.widget-page)
  #timezone-options
  [role="option"] {
  color: var(--ink);
}
html[data-theme="dark"]
  body:not(.widget-page)
  #timezone-options
  [role="option"]
  small {
  color: var(--muted);
}
html[data-theme="dark"]
  body:not(.widget-page)
  #timezone-options
  [role="option"].active {
  background: var(--menu-hover);
  color: var(--ink);
}
html[data-theme="dark"]
  .onboarding-wizard
  :is(.usecase-card, .platform-card):has(input:checked) {
  border-color: #617ba9;
  background: #233149;
  color: #c5d7ff;
}
html[data-theme="dark"] .onboarding-wizard .choice-icon {
  background: var(--soft);
  border-color: var(--line);
  color: var(--muted);
}
html[data-theme="dark"]
  .onboarding-wizard
  .usecase-card:has(input:checked)
  .choice-icon {
  background: #2b4269;
  border-color: #475f87;
  color: #c6d8ff;
}
html[data-theme="dark"]
  .onboarding-wizard
  .usecase-card:has(input:checked)
  .choice-check {
  background: var(--theme-primary);
  border-color: var(--theme-primary);
}
/* These bundled platform symbols are monochrome, unlike customer-uploaded logos. */
html[data-theme="dark"] .onboarding-wizard .platform-card > img {
  filter: invert(1);
  opacity: 0.85;
}
html[data-theme="dark"] .onboarding-wizard .theme-options > div {
  background: #0c0c0c;
  border-color: var(--line);
}
html[data-theme="dark"]
  .onboarding-wizard
  .theme-options
  label:has(input:checked) {
  background: #333333;
  color: var(--ink);
  box-shadow: 0 1px 3px #00000026;
}
html[data-theme="dark"] .onboarding-wizard .setup-recommendation {
  background: #181818;
  border-color: var(--theme-info-line);
}
html[data-theme="dark"]
  .onboarding-wizard
  :is(.setup-recommendation strong, .setup-recommendation > svg) {
  color: #d4d4d4;
}

/* A dark dashboard must not silently recolor a customer's chosen light preview. */
html[data-theme="dark"] .dashboard-page .widget-preview-stage {
  background: #181b22;
  --widget-preview-canvas: #202631;
  --widget-preview-dot: #414957;
}
html[data-theme="dark"] .dashboard-page .preview-widget:not(.preview-dark) {
  color-scheme: light;
  --ink: #192238;
  --surface: #fff;
  --line: #e0e1e4;
  --muted: #6b7280;
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}
html[data-theme="dark"]
  .dashboard-page
  .preview-widget:not(.preview-dark)
  .avatar {
  color: #636871;
  background: #e4e6ea;
  border-color: var(--line);
}
html[data-theme="dark"] .dashboard-page .preview-widget.preview-dark .avatar {
  color: #b1b4ba;
  background: #2f3237;
  border-color: var(--line);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .preview-widget
  .button.primary {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

/* One quiet preference control, in the same position before and after switching. */
.auth-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.theme-toggle {
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 35px;
  height: 35px;
  min-height: 35px;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.theme-toggle:hover {
  background: var(--menu-hover);
  color: var(--ink);
}
.theme-toggle > svg {
  width: 17px;
  height: 17px;
}
.theme-toggle .theme-sun {
  display: none;
}
html[data-theme="dark"] body:not(.widget-page) .theme-toggle .theme-sun {
  display: block;
}
html[data-theme="dark"] body:not(.widget-page) .theme-toggle .theme-moon {
  display: none;
}
html[data-theme="dark"] body:not(.widget-page) .account-signout {
  color: var(--danger);
}

/* Match dashboard control specificity, including the compact form overrides. */
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  :is(input:not([type="checkbox"]):not([type="radio"]), textarea, select) {
  border-color: var(--line);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  :is(
    input:not([type="checkbox"]):not([type="radio"]),
    textarea,
    select
  ):focus {
  border-color: #858585;
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  input:not([type="checkbox"]):not([type="radio"])[aria-invalid="true"] {
  border-color: var(--danger);
}
html[data-theme="dark"]
  .dashboard-page
  .app-shell:not(.is-setup)
  .profile-footer {
  border-color: var(--line);
}

/* Cover browser autofill paint without hiding values, caret or validity states.
   Separate selectors keep an unknown vendor pseudo-class from dropping both. */
html[data-theme="dark"] body:not(.widget-page) input:autofill {
  background-color: var(--surface) !important;
  color: var(--ink) !important;
  -webkit-text-fill-color: var(--ink) !important;
  caret-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--surface) inset !important;
}
html[data-theme="dark"] body:not(.widget-page) input:-webkit-autofill {
  background-color: var(--surface) !important;
  color: var(--ink) !important;
  -webkit-text-fill-color: var(--ink) !important;
  caret-color: var(--ink);
  box-shadow: 0 0 0 1000px var(--surface) inset !important;
}

/* Count badges: white numbers need the deep primary blue, not the light text blue. */
html[data-theme="dark"] :is(.notification-trigger > span, .nav-count, .today-count) {
  background: var(--theme-primary);
}
