:root {
  --ink: #102333;
  --muted: #607487;
  --line: #dbe6ee;
  --soft: #f5f9fc;
  --blue: #0d74b8;
  --blue-2: #084d82;
  --green: #13a85b;
  --danger: #b42318;
  --warn: #b76a00;
  --panel: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: Inter, Segoe UI, Arial, sans-serif;
  background: #eef5f9;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
}

button.secondary {
  background: #e7f1f8;
  color: var(--blue-2);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  padding: 10px 14px;
  cursor: pointer;
  font-weight: 700;
  text-decoration: none;
}

.button.secondary {
  background: #e7f1f8;
  color: var(--blue-2);
}

button.ghost {
  background: transparent;
  color: var(--blue-2);
  border: 1px solid var(--line);
}

button.danger {
  background: var(--danger);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 80px;
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: #31495b;
  font-size: 13px;
  font-weight: 700;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 440px) 1fr;
}

.login-panel {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 22px;
  padding: 42px;
  background: #fff;
  border-right: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand img {
  width: 64px;
  height: auto;
}

.brand h1,
.brand h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
}

.login-form {
  display: grid;
  gap: 14px;
}

.login-art {
  position: relative;
  padding: 48px;
  display: grid;
  align-content: center;
  background:
    linear-gradient(120deg, rgba(13, 116, 184, 0.88), rgba(19, 168, 91, 0.76)),
    url("/static/assets/logo-acmlab.png") center / 360px auto no-repeat;
  color: #fff;
}

.login-art h2 {
  max-width: 650px;
  font-size: 42px;
  margin: 0 0 12px;
}

.login-art p {
  max-width: 620px;
  margin: 0;
  font-size: 18px;
  line-height: 1.5;
}

.demo-box { display: none !important; /* oculto en producción */
  
  border: 1px solid var(--line);
  background: var(--soft);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #082d49;
  color: #dceefb;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.sidebar .brand img {
  width: 52px;
}

.sidebar .brand h2 {
  color: #fff;
  font-size: 19px;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav button {
  text-align: left;
  background: transparent;
  color: #dceefb;
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.nav button.active {
  background: #0d74b8;
  border-color: #0d74b8;
}

.userbox {
  margin-top: auto;
  color: #b7d6e8;
  font-size: 13px;
}

.content {
  padding: 24px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1 {
  margin: 0;
  font-size: 26px;
}

.grid {
  display: grid;
  gap: 14px;
}

.cols-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cols-3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.cols-4 {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.panel,
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
}

.panel h2,
.panel h3 {
  margin: 0 0 12px;
}

.metric {
  padding: 16px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
}

.metric.small {
  padding: 12px;
}

.metric strong {
  display: block;
  font-size: 28px;
  color: var(--blue-2);
}

.metric span {
  color: var(--muted);
  font-size: 13px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table.compact td,
.table.compact th {
  padding: 8px;
}

.table th,
.table td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  text-align: left;
  font-size: 13px;
}

.table th {
  background: #eaf4fb;
  color: #1f455f;
}

.table input[type="checkbox"],
.checkline input[type="checkbox"] {
  width: auto;
}

.checkline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 0 0;
}

.compact-filters label {
  min-width: 0;
}

.compact-list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.compact-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: grid;
  gap: 3px;
}

.compact-item span,
.compact-item small {
  color: var(--muted);
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  font-weight: 800;
  font-size: 12px;
  background: #eef5f9;
}

.status.ok {
  color: #087443;
  background: #e7f8ee;
}

.status.warn {
  color: var(--warn);
  background: #fff4df;
}

.status.info {
  color: #0b5cab;
  background: #eaf3ff;
}

.notice {
  padding: 11px 12px;
  border: 1px solid #b7ddf3;
  background: #edf8ff;
  color: #164764;
  border-radius: 8px;
  margin: 10px 0;
}

.error {
  color: var(--danger);
  font-weight: 700;
}

.sample-row {
  display: grid;
  grid-template-columns: 1.5fr 1fr 1fr 1fr 0.8fr 0.8fr auto;
  gap: 8px;
  align-items: end;
}

.signature-wrap {
  margin-top: 8px;
  border: 1px dashed #8aa9bd;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.signature-wrap canvas {
  width: 100%;
  height: 160px;
  display: block;
  border-radius: 6px;
  background: #fff;
  touch-action: none;
}

.official-preview-panel {
  align-self: start;
  margin-top: 14px;
  max-width: 980px;
}

.official-format-preview {
  width: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.official-pdf-preview {
  width: 100%;
  height: 360px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.share-box {
  display: grid;
  gap: 8px;
  min-width: 150px;
}

.report-qr {
  width: 92px;
  height: 92px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 4px;
}

.validation {
  display: grid;
  place-items: center;
  padding: 28px;
}

.validation-card {
  width: min(760px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.validation-card img {
  width: 96px;
}

.validation-card dl {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 8px 14px;
}

.validation-card dt {
  color: var(--muted);
  font-weight: 700;
}

.hash {
  overflow-wrap: anywhere;
  font-family: Consolas, monospace;
}

.status-badge {
  display: inline-block;
  background: #e7f8ee;
  color: #087443;
  padding: 6px 12px;
  border-radius: 999px;
  font-weight: 800;
}

@media (max-width: 900px) {
  .login-shell,
  .app-shell,
  .cols-2,
  .cols-3,
  .cols-4 {
    grid-template-columns: 1fr;
  }

  .login-art {
    min-height: 260px;
  }

  .sidebar {
    position: static;
  }

  .sample-row {
    grid-template-columns: 1fr;
  }
}

/* === Mejoras visuales ACM Lab 2026: menú, tablas y trazabilidad === */
:root {
  --radius: 16px;
  --shadow: 0 18px 45px rgba(8, 45, 73, 0.10);
  --shadow-soft: 0 10px 25px rgba(8, 45, 73, 0.08);
}

body {
  background: radial-gradient(circle at top left, #e6f6ff 0, #f4f8fb 36%, #eef5f9 100%);
}

.app-shell { grid-template-columns: 292px 1fr; }

.sidebar {
  background: linear-gradient(180deg, #06253d 0%, #083b60 62%, #07507c 100%);
  box-shadow: 8px 0 30px rgba(8, 45, 73, 0.16);
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar .brand {
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 12px;
}

.nav { gap: 10px; }
.nav button {
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 10px;
  padding: 11px 12px;
  border-radius: 14px;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.nav button:hover { transform: translateX(3px); background: rgba(255,255,255,0.08); }
.nav button.active {
  background: linear-gradient(135deg, #0d74b8, #13a85b);
  box-shadow: 0 10px 22px rgba(13,116,184,0.28);
}
.nav .nav-ico { font-size: 18px; text-align: center; }
.nav small { display:block; margin-top:2px; color:#b7d6e8; font-size:11px; font-weight:600; }
.nav button.active small { color:#eefaff; }

.content { padding: 28px; max-width: 1600px; width: 100%; }
.topbar {
  background: rgba(255,255,255,0.76);
  border: 1px solid rgba(219,230,238,0.9);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-soft);
}
.topbar h1 { color: #082d49; }

.panel, .card, .metric {
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
}
.panel { overflow-x: auto; }
.metric {
  position: relative;
  overflow: hidden;
  border: 0;
}
.metric::after {
  content: "";
  position: absolute;
  inset: auto -30px -42px auto;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: rgba(13,116,184,0.08);
}

.table {
  min-width: 920px;
  border-collapse: separate;
  border-spacing: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
}
.table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: linear-gradient(180deg, #f2f9fd, #e7f2f9);
  color: #082d49;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: 11px;
}
.table td { background: #fff; }
.table tbody tr:nth-child(even) td { background: #f8fbfd; }
.table tbody tr:hover td { background: #edf8ff; }

button, .button { border-radius: 11px; box-shadow: 0 6px 14px rgba(13,116,184,0.14); }
button.ghost { box-shadow: none; background: #fff; }
button.secondary, .button.secondary { box-shadow: none; }

.status { letter-spacing: .01em; }
.status.ok { border: 1px solid #b7edcf; }
.status.warn { border: 1px solid #ffe0a3; }
.status.info { border: 1px solid #bddcff; }
.status.danger { color: #b42318; background: #fff0ee; border: 1px solid #ffc9c3; }

.process-rail {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -4px 0 18px;
}
.process-rail span {
  padding: 8px 12px;
  border-radius: 999px;
  background: #eaf1f6;
  color: #607487;
  font-weight: 800;
  font-size: 12px;
}
.process-rail span.done {
  background: #e7f8ee;
  color: #087443;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(8, 35, 51, .55);
  display: grid;
  place-items: center;
  padding: 18px;
  z-index: 20;
}
.trace-modal {
  width: min(760px, 100%);
  background: #fff;
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 18px;
}
.trace-head {
  display: grid;
  gap: 4px;
  padding: 14px;
  border-radius: 14px;
  background: #f4f9fc;
  border: 1px solid var(--line);
  margin-bottom: 14px;
}
.trace-head span, .trace-head small { color: var(--muted); }
.timeline { display: grid; gap: 10px; margin: 12px 0; }
.timeline-item {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
}
.timeline-item > span {
  width: 14px;
  height: 14px;
  border-radius: 999px;
  margin-top: 4px;
  background: #ffbf47;
  box-shadow: 0 0 0 5px #fff4df;
}
.timeline-item.ok > span { background: #13a85b; box-shadow: 0 0 0 5px #e7f8ee; }
.timeline-item b { color: #082d49; }
.timeline-item p { margin: 2px 0 0; color: var(--muted); }

.login-panel, .login-art { box-shadow: var(--shadow-soft); }
.login-art { background: linear-gradient(120deg, rgba(8,45,73,.92), rgba(13,116,184,.86), rgba(19,168,91,.78)), url("/static/assets/logo-acmlab.png") center / 390px auto no-repeat; }

@media (max-width: 900px) {
  .sidebar { height: auto; position: static; }
  .app-shell { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .table { min-width: 780px; }
}


/* === FT-03 captura rápida móvil / trazabilidad operativa === */
.custody-mobile-top p { margin: 4px 0 0; color: var(--muted); }
.custody-progress-panel { margin: 0 0 14px; position: sticky; top: 10px; z-index: 5; }
.progress-title { display:flex; justify-content:space-between; gap:10px; align-items:center; margin-bottom:10px; color:#082d49; }
.progress-title span, #custody-draft-status { color: var(--muted); font-size: 12px; font-weight: 700; }
.progress-track { height: 10px; background:#eaf1f6; border-radius:999px; overflow:hidden; margin-bottom:10px; }
.progress-track span { display:block; height:100%; width:0%; background: linear-gradient(90deg, #0d74b8, #13a85b); border-radius:999px; transition: width .2s ease; }
.quick-jump { margin-top: 10px; }
.sticky-custody-actions { position: sticky; top: 112px; z-index: 4; background: rgba(255,255,255,.96); padding: 10px; border: 1px solid var(--line); border-radius: 14px; }
.custody-sample-card { grid-template-columns: 1.1fr 1.3fr 1fr 1fr .8fr .8fr 1.1fr; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fdfefe; box-shadow: var(--shadow-soft); }
.sample-title { display:grid; gap:3px; align-self:center; }
.sample-title b { color:#082d49; font-size: 15px; }
.sample-title span { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.sample-actions { display:flex; gap:6px; flex-wrap:wrap; align-items:end; }
.custody-fast-panel #samples { gap: 10px; }

@media (max-width: 900px) {
  .custody-progress-panel { position: static; }
  .sticky-custody-actions { position: static; }
  .custody-mobile-top { align-items: stretch; }
  .custody-mobile-top, .progress-title { flex-direction: column; }
  .custody-sample-card { grid-template-columns: 1fr; }
  .sample-actions button, .sticky-custody-actions button, .quick-jump button, .custody-mobile-top button { width: 100%; min-height: 46px; }
  input, select, textarea { min-height: 44px; font-size: 16px; }
  .official-preview-panel { display: none; }
}

/* === AJUSTE RESPONSIVO 2026: laptop / tablet / celular === */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-size: clamp(16px, 1.05vw, 18px);
}

.content {
  max-width: none;
  padding: clamp(18px, 2.2vw, 34px);
}

.topbar h1 {
  font-size: clamp(28px, 2.4vw, 38px);
  line-height: 1.15;
}

.panel,
.card,
.metric {
  padding: clamp(18px, 1.5vw, 26px);
}

.panel h2,
.panel h3 {
  font-size: clamp(22px, 1.8vw, 30px);
}

label {
  font-size: clamp(14px, 1vw, 16px);
}

input,
select,
textarea {
  min-height: 48px;
  font-size: clamp(16px, 1vw, 18px);
  padding: 12px 14px;
}

button,
.button {
  min-height: 46px;
  font-size: clamp(15px, 1vw, 17px);
  padding: 12px 16px;
}

.table th,
.table td {
  font-size: clamp(14px, .95vw, 16px);
  padding: 12px 13px;
}

.table th {
  font-size: clamp(12px, .85vw, 14px);
}

.metric strong {
  font-size: clamp(32px, 2.4vw, 46px);
}

.metric span,
.compact-item span,
.compact-item small,
.notice,
.demo-box {
  font-size: clamp(14px, .95vw, 16px);
}

.sidebar {
  padding: clamp(18px, 1.5vw, 26px);
}

.sidebar .brand h2 {
  font-size: clamp(20px, 1.4vw, 24px);
}

.sidebar .brand img {
  width: clamp(58px, 4vw, 74px);
}

.nav button {
  min-height: 52px;
  font-size: clamp(15px, 1vw, 17px);
}

.nav small {
  font-size: 12px;
}

/* Laptop normal: evita que todo se vea chiquito */
@media (min-width: 901px) and (max-width: 1450px) {
  .app-shell {
    grid-template-columns: 310px 1fr;
  }

  .content {
    padding: 26px;
  }

  .cols-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .cols-3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sample-row,
  .custody-sample-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sample-title,
  .sample-actions {
    grid-column: 1 / -1;
  }
}

/* Tablet: menú arriba y captura cómoda */
@media (min-width: 701px) and (max-width: 900px) {
  body {
    font-size: 17px;
  }

  .sidebar {
    height: auto;
    position: static;
    padding: 16px;
  }

  .nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content {
    padding: 18px;
  }

  .topbar {
    align-items: flex-start;
  }

  .topbar,
  .row-actions {
    flex-direction: column;
  }

  .row-actions button,
  .row-actions .button {
    width: 100%;
  }

  .table {
    min-width: 720px;
  }
}

/* Celular: una columna, botones grandes y sin letras pequeñas */
@media (max-width: 700px) {
  html {
    font-size: 17px;
  }

  body {
    font-size: 17px;
  }

  .login-shell,
  .app-shell,
  .cols-2,
  .cols-3,
  .cols-4,
  .sample-row,
  .custody-sample-card {
    grid-template-columns: 1fr !important;
  }

  .login-panel,
  .login-art,
  .content {
    padding: 14px;
  }

  .login-art h2 {
    font-size: 30px;
  }

  .sidebar {
    padding: 12px;
  }

  .sidebar .brand {
    padding: 10px;
  }

  .nav {
    grid-template-columns: 1fr;
  }

  .nav button {
    width: 100%;
    min-height: 54px;
  }

  .topbar {
    display: grid;
    gap: 12px;
    padding: 14px;
  }

  .topbar h1 {
    font-size: 28px;
  }

  .panel,
  .card,
  .metric {
    padding: 14px;
    border-radius: 14px;
  }

  input,
  select,
  textarea,
  button,
  .button {
    width: 100%;
    min-height: 50px;
    font-size: 17px;
  }

  .row-actions,
  .sample-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .table {
    min-width: 680px;
  }

  .panel:has(.table)::before {
    content: "Desliza la tabla hacia los lados para ver más columnas";
    display: block;
    margin-bottom: 10px;
    color: var(--muted);
    font-weight: 700;
    font-size: 14px;
  }

  .official-pdf-preview,
  .official-format-preview {
    display: none;
  }
}

/* Usuarios: permisos por modulo */
.permission-grid{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(190px,1fr));
  gap:10px;
}
.perm-card{
  border:1px solid rgba(15,23,42,.12);
  border-radius:14px;
  padding:10px 12px;
  display:flex;
  gap:10px;
  align-items:flex-start;
  background:#fff;
  cursor:pointer;
}
.perm-card input{width:20px;height:20px;margin-top:2px}
.perm-card b{display:block;font-size:.94rem}
.perm-card small{display:block;color:#64748b;margin-top:2px;line-height:1.2}
.perm-card.disabled{opacity:.45;background:#f8fafc;cursor:not-allowed}
.soft-panel{background:linear-gradient(180deg,#f8fafc,#fff)}

.tabs-lite{display:flex;gap:10px;flex-wrap:wrap;margin:0 0 16px}
.tabs-lite button{border:1px solid rgba(15,23,42,.12);background:#fff;border-radius:14px;padding:12px 18px;font-weight:800;box-shadow:0 8px 24px rgba(15,23,42,.06);cursor:pointer}
.tabs-lite button.active{background:#0f172a;color:#fff;border-color:#0f172a}
.permission-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(190px,1fr));gap:10px}
.perm-card{display:flex;gap:10px;align-items:flex-start;padding:12px;border:1px solid rgba(15,23,42,.12);border-radius:14px;background:#fff}
.perm-card input{margin-top:4px;transform:scale(1.2)}
.perm-card span{display:flex;flex-direction:column;gap:2px}
.perm-card small{color:#64748b;font-size:.78rem}.perm-card.disabled{opacity:.45;background:#f8fafc}
@media(max-width:760px){.tabs-lite button{flex:1 1 100%;font-size:1rem}.permission-grid{grid-template-columns:1fr}.perm-card{padding:14px}.perm-card input{transform:scale(1.35)}}

.row-highlight{outline:3px solid #0b65c2; background:#eaf3ff!important;}
.status.bad, .status.danger { color:#b42318; background:#fff0ee; border:1px solid #ffc9c3; }
.danger-card { border-color:#ffc9c3 !important; background:#fff7f6 !important; }
.result-negative { border-color:#d92d20 !important; background:#fff4f2 !important; color:#b42318 !important; font-weight:800; }
.inline-alert { margin-top:6px; padding:6px 8px; font-size:12px; border-radius:8px; }

/* === MENÚ AUTOAJUSTABLE v3.1: laptop / zoom / tablet / celular === */
.app-shell {
  grid-template-columns: clamp(230px, 19vw, 310px) minmax(0, 1fr);
}

.sidebar {
  overflow: hidden;
  max-height: 100vh;
}

.sidebar .brand.sidebar-brand-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
}

.sidebar .brand h2,
.sidebar .brand p,
.nav button b,
.nav button small {
  overflow: hidden;
  text-overflow: ellipsis;
}

.menu-toggle {
  display: none;
  min-width: 44px;
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  border-radius: 12px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  color: #fff;
  box-shadow: none;
}

.nav {
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  scrollbar-width: thin;
  max-height: calc(100vh - 185px);
}

.nav::-webkit-scrollbar { width: 7px; }
.nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.28); border-radius: 999px; }
.nav::-webkit-scrollbar-track { background: rgba(255,255,255,.06); border-radius: 999px; }

.nav button {
  width: 100%;
  min-width: 0;
}

.nav button span:last-child {
  min-width: 0;
}

.userbox {
  flex-shrink: 0;
}

@media (min-width: 901px) {
  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-shell.menu-collapsed {
    grid-template-columns: 86px minmax(0, 1fr);
  }

  .app-shell.menu-collapsed .sidebar {
    padding: 12px;
    gap: 12px;
  }

  .app-shell.menu-collapsed .sidebar .brand.sidebar-brand-row {
    grid-template-columns: 1fr;
    justify-items: center;
  }

  .app-shell.menu-collapsed .sidebar .brand img {
    width: 50px;
  }

  .app-shell.menu-collapsed .sidebar .brand div,
  .app-shell.menu-collapsed .nav button span:last-child,
  .app-shell.menu-collapsed .nav-group-title,
  .app-shell.menu-collapsed .userbox {
    display: none;
  }

  .app-shell.menu-collapsed .nav {
    max-height: calc(100vh - 92px);
    padding-right: 0;
  }

  .app-shell.menu-collapsed .nav button {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 50px;
    padding: 9px 6px;
  }

  .app-shell.menu-collapsed .nav .nav-ico {
    font-size: 22px;
  }
}

@media (min-width: 901px) and (max-height: 760px) {
  .sidebar {
    padding: 12px;
    gap: 10px;
  }

  .sidebar .brand {
    padding: 9px;
  }

  .sidebar .brand img {
    width: 46px;
  }

  .nav {
    gap: 6px;
    max-height: calc(100vh - 148px);
  }

  .nav button {
    min-height: 42px;
    padding: 8px 10px;
    grid-template-columns: 28px 1fr;
  }

  .nav small {
    display: none;
  }

  .userbox {
    font-size: 12px;
  }

  .userbox button {
    min-height: 36px;
    padding: 8px 10px;
  }
}

@media (min-width: 901px) and (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 88px minmax(0, 1fr);
  }

  .sidebar {
    padding: 12px;
    gap: 12px;
  }

  .sidebar .brand {
    grid-template-columns: 1fr;
    justify-items: center;
    padding: 10px;
  }

  .sidebar .brand div {
    display: none;
  }

  .sidebar .brand img {
    width: 54px;
  }

  .nav {
    max-height: calc(100vh - 105px);
    padding-right: 0;
  }

  .nav button {
    grid-template-columns: 1fr;
    justify-items: center;
    min-height: 54px;
    padding: 10px 6px;
  }

  .nav .nav-ico {
    font-size: 22px;
  }

  .nav button span:last-child {
    display: none;
  }

  .userbox {
    display: none;
  }
}

@media (max-width: 900px) {
  .app-shell {
    grid-template-columns: 1fr !important;
  }

  .sidebar {
    position: sticky !important;
    top: 0;
    z-index: 30;
    height: auto !important;
    max-height: none;
    padding: 10px 12px;
    gap: 8px;
    border-bottom: 1px solid rgba(255,255,255,.16);
  }

  .sidebar .brand.sidebar-brand-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    padding: 8px 10px;
  }

  .sidebar .brand img {
    width: 42px;
  }

  .sidebar .brand h2 {
    font-size: 17px;
  }

  .sidebar .brand p {
    font-size: 12px;
    white-space: nowrap;
  }

  .menu-toggle {
    display: inline-grid;
    place-items: center;
  }

  .nav,
  .userbox {
    display: none;
  }

  .sidebar.nav-open .nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    max-height: min(58vh, 460px);
    overflow-y: auto;
    padding: 8px 2px 4px 0;
  }

  .sidebar.nav-open .userbox {
    display: block;
    margin-top: 4px;
    padding: 8px 10px 0;
    border-top: 1px solid rgba(255,255,255,.14);
  }

  .sidebar.nav-open .nav button {
    min-height: 48px;
    padding: 9px 10px;
    grid-template-columns: 30px 1fr;
  }

  .content {
    min-width: 0;
  }
}

@media (max-width: 560px) {
  .sidebar.nav-open .nav {
    grid-template-columns: 1fr;
    max-height: 62vh;
  }

  .sidebar .brand p {
    display: none;
  }
}

/* v3.1 mejoras control operativo / ajuste rápido */
button.danger, .danger { background:#b00020 !important; color:#fff !important; border-color:#b00020 !important; }
button.danger.secondary { background:#fff !important; color:#b00020 !important; border-color:#b00020 !important; }
button.small { padding:6px 9px; font-size:12px; border-radius:8px; }
.row-highlight { animation: acmPulse 2.5s ease-in-out; outline:3px solid #ffbf00; }
@keyframes acmPulse { 0%,100%{background:transparent} 20%,80%{background:#fff2b8} }
.layout-card .layout-row { border-top:1px solid #e6edf3; padding:8px 0; }
.layout-card .layout-row:first-of-type { border-top:0; }
.row-actions.mini { gap:4px; flex-wrap:wrap; }
.row-actions.mini button { padding:5px 7px; font-size:11px; }

/* v3.4 menú organizado por submenús */
.nav-group { margin: 8px 0 12px; }
.nav-group-title { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,.55); padding: 8px 14px 5px; }
.nav-group button { margin-bottom: 5px; }


/* v4.1 menú responsive final */
.sidebar { overscroll-behavior: contain; }
.nav-group { min-width: 0; }
.nav-group-title { cursor: default; }
@media (max-width: 900px) {
  .sidebar.nav-open { position: sticky !important; top: 0; }
  .sidebar.nav-open .nav { display: block; }
  .sidebar.nav-open .nav-group { margin: 8px 0; }
  .sidebar.nav-open .nav-group-title { padding: 10px 12px 6px; }
  .sidebar.nav-open .nav button { width: 100%; margin: 5px 0; text-align: left; }
  .sidebar:not(.nav-open) .nav, .sidebar:not(.nav-open) .userbox { display:none!important; }
}
@media (min-width: 901px) {
  .menu-toggle { display: none !important; }
}

/* ── v5.2: KPIs dashboard mejorado ──────────────────────────── */
.metric.acmkpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.metric.acmkpi strong {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
}
.metric.acmkpi span {
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.metric.acmkpi small {
  font-size: 11px;
  color: var(--muted);
  opacity: .75;
}
.metric.acmkpi-sm {
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.metric.acmkpi-sm strong { font-size: 20px; font-weight: 700; color: var(--ink); }
.metric.acmkpi-sm span  { font-size: 11px; color: var(--muted); }

/* ── Búsqueda global ──────────────────────────────────────── */
.badge-type {
  display: inline-block;
  font-size: 11px;
  background: var(--soft);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 6px;
  margin-right: 6px;
  white-space: nowrap;
}
.search-result-row:hover { background: var(--soft); border-radius: 6px; }
#global-search-results { border-radius: 8px; }
#global-search-results .compact-item {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  transition: background .12s;
}
#global-search-results .compact-item:last-child { border-bottom: none; }

/* ── Botones de acción con color uniforme (sin !important) ── */
button.danger      { background: #b00020; color: #fff; border-color: #b00020; }
button.danger:hover{ background: #8c001a; }
button.danger.secondary { background: #fff; color: #b00020; border-color: #b00020; }

/* ══════════════════════════════════════════════════════════════
   RESPONSIVE TOUCH — FT-03 Campo (stepper) y FT-03 Cadena
   Targets táctiles mínimo 52px en mobile/tablet
   ══════════════════════════════════════════════════════════════ */

/* Paso activo del stepper en FT-03 Campo */
#field-stepper-panel {
  scroll-margin-top: 12px;
}

/* Botones de navegación del stepper */
#field-step-bar div div:first-child {
  transition: background .2s;
}

/* ── Touch targets globales en mobile ── */
@media (max-width: 768px) {

  /* Todos los inputs, selects y textareas: mínimo 52px, font-size 16px
     (evita zoom automático en iOS que ocurre con font-size < 16px) */
  input:not([type=checkbox]):not([type=radio]):not([type=range]),
  select,
  textarea {
    font-size: 16px !important;
    min-height: 52px;
    padding: 10px 12px;
    border-radius: 10px;
  }

  /* Botones táctiles */
  button, .btn, [role=button] {
    min-height: 52px;
    font-size: 15px;
    padding: 0 18px;
    border-radius: 10px;
  }

  /* Labels más espacio */
  label {
    font-size: 14px;
    margin-bottom: 12px;
    display: block;
  }

  /* Grids de 2 columnas → 1 columna en mobile */
  .grid.cols-2,
  .grid.cols-3,
  .grid.cols-4 {
    grid-template-columns: 1fr !important;
  }

  /* Secciones panel con más padding */
  .panel {
    padding: 14px 12px;
    margin-bottom: 10px;
  }

  /* Canvas de firma — más alto en mobile */
  canvas#fo_firma_cliente,
  canvas#fo_firma_muestreador,
  canvas#signature-pad,
  canvas#sampler-signature-pad {
    height: 160px !important;
  }

  /* Stepper paso 4 — botón guardar bien grande */
  #field-step-4 button:first-of-type {
    min-height: 64px;
    font-size: 17px;
  }

  /* Tabla de historial — scroll horizontal */
  .table-wrap, .table {
    overflow-x: auto;
    display: block;
    -webkit-overflow-scrolling: touch;
  }

  /* Métricas en una sola fila */
  .grid.cols-3 .metric {
    padding: 10px;
  }

  /* Botones de acción en fila → columna si hay muchos */
  .row-actions {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Quick-jump de FT-03 Cadena */
  .quick-jump button {
    flex: 1 1 calc(50% - 4px);
    min-height: 48px;
    font-size: 13px;
  }

  /* Panel de progreso FT-03 Cadena */
  .custody-progress-panel {
    padding: 12px;
  }

  /* Acciones sticky de muestras */
  .sticky-custody-actions {
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--soft, #f8f9fa);
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    margin-bottom: 8px;
  }

  /* Sample rows — stack vertical */
  .sample-row.grid.cols-5 {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .sample-row.grid.cols-5 > label:first-child,
  .sample-row.grid.cols-5 > label:last-of-type {
    grid-column: 1 / -1;
  }

  /* Topbar compacto */
  .topbar {
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 0;
  }
  .topbar h1 {
    font-size: 18px;
  }
}

/* ── Tablet: 769px - 1024px ── */
@media (min-width: 769px) and (max-width: 1024px) {
  input:not([type=checkbox]):not([type=radio]):not([type=range]),
  select {
    min-height: 48px;
    font-size: 15px;
  }
  button, .btn {
    min-height: 48px;
  }
  .grid.cols-4 {
    grid-template-columns: 1fr 1fr !important;
  }
  /* FT-03 Campo stepper — en tablet mostrar todo sin stepper */
  #field-step-bar {
    display: flex !important;
  }
}

/* ── Desktop: sin stepper visible como tal ── */
@media (min-width: 1025px) {
  /* Mostrar todos los pasos a la vez en desktop */
  #field-step-1,
  #field-step-2,
  #field-step-3,
  #field-step-4 {
    display: block !important;
  }
  /* Ocultar la barra de pasos en desktop */
  #field-step-bar {
    display: none !important;
  }
  #step-subtitle {
    display: none;
  }
  /* Ocultar botones de navegación paso a paso */
  #field-step-1 > div:last-child,
  #field-step-2 > div:last-child,
  #field-step-3 > div:last-child,
  #field-step-4 > div:last-child {
    display: none !important;
  }
}

/* ── Firma canvas touch — prevenir scroll al firmar ── */
canvas[id*="firma"], canvas[id*="signature"] {
  touch-action: none;
  cursor: crosshair;
}


/* ══════════════════════════════════════════════════
   MENÚ COLAPSABLE — toggle con botón o atajo
══════════════════════════════════════════════════ */
.sidebar-toggle-btn {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1100;
  background: var(--primary, #003E91);
  color: #fff;
  border: none;
  border-radius: 6px;
  width: 32px;
  height: 32px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: left 0.25s;
}
.sidebar-toggle-btn:hover { background: var(--primary-dark, #002060); }

/* Sidebar colapsado */
.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden !important;
  padding: 0 !important;
  border: none !important;
}
.sidebar.collapsed * { visibility: hidden; }

/* Contenido se expande cuando sidebar colapsa */
.app-shell { transition: grid-template-columns 0.25s; }
.sidebar.collapsed ~ .main-content,
.sidebar-collapsed {
  margin-left: 0 !important;
}

/* Botón de toggle dentro del sidebar */
.sidebar-toggle-inner {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 6px 8px 0;
}
.sidebar-toggle-inner button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted, #888);
  font-size: 18px;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}
.sidebar-toggle-inner button:hover { 
  background: var(--surface-2, #f0f0f0); 
  color: var(--primary, #003E91);
}
