/* ==========================================================================
   CriativoAI — style.css
   Mesmo shell (sidebar + topbar + views) e tokens do BrandForgeAI, com
   seções novas para o editor de criativos (canvas, controles, galeria).
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

/* ==========================================================================
   1. DESIGN TOKENS
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SFMono-Regular', Consolas, monospace;

  --fs-2xs: 0.6875rem;
  --fs-xs: 0.75rem;
  --fs-sm: 0.8125rem;
  --fs-md: 0.9375rem;
  --fs-lg: 1.125rem;
  --fs-xl: 1.5rem;
  --fs-2xl: 2rem;

  --lh-normal: 1.5;
  --tracking-tight: -0.03em;

  --space-3xs: 2px;
  --space-2xs: 4px;
  --space-xs: 8px;
  --space-sm: 12px;
  --space-md: 16px;
  --space-lg: 24px;
  --space-xl: 32px;
  --space-2xl: 48px;
  --space-3xl: 72px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;

  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --t-fast: 120ms var(--ease-out);
  --t-base: 200ms var(--ease-out);
  --t-slow: 420ms var(--ease-out);

  --z-sidebar: 100;
  --z-sidebar-overlay: 90;
  --z-toast: 400;

  --sidebar-width: 248px;
  --topbar-height: 64px;
  --container-max: 1360px;

  --accent-hue: 251;
  --accent: hsl(var(--accent-hue) 78% 66%);
  --accent-hover: hsl(var(--accent-hue) 85% 72%);
  --accent-contrast: #ffffff;

  --success: #2fd699;
  --danger: #f66a6a;
  --warning: #f5b955;

  /* Fundo xadrez — indica área transparente/vazia no canvas */
  --canvas-checkerboard:
    repeating-conic-gradient(var(--checker-a, #26262c) 0% 25%, var(--checker-b, #1a1a1f) 0% 50%) 50% / 20px 20px;
}

:root,
[data-theme='dark'] {
  --bg: #08080a;
  --bg-elevated: #0d0d10;
  --surface: #111114;
  --surface-2: #17171b;
  --surface-3: #1e1e23;
  --border: #232329;
  --border-strong: #2f2f36;

  --text-primary: #f4f4f6;
  --text-secondary: #9a9aa6;
  --text-tertiary: #6b6b76;

  --accent-soft: hsl(var(--accent-hue) 78% 66% / 0.14);
  --accent-border: hsl(var(--accent-hue) 78% 66% / 0.35);

  --shadow-color: 240 15% 2%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.4);
  --shadow-md: 0 8px 24px -8px hsl(var(--shadow-color) / 0.55);
  --shadow-lg: 0 24px 48px -16px hsl(var(--shadow-color) / 0.65);
  --shadow-glow: 0 0 0 1px var(--accent-border), 0 8px 32px -8px hsl(var(--accent-hue) 78% 60% / 0.35);

  --scrim: rgba(4, 4, 6, 0.72);
  --checker-a: #26262c;
  --checker-b: #1a1a1f;
}

[data-theme='light'] {
  --bg: #ffffff;
  --bg-elevated: #ffffff;
  --surface: #fafafa;
  --surface-2: #f4f4f6;
  --surface-3: #ececef;
  --border: #e6e6ea;
  --border-strong: #d8d8df;

  --text-primary: #0b0b0f;
  --text-secondary: #61616b;
  --text-tertiary: #8a8a92;

  --accent-soft: hsl(var(--accent-hue) 70% 55% / 0.08);
  --accent-border: hsl(var(--accent-hue) 70% 55% / 0.3);

  --shadow-color: 240 15% 60%;
  --shadow-sm: 0 1px 2px hsl(var(--shadow-color) / 0.12);
  --shadow-md: 0 8px 24px -8px hsl(var(--shadow-color) / 0.22);
  --shadow-lg: 0 24px 48px -16px hsl(var(--shadow-color) / 0.28);
  --shadow-glow: 0 0 0 1px var(--accent-border), 0 8px 32px -8px hsl(var(--accent-hue) 70% 55% / 0.22);

  --scrim: rgba(20, 20, 25, 0.4);
  --checker-a: #e4e4e8;
  --checker-b: #f4f4f6;
}

