/* Panel Benzi */
:root {
  --bg: #f4f5f7; --surface: #fff; --text: #1d2330; --dim: #6b7280; --line: #e3e6eb;
  --accent: #c8102e; --accent-ink: #fff; --blue: #1d4ed8; --row-hover: #f8f9fb;
  --green-bg: #e7f6ec; --green: #13703a; --red-bg: #fdecec; --red: #b42318;
  --amber-bg: #fff4dc; --amber: #8a5a00; --blue-bg: #e8efff; --tag-bg: #eef0f3;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1a1e26; --text: #e6e8ec; --dim: #9aa3b2; --line: #2a303b;
    --row-hover: #20252f; --green-bg: #12301f; --green: #6fdc9a; --red-bg: #3a1717; --red: #ff9b93;
    --amber-bg: #3a2c10; --amber: #ffcf70; --blue-bg: #17264a; --blue: #9db8ff; --tag-bg: #262c37;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; }
a { color: var(--blue); }
h1 { font-size: 22px; margin: 0; }
h1 small { font-size: 14px; color: var(--dim); font-weight: 400; margin-left: 6px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--dim); margin: 18px 0 6px; }
pre { background: var(--tag-bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.dim { color: var(--dim); }
.strong { font-weight: 600; }
.hint { color: var(--dim); font-size: 13px; }

/* Cabecera */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 0 20px; height: 56px; background: var(--surface); border-bottom: 1px solid var(--line); }
.brand { font-weight: 800; font-size: 18px; color: var(--text); text-decoration: none; letter-spacing: -.01em; }
.brand span { color: var(--accent); font-weight: 600; margin-left: 2px; }
.brand.big { font-size: 26px; text-align: center; margin-bottom: 18px; }
.top nav { display: flex; gap: 4px; flex: 1; }
.top nav a { padding: 8px 12px; border-radius: 8px; color: var(--dim); text-decoration: none; font-weight: 500; }
.top nav a:hover { background: var(--tag-bg); color: var(--text); }
.top nav a.on { background: var(--tag-bg); color: var(--text); }
.who { display: flex; align-items: center; gap: 14px; color: var(--dim); font-size: 13px; }
.who a { color: var(--dim); }
.sync-pill { background: var(--tag-bg); border-radius: 99px; padding: 3px 10px; white-space: nowrap; }
main { max-width: 1440px; margin: 0 auto; padding: 22px 20px 60px; }

/* Bloques */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.flush { padding: 0; }
.card.flush .tbl th:first-child { border-top-left-radius: var(--radius); }
.card.flush .tbl th:last-child { border-top-right-radius: var(--radius); }
.card.narrow { width: 100%; max-width: 400px; }
body.center { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 16px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 22px; }
.stat span { color: var(--dim); font-size: 13px; }
.empty, .empty-state { text-align: center; color: var(--dim); padding: 30px 12px; }
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; }
.flash.ok { background: var(--green-bg); color: var(--green); }
.flash.error { background: var(--red-bg); color: var(--red); }

/* Formularios */
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 500; font-size: 13px; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
.btn { display: inline-block; background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 8px; padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn.sm { padding: 6px 10px; font-size: 13px; }
.link { background: none; border: 0; color: var(--blue); cursor: pointer; font: inherit; padding: 4px 6px; }
.link:disabled { color: var(--dim); cursor: default; }
.row { display: flex; gap: 6px; margin-top: 6px; }
.search { width: min(440px, 100%); padding: 10px 14px; font-size: 15px; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; align-items: center; }
.filters select { max-width: 260px; }

/* Tablas */
.tbl { width: 100%; border-collapse: collapse; }
.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--dim); font-weight: 600; padding: 10px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--surface); }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl tr.muted td { opacity: .55; }
.tbl.compact td, .tbl.compact th { padding: 6px 8px; font-size: 13px; }
.products thead th { position: sticky; top: 56px; z-index: 5; }
.products th[data-sort] { cursor: pointer; user-select: none; }
.products th[data-sort]::after { content: attr(data-dir); margin-left: 4px; }
.products th.sorted { color: var(--text); }
.products tbody tr { cursor: pointer; }
.products tbody tr:hover, .products tbody tr:focus { background: var(--row-hover); outline: none; }
.products .name { font-weight: 500; max-width: 420px; }
.col-img { width: 52px; }
.col-img img, .noimg { width: 40px; height: 40px; object-fit: contain; border-radius: 6px; background: #fff; border: 1px solid var(--line); display: block; }
.actions { white-space: nowrap; }
.actions form { display: inline; }
details.inline { display: inline-block; }
details.inline summary { list-style: none; display: inline; }
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; padding: 12px; border-top: 1px solid var(--line); color: var(--dim); }
.pager:empty { display: none; }

/* Etiquetas */
.tag { display: inline-block; padding: 2px 8px; border-radius: 99px; background: var(--tag-bg); font-size: 12px; font-weight: 500; white-space: nowrap; }
.tag.green { background: var(--green-bg); color: var(--green); }
.tag.red { background: var(--red-bg); color: var(--red); }
.tag.amber { background: var(--amber-bg); color: var(--amber); }
.tag.blue { background: var(--blue-bg); color: var(--blue); }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

