@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;600;700&family=Sora:wght@500;700&display=swap');

:root {
  --font-heading: 'Sora', 'Segoe UI', sans-serif;
  --font-body: 'Manrope', 'Segoe UI', sans-serif;
  --radius-lg: 16px;
  --radius-md: 10px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --shadow-card: 0 14px 36px rgba(9, 24, 46, 0.11);
}

html[data-palette='ocean'] {
  --color-bg: #f8fafc;
  --color-bg-soft: #eef3f8;
  --color-text: #0f172a;
  --color-muted: #64748b;
  --color-border: #d7e0ea;
  --color-card: #ffffff;
  --color-sidebar: #102a43;
  --color-sidebar-border: #334e68;
  --color-sidebar-text: #d9e2ec;
  --color-sidebar-text-soft: #9fb3c8;
  --color-sidebar-active: #486581;
  --color-primary: #627d98;
  --color-primary-strong: #486581;
  --color-pill: #edf2f8;
  --studio-glow-a: rgba(56, 189, 248, 0.28);
  --studio-glow-b: rgba(99, 102, 241, 0.24);
  --studio-glow-c: rgba(14, 165, 233, 0.2);
}

html[data-palette='forest'] {
  --color-bg: #f5faf5;
  --color-bg-soft: #edf6ed;
  --color-text: #132215;
  --color-muted: #58705e;
  --color-border: #d4e2d6;
  --color-card: #ffffff;
  --color-sidebar: #173a2a;
  --color-sidebar-border: #2f5d46;
  --color-sidebar-text: #d4ead9;
  --color-sidebar-text-soft: #9fc9ac;
  --color-sidebar-active: #2f6a4d;
  --color-primary: #2f7d58;
  --color-primary-strong: #256548;
  --color-pill: #ebf6ef;
  --studio-glow-a: rgba(74, 222, 128, 0.25);
  --studio-glow-b: rgba(16, 185, 129, 0.22);
  --studio-glow-c: rgba(45, 212, 191, 0.2);
}

html[data-palette='sunset'] {
  --color-bg: #fff8f3;
  --color-bg-soft: #fff1e6;
  --color-text: #2a1a10;
  --color-muted: #7d6354;
  --color-border: #edd7c8;
  --color-card: #fffdfb;
  --color-sidebar: #402312;
  --color-sidebar-border: #6f4127;
  --color-sidebar-text: #fde7da;
  --color-sidebar-text-soft: #f8cbb0;
  --color-sidebar-active: #7f4a2c;
  --color-primary: #c06c37;
  --color-primary-strong: #a3582a;
  --color-pill: #fff0e5;
  --studio-glow-a: rgba(251, 146, 60, 0.26);
  --studio-glow-b: rgba(249, 115, 22, 0.24);
  --studio-glow-c: rgba(245, 158, 11, 0.21);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
}

.shell-bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 8% 14%, color-mix(in srgb, var(--color-primary) 16%, transparent), transparent 35%),
    radial-gradient(circle at 86% 86%, color-mix(in srgb, var(--color-primary) 20%, transparent), transparent 34%),
    linear-gradient(145deg, var(--color-bg), var(--color-bg-soft));
}

.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: var(--color-sidebar);
  color: var(--color-sidebar-text);
  border-right: 1px solid var(--color-sidebar-border);
  padding: var(--space-5) var(--space-4);
  display: grid;
  align-content: start;
  gap: var(--space-5);
}

.brand h1 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.14rem;
}

.brand p {
  margin: var(--space-1) 0 0;
  color: var(--color-sidebar-text-soft);
  font-size: 0.84rem;
}

.module-nav {
  display: grid;
  gap: var(--space-2);
}

.module-nav__item {
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--color-sidebar-text);
  text-align: left;
  padding: 11px 12px;
  font-weight: 600;
  cursor: pointer;
}

.module-nav__item:hover {
  background: color-mix(in srgb, var(--color-sidebar-active) 80%, transparent);
}

.module-nav__item.is-active {
  background: var(--color-sidebar-active);
  border-color: color-mix(in srgb, white 18%, var(--color-sidebar-active));
}

.sidebar-note {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.4;
  color: var(--color-sidebar-text-soft);
}

.content {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--color-card) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--color-border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  align-items: center;
}

.topbar__left {
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.topbar__left h2 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1.02rem;
}

.brand-caption {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.82rem;
}

