/* Turno IA — identidad
   Los tres colores del logo de YT (azul, magenta, coral) son los tres agentes.
   Gris del logo como fondo, azul marino como tinta. Pixel solo donde hay personaje. */

:root {
  --ink: #172440;
  --ink-2: #3A4767;
  --muted: #5A6684;
  --paper: #E9ECF2;
  --surface: #FFFFFF;
  --surface-2: #F4F6FA;
  --line: #CDD2DE;
  --lupa: #3D6BFF;
  --tono: #E0287A;
  --gerald: #FF5B45;
  --lupa-ink: #2346C7;
  --tono-ink: #B0185E;
  --gerald-ink: #C23A28;
  --ok: #1E8E5A;
  --hard-shadow: 6px 6px 0 #172440;
  --radius-s: 4px;
  --radius-m: 10px;
  --font-pixel: "Silkscreen", "Courier New", monospace;
  --font-body: "Atkinson Hyperlegible Next", "Segoe UI", system-ui, sans-serif;
  --gutter: clamp(16px, 4vw, 40px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #E8ECF5;
    --ink-2: #C3CBE0;
    --muted: #97A3C2;
    --paper: #131C36;
    --surface: #1B2747;
    --surface-2: #213056;
    --line: #2F3D66;
    --lupa-ink: #8EAAFF;
    --tono-ink: #FF7AB4;
    --gerald-ink: #FF8B7A;
    --ok: #4FD08F;
    --hard-shadow: 6px 6px 0 #0A1022;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --ink: #E8ECF5;
  --ink-2: #C3CBE0;
  --muted: #97A3C2;
  --paper: #131C36;
  --surface: #1B2747;
  --surface-2: #213056;
  --line: #2F3D66;
  --lupa-ink: #8EAAFF;
  --tono-ink: #FF7AB4;
  --gerald-ink: #FF8B7A;
  --ok: #4FD08F;
  --hard-shadow: 6px 6px 0 #0A1022;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  overflow-x: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

:focus-visible {
  outline: 3px solid var(--tono);
  outline-offset: 2px;
}

h1, h2, h3 { margin: 0; line-height: 1.15; }
p { margin: 0; }

/* ---------- barra superior ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px var(--gutter);
  border-bottom: 2px solid var(--ink);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 20;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}
.brand-mark {
  display: grid;
  grid-template-columns: repeat(3, 8px);
  gap: 2px;
}
.brand-mark i { display: block; width: 8px; height: 22px; }
.brand-mark i:nth-child(1) { background: var(--lupa); height: 14px; align-self: end; }
.brand-mark i:nth-child(2) { background: var(--tono); }
.brand-mark i:nth-child(3) { background: var(--gerald); height: 18px; align-self: end; }
.brand-text { display: flex; flex-direction: column; }
.brand-name {
  font-family: var(--font-pixel);
  font-size: 1.375rem;
  line-height: 1;
  letter-spacing: 0.02em;
}
.brand-sub { font-size: 0.8125rem; color: var(--muted); }

.tabs { display: flex; gap: 4px; }
.tab {
  font-weight: 600;
  color: var(--muted);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: var(--radius-s);
  border: 2px solid transparent;
}
.tab:hover { color: var(--ink); }
.tab[aria-current="page"] {
  color: var(--ink);
  border-color: var(--ink);
  background: var(--surface);
}

.topbar-end { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.month select {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
  padding: 6px 10px;
}
.sample {
  white-space: nowrap;
  font-size: 0.8125rem;
  padding: 4px 10px;
  border: 1.5px dashed var(--muted);
  border-radius: 999px;
  color: var(--muted);
}

/* ---------- oficina ---------- */
.view { padding: 28px var(--gutter) 56px; max-width: 1280px; margin: 0 auto; }

.stage-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.stage-title {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: clamp(1.5rem, 3.2vw, 2.5rem);
  letter-spacing: -0.01em;
  max-width: 18ch;
}
.stage-lede { max-width: 44ch; color: var(--ink-2); }

.stage {
  position: relative;
  border: 4px solid #172440;
  box-shadow: var(--hard-shadow);
  background: #36446A;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}
.stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.stage-layer { position: absolute; inset: 0; pointer-events: none; }

.zone-tag {
  position: absolute;
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1.1vw, 0.75rem);
  color: #DCE0EA;
  opacity: 0.75;
  pointer-events: none;
}

/* botón invisible sobre cada muñeco */
.bot-hit {
  position: absolute;
  width: 9%;
  height: 19%;
  transform: translate(-50%, -100%);
  pointer-events: auto;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  border-radius: 6px;
}
.bot-hit .tag {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 2px);
  transform: translateX(-50%);
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1vw, 0.75rem);
  white-space: nowrap;
  color: #fff;
  background: var(--c);
  padding: 1px 6px 2px;
  box-shadow: 2px 2px 0 #172440;
  transition: transform 160ms ease;
}
.bot-hit:hover .tag,
.bot-hit:focus-visible .tag { transform: translateX(-50%) translateY(-3px); }
.bot-hit:focus-visible { outline: 3px solid #fff; outline-offset: 0; }

.pop {
  position: absolute;
  font-family: var(--font-pixel);
  font-size: clamp(0.5rem, 1vw, 0.75rem);
  color: #fff;
  text-shadow: 1px 1px 0 #172440, -1px 1px 0 #172440, 1px -1px 0 #172440, -1px -1px 0 #172440;
  transform: translate(-50%, 0);
  animation: pop-up 1.4s steps(14) forwards;
  white-space: nowrap;
}
@keyframes pop-up {
  0% { opacity: 0; transform: translate(-50%, 4px); }
  15% { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%, -26px); }
}

