:root {
  /* ============================================================
   * PRIMITIVES — escala Tailwind v3 standard
   * ============================================================ */

  /* gray */
  --gray-50:  #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --gray-950: #030712;

  /* blue */
  --blue-50:  #eff6ff;
  --blue-100: #dbeafe;
  --blue-200: #bfdbfe;
  --blue-300: #93c5fd;
  --blue-400: #60a5fa;
  --blue-500: #3b82f6;
  --blue-600: #2563eb;
  --blue-700: #1d4ed8;
  --blue-800: #1e40af;
  --blue-900: #1e3a8a;

  /* green / emerald */
  --green-50:  #ecfdf5;
  --green-100: #d1fae5;
  --green-200: #a7f3d0;
  --green-300: #6ee7b7;
  --green-400: #34d399;
  --green-500: #10b981;
  --green-600: #059669;
  --green-700: #047857;
  --green-800: #065f46;
  --green-900: #064e3b;

  /* red */
  --red-50:  #fef2f2;
  --red-100: #fee2e2;
  --red-200: #fecaca;
  --red-300: #fca5a5;
  --red-400: #f87171;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --red-700: #b91c1c;
  --red-800: #991b1b;
  --red-900: #7f1d1d;

  /* yellow / amber */
  --yellow-50:  #fffbeb;
  --yellow-100: #fef3c7;
  --yellow-200: #fde68a;
  --yellow-300: #fcd34d;
  --yellow-400: #fbbf24;
  --yellow-500: #f59e0b;
  --yellow-600: #d97706;
  --yellow-700: #b45309;
  --yellow-800: #92400e;
  --yellow-900: #78350f;

  /* purple / violet */
  --purple-50:  #f5f3ff;
  --purple-100: #ede9fe;
  --purple-200: #ddd6fe;
  --purple-300: #c4b5fd;
  --purple-400: #a78bfa;
  --purple-500: #8b5cf6;
  --purple-600: #7c3aed;
  --purple-700: #6d28d9;
  --purple-800: #5b21b6;
  --purple-900: #4c1d95;

  /* cyan */
  --cyan-50:  #ecfeff;
  --cyan-100: #cffafe;
  --cyan-200: #a5f3fc;
  --cyan-300: #67e8f9;
  --cyan-400: #22d3ee;
  --cyan-500: #06b6d4;
  --cyan-600: #0891b2;
  --cyan-700: #0e7490;
  --cyan-800: #155e75;
  --cyan-900: #164e63;

  /* pink */
  --pink-50:  #fdf2f8;
  --pink-100: #fce7f3;
  --pink-200: #fbcfe8;
  --pink-300: #f9a8d4;
  --pink-400: #f472b6;
  --pink-500: #ec4899;
  --pink-600: #db2777;
  --pink-700: #be185d;
  --pink-800: #9d174d;
  --pink-900: #831843;

  /* orange */
  --orange-50:  #fff7ed;
  --orange-100: #ffedd5;
  --orange-200: #fed7aa;
  --orange-300: #fdba74;
  --orange-400: #fb923c;
  --orange-500: #f97316;
  --orange-600: #ea580c;
  --orange-700: #c2410c;
  --orange-800: #9a3412;
  --orange-900: #7c2d12;

  /* ============================================================
   * SEMANTIC — dark mode (default)
   * ============================================================ */

  --bg: var(--gray-950);
  --bg-2: var(--gray-900);
  --surface: var(--gray-900);
  --surface2: var(--gray-800);
  --surface3: var(--gray-700);
  --card: var(--gray-900);
  --card-2: var(--gray-800);
  --border: var(--gray-800);
  --border-2: var(--gray-700);
  --border-strong: var(--gray-600);
  --text: var(--gray-100);
  --text-muted: var(--gray-400);
  --text-dim: var(--gray-500);

  /* aliases retrocompat (analytics/seller usavam abreviados) */
  --t: var(--text);
  --tm: var(--text-muted);
  --td: var(--text-dim);
  --muted: var(--text-muted);
  --muted-2: var(--text-dim);
  --s: var(--surface);
  --s2: var(--surface2);
  --s3: var(--surface3);
  --b: var(--border);
  --b2: var(--border-2);
  --hover: var(--surface2);

  /* primária EMERALD — decisão de marca, sobrescreve LIME legado */
  --green: #10b981;
  --g: var(--green);
  --accent: var(--green);
  --accent-2: #059669;
  --accent-soft: rgba(16, 185, 129, 0.12);
  --green-glow: rgba(16, 185, 129, 0.15);

  --blue: #3b82f6;
  --bl: var(--blue);
  --blue-glow: rgba(59, 130, 246, 0.15);

  --purple: #8b5cf6;
  --pu: var(--purple);
  --purple-glow: rgba(139, 92, 246, 0.15);

  --yellow: #f59e0b;
  --ye: var(--yellow);
  --yellow-glow: rgba(245, 158, 11, 0.15);

  --red: #ef4444;
  --re: var(--red);
  --red-glow: rgba(239, 68, 68, 0.15);
  --danger: var(--red);
  --danger-soft: rgba(239, 68, 68, 0.12);
  --warn: var(--yellow);
  --warn-soft: rgba(245, 158, 11, 0.14);

  --cyan: #06b6d4;
  --cy: var(--cyan);
  --cyan-glow: rgba(6, 182, 212, 0.15);

  --pink: #ec4899;
  --pk: var(--pink);

  --orange: #f97316;

  /* ============================================================
   * SPACING — base 4
   * ============================================================ */
  --space-1:  4px;
  --space-2:  8px;
  --space-3:  12px;
  --space-4:  16px;
  --space-5:  20px;
  --space-6:  24px;
  --space-7:  28px;
  --space-8:  32px;
  --space-9:  36px;
  --space-10: 40px;
  --space-11: 44px;
  --space-12: 48px;
  --space-13: 52px;
  --space-14: 56px;
  --space-15: 60px;
  --space-16: 64px;

  /* ============================================================
   * TYPOGRAPHY
   * ============================================================ */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace;

  --text-xs:   12px;
  --text-sm:   14px;
  --text-base: 16px;
  --text-lg:   18px;
  --text-xl:   20px;
  --text-2xl:  24px;
  --text-3xl:  30px;

  --leading-tight:   1.25;
  --leading-normal:  1.5;
  --leading-relaxed: 1.75;

  --weight-normal:   400;
  --weight-medium:   500;
  --weight-semibold: 600;
  --weight-bold:     700;

  /* ============================================================
   * RADIUS
   * ============================================================ */
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  /* ============================================================
   * SHADOWS — alpha mais alto pra sobressair em dark mode
   * ============================================================ */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.5);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.6);

  /* ============================================================
   * MOTION
   * ============================================================ */
  --duration-fast:   120ms;
  --duration-normal: 200ms;
  --duration-slow:   320ms;
  --ease-default:    cubic-bezier(0.4, 0, 0.2, 1);

  /* ============================================================
   * LAYOUT
   * ============================================================ */
  --topbar-h: 52px;
  --layout-sidebar-width: 240px;
  --layout-sidebar-collapsed: 64px;
  --layout-content-max-width: 1280px;

  /* ============================================================
   * Z-INDEX
   * ============================================================ */
  --z-base:     0;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  800;
  --z-modal:    900;
  --z-toast:    950;
  --z-tooltip:  1000;
}

