/* Panel de administración — Holistic Mountain. Sin dependencias; responsive (menú lateral → desplegable < 900 px). */
:root {
  --bg: #f4f5f2; --surface: #fff; --text: #1d2420; --muted: #5d6a63; --line: #dde2dc;
  --brand: #1f4d3a; --brand-2: #2f6b52; --brand-soft: #e6efe9;
  --ok: #1d6b3f; --ok-bg: #e2f2e8; --warn: #8a5a00; --warn-bg: #fdf1d8; --bad: #a3271f; --bad-bg: #fbe4e1;
  --radius: 8px; --shadow: 0 1px 2px rgba(20, 30, 25, .06), 0 2px 8px rgba(20, 30, 25, .05);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.45; color: var(--text); background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--brand-2); }
h1 { font-size: 1.45rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 1rem 0 .5rem; color: var(--muted); }
code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; }
.boot, .loading { padding: 2rem; color: var(--muted); }
.muted { color: var(--muted); }

/* Barra superior y estructura */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem; padding: .55rem 1rem; background: var(--brand); color: #fff; }
.brand { display: flex; align-items: center; gap: .5rem; color: inherit; text-decoration: none; font-weight: 650; }
.brand img { width: 26px; height: 26px; }
.brand.big { justify-content: center; font-size: 1.3rem; color: var(--brand); }
.brand.big img { width: 40px; height: 40px; }
.mode { font-size: .75rem; font-weight: 650; letter-spacing: .03em; background: #f5c542; color: #3b2c00; padding: .2rem .55rem; border-radius: 99px; }
.user { margin-left: auto; display: flex; align-items: center; gap: .75rem; }
.user a { color: #fff; }
.user a.btn { color: var(--brand); font-weight: 650; }
.layout { display: grid; grid-template-columns: 230px 1fr; min-height: calc(100vh - 50px); }
/* La barra lateral tiene su propio scroll y se queda fija: el contenido baja sin moverla. */
.sidebar { position: sticky; top: var(--topbar-h, 50px); align-self: start; height: calc(100vh - var(--topbar-h, 50px)); background: var(--surface); border-right: 1px solid var(--line); padding: .6rem .6rem 2rem; overflow-y: auto; overscroll-behavior: contain; }
.nav-group + .nav-group { border-top: 1px solid var(--line); margin-top: .4rem; padding-top: .4rem; }
.nav-head { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 0; padding: .55rem .6rem; border: 0; border-radius: 6px; background: none; cursor: pointer;
  font: inherit; font-size: .78rem; font-weight: 750; text-transform: uppercase; letter-spacing: .07em; color: var(--brand); }
.nav-head:hover { background: var(--brand-soft); }
.nav-head .chev { font-size: 1.1rem; line-height: 1; transform: rotate(90deg); color: var(--muted); }
.nav-group.collapsed .nav-head .chev { transform: none; }
.nav-group.collapsed .nav-items { display: none; }
.nav-items { margin: .1rem 0 .3rem .7rem; padding-left: .45rem; border-left: 2px solid var(--line); }
.nav-group a { display: block; padding: .38rem .6rem; border-radius: 6px; color: var(--text); text-decoration: none; font-size: .95rem; }
.nav-group a:hover { background: var(--brand-soft); }
.nav-group a.active { background: var(--brand); color: #fff; }
.content { padding: 1.4rem 1.6rem 3rem; min-width: 0; outline: none; }
.menu-toggle { display: none; color: #fff; }

/* Páginas y tarjetas */
.page { max-width: 1280px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.1rem; margin-bottom: 1rem; min-width: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; align-items: start; }
.cols > .card { margin-bottom: 0; }
.cols { margin-bottom: 1rem; }
.cols.three { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.stat { display: flex; flex-direction: column; gap: .25rem; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--brand-2); border-radius: var(--radius); padding: .8rem 1rem; color: var(--text); text-decoration: none; box-shadow: var(--shadow); }
.stat span { font-size: .82rem; color: var(--muted); }
.stat strong { font-size: 1.2rem; }
.stat.warn { border-left-color: #d99a00; }
.stat.bad { border-left-color: var(--bad); }
.health { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.notice { padding: .65rem .85rem; border-radius: var(--radius); background: var(--brand-soft); border: 1px solid #c9dccf; margin: 0 0 1rem; }
.notice.warn { background: var(--warn-bg); border-color: #f0d9a8; color: #5a3b00; }
.notice.bad { background: var(--bad-bg); border-color: #f1c2bc; color: var(--bad); }
.dl { display: grid; grid-template-columns: minmax(140px, max-content) 1fr; gap: .35rem 1rem; margin: 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; overflow-wrap: anywhere; }
.hash, .token, .details { overflow-wrap: anywhere; word-break: break-all; }
.token { display: block; padding: .75rem; background: #111; color: #9ef0b8; border-radius: 6px; margin: .5rem 0; user-select: all; }
.details { display: block; max-width: 420px; color: var(--muted); }
pre.json { max-height: 60vh; overflow: auto; background: #f7f8f6; padding: .75rem; border-radius: 6px; font-size: .8rem; }
pre.mail-preview { white-space: pre-wrap; max-height: 40vh; overflow: auto; background: #f7f8f6; padding: .75rem; border-radius: 6px; font: inherit; }

/* Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; white-space: nowrap; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.center { text-align: center; }
tr.clickable { cursor: pointer; }
tr.clickable:hover, tr.clickable:focus { background: var(--brand-soft); outline: none; }
.matrix td:first-child { min-width: 240px; }
.empty { color: var(--muted); padding: .75rem 0; }
.pager { display: flex; align-items: center; gap: .75rem; justify-content: flex-end; margin-top: .75rem; }

/* Insignias y botones */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 99px; font-size: .78rem; font-weight: 600; background: #eceeea; color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; min-height: 38px; padding: .45rem .9rem; border: 1px solid #c7cec8; border-radius: 6px; background: var(--surface); color: var(--text); font: inherit; font-weight: 550; text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--brand-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-2); }
.btn.danger { color: var(--bad); border-color: #e5b4ae; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.small { min-height: 30px; padding: .25rem .6rem; font-size: .85rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon { background: none; border: 0; font-size: 1.4rem; line-height: 1; padding: .2rem .45rem; cursor: pointer; color: inherit; border-radius: 6px; }
.icon:hover { background: rgba(0, 0, 0, .06); }
:focus-visible { outline: 3px solid #7fb69a; outline-offset: 2px; }
.row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }

/* Formularios */
.form { display: grid; gap: .8rem; }
.field { display: grid; gap: .3rem; min-width: 0; }
.field label { font-weight: 600; font-size: .88rem; }
.field small { color: var(--muted); font-size: .8rem; }
input, select, textarea { font: inherit; padding: .5rem .6rem; border: 1px solid #c7cec8; border-radius: 6px; background: #fff; color: var(--text); min-height: 38px; width: 100%; }
input:disabled, select:disabled, textarea:disabled { background: #f1f3f0; color: var(--muted); }
input[type=checkbox] { width: auto; min-height: 0; }
input.qty { max-width: 7.5rem; }
fieldset { border: 0; padding: 0; margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .8rem; }
.check { display: inline-flex; align-items: center; gap: .35rem; font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: flex-end; }
.form-error { color: var(--bad); margin: 0; min-height: 0; }
.form-error:empty { display: none; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 150px; }
.filters .field { width: auto; }
.picker { display: grid; gap: .4rem; }
.pick-results { display: grid; gap: .25rem; max-height: 260px; overflow-y: auto; }
.pick-item { text-align: left; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 6px; background: #fafbf9; cursor: pointer; font: inherit; }
.pick-item:hover { background: var(--brand-soft); }
.total { color: var(--muted); }

/* Diálogos y avisos */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(15, 25, 20, .45); display: grid; place-items: center; padding: 1rem; }
.modal { background: var(--surface); border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.modal.wide { width: min(920px, 100%); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal-body { padding: 1rem; overflow-y: auto; }
.toasts { position: fixed; right: 1rem; bottom: 1rem; z-index: 60; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.toast { padding: .7rem .9rem; border-radius: 8px; background: #1d2420; color: #fff; box-shadow: var(--shadow); }
.toast.bad { background: var(--bad); }

/* Acceso */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-box { width: min(400px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 1.8rem; box-shadow: var(--shadow); }
.login-box > .muted { text-align: center; margin-top: .25rem; }

/* Móvil y tableta */
@media (max-width: 900px) {
  .menu-toggle { display: inline-block; }
  .layout { grid-template-columns: 1fr; }
  .sidebar { display: none; position: fixed; top: var(--topbar-h, 50px); left: 0; bottom: 0; height: auto; width: min(280px, 85vw); z-index: 30; box-shadow: 4px 0 20px rgba(0, 0, 0, .15); }
  body.nav-open .sidebar { display: block; }
  .mode { display: none; }
  .content { padding: 1rem .8rem 3rem; }
  .cols { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .brand span { display: none; }
  /* Tablas como tarjetas apiladas: cada celda muestra su etiqueta. */
  table:not(.matrix) thead { display: none; }
  table:not(.matrix) tr { display: block; border: 1px solid var(--line); border-radius: 8px; margin-bottom: .6rem; padding: .3rem .2rem; background: var(--surface); }
  table:not(.matrix) td { display: flex; justify-content: space-between; gap: 1rem; border: 0; padding: .3rem .6rem; text-align: right; }
  table:not(.matrix) td::before { content: attr(data-label); font-weight: 600; color: var(--muted); text-align: left; }
  table:not(.matrix) td[data-label=""]::before { content: none; }
  .dl { grid-template-columns: 1fr; gap: .1rem; }
  .dl dd { margin-bottom: .5rem; }
  .filters input, .filters select { width: 100%; }
  .page-actions .btn { flex: 1 1 auto; }
}
@media (prefers-reduced-motion: no-preference) { .btn, .nav-group a, .nav-head { transition: background-color .12s, border-color .12s; } .nav-head .chev { transition: transform .15s; } }
td a, .hash-nowrap { white-space: nowrap; }

/* Indicador de carga (peticiones que tardan más de 250 ms). */
#busy { position: fixed; inset: 0 0 auto 0; z-index: 9999; pointer-events: none; opacity: 0; transition: opacity .15s; }
#busy.on { opacity: 1; }
#busy .busy-bar { height: 3px; background: linear-gradient(90deg, transparent, var(--accent, #c8792f), transparent); background-size: 50% 100%; background-repeat: no-repeat; animation: busy-slide 1s linear infinite; }
#busy .busy-chip { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: .5rem; padding: .4rem .8rem;
  border-radius: 999px; background: #fff; color: var(--brand, #1f4d3a); font-weight: 600; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.18); }
#busy .busy-spin { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: busy-turn .7s linear infinite; }
@keyframes busy-slide { from { background-position: -50% 0; } to { background-position: 150% 0; } }
@keyframes busy-turn { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { #busy .busy-bar, #busy .busy-spin { animation-duration: 3s; } }
.thumb { object-fit: cover; border-radius: 6px; }
.scan { width: 100%; margin-bottom: .75rem; font-size: 1.05rem; }

/* Componentes de un pack */
.pack-row { display: grid; grid-template-columns: minmax(0, 1fr) 7rem auto; gap: 12px; align-items: end; }
.pack-row .btn { margin-bottom: 14px; }

/* Alta de productos: opciones (tallas, colores…), foto */
[hidden] { display: none !important; }
.attr-list { display: grid; gap: 14px; margin: 8px 0 12px; }
.attr-row { display: grid; grid-template-columns: minmax(10rem, 14rem) 1fr; gap: 16px; align-items: start; padding: 12px; border: 1px solid var(--line); border-radius: 8px; }
.attr-name { display: grid; gap: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 8px; }
.chip { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: .3rem .75rem; font: inherit; cursor: pointer; }
.chip.on { background: var(--brand); border-color: var(--brand); color: #fff; }
.variant-table input { width: 100%; min-width: 4.5rem; }
.photo-pick { display: flex; gap: 12px; align-items: center; }
.photo-preview { width: 84px; height: 84px; border: 1px dashed var(--line); border-radius: 8px; display: grid; place-items: center; overflow: hidden; font-size: .8rem; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; }
.product-photo { width: 120px; height: 120px; object-fit: cover; border-radius: 8px; float: right; margin: 0 0 8px 12px; }
@media (max-width: 640px) { .attr-row { grid-template-columns: 1fr; } }
.add-value { display: flex; gap: 8px; align-items: center; }
.add-value input { width: 12rem; max-width: 100%; }
.chip.done { cursor: default; color: var(--muted); background: var(--bg); }
.attr-name .btn { justify-self: start; }