/* Panel lateral */
.backdrop { position: fixed; inset: 0; background: rgba(10,14,22,.35); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 30; }
.backdrop.open { opacity: 1; pointer-events: auto; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100vw); background: var(--surface); z-index: 40; transform: translateX(100%); display: flex; flex-direction: column; box-shadow: none; visibility: hidden; transition: transform .2s ease, visibility 0s .2s; }
.drawer.open { transform: none; visibility: visible; box-shadow: -8px 0 30px rgba(0,0,0,.15); transition: transform .2s ease; }
.drawer-head { display: flex; justify-content: flex-end; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.drawer-body { padding: 20px 22px 40px; overflow-y: auto; flex: 1; }
.d-head { display: flex; gap: 16px; align-items: flex-start; }
.d-head h2 { font-size: 18px; margin: 4px 0 0; }
.d-cover { width: 120px; height: 120px; object-fit: contain; border: 1px solid var(--line); border-radius: 10px; background: #fff; flex: none; }
.facts { display: grid; grid-template-columns: 180px 1fr; gap: 6px 14px; margin: 16px 0; }
.facts dt { color: var(--dim); }
.facts dd { margin: 0; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-top: 8px; overflow-x: auto; }
.tabs button { white-space: nowrap; background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; font: inherit; color: var(--dim); cursor: pointer; }
.tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tab { display: none; padding-top: 14px; }
.tab.on { display: block; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-top: 12px; }
.gallery figure { margin: 0; display: grid; gap: 6px; justify-items: center; }
.gallery figure a { border: 1px solid var(--line); border-radius: 8px; background: #fff; aspect-ratio: 1; width: 100%; display: grid; place-items: center; overflow: hidden; }
.gallery figure.cover a { outline: 2px solid var(--accent); }
.gallery img { max-width: 100%; max-height: 100%; }
.gallery figure > span { background: var(--accent); color: #fff; font-size: 11px; border-radius: 4px; padding: 1px 8px; }
.serp { border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; background: #fff; color: #202124; font-family: Arial, sans-serif; }
.serp-url { font-size: 12px; color: #4d5156; }
.serp-title { font-size: 18px; color: #1a0dab; margin: 2px 0 4px; }
.serp-desc { font-size: 13px; color: #4d5156; }

/* Edición en la tabla */
.col-check { width: 34px; text-align: center; }
.products tbody tr.selected { background: var(--blue-bg); }
.products td.ed, .products td.ed-toggle { cursor: text; }
.products td.ed-toggle { cursor: pointer; }
.products td.ed:hover, .products td.ed-toggle:hover { outline: 1px dashed var(--dim); outline-offset: -4px; border-radius: 6px; }
.products td.editing { padding: 4px 6px; outline: none; }
.products td.saving { opacity: .45; pointer-events: none; }
.products tr.flash-ok td { animation: flashok 1.2s ease; }
@keyframes flashok { from { background: var(--green-bg); } to { background: transparent; } }
.cell-input { width: 100%; padding: 6px 8px; font-size: 14px; }
.cell-input.num { text-align: right; min-width: 90px; }
.open-btn { white-space: nowrap; }
.ed-sample { outline: 1px dashed var(--dim); border-radius: 4px; padding: 0 4px; }
.push { margin-left: auto; }
.grow { flex: 1; }
.nowrap { white-space: nowrap; }
.val { max-width: 280px; overflow-wrap: anywhere; font-size: 13px; }
.tbl tr.err td { background: var(--red-bg); }
.tbl tr.err-row td { border-top: 0; padding-top: 0; font-size: 12px; }
.link.sm { font-size: 12px; }

.checks { list-style: none; margin: 14px 0 0; padding: 10px 14px; background: var(--amber-bg); color: var(--amber); border-radius: 8px; display: grid; gap: 4px; font-size: 13px; }
.checks b { font-weight: 600; }

/* Acciones en bloque */
.bulkbar { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 25; display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: 0 8px 30px rgba(0,0,0,.18); max-width: calc(100vw - 32px); }
.bulkbar[hidden] { display: none; }
#bulk-param { display: inline-flex; align-items: center; gap: 6px; }
#bulk-param select { max-width: 280px; }

/* Avisos flotantes */
.toasts { position: fixed; right: 18px; top: 70px; z-index: 60; display: grid; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 10px 14px; border-radius: 10px; background: var(--green-bg); color: var(--green); box-shadow: var(--shadow); white-space: pre-line; cursor: pointer; font-weight: 500; }
.toast.error { background: var(--red-bg); color: var(--red); }

/* Ficha editable */
.drawer-head { align-items: center; justify-content: space-between; }
.drawer-foot { display: flex; align-items: center; justify-content: flex-end; gap: 12px; padding: 12px 22px; border-top: 1px solid var(--line); background: var(--surface); }
.drawer-foot[hidden] { display: none; }
.drawer-foot #dirty-info { margin-right: auto; }
.fgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.fgrid label, .fgrid .lbl { display: grid; gap: 4px; font-weight: 500; font-size: 13px; }
.fgrid .span2 { grid-column: 1 / -1; }
.fgrid .row { display: flex; gap: 8px; align-items: center; margin: 0; }
.lbl { display: flex !important; justify-content: space-between; align-items: center; }
.cat-filter { padding: 4px 8px; font-size: 13px; width: 180px; font-weight: 400; }
label.switch { display: flex; align-items: center; gap: 8px; align-self: end; padding-bottom: 8px; }
label.switch input { width: 18px; height: 18px; }
.catlist { max-height: 210px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; display: grid; gap: 2px; }
.catlist label { display: flex; gap: 8px; align-items: center; font-weight: 400; font-size: 13px; padding: 2px 0; }
.catlist label[hidden] { display: none; }
.cnt { font-weight: 400; }
.cnt.warn { color: var(--amber); font-weight: 600; }
.combs input { width: 100%; min-width: 70px; padding: 5px 7px; font-size: 13px; }
.combs input.num { text-align: right; }
.upload { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.upload .btn { cursor: pointer; }
.editor { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.ed-toolbar { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px; border-bottom: 1px solid var(--line); background: var(--tag-bg); }
.ed-toolbar button { background: transparent; border: 0; border-radius: 6px; padding: 4px 8px; cursor: pointer; font: inherit; font-size: 13px; color: var(--text); }
.ed-toolbar button:hover:not(:disabled), .ed-toolbar button.on { background: var(--surface); }
.ed-toolbar button:disabled { opacity: .35; cursor: default; }
.ed-area { min-height: 110px; max-height: 260px; overflow-y: auto; padding: 10px 12px; color: #222; font: 14px/1.5 Arial, sans-serif; outline: none; }
.editor.tall .ed-area { min-height: 300px; max-height: 520px; }
.ed-area img { max-width: 100%; height: auto; }
.ed-html { width: 100%; min-height: 220px; border: 0; border-radius: 0; font: 12.5px/1.45 ui-monospace, Menlo, monospace; padding: 10px 12px; background: #fff; color: #222; }
.editor.tall .ed-html { min-height: 400px; }

/* Alta de producto */
.head-actions { display: flex; gap: 10px; align-items: center; flex: 0 1 600px; justify-content: flex-end; }
.head-actions .search { flex: 1 1 auto; width: auto; min-width: 0; }
.head-actions .btn { white-space: nowrap; flex: none; padding: 10px 16px; }
.new-grid { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; align-items: start; }
.new-side { display: grid; gap: 0; position: sticky; top: 72px; }
.fgrid.one { grid-template-columns: 1fr; margin-top: 12px; }
.seg { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.seg label { display: flex; gap: 6px; align-items: center; font-weight: 500; }
.attr-group { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin-bottom: 12px; }
.attr-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.attr-filter { padding: 4px 8px; font-size: 13px; width: 200px; margin-left: auto; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow-y: auto; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 99px; cursor: pointer; font-size: 13px; user-select: none; }
.chip input { display: none; }
.chip.on { background: var(--blue-bg); border-color: var(--blue); color: var(--blue); font-weight: 600; }
.chip[hidden] { display: none; }
.sw { width: 12px; height: 12px; border-radius: 50%; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.new-value { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.new-value[hidden] { display: none; }
.new-value input[type=color] { width: 42px; height: 36px; padding: 2px; }
.codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.codes label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 4px 4px 10px; }
.codes input.missing { border-color: var(--amber); background: var(--amber-bg); }
.gen-tools { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; font-size: 13px; }
.gen-tools label { display: flex; gap: 6px; align-items: center; }
.center { text-align: center; }
.new-imgs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.new-imgs figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; cursor: grab; background: #fff; }
.new-imgs figure.cover { outline: 2px solid var(--accent); }
.new-imgs img { width: 100%; aspect-ratio: 1; object-fit: contain; display: block; }
.new-imgs figcaption { display: flex; justify-content: space-between; align-items: center; padding: 2px 6px; font-size: 12px; color: var(--dim); background: var(--surface); }
.btn.wide { width: 100%; margin-top: 8px; padding: 12px; font-size: 15px; }
.sticky-create .switch { padding-bottom: 0; }

@media (max-width: 900px) {
  .fgrid { grid-template-columns: 1fr; }
  .new-grid { grid-template-columns: 1fr; }
  .new-side { position: static; }
  .attr-filter { margin-left: 0; width: 100%; }
  .bulkbar { left: 16px; right: 16px; transform: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .who span:not(.sync-pill) { display: none; }
  .top { gap: 12px; padding: 0 12px; }
  .card.flush { overflow-x: auto; }
  .products thead th { position: static; }
  .facts { grid-template-columns: 1fr; }
  .facts dt { margin-top: 6px; }
}
@media (max-width: 520px) {
  .sync-pill { display: none; }
  .head-actions { flex-wrap: wrap; }
}
