:root {
  --bg: #070d1d;
  --panel: rgba(15, 25, 45, 0.88);
  --panel2: rgba(13, 22, 40, 0.96);
  --line: rgba(140, 165, 210, 0.22);
  --text: #f5f8ff;
  --muted: #9fb1ca;
  --cyan: #38c7ff;
  --green: #2fe59b;
  --yellow: #f5b945;
  --red: #ff4c5b;
  --shadow: 0 24px 70px rgba(0,0,0,.32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 10%, rgba(24, 203, 255, .18), transparent 28%),
    radial-gradient(circle at 76% 4%, rgba(160, 55, 255, .24), transparent 32%),
    linear-gradient(135deg, #071326, #060b18 55%, #101827);
  color: var(--text);
}
button, input, select { font: inherit; }
.hidden { display: none !important; }
.page { width: min(1180px, calc(100% - 32px)); margin: 0 auto; padding: 34px 0 60px; }
.login-shell { min-height: calc(100vh - 68px); display: grid; place-items: center; }
.login-card { width: min(480px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 28px; padding: 30px; box-shadow: var(--shadow); }
.brand-small { color: var(--cyan); font-weight: 900; letter-spacing: .18em; font-size: 13px; }
h1 { margin: 8px 0 4px; font-size: clamp(44px, 7vw, 72px); line-height: .95; letter-spacing: -0.06em; }
h2 { margin: 0; font-size: 22px; }
p { color: var(--muted); margin: 8px 0 0; }
strong { color: var(--text); }
.hero { display: flex; gap: 22px; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.top-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }
.status-pill { min-width: 275px; display: flex; align-items: center; gap: 13px; background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 17px 20px; box-shadow: var(--shadow); }
.status-pill strong { display: block; font-size: 17px; }
.status-pill small { color: var(--muted); display: block; margin-top: 2px; }
.dot { width: 16px; height: 16px; border-radius: 999px; background: var(--red); box-shadow: 0 0 0 8px rgba(255, 76, 91, .12); }
.status-pill.online .dot { background: var(--green); box-shadow: 0 0 0 8px rgba(47, 229, 155, .12); }
.status-pill.connecting .dot { background: var(--yellow); box-shadow: 0 0 0 8px rgba(245, 185, 69, .12); }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 18px; margin-bottom: 18px; box-shadow: var(--shadow); }
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.machine-toolbar { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: end; }
.machine-info { color: var(--muted); font-size: 14px; margin-top: 12px; }
.tabs { display: flex; gap: 10px; overflow-x: auto; padding: 8px 0 18px; }
.tab { white-space: nowrap; border: 1px solid var(--line); background: rgba(255,255,255,.05); color: var(--text); border-radius: 999px; padding: 11px 16px; font-weight: 900; cursor: pointer; }
.tab.active { background: var(--cyan); color: #04101c; border-color: transparent; }
.form-grid { display: grid; gap: 14px; }
.two-cols { grid-template-columns: 1fr 1fr; }
.span-2 { grid-column: span 2; }
label { display: grid; gap: 7px; color: var(--muted); font-weight: 800; font-size: 13px; letter-spacing: .06em; text-transform: uppercase; }
input, select { width: 100%; border: 1px solid var(--line); background: rgba(2, 8, 22, .82); color: var(--text); border-radius: 16px; padding: 14px 16px; outline: none; }
input:disabled { opacity: .72; }
input:focus, select:focus { border-color: rgba(56, 199, 255, .78); box-shadow: 0 0 0 4px rgba(56, 199, 255, .10); }
.btn { border: 1px solid var(--line); background: rgba(255,255,255,.06); color: var(--text); border-radius: 15px; padding: 13px 16px; font-weight: 900; cursor: pointer; transition: transform .15s ease, background .15s ease; }
.btn:hover { transform: translateY(-1px); background: rgba(255,255,255,.10); }
.btn.primary { background: var(--cyan); color: #04101c; border-color: transparent; }
.btn.ghost { background: transparent; }
.btn.danger-soft { color: #ffd7db; border-color: rgba(255,76,91,.35); background: rgba(255,76,91,.08); }
.btn.full { width: 100%; }
.cards-grid { display: grid; gap: 14px; }
.metrics-grid { grid-template-columns: repeat(4, 1fr); margin: 14px 0 26px; }
.metric-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 22px; padding: 20px; min-height: 126px; }
.metric-card span { color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 900; font-size: 13px; }
.metric-card strong { display: block; font-size: clamp(26px, 3.1vw, 38px); margin-top: 8px; letter-spacing: -0.04em; }
.metric-card small { color: var(--muted); }
.section-head { margin-bottom: 12px; }
.inks-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; }
.ink-card { position: relative; overflow: hidden; background: var(--panel2); border: 1px solid var(--line); border-radius: 22px; padding: 18px; min-height: 176px; }
.ink-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.ink-badge { width: 44px; height: 44px; border-radius: 15px; display: grid; place-items: center; font-size: 22px; font-weight: 950; color: #07101e; }
.ink-badge.K { color: #fff; background: #020617; border: 1px solid rgba(255,255,255,.14); }
.ink-badge.C { background: #17c4df; }
.ink-badge.M { background: #d746ef; }
.ink-badge.Y { background: #f5c400; }
.ink-badge.W { background: #e8eef8; }
.ink-state { color: var(--red); font-weight: 950; font-size: 12px; }
.ink-state.ok { color: var(--green); }
.ink-kg { font-size: 26px; font-weight: 950; }
.ink-ml { color: var(--muted); margin-top: 4px; }
.bar { height: 10px; background: rgba(150, 170, 205, .18); border-radius: 999px; overflow: hidden; margin-top: 14px; }
.bar > div { height: 100%; background: rgba(56,199,255,.9); width: 0%; }
.list { display: grid; gap: 10px; margin-top: 14px; }
.row-card { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center; background: var(--panel2); border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.row-card h3 { margin: 0 0 4px; }
.row-card p { margin: 0; font-size: 14px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.density-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.density-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 18px; padding: 14px; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; }
.alert { border-radius: 20px; padding: 16px 18px; margin-top: 16px; font-weight: 700; }
.alert.danger { background: rgba(255, 76, 91, .14); border: 1px solid rgba(255, 76, 91, .5); color: #fff0f2; }
.alert.ok { background: rgba(47, 229, 155, .12); border: 1px solid rgba(47, 229, 155, .38); color: #eafff6; }
@media (max-width: 980px) {
  .hero { align-items: flex-start; flex-direction: column; }
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .inks-grid, .density-grid { grid-template-columns: repeat(2, 1fr); }
  .machine-toolbar { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .page { width: min(100% - 22px, 1180px); padding-top: 20px; }
  .two-cols { grid-template-columns: 1fr; }
  .span-2 { grid-column: span 1; }
  .metrics-grid, .inks-grid, .density-grid { grid-template-columns: 1fr; }
  .panel-title-row { align-items: stretch; flex-direction: column; }
  .status-pill { min-width: 100%; }
  .row-card { grid-template-columns: 1fr; }
}
.setup-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; margin: 16px 0; }
.setup-card { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 16px; display: grid; gap: 12px; }
.setup-card.wide { grid-column: span 2; }
.setup-card span { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: 12px; font-weight: 900; }
.setup-card strong { font-size: 24px; word-break: break-word; }
.setup-card code { color: #d9edff; background: rgba(2, 8, 22, .82); border: 1px solid var(--line); border-radius: 14px; padding: 12px; word-break: break-all; }
.code-panel { background: rgba(2, 8, 22, .65); border: 1px solid var(--line); border-radius: 20px; padding: 16px; margin-top: 12px; }
.code-panel pre { margin: 0; white-space: pre-wrap; word-break: break-word; color: #d9edff; font-size: 14px; }
.note-box { margin-top: 14px; border: 1px solid rgba(245, 185, 69, .35); background: rgba(245, 185, 69, .09); border-radius: 18px; padding: 14px 16px; color: #fff8e8; }
@media (max-width: 620px) { .setup-grid { grid-template-columns: 1fr; } .setup-card.wide { grid-column: span 1; } }

.muted-text { color: var(--muted); margin: 10px 0 0; font-size: 14px; }
.config-unlock-row { align-items: center; justify-content: space-between; }
.config-unlock-row h2 { margin: 0 0 4px; }
.config-unlock-row p { margin: 0; color: var(--muted); }
.machine-toolbar { grid-template-columns: 1fr; }

/* Inventario de bodega */
.withdrawal-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.scan-box { background: var(--panel2); border: 1px solid var(--line); border-radius: 20px; padding: 16px; display: grid; gap: 12px; }
.selected-worker { border: 1px dashed rgba(56,199,255,.35); background: rgba(56,199,255,.08); border-radius: 16px; padding: 13px 14px; color: var(--muted); font-weight: 800; }
.selected-worker.active { color: #eafff6; border-color: rgba(47,229,155,.55); background: rgba(47,229,155,.10); }

.entry-item-preview { margin-top: 0; }
.entry-item-preview.error { color: #ffd7db; border-color: rgba(255,76,91,.55); background: rgba(255,76,91,.10); }
.entry-item-preview.warning { color: #fff7df; border-color: rgba(245,185,69,.52); background: rgba(245,185,69,.12); }
.entry-item-preview strong { color: var(--text); }
.entry-item-preview span { color: var(--muted); }
.stock-pill { display: inline-flex; align-items: center; gap: 6px; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 950; border: 1px solid var(--line); background: rgba(255,255,255,.06); }
.stock-pill.ok { color: #eafff6; border-color: rgba(47,229,155,.36); background: rgba(47,229,155,.10); }
.stock-pill.low { color: #fff7df; border-color: rgba(245,185,69,.44); background: rgba(245,185,69,.12); }
.stock-pill.inactive { color: #ffd7db; border-color: rgba(255,76,91,.44); background: rgba(255,76,91,.10); }
.movement-type { display: inline-block; min-width: 52px; text-align: center; border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 950; }
.movement-type.out { background: rgba(255,76,91,.14); color: #ffd7db; border: 1px solid rgba(255,76,91,.35); }
.movement-type.in { background: rgba(47,229,155,.12); color: #eafff6; border: 1px solid rgba(47,229,155,.35); }
.row-card.compact { grid-template-columns: 1fr; }
.row-card .muted { color: var(--muted); font-size: 13px; }
.row-card .big-stock { font-size: 24px; font-weight: 950; letter-spacing: -.03em; }
.qty-input { max-width: 130px; padding: 10px 12px; border-radius: 12px; }
.check-label { display: flex; align-items: center; gap: 10px; min-height: 50px; }
.check-label input[type="checkbox"] { width: auto; transform: scale(1.15); }
@media (max-width: 820px) { .withdrawal-layout { grid-template-columns: 1fr; } }

/* Resumen por trabajador */
.history-actions { align-items: center; }
.worker-summary-card h3 { display: flex; gap: 8px; flex-wrap: wrap; align-items: baseline; }
.summary-total { color: #eafff6; font-weight: 900; margin-top: 6px; }
.summary-list { margin: 10px 0 0; padding-left: 18px; color: var(--muted); display: grid; gap: 5px; }
.summary-list strong { color: var(--text); }
.muted-inline { color: var(--muted); font-size: 13px; font-weight: 800; }

.role-hidden { display: none !important; }
.role-badge {
  min-width: 210px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.role-badge strong { display: block; font-size: 14px; }
.role-badge small { display: block; color: var(--muted); margin-top: 3px; word-break: break-word; }
.role-badge.warehouse { border-color: rgba(47, 229, 155, .35); background: rgba(47, 229, 155, .08); }
.role-badge.operator { border-color: rgba(59, 130, 246, .35); background: rgba(59, 130, 246, .08); }
.role-badge.production { border-color: rgba(250, 204, 21, .35); background: rgba(250, 204, 21, .08); }
.keeper-box {
  border: 1px solid rgba(47, 229, 155, .28);
  background: rgba(47, 229, 155, .08);
  border-radius: 18px;
  padding: 14px 16px;
  color: var(--muted);
  margin-bottom: 14px;
}
.keeper-box strong { color: var(--text); }
.keeper-box span { color: var(--muted); }
@media (max-width: 720px) {
  .role-badge { width: 100%; }
}


/* Cadena de custodia de materiales */
.custody-balance-card { border-left: 4px solid rgba(56,199,255,.72); }
.transfer-card { border-left: 4px solid rgba(148,163,184,.45); }
.transfer-card.status-pending { border-left-color: rgba(245,185,69,.85); }
.transfer-card.status-received { border-left-color: rgba(47,229,155,.82); }
.transfer-card.status-rejected, .transfer-card.status-cancelled, .transfer-card.status-waste { border-left-color: rgba(255,76,91,.78); }
.transfer-card.status-consumed { border-left-color: rgba(139,92,246,.85); }
.custody-balance-card .big-stock { margin-top: 8px; color: #eafff6; }
#custodyWorkerSelectWrap { margin-top: 14px; }
#materialTransferForm { margin-top: 14px; }
@media (max-width: 760px) {
  .custody-balance-card .row-actions, .transfer-card .row-actions { justify-content: stretch; }
  .custody-balance-card .row-actions .btn, .transfer-card .row-actions .btn { flex: 1; }
}


/* v21 · Tarjetas y códigos únicos de trabajadores */
.barcode-input-row{display:flex;gap:10px;align-items:center}.barcode-input-row input{flex:1;font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-weight:800;letter-spacing:1.2px;background:var(--surface-2,#f4f7fb)}
.worker-barcode-preview{min-height:116px;border:1px dashed #9aa9bd;border-radius:16px;background:#fff;color:#111;padding:12px;display:flex;flex-direction:column;align-items:center;justify-content:center;overflow:hidden}.worker-barcode-preview span{color:#667085}.worker-barcode-preview .worker-barcode-svg{width:min(100%,520px);height:78px}.barcode-preview-code{font-family:ui-monospace,SFMono-Regular,Consolas,monospace;font-size:14px;font-weight:800;letter-spacing:1.5px;margin-top:4px}.worker-card-row .row-actions{max-width:520px}.warning-soft{background:#fff4d6!important;color:#8a5700!important;border-color:#f0cc72!important}.warning-soft:hover{background:#ffeab0!important}
@media(max-width:720px){.barcode-input-row{align-items:stretch;flex-direction:column}.barcode-input-row .btn{width:100%}.worker-card-row .row-actions{max-width:none}}

/* v24 · Layout de ancho completo y navegación por módulos */
html { min-width: 320px; }
body { overflow-x: hidden; }
.page {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: clamp(16px, 2.2vw, 34px);
}
.app-shell { width: 100%; max-width: none; }
.hero {
  width: 100%;
  padding: 0 2px;
  margin-bottom: 22px;
}
.hero h1 { font-size: clamp(36px, 4.2vw, 66px); }
.hero > div:first-child { max-width: 820px; }
.workspace {
  display: grid;
  grid-template-columns: minmax(250px, 292px) minmax(0, 1fr);
  gap: clamp(16px, 1.8vw, 28px);
  align-items: start;
  width: 100%;
}
.sidebar {
  position: sticky;
  top: 18px;
  min-width: 0;
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: rgba(9, 17, 33, .92);
  box-shadow: var(--shadow);
  scrollbar-width: thin;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 4px 16px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.sidebar-brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 14px;
  background: linear-gradient(145deg, var(--cyan), #8a5cff);
  color: #04101c;
  font-size: 21px;
  font-weight: 950;
}
.sidebar-brand strong, .sidebar-brand small { display: block; }
.sidebar-brand small { color: var(--muted); margin-top: 2px; }
.tabs {
  display: grid;
  gap: 12px;
  overflow: visible;
  padding: 0;
}
.nav-module {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid rgba(140, 165, 210, .16);
  border-radius: 20px;
  background: rgba(255,255,255,.025);
}
.nav-module-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 4px 8px;
}
.nav-module-title strong, .nav-module-title small { display: block; }
.nav-module-title strong { font-size: 14px; }
.nav-module-title small { color: var(--muted); font-size: 11px; margin-top: 2px; }
.nav-module-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  flex: 0 0 30px;
  border-radius: 10px;
  background: rgba(56,199,255,.11);
  color: var(--cyan);
  font-weight: 950;
}
.nav-module-links { display: grid; gap: 6px; }
.tab {
  width: 100%;
  min-width: 0;
  display: grid;
  gap: 2px;
  text-align: left;
  white-space: normal;
  border-radius: 14px;
  padding: 11px 12px;
  font-weight: 800;
}
.tab span { font-size: 14px; }
.tab small { color: var(--muted); font-size: 11px; font-weight: 650; }
.tab.active {
  background: linear-gradient(135deg, rgba(56,199,255,.98), rgba(116,213,255,.9));
  box-shadow: 0 10px 24px rgba(56,199,255,.18);
}
.tab.active span { color: #04101c; }
.tab.active small { color: rgba(4,16,28,.72); }
.workspace-main { min-width: 0; width: 100%; }
.content-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 88px;
  padding: 5px 2px 18px;
}
.content-heading h2 { font-size: clamp(27px, 3vw, 40px); letter-spacing: -.035em; }
.content-heading p { max-width: 760px; }
.content-eyebrow {
  display: block;
  margin-bottom: 5px;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 950;
  letter-spacing: .15em;
  text-transform: uppercase;
}
.machine-panel { margin-bottom: 20px; }
.tab-page { width: 100%; min-width: 0; }
.panel { width: 100%; }
.context-hidden { display: none !important; }

/* Aprovecha el ancho disponible sin estirar en exceso los controles */
.metrics-grid { grid-template-columns: repeat(4, minmax(180px, 1fr)); }
.inks-grid { grid-template-columns: repeat(5, minmax(170px, 1fr)); }
.density-grid { grid-template-columns: repeat(5, minmax(160px, 1fr)); }
.row-card { min-width: 0; }
.row-card > * { min-width: 0; }

@media (min-width: 1500px) {
  .workspace { grid-template-columns: 300px minmax(0, 1fr); }
  .page { padding-left: 38px; padding-right: 38px; }
  .panel { padding: 22px; }
  .metrics-grid { gap: 18px; }
  .inks-grid, .density-grid { gap: 18px; }
}

@media (max-width: 1180px) {
  .workspace { grid-template-columns: 235px minmax(0, 1fr); gap: 16px; }
  .sidebar { padding: 12px; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inks-grid, .density-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .page { padding: 16px; }
  .workspace { grid-template-columns: 1fr; }
  .sidebar {
    position: static;
    max-height: none;
    overflow: visible;
    padding: 12px;
  }
  .sidebar-brand { display: none; }
  .tabs { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .nav-module { align-content: start; }
  .content-heading { min-height: 0; padding-top: 18px; }
}

@media (max-width: 620px) {
  .page { width: 100%; padding: 12px; }
  .hero { gap: 16px; }
  .hero h1 { font-size: 39px; }
  .top-actions { width: 100%; justify-content: stretch; }
  .top-actions > * { width: 100%; }
  .tabs { grid-template-columns: 1fr; }
  .nav-module-links { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tab { min-height: 63px; }
  .content-heading h2 { font-size: 29px; }
  .metrics-grid, .inks-grid, .density-grid { grid-template-columns: 1fr; }
}

@media (max-width: 430px) {
  .nav-module-links { grid-template-columns: 1fr; }
  .panel { border-radius: 20px; padding: 15px; }
  .metric-card, .ink-card { border-radius: 18px; }
}
