/* InkWoof v2 atoms: icons, buttons, chips, orb, fields, modal, toast, boot.
   Direção de arte da Nova (design/ui-v2). Consome somente tokens --iw-* do theme.css.
   Carregado depois do CSS legado (que vive em @layer legacy): estas regras vencem sem truques de especificidade. */

:focus-visible { outline: 2px solid var(--iw-focus); outline-offset: 2px; }
:where(input, textarea, select):focus-visible { outline: none; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.mono { font-family: var(--iw-font-mono); font-feature-settings: "tnum"; letter-spacing: 0; }
::selection { background: color-mix(in oklab, var(--iw-accent) 38%, transparent); color: var(--iw-text-1); }

/* ---------- Ícones (sprite local) ---------- */
.i { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.i-sm { width: 16px; height: 16px; }
.i-xs { width: 14px; height: 14px; stroke-width: 2; }
.i-fill { fill: currentColor; stroke: none; }

/* ---------- Grão de filme (matéria nos gradientes; fundo precisa estar no mesmo grupo isolado) ---------- */
.iw-grain::after {
  content: ""; position: absolute; inset: 0; pointer-events: none; z-index: 1;
  opacity: var(--iw-grain-opacity); mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 .9 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

/* ---------- Botões ---------- */
.iw-btn, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--iw-control-h); min-height: var(--iw-control-h); padding: 0 16px; border-radius: var(--iw-radius-md);
  font-size: var(--iw-fs-md); font-weight: 600; white-space: nowrap; letter-spacing: var(--iw-ls-ui);
  transition: background var(--iw-dur-fast) var(--iw-ease-out), color var(--iw-dur-fast) var(--iw-ease-out),
              box-shadow var(--iw-dur-fast) var(--iw-ease-out), transform var(--iw-dur-instant) var(--iw-ease-out);
}
.iw-btn:active:not(:disabled), .button:active:not(:disabled) { transform: translateY(calc(var(--iw-move) * 1px)) scale(.98); }
.iw-btn-lg { height: var(--iw-control-h-lg); padding: 0 20px; border-radius: 14px; font-size: 15px; }
.iw-btn-primary, .button.primary {
  color: var(--iw-text-on-accent); border: 0;
  background: linear-gradient(180deg, var(--iw-accent-top), var(--iw-accent-bottom));
  box-shadow: var(--iw-button-sheen), var(--iw-glow-accent);
}
.iw-btn-primary:hover:not(:disabled), .button.primary:hover:not(:disabled) { background: linear-gradient(180deg, var(--iw-accent-hover), var(--iw-accent)); }
.iw-btn-secondary, .button.secondary { background: var(--iw-surface-3); color: var(--iw-text-1); border: 0; box-shadow: inset 0 0 0 1px var(--iw-line-2), inset 0 1px 0 var(--iw-highlight); }
.iw-btn-secondary:hover:not(:disabled), .button.secondary:hover:not(:disabled) { background: var(--iw-surface-4); }
.iw-btn-ghost { color: var(--iw-text-2); padding: 0 12px; }
.iw-btn-ghost:hover:not(:disabled) { background: var(--iw-surface-3); color: var(--iw-text-1); }
.iw-btn-warn { color: var(--iw-text-on-bright); background: var(--iw-warning); box-shadow: var(--iw-button-sheen); }
.iw-btn-danger-ghost, .button.secondary.danger, .button.danger { color: var(--iw-danger); }
.iw-btn-danger-ghost:hover:not(:disabled), .button.secondary.danger:hover:not(:disabled) { background: var(--iw-danger-soft); }
.button.small { height: 36px; min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 10px; }
.button.full { width: 100%; }
.button svg, .iw-btn svg { width: 18px; height: 18px; }
.iw-btn:disabled, .button:disabled, .iw-btn[disabled] { opacity: .45; cursor: default; box-shadow: none; }
.iw-icon-btn, .icon-button {
  width: 40px; height: 40px; min-height: 0; display: inline-grid; place-items: center; flex: none; padding: 0;
  border-radius: 10px; color: var(--iw-text-2);
  transition: background var(--iw-dur-fast) var(--iw-ease-out), color var(--iw-dur-fast) var(--iw-ease-out);
}
.iw-icon-btn:hover:not(:disabled), .icon-button:hover:not(:disabled) { background: var(--iw-surface-3); color: var(--iw-text-1); }
.iw-icon-btn[aria-pressed="true"], .iw-icon-btn.is-on, .icon-button.is-active { background: var(--iw-accent-soft); color: var(--iw-accent-text); }
.iw-icon-btn:disabled, .icon-button:disabled { color: var(--iw-text-4); cursor: default; background: none; }
.iw-link, .text-button {
  display: inline; color: var(--iw-accent-text); text-decoration: underline; text-decoration-color: var(--iw-accent-line); text-underline-offset: 3px;
  font-size: var(--iw-fs-sm); font-weight: 500; background: none; padding: 0;
}
.text-button { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; text-decoration: none; font-weight: 600; }
.text-button:hover { text-decoration: underline; }
kbd, .iw-kbd {
  display: inline-flex; align-items: center; height: 20px; padding: 0 6px; border-radius: var(--iw-radius-xs);
  font: 500 11px/1 var(--iw-font-mono); color: var(--iw-text-3);
  background: linear-gradient(180deg, var(--iw-surface-3), var(--iw-surface-2));
  box-shadow: inset 0 0 0 1px var(--iw-line-2), inset 0 -1px 0 rgba(0, 0, 0, .25);
}
.iw-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; background: var(--iw-text-4); }
.iw-dot-ok { background: var(--iw-success); }
.iw-dot-live { background: var(--iw-success); }
.iw-dot-live.is-pulse { animation: iw-heartbeat 1.6s var(--iw-ease-out) 1; }
@keyframes iw-heartbeat { 0% { box-shadow: 0 0 0 0 rgba(62, 224, 197, .5); } 60% { box-shadow: 0 0 0 6px rgba(62, 224, 197, 0); } 100% { box-shadow: 0 0 0 0 rgba(62, 224, 197, 0); } }
.iw-sep { width: 1px; height: 20px; background: var(--iw-line-2); flex: none; }