/* ==========================================================================
   2. RESET & BASE
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { color-scheme: dark; -webkit-text-size-adjust: 100%; }
[data-theme='light'] { color-scheme: light; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background-color: var(--bg);
  transition: background-color var(--t-base), color var(--t-base);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

img { max-width: 100%; display: block; }
button { font-family: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select, textarea { font-family: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
ul { list-style: none; }
fieldset { border: none; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }
::selection { background: var(--accent-soft); color: var(--accent); }

.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; flex-shrink: 0; }
[hidden] { display: none !important; }

/* ==========================================================================
   3. BOTÕES
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-xs);
  height: 40px;
  padding: 0 var(--space-md);
  font-size: var(--fs-sm);
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast), transform var(--t-fast);
}

.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

.btn--primary { background: var(--accent); color: var(--accent-contrast); box-shadow: var(--shadow-glow); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn--secondary { background: var(--surface-2); border-color: var(--border); color: var(--text-primary); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-3); border-color: var(--border-strong); }

.btn--icon { width: 38px; height: 38px; padding: 0; border-radius: var(--radius-md); color: var(--text-secondary); }
.btn--icon:hover { background: var(--surface-2); color: var(--text-primary); }

.btn--full { width: 100%; }

/* ==========================================================================
   4. APP SHELL
   ========================================================================== */

.app-shell { display: grid; grid-template-columns: 1fr; min-height: 100vh; }
.app-shell__main { display: flex; flex-direction: column; min-width: 0; min-height: 100vh; }

@media (min-width: 960px) {
  .app-shell { grid-template-columns: var(--sidebar-width) minmax(0, 1fr); }
}

/* ==========================================================================
   5. SIDEBAR
   ========================================================================== */

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: min(280px, 84vw);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: var(--space-md);
  transform: translateX(-100%);
  transition: transform var(--t-base);
}

.sidebar--open { transform: translateX(0); box-shadow: var(--shadow-lg); }

.sidebar-overlay {
  position: fixed;
  inset: 0;
  z-index: var(--z-sidebar-overlay);
  background: var(--scrim);
  backdrop-filter: blur(2px);
}

@media (min-width: 960px) {
  .sidebar { position: sticky; top: 0; width: 100%; height: 100vh; transform: none; }
  .sidebar-overlay { display: none; }
}

.sidebar__brand { display: flex; align-items: center; gap: var(--space-xs); padding: var(--space-xs) var(--space-xs) var(--space-lg); }
.sidebar__logo { width: 26px; height: 26px; border-radius: var(--radius-sm); }
.sidebar__title { font-size: var(--fs-md); font-weight: 700; letter-spacing: var(--tracking-tight); }

.sidebar__nav { flex: 1; overflow-y: auto; }
.sidebar__nav-list { display: flex; flex-direction: column; gap: var(--space-3xs); }

.sidebar__nav-link {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  transition: background-color var(--t-fast), color var(--t-fast);
}

.sidebar__nav-icon { color: var(--text-tertiary); transition: color var(--t-fast); }
.sidebar__nav-link:hover { background: var(--surface-2); color: var(--text-primary); }
.sidebar__nav-link:hover .sidebar__nav-icon { color: var(--text-primary); }
.sidebar__nav-link--active { background: var(--accent-soft); color: var(--text-primary); }
.sidebar__nav-link--active .sidebar__nav-icon { color: var(--accent); }

.sidebar__footer { padding-top: var(--space-sm); border-top: 1px solid var(--border); }

.sidebar__theme-toggle {
  width: 100%;
  height: auto;
  justify-content: flex-start;
  gap: var(--space-sm);
  padding: var(--space-sm);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
}

.sidebar__theme-toggle:hover { background: var(--surface-2); color: var(--text-primary); }

.theme-toggle__icon { display: none; width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; }
[data-theme='light'] .theme-toggle__icon--sun,
[data-theme='dark'] .theme-toggle__icon--moon { display: block; }

/* ==========================================================================
   6. TOPBAR
   ========================================================================== */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space-md);
  height: var(--topbar-height);
  padding-inline: var(--space-md);
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px) saturate(140%);
  border-bottom: 1px solid var(--border);
}