.stage-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-top: 16px;
  flex-wrap: wrap;
}
.clock-line { color: var(--muted); font-size: 0.9375rem; }

.btn-ghost {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  background: transparent;
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
  padding: 6px 14px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--surface); }

/* ---------- plantilla de agentes ---------- */
.roster { margin-top: 40px; }
.roster ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-top: 2px solid var(--ink);
}
.roster li {
  padding: 20px 20px 22px 0;
  display: grid;
  grid-template-columns: 56px 1fr;
  column-gap: 14px;
  row-gap: 10px;
  align-items: start;
}
.roster li + li { padding-left: 20px; border-left: 1px solid var(--line); }
.mini {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
  background: var(--c);
  border-radius: var(--radius-s);
}
.r-name {
  font-family: var(--font-pixel);
  font-size: 1.25rem;
  line-height: 1.1;
}
.r-role { color: var(--muted); font-size: 0.9375rem; }
.r-status {
  grid-column: 1 / -1;
  font-size: 0.9375rem;
  min-height: 3em;
  color: var(--ink-2);
}
.r-status::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  background: var(--c);
  margin-right: 8px;
  vertical-align: 1px;
  animation: blink 1.2s steps(2) infinite;
}
@keyframes blink { 50% { opacity: 0.2; } }
.r-today { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 8px; }
.r-today strong {
  font-family: var(--font-pixel);
  font-size: 1.75rem;
  font-weight: 400;
  color: var(--c-ink);
  font-variant-numeric: tabular-nums;
}
.r-today span { color: var(--muted); }
.r-open {
  grid-column: 1 / -1;
  justify-self: start;
  font: inherit;
  font-weight: 700;
  color: var(--c-ink);
  background: none;
  border: 0;
  padding: 0;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* ---------- ficha (hoja lateral) ---------- */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(10, 16, 40, 0.45);
  z-index: 40;
  animation: fade 200ms ease;
}
@keyframes fade { from { opacity: 0; } }

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(520px, 100vw);
  background: var(--surface);
  border-left: 4px solid var(--c);
  z-index: 50;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: slide-in 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet.closing { animation: slide-out 200ms ease-in forwards; }
@keyframes slide-in { from { transform: translateX(100%); } }
@keyframes slide-out { to { transform: translateX(100%); } }

.sheet-inner { padding: 28px 28px 48px; }

.sheet-head {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 18px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 2px solid var(--ink);
}
.portrait {
  width: 96px;
  height: 96px;
  image-rendering: pixelated;
  background: var(--c);
  border-radius: var(--radius-m);
}
.sheet-name {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 2.25rem;
  line-height: 1;
}
.sheet-role { color: var(--muted); margin-top: 4px; }
.close {
  align-self: start;
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  width: 40px;
  height: 40px;
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.now {
  margin-top: 18px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-s);
  font-size: 0.9375rem;
}
.now b { color: var(--c-ink); }