/* ---------- Orbe do agente (gota de tinta) ---------- */
.iw-orb { position: relative; width: 28px; height: 28px; flex: none; display: inline-grid; place-items: center; }
.iw-orb svg { width: 100%; height: 100%; overflow: visible; filter: drop-shadow(0 2px 6px rgba(61, 92, 255, .45)); }
.iw-orb-sm { width: 20px; height: 20px; }
.iw-orb-lg { width: 56px; height: 56px; }
.iw-orb::before {
  content: ""; position: absolute; inset: -6px; border-radius: 50%; opacity: 0; pointer-events: none;
  background: conic-gradient(from var(--iw-angle), rgba(61, 92, 255, 0), rgba(61, 92, 255, .55), rgba(62, 224, 197, .5), rgba(61, 92, 255, 0));
  filter: blur(6px); transition: opacity var(--iw-dur-base) var(--iw-ease-out);
}
.is-working .iw-orb::before, .iw-orb.is-working::before {
  opacity: 1; animation: iw-rim var(--iw-dur-rim) linear infinite, iw-breath var(--iw-dur-breath) ease-in-out infinite alternate; animation-play-state: var(--iw-loop-state);
}
@keyframes iw-rim { to { --iw-angle: 360deg; } }
@keyframes iw-breath { from { transform: scale(.92); } to { transform: scale(1.08); } }

/* ---------- Chips ---------- */
.iw-chip, .chip {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 999px; flex: none;
  font-size: 12.5px; font-weight: 500; color: var(--iw-text-2); background: var(--iw-surface-2); box-shadow: inset 0 0 0 1px var(--iw-line-2);
}
.iw-chip::after { content: ""; position: absolute; inset: -5px -2px; }
.iw-chip.is-target, .chip.chip-accent { color: var(--iw-accent-text); background: var(--iw-accent-soft); box-shadow: inset 0 0 0 1px var(--iw-accent-line); }
.chip.chip-ok, .chip.chip-live { color: var(--iw-success); background: var(--iw-success-soft); box-shadow: none; }
.chip.chip-attention { color: var(--iw-warning); background: var(--iw-warning-soft); box-shadow: none; }
.chip.chip-danger { color: var(--iw-danger); background: var(--iw-danger-soft); box-shadow: none; }
.chip.chip-muted { box-shadow: none; background: var(--iw-surface-3); color: var(--iw-text-3); }
.chip { height: 24px; font-size: 11.5px; font-weight: 600; }
.chip svg { width: 13px; height: 13px; }
.iw-chip .i-xs { opacity: .8; }