.topbar__heading { flex: 1; min-width: 0; }
.topbar__title { font-size: var(--fs-md); font-weight: 700; letter-spacing: var(--tracking-tight); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__subtitle { display: none; font-size: var(--fs-xs); color: var(--text-tertiary); }
.topbar__cta { flex-shrink: 0; }

@media (min-width: 640px) { .topbar__subtitle { display: block; } }
@media (min-width: 960px) {
  .topbar { padding-inline: var(--space-lg); }
  .topbar__menu-toggle { display: none; }
}

/* ==========================================================================
   7. VIEW CONTAINER / VIEWS
   ========================================================================== */

.view-container {
  flex: 1;
  padding: var(--space-lg) var(--space-md) var(--space-3xl);
  max-width: var(--container-max);
  width: 100%;
  margin-inline: auto;
}

.view { display: flex; flex-direction: column; gap: var(--space-lg); animation: view-fade-in var(--t-slow); }
.view--active { display: flex; }

@keyframes view-fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (min-width: 960px) {
  .view-container { padding: var(--space-xl) var(--space-lg) var(--space-3xl); }
}

/* ==========================================================================
   8. FORM FIELDS
   ========================================================================== */

.form-field { display: flex; flex-direction: column; gap: var(--space-2xs); }
.form-field__label { font-size: var(--fs-xs); font-weight: 600; color: var(--text-secondary); }

.form-field__input {
  width: 100%;
  height: 42px;
  padding: 0 var(--space-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: var(--fs-sm);
  color: var(--text-primary);
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.form-field__input--textarea { height: auto; padding: var(--space-xs) var(--space-sm); resize: vertical; min-height: 64px; line-height: var(--lh-normal); }

select.form-field__input {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 18px) center, calc(100% - 13px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.form-field__input::placeholder { color: var(--text-tertiary); }
.form-field__input:focus-visible { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); outline: none; }
.form-field__hint { font-size: var(--fs-2xs); color: var(--text-tertiary); }

.form-field__range { width: 100%; accent-color: var(--accent); height: 4px; margin-top: var(--space-xs); }

.color-token-row__picker {
  width: 100%;
  height: 42px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-2);
  cursor: pointer;
}

/* ==========================================================================
   9. FORMAT PICKER
   ========================================================================== */

.format-picker { display: flex; flex-direction: column; gap: var(--space-sm); }

.format-picker__list {
  display: flex;
  gap: var(--space-xs);
  overflow-x: auto;
  padding-bottom: var(--space-2xs);
  scrollbar-width: thin;
}

.format-chip {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  min-width: 128px;
  padding: var(--space-sm) var(--space-md);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color var(--t-fast), background-color var(--t-fast);
}

.format-chip:hover { border-color: var(--border-strong); }

.format-chip.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.format-chip__label { font-size: var(--fs-xs); font-weight: 700; color: var(--text-primary); }
.format-chip__dimensions { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-tertiary); }

.format-picker__custom {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 160px));
  gap: var(--space-sm);
}

/* ==========================================================================
   10. LAYOUT DO EDITOR (canvas + painel de controles)
   ========================================================================== */

.editor-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
  align-items: start;
}

@media (min-width: 1024px) {
  .editor-layout { grid-template-columns: minmax(0, 1fr) 380px; gap: var(--space-xl); }
  .canvas-stage-wrapper { position: sticky; top: calc(var(--topbar-height) + var(--space-lg)); }
}

.canvas-stage-wrapper { display: flex; flex-direction: column; align-items: center; gap: var(--space-xs); }

.canvas-stage {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: var(--canvas-checkerboard);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
}

.canvas-stage canvas { width: 100%; height: auto; display: block; touch-action: none; }
.canvas-stage canvas.is-dragging { cursor: grabbing !important; }

.canvas-stage__loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  background: var(--scrim);
  backdrop-filter: blur(4px);
  color: #ffffff;
}

.canvas-stage__loading-text { font-size: var(--fs-sm); }

.canvas-stage__dimensions { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-tertiary); }

.loading-state__spinner {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2.5px solid rgba(255, 255, 255, 0.25);
  border-top-color: #ffffff;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Painel de controles --- */

.control-panel { display: flex; flex-direction: column; gap: var(--space-md); }

.control-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  box-shadow: var(--shadow-sm);
}

