/* QRTrack - hoja de estilos unica. Sin dependencias externas. */

:root {
  color-scheme: light;
  --plane:          #f9f9f7;
  --surface:        #fcfcfb;
  --text-primary:   #0b0b0b;
  --text-secondary: #52514e;
  --text-muted:     #898781;
  --grid:           #e1e0d9;
  --axis:           #c3c2b7;
  --border:         rgba(11, 11, 11, .10);
  --series-1:       #2a78d6;
  --series-1-soft:  #cde2fb;
  --accent-ink:     #ffffff;
  --good:           #0ca30c;
  --critical:       #d03b3b;
  --shadow:         0 1px 2px rgba(11, 11, 11, .05), 0 4px 12px rgba(11, 11, 11, .04);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --plane:          #0d0d0d;
    --surface:        #1a1a19;
    --text-primary:   #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted:     #898781;
    --grid:           #2c2c2a;
    --axis:           #383835;
    --border:         rgba(255, 255, 255, .10);
    --series-1:       #3987e5;
    --series-1-soft:  #184f95;
    --good:           #0ca30c;
    --critical:       #e66767;
    --shadow:         0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--plane);
  color: var(--text-primary);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--series-1); }

.wrap { max-width: 62rem; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.wrap--narrow { max-width: 34rem; }

/* ---------- Encabezado ---------- */

.topbar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar__inner {
  max-width: 62rem;
  margin: 0 auto;
  padding: .85rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.brand {
  font-weight: 650;
  letter-spacing: -.01em;
  text-decoration: none;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.brand__mark {
  width: 1.1rem; height: 1.1rem;
  border-radius: 3px;
  background:
    linear-gradient(var(--series-1) 0 0) 0 0 / 42% 42% no-repeat,
    linear-gradient(var(--series-1) 0 0) 100% 0 / 42% 42% no-repeat,
    linear-gradient(var(--series-1) 0 0) 0 100% / 42% 42% no-repeat,
    linear-gradient(var(--text-muted) 0 0) 100% 100% / 42% 42% no-repeat;
}
.topbar__spacer { margin-left: auto; }

/* ---------- Titulos ---------- */

.page-head {
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 1.5rem 0 1.25rem;
}
h1 { font-size: 1.35rem; margin: 0; letter-spacing: -.015em; }
h2 { font-size: 1rem; margin: 0 0 .75rem; letter-spacing: -.01em; }
.subtle { color: var(--text-secondary); font-size: .9rem; margin: .25rem 0 0; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem .85rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font: inherit;
  font-size: .9rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--axis); }
.btn--primary {
  background: var(--series-1);
  border-color: var(--series-1);
  color: #fff;
}
.btn--primary:hover { filter: brightness(1.06); }
.btn--danger { color: var(--critical); }
.btn--sm { padding: .3rem .55rem; font-size: .82rem; }

/* ---------- Tarjetas ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 1.15rem;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 1rem; }

/* ---------- Formularios ---------- */

.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: .85rem;
  font-weight: 550;
  margin-bottom: .3rem;
}
.field .hint { font-size: .8rem; color: var(--text-secondary); margin: .3rem 0 0; }
input[type=text], input[type=url], input[type=password], select {
  width: 100%;
  padding: .55rem .65rem;
  border-radius: 7px;
  border: 1px solid var(--axis);
  background: var(--plane);
  color: var(--text-primary);
  font: inherit;
  font-size: .92rem;
}
input:focus, select:focus {
  outline: 2px solid var(--series-1);
  outline-offset: -1px;
  border-color: var(--series-1);
}

.alert {
  padding: .7rem .85rem;
  border-radius: 8px;
  font-size: .9rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
}
.alert--error { color: var(--critical); border-color: var(--critical); }
.alert--ok { color: var(--good); border-color: var(--good); }

/* ---------- Listado de QRs ---------- */

.qr-list { display: grid; gap: .75rem; }
.qr-item {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 1rem;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: .85rem 1rem;
  box-shadow: var(--shadow);
}
.qr-item img { width: 64px; height: 64px; display: block; border-radius: 4px; }
.qr-item__name {
  font-weight: 600;
  text-decoration: none;
  color: var(--text-primary);
  letter-spacing: -.01em;
}
.qr-item__name:hover { text-decoration: underline; }
.qr-item__meta {
  font-size: .82rem;
  color: var(--text-secondary);
  margin-top: .15rem;
  overflow-wrap: anywhere;
}
.qr-item__count { text-align: right; }
.qr-item__count b {
  display: block;
  font-size: 1.5rem;
  font-weight: 620;
  letter-spacing: -.02em;
  line-height: 1.1;
}
.qr-item__count span { font-size: .75rem; color: var(--text-muted); }
.tag {
  display: inline-block;
  font-size: .7rem;
  padding: .1rem .4rem;
  border-radius: 4px;
  border: 1px solid var(--axis);
  color: var(--text-secondary);
  vertical-align: middle;
}

.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-secondary);
}

/* ---------- Fichas de estadistica ---------- */

.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: .9rem 1rem;
  box-shadow: var(--shadow);
}
.stat__label {
  font-size: .78rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.stat__value {
  font-size: 2rem;
  font-weight: 620;
  letter-spacing: -.025em;
  line-height: 1.15;
  margin-top: .2rem;
}
.stat__note { font-size: .78rem; color: var(--text-muted); }

/* ---------- Grafico de barras por dia ---------- */

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .grid-line { stroke: var(--grid); stroke-width: 1; }
.chart .axis-line { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-muted); font-size: 10px; }
.chart .bar { fill: var(--series-1); }
.chart .bar-hit { fill: transparent; cursor: pointer; }
.chart .bar-hit:hover + .bar, .chart .bar-hit:focus-visible + .bar { fill: var(--text-primary); }

.tip {
  position: absolute;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -100%);
  background: var(--text-primary);
  color: var(--plane);
  font-size: .78rem;
  line-height: 1.35;
  padding: .35rem .5rem;
  border-radius: 6px;
  white-space: nowrap;
  transition: opacity .1s;
  z-index: 5;
}
.tip.is-on { opacity: 1; }

/* ---------- Desglose (barras horizontales) ---------- */

.breakdowns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem;
}
.bar-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .5rem;
  align-items: baseline;
  margin-bottom: .55rem;
  font-size: .88rem;
}
.bar-row__label { color: var(--text-secondary); }
.bar-row__value { font-variant-numeric: tabular-nums; color: var(--text-primary); }
.bar-row__track {
  grid-column: 1 / -1;
  height: 8px;
  background: var(--grid);
  border-radius: 4px;
  overflow: hidden;
  margin-top: -.35rem;
}
.bar-row__fill {
  height: 100%;
  background: var(--series-1);
  border-radius: 4px;
}

/* ---------- Tablas ---------- */

table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table-scroll table { min-width: 32rem; }
th, td { text-align: left; padding: .5rem .4rem; border-bottom: 1px solid var(--border); }
th { color: var(--text-secondary); font-weight: 550; font-size: .8rem; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

/* ---------- Bloque del QR en el detalle ---------- */

.qr-panel {
  display: grid;
  grid-template-columns: 180px 1fr;
  gap: 1.25rem;
  align-items: start;
}
.qr-panel img {
  width: 180px; height: 180px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
}
.copybox {
  display: flex;
  gap: .5rem;
  align-items: center;
  background: var(--plane);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: .45rem .6rem;
  font-size: .88rem;
  overflow-wrap: anywhere;
}
.copybox code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.dl-links { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .75rem; }

.chart-head { display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.chart-head .range { display: flex; gap: .4rem; margin-left: auto; }

@media (max-width: 640px) {
  /* El grafico no se comprime: se desplaza para que las etiquetas sigan legibles. */
  .chart { overflow-x: auto; }
  .chart svg { min-width: 34rem; }
  .chart-head .range { margin-left: 0; }

  .qr-item { grid-template-columns: 48px 1fr; }
  .qr-item img { width: 48px; height: 48px; }
  .qr-item__count { grid-column: 2; text-align: left; }
  .qr-panel { grid-template-columns: 1fr; }
  .qr-panel img { width: 160px; height: 160px; }
}