/* ---------- Campos (modais, inspetor, formulários) ---------- */
:where(.modal, .inspector, .design-library-host, .auth-screen, .iw-form, .brand-editor, .connections-page, .references-page, .reference-dock-panel) :where(input:not([type="checkbox"], [type="radio"], [type="range"], [type="color"], [type="file"], [type="hidden"]), select, textarea) {
  min-height: 40px; padding: 0 12px; border: 0; border-radius: 12px; background: var(--iw-surface-3); color: var(--iw-text-1);
  font-size: 14px; box-shadow: inset 0 0 0 1px var(--iw-line-2); transition: box-shadow var(--iw-dur-fast), background var(--iw-dur-fast);
}
:where(.modal, .inspector, .design-library-host, .auth-screen, .iw-form, .brand-editor) textarea { padding: 10px 12px; line-height: 1.5; }
:where(.modal, .inspector, .design-library-host, .auth-screen, .iw-form, .brand-editor) :where(input, select, textarea):hover:not(:disabled, :focus) { box-shadow: inset 0 0 0 1px var(--iw-line-3); }
:where(.modal, .inspector, .design-library-host, .auth-screen, .iw-form, .brand-editor) :where(input, select, textarea):focus { box-shadow: inset 0 0 0 1.5px var(--iw-accent-text), 0 0 0 4px var(--iw-accent-soft); background: var(--iw-surface-3); }
:where(.modal, .inspector, .design-library-host, .auth-screen, .iw-form, .brand-editor) ::placeholder { color: var(--iw-text-3); opacity: 1; }
:where(.modal, .inspector, .design-library-host, .iw-form, .brand-editor) select {
  appearance: none; padding-right: 34px;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238C95A8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 16px;
}
:where(.modal, .inspector, .brand-editor) option { background: var(--iw-surface-2); color: var(--iw-text-1); }
:where(.modal, .inspector, .iw-form, .brand-editor) input[type="color"] { padding: 3px; min-height: 36px; width: 44px; border-radius: 10px; background: var(--iw-surface-3); box-shadow: inset 0 0 0 1px var(--iw-line-2); cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--iw-accent); }
.field { color: var(--iw-text-3); }
.field > span { font-size: 12px; font-weight: 600; color: var(--iw-text-2); }
.field small { color: var(--iw-text-3); }
.form-error { color: var(--iw-danger); font-size: 13px; }
.property-check { display: flex; align-items: center; gap: 10px; color: var(--iw-text-2); font-size: 13px; }

input[type="range"] { appearance: none; height: 20px; padding: 0; border: 0; background: transparent; cursor: pointer; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 999px; background: var(--iw-surface-5); }
input[type="range"]::-webkit-slider-thumb { appearance: none; width: 14px; height: 14px; margin-top: -5px; border-radius: 50%; background: var(--iw-text-1); box-shadow: 0 0 0 2px var(--iw-accent), 0 2px 6px rgba(0, 0, 0, .4); }

/* ---------- Modal ---------- */
.modal-backdrop { background: rgba(5, 6, 10, .55); backdrop-filter: none; animation: iw-fade var(--iw-dur-base) var(--iw-ease-out) both; }
.modal {
  background: var(--iw-surface-2); color: var(--iw-text-1); border: 0; border-radius: 20px;
  box-shadow: var(--iw-shadow-3); animation: iw-modal-in var(--iw-dur-base) var(--iw-ease-out) both;
}
.modal > header { padding: 20px 24px 12px; }
.modal h2 { font-size: 18px; font-weight: 650; letter-spacing: -0.012em; color: var(--iw-text-1); }
.modal-description { font-size: 13.5px; line-height: 1.6; color: var(--iw-text-2); }
.modal footer { gap: 8px; }
.modal-subhead { color: var(--iw-text-2); }
@keyframes iw-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes iw-modal-in { from { opacity: 0; transform: translateY(calc(var(--iw-move) * 10px)) scale(calc(1 - var(--iw-move) * .02)); } to { opacity: 1; transform: none; } }

