/*
 * Final design-system firewall for legacy surfaces.
 *
 * The application still keeps its original DOM and event handlers. This file is
 * loaded last so an old inline background cannot reappear while a module opens,
 * switches state or is rendered by a delayed request.
 */

body.has-redesign-ui :where(
  .license-gate,
  .license-card,
  .auth-panel,
  .legal-modal,
  .legal-dialog,
  .widget-name-modal,
  .widget-name-dialog,
  .widget-context-menu,
  .mobile-tab-rail,
  .mobile-side-rail,
  .project-composition-workspace,
  .project-composition-dialog,
  .mail-client-shell,
  .mail-compose-panel,
  .internal-chat-shell,
  .internal-chat-dialog
) {
  font-family: "Segoe UI Variable", "Segoe UI", Arial, sans-serif;
}

/* Activation is an application state, not a visually separate product. */
body.has-redesign-ui .license-gate {
  z-index: 15000;
  padding: clamp(18px, 4vw, 48px);
  background:
    radial-gradient(circle at 50% 4%, color-mix(in srgb, var(--mayak-color-accent) 8%, transparent), transparent 32%),
    var(--mayak-color-canvas);
  color: var(--mayak-color-text);
}

body.has-redesign-ui .license-card {
  width: min(520px, 100%);
  padding: clamp(24px, 4vw, 40px);
  border: 1px solid var(--mayak-color-border);
  border-radius: 24px;
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
  box-shadow: var(--redesign-shadow-strong);
}

body.has-redesign-ui .license-logo {
  width: 76px;
  height: 76px;
  margin-bottom: 18px;
  border: 0;
  border-radius: 20px;
  background-color: var(--mayak-color-surface-soft);
  box-shadow: 0 12px 30px color-mix(in srgb, var(--mayak-color-accent) 18%, transparent);
}

body.has-redesign-ui .license-title,
body.has-redesign-ui .license-pane-title {
  color: var(--mayak-color-text);
  letter-spacing: -.035em;
}

body.has-redesign-ui .license-subtitle,
body.has-redesign-ui .license-note {
  color: var(--mayak-color-muted);
}

body.has-redesign-ui .license-pane.is-open {
  gap: 10px;
}

body.has-redesign-ui :where(.license-primary-button, .license-secondary-button, .license-input) {
  min-height: 48px;
  border-radius: var(--mayak-radius-md);
  font: inherit;
}

body.has-redesign-ui .license-primary-button {
  border: 1px solid var(--mayak-color-accent);
  background: var(--mayak-color-accent);
  color: #fff;
  box-shadow: none;
}

body.has-redesign-ui .license-secondary-button {
  border: 1px solid var(--mayak-color-border);
  background: var(--mayak-color-surface-soft);
  color: var(--mayak-color-text);
}

body.has-redesign-ui :where(.license-primary-button, .license-secondary-button):hover {
  transform: none;
  border-color: var(--mayak-color-accent);
}

body.has-redesign-ui .license-secondary-button:hover {
  background: var(--mayak-color-accent-soft);
  color: var(--mayak-color-accent);
}

body.has-redesign-ui .license-input {
  border: 1px solid var(--mayak-color-border);
  background: var(--redesign-input);
  color: var(--mayak-color-text);
  text-align: left;
}

body.has-redesign-ui .license-input::placeholder {
  color: var(--mayak-color-muted);
}

body.has-redesign-ui .license-input:focus {
  border-color: var(--mayak-color-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mayak-color-accent) 16%, transparent);
}

body.has-redesign-ui .license-back-button {
  min-height: 36px;
  color: var(--mayak-color-accent);
  text-decoration: none;
}

body.has-redesign-ui .license-note.is-error {
  color: var(--mayak-color-danger);
}

body.has-redesign-ui .license-note.is-success {
  color: var(--mayak-color-success);
}

/* Original account forms remain as functional fallbacks and match the shell. */
body.has-redesign-ui :where(.auth-panel, .company-suggestions, .mail-connect-section) {
  border-color: var(--mayak-color-border);
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
  box-shadow: none;
}

body.has-redesign-ui :where(.auth-title, .widget-name-title, .mail-connect-section-title) {
  color: var(--mayak-color-text);
  letter-spacing: normal;
  text-transform: none;
}

body.has-redesign-ui :where(.auth-field, .account-type-preview, .auth-note, .mail-connect-check, .company-admin-summary) {
  color: var(--mayak-color-muted);
  letter-spacing: normal;
  text-transform: none;
}

body.has-redesign-ui :where(.auth-input, .account-type-button, .auth-consent) {
  border-color: var(--mayak-color-border);
  background: var(--redesign-input);
  color: var(--mayak-color-text);
}

body.has-redesign-ui .account-type-button.is-active,
body.has-redesign-ui .version-switch .main-button.is-active {
  border-color: var(--mayak-color-accent);
  background: var(--mayak-color-accent-soft);
  color: var(--mayak-color-accent);
  box-shadow: none;
}

body.has-redesign-ui .company-suggestion {
  border-color: var(--mayak-color-border);
  color: var(--mayak-color-text);
}

body.has-redesign-ui .company-suggestion:hover {
  background: var(--redesign-hover);
}

/* Every overlay uses the same depth and remains theme-aware. */
body.has-redesign-ui :where(.legal-modal, .widget-name-modal) {
  background: var(--redesign-overlay);
  backdrop-filter: blur(4px);
}

body.has-redesign-ui :where(.legal-dialog, .widget-name-dialog, .project-composition-dialog) {
  border: 1px solid var(--mayak-color-border);
  border-radius: 18px;
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
  box-shadow: var(--redesign-shadow-strong);
}

body.has-redesign-ui :where(.widget-name-actions, .legal-actions) {
  gap: 8px;
}

/* Context menus no longer fall back to the former navy command palette. */
body.has-redesign-ui .widget-context-menu {
  min-width: 210px;
  overflow: hidden;
  padding: 6px;
  border: 1px solid var(--mayak-color-border);
  border-radius: 13px;
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
  box-shadow: var(--redesign-shadow-strong);
}

body.has-redesign-ui .widget-context-menu button {
  min-height: 38px;
  padding: 8px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--mayak-color-text);
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  text-align: left;
}

body.has-redesign-ui .widget-context-menu button:hover:not(:disabled) {
  background: var(--redesign-hover);
  color: var(--mayak-color-accent);
}

body.has-redesign-ui .widget-context-menu button:disabled {
  color: var(--mayak-color-muted);
}

/* The compact/mobile rails are the same navigation at a different density. */
@media (max-width: 760px) {
  body.has-redesign-ui {
    background: var(--mayak-color-canvas);
  }

  body.has-redesign-ui :where(.mobile-tab-rail, .mobile-side-rail) {
    border-color: var(--mayak-color-border);
    background: var(--mayak-color-surface);
    color: var(--mayak-color-text);
    box-shadow: var(--mayak-shadow);
  }
}

/* Project composition: grouped tools, calmer hierarchy, unchanged handlers. */
body.has-redesign-ui .project-composition-workspace {
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
}

body.has-redesign-ui .project-composition-tools {
  padding: 9px 12px 8px;
  background: var(--mayak-color-surface-soft);
}

body.has-redesign-ui .project-composition-toolbar {
  max-height: none;
  display: flex;
  flex-wrap: nowrap;
  align-items: stretch;
  gap: 8px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1px 2px 5px;
  scrollbar-gutter: stable;
}

body.has-redesign-ui .project-composition-toolbar-group {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 5px;
  min-height: 44px;
  padding: 4px;
  border: 1px solid var(--mayak-color-border);
  border-radius: 11px;
  background: var(--mayak-color-surface);
}

body.has-redesign-ui .project-composition-toolbar-group .project-composition-button,
body.has-redesign-ui .project-composition-toolbar-group select {
  min-height: 34px;
  margin: 0;
  border-radius: 8px;
}

body.has-redesign-ui .project-composition-toolbar-group.is-structure .project-composition-button:not(.is-danger, .is-urgent) {
  border-color: transparent !important;
  background: transparent !important;
}

body.has-redesign-ui .project-composition-table-shell {
  background: var(--mayak-color-surface);
  scrollbar-color: var(--mayak-color-border) transparent;
}

body.has-redesign-ui .project-composition-table {
  font-family: inherit;
  font-size: 12px;
}

body.has-redesign-ui .project-composition-table :where(th, td) {
  border-color: var(--mayak-color-border);
}

body.has-redesign-ui .project-composition-operation-menu,
body.has-redesign-ui .project-composition-operation-picker {
  border-color: var(--mayak-color-border);
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
}

/* Correspondence surfaces stay consistent during empty/loading/compose states. */
body.has-redesign-ui :where(.mail-client-shell, .mail-compose-panel, .internal-chat-shell, .internal-chat-dialog) {
  border-color: var(--mayak-color-border);
  background: var(--mayak-color-surface);
  color: var(--mayak-color-text);
}

body.has-redesign-ui :where(.mail-client-toolbar, .internal-chat-conversation-head, .internal-chat-composer) {
  border-color: var(--mayak-color-border);
  background: var(--mayak-color-surface);
}

body.has-redesign-ui :where(.mail-client-search, .mail-compose-input, .mail-compose-text, .internal-chat-search, .internal-chat-composer textarea) {
  border-color: var(--mayak-color-border);
  background: var(--redesign-input);
  color: var(--mayak-color-text);
}

body.has-redesign-ui :where(.mail-message-meta, .mail-message-date, .internal-chat-conversation-head p) {
  color: var(--mayak-color-muted);
}

@media (max-width: 980px) {
  body.has-redesign-ui .project-composition-head {
    grid-template-columns: minmax(0, 1fr) minmax(190px, 300px) !important;
  }
}

@media (max-width: 620px) {
  body.has-redesign-ui .license-card {
    padding: 24px 18px;
    border-radius: 18px;
  }

  body.has-redesign-ui .project-composition-head {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  body.has-redesign-ui :where(.license-primary-button, .license-secondary-button) {
    transition: none;
  }
}