.menu-btn {
  display: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  background: var(--color-card);
  color: var(--color-text);
}

.topbar__right {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: var(--space-2);
  justify-content: flex-end;
}

label {
  display: grid;
  gap: 4px;
  color: var(--color-muted);
  font-size: 0.76rem;
}

input,
select {
  min-width: 148px;
  border: 1px solid var(--color-border);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  background: var(--color-card);
  color: var(--color-text);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: var(--space-4);
  padding: var(--space-4);
}

.main-grid,
.side-stack {
  display: grid;
  gap: var(--space-4);
  align-content: start;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: var(--space-3);
}

.card {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-card);
  box-shadow: var(--shadow-card);
}

.kpi {
  padding: var(--space-3);
}

.kpi h3 {
  margin: 0;
  font-size: 0.82rem;
  color: var(--color-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.kpi strong {
  display: block;
  margin-top: 6px;
  font-size: 1.52rem;
  font-family: var(--font-heading);
}

.card__header {
  padding: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

.card__header h3 {
  margin: 0;
  font-family: var(--font-heading);
  font-size: 1rem;
}

.status-pill {
  border: 1px solid var(--color-border);
  border-radius: 999px;
  background: var(--color-pill);
  padding: 5px 9px;
  font-size: 0.74rem;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--color-border);
}

th {
  color: var(--color-muted);
  font-size: 0.8rem;
}

.empty {
  text-align: center;
  color: var(--color-muted);
}

.form {
  display: grid;
  gap: var(--space-3);
  padding: var(--space-4);
}

.status {
  margin: 0;
  color: var(--color-muted);
  font-size: 0.84rem;
}

.insights {
  padding: var(--space-4);
  display: grid;
  gap: var(--space-2);
}

.insights p {
  margin: 0;
  color: var(--color-muted);
  line-height: 1.4;
}

.btn {
  border: 1px solid var(--color-primary);
  border-radius: 10px;
  padding: 9px 12px;
  background: linear-gradient(145deg, var(--color-primary), var(--color-primary-strong));
  color: white;
  font-weight: 700;
  cursor: pointer;
}

.btn--ghost {
  border-color: var(--color-border);
  color: var(--color-text);
  background: var(--color-card);
}

html[data-embedded='1'] .shell-bg {
  display: none;
}

html[data-embedded='1'] .app-shell {
  grid-template-columns: 1fr;
  min-height: auto;
}

html[data-embedded='1'] .sidebar,
html[data-embedded='1'] .menu-btn {
  display: none !important;
}

html[data-embedded='1'] .content {
  width: 100%;
}

/* Layout 2: Studio Neural */
html[data-layout='studio'] .shell-bg {
  background:
    radial-gradient(circle at 12% 22%, var(--studio-glow-a), transparent 34%),
    radial-gradient(circle at 88% 16%, var(--studio-glow-b), transparent 30%),
    radial-gradient(circle at 72% 86%, var(--studio-glow-c), transparent 42%),
    linear-gradient(135deg, #070b14 0%, #0b1222 52%, #0b101a 100%);
  animation: studio-bg-drift 13s ease-in-out infinite alternate;
}

html[data-layout='studio'] body {
  color: #e7ecff;
}

html[data-layout='studio'] .app-shell {
  grid-template-columns: 1fr;
  grid-template-rows: auto 1fr;
}

html[data-layout='studio'] .sidebar {
  border-right: 0;
  border-bottom: 1px solid rgba(159, 179, 200, 0.2);
  background: linear-gradient(135deg, rgba(16, 42, 67, 0.85), rgba(15, 23, 42, 0.85));
  backdrop-filter: blur(14px);
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-4);
  padding: var(--space-3) var(--space-4);
}

html[data-layout='studio'] .brand p,
html[data-layout='studio'] .sidebar-note {
  color: rgba(226, 232, 240, 0.8);
}

html[data-layout='studio'] .module-nav {
  display: flex;
  gap: var(--space-2);
  overflow: auto;
}

html[data-layout='studio'] .module-nav__item {
  white-space: nowrap;
  border-color: rgba(148, 163, 184, 0.22);
  background: rgba(15, 23, 42, 0.44);
  color: #dbeafe;
}

html[data-layout='studio'] .module-nav__item:hover {
  background: rgba(30, 41, 59, 0.7);
}

html[data-layout='studio'] .module-nav__item.is-active {
  border-color: rgba(56, 189, 248, 0.42);
  background: linear-gradient(145deg, rgba(30, 64, 175, 0.55), rgba(2, 132, 199, 0.58));
}

html[data-layout='studio'] .sidebar-note {
  text-align: right;
  max-width: 360px;
}

html[data-layout='studio'] .topbar {
  background: rgba(15, 23, 42, 0.62);
  border-bottom: 1px solid rgba(148, 163, 184, 0.22);
}

html[data-layout='studio'] .topbar__left h2 {
  color: #f8fafc;
}

html[data-layout='studio'] .brand-caption,
html[data-layout='studio'] label {
  color: rgba(226, 232, 240, 0.78);
}

html[data-layout='studio'] input,
html[data-layout='studio'] select,
html[data-layout='studio'] .menu-btn,
html[data-layout='studio'] .btn--ghost {
  border-color: rgba(148, 163, 184, 0.28);
  color: #e2e8f0;
  background: rgba(15, 23, 42, 0.56);
}

html[data-layout='studio'] .btn {
  border-color: rgba(56, 189, 248, 0.44);
  background: linear-gradient(145deg, #0284c7, #4338ca);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.28);
}

html[data-layout='studio'] .workspace {
  grid-template-columns: minmax(0, 1fr) 360px;
}

html[data-layout='studio'] .card {
  background: linear-gradient(165deg, rgba(15, 23, 42, 0.62), rgba(15, 23, 42, 0.5));
  border: 1px solid rgba(148, 163, 184, 0.24);
  box-shadow:
    0 20px 48px rgba(2, 6, 23, 0.45),
    inset 0 0 0 1px rgba(226, 232, 240, 0.03);
  backdrop-filter: blur(12px);
}

html[data-layout='studio'] .card__header {
  border-bottom: 1px solid rgba(148, 163, 184, 0.2);
}

html[data-layout='studio'] .kpi {
  position: relative;
  overflow: hidden;
}

html[data-layout='studio'] .kpi::before {
  content: '';
  position: absolute;
  right: -30px;
  top: -30px;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(56, 189, 248, 0.28), transparent 70%);
}

html[data-layout='studio'] .kpi h3,
html[data-layout='studio'] .status,
html[data-layout='studio'] .insights p,
html[data-layout='studio'] th,
html[data-layout='studio'] .empty {
  color: rgba(226, 232, 240, 0.72);
}

html[data-layout='studio'] td {
  border-bottom-color: rgba(148, 163, 184, 0.2);
}

html[data-layout='studio'] .status-pill {
  border-color: rgba(148, 163, 184, 0.26);
  background: rgba(15, 23, 42, 0.52);
  color: #dbeafe;
}

@keyframes studio-bg-drift {
  0% {
    filter: saturate(100%);
    transform: scale(1);
  }

  100% {
    filter: saturate(120%);
    transform: scale(1.02);
  }
}

@media (max-width: 1260px) {
  .workspace,
  html[data-layout='studio'] .workspace {
    grid-template-columns: 1fr;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 260px;
    height: 100vh;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform 170ms ease;
  }

  body.menu-open .sidebar {
    transform: translateX(0);
  }

  html[data-layout='studio'] .sidebar {
    position: static;
    width: auto;
    height: auto;
    transform: none;
    grid-template-columns: 1fr;
    align-items: start;
  }

  html[data-layout='studio'] .sidebar-note {
    text-align: left;
  }

  .menu-btn {
    display: inline-flex;
  }

  .topbar__right {
    justify-content: flex-start;
  }

  input,
  select {
    min-width: 132px;
  }

  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.whatsapp-qr-desc {
  font-size: 0.9rem;
  color: var(--color-muted);
  margin: 0 0 var(--space-3);
}
.whatsapp-qr-result {
  margin-top: var(--space-3);
}
.whatsapp-qr-status {
  margin: 0 0 var(--space-2);
  font-size: 0.9rem;
}
.whatsapp-qr-image-wrap {
  margin: var(--space-3) 0;
  padding: var(--space-3);
  background: var(--color-bg-soft);
  border-radius: var(--radius-md);
  display: inline-block;
}
.whatsapp-qr-img {
  display: block;
  max-width: 260px;
  height: auto;
}
.whatsapp-pairing-code {
  font-size: 0.85rem;
  color: var(--color-muted);
  margin: var(--space-2) 0 0;
}

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