:root {
  color-scheme: light;
  --ink: #18211c;
  --muted: #657069;
  --line: #e2e7e3;
  --paper: #ffffff;
  --canvas: #f4f6f3;
  --green-900: #20382b;
  --green-700: #315f45;
  --green-100: #e6f1e9;
  --amber: #a76316;
  --amber-bg: #fff3d6;
  --blue-bg: #e9f1fb;
  --rose-bg: #f9e8e5;
  --shadow: 0 12px 34px rgba(34, 55, 43, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { background: var(--canvas); }
body { margin: 0; color: var(--ink); background: var(--canvas); }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible, input:focus-visible { outline: 3px solid #d59a4a; outline-offset: 2px; }
.skip-link { position: fixed; left: 1rem; top: -4rem; z-index: 99; padding: .7rem 1rem; background: white; color: var(--ink); border-radius: .5rem; }
.skip-link:focus { top: 1rem; }
.eyebrow { margin: 0 0 .35rem; color: var(--green-700); font-size: .68rem; font-weight: 800; letter-spacing: .14em; }
.muted { color: var(--muted); }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: radial-gradient(circle at 20% 20%, #f0e6cd 0, transparent 25%), linear-gradient(145deg, #f7f5ed, #e7eee8); }
.login-card { width: min(100%, 430px); padding: clamp(2rem, 6vw, 3.25rem); background: rgba(255,255,255,.94); border: 1px solid rgba(255,255,255,.8); border-radius: 1.2rem; box-shadow: 0 30px 70px rgba(32,56,43,.16); }
.brand-mark { display: grid; place-items: center; width: 3.6rem; height: 3.6rem; margin-bottom: 1.5rem; border-radius: 50% 50% 45% 45%; background: var(--green-900); color: #f1dfb3; font-family: Georgia, serif; font-weight: 700; letter-spacing: -.06em; }
.brand-mark.small { width: 2.5rem; height: 2.5rem; margin: 0; flex: 0 0 auto; font-size: .85rem; }
.login-card h1 { margin: 0; font-family: Georgia, serif; font-size: clamp(2rem, 7vw, 2.75rem); line-height: 1.05; }
.login-card form { display: grid; gap: .55rem; margin-top: 2rem; }
label { color: #33423a; font-size: .83rem; font-weight: 700; }
input { width: 100%; min-height: 2.85rem; padding: .75rem .85rem; border: 1px solid #ccd4ce; border-radius: .55rem; background: white; color: var(--ink); }
input:focus { border-color: var(--green-700); }
.login-card input { margin-bottom: .75rem; }
.demo-note { margin: 1.1rem 0 0; padding: .8rem 1rem; color: #72501e; background: var(--amber-bg); border-radius: .55rem; font-size: .78rem; line-height: 1.5; }
.form-error { padding: .75rem; color: #8f2d26; background: #fce9e7; border-radius: .5rem; }

.app-shell { min-height: 100vh; }
.page-shell { min-width: 0; }
.topbar { min-height: 78px; display: flex; align-items: center; gap: 1rem; padding: 1rem clamp(1rem, 3vw, 2.5rem); background: var(--paper); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0; font-family: Georgia, serif; font-size: 1.55rem; font-weight: 600; }
.user-chip { margin-left: auto; display: flex; align-items: center; gap: .6rem; }
.user-chip > span { display: grid; place-items: center; width: 2.35rem; height: 2.35rem; border-radius: 50%; color: white; background: var(--green-700); font-size: .72rem; font-weight: 800; }
.user-chip strong, .user-chip small { display: block; }
.user-chip strong { font-size: .78rem; }
.user-chip small { color: var(--muted); font-size: .68rem; }
.demo-banner { display: flex; align-items: center; gap: .9rem; padding: .65rem clamp(1rem, 3vw, 2.5rem); color: #72501e; background: #fff7e4; border-bottom: 1px solid #f1dfb3; font-size: .76rem; }
.demo-banner strong { padding: .2rem .5rem; border-radius: 999px; background: #f4d990; text-transform: uppercase; font-size: .62rem; letter-spacing: .06em; }
.content { width: min(1480px, 100%); margin: auto; padding: clamp(1.2rem, 3vw, 2.5rem); }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 1rem; margin-bottom: 1.4rem; }
.section-heading h2 { margin: 0 0 .25rem; font-family: Georgia, serif; font-size: 1.65rem; }
.section-heading p, .panel-title p, .quick-actions > p { margin: 0; color: var(--muted); font-size: .82rem; }

.button { min-height: 2.6rem; padding: .65rem 1rem; border: 1px solid transparent; border-radius: .5rem; cursor: pointer; font-weight: 750; font-size: .8rem; }
.button:disabled { cursor: wait; opacity: .65; }
.button.primary { color: white; background: var(--green-700); }
.button.primary:hover { background: var(--green-900); }
.button.secondary { color: var(--green-900); background: white; border-color: #bdc9c1; }
.button.danger { color: #8d3028; background: #fff; border-color: #d9aaa5; }
.button.full { width: 100%; margin-top: .6rem; }
.icon-button { display: grid; place-items: center; width: 2.6rem; height: 2.6rem; padding: 0; border: 0; border-radius: .5rem; background: transparent; cursor: pointer; font-size: 1.35rem; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1rem; margin-bottom: 1.2rem; }
.metrics article { display: flex; align-items: center; gap: .9rem; min-width: 0; padding: 1.15rem; background: white; border: 1px solid var(--line); border-radius: .75rem; box-shadow: 0 5px 16px rgba(35,55,43,.035); }
.metric-icon { display: grid; place-items: center; flex: 0 0 auto; width: 2.55rem; height: 2.55rem; border-radius: .65rem; font-weight: 900; }
.metric-icon.green { color: var(--green-700); background: var(--green-100); }
.metric-icon.amber { color: var(--amber); background: var(--amber-bg); }
.metric-icon.blue { color: #416a96; background: var(--blue-bg); }
.metric-icon.rose { color: #975148; background: var(--rose-bg); }
.metrics small, .metrics strong, .metrics em { display: block; }
.metrics small { color: var(--muted); font-size: .7rem; }
.metrics strong { margin: .05rem 0; font-family: Georgia, serif; font-size: 1.7rem; }
.metrics em { color: #809087; font-size: .65rem; font-style: normal; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1fr) 270px; gap: 1.2rem; }
.panel { min-width: 0; margin-bottom: 1rem; padding: 1.15rem; background: white; border: 1px solid var(--line); border-radius: .75rem; box-shadow: 0 5px 18px rgba(35,55,43,.035); }
.panel h3 { margin: 0 0 .35rem; font-family: Georgia, serif; font-size: 1.05rem; }
.panel-title { display: flex; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.panel-title a { color: var(--green-700); font-size: .75rem; font-weight: 700; }
.quick-actions button { width: 100%; display: flex; align-items: center; gap: .75rem; margin-top: .7rem; padding: .75rem; color: var(--ink); text-align: left; background: #f8faf8; border: 1px solid var(--line); border-radius: .5rem; cursor: pointer; font-weight: 650; font-size: .78rem; }
.quick-actions button span { display: grid; place-items: center; width: 1.8rem; height: 1.8rem; color: var(--green-700); background: var(--green-100); border-radius: .4rem; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: .78rem; }
th { padding: .7rem .8rem; color: #748178; background: #f7f9f7; border-bottom: 1px solid var(--line); text-transform: capitalize; font-size: .66rem; letter-spacing: .02em; }
td { padding: .85rem .8rem; border-bottom: 1px solid #edf0ed; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.status { display: inline-flex; align-items: center; gap: .3rem; padding: .24rem .5rem; border-radius: 999px; font-size: .66rem; font-weight: 750; }
.status::before { content: ""; width: .35rem; height: .35rem; border-radius: 50%; background: currentColor; }
.status.success { color: #34734f; background: #e8f3eb; }
.status.warning { color: #9b641e; background: var(--amber-bg); }
.loading { min-height: 40vh; display: grid; place-items: center; align-content: center; gap: .7rem; color: var(--muted); font-size: .8rem; }
.loading span { width: 1.8rem; height: 1.8rem; border: 3px solid #dce5df; border-top-color: var(--green-700); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty, .error-state { padding: 4rem 1rem; text-align: center; color: var(--muted); }
.empty > span { font-size: 2rem; }
.empty h2, .error-state h2 { margin: .6rem 0 .25rem; color: var(--ink); font-family: Georgia, serif; }
.empty p, .error-state p { margin: 0 0 1rem; font-size: .82rem; }
.empty.compact { padding: 2rem; margin-bottom: 1rem; background: white; border: 1px dashed #c7d0ca; border-radius: .75rem; }
.not-found strong { display: block; color: #cad4cd; font: 700 6rem/1 Georgia, serif; }

dialog { width: min(560px, calc(100% - 2rem)); padding: 0; border: 0; border-radius: .85rem; box-shadow: 0 30px 80px rgba(20,35,26,.28); }
dialog::backdrop { background: rgba(23,35,28,.55); backdrop-filter: blur(2px); }
.dialog-head, .dialog-actions { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.2rem 1.35rem; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-family: Georgia, serif; }
.dialog-actions { justify-content: flex-end; border: 0; border-top: 1px solid var(--line); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; padding: 1.35rem; }
.form-grid label { display: grid; gap: .4rem; }
dialog .demo-note { margin: 0 1.35rem 1.2rem; }
.trace-search form > label { display: block; margin-bottom: .45rem; }
.trace-search form > div { display: flex; gap: .6rem; }
.trace-flow { display: flex; align-items: center; justify-content: center; gap: 1rem; margin: 1.2rem 0; padding: 1rem; background: #f7f9f7; border-radius: .6rem; font-size: .78rem; }
.trace-flow span { padding: .6rem; background: white; border: 1px solid var(--line); border-radius: .4rem; }
.trace-card > p { color: var(--muted); font-size: .78rem; }
.settings-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.settings-grid .panel p { color: var(--muted); font-size: .8rem; line-height: 1.5; }
dl { margin: 1rem 0 0; }
dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .7rem 0; border-bottom: 1px solid var(--line); font-size: .76rem; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; font-weight: 700; }
.toast { position: fixed; right: 1.25rem; bottom: 1.25rem; z-index: 100; max-width: calc(100% - 2.5rem); padding: .85rem 1rem; color: white; background: var(--green-900); border-radius: .55rem; box-shadow: var(--shadow); font-size: .8rem; }

@media (max-width: 1040px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .topbar { min-height: 68px; }
  .topbar .eyebrow { display: none; }
  .topbar h1 { font-size: 1.2rem; }
  .user-chip div { display: none; }
  .demo-banner { align-items: flex-start; }
  .section-heading { align-items: flex-start; }
  .dashboard-grid, .settings-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .trace-flow { align-items: stretch; flex-direction: column; text-align: center; }
  .trace-flow b { transform: rotate(90deg); }
}

@media (max-width: 540px) {
  .content { padding: 1rem; }
  .demo-banner { flex-direction: column; gap: .45rem; }
  .demo-banner span { line-height: 1.4; }
  .metrics { grid-template-columns: 1fr; gap: .65rem; }
  .metrics article { align-items: center; padding: .85rem; }
  .metrics article > div { min-width: 0; }
  .metric-icon { width: 2rem; height: 2rem; }
  .metrics strong { font-size: 1.35rem; }
  .section-heading { flex-direction: column; }
  .section-heading .button { width: 100%; }
  .panel { padding: .8rem; }
  .table-wrap { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  tbody { display: grid; gap: .7rem; }
  tbody tr { padding: .5rem .7rem; border: 1px solid var(--line); border-radius: .55rem; }
  td { display: flex; justify-content: space-between; gap: 1rem; padding: .48rem 0; border-bottom: 1px solid #edf0ed; white-space: normal; text-align: right; }
  td::before { content: attr(data-label); color: var(--muted); text-align: left; text-transform: capitalize; font-size: .68rem; font-weight: 700; }
  .trace-search form > div { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}


/* Dashboard interactivo */
.dashboard-grid {
  align-items: start;
}

.quick-actions {
  align-self: start;
  height: fit-content;
}

.table-sort {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: .35rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  cursor: pointer;
}

.table-sort:hover {
  color: var(--green-700);
}

.sort-indicator {
  font-size: .75rem;
  opacity: .7;
}

.clickable-row {
  cursor: pointer;
  transition: background .12s ease;
}

.clickable-row:hover,
.clickable-row:focus {
  background: #f4f8f5;
  outline: none;
}

.clickable-row:focus-visible {
  box-shadow: inset 0 0 0 2px var(--green-700);
}

@media (max-width: 540px) {
  .table-sort {
    display: none;
  }
}


/* ==========================================================
   Shell operativo
   Orden visual:
   cabecera -> navegación -> aviso -> contenido
   ========================================================== */

.page-shell > .topbar {
  order: 1;
}

.page-shell > .operational-nav {
  order: 2;
}

.page-shell > .demo-banner {
  order: 3;
}

.page-shell > .content {
  order: 4;
}

.page-shell {
  display: flex;
  flex-direction: column;
}

.topbar {
  width: 100%;
}

.operational-nav {
  width: 100%;
  flex: 0 0 auto;
}

.demo-banner {
  width: 100%;
  flex: 0 0 auto;
}


/* Actividad reciente · identificación visual por operación */
.activity-type {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 88px;
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1;
  white-space: nowrap;
}

.activity-type-entrada {
  background: #dcfce7;
  color: #166534;
}

.activity-type-elaboracion {
  background: #dbeafe;
  color: #1d4ed8;
}

.activity-type-consumo {
  background: #fef3c7;
  color: #92400e;
}

.activity-type-merma,
.activity-type-ajuste-negativo {
  background: #fee2e2;
  color: #991b1b;
}

.activity-type-ajuste {
  background: #f3e8ff;
  color: #7e22ce;
}

.activity-type-salida {
  background: #e0e7ff;
  color: #3730a3;
}

.activity-type-movimiento,
.activity-type-otro {
  background: #f1f5f9;
  color: #475569;
}
