:root {
  --navy: #173f68;
  --navy-deep: #102f50;
  --blue: #245b88;
  --red: #d9283a;
  --green: #218c3a;
  --bg: #edf2f7;
  --paper: #ffffff;
  --line: #dfe7ee;
  --muted: #8496a4;
  --text: #25384a;
  font-family: "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--bg); }
body { margin: 0; min-width: 320px; background: var(--bg); color: var(--text); }
a { color: inherit; text-decoration: none; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

/* Barra superior exactamente con la estructura del sistema local de referencia. */
.app { display: block; min-height: 100vh; background: var(--bg); }
.side {
  width: auto;
  min-height: 0;
  position: relative;
  margin: 20px 28px 0;
  padding: 23px 26px 17px;
  display: grid;
  grid-template-columns: minmax(260px, 1fr) auto auto;
  grid-template-rows: auto auto auto;
  align-items: center;
  gap: 0 12px;
  background: linear-gradient(135deg, #102f50 0%, #1b4f7a 65%, #286b99 100%);
  border-radius: 23px;
  box-shadow: 0 15px 32px #173f6833;
  color: #fff;
}
.brand {
  grid-column: 1;
  grid-row: 1;
  color: #fff;
  font-size: 24px;
  line-height: 1;
  letter-spacing: .6px;
  font-weight: 800;
}
.brand::before {
  content: "RGZ";
  display: inline-flex;
  width: 46px;
  height: 46px;
  margin-right: 10px;
  align-items: center;
  justify-content: center;
  border-radius: 15px;
  background: #fff;
  color: var(--navy);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  vertical-align: middle;
  box-shadow: 0 5px 14px #071b2e44;
}
.side .sub {
  grid-column: 1;
  grid-row: 2;
  padding: 0 0 12px 57px;
  margin: 6px 0 0;
  color: #c5d8e8;
  font-size: 12px;
}
.side > .btn {
  width: auto;
  margin: 0;
  padding: 11px 15px;
  border-radius: 9px;
  font-size: 10px;
  box-shadow: none;
}
.side > .btn.blue { grid-column: 2; grid-row: 1; background: #ffffff18; color: #fff; border: 1px solid #ffffff50; }
.side > .btn.red { grid-column: 3; grid-row: 1; background: #e32a3e; }
.side h3 {
  grid-column: 1 / -1;
  grid-row: 3;
  margin: 10px 0 3px;
  padding: 12px 0 0;
  color: #c7d9e8;
  border-top: 1px solid #ffffff2b;
  font-size: 10px;
  letter-spacing: 1.5px;
}
.catlist {
  grid-column: 1 / -1;
  grid-row: 4;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 7px;
  overflow: visible;
  padding: 6px 0 0;
}
.cat {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 0;
  padding: 10px 12px;
  border: 1px solid #ffffff2b;
  border-radius: 10px;
  background: #ffffff12;
  color: #e7f0f7;
  font-size: 11px;
  font-weight: 700;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.cat-name { min-width: 0; display: flex; align-items: center; gap: 7px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-icon { display: inline-flex; width: 23px; height: 23px; flex: 0 0 23px; align-items: center; justify-content: center; border-radius: 7px; background: #ffffff1f; font-size: 14px; line-height: 1; }
.cat-arrow { flex: 0 0 auto; font-size: 16px; line-height: 1; opacity: .85; }
.cat:hover { background: #ffffff22; border-color: #ffffff60; transform: translateY(-1px); }
.cat.active { background: #fff; color: var(--navy); border-color: #fff; box-shadow: 0 5px 12px #071b2e33; }
.cat.active .cat-icon { background: #edf5fa; }
.empty-side { padding: 10px 12px; color: #c5d8e8; font-size: 12px; }
.footer-note { display: none; }

.main { max-width: none; min-width: 0; padding: 22px 28px 44px; background: transparent; }
.top { max-width: 1500px; margin: 0 auto 20px; padding: 0 4px 2px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; background: transparent; }
.title { color: var(--navy); font-size: 31px; font-weight: 800; line-height: 1.05; letter-spacing: -.6px; }
.title::before { content: "ESPACIO DE TRABAJO"; display: block; margin-bottom: 7px; color: #91a2b1; font-size: 10px; letter-spacing: 1.8px; }
.top-sub { margin-top: 6px; color: #8193a2; font-size: 13px; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.restore-form { display: none; margin: 0; }
.logout-form { margin: 0; }
.btn {
  display: inline-flex;
  min-height: 39px;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
  border: 0;
  border-radius: 9px;
  color: #fff;
  cursor: pointer;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .1px;
  line-height: 1;
  box-shadow: 0 4px 10px #173f6813;
  transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}
.btn:hover { filter: brightness(1.06); transform: translateY(-1px); box-shadow: 0 7px 15px #173f6826; }
.btn:active { transform: translateY(0); }
.btn.green { background: #218c3a; }
.btn.blue { background: var(--blue); }
.btn.red { background: var(--red); }
.btn.gray { background: #7b8e9d; }
.btn.access { background: #ffffff18; border: 1px solid #ffffff50; color: #fff; }
.actions .btn.access { background: #fff; border: 1px solid #c6d5df; color: var(--navy); }
.actions .btn.access:hover { background: #f1f7fb; border-color: #8eabc0; }
.logout-action { min-width: 55px; padding-inline: 11px; }

.card { max-width: 1500px; margin: 0 auto 18px; border: 1px solid #dfe7ee; border-radius: 20px; background: #fff; box-shadow: 0 13px 32px #173f6812; }
.welcome { min-height: 470px; padding: 50px 40px; text-align: center; }
.welcome h2 { margin: 0 0 10px; color: var(--navy); font-size: 32px; }
.welcome > p { margin: 0; color: #8496a4; }
.home-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 15px; margin: 25px 0; text-align: left; }
.category-card { position: relative; overflow: hidden; padding: 20px; border: 1px solid #dce6ed; border-radius: 14px; background: #fff; box-shadow: 0 8px 18px #173f680d; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.category-card:hover { transform: translateY(-3px); border-color: #9fbfd1; box-shadow: 0 13px 24px #173f6818; }
.category-card::after { content: "↗"; position: absolute; top: 17px; right: 18px; color: var(--red); font-size: 19px; }
.category-card-link { display: block; }
.category-card h3 { display: flex; align-items: center; gap: 9px; margin: 0 0 8px; padding-right: 22px; color: var(--navy); font-size: 18px; }
.category-card p { margin: 0 0 15px; color: #8797a3; font-size: 13px; }
.category-card-icon { display: inline-flex; width: 32px; height: 32px; flex: 0 0 32px; align-items: center; justify-content: center; border-radius: 10px; background: #edf5fa; font-size: 19px; line-height: 1; }
.category-card-actions { display: flex; align-items: center; gap: 6px; }
.category-card-actions form { margin: 0; }
.category-card-actions .btn { min-height: 32px; padding: 8px 10px; border-radius: 7px; font-size: 10px; box-shadow: none; }
.delete-category { background: #f7e4e7; color: #c12636; }
.home-add-category { margin-top: 4px; }
.empty-state { padding: 45px 20px; border: 1px dashed #cad9e4; border-radius: 13px; background: #fbfdff; }
.empty-icon { display: grid; width: 48px; height: 48px; margin: 0 auto 14px; place-items: center; border-radius: 50%; background: #edf5fa; color: var(--blue); font-size: 26px; }
.empty-state h3 { margin: 0 0 6px; color: var(--navy); font-size: 18px; }
.empty-state p { margin: 0 0 17px; color: var(--muted); font-size: 13px; }

.toolbar { display: flex; align-items: center; gap: 8px; padding: 19px 20px 14px; background: #fff; border-bottom: 1px solid #edf2f5; }
.search-form { position: relative; display: flex; flex: 1; min-width: 240px; }
.search { width: 100%; height: 45px; padding: 0 110px 0 16px; border: 1px solid #d5e0e7; border-radius: 10px; outline: none; background: #f9fbfc; color: var(--text); font-size: 13px; }
.search::placeholder { color: #9babb9; }
.search:focus { border-color: #2a6b99; outline: 3px solid #2a6b991c; background: #fff; }
.clear-search { position: absolute; top: 50%; right: 54px; transform: translateY(-50%); color: var(--red); font-size: 10px; font-weight: 800; }
.search-button { position: absolute; top: 50%; right: 8px; display: grid; width: 34px; height: 34px; padding: 0; place-items: center; border: 0; border-radius: 9px; background: #eaf3f8; color: var(--navy); cursor: pointer; line-height: 1; transform: translateY(-50%); transition: background .15s ease, color .15s ease, transform .15s ease; }
.search-icon { position: relative; display: block; width: 13px; height: 13px; border: 2px solid currentColor; border-radius: 50%; }
.search-icon::after { content: ""; position: absolute; right: -6px; bottom: -3px; width: 7px; height: 2px; border-radius: 2px; background: currentColor; transform: rotate(45deg); transform-origin: left center; }
.search-button:hover { background: var(--blue); color: #fff; transform: translateY(-50%) scale(1.04); }
.search-button:focus-visible { outline: 3px solid #245b8830; outline-offset: 2px; }
.hint { display: flex; align-items: center; gap: 8px; margin: 0 20px 16px; color: #8496a4; font-size: 11px; line-height: 1.35; }
.hint-icon { display: inline-grid; width: 20px; height: 20px; flex: 0 0 20px; place-items: center; border-radius: 50%; background: #edf5fa; color: var(--blue); font-weight: 800; }

/* Tabla: compacta, legible y con una jerarquía visual clara entre datos y precios. */
.table-wrap { position: relative; padding: 0 11px 14px; overflow-x: auto; overflow-y: visible; border-radius: 0 0 20px 20px; background: #fbfdff; scrollbar-color: #8c9aa6 #edf2f7; scrollbar-width: thin; }
.table-wrap::-webkit-scrollbar { height: 13px; }
.table-wrap::-webkit-scrollbar-track { background: #edf2f7; border-radius: 10px; }
.table-wrap::-webkit-scrollbar-thumb { background: #8998a5; border: 3px solid #edf2f7; border-radius: 10px; }
.table { width: 100%; min-width: 1450px; border-collapse: separate; border-spacing: 0 3px; table-layout: fixed; }
.table thead { position: static; }
.table th { height: 56px; padding: 8px 6px; border-top: 3px solid #245b88; border-right: 1px solid #2f6a94; border-bottom: 0; background: linear-gradient(180deg, #245b88 0%, #173f68 100%); color: #fff; font-size: 9px; font-weight: 800; letter-spacing: .42px; line-height: 1.15; text-align: center; text-transform: uppercase; vertical-align: middle; box-shadow: 0 5px 12px #173f681a; }
.table th.price-head { border-top-color: #e33446; border-right-color: #dc5261; background: linear-gradient(180deg, #e33446 0%, #d21f35 100%); color: #fff; }
.table th.options-header { border-top-color: #6f8494; border-right-color: #8093a1; background: linear-gradient(180deg, #7c8e9d 0%, #657987 100%); color: #fff; }
.table th:first-child { border-radius: 9px 0 0 9px; }
.table th:last-child { border-radius: 0 9px 9px 0; }
.table .col-product { width: 14%; }
.table .col-image { width: 12%; }
.table .col-code { width: 5.5%; }
.table .col-measure { width: 7%; }
.table .col-qty { width: 5.5%; }
.table .col-unit { width: 7%; }
.table .col-doc { width: 7%; }
.table .col-bulk { width: 10%; }
.table .col-pack { width: 7%; }
.table .col-major { width: 8%; }
.table .col-dist { width: 11%; }
.table .col-options { width: 4%; }
.table.public-table .col-product { width: 14%; }
.table.public-table .col-image { width: 12%; }
.table.public-table .col-code { width: 5.7%; }
.table.public-table .col-measure { width: 7.2%; }
.table.public-table .col-qty { width: 5.8%; }
.table.public-table .col-unit { width: 7.5%; }
.table.public-table .col-doc { width: 7.5%; }
.table.public-table .col-bulk { width: 10.5%; }
.table.public-table .col-pack { width: 7.5%; }
.table.public-table .col-major { width: 8.5%; }
.table.public-table .col-dist { width: 11.3%; }
.table th.options-header, .table td.options-cell { width: 4%; min-width: 58px; }
.table td { height: 54px; padding: 6px 8px; border-top: 1px solid #dbe6ed; border-bottom: 1px solid #dbe6ed; background: #fff; vertical-align: middle; }
.table td:first-child { border-left: 1px solid #e0e8ee; border-radius: 11px 0 0 11px; }
.table td:last-child { border-right: 1px solid #e0e8ee; border-radius: 0 11px 11px 0; }
.table tbody tr:hover td { background: #f7fbfd; }
.product-cell { color: var(--navy); background: #f4f9fc !important; border-left: 3px solid #2b6793 !important; font-size: 12px; font-weight: 800; line-height: 1.3; text-align: center; }
.img-cell { padding: 7px !important; background: #edf6fb !important; text-align: center; }
.img-cell img { display: block; width: 140px; height: 70px; margin: 0 auto; padding: 3px; border: 1px solid #cddfe9; border-radius: 10px; background: #fff; box-shadow: 0 4px 10px #173f6814; object-fit: contain; }
.muted { color: #9aabb8; font-size: 11px; text-align: center; }
.table td:not(.product-cell):not(.img-cell):not(.options-cell):not(.table-empty):not(.empty-variant) { padding: 6px 8px; }
.inline-input { width: 100%; height: 34px; min-height: 34px; padding: 7px 7px; border: 1px solid transparent; border-radius: 9px; outline: none; color: var(--text); font-size: 11.5px; text-align: center; }
.code-input, .measure-input, .qty-input { background: #f5f9fc; }
.price { background: #fff3f5; color: #7f2530; }
.inline-input[readonly] { cursor: default; user-select: text; }
.inline-input:hover { border-color: #c3d3df; }
.inline-input.is-editing { cursor: text; border-color: #2f6f9f; outline: 3px solid #2f6f9f20; background: #fff; }
.options-cell { width: 76px; min-width: 76px; padding: 6px 4px !important; background: #f8fafc !important; text-align: center; }
.options-cell form { display: inline; margin: 0; }
.icon-button { display: inline-grid; width: 29px; height: 29px; margin: 2px; padding: 0; place-items: center; border: 0; border-radius: 8px; background: #fae5e8; color: #c02536; cursor: pointer; font-size: 15px; }
.icon-button:hover { filter: brightness(.96); transform: translateY(-1px); }
.empty-variant { color: var(--muted); font-size: 12px; text-align: center; }
.table-empty { padding: 55px 20px !important; color: var(--muted); text-align: center; }
.table-empty span { display: block; color: var(--blue); font-size: 27px; }
.table-empty strong, .table-empty small { display: block; }
.table-empty strong { margin-top: 7px; color: var(--navy); font-size: 14px; }
.table-empty small { margin-top: 4px; font-size: 12px; }

/* Banda fija: reutiliza exactamente el mismo encabezado, anchos y estilos de la tabla normal. */
#rgzPinnedHeader { position: fixed; top: 0; left: 0; z-index: 80; display: none; overflow: hidden; pointer-events: none; background: transparent; }
#rgzPinnedHeader .pinned-table { width: 100%; min-width: 0; margin: 0; transform-origin: top left; will-change: transform; }
#rgzPinnedHeader .pinned-table thead { position: static; }
#rgzPinnedHeader .pinned-table th { position: static; }

.message-stack { display: grid; gap: 8px; max-width: 1500px; margin: 0 auto 15px; }
.server-message { padding: 11px 14px; border-radius: 9px; font-size: 12px; font-weight: 600; }
.server-message-success { border: 1px solid #bcebd0; background: #e8f8ef; color: #116544; }
.server-message-error { border: 1px solid #ffcbd3; background: #fff4f5; color: #a02338; }
.toast-region { position: fixed; right: 24px; bottom: 24px; z-index: 200; width: min(360px, calc(100vw - 48px)); }
.toast { padding: 12px 16px; border-radius: 10px; background: var(--navy); color: #fff; box-shadow: 0 9px 24px #173f6840; font-size: 13px; font-weight: 700; animation: toast-in .18s ease; }
.toast.error { background: #a32938; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Formularios de categoría y producto. */
.form-page { max-width: 1040px; margin: 0 auto; }
.back-link { display: inline-block; margin: 0 0 16px; color: var(--blue); font-size: 12px; font-weight: 800; }
.form-card { padding: 24px; border: 1px solid #dfe7ee; border-radius: 16px; background: #fff; box-shadow: 0 13px 32px #173f6812; }
.narrow-card { max-width: 650px; margin-inline: auto; }
.form-card-heading { display: flex; align-items: center; gap: 14px; padding-bottom: 20px; margin-bottom: 22px; border-bottom: 1px solid #edf2f5; }
.form-card-heading h1 { margin: 0 0 5px; color: var(--navy); font-size: 28px; }
.form-card-heading .title-icon { display: grid; width: 46px; height: 46px; place-items: center; border-radius: 13px; background: #edf5fa; color: var(--navy); font-size: 23px; }
.eyebrow { margin: 0 0 5px; color: #91a2b1; font-size: 10px; font-weight: 800; letter-spacing: 1.4px; }
.subtitle { margin: 0; color: var(--muted); font-size: 13px; }
.stack-form { display: grid; gap: 20px; }
.product-main-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.field-group { display: grid; gap: 6px; }
.field-group label, .field label { color: #718599; font-size: 11px; font-weight: 800; }
.form-control { width: 100%; min-height: 40px; padding: 9px 11px; border: 1px solid #ccd9e5; border-radius: 9px; outline: none; background: #fbfdff; color: var(--text); }
.form-control:focus { border-color: var(--blue); outline: 3px solid #245b8820; }
.field-error { color: var(--red); font-size: 11px; }
.variants-heading { display: flex; align-items: end; justify-content: space-between; gap: 12px; }
.variants-heading h2 { margin: 0; color: var(--navy); font-size: 20px; }
.variants-heading > span { color: var(--muted); font-size: 12px; }
.variant-editor-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 11px; }
.variant-editor { width: 1100px; border-collapse: collapse; }
.variant-editor th { padding: 11px 8px; background: var(--navy); color: #fff; font-size: 10px; line-height: 1.15; text-align: center; }
.variant-editor td { padding: 6px; border-top: 1px solid var(--line); background: #fbfdff; }
.variant-form-row.is-deleted { display: none; }
.variant-editor .form-control { min-width: 100px; min-height: 38px; padding: 6px 8px; font-size: 12px; }
.delete-cell { width: 75px; text-align: center; }
.delete-cell input { accent-color: var(--red); }
.remove-variant { display: inline-flex; align-items: center; gap: 4px; color: #b82a3a; font-size: 10px; cursor: pointer; }
.remove-variant input { display: none; }
.remove-variant::before { content: "×"; display: inline-grid; width: 24px; height: 24px; place-items: center; border-radius: 7px; background: #fae5e8; font-size: 16px; }
.variant-add-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.variant-add-note { color: var(--muted); font-size: 11px; }
.form-actions { display: flex; justify-content: flex-end; gap: 9px; padding-top: 2px; }
.button-ghost { display: inline-flex; align-items: center; min-height: 39px; padding: 10px 14px; border: 1px solid #cddbe6; border-radius: 9px; color: var(--navy); font-size: 11px; font-weight: 800; }

.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 10% 10%, #dcecf8, transparent 35%), var(--bg); }
.login-card { width: min(410px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 19px; background: #fff; box-shadow: 0 22px 55px #173f6822; }
.login-mark { display: grid; width: 57px; height: 57px; margin-bottom: 22px; place-items: center; border-radius: 17px; background: var(--navy); color: #fff; font-size: 18px; font-weight: 900; }
.login-card h1 { margin: 0 0 8px; color: var(--navy); font-size: 31px; }
.login-form { display: grid; gap: 8px; margin-top: 25px; }
.login-form label { margin-top: 8px; color: var(--navy); font-size: 12px; font-weight: 800; }
.login-form input { min-height: 43px; padding: 9px 11px; border: 1px solid #cfdde8; border-radius: 9px; outline: none; }
.login-form input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #245b8818; }
.login-submit { width: 100%; margin-top: 15px; }
.form-error { padding: 10px 12px; border: 1px solid #ffcbd3; border-radius: 9px; background: #fff4f5; color: #a02338; font-size: 12px; }

.back-to-top { position: fixed; right: 24px; bottom: 24px; z-index: 90; display: grid; width: 44px; height: 44px; place-items: center; border: 0; border-radius: 50%; background: var(--navy); color: #fff; cursor: pointer; box-shadow: 0 8px 20px #173f6840; font-size: 23px; line-height: 1; opacity: 0; visibility: hidden; transform: translateY(10px); transition: opacity .2s ease, visibility .2s ease, transform .2s ease, background .2s ease; }
.back-to-top.visible { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { background: var(--blue); }

@media (max-width: 900px) {
  .side { margin: 12px 12px 0; padding: 18px 17px; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto auto; }
  .brand { grid-column: 1; grid-row: 1; }
  .side .sub { grid-column: 1; grid-row: 2; padding-left: 0; }
  .side > .btn.blue { grid-column: 2; grid-row: 1; }
  .side > .btn.red { grid-column: 2; grid-row: 2; }
  .side h3 { grid-column: 1 / -1; grid-row: 3; }
  .catlist { grid-column: 1 / -1; grid-row: 4; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .main { padding: 20px 12px 35px; }
  .top { align-items: flex-start; flex-direction: column; gap: 14px; }
  .actions { width: 100%; justify-content: flex-start; }
  .actions .btn { flex: 1; }
  .toolbar { align-items: stretch; flex-wrap: wrap; }
  .search-form { min-width: 100%; }
  .product-main-fields { grid-template-columns: 1fr; }
  #rgzPinnedHeader .pinned-cell { height: 49px; padding: 7px; font-size: 8.5px; }
  #rgzPinnedHeader { height: 49px; }
}

@media (max-width: 560px) {
  .side { margin: 8px 9px 0; padding: 14px 13px; border-radius: 17px; }
  .brand { font-size: 20px; }
  .brand::before { width: 40px; height: 40px; margin-right: 7px; }
  .side .sub { font-size: 11px; }
  .title { font-size: 27px; }
  .welcome { padding: 38px 17px; }
  .welcome h2 { font-size: 28px; }
  .actions .btn { padding-inline: 9px; font-size: 9px; }
  .form-card { padding: 18px; }
  .form-actions { flex-wrap: wrap; }
  .back-to-top { right: 14px; bottom: 14px; }
}
