/* Dark theme for the CRM workspace, account forms and the Vasilek panel. */
:root[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8edf5;
  --muted: #a4b0c2;
  --blue: #88a9ff;
  --pale: #263653;
  --line: #39485d;
  --bg: #111722;
  --danger: #ff9da6;
  --green: #82d8ad;
  --white: #1c2635;
  --surface-raised: #222e40;
  --surface-inset: #151e2b;
  --surface-hover: #2a3850;
  --surface-selected: #263653;
}

html[data-theme="dark"] body { background: var(--bg); color: var(--ink); }
html[data-theme="dark"] a { color: #a9c0ff; }
html[data-theme="dark"] ::selection { color: #fff; background: #4568b8; }

html[data-theme="dark"] button:not(.primary) {
  color: var(--ink);
  border-color: var(--line);
  background-color: var(--surface-raised);
}
html[data-theme="dark"] button:not(.primary):not(.text):hover { background: var(--surface-hover); }
html[data-theme="dark"] button.text,
html[data-theme="dark"] .nav-button,
html[data-theme="dark"] .mobile-nav button,
html[data-theme="dark"] .organization-room-open {
  color: var(--blue);
  border-color: transparent;
  background: transparent;
}
html[data-theme="dark"] button.secondary,
html[data-theme="dark"] .nav-button.active,
html[data-theme="dark"] .mobile-nav button.active,
html[data-theme="dark"] .tabs [aria-pressed="true"],
html[data-theme="dark"] .stat[aria-pressed="true"],
html[data-theme="dark"] .master-org-filters button.selected,
html[data-theme="dark"] .organization-room-filters button.selected,
html[data-theme="dark"] .organization-back {
  color: #b4c8ff;
  border-color: transparent;
  background: var(--pale);
}
html[data-theme="dark"] input,
html[data-theme="dark"] select,
html[data-theme="dark"] textarea {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-inset);
}
html[data-theme="dark"] input::placeholder,
html[data-theme="dark"] textarea::placeholder { color: #8997ac; }
html[data-theme="dark"] .auth,
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .queue-list,
html[data-theme="dark"] .detail,
html[data-theme="dark"] .surface,
html[data-theme="dark"] .notification,
html[data-theme="dark"] .account-row,
html[data-theme="dark"] .account-dialog,
html[data-theme="dark"] .account-table-wrap,
html[data-theme="dark"] .organization-share,
html[data-theme="dark"] .organization-requisites-group,
html[data-theme="dark"] .organization-room-row,
html[data-theme="dark"] .organization-room-card,
html[data-theme="dark"] .room-device-attachment,
html[data-theme="dark"] .master-org-action-menu,
html[data-theme="dark"] .master-category-create,
html[data-theme="dark"] .master-category-row,
html[data-theme="dark"] .master-category-archive {
  color: var(--ink);
  border-color: var(--line);
  background: var(--white);
}
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .mobile-nav { background: #171f2d; }
html[data-theme="dark"] .topbar { color: var(--muted); }
html[data-theme="dark"] .branding-preview,
html[data-theme="dark"] .master-org-create-form,
html[data-theme="dark"] .master-org-metric,
html[data-theme="dark"] .room-device-form,
html[data-theme="dark"] .account-table th,
html[data-theme="dark"] .account-one-time-password,
html[data-theme="dark"] .reset-code,
html[data-theme="dark"] .policy,
html[data-theme="dark"] .master-org-overview-note {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-raised);
}
html[data-theme="dark"] .ticket-row { color: var(--ink); background: var(--white); }
html[data-theme="dark"] .ticket-row.selected,
html[data-theme="dark"] .notification.unread,
html[data-theme="dark"] .code,
html[data-theme="dark"] .master-org-item.selected { color: var(--ink); background: var(--surface-selected); }
html[data-theme="dark"] .master-org-item { color: var(--ink); border-color: var(--line); background: var(--white); }
html[data-theme="dark"] .master-org-item:hover { background: var(--surface-hover); }
html[data-theme="dark"] .badge { color: #c5d4f3; background: #303d53; }
html[data-theme="dark"] .master-organization-workspace .badge.active,
html[data-theme="dark"] .pill.resolved,
html[data-theme="dark"] .pill.closed,
html[data-theme="dark"] .receipt {
  color: #a3e6c3;
  background: #1e3a32;
}
html[data-theme="dark"] .master-organization-workspace .badge.archive,
html[data-theme="dark"] .pill { color: #c0c9d8; background: #303a4a; }
html[data-theme="dark"] .pill.in_progress,
html[data-theme="dark"] .pill.queued { color: #b6caff; background: #293b5c; }
html[data-theme="dark"] .pill.needs_info,
html[data-theme="dark"] .pill.waiting,
html[data-theme="dark"] .connection,
html[data-theme="dark"] .message.internal,
html[data-theme="dark"] .agent-approval {
  color: #f1d28c;
  border-color: #6b5832;
  background: #382f20;
}
html[data-theme="dark"] .notice { color: var(--ink); border-color: #445b83; background: #202d43; }
html[data-theme="dark"] .notice.error { color: #ffc1c6; border-color: #76434a; background: #38252c; }
html[data-theme="dark"] .receipt { border-color: #365b49; }
html[data-theme="dark"] .account-menu-icon i { background: var(--ink); }
html[data-theme="dark"] .account-action-menu,
html[data-theme="dark"] .account-table .account-actions .account-menu-trigger,
html[data-theme="dark"] .account-table .account-actions .account-action-menu button,
html[data-theme="dark"] .account-edit-form input,
html[data-theme="dark"] .room-device-form input,
html[data-theme="dark"] .room-device-form textarea,
html[data-theme="dark"] .room-device-form input[type="file"],
html[data-theme="dark"] #ticket-form #contact-section input {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface-inset);
}
html[data-theme="dark"] .account-action-menu button.danger,
html[data-theme="dark"] button.danger { color: var(--danger); }
html[data-theme="dark"] .account-dialog-backdrop { background: rgb(0 0 0 / 72%); }
html[data-theme="dark"] #ticket-form #contact-section {
  border-color: var(--line);
  background: var(--surface-raised);
}
html[data-theme="dark"] .room-device-thumbnail,
html[data-theme="dark"] .room-device-file-badge { background: #303a4a; }
html[data-theme="dark"] .overdue { color: #ff9da6 !important; }

html[data-theme="dark"] .agent-chat-shell,
html[data-theme="dark"] .agent-message,
html[data-theme="dark"] .agent-composer,
html[data-theme="dark"] .agent-history-item:hover,
html[data-theme="dark"] .agent-history-item.active {
  color: var(--ink);
  border-color: var(--line);
  background: var(--white);
}
html[data-theme="dark"] .agent-chat-side { background: #171f2d; }
html[data-theme="dark"] .agent-message-list { background: var(--surface-inset); }
html[data-theme="dark"] .agent-message.user { border-color: #41577e; background: #263653; }
html[data-theme="dark"] .agent-attachment { border-color: var(--line); background: #2a3547; color: var(--ink); }
html[data-theme="dark"] .agent-model-badge,
html[data-theme="dark"] .agent-service-state { color: #b8cbff; background: var(--pale); }
html[data-theme="dark"] .agent-service-state.offline,
html[data-theme="dark"] .agent-error { color: #ffadb4; background: #38252c; }
html[data-theme="dark"] .agent-tool-state { color: #8be0b4; }

.topbar-actions { display: flex; align-items: center; gap: 8px; }
.theme-toggle { display: inline-flex; align-items: center; justify-content: center; gap: 7px; min-height: 38px; padding: 6px 9px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.theme-toggle-icon { font-size: 16px; line-height: 1; }
.auth-utilities { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 10px; }
.auth-utilities #auth-retry { margin: 0; }
.auth-theme-toggle .theme-toggle-label { display: none; }
@media(max-width:800px) {
  .topbar-actions { gap: 2px; }
  .topbar .theme-toggle { padding: 6px 7px; }
  .topbar .theme-toggle-label { display: none; }
  .auth-utilities .theme-toggle-label { display: none; }
}


/* Accessible dark mode action colors */
html[data-theme="dark"] button.primary {
  color: #fff;
  border-color: #3c5fb8;
  background: #3c5fb8;
}
html[data-theme="dark"] .theme-toggle {
  color: var(--muted);
  border-color: transparent;
  background: transparent;
}
html[data-theme="dark"] .theme-toggle:hover { background: var(--surface-hover); }

/* High-contrast selection controls in dark mode. */
html[data-theme="dark"] select {
  color: #f3f6ff;
  color-scheme: dark;
  border-color: #657995;
  background-color: #202d41;
}
html[data-theme="dark"] select option {
  color: #e8edf5;
  background-color: #1c2635;
}
html[data-theme="dark"] select option:checked {
  color: #fff;
  background-color: #3f65b6;
}
html[data-theme="dark"] select option:disabled {
  color: #9aa8bc;
}
html[data-theme="dark"] select:focus-visible {
  border-color: #a8c0ff;
  outline-color: #88a9ff;
  box-shadow: 0 0 0 2px rgb(136 169 255 / 24%);
}
html[data-theme="dark"] select:has(> option:checked:not([value=""])) {
  border-color: #7898d7;
  background-color: #263853;
}
