/* Tokens: espaciado 2 4 8 12 16 24 32 40 48 64 80 96, radios y tipografía en escala Tailwind. */
:root {
  color-scheme: light;
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface-2: #efefec;
  --line: #e2e2dd;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #76756f;
  --primary: #0b0b0b;
  --on-primary: #ffffff;
  --series-1: #2a78d6;
  --danger: #b42318;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #181818;
    --surface: #1f1f1f;
    --surface-2: #272727;
    --line: #313131;
    --text: #f0efec;
    --text-2: #c3c2b7;
    --text-3: #9a9992;
    --primary: #f0efec;
    --on-primary: #0b0b0b;
    --series-1: #3987e5;
    --danger: #ff8a7a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  padding: 96px 0 48px;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", "Manrope", system-ui, sans-serif;
  font-size: 16px;
  line-height: 24px;
  font-style: normal;
}
h1, h2, p, ul, dl, dd, fieldset { margin: 0; padding: 0; }
h1, h2 { text-wrap: balance; }
p { text-wrap: pretty; }
fieldset { border: 0; min-width: 0; }
a { color: inherit; text-underline-offset: 2px; transition: color 300ms var(--ease), opacity 300ms var(--ease); }
a:hover { opacity: 0.7; }
:focus-visible { outline: 2px solid var(--series-1); outline-offset: 2px; border-radius: 4px; }

/* Estilos de texto */
.heading-4 { font-size: 30px; line-height: 36px; font-weight: 600; }
.heading-5 { font-size: 24px; line-height: 32px; font-weight: 600; }
.heading-6 { font-size: 20px; line-height: 28px; font-weight: 600; }
.title-2 { font-size: 18px; line-height: 28px; font-weight: 500; }
.title-3 { font-size: 16px; line-height: 24px; font-weight: 500; }
.title-4 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-5 { font-size: 14px; line-height: 20px; font-weight: 500; }
.body-6 { font-size: 14px; line-height: 20px; font-weight: 400; }
.button-md { font-size: 16px; line-height: 24px; font-weight: 600; }
.button-sm { font-size: 14px; line-height: 20px; font-weight: 600; }
.caption-1 { font-size: 14px; line-height: 20px; font-weight: 500; }
.caption-2 { font-size: 14px; line-height: 20px; font-weight: 400; }
.caption-4 { font-size: 12px; line-height: 16px; font-weight: 500; }
.caption-5 { font-size: 12px; line-height: 16px; font-weight: 400; }
.mono { font-family: "Geist Mono", ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.muted { color: var(--text-2); }
.strong { font-weight: 600; }

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 16px; display: grid; gap: 24px; }
.wrap > * { min-width: 0; }
.skip { position: absolute; left: 16px; top: -64px; background: var(--primary); color: var(--on-primary); padding: 8px 12px; border-radius: 8px; z-index: 30; }
.skip:focus { top: 16px; }

/* Navegación flotante */
.nav {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 20;
  display: flex; align-items: center; gap: 16px;
  max-width: calc(100% - 32px); padding: 8px 8px 8px 16px;
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border: 1px solid var(--line); border-radius: 9999px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 600; white-space: nowrap; }
.brand img { display: block; border-radius: 6px; }
.nav-links { display: flex; align-items: center; gap: 4px; }
.nav-links a { text-decoration: none; padding: 8px 12px; border-radius: 9999px; white-space: nowrap; transition: background-color 300ms var(--ease); }
.nav-links a:hover { opacity: 1; background: var(--surface-2); }
.nav-links a[aria-current="page"] { background: var(--primary); color: var(--on-primary); }
.nav-links form { margin: 0; }
.nav-toggle { display: none; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 8px 12px; border-radius: 8px; border: 1px solid transparent;
  font-family: inherit; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background-color 300ms var(--ease), opacity 300ms var(--ease), transform 300ms var(--ease);
}
.btn:hover { opacity: 0.85; }
.btn:active { transform: scale(0.98); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line); }
.btn-quiet { background: transparent; color: var(--text-2); }
.btn-quiet:hover { background: var(--surface-2); opacity: 1; }
.btn-danger { background: var(--danger); color: var(--surface); }

