:root {
  --ink: #1C2230; --muted: #5B6475; --line: #E2E5EA; --bg: #F5F6F8; --card: #FFFFFF;
  --navy: #1F3A5F; --navy-2: #2B4C78; --accent: #B4561B; --accent-bg: #FBEDE2;
  --ok: #1E7A4C; --low: #9A5B00; --out: #8A2B2B;
  --radius: 12px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); color: var(--ink); background: var(--bg); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
a { color: var(--navy); }
:focus-visible { outline: 3px solid #7FA6D9; outline-offset: 2px; }

/* Barra superior */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 12px 20px; display: flex; gap: 20px; align-items: center; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; font-size: 17px; white-space: nowrap; }
.brand b { font-weight: 700; }
.search { flex: 1; position: relative; max-width: 720px; }
.search svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; fill: none; stroke: #5B6475; stroke-width: 2.2; stroke-linecap: round; }
.search input { width: 100%; height: 44px; border-radius: 22px; border: 0; padding: 0 18px 0 42px; background: #fff; color: var(--ink); }
.usernav { display: flex; align-items: center; gap: 16px; white-space: nowrap; }
.usernav .linkbtn { color: #fff; }
.username { color: #C9D6E8; font-size: 14px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; }
.linkbtn { display: inline-flex; align-items: center; background: none; border: 0; padding: 6px 0; cursor: pointer; color: var(--navy); text-decoration: underline; text-underline-offset: 3px; min-height: 44px; }
.notice { background: var(--accent-bg); color: #6B3410; text-align: center; padding: 10px 16px; font-size: 14px; border-bottom: 1px solid #EBC9AE; }

/* Estructura */
.layout { max-width: 1400px; margin: 0 auto; padding: 24px 20px 48px; display: grid; grid-template-columns: 260px minmax(0, 1fr); gap: 28px; }
.filters { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; align-self: start; position: sticky; top: 92px; max-height: calc(100vh - 110px); overflow: auto; }
.filters-head { display: flex; justify-content: space-between; align-items: center; }
.filters h2 { font-size: 16px; margin: 0; }
.filters h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.catlist { list-style: none; margin: 0; padding: 0; }
.catlist button { width: 100%; display: flex; justify-content: space-between; gap: 8px; text-align: left; background: none; border: 0; border-radius: 8px; padding: 9px 10px; cursor: pointer; min-height: 40px; }
.catlist button span { color: var(--muted); font-size: 13px; }
.catlist button:hover { background: var(--bg); }
.catlist button.active { background: #E7EEF7; color: var(--navy); font-weight: 600; }
.filters select, .sort select { width: 100%; height: 42px; border: 1px solid #C9CED6; border-radius: 8px; padding: 0 10px; background: #fff; }
.check { display: flex; align-items: center; gap: 10px; margin-top: 18px; min-height: 40px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--navy); }

.toolbar { display: flex; align-items: center; gap: 16px; }
.count { margin: 0; font-weight: 600; font-size: 17px; flex: 1; }
.sort { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.sort select { width: auto; color: var(--ink); }
.meta { color: var(--muted); font-size: 13px; margin: 4px 0 16px; }
.btn-ghost { display: none; height: 42px; padding: 0 16px; border: 1px solid #C9CED6; background: #fff; border-radius: 8px; cursor: pointer; }

/* Tarjetas */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px; }
.grid[aria-busy="true"] { opacity: .55; transition: opacity .15s; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; transition: box-shadow .15s, transform .15s; }
.card:hover { box-shadow: 0 6px 18px rgba(16,24,40,.12); transform: translateY(-2px); }
.card-btn { all: unset; display: flex; flex-direction: column; height: 100%; width: 100%; cursor: pointer; box-sizing: border-box; }
.card-btn:focus-visible { outline: 3px solid #7FA6D9; outline-offset: -3px; border-radius: var(--radius); }
.card-img { position: relative; aspect-ratio: 1 / 1; background: #fff; padding: 14px; border-bottom: 1px solid var(--line); }
.card-img img { width: 100%; height: 100%; object-fit: contain; }
.badge { position: absolute; top: 10px; left: 10px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.card-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card-brand { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.card-name { margin: 0; font-size: 14.5px; font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; min-height: 3.9em; }
.card-price { margin: 6px 0 0; font-size: 18px; font-weight: 700; color: var(--ink); }
.card-price s, .pd-price s { color: var(--muted); font-weight: 400; font-size: 13px; margin-left: 6px; }
.card-stock { margin: 0; font-size: 13px; }
.ok { color: var(--ok); } .low { color: var(--low); } .out { color: var(--out); }
.empty { grid-column: 1 / -1; text-align: center; padding: 60px 20px; background: var(--card); border: 1px dashed #C9CED6; border-radius: var(--radius); }
.empty h3 { margin: 0 0 6px; }
.empty p { margin: 0; color: var(--muted); }

.pager { display: flex; gap: 6px; justify-content: center; align-items: center; margin-top: 28px; flex-wrap: wrap; }
.pager button { min-width: 44px; height: 44px; padding: 0 12px; border: 1px solid #C9CED6; background: #fff; border-radius: 8px; cursor: pointer; }
.pager button[aria-current="page"] { background: var(--navy); border-color: var(--navy); color: #fff; font-weight: 600; }
.pager button:disabled { opacity: .45; cursor: default; }
.pager span { color: var(--muted); padding: 0 4px; }

/* Diálogos */
.dlg { border: 0; border-radius: 16px; padding: 0; width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 24px 60px rgba(16,24,40,.25); }
.dlg::backdrop { background: rgba(15,23,42,.55); }
.dlg-narrow { width: min(560px, calc(100vw - 32px)); padding: 24px; }
.dlg-narrow h2 { margin: 0 0 16px; }
.dlg-close { position: absolute; top: 10px; right: 12px; width: 44px; height: 44px; border: 0; background: rgba(255,255,255,.9); border-radius: 50%; font-size: 26px; line-height: 1; cursor: pointer; z-index: 2; }
.pd { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.pd-img { background: #fff; padding: 32px; border-right: 1px solid var(--line); display: flex; align-items: center; justify-content: center; }
.pd-img img { max-height: 380px; object-fit: contain; }
.pd-info { padding: 28px 28px 24px; }
.pd-brand { margin: 0; text-transform: uppercase; letter-spacing: .06em; font-size: 12px; color: var(--muted); }
.pd-info h2 { margin: 6px 44px 6px 0; font-size: 21px; line-height: 1.3; }
.pd-ref { margin: 0; color: var(--muted); font-size: 13px; }
.pd-price { font-size: 28px; font-weight: 700; margin: 14px 0 2px; }
.pd-stock { margin: 0 0 4px; font-weight: 500; }
.pd-note { margin: 0; font-size: 13px; color: var(--muted); }
.req { margin-top: 18px; padding: 16px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); display: grid; gap: 10px; }
.req h3 { margin: 0; font-size: 15px; }
.req-row { display: grid; grid-template-columns: 120px 1fr; gap: 10px; }
.req label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.req input, .req textarea { border: 1px solid #C9CED6; border-radius: 8px; padding: 9px 10px; background: #fff; color: var(--ink); font-size: 15px; min-height: 42px; }
.req textarea { resize: vertical; }
.req-total { margin: 0; font-weight: 600; }
.btn-primary { height: 48px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 600; font-size: 16px; cursor: pointer; }
.btn-primary:hover { background: #994814; }
.btn-primary:disabled { background: #A7AFBB; cursor: default; }
.req-msg { margin: 0; font-size: 14px; }
.req-msg.success { color: var(--ok); background: #E6F4EC; padding: 10px 12px; border-radius: 8px; }
.req-msg.error { color: var(--out); background: #FBEAEA; padding: 10px 12px; border-radius: 8px; }
.pd-more { padding: 4px 28px 28px; border-top: 1px solid var(--line); display: grid; gap: 8px; }
.pd-more h3 { font-size: 15px; margin: 18px 0 6px; }
.pd-more p { margin: 0; color: #343B4A; }
.spec { width: 100%; border-collapse: collapse; margin-bottom: 12px; font-size: 14px; }
.spec caption { text-align: left; font-weight: 600; padding: 6px 0; color: var(--muted); }
.spec th, .spec td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.spec th { width: 38%; font-weight: 500; color: var(--muted); }
.mis { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.mis li { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 4px; }
.mis-foot { display: flex; justify-content: space-between; align-items: center; font-weight: 600; }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: #E7EEF7; color: var(--navy); }
.pill-nueva { background: var(--accent-bg); color: #7A3A10; }
.pill-entregada { background: #E6F4EC; color: var(--ok); }
.pill-cancelada { background: #F1F2F4; color: var(--muted); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: linear-gradient(var(--navy), var(--navy)) top / 100% 42% no-repeat, var(--bg); }
.login-card { background: #fff; border-radius: 16px; box-shadow: 0 24px 60px rgba(16,24,40,.18); padding: 40px 36px; width: min(420px, 100%); text-align: center; }
.login-card h1 { font-size: 24px; margin: 18px 0 8px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.ms-btn { display: flex; align-items: center; justify-content: center; gap: 12px; height: 50px; border: 1px solid #8C8C8C; border-radius: 6px; text-decoration: none; color: #1F1F1F; font-weight: 600; }
.ms-btn:hover { background: #F3F3F3; }
.ms-logo { display: grid; grid-template-columns: 9px 9px; gap: 2px; }
.ms-logo i { width: 9px; height: 9px; display: block; }
.ms-logo i:nth-child(1) { background: #F25022; } .ms-logo i:nth-child(2) { background: #7FBA00; }
.ms-logo i:nth-child(3) { background: #00A4EF; } .ms-logo i:nth-child(4) { background: #FFB900; }
.login-foot { font-size: 13px; margin-top: 20px !important; margin-bottom: 0 !important; }

/* Admin */
.admin { max-width: 1400px; margin: 0 auto; padding: 24px 20px 48px; }
.admin h1 { font-size: 22px; margin: 0 0 4px; }
.admin-bar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin: 16px 0; }
.admin-bar select { height: 42px; border: 1px solid #C9CED6; border-radius: 8px; padding: 0 10px; background: #fff; }
.btn-sec { height: 42px; padding: 0 16px; border: 1px solid var(--navy); color: var(--navy); background: #fff; border-radius: 8px; cursor: pointer; font-weight: 600; }
.tbl-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th, .tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.tbl th { background: #F8F9FB; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
.tbl td.num { text-align: right; white-space: nowrap; }
.tbl select { height: 36px; border: 1px solid #C9CED6; border-radius: 6px; background: #fff; }
.tbl textarea { width: 220px; min-height: 36px; border: 1px solid #C9CED6; border-radius: 6px; padding: 6px; font-size: 13px; }
.small { color: var(--muted); font-size: 12.5px; }
.flag-bad { color: var(--out); font-weight: 600; }

/* Responsivo */
@media (max-width: 900px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px 16px; padding: 10px 16px; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .usernav { margin-left: auto; gap: 12px; }
  .username { display: none; }
  .layout { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 40px; gap: 16px; }
  .count { font-size: 15px; }
  .toolbar { gap: 10px; }
  .btn-ghost { display: inline-block; }
  .filters { display: none; position: static; max-height: none; }
  body.show-filters .filters { display: block; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .sort span { display: none; }
  .sort select { max-width: 150px; }
  .count { min-width: 0; }
  .pd { grid-template-columns: 1fr; }
  .pd-img { border-right: 0; border-bottom: 1px solid var(--line); padding: 20px; }
  .pd-img img { max-height: 240px; }
  .pd-info, .pd-more { padding-left: 18px; padding-right: 18px; }
  .dlg { max-height: calc(100vh - 24px); width: calc(100vw - 16px); }
}
@media (max-width: 480px) {
  .brand span { display: none; }
  .req-row { grid-template-columns: 1fr; }
  .card-price { font-size: 16px; }
}
.login-logo { margin: 0 auto; }
.tbl td:nth-child(4) { min-width: 260px; }
.clave-form { display: grid; gap: 12px; text-align: left; }
.clave-form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.clave-form input { height: 44px; border: 1px solid #C9CED6; border-radius: 8px; padding: 0 12px; font-size: 15px; color: var(--ink); }
[hidden] { display: none !important; }

.req-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.hp { position: absolute !important; left: -9999px; width: 1px; height: 1px; overflow: hidden; }
.btn-wa { display: flex; align-items: center; justify-content: center; height: 46px; border-radius: 10px; border: 1px solid #1A7F4B; color: #146C3F; font-weight: 600; text-decoration: none; background: #fff; }
.btn-wa:hover { background: #EAF6EF; }
@media (max-width: 480px) { .req-row2 { grid-template-columns: 1fr; } }

.brand-logo, .brand-tag { display: none; }
.hero { display: none; }

.envio { display: grid; gap: 6px; }
.envio > label { font-size: 13px; color: var(--muted); }
.envio-row { display: flex; gap: 8px; }
.envio-row input { flex: 1; min-width: 0; border: 1px solid #C9CED6; border-radius: 8px; padding: 9px 10px; font-size: 15px; min-height: 42px; background: #fff; color: var(--ink); }
.btn-cp { min-height: 42px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--navy); background: #fff; color: var(--navy); font-weight: 600; cursor: pointer; white-space: nowrap; }
.btn-cp:disabled { opacity: .6; cursor: default; }
.envio-opc { display: grid; gap: 6px; }
.envio-op { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid #C9CED6; border-radius: 10px; background: #fff; cursor: pointer; color: var(--ink) !important; font-size: 14px !important; }
.envio-op:has(input:checked) { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(31,58,95,.18); }
.envio-op input { accent-color: var(--navy); width: 18px; height: 18px; }
.envio-nom { flex: 1; display: grid; font-weight: 600; }
.envio-nom small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.envio-pre { font-weight: 700; white-space: nowrap; }
.envio-msg { margin: 0; font-size: 13px; color: var(--muted); }
.envio-msg.error { color: var(--out); }
.req .envio-op { display: flex; flex-direction: row; align-items: center; gap: 12px; }
.req .envio-op input { min-height: 0; width: 18px; height: 18px; padding: 0; margin: 0; border: 0; box-shadow: none; background: none; flex: none; }