/* ---------- Toast: embaixo e ao centro, acima da tira de páginas (editor) e da barra de abas (celular) ---------- */
.toast {
  position: fixed; left: 50%; bottom: 28px; top: auto; transform: translateX(-50%); z-index: var(--iw-z-toast);
  display: flex; align-items: center; gap: 10px; max-width: min(540px, calc(100vw - 32px)); padding: 11px 18px 11px 14px; border: 0; border-radius: 999px;
  background: var(--iw-glass-bg-strong); backdrop-filter: var(--iw-glass-blur); color: var(--iw-text-1);
  box-shadow: var(--iw-shadow-3); font-size: 13.5px; line-height: 19px; font-weight: 500;
}
body:has(.iw-editor) .toast { bottom: 104px; }
.toast[hidden] { display: none; }
.toast::before { content: ""; width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--iw-success); box-shadow: 0 0 0 3px rgba(62, 224, 197, .18); }
.toast:not([hidden]) { animation: iw-toast-in var(--iw-dur-base) var(--iw-ease-out) both; }
.toast.error { color: var(--iw-text-1); box-shadow: inset 0 0 0 1px rgba(255, 107, 134, .45), var(--iw-shadow-3); }
.toast.error::before { background: var(--iw-danger); box-shadow: 0 0 0 3px rgba(255, 107, 134, .2); }
@keyframes iw-toast-in { from { opacity: 0; transform: translate(-50%, calc(var(--iw-move) * 10px)); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (max-width: 700px) { .toast, body:has(.iw-editor) .toast { bottom: 96px; border-radius: 18px; } }

/* ---------- Boot ---------- */
.boot { background: var(--iw-void); color: var(--iw-text-3); }
.boot .product-symbol { width: 88px; height: auto; animation: iw-bob 2.4s var(--iw-ease-in-out) infinite; animation-play-state: var(--iw-loop-state); filter: drop-shadow(0 12px 18px rgba(0, 0, 0, .5)); }
.boot p { font-size: 13px; }
@keyframes iw-bob { 0%, 100% { transform: translateY(0) rotate(-1.5deg); } 50% { transform: translateY(calc(var(--iw-move) * -7px)) rotate(1.5deg); } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}

/* ---------- Modais e formulários: arquivos, formatos ---------- */
input[type="file"] { color: var(--iw-text-2); font-size: 13px; }
input[type="file"]::file-selector-button {
  margin-right: 12px; height: 34px; padding: 0 14px; border: 0; border-radius: 10px; cursor: pointer; font: 600 13px/1 var(--iw-font-ui);
  color: var(--iw-text-1); background: var(--iw-surface-4); box-shadow: inset 0 0 0 1px var(--iw-line-3); transition: background var(--iw-dur-fast);
}
input[type="file"]::file-selector-button:hover { background: var(--iw-surface-5); }
:where(.modal, .iw-form, .brand-editor) input[type="file"] { display: flex; align-items: center; width: 100%; min-height: 52px; padding: 8px 10px; border-radius: 12px; background: var(--iw-surface-1); box-shadow: inset 0 0 0 1px var(--iw-line-2); }
.format-options label { min-width: 0; overflow-wrap: anywhere; hyphens: auto; }
.modal.wide { width: min(760px, calc(100vw - 32px)); }
.modal-backdrop { background: rgba(5, 6, 10, .62); backdrop-filter: blur(6px); }
.shortcut-grid p b { color: var(--iw-accent-text); }

.modal { max-height: calc(100dvh - 32px); overflow: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--iw-surface-5) transparent; }
.modal footer { position: sticky; bottom: -1px; margin-top: 18px; padding: 14px 0 2px; background: linear-gradient(180deg, transparent, var(--iw-surface-2) 34%); z-index: 2; }
