/* Maestro structural token contract.
 *
 * The shared component owns one DOM tree for every visual theme. Every
 * `.mchat-surface` exposes a `::before` texture layer that consumes
 * `--maestro-texture-image`, `--maestro-texture-size`, and
 * `--maestro-texture-opacity`. The layer is decorative, non-interactive,
 * inherits the host radius, and stays behind the host content. Themes change
 * only token values; they never add a texture node or theme-specific markup.
 *
 * Backdrop budget: only the sources panel and login gate aliases may consume
 * a non-none backdrop token. All other visible roles resolve to none, keeping
 * the component at the project maximum of two simultaneous backdrop filters.
 */

:root,
[data-maestro-theme="neumorphic"] {
  /* Material and semantic color */
  --maestro-surface: #e6e9df;
  --maestro-surface-raised: #fafbf7;
  --maestro-surface-sunken: #dde0d3;
  --maestro-surface-accent: linear-gradient(135deg, #dbe64c 0%, #6fbe54 58%, #008c4d 100%);
  --maestro-ink: #0b1426;
  --maestro-ink-soft: #4f4b51;
  --maestro-on-accent: #0b1426;
  --maestro-accent: #008c4d;
  --maestro-status-success: #008c4d;
  --maestro-status-warning: #92400e;
  --maestro-status-danger: #a81616;
  --maestro-mono-ink: #000000;
  --maestro-mono-paper: #ffffff;

  /* Border */
  --maestro-border-color: rgba(0, 31, 62, 0.18);
  --maestro-border-color-strong: rgba(0, 31, 62, 0.42);
  --maestro-border-width: 1px;
  --maestro-border-width-strong: 2px;
  --maestro-border-style: solid;
  --maestro-border-style-emphasis: solid;
  --maestro-border-accent: #008c4d;
  --maestro-border-default: var(--maestro-border-width) var(--maestro-border-style) var(--maestro-border-color);
  --maestro-border-strong: var(--maestro-border-width-strong) var(--maestro-border-style-emphasis) var(--maestro-border-color-strong);

  /* Radius */
  --maestro-radius-none: 0;
  --maestro-radius-sm: 10px;
  --maestro-radius-md: 14px;
  --maestro-radius-lg: 20px;
  --maestro-radius-bubble: 20px;
  --maestro-radius-pill: 999px;

  /* Elevation and focus */
  --maestro-elevation-none: 0 0 0 0 transparent;
  --maestro-elevation-raised: 6px 6px 14px rgba(0, 31, 62, 0.16), -6px -6px 13px rgba(255, 255, 255, 0.58);
  --maestro-elevation-sunken: inset 3px 3px 8px rgba(0, 31, 62, 0.14), inset -3px -3px 7px rgba(255, 255, 255, 0.55);
  --maestro-elevation-floating: 0 12px 28px rgba(0, 31, 62, 0.18), 0 2px 4px rgba(0, 31, 62, 0.08);
  /* Foco canônico: anel de 2px na tinta de acento #005f34 (6,36:1 sobre a
     superfície #e6e9df). O pólen a 58% (#dbe64c) dava ~1,07:1 e sumia.
     Consumidor deve preferir --maestro-focus-outline (outline) a empilhar
     --maestro-elevation-focus como 3.ª box-shadow sobre o relevo. */
  --maestro-focus-color: #005f34;
  --maestro-focus-outline: 2px solid var(--maestro-focus-color);
  --maestro-elevation-focus: 0 0 0 2px var(--maestro-focus-color);
  --maestro-elevation-accent: 0 10px 24px rgba(0, 140, 77, 0.22);

  /* Backdrop */
  --maestro-backdrop-none: none;
  --maestro-backdrop-primary: blur(12px) saturate(110%);
  --maestro-backdrop-secondary: blur(8px) saturate(105%);

  /* Texture */
  --maestro-texture-none: none;
  --maestro-texture-subtle: none;
  --maestro-texture-strong: none;
  --maestro-texture-image: var(--maestro-texture-none);
  --maestro-texture-size: 6px 6px;
  --maestro-texture-opacity: 1;
  --maestro-texture-position: 0 0;
  --maestro-texture-repeat: repeat;
  --maestro-texture-blend: normal;

  /* Mascot asset hooks */
  --maestro-mascot-image: url("/static/brand-kit/maestro/maestro.png?v=90305011c940");
  --maestro-mascot-mask-image: none;
  --maestro-mascot-fill: transparent;

  /* Composer aliases */
  --maestro-composer-surface: var(--maestro-surface-raised);
  --maestro-composer-border: var(--maestro-border-default);
  --maestro-composer-radius: var(--maestro-radius-lg);
  --maestro-composer-elevation: var(--maestro-elevation-sunken);
  --maestro-composer-backdrop: var(--maestro-backdrop-none);
  --maestro-composer-texture: var(--maestro-texture-subtle);

  /* Message bubble aliases */
  --maestro-bubble-surface: var(--maestro-surface-raised);
  --maestro-bubble-surface-accent: var(--maestro-surface-accent);
  --maestro-bubble-border: var(--maestro-border-default);
  --maestro-bubble-border-accent: var(--maestro-border-strong);
  --maestro-bubble-radius: var(--maestro-radius-bubble);
  --maestro-bubble-elevation: var(--maestro-elevation-raised);
  --maestro-bubble-texture: var(--maestro-texture-subtle);

  /* Citation card aliases */
  --maestro-citation-surface: var(--maestro-surface-raised);
  --maestro-citation-border: var(--maestro-border-default);
  --maestro-citation-radius: var(--maestro-radius-sm);
  --maestro-citation-elevation: var(--maestro-elevation-none);
  --maestro-citation-backdrop: var(--maestro-backdrop-none);
  --maestro-citation-texture: var(--maestro-texture-subtle);

  /* Sources panel aliases — backdrop slot one of two */
  --maestro-sources-surface: var(--maestro-surface-raised);
  --maestro-sources-border: var(--maestro-border-strong);
  --maestro-sources-radius: var(--maestro-radius-lg);
  --maestro-sources-elevation: var(--maestro-elevation-floating);
  --maestro-sources-backdrop: var(--maestro-backdrop-secondary);
  --maestro-sources-texture: var(--maestro-texture-subtle);

  /* Model selector aliases */
  --maestro-selector-surface: var(--maestro-surface-raised);
  --maestro-selector-border: var(--maestro-border-default);
  --maestro-selector-border-active: var(--maestro-border-strong);
  --maestro-selector-radius: var(--maestro-radius-sm);
  --maestro-selector-elevation: var(--maestro-elevation-raised);
  --maestro-selector-backdrop: var(--maestro-backdrop-none);
  --maestro-selector-texture: var(--maestro-texture-subtle);

  /* Credit meter aliases */
  --maestro-credit-track: var(--maestro-surface-sunken);
  --maestro-credit-fill: var(--maestro-surface-accent);
  --maestro-credit-border: var(--maestro-border-default);
  --maestro-credit-radius: var(--maestro-radius-pill);
  --maestro-credit-elevation: var(--maestro-elevation-sunken);
  --maestro-credit-texture: var(--maestro-texture-strong);

  /* Login gate aliases — backdrop slot two of two */
  --maestro-gate-surface: var(--maestro-surface-raised);
  --maestro-gate-border: var(--maestro-border-strong);
  --maestro-gate-radius: var(--maestro-radius-lg);
  --maestro-gate-elevation: var(--maestro-elevation-floating);
  --maestro-gate-backdrop: var(--maestro-backdrop-primary);
  --maestro-gate-texture: var(--maestro-texture-subtle);
}

/* ── Escuro ───────────────────────────────────────────────────────────────
   O contrato do componente diz «themes change only token values», mas só o
   tema claro existia: com [data-theme="dark"] as superfícies do shell
   escurecem e o composer, as fichas e o painel do Maestro continuam com a face
   clara (#e6e9df sobre página #04070d).

   A matéria vem da família canônica: a face é --ch-neu-surface-* e o relevo é
   --ch-neu-raised/pressed, que o brand kit redeclara em [data-theme="dark"].
   Só os papéis que o brand kit não tem são escritos aqui, e nenhum valor
   literal novo nasce: cada um aponta para um papel do shell com reserva, para
   a folha continuar servindo a landing, que não carrega o shell do app.

   Contraste (WCAG 2.x, mesma conta de tests/test_maestro_office_a11y_tokens.py):
   tinta #f1f4fb sobre face #142132 = 14,75; apoio #a8b1c2 = 7,53; acento
   #4ed38a = 8,51; foco #4ed38a sobre a face = 8,51 (mínimo 3,0 na 1.4.11). */
[data-theme="dark"] {
  /* Com reserva: a landing carrega esta folha sem o brand kit, e sem o literal
     a face ficaria indefinida (o valor da reserva é o do brand kit no escuro). */
  --maestro-surface: var(--ch-neu-surface, #142132);
  --maestro-surface-raised: var(--ch-neu-surface-raised, #192a3e);
  --maestro-surface-sunken: var(--ch-neu-surface-sunken, #0b1426);
  --maestro-surface-accent: linear-gradient(
    135deg,
    var(--c-pollen, #e8f25c) 0%,
    var(--accent-fg, #4ed38a) 58%,
    color-mix(in srgb, var(--accent-fg, #4ed38a) 62%, var(--ch-neu-shadow-ink, #000)) 100%
  );
  --maestro-ink: var(--fg-strong, #f1f4fb);
  --maestro-ink-soft: var(--fg-muted, #a8b1c2);
  --maestro-on-accent: var(--fg-on-signal, #0b1426);
  --maestro-accent: var(--accent-fg, #4ed38a);
  --maestro-status-success: var(--ok-fg, #4ed38a);
  --maestro-status-warning: var(--c-warn, #fbbf24);
  --maestro-status-danger: var(--color-danger, #f87171);
  /* Em fundo escuro a tinta do monocromático inverte: papel escuro, traço claro. */
  --maestro-mono-ink: var(--fg-strong, #f1f4fb);
  --maestro-mono-paper: var(--ch-neu-surface-sunken, #0b1426);

  --maestro-border-color: var(--line, rgba(255, 255, 255, 0.18));
  --maestro-border-color-strong: var(--line-strong, rgba(255, 255, 255, 0.42));
  --maestro-border-accent: var(--accent-fg, #4ed38a);
  --maestro-border-default: var(--maestro-border-width) var(--maestro-border-style) var(--maestro-border-color);
  --maestro-border-strong: var(--maestro-border-width-strong) var(--maestro-border-style-emphasis) var(--maestro-border-color-strong);

  /* O foco do claro (#005f34) mede 1,02 sobre a face escura e some. Aqui o anel
     é o acento do escuro, 8,51 contra a face. */
  --maestro-focus-color: var(--accent-fg, #4ed38a);
  --maestro-focus-outline: 2px solid var(--maestro-focus-color);
  --maestro-elevation-focus: 0 0 0 2px var(--maestro-focus-color);
  --maestro-elevation-accent: var(
    --ch-neu-raised-tight,
    -4px -4px 10px rgba(255, 255, 255, 0.08),
    5px 5px 12px rgba(0, 0, 0, 0.45)
  );

  /* Profundidade pela matéria canônica: no escuro a lâmpada é quem carrega o
     relevo, porque a matéria já está no piso. */
  --maestro-elevation-raised: var(
    --ch-neu-raised-tight,
    -4px -4px 10px rgba(255, 255, 255, 0.08),
    5px 5px 12px rgba(0, 0, 0, 0.45)
  );
  --maestro-elevation-sunken: var(
    --ch-neu-pressed,
    inset 6px 6px 14px rgba(0, 0, 0, 0.45),
    inset -6px -6px 14px rgba(255, 255, 255, 0.08)
  );
  --maestro-elevation-floating: var(
    --ch-neu-raised,
    -8px -8px 18px rgba(255, 255, 255, 0.08),
    10px 10px 24px rgba(0, 0, 0, 0.45)
  );
  --maestro-elevation-none: 0 0 0 0 transparent;

  --maestro-texture-image: var(--maestro-texture-none);

  --maestro-mascot-image: url("/static/brand-kit/maestro/maestro.png?v=90305011c940");
  --maestro-mascot-mask-image: none;
  --maestro-mascot-fill: transparent;
}

[data-maestro-theme="micrographic"] {
  /* Material and semantic color — consome --maestro-mono-paper e --maestro-mono-ink
     declarados em :root (#ffffff / #000000 no claro) e invertidos em [data-theme="dark"]
     (#0b1426 / #f1f4fb no escuro), sem redeclarar literal por cima do escuro. */
  --maestro-surface: var(--maestro-mono-paper, #ffffff);
  --maestro-surface-raised: var(--maestro-mono-paper, #ffffff);
  --maestro-surface-sunken: var(--maestro-mono-paper, #ffffff);
  --maestro-surface-accent: var(--maestro-mono-ink, #000000);
  --maestro-ink: var(--maestro-mono-ink, #000000);
  --maestro-ink-soft: var(--maestro-mono-ink, #000000);
  --maestro-on-accent: var(--maestro-mono-paper, #ffffff);
  --maestro-accent: var(--maestro-mono-ink, #000000);
  --maestro-status-success: var(--maestro-mono-ink, #000000);
  --maestro-status-warning: var(--maestro-mono-ink, #000000);
  --maestro-status-danger: var(--maestro-mono-ink, #000000);

  /* Border */
  --maestro-border-color: var(--maestro-mono-ink, #000000);
  --maestro-border-color-strong: var(--maestro-mono-ink, #000000);
  --maestro-border-width: 1px;
  --maestro-border-width-strong: 2px;
  --maestro-border-style: solid;
  --maestro-border-style-emphasis: solid;
  --maestro-border-accent: var(--maestro-mono-ink, #000000);
  --maestro-border-default: var(--maestro-border-width) var(--maestro-border-style) var(--maestro-border-color);
  --maestro-border-strong: var(--maestro-border-width-strong) var(--maestro-border-style-emphasis) var(--maestro-border-color-strong);

  /* Radius */
  --maestro-radius-none: 0;
  --maestro-radius-sm: 1px;
  --maestro-radius-md: 2px;
  --maestro-radius-lg: 2px;
  --maestro-radius-bubble: 2px;
  --maestro-radius-pill: 2px;

  /* Elevation and focus */
  --maestro-elevation-none: 0 0 0 0 transparent;
  --maestro-elevation-raised: 0 0 0 0 transparent;
  --maestro-elevation-sunken: 0 0 0 0 transparent;
  --maestro-elevation-floating: 0 0 0 0 transparent;
  --maestro-focus-color: var(--maestro-mono-ink);
  --maestro-focus-outline: 2px solid var(--maestro-focus-color);
  --maestro-elevation-focus: 0 0 0 2px var(--maestro-focus-color);
  --maestro-elevation-accent: 0 0 0 0 transparent;

  /* Backdrop */
  --maestro-backdrop-none: none;
  --maestro-backdrop-primary: none;
  --maestro-backdrop-secondary: none;

  /* Texture */
  --maestro-texture-none: none;
  --maestro-texture-subtle: repeating-linear-gradient(135deg, transparent 0 5px, var(--maestro-mono-ink) 5px 6px);
  --maestro-texture-strong: repeating-linear-gradient(135deg, transparent 0 3px, var(--maestro-mono-ink) 3px 4px);
  --maestro-texture-image: var(--maestro-texture-subtle);
  --maestro-texture-size: 8px 8px;
  --maestro-texture-opacity: 1;
  --maestro-texture-position: 0 0;
  --maestro-texture-repeat: repeat;
  --maestro-texture-blend: normal;

  /* Mascot asset hooks */
  --maestro-mascot-image: none;
  --maestro-mascot-mask-image: url("/static/brand-kit/maestro/maestro-hands.svg?v=4176dbd05488");
  --maestro-mascot-fill: var(--maestro-mono-ink);
}
