/* ==========================================================================
   Coferpol Design Tokens & Icon Engine
   Modern Web Guidance: color, dark-mode, typography, icons, css
   ========================================================================== */

@layer tokens {
  :root {
    color-scheme: light dark;

    /* ----------------------------------------------------------------------
       Tier 1: Paleta Industrial Coferpol — Preto, Grafite & Carmim
       ---------------------------------------------------------------------- */
    --raw-crimson-600: #c81018;
    --raw-crimson-700: #a10c13;
    --raw-crimson-400: #ff5c62;
    --raw-crimson-300: #ff858a;

    --raw-steel-50: #e5e5e7;
    --raw-steel-100: #dcdce0;
    --raw-steel-200: #c8c8ce;
    --raw-steel-300: #a1a1aa;
    --raw-steel-500: #52525b;
    --raw-steel-600: #3f3f46;
    --raw-steel-700: #27272a;
    --raw-steel-800: #161618;
    --raw-steel-900: #0b0b0d;
    --raw-steel-950: #050506;

    --raw-emerald-600: #157337;
    --raw-emerald-400: #4ade80;
    --raw-error-light: #b91c1c;
    --raw-error-dark: #fca5a5;
    --raw-error-bg-light: #fef2f2;
    --raw-error-bg-dark: #3b1215;

    /* ----------------------------------------------------------------------
       Tier 2: Tokens Semânticos (Preto & Grafite + Grafite Claro no Light)
       ---------------------------------------------------------------------- */
    --surface-page: var(--raw-steel-50);
    --surface-card: var(--raw-steel-50);
    --surface-elevated: var(--raw-steel-100);
    --surface-media-stage: #121316;
    --surface-header: rgba(229, 229, 231, 0.94);
    --surface-footer: #09090b;
    --surface-footer-deep: #040405;

    --ink-primary: #09090b;
    --ink-secondary: #27272a;
    --ink-muted: #52525b;
    --ink-on-accent: #ffffff;
    --ink-on-dark: #f4f4f5;
    --ink-on-dark-muted: #d4d4d8;

    --accent: var(--raw-crimson-600);
    --accent-hover: var(--raw-crimson-700);
    --accent-soft: color-mix(in oklab, var(--raw-crimson-600) 11%, transparent);

    --border-subtle: rgba(255, 255, 255, 0.72);
    --border-hairline: rgba(161, 161, 170, 0.34);
    --border-strong: #52525b; /* Contraste >= 3:1 em UI controls (WCAG 1.4.11) */
    --focus-ring: #2563eb;

    --state-error: var(--raw-error-light);
    --state-error-bg: var(--raw-error-bg-light);
    --state-valid: var(--raw-emerald-600);

    --scrollbar-track: #dcdce0;
    --scrollbar-thumb: #52525b;

    /* Sombras Soft-Steel Extrudadas e Rebaixadas Neutras */
    --neu-extrude:
      -8px -8px 18px rgba(255, 255, 255, 0.88),
      8px 8px 18px rgba(160, 160, 168, 0.72);
    --neu-extrude-sm:
      -4px -4px 10px rgba(255, 255, 255, 0.88),
      4px 4px 10px rgba(160, 160, 168, 0.66);
    --neu-inset:
      inset 4px 4px 8px rgba(160, 160, 168, 0.78),
      inset -4px -4px 8px rgba(255, 255, 255, 0.9);
    --neu-inset-soft:
      inset 3px 3px 6px rgba(164, 164, 172, 0.8),
      inset -3px -3px 6px rgba(255, 255, 255, 0.9);
    --neu-cta:
      -4px -4px 10px rgba(255, 255, 255, 0.8),
      6px 6px 14px rgba(180, 18, 25, 0.36);
    --header-shadow: 0 4px 16px rgba(160, 160, 168, 0.45);

    /* Tipografia */
    --font-display: "Barlow Semi Condensed", "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", monospace;

    /* Escalas de Espaçamento, Raios e Sombras */
    --container-max: 78rem;
    --gutter: clamp(1rem, 3vw, 2.25rem);
    --radius-sm: 0.5rem;
    --radius-md: 0.95rem;
    --radius-lg: 1.25rem;
    --radius-pill: 999rem;

    --shadow-sm: var(--neu-extrude-sm);
    --shadow-md: var(--neu-extrude);
    --shadow-lg: 0 24px 50px -12px rgba(14, 19, 25, 0.28);

    /* Duração de transição padrão */
    --ease-out: cubic-bezier(0.22, 1, 0.36, 1);

    /* Scrollbar e Accent nativo */
    accent-color: var(--accent);
    scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);

    /* Ícones Inline SVG Data URI */
    --icon-style-size: 1em;
    --icon-style-spacing: 0.45em;
    --icon-sun: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v2M12 20v2M4.93 4.93l1.41 1.41M17.66 17.66l1.41 1.41M2 12h2M20 12h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41'/%3E%3C/svg%3E");
    --icon-moon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M12 3a6 6 0 0 0 9 9 9 9 0 1 1-9-9Z'/%3E%3C/svg%3E");
    --icon-phone: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z'/%3E%3C/svg%3E");
    --icon-whatsapp: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpath d='M12.04 2C6.58 2 2.13 6.45 2.13 11.91c0 1.75.46 3.45 1.32 4.95L2.05 22l5.25-1.38c1.45.79 3.08 1.21 4.74 1.21 5.46 0 9.91-4.45 9.91-9.91C21.95 6.45 17.5 2 12.04 2m5.79 14.12c-.24.68-1.41 1.3-1.95 1.38-.51.07-1.16.1-1.87-.12-.44-.14-1-.33-1.71-.64-3.01-1.3-4.97-4.32-5.12-4.52-.15-.2-1.22-1.63-1.22-3.1s.77-2.2 1.05-2.5c.28-.3.6-.37.8-.37s.4 0 .57.01c.18.01.43-.07.67.51.24.6.84 2.05.91 2.2.07.15.12.32.02.52-.1.2-.15.32-.3.5-.15.17-.32.39-.45.52-.15.15-.31.32-.13.62.18.3.78 1.29 1.68 2.09 1.15 1.03 2.12 1.35 2.42 1.5.3.15.48.13.65-.07.18-.2.75-.87.95-1.17.2-.3.4-.25.67-.15.27.1 1.74.82 2.04.97.3.15.5.22.57.35.08.13.08.73-.16 1.41Z'/%3E%3C/svg%3E");
    --icon-arrow-right: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M5 12h14'/%3E%3Cpath d='m12 5 7 7-7 7'/%3E%3C/svg%3E");
    --icon-arrow-left: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='m12 19-7-7 7-7'/%3E%3C/svg%3E");
    --icon-menu: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M4 7h16M4 12h16M4 17h16'/%3E%3C/svg%3E");
    --icon-close: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round'%3E%3Cpath d='M18 6 6 18M6 6l12 12'/%3E%3C/svg%3E");
    --icon-chevron-down: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    --icon-external: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M15 3h6v6'/%3E%3Cpath d='M10 14 21 3'/%3E%3Cpath d='M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6'/%3E%3C/svg%3E");
    --icon-map-pin: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 10c0 6-8 12-8 12s-8-6-8-12a8 8 0 0 1 16 0Z'/%3E%3Ccircle cx='12' cy='10' r='3'/%3E%3C/svg%3E");
    --icon-mail: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect width='20' height='16' x='2' y='4' rx='2'/%3E%3Cpath d='m22 7-8.97 5.7a1.94 1.94 0 0 1-2.06 0L2 7'/%3E%3C/svg%3E");
    --icon-check: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
    --icon-roof: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M3 10.5 12 3l9 7.5'/%3E%3Cpath d='M5 9.5V20h14V9.5'/%3E%3Cpath d='M9 20v-6h6v6'/%3E%3C/svg%3E");
    --icon-truck: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2'/%3E%3Cpath d='M15 18H9'/%3E%3Cpath d='M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.624l-3.48-4.35A1 1 0 0 0 17.52 8H14'/%3E%3Ccircle cx='17' cy='18' r='2'/%3E%3Ccircle cx='7' cy='18' r='2'/%3E%3C/svg%3E");
    --icon-factory: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2 20a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2V8l-7 5V8l-7 5V4a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z'/%3E%3Cpath d='M17 18h1'/%3E%3Cpath d='M12 18h1'/%3E%3Cpath d='M7 18h1'/%3E%3C/svg%3E");
    --icon-play: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='black'%3E%3Cpolygon points='6 3 20 12 6 21 6 3'/%3E%3C/svg%3E");
    --icon-quote: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='3' width='16' height='18' rx='2'/%3E%3Cpath d='M8 7h8M8 11h8M8 15h4'/%3E%3C/svg%3E");
  }

  /* Controle manual do Switch Claro / Escuro */
  :root[data-theme="light"] {
    color-scheme: light;
  }

  :root[data-theme="dark"] {
    color-scheme: dark;
  }

  /* Fallback explícito para navegadores sem light-dark() ou dark manual (Preto & Grafite) */
  @media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
      --surface-page: var(--raw-steel-900);
      --surface-card: var(--raw-steel-800);
      --surface-elevated: #111113;
      --surface-media-stage: #121316;
      --surface-header: rgba(11, 11, 13, 0.94);

      --ink-primary: #f4f4f5;
      --ink-secondary: #d4d4d8;
      --ink-muted: #a1a1aa;

      --accent: var(--raw-crimson-400);
      --accent-hover: var(--raw-crimson-300);
      --accent-soft: rgba(255, 92, 98, 0.16);

      --border-subtle: rgba(255, 255, 255, 0.08);
      --border-hairline: rgba(255, 255, 255, 0.12);
      --border-strong: #71717a;
      --focus-ring: #60a5fa;

      --state-error: var(--raw-error-dark);
      --state-error-bg: var(--raw-error-bg-dark);
      --state-valid: var(--raw-emerald-400);

      --scrollbar-track: #111113;
      --scrollbar-thumb: #52525b;

      --neu-extrude:
        -6px -6px 14px rgba(255, 255, 255, 0.04),
        8px 8px 18px rgba(0, 0, 0, 0.78);
      --neu-extrude-sm:
        -4px -4px 10px rgba(255, 255, 255, 0.035),
        5px 5px 12px rgba(0, 0, 0, 0.68);
      --neu-inset:
        inset 4px 4px 9px rgba(0, 0, 0, 0.82),
        inset -3px -3px 8px rgba(255, 255, 255, 0.04);
      --neu-inset-soft:
        inset 3px 3px 6px rgba(0, 0, 0, 0.78),
        inset -3px -3px 6px rgba(255, 255, 255, 0.05);
      --neu-cta:
        -3px -3px 8px rgba(255, 255, 255, 0.05),
        6px 6px 14px rgba(0, 0, 0, 0.72);
      --header-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);

      --shadow-sm: var(--neu-extrude-sm);
      --shadow-md: var(--neu-extrude);
      --shadow-lg: 0 24px 50px -12px rgba(0, 0, 0, 0.8);
    }
  }

  :root[data-theme="dark"] {
    --surface-page: var(--raw-steel-900);
    --surface-card: var(--raw-steel-800);
    --surface-elevated: #111113;
    --surface-media-stage: #121316;
    --surface-header: rgba(11, 11, 13, 0.94);

    --ink-primary: #f4f4f5;
    --ink-secondary: #d4d4d8;
    --ink-muted: #a1a1aa;

    --accent: var(--raw-crimson-400);
    --accent-hover: var(--raw-crimson-300);
    --accent-soft: rgba(255, 92, 98, 0.16);

    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-hairline: rgba(255, 255, 255, 0.12);
    --border-strong: #71717a;
    --focus-ring: #60a5fa;

    --state-error: var(--raw-error-dark);
    --state-error-bg: var(--raw-error-bg-dark);
    --state-valid: var(--raw-emerald-400);

    --scrollbar-track: #111113;
    --scrollbar-thumb: #52525b;

    --neu-extrude:
      -6px -6px 14px rgba(255, 255, 255, 0.04),
      8px 8px 18px rgba(0, 0, 0, 0.78);
    --neu-extrude-sm:
      -4px -4px 10px rgba(255, 255, 255, 0.035),
      5px 5px 12px rgba(0, 0, 0, 0.68);
    --neu-inset:
      inset 4px 4px 9px rgba(0, 0, 0, 0.82),
      inset -3px -3px 8px rgba(255, 255, 255, 0.04);
    --neu-inset-soft:
      inset 3px 3px 6px rgba(0, 0, 0, 0.78),
      inset -3px -3px 6px rgba(255, 255, 255, 0.05);
    --neu-cta:
      -3px -3px 8px rgba(255, 255, 255, 0.05),
      6px 6px 14px rgba(0, 0, 0, 0.72);
    --header-shadow: 0 4px 18px rgba(0, 0, 0, 0.55);

    --shadow-sm: var(--neu-extrude-sm);
    --shadow-md: var(--neu-extrude);
    --shadow-lg: 0 24px 50px -12px rgba(0, 0, 0, 0.8);
  }

  /* Versão nativa com light-dark() quando suportada (responde a color-scheme e switch) */
  @supports (color: light-dark(white, black)) {
    :root {
      --surface-page: light-dark(var(--raw-steel-50), var(--raw-steel-900));
      --surface-card: light-dark(var(--raw-steel-50), var(--raw-steel-800));
      --surface-elevated: light-dark(var(--raw-steel-100), #111113);
      --surface-media-stage: light-dark(#121316, #121316);
      --surface-header: light-dark(rgba(229, 229, 231, 0.94), rgba(11, 11, 13, 0.94));

      --ink-primary: light-dark(#09090b, #f4f4f5);
      --ink-secondary: light-dark(#27272a, #d4d4d8);
      --ink-muted: light-dark(#52525b, #a1a1aa);

      --accent: light-dark(var(--raw-crimson-600), var(--raw-crimson-400));
      --accent-hover: light-dark(var(--raw-crimson-700), var(--raw-crimson-300));
      --accent-soft: light-dark(rgba(200, 16, 24, 0.1), rgba(255, 92, 98, 0.16));

      --border-subtle: light-dark(rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.08));
      --border-hairline: light-dark(rgba(161, 161, 170, 0.34), rgba(255, 255, 255, 0.12));
      --border-strong: light-dark(#52525b, #71717a);
      --focus-ring: light-dark(#2563eb, #60a5fa);

      --state-error: light-dark(var(--raw-error-light), var(--raw-error-dark));
      --state-error-bg: light-dark(var(--raw-error-bg-light), var(--raw-error-bg-dark));
      --state-valid: light-dark(var(--raw-emerald-600), var(--raw-emerald-400));

      --scrollbar-track: light-dark(#dcdce0, #111113);
      --scrollbar-thumb: light-dark(#52525b, #52525b);
    }
  }
}

/* Fallback WebKit para scrollbar-color */
@supports not (scrollbar-color: auto) {
  :root::-webkit-scrollbar {
    width: 12px;
    height: 12px;
  }
  :root::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
  :root::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 6px;
    border: 2px solid var(--scrollbar-track);
  }
}

/* ==========================================================================
   Motor de Ícones CSS (Modern Web Guidance: icons)
   ========================================================================== */
@property --icon-start {
  syntax: "*";
  inherits: false;
}

@property --icon-end {
  syntax: "*";
  inherits: false;
}

@container style(--icon-start) {
  ::before {
    --icon-start: inherit;
    content: "" / var(--icon-style-alt, "");
    display: inline-block;
    inline-size: var(--icon-style-size, 1em);
    block-size: var(--icon-style-size, 1em);
    background-color: var(--icon-style-color, currentColor);
    mask: var(--icon-start) no-repeat center / contain;
    vertical-align: calc(0.5cap - var(--icon-style-size, 1em) / 2 + var(--icon-style-voffset, -0.02em));
    flex: none;
    pointer-events: none;
    forced-color-adjust: none;
  }

  :where(:not(.icon, :empty))::before {
    margin-inline-end: var(--icon-style-spacing, 0.4em);
  }
}

@container style(--icon-end) {
  ::after {
    --icon-end: inherit;
    content: "" / var(--icon-style-alt, "");
    display: inline-block;
    inline-size: var(--icon-style-size, 1em);
    block-size: var(--icon-style-size, 1em);
    background-color: var(--icon-style-color, currentColor);
    mask: var(--icon-end) no-repeat center / contain;
    vertical-align: calc(0.5cap - var(--icon-style-size, 1em) / 2 + var(--icon-style-voffset, -0.02em));
    flex: none;
    pointer-events: none;
    forced-color-adjust: none;
  }

  :where(:not(.icon, :empty))::after {
    margin-inline-start: var(--icon-style-spacing, 0.4em);
  }
}

.icon:empty {
  --icon-start: var(--icon);
}

/* Fallback para navegadores sem Container Style Queries */
@supports not (container-type: inline-size) {
  :where(.icon-start, .icon:empty)::before {
    content: image-set(linear-gradient(transparent 0 100%), var(--icon-start)) / var(--icon-style-alt, "");
    display: inline-block;
    inline-size: var(--icon-style-size, 1em);
    block-size: var(--icon-style-size, 1em);
    background-color: var(--icon-style-color, currentColor);
    mask: var(--icon-start) no-repeat center / contain;
    vertical-align: middle;
    flex: none;
    pointer-events: none;
    forced-color-adjust: none;
  }
  :where(.icon-start)::before {
    --icon-start: inherit;
  }
  :where(.icon:empty)::before {
    --icon-start: var(--icon);
  }
  :where(.icon-start:not(.icon, :empty))::before {
    margin-inline-end: var(--icon-style-spacing, 0.4em);
  }
}

/* Safari workarounds (#301609 / #325900) */
@keyframes webkit-301609 {}

@supports ((-webkit-nbsp-mode: normal) or (-webkit-touch-callout: none) or (font: -apple-system-body)) and (content-visibility: auto) {
  @layer webkit-301609-fix {
    ::before,
    ::after {
      animation: webkit-301609 0s;
    }
  }
}

@supports ((-webkit-nbsp-mode: normal) or (-webkit-touch-callout: none) or (font: -apple-system-body)) and (content-visibility: auto) {
  @property --icon-start {
    syntax: "*";
    inherits: true;
  }

  @layer webkit-325900-fix {
    @container style(--icon-start) {
      :where(a, button, span, div, li, summary) {
        --icon-start: initial;
      }
    }
  }
}
