:root {
  color-scheme: light;
  --ink: #171717;
  --muted: #6f6f66;
  --line: #dedbd2;
  --paper: #f4f1e9;
  --panel: #fbfaf6;
  --panel-strong: #efeadf;
  --accent: #1f7a5b;
  --accent-dark: #15533f;
  --warning: #a05a2c;
  --danger: #9b2f35;
  --shadow: 0 18px 50px rgba(48, 42, 31, 0.10);
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100dvh;
  background:
    linear-gradient(90deg, rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    linear-gradient(180deg, rgba(23, 23, 23, 0.035) 1px, transparent 1px),
    var(--paper);
  background-size: 36px 36px;
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.86);
  backdrop-filter: blur(18px);
  display: flex;
  flex-direction: column;
  gap: 26px;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: var(--ink);
  color: var(--panel);
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
}

.brand small,
.helper-text,
.section-kicker {
  color: var(--muted);
}

.section-kicker {
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 1px solid transparent;
  background: transparent;
  padding: 11px 12px;
  border-radius: 8px;
  text-align: left;
  color: var(--muted);
  transition: 180ms ease;
}

.nav-item:hover,
.nav-item.active {
  color: var(--ink);
  background: var(--panel-strong);
  border-color: var(--line);
}

.connection-panel,
.data-panel,
.command-panel,
.recommendation-panel {
  border: 1px solid var(--line);
  background: rgba(251, 250, 246, 0.92);
  box-shadow: var(--shadow);
  border-radius: 8px;
}

.connection-panel {
  margin-top: auto;
  padding: 16px;
  display: grid;
  gap: 10px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

label small,
.builder-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.45;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fffdf8;
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 122, 91, 0.14);
}

.primary-btn,
.secondary-btn {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 42px;
  padding: 10px 14px;
  font-weight: 800;
  transition: transform 160ms ease, background 160ms ease, border-color 160ms ease;
}

.primary-btn {
  color: white;
  background: var(--accent);
}

.primary-btn:hover {
  background: var(--accent-dark);
}

.secondary-btn {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.primary-btn:active,
.secondary-btn:active {
  transform: translateY(1px) scale(0.99);
}

.wide {
  width: 100%;
}

.main {
  padding: clamp(14px, 2.5vw, 28px);
  display: grid;
  gap: 24px;
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 20px;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 3.4vw, 42px);
  line-height: 1.02;
  max-width: 780px;
}

h2 {
  margin-bottom: 0;
  font-size: 20px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(210px, 1fr) 120px auto auto auto;
  gap: 10px;
  align-items: center;
  min-width: 520px;
}

.notice {
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  background: var(--panel);
  padding: 14px 16px;
  border-radius: 8px;
  color: var(--ink);
}

.notice.error {
  border-left-color: var(--danger);
}

.page-info {
  display: grid;
  grid-template-columns: minmax(220px, 1.2fr) repeat(3, minmax(120px, 0.55fr));
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 250, 246, 0.92);
  box-shadow: var(--shadow);
  padding: 16px;
  min-width: 0;
}

.page-info div {
  display: grid;
  gap: 4px;
  border-left: 1px solid var(--line);
  padding-left: 12px;
}

.page-info div:first-child {
  border-left: 0;
  padding-left: 0;
}

.page-info strong {
  font-size: 16px;
  overflow-wrap: anywhere;
}

.page-info span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.hidden {
  display: none !important;
}

.hero-grid,
.optimizer-grid,
.builder-grid,
.agent-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) minmax(300px, 0.85fr);
  gap: 20px;
  min-width: 0;
}

.login-body {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(1040px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
  gap: 24px;
  align-items: stretch;
}

.login-copy,
.login-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 250, 246, 0.92);
  box-shadow: var(--shadow);
}

.login-copy {
  padding: clamp(28px, 6vw, 58px);
  display: grid;
  align-content: end;
  min-height: 520px;
}

.login-copy p:last-child {
  margin: 18px 0 0;
  color: var(--muted);
  max-width: 56ch;
  line-height: 1.6;
}

.login-card {
  padding: 24px;
  display: grid;
  gap: 16px;
  align-content: center;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-weight: 700;
}

.command-panel,
.recommendation-panel,
.data-panel {
  padding: clamp(14px, 2vw, 20px);
  min-width: 0;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-header.compact {
  margin-bottom: 14px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  border: 0;
}

.kpi {
  min-height: 142px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.66);
  min-width: 0;
}

.kpi span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi strong {
  display: block;
  margin-top: 12px;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: clamp(19px, 2.1vw, 28px);
  line-height: 1.05;
  overflow-wrap: anywhere;
}