/* ============================================================
 * LIGHT THEME — sobrescreve apenas semânticos
 * ============================================================ */
[data-theme="light"] {
  --bg: #ffffff;
  --bg-2: var(--gray-50);
  --surface: var(--gray-50);
  --surface2: var(--gray-100);
  --surface3: var(--gray-200);
  --card: #ffffff;
  --card-2: var(--gray-50);
  --border: var(--gray-200);
  --border-2: var(--gray-300);
  --border-strong: var(--gray-400);
  --text: var(--gray-900);
  --text-muted: var(--gray-600);
  --text-dim: var(--gray-500);

  --t: var(--text);
  --tm: var(--text-muted);
  --td: var(--text-dim);
  --muted: var(--text-muted);
  --muted-2: var(--text-dim);
  --s: var(--surface);
  --s2: var(--surface2);
  --s3: var(--surface3);
  --b: var(--border);
  --b2: var(--border-2);
  --hover: var(--gray-100);

  /* primária mantém #10b981 — alphas maiores pra contrastar em fundo claro */
  --accent-soft: rgba(16, 185, 129, 0.18);
  --green-glow: rgba(16, 185, 129, 0.22);
  --blue-glow: rgba(59, 130, 246, 0.20);
  --purple-glow: rgba(139, 92, 246, 0.20);
  --yellow-glow: rgba(245, 158, 11, 0.22);
  --red-glow: rgba(239, 68, 68, 0.20);
  --danger-soft: rgba(239, 68, 68, 0.14);
  --warn-soft: rgba(245, 158, 11, 0.18);
  --cyan-glow: rgba(6, 182, 212, 0.20);

  /* sombras com alpha menor — papel branco precisa de menos peso */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.10), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.12), 0 4px 6px -4px rgba(0, 0, 0, 0.08);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.14), 0 8px 10px -6px rgba(0, 0, 0, 0.10);
}

/* ============================================================
 * RESET & BASE
 * ============================================================ */
*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

*:focus-visible {
  outline: 2px solid var(--green);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ============================================================
 * COMPONENTES UNIFICADOS — TOPBAR
 * Padrão visual: CRM-based, mais moderno e compacto.
 * Altura 50px, pill ativo soft, transições suaves.
 * ============================================================ */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}