/* Superficies */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 24px; display: grid; gap: 16px; align-content: start; }
.page-head { display: grid; gap: 8px; }
.page-head p { max-width: 680px; }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; align-items: start; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.tile { gap: 4px; padding: 16px 24px; }
.empty { justify-items: start; padding: 48px 24px; }
.empty p { max-width: 560px; }
.empty-inline { padding: 16px 0; }
.note { max-width: 680px; }
.count { display: inline-block; min-width: 20px; padding: 2px 4px; border-radius: 9999px; text-align: center; background: var(--series-1); color: #ffffff; }
.cell-sub { display: block; }
.why { max-width: 200px; white-space: normal; }
.table td .spark + span { display: block; margin-top: 2px; }
.group-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 24px 8px; }
.group-kw { padding: 0 24px 12px; }
.bulk-card { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 24px; position: sticky; top: 72px; z-index: 5; }
.alert-list { list-style: none; display: grid; gap: 12px; }
.alert { display: grid; gap: 4px; padding: 16px; background: var(--surface-2); border-radius: 12px; }
.alert.unread { background: color-mix(in srgb, var(--series-1) 12%, var(--surface)); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 9999px; background: var(--surface-2); color: var(--text); white-space: nowrap; }

.flash { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.flash-error, .field-error { color: var(--danger); }
.field-error { background: color-mix(in srgb, var(--danger) 8%, var(--surface)); border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--surface)); border-radius: 8px; padding: 8px 12px; }

.scanbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; color: var(--text-2); }
.scanbar form { margin: 0; }
.pulse { display: inline-block; width: 8px; height: 8px; border-radius: 9999px; background: var(--series-1); margin-right: 4px; animation: pulse 1600ms var(--ease) infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

/* Formularios */
.stack { display: grid; gap: 16px; }
.field { display: grid; gap: 4px; }
.field.grow { flex: 1 1 200px; }
.input {
  width: 100%; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-size: 14px; line-height: 20px;
  transition: border-color 300ms var(--ease);
}
.input.mono { font-family: "Geist Mono", ui-monospace, monospace; }
.input:hover { border-color: var(--text-3); }
.input::placeholder { color: var(--text-3); }
textarea.input { resize: vertical; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input, .table input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }
.filters { display: flex; flex-wrap: wrap; align-items: end; gap: 16px; padding: 16px 24px; }
.filters .check { padding: 8px 0; }
.chipline { display: flex; gap: 8px; flex-wrap: wrap; }
.kind-form:has(#k-keywords:checked) :is(.f-supplier, .f-ids),
.kind-form:has(#k-supplier:checked) :is(.f-keywords, .f-ids),
.kind-form:has(#k-ids:checked) :is(.f-keywords, .f-supplier) { display: none; }
.kind-form fieldset { gap: 8px; }

/* Tablas */
.table-card { padding: 0; gap: 0; overflow: hidden; }
.bulk { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding: 16px 24px; }
.bulk-actions, .actions, .lote-actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.actions form, .row-actions form, .lote-actions form { margin: 0; display: flex; gap: 8px; flex-wrap: wrap; }
.table-scroll { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; color: var(--text-3); padding: 8px 12px; white-space: nowrap; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background-color 300ms var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table th:first-child, .table td:first-child { padding-left: 24px; }
.table th:last-child, .table td:last-child { padding-right: 24px; }
.table .r { text-align: right; }
.table .prod { white-space: normal; min-width: 240px; max-width: 360px; }
.prod > a { display: block; text-decoration: none; }
.prod > span { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.card > .table-scroll .table th:first-child, .card > .table-scroll .table td:first-child { padding-left: 0; }
.card > .table-scroll .table th:last-child, .card > .table-scroll .table td:last-child { padding-right: 0; }
.table-card > .table-scroll .table th:first-child, .table-card > .table-scroll .table td:first-child { padding-left: 24px; }
.table-card > .table-scroll .table th:last-child, .table-card > .table-scroll .table td:last-child { padding-right: 24px; }

/* Pestañas de periodo */
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: var(--surface-2); border-radius: 12px; justify-self: start; }
.tabs a { text-decoration: none; padding: 4px 12px; border-radius: 8px; transition: background-color 300ms var(--ease); }
.tabs a[aria-current="true"] { background: var(--surface); }

/* Gráficos */
.spark { display: block; }
.spark path { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.spark circle { fill: var(--series-1); }
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: auto; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .tick { fill: var(--text-3); font-size: 12px; font-family: "Geist Mono", ui-monospace, monospace; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .end, .chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .cross { stroke: var(--text-3); stroke-width: 1; }
.chart .cross, .chart .dot { opacity: 0; transition: opacity 200ms var(--ease); }
.chart.hover .cross, .chart.hover .dot { opacity: 1; }
.tip { position: absolute; top: 0; left: 0; pointer-events: none; background: var(--primary); color: var(--on-primary); padding: 4px 8px; border-radius: 8px; white-space: nowrap; }

/* Lotes y ficha */
.lote-list { list-style: none; display: grid; gap: 12px; }
.lote { display: grid; gap: 12px; padding: 16px; background: var(--surface-2); border-radius: 12px; }
.lote > div:first-child { display: grid; gap: 4px; }
.confirm summary { list-style: none; }
.confirm summary::-webkit-details-marker { display: none; }
.confirm[open] { flex-basis: 100%; }
.confirm form { display: grid; gap: 8px; justify-items: start; padding-top: 8px; }
.facts { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px 24px; }

/* Ingreso */
body.auth { padding: 48px 16px; min-height: 100vh; display: grid; place-items: center; }
.auth-card { width: 100%; max-width: 400px; padding: 32px; }
.auth-card .btn { justify-self: stretch; }

.foot { max-width: 1240px; margin: 48px auto 0; padding: 0 16px; color: var(--text-3); }

@media (max-width: 900px) {
  .two { grid-template-columns: minmax(0, 1fr); }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .heading-4 { font-size: 24px; line-height: 32px; }
  .card { padding: 16px; }
  .filters, .bulk { padding: 16px; }
  .filters .field { flex: 1 1 100%; }
}
@media (max-width: 1040px) {
  .nav { left: 16px; right: 16px; transform: none; justify-content: space-between; max-width: none; }
  .nav-toggle {
    display: grid; place-items: center; gap: 0; width: 40px; height: 40px; position: relative; z-index: 2;
    background: transparent; border: 0; border-radius: 9999px; cursor: pointer; color: var(--text);
  }
  .nav-toggle span { position: absolute; width: 16px; height: 2px; border-radius: 2px; background: currentColor; transition: transform 500ms var(--ease); }
  .nav-toggle span:first-child { transform: translateY(-4px); }
  .nav-toggle span:last-child { transform: translateY(4px); }
  .nav.open .nav-toggle span:first-child { transform: rotate(45deg); }
  .nav.open .nav-toggle span:last-child { transform: rotate(-45deg); }
  .nav-links {
    position: fixed; inset: -12px -16px auto; height: 100vh; z-index: 1;
    flex-direction: column; align-items: flex-start; gap: 8px; padding: 96px 32px 32px;
    background: color-mix(in srgb, var(--bg) 94%, transparent);
    -webkit-backdrop-filter: blur(24px); backdrop-filter: blur(24px);
    opacity: 0; visibility: hidden; transition: opacity 300ms var(--ease), visibility 300ms;
  }
  .nav.open .nav-links { opacity: 1; visibility: visible; }
  .nav-links a { font-size: 24px; line-height: 32px; font-weight: 600; }
  .nav-links > * { opacity: 0; transform: translateY(24px); transition: transform 500ms var(--ease), opacity 500ms var(--ease); }
  .nav.open .nav-links > * { opacity: 1; transform: none; }
  .nav.open .nav-links > :nth-child(2) { transition-delay: 60ms; }
  .nav.open .nav-links > :nth-child(3) { transition-delay: 120ms; }
  .nav.open .nav-links > :nth-child(4) { transition-delay: 180ms; }
  .nav.open .nav-links > :nth-child(5) { transition-delay: 240ms; }
  .nav.open .nav-links > :nth-child(6) { transition-delay: 300ms; }
  .nav.open .nav-links > :nth-child(n+7) { transition-delay: 360ms; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 1ms !important; animation: none !important; }
  .nav-links > * { transform: none !important; }
}