.control-section__title {
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.control-section__hint { font-size: var(--fs-2xs); color: var(--text-tertiary); }

.control-section__grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-sm); }
.control-section__grid--2 { grid-template-columns: repeat(2, 1fr); }

@media (max-width: 420px) {
  .control-section__grid { grid-template-columns: repeat(2, 1fr); }
}

.control-subgroup { display: flex; flex-direction: column; gap: var(--space-sm); padding-top: var(--space-sm); border-top: 1px solid var(--border); }

.control-subgroup__toggle {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  font-size: var(--fs-xs);
  color: var(--text-secondary);
  cursor: pointer;
}

.control-subgroup__toggle input { accent-color: var(--accent); width: 16px; height: 16px; }
.control-subgroup__row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-sm); }

.control-section__actions { padding-top: var(--space-2xs); }

/* ==========================================================================
   11. GALERIA (Meus Criativos)
   ========================================================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-sm);
  padding: var(--space-3xl) var(--space-lg);
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  color: var(--text-tertiary);
  min-height: 220px;
}

.empty-state__icon { width: 34px; height: 34px; stroke: var(--text-tertiary); fill: none; stroke-width: 1.5; }
.empty-state__text { font-size: var(--fs-sm); color: var(--text-tertiary); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-md);
}

@media (min-width: 640px) { .gallery-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1024px) { .gallery-grid { grid-template-columns: repeat(4, 1fr); } }

.gallery-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
  transition: transform var(--t-base), box-shadow var(--t-base);
}

.gallery-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }

.gallery-card__thumb { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--canvas-checkerboard); }

.gallery-card__body { padding: var(--space-sm); display: flex; flex-direction: column; gap: 2px; }
.gallery-card__label { font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-card__meta { font-family: var(--font-mono); font-size: var(--fs-2xs); color: var(--text-tertiary); }

.gallery-card__actions { display: flex; gap: var(--space-2xs); padding: 0 var(--space-sm) var(--space-sm); }

/* ==========================================================================
   12. CONFIGURAÇÕES
   ========================================================================== */

.settings-form { display: flex; flex-direction: column; gap: var(--space-lg); }

.settings-group {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
}

.settings-group__title {
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.settings-group__grid { display: grid; grid-template-columns: 1fr; gap: var(--space-md); }
@media (min-width: 640px) { .settings-group__grid { grid-template-columns: repeat(2, 1fr); } }

.settings-form__submit { align-self: flex-start; }

/* ==========================================================================
   13. EXPORTAR
   ========================================================================== */

.export-page { max-width: 560px; display: flex; flex-direction: column; gap: var(--space-lg); align-items: flex-start; }

.export-preview-frame {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-lg);
  border: 1px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--canvas-checkerboard);
  min-height: 240px;
}

.export-preview-frame img { max-width: 100%; max-height: 480px; border-radius: var(--radius-md); box-shadow: var(--shadow-md); }

/* ==========================================================================
   14. FOOTER
   ========================================================================== */

.app-footer { border-top: 1px solid var(--border); }

.app-footer__container {
  max-width: var(--container-max);
  margin-inline: auto;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  text-align: center;
}

.app-footer__text { font-size: var(--fs-xs); color: var(--text-tertiary); }
.app-footer__links { display: flex; gap: var(--space-md); }
.app-footer__link { font-size: var(--fs-xs); color: var(--text-tertiary); transition: color var(--t-fast); }
.app-footer__link:hover { color: var(--text-primary); }

@media (min-width: 640px) {
  .app-footer__container { flex-direction: row; justify-content: space-between; text-align: left; }
}

/* ==========================================================================
   15. TOASTS
   ========================================================================== */

.toast-container {
  position: fixed;
  bottom: var(--space-lg);
  left: 50%;
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  pointer-events: none;
  width: min(360px, calc(100vw - var(--space-lg) * 2));
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--space-xs);
  padding: var(--space-sm) var(--space-md);
  width: 100%;
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
  animation: toast-in var(--t-slow);
}

.toast[data-type='success'] { border-color: color-mix(in srgb, var(--success) 50%, var(--border-strong)); }
.toast[data-type='error'] { border-color: color-mix(in srgb, var(--danger) 50%, var(--border-strong)); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ==========================================================================
   16. ACESSIBILIDADE — MOVIMENTO REDUZIDO
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