.kpi small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
}

.kpi p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.recommendation-list,
.rule-list,
.optimizer-actions {
  display: grid;
  gap: 12px;
}

.recommendation-list {
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.optimizer-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 253, 248, 0.72);
}

.optimizer-card strong {
  display: block;
  margin-bottom: 8px;
}

.optimizer-card p {
  color: var(--muted);
  line-height: 1.45;
}

.recommendation,
.rule-list div {
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.recommendation:first-child,
.rule-list div:first-child {
  border-top: 0;
  padding-top: 0;
}

.recommendation strong,
.rule-list strong {
  display: block;
  margin-bottom: 5px;
}

.recommendation p,
.rule-list span {
  display: block;
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}

.priority {
  display: inline-flex;
  margin-bottom: 8px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  color: var(--accent-dark);
}

.search-input {
  max-width: 280px;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

th,
td {
  padding: 13px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

td.numeric {
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.state-chip {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--ink);
  font-size: 12px;
  font-weight: 800;
}

.json-output {
  min-height: 300px;
  overflow: auto;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #1f211f;
  color: #f2efe6;
  font-family: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

.compact-output {
  min-height: 180px;
  max-height: 320px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.wizard-steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.wizard-step {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: center;
}

.wizard-step.active {
  color: var(--accent-dark);
  background: rgba(31, 122, 91, 0.1);
  border-color: rgba(31, 122, 91, 0.34);
}

.builder-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  padding: 12px;
  margin-bottom: 14px;
}

.launch-toggle {
  display: flex;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.launch-toggle input {
  width: 18px;
  height: 18px;
}

.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--panel-strong);
  min-height: 86px;
}

.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.42), transparent);
  animation: shimmer 1.2s infinite;
}

.agent-fab {
  position: fixed;
  right: 22px;
  bottom: 22px;
  min-width: 112px;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--ink);
  color: var(--panel);
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 20;
}

.agent-drawer {
  position: fixed;
  right: 18px;
  bottom: 82px;
  width: min(420px, calc(100vw - 36px));
  max-height: calc(100dvh - 110px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(251, 250, 246, 0.98);
  box-shadow: 0 24px 70px rgba(48, 42, 31, 0.22);
  padding: 18px;
  z-index: 20;
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

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

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav-list {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .topbar,
  .hero-grid,
  .optimizer-grid,
  .builder-grid,
  .agent-grid,
  .login-shell,
  .page-info {
    grid-template-columns: 1fr;
    display: grid;
  }

  .page-info div {
    border-left: 0;
    border-top: 1px solid var(--line);
    padding-left: 0;
    padding-top: 10px;
  }

  .page-info div:first-child {
    border-top: 0;
    padding-top: 0;
  }

  .toolbar {
    min-width: 0;
    grid-template-columns: 1fr 120px repeat(3, minmax(96px, auto));
  }
}

@media (max-width: 720px) {
  .main,
  .sidebar {
    padding: 14px;
  }

  .nav-list,
  .toolbar,
  .kpi-grid,
  .form-grid,
  .wizard-steps {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
  }

  h1 {
    font-size: 28px;
  }

  .nav-item,
  .primary-btn,
  .secondary-btn {
    min-height: 40px;
    padding: 9px 10px;
  }

  .page-info {
    padding: 12px;
    gap: 8px;
  }

  .recommendation-list {
    max-height: none;
  }

  .kpi {
    min-height: auto;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  tr {
    border-bottom: 1px solid var(--line);
    padding: 10px 0;
  }

  td {
    display: grid;
    grid-template-columns: 112px minmax(0, 1fr);
    gap: 12px;
    border-bottom: 0;
    padding: 8px 12px;
  }

  td::before {
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
  }

  td:nth-child(1)::before { content: "Campana"; }
  td:nth-child(2)::before { content: "Estado"; }
  td:nth-child(3)::before { content: "Objetivo"; }
  td:nth-child(4)::before { content: "Gasto"; }
  td:nth-child(5)::before { content: "CTR"; }
  td:nth-child(6)::before { content: "CPC"; }
  td:nth-child(7)::before { content: "Conv."; }
  td:nth-child(8)::before { content: "CPA"; }

  .login-copy {
    min-height: auto;
  }

  .panel-header {
    display: grid;
  }

  .agent-fab {
    right: 14px;
    bottom: 14px;
  }

  .agent-drawer {
    right: 10px;
    bottom: 72px;
    width: calc(100vw - 20px);
  }
}
