/* Semantic theme tokens: colors named by role, not by value.

   Markup and new CSS style against these (Tailwind exposes them as utilities:
   bg-surface, text-fg-muted, border-border, bg-accent… see
   app/assets/tailwind/application.css), never against the concrete brand tokens
   (--dark-3, --on-dark-1) or raw hex. A theme is then just a block that
   redefines these variables.

   Dark is the product default. data-theme="light" flips everything built on
   these tokens inside it: on <html> a whole screen, on an element one block
   (the landing page's light sections). */

/* Accessibility override of the brand's tertiary text on dark (#6A7C84): it
   read 3.6:1 on cards. #8A9CA5 reaches 5.5:1 on cards and 4.6:1 on raised
   surfaces, keeping the same hue. Applies to legacy screens too. */
:root {
  --on-dark-3: #8A9CA5;
}

/* data-theme="dark" brings it back inside a light block (code panels in the docs). */
:root, [data-theme="dark"] {
  --ui-bg:             var(--dark-2);
  --ui-bg-deep:        var(--dark-1);
  --ui-surface:        var(--dark-3);
  --ui-surface-raised: var(--dark-4);
  --ui-border:         var(--dark-4);
  --ui-border-strong:  var(--dark-5);
  /* A form field's outline (ui_input_class). The product keeps the card border;
     the payer's theme raises it to 3:1 (WCAG 1.4.11). Declared in each theme
     block: a var() resolves where it is declared, not where it is used. */
  --ui-border-input:   var(--ui-border);

  --ui-fg-strong: #FFFFFF;
  --ui-fg:        var(--on-dark-1);
  --ui-fg-muted:  var(--on-dark-2);
  --ui-fg-subtle: var(--on-dark-3);

  /* Navy on teal: white on #17C4A3 is 2.2:1, navy is 8:1 (WCAG AA needs 4.5).
     The hover lightens the teal so it keeps that contrast. */
  --ui-accent:       var(--living-teal);
  --ui-accent-hover: #3DD6B8;
  --ui-accent-fg:    var(--deep-core-navy);
  --ui-focus-ring:   rgba(23, 196, 163, 0.18);
  /* Behind an accent-coloured selection (the active filter chip). */
  --ui-accent-soft:  rgba(23, 196, 163, 0.14);
  /* The accent as text or a link: on light grounds teal is too pale to read. */
  --ui-accent-text:  var(--living-teal);

  /* Status: the plain token is the foreground (text, dots, icons), -soft is
     the tinted background behind it. Tuned for contrast on the dark surface. */
  --ui-success:         var(--mint-layer);
  --ui-success-soft:    rgba(23, 196, 163, 0.14);
  --ui-processing:      #94B2D4;
  --ui-processing-soft: rgba(93, 138, 184, 0.18);
  --ui-warning:         #F0BE73;
  --ui-warning-soft:    rgba(219, 162, 76, 0.18);
  --ui-danger:          #F47B82;
  --ui-danger-soft:     rgba(224, 77, 85, 0.18);
  --ui-danger-solid:    var(--danger);

  --ui-radius-control: 10px;
  --ui-radius-card:    14px;

  --ui-shadow-raised:  var(--shadow-dark-1);
  --ui-shadow-overlay: var(--shadow-dark-2);
  --ui-shadow-glow:    var(--shadow-teal-glow);

  /* Dims the page behind a modal (the confirmation dialog's backdrop). */
  --ui-scrim: rgba(5, 15, 20, 0.65);

  /* Behind a Pix QR code: scanners need dark modules on white in any theme. */
  --ui-qr-bg: #FFFFFF;
  /* Behind a merchant's logo (Configurações › Marca), as on the payer's page. */
  --ui-logo-tile: #FFFFFF;

  /* Native controls (checkbox, radio, date picker, scrollbars) follow it. */
  --ui-color-scheme: dark;
}

[data-theme="light"] {
  --ui-bg:             var(--surface-mist);
  --ui-accent-text:    var(--success-dark);
  --ui-bg-deep:        var(--surface-mist);
  --ui-surface:        var(--white);
  --ui-surface-raised: var(--surface-mist);
  --ui-border:         var(--border);
  --ui-border-strong:  var(--text-muted);
  --ui-border-input:   var(--ui-border);

  --ui-fg-strong: var(--text-primary);
  --ui-fg:        var(--text-primary);
  --ui-fg-muted:  var(--text-secondary);
  /* The brand's tertiary (#8FA0A8) reads 2.6:1 on mist; this keeps its hue at 4.5:1. */
  --ui-fg-subtle: #627580;

  --ui-success:         var(--success-dark);
  --ui-success-soft:    var(--success-soft);
  --ui-processing:      var(--processing);
  --ui-processing-soft: var(--processing-soft);
  --ui-warning:         #9A6A1F;
  --ui-warning-soft:    var(--warning-soft);
  --ui-danger:          var(--danger);
  --ui-danger-soft:     var(--danger-soft);

  --ui-shadow-raised:  var(--shadow-1);
  --ui-shadow-overlay: var(--shadow-pop);

  --ui-scrim: rgba(8, 26, 34, 0.45);

  --ui-qr-bg: #FFFFFF;
  --ui-logo-tile: #FFFFFF;

  --ui-color-scheme: light;
}

/* The payer's theme (layouts/billing_portal): the pages a merchant's customer
   opens to pay. They carry the merchant, not Scoby, so the palette is neutral,
   slightly cool, and the accent is the text colour (a dark button with light
   text on light, the reverse on dark): no Scoby teal. States keep their own
   colours. Light by default, dark when the device asks, in CSS alone, so the
   first paint is already right. Every text role reads at 4.5:1 or more on the
   background, the surfaces and the raised surface. */
[data-theme="payer"] {
  --ui-bg:             #F5F6F8;
  --ui-bg-deep:        #ECEEF1;
  --ui-surface:        #FFFFFF;
  --ui-surface-raised: #F0F2F5;
  --ui-border:         #DFE3E8;
  --ui-border-strong:  #C2C9D1;
  /* 3.6:1 on the surface around a field, 3.4:1 on its own fill. */
  --ui-border-input:   #7D8792;

  --ui-fg-strong: #16191D;
  --ui-fg:        #23272C;
  /* Subtle is a visible step lighter than muted, still 4.5:1 on accent-soft. */
  --ui-fg-muted:  #4D5763;
  --ui-fg-subtle: #626C78;

  --ui-accent:       #16191D;
  --ui-accent-hover: #353B43;
  --ui-accent-fg:    #FFFFFF;
  --ui-focus-ring:   rgba(22, 25, 29, 0.18);
  --ui-accent-soft:  #EBEDF0;
  --ui-accent-text:  #16191D;

  --ui-success:         #12764A;
  --ui-success-soft:    #E2F4EA;
  --ui-processing:      #2F5D8C;
  --ui-processing-soft: #E3ECF6;
  --ui-warning:         #7A5200;
  --ui-warning-soft:    #FBF0D4;
  --ui-danger:          #B3261E;
  --ui-danger-soft:     #FBE9E7;
  --ui-danger-solid:    #B3261E;

  --ui-shadow-raised:  var(--shadow-1);
  --ui-shadow-overlay: var(--shadow-pop);
  --ui-shadow-glow:    0 0 #0000;

  --ui-scrim: rgba(22, 25, 29, 0.45);
  --ui-qr-bg: #FFFFFF;
  /* A merchant's logo sits on white in either scheme, so a dark logo never sinks. */
  --ui-logo-tile: #FFFFFF;

  /* The merchant's colour (ProjectBranding::Palette): only on the logo, the main
     button and the chosen option. A branded page overrides these on
     html[data-brand][data-theme=payer] (BrandingHelper#brand_stylesheet_tag), the
     settings preview in a style attribute; without a brand they are the
     neutral accent, so nothing changes. */
  --ui-brand:      var(--ui-accent);
  --ui-on-brand:   var(--ui-accent-fg);
  --ui-brand-text: var(--ui-accent-text);
  --ui-brand-edge: var(--ui-accent);

  --ui-color-scheme: light;
}

/* Dark: when the device asks, unless the page forces light (data-payer-scheme,
   the settings preview of each scheme), and when the page forces dark. The two
   blocks declare the same (test/helpers/payer_theme_css_test.rb). */
@media (prefers-color-scheme: dark) {
  [data-theme="payer"]:not([data-payer-scheme="light"]) {
    --ui-bg:             #0E1216;
    --ui-bg-deep:        #090C0F;
    --ui-surface:        #171C22;
    --ui-surface-raised: #1F252C;
    --ui-border:         #2B323B;
    --ui-border-strong:  #46505C;
    /* 3.7:1 on the surface, 4:1 on a field's fill. */
    --ui-border-input:   #6B7581;

    --ui-fg-strong: #F1F3F5;
    --ui-fg:        #E1E5EA;
    --ui-fg-muted:  #A5AEB9;
    --ui-fg-subtle: #959FAB;

    --ui-accent:       #F1F3F5;
    --ui-accent-hover: #D3D8DE;
    --ui-accent-fg:    #0E1216;
    --ui-focus-ring:   rgba(241, 243, 245, 0.24);
    --ui-accent-soft:  #262C33;
    --ui-accent-text:  #F1F3F5;

    --ui-success:         #5FD39A;
    --ui-success-soft:    #153325;
    --ui-processing:      #9DB9E8;
    --ui-processing-soft: #1A2738;
    --ui-warning:         #F0C36A;
    --ui-warning-soft:    #3A2E12;
    --ui-danger:          #FF9C94;
    --ui-danger-soft:     #3D1B19;
    --ui-danger-solid:    #B3261E;

    --ui-shadow-raised:  var(--shadow-dark-1);
    --ui-shadow-overlay: var(--shadow-dark-2);

    --ui-scrim: rgba(0, 0, 0, 0.6);
    --ui-logo-tile: #FFFFFF;

    /* Declared again: a var() resolves where it is declared. */
    --ui-brand:      var(--ui-accent);
    --ui-on-brand:   var(--ui-accent-fg);
    --ui-brand-text: var(--ui-accent-text);
    --ui-brand-edge: var(--ui-accent);

    --ui-color-scheme: dark;
  }
}

[data-theme="payer"][data-payer-scheme="dark"] {
  --ui-bg:             #0E1216;
  --ui-bg-deep:        #090C0F;
  --ui-surface:        #171C22;
  --ui-surface-raised: #1F252C;
  --ui-border:         #2B323B;
  --ui-border-strong:  #46505C;
  /* 3.7:1 on the surface, 4:1 on a field's fill. */
  --ui-border-input:   #6B7581;

  --ui-fg-strong: #F1F3F5;
  --ui-fg:        #E1E5EA;
  --ui-fg-muted:  #A5AEB9;
  --ui-fg-subtle: #959FAB;

  --ui-accent:       #F1F3F5;
  --ui-accent-hover: #D3D8DE;
  --ui-accent-fg:    #0E1216;
  --ui-focus-ring:   rgba(241, 243, 245, 0.24);
  --ui-accent-soft:  #262C33;
  --ui-accent-text:  #F1F3F5;

  --ui-success:         #5FD39A;
  --ui-success-soft:    #153325;
  --ui-processing:      #9DB9E8;
  --ui-processing-soft: #1A2738;
  --ui-warning:         #F0C36A;
  --ui-warning-soft:    #3A2E12;
  --ui-danger:          #FF9C94;
  --ui-danger-soft:     #3D1B19;
  --ui-danger-solid:    #B3261E;

  --ui-shadow-raised:  var(--shadow-dark-1);
  --ui-shadow-overlay: var(--shadow-dark-2);

  --ui-scrim: rgba(0, 0, 0, 0.6);
  --ui-logo-tile: #FFFFFF;

  /* Declared again: a var() resolves where it is declared. */
  --ui-brand:      var(--ui-accent);
  --ui-on-brand:   var(--ui-accent-fg);
  --ui-brand-text: var(--ui-accent-text);
  --ui-brand-edge: var(--ui-accent);

  --ui-color-scheme: dark;
}

/* Motion only for people who haven't asked to reduce it. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