.sheet section { margin-top: 30px; }
.sheet h3 {
  font-size: 1.0625rem;
  font-weight: 700;
  margin-bottom: 10px;
}
.desc { color: var(--ink-2); max-width: 60ch; }
.steps { margin: 14px 0 0; padding-left: 1.4em; color: var(--ink-2); }
.steps li { margin-bottom: 6px; padding-left: 4px; }
.steps li::marker { font-family: var(--font-pixel); color: var(--c-ink); }

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0;
  border: 2px solid var(--ink);
  border-radius: var(--radius-s);
}
.kpi { padding: 14px 14px 16px; }
.kpi + .kpi { border-left: 1px solid var(--line); }
.kpi-label { font-size: 0.8125rem; color: var(--muted); display: block; }
.kpi-value {
  font-family: var(--font-pixel);
  font-size: clamp(1.125rem, 2.4vw, 1.625rem);
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  display: block;
  margin-top: 4px;
  word-break: break-word;
}
.kpi-foot { font-size: 0.8125rem; color: var(--muted); display: block; margin-top: 2px; }
.kpi-delta { color: var(--ok); }
.kpi-note { font-size: 0.8125rem; color: var(--muted); margin-top: 10px; max-width: 60ch; }

.segbar { display: flex; gap: 2px; margin-top: 8px; }
.segbar i { flex: 1; height: 8px; background: var(--line); }
.segbar i.on { background: var(--c); }

.specials { list-style: none; margin: 0; padding: 0; }
.specials li {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  align-items: baseline;
}
.specials strong {
  font-family: var(--font-pixel);
  font-weight: 400;
  font-size: 1.375rem;
  color: var(--c-ink);
  font-variant-numeric: tabular-nums;
}
.specials span { color: var(--ink-2); font-size: 0.9375rem; }

.daily svg { display: block; width: 100%; height: auto; }
.daily .bar { fill: var(--c); opacity: 0.55; }
.daily .bar.weekend { opacity: 0.3; }
.daily .bar.today { opacity: 1; }
.daily .axis { fill: var(--muted); font-size: 10px; font-family: var(--font-body); }
.daily-note { font-size: 0.8125rem; color: var(--muted); margin-top: 6px; }

.prec-list { list-style: none; margin: 0; padding: 0; }
.prec-list li { margin-bottom: 12px; }
.prec-row { display: flex; justify-content: space-between; font-size: 0.9375rem; }
.prec-row b { font-variant-numeric: tabular-nums; }
.prec-track { height: 10px; background: var(--surface-2); margin-top: 4px; position: relative; }
.prec-fill { position: absolute; inset: 0 auto 0 0; background: var(--c); transform-origin: left; animation: grow 600ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes grow { from { transform: scaleX(0); } }
.prec-note { font-size: 0.8125rem; color: var(--muted); }

.log { list-style: none; margin: 0; padding: 0; font-size: 0.9375rem; }
.log li { padding: 8px 0; border-bottom: 1px dashed var(--line); display: flex; gap: 12px; }
.log time { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; width: 3.2em; }
.log li.fresh { animation: flash 900ms ease; }
@keyframes flash { from { background: color-mix(in srgb, var(--c) 22%, transparent); } }

.spec { display: grid; grid-template-columns: 9rem 1fr; gap: 6px 14px; margin: 0; font-size: 0.9375rem; }
.spec dt { color: var(--muted); }
.spec dd { margin: 0; }

.empty {
  padding: 18px;
  border: 2px dashed var(--line);
  border-radius: var(--radius-s);
  color: var(--muted);
}

/* ---------- tablero ---------- */
.board {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 32px;
  align-items: start;
}
.board > * { min-width: 0; }
.panel {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--radius-m);
  padding: 22px 24px;
}
.panel-title { font-size: 1.25rem; font-weight: 700; }
.panel-sub { color: var(--muted); font-size: 0.9375rem; margin-top: 2px; }
.table-panel { grid-column: 1 / -1; }