.topbar-left { display: flex; align-items: center; gap: 14px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar-logo {
  font-size: 17px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
  text-decoration: none;
  white-space: nowrap;
}
.topbar-logo span { color: var(--text); font-weight: 600; }
.topbar-divider { width: 1px; height: 22px; background: var(--border); flex-shrink: 0; }

.topbar-nav { display: flex; gap: 2px; align-items: center; }
.topbar-nav a,
.topbar-nav button {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
  background: transparent;
  border: 0;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: color 0.15s var(--ease-default), background 0.15s var(--ease-default);
}
.topbar-nav a:hover,
.topbar-nav button:hover {
  background: var(--surface2);
  color: var(--text);
}
.topbar-nav a.active,
.topbar-nav button.active {
  background: var(--accent-soft);
  color: var(--accent);
}
.topbar-nav a svg,
.topbar-nav button svg { width: 14px; height: 14px; flex-shrink: 0; }

.topbar-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background 0.15s var(--ease-default), border-color 0.15s var(--ease-default);
}
.topbar-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.topbar-btn:hover {
  background: var(--surface3);
  border-color: var(--border-strong);
}
.topbar-btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.topbar-btn-primary:hover {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #000;
}
.topbar-btn-ghost {
  border-color: transparent;
  background: transparent;
}
.topbar-btn-ghost:hover {
  background: var(--surface2);
  border-color: transparent;
}

.topbar-date {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
}
.topbar-user {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.topbar-user .avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.topbar-user .name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.topbar-logout {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  padding: 5px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s var(--ease-default);
}
.topbar-logout:hover {
  background: var(--surface2);
  color: var(--text);
  border-color: var(--border-strong);
}

/* Responsive — esconder elementos opcionais quando há pouco espaço.
   Os 9 itens do nav + topbar-right tendem a estourar em <=1280px. */
@media (max-width: 1400px) {
  .topbar-date { display: none; }
}
@media (max-width: 1200px) {
  .topbar-user .name { display: none; }
}
@media (max-width: 1080px) {
  .topbar-nav a span,
  .topbar-nav button span { display: none; }
  /* Em telas ainda menores: mostrar só ícones (nav) */
  .topbar-nav a,
  .topbar-nav button { padding: 6px 8px; font-size: 0; gap: 0; }
  .topbar-nav a svg,
  .topbar-nav button svg { width: 16px; height: 16px; }
}
@media (max-width: 720px) {
  .topbar-logo { font-size: 14px; }
  .topbar-divider { display: none; }
  .topbar { padding: 0 12px; }
}

/* ============================================================
 * COMPONENTES UNIFICADOS — MODAL
 * Padrão: overlay com fade, box com slide+scale, foco no campo de borda accent.
 * ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: ds-modal-fade 0.18s var(--ease-default);
}
.modal-overlay.active { display: flex; }
@keyframes ds-modal-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.modal-box {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 22px;
  width: 460px;
  max-width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: ds-modal-slide 0.22s var(--ease-default);
}
@keyframes ds-modal-slide {
  from { opacity: 0; transform: translateY(8px) scale(0.985); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-box h2,
.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 16px;
  color: var(--text);
  letter-spacing: -0.2px;
}
.modal-field { margin-bottom: 12px; }
.modal-field label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 4px;
}
.modal-field input,
.modal-field select,
.modal-field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 11px;
  border-radius: var(--radius-md);
  width: 100%;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s var(--ease-default);
}
.modal-field textarea { resize: vertical; min-height: 60px; }
.modal-field input:focus,
.modal-field select:focus,
.modal-field textarea:focus { border-color: var(--accent); }
.modal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.modal-actions { display: flex; gap: 8px; margin-top: 18px; }
.modal-actions .btn-save,
.modal-btn-primary {
  flex: 1;
  padding: 9px 14px;
  border-radius: var(--radius-md);
  border: 0;
  background: var(--accent);
  color: #000;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s var(--ease-default);
}
.modal-actions .btn-save:hover,
.modal-btn-primary:hover { background: var(--accent-2); }
.modal-actions .btn-cancel,
.modal-btn-cancel {
  padding: 9px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s var(--ease-default), border-color 0.15s var(--ease-default);
}
.modal-actions .btn-cancel:hover,
.modal-btn-cancel:hover {
  background: var(--surface2);
  border-color: var(--border-strong);
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  font-size: 18px;
  line-height: 1;
  transition: background 0.15s var(--ease-default), color 0.15s var(--ease-default);
}
.modal-close:hover {
  background: var(--surface2);
  color: var(--text);
}

/* ============================================================
 * PAGINATOR — usado por izPaginate (paginate.js).
 * Mesma aparencia do .kanban-pager mas reutilizavel em qualquer lista.
 * ============================================================ */
.iz-pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 7px;
  margin-bottom: 10px;
  gap: 8px;
}
.iz-pager .kpg-btn {
  width: 24px;
  height: 24px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  font-weight: 700;
  font-size: 13px;
  padding: 0;
  line-height: 1;
  transition: all 0.12s var(--ease-default);
  -webkit-appearance: none;
  appearance: none;
  flex-shrink: 0;
}
.iz-pager .kpg-btn:hover:not(:disabled) {
  background: var(--surface3);
  border-color: var(--border-strong);
}
.iz-pager .kpg-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.iz-pager .kpg-info {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex: 1;
  text-align: center;
}

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