:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #e2e8e5;
  --text: #17201d;
  --muted: #64716c;
  --primary: #0f766e;
  --primary-ink: #ffffff;
  --primary-soft: #e6f4f2;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --warn: #b45309;
  --warn-soft: #fdf3e3;
  --danger: #b91c1c;
  --danger-soft: #fdecec;
  --info: #1d4ed8;
  --info-soft: #e9effd;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 3px rgba(16, 24, 20, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1412;
    --surface: #161d1a;
    --surface-2: #1b2420;
    --border: #2a3530;
    --text: #e6ece9;
    --muted: #93a19b;
    --primary: #2dd4bf;
    --primary-ink: #04201c;
    --primary-soft: #133430;
    --ok: #4ade80;
    --ok-soft: #12301d;
    --warn: #fbbf24;
    --warn-soft: #33270e;
    --danger: #f87171;
    --danger-soft: #3a1717;
    --info: #93b4ff;
    --info-soft: #172443;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); margin: 8px 0 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

/* layout */
.layout { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 8px 18px; }
.brand-lg { font-size: 22px; padding: 0 0 4px; }
.brand-logo { display: block; height: 38px; width: auto; max-width: 100%; }
.brand-lg { justify-content: center; }
.brand-lg .brand-logo { height: 56px; }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { color: var(--text); padding: 8px 10px; border-radius: 8px; }
nav a:hover { background: var(--surface-2); }
nav a.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.sidebar-foot { margin-top: auto; padding: 0 8px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.main { padding: 24px 28px 48px; max-width: 1200px; width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* cards & grid */
.grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.grid > .card { margin-top: 0; }
a.card { color: inherit; display: block; }
a.card:hover { border-color: var(--primary); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

/* table */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
td.empty { text-align: center; color: var(--muted); padding: 28px; }

/* badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.b-ok { background: var(--ok-soft); color: var(--ok); }
.b-warn { background: var(--warn-soft); color: var(--warn); }
.b-danger { background: var(--danger-soft); color: var(--danger); }
.b-info { background: var(--info-soft); color: var(--info); }
.b-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* forms */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.form-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.choice { display: flex; flex-direction: row; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer; font-weight: 400; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice input { margin-top: 3px; }
.choice strong { display: block; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); color: var(--primary-ink); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* switch */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 999px; transition: .15s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(16px); }

/* tabs */
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tab { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; font-size: 13px; }
.tab.active { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }

.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 12px; }

/* sections */
.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.section-head h2 { margin: 0; }
.help { color: var(--muted); font-size: 13px; margin: 0 0 10px; max-width: 760px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px dashed var(--border); display: flex; gap: 10px; }
.timeline li:last-child { border-bottom: 0; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 14px; align-items: start; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow); }
.login-card p { margin: 0; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--text); padding: 22px; width: min(420px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
#dialog-body { display: flex; flex-direction: column; gap: 12px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 500; z-index: 10; max-width: calc(100vw - 40px); }
.toast.err { background: var(--danger); color: #fff; }
.loading { color: var(--muted); padding: 30px 0; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 16px; gap: 8px; }
  .brand { padding: 0 8px 0 0; }
  .brand-logo { height: 30px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; }
  .main { padding: 18px 16px 40px; }
  .two-col { grid-template-columns: 1fr; }
}
.mt { margin-top: 12px; }
label.row { flex-direction: row; font-weight: 400; }
.table-wrap + .card { margin-top: 14px; }
.timeline li { align-items: flex-start; }
.timeline .badge { flex: none; min-width: 86px; text-align: center; }

/* --- contenido de la tienda --- */
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 10px 4px; }
dialog.wide { width: min(760px, calc(100vw - 32px)); }
textarea { resize: vertical; }
label.check { gap: 8px; align-items: center; font-weight: 400; white-space: nowrap; }
label.check input { width: auto; }
.ok { color: var(--ok); }
.warn-card { border-color: var(--warn); background: var(--warn-soft); margin-bottom: 14px; }

.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--surface-2); border: 1px solid var(--border); display: inline-grid; place-items: center; vertical-align: middle; }
.thumb-empty { font-size: 9px; color: var(--muted); text-align: center; line-height: 1.1; }
.icon-chip { display: inline-block; font-size: 11px; padding: 2px 6px; border-radius: 6px; background: var(--primary-soft); color: var(--primary); }

.img-field { display: flex; flex-direction: column; gap: 6px; }
.img-label { font-size: 13px; font-weight: 500; }
.img-preview { min-height: 90px; max-height: 180px; border: 1px dashed var(--border); border-radius: 8px; display: grid; place-items: center; overflow: hidden; background: var(--surface-2); }
.img-preview img { max-width: 100%; max-height: 180px; object-fit: contain; display: block; }

/* Encuadre de imágenes (recortarImagen) */
.crop-vista { position: relative; margin: 12px auto 0; overflow: hidden; border-radius: 8px; cursor: grab; touch-action: none;
  background: repeating-conic-gradient(var(--border) 0 25%, var(--surface) 0 50%) 0 0 / 16px 16px; outline: 2px solid var(--primary); }
.crop-vista:active { cursor: grabbing; }
.crop-vista img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; user-select: none; pointer-events: none; }
.crop-zoom { margin-top: 12px; gap: 10px; align-items: center; }
.crop-zoom input { flex: 1; }
.warn-text { color: var(--warn); }

.prod-field { display: flex; flex-direction: column; gap: 6px; }
.prod-elegido { font-weight: 600; }
.prod-resultados { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto; }
.prod-resultados button { text-align: left; font: inherit; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; cursor: pointer; }
.prod-resultados button:hover { border-color: var(--primary); }

.cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.cards > .card { margin-top: 0; }
.banner-card { display: flex; flex-direction: column; gap: 10px; padding: 0; overflow: hidden; }
.banner-img { width: 100%; aspect-ratio: 16 / 5; object-fit: cover; background: var(--surface-2); display: grid; place-items: center; border-bottom: 1px solid var(--border); }
.banner-info { padding: 0 16px 16px; display: flex; flex-direction: column; gap: 4px; }
.combo-farm { border-top: 1px dashed var(--border); padding-top: 6px; margin-top: 4px; }

.media-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.media-tile { display: flex; flex-direction: column; gap: 4px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 8px; font: inherit; color: var(--text); text-align: left; }
button.media-tile { cursor: pointer; }
button.media-tile:hover { border-color: var(--primary); }
.media-tile img { width: 100%; aspect-ratio: 1; object-fit: contain; background: var(--surface-2); border-radius: 6px; }
.drop { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); }
.drop.over { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

/* Editor de botones del banner */
.botones-field { display: flex; flex-direction: column; gap: 6px; }
.boton-fila { display: grid; grid-template-columns: 1.2fr 1.4fr 1fr 0.9fr auto; gap: 6px; margin-bottom: 6px; }
@media (max-width: 640px) { .boton-fila { grid-template-columns: 1fr 1fr; } }

/* Interruptores de secciones (Configuración) */
label.seccion { flex-direction: row; flex-wrap: nowrap; white-space: normal; align-items: flex-start; gap: 10px; }
label.seccion > span:last-child { min-width: 0; }
.block { display: block; }