.receipt { grid-row: span 1; }
.receipt-paper {
  background: #FFFFFF;
  color: #172440;
  padding: 26px 24px 30px;
  box-shadow: var(--hard-shadow);
  position: relative;
  /* borde de papel cortado */
  -webkit-mask: linear-gradient(#000 0 0) top / 100% calc(100% - 10px) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / 16px 10px repeat-x;
          mask: linear-gradient(#000 0 0) top / 100% calc(100% - 10px) no-repeat,
    conic-gradient(from -45deg at bottom, #0000, #000 1deg 89deg, #0000 90deg) bottom / 16px 10px repeat-x;
}
.receipt-title { font-family: var(--font-pixel); font-weight: 400; font-size: 1.75rem; text-align: center; }
.receipt-month { text-align: center; color: #5A6684; margin-top: 2px; }
.receipt-lines { list-style: none; margin: 20px 0 0; padding: 16px 0 0; border-top: 2px dashed #172440; }
.receipt-lines li {
  display: grid;
  grid-template-columns: 12px 1fr auto;
  gap: 10px;
  align-items: baseline;
  padding: 6px 0;
}
.receipt-lines .sw { width: 12px; height: 12px; background: var(--c); align-self: center; }
.receipt-lines small { display: block; color: #5A6684; font-size: 0.8125rem; }
.receipt-lines b { font-variant-numeric: tabular-nums; }
.receipt-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 2px dashed #172440;
  font-weight: 700;
}
.receipt-total strong { font-family: var(--font-pixel); font-weight: 400; font-size: 2rem; font-variant-numeric: tabular-nums; }
.receipt-note { margin-top: 14px; font-size: 0.8125rem; color: #5A6684; text-align: center; }

.cost-chart { margin-top: 18px; }
.cost-chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.cost-chart .grid line { stroke: var(--line); }
.cost-chart .grid text, .cost-chart .xlab { fill: var(--muted); font-size: 12px; font-family: var(--font-body); }
.cost-chart .xlab.current { fill: var(--ink); font-weight: 700; }
.cost-chart .tot { fill: var(--ink); font-size: 12px; font-weight: 700; font-family: var(--font-body); }
.cost-chart rect.seg { transform-box: fill-box; transform-origin: bottom; animation: rise 500ms cubic-bezier(0.2, 0.8, 0.2, 1) both; }
@keyframes rise { from { transform: scaleY(0); } }

.legend { list-style: none; display: flex; gap: 18px; margin: 14px 0 0; padding: 0; flex-wrap: wrap; font-size: 0.9375rem; }
.legend li { display: flex; align-items: center; gap: 8px; }
.legend i { width: 12px; height: 12px; background: var(--c); }

.table-scroll { overflow-x: auto; margin-top: 12px; }
.kpi-table { width: 100%; border-collapse: collapse; min-width: 560px; }
.kpi-table th, .kpi-table td { padding: 12px 10px; text-align: left; border-bottom: 1px solid var(--line); }
.kpi-table th { font-size: 0.8125rem; color: var(--muted); font-weight: 600; }
.kpi-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.kpi-table td:first-child { font-weight: 700; }
.kpi-table .who { display: flex; align-items: center; gap: 10px; }
.kpi-table .who i { width: 10px; height: 22px; background: var(--c); }
.kpi-table .muted { color: var(--muted); font-weight: 400; }
.kpi-table button {
  font: inherit; font-weight: 700; color: var(--c-ink); background: none; border: 0; padding: 0;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  .roster ul { grid-template-columns: 1fr; }
  .roster li, .roster li + li { padding: 18px 0; border-left: 0; border-bottom: 1px solid var(--line); }
  .board { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 640px) {
  .topbar { gap: 12px; }
  .topbar-end { margin-left: 0; width: 100%; justify-content: space-between; }
  .brand-sub { display: none; }
  .stage { border-width: 3px; box-shadow: 4px 4px 0 #172440; }
  .zone-tag { display: none; }
  .bot-hit { width: 12%; height: 22%; }
  .sheet { border-left: 0; border-top: 4px solid var(--c); top: 8vh; border-radius: 14px 14px 0 0; animation-name: slide-up; }
  .sheet.closing { animation-name: slide-down; }
  @keyframes slide-up { from { transform: translateY(100%); } }
  @keyframes slide-down { to { transform: translateY(100%); } }
  .sheet-inner { padding: 22px 16px 40px; }
  .sheet-head { grid-template-columns: 64px 1fr auto; gap: 12px; }
  .portrait { width: 64px; height: 64px; }
  .sheet-name { font-size: 1.75rem; }
  .kpis { grid-template-columns: 1fr; }
  .kpi + .kpi { border-left: 0; border-top: 1px solid var(--line); }
  .specials li { grid-template-columns: 5rem 1fr; }
  .spec { grid-template-columns: 1fr; }
  .spec dd { margin-bottom: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 1ms !important;
  }
}

/* datos reales */
.sample.live {
  border-style: solid;
  border-color: var(--ok);
  color: var(--ok);
}
.sample.live::before {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--ok);
  margin-right: 7px;
  vertical-align: 1px;
  animation: blink 1.6s steps(2) infinite;
}
.roster li.off .r-status::before { animation: none; }
.roster li.off .r-name { color: var(--muted); }
