/* Contador Aginox - mobile-first, tema claro/oscuro segun el sistema */
:root {
  --bg: #f2f5f8;
  --surface: #ffffff;
  --text: #15202b;
  --muted: #566677;
  --line: #d3dbe3;
  --accent: #0b63c4;
  --accent-text: #ffffff;
  --stage: #1a222c;
  --btn: #e6ecf2;
  --btn-text: #15202b;
  --shadow: 0 1px 3px rgba(20, 32, 46, .12);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --surface: #1a232d;
    --text: #e8eef4;
    --muted: #9aaab9;
    --line: #2d3a47;
    --accent: #4b9bf2;
    --accent-text: #08121c;
    --stage: #0a0e13;
    --btn: #2a3744;
    --btn-text: #e8eef4;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top { padding: 14px 16px 6px; }
.top h1 { margin: 0; font-size: 1.4rem; letter-spacing: .01em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: .9rem; }

.layout { display: flex; flex-direction: column; gap: 12px; padding: 8px 12px 28px; max-width: 1200px; margin: 0 auto; }
.col-view, .col-ctl { display: flex; flex-direction: column; gap: 12px; min-width: 0; }

/* Botones */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 16px; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-text);
  font: inherit; font-weight: 600; cursor: pointer; text-align: center;
  -webkit-tap-highlight-color: transparent; user-select: none;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-big { min-height: 60px; font-size: 1.15rem; }
.btn-small { min-height: 44px; padding: 6px 14px; }
.btn:focus-visible, .icon:focus-visible, select:focus-visible, input[type=range]:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Visor */
.stage {
  position: relative; width: 100%; height: 62vh; height: 62dvh; min-height: 300px; max-height: 760px;
  background: var(--stage); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
}
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; color: #9aaab9; padding: 24px; pointer-events: none; }
.total {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  padding: 6px 18px; border-radius: 999px; background: rgba(0, 0, 0, .72); color: #fff;
  font-size: clamp(1.4rem, 6vw, 2.2rem); font-weight: 800; line-height: 1.15;
  pointer-events: none; white-space: nowrap; font-variant-numeric: tabular-nums;
}
.zoom { position: absolute; right: 8px; bottom: 8px; display: flex; flex-direction: row; gap: 6px; }
.icon {
  width: 44px; height: 44px; border: 0; border-radius: 10px; font-size: 1.4rem; line-height: 1;
  background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.busy {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(0, 0, 0, .55); color: #fff; font-weight: 700; font-size: 1.2rem;
}
.spin { width: 38px; height: 38px; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hint { margin: 0; color: var(--muted); font-size: .85rem; }

/* Tarjetas */
.card { background: var(--surface); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.card h2 { margin: 0; font-size: 1.05rem; }
.field { display: flex; flex-direction: column; gap: 4px; }
.lbl { font-weight: 600; font-size: .9rem; }
.range-lbl { display: flex; justify-content: space-between; color: var(--muted); font-size: .8rem; }
input[type=range] { width: 100%; min-height: 44px; margin: 0; accent-color: var(--accent); }
select {
  width: 100%; min-height: 48px; padding: 0 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit;
}

.sum { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0; }
.sum > div { background: var(--bg); border-radius: 10px; padding: 8px 12px; }
.sum dt { color: var(--muted); font-size: .8rem; }
.sum dd { margin: 0; font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.meta { margin: 0; color: var(--muted); font-size: .82rem; min-height: 1em; }
.meta.warn { color: #c2410c; }
@media (prefers-color-scheme: dark) { .meta.warn { color: #fb923c; } }

.hist-head { display: flex; align-items: center; justify-content: space-between; }
.hist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hist li { display: flex; align-items: center; gap: 10px; padding: 6px; background: var(--bg); border-radius: 10px; min-height: 44px; }
.hist img { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; flex: none; background: var(--stage); }
.hist .n { font-weight: 800; font-size: 1.2rem; min-width: 3ch; font-variant-numeric: tabular-nums; }
.hist .d { color: var(--muted); font-size: .8rem; line-height: 1.25; }

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 12px; background: #111a22; color: #fff;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .35); font-size: .95rem; z-index: 10; text-align: center;
}

/* Escritorio: visor a la izquierda, controles a la derecha */
@media (min-width: 900px) {
  .layout { flex-direction: row; align-items: flex-start; padding-top: 12px; }
  .col-view { flex: 1 1 auto; }
  .col-ctl { flex: 0 0 360px; }
  .stage { height: calc(100vh - 230px); height: calc(100dvh - 230px); min-height: 420px; }
}
