/* ============================================================
   Punto de Venta adnode360 — Hoja de estilo base (referencia de UI)
   Estética de software de gestión empresarial: limpia, corporativa
   y orientada a productividad. Código 100% original.
   ============================================================ */

:root {
  --brand:        #714B67;   /* acento corporativo púrpura-grisáceo */
  --brand-dark:   #5c3b53;
  --brand-light:  #e8e1e6;
  --text:         #34495e;
  --text-soft:    #7f8c8d;
  --bg:           #f6f7f9;    /* gris muy claro tipo "área de trabajo" */
  --card:         #ffffff;
  --line:         #e4e9ee;
  --line-strong:  #d5dbe2;
  --ok:           #21a366;
  --warn:         #c9971c;
  --danger:       #c0392b;
  --table-head:   #f8f9fa;
  --radius:       10px;
  --shadow:       0 1px 2px rgba(23,26,31,.04), 0 2px 6px rgba(23,26,31,.05);
  --shadow-pop:   0 4px 16px rgba(23,26,31,.12);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* Medios: nunca deben empujar el layout fuera del contenedor */
img, video, canvas {
  max-width: 100%;
  height: auto;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Barra superior (navegación) ---------- */
.topbar {
  height: 46px;
  background: var(--brand);
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 14px;
  position: sticky;
  top: 0;
  z-index: 20;
  min-width: 0; /* permite truncar hijos flex (breadcrumb/user) sin overflow */
}
.topbar .menubtn {
  background: none; border: none; color: #fff; font-size: 18px;
  cursor: pointer; margin-right: 10px; width: 34px; height: 34px;
  border-radius: 6px; line-height: 1;
}
.topbar .menubtn:hover { background: rgba(255,255,255,.15); }
.topbar .brand {
  font-weight: 600; letter-spacing: .2px; white-space: nowrap;
}
.topbar .spacer { flex: 1; }

/* migas de pan (control del "modalidad / lista / formulario") */
.o-breadcrumb {
  display: flex;
  align-items: center;
  color: rgba(255,255,255,.85);
  gap: 6px;
  min-width: 0;
}
.o-breadcrumb .crumb {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.o-breadcrumb .sep { flex: 0 0 auto; }
.o-breadcrumb .crumb.mod { font-weight: 600; color: #fff; }
.o-breadcrumb .sep { opacity: .6; }

.topbar .userbox {
  display: flex; align-items: center; gap: 8px; padding-left: 12px;
  min-width: 0;
}
.topbar .userbox > span:not(.avatar):not(.badge) {
  min-width: 0;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: rgba(255,255,255,.25); display: flex; align-items: center;
  justify-content: center; font-size: 12px; font-weight: 600;
}
.topbar .userbox .chev { margin-left: 2px; opacity: .7; }

/* ---------- Contenedor y barra lateral ---------- */
.app { display: flex; min-height: calc(100vh - 46px); }
.app { min-width: 0; }
.sidebar {
  width: 220px; background: var(--card); border-right: 1px solid var(--line);
  padding: 12px 10px; position: fixed; top: 46px; left: 0;
  height: calc(100vh - 46px); overflow-y: auto; z-index: 30;
  transform: translateX(-100%); transition: transform .2s ease;
}
.sidebar.open { transform: translateX(0); }
.sidebar-overlay {
  display: none; position: fixed; inset: 0; z-index: 25;
  background: rgba(0,0,0,.3);
}
.sidebar-overlay.show { display: block; }
.content { flex: 1; padding: 18px 22px; min-width: 0; margin-left: 0; }
.sidebar.open ~ .content { margin-left: 0; }
.side-group { margin-bottom: 14px; }
.side-label {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; border: none; background: none; cursor: pointer;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .7px;
  color: var(--text-soft); padding: 9px 10px; border-radius: 8px;
  font-family: inherit; text-align: left; font-weight: 700; transition:all .12s;
}
.side-label:hover { background: var(--bg); color: var(--text); }
.side-label.open { color: var(--brand); background: var(--brand-light); }
.side-label .chev { font-size: 9px; transition: transform .2s; color: inherit; opacity:.6; }
.side-label[aria-expanded="true"] .chev { transform: rotate(0deg); }
.side-label[aria-expanded="false"] .chev { transform: rotate(-90deg); }
.side-items { overflow: hidden; transition:max-height .25s ease; }
.side-label[aria-expanded="true"] + .side-items { max-height:600px; }
.side-label[aria-expanded="false"] + .side-items { max-height:0; opacity:0; }
.side-link {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text);
  margin-bottom: 2px; font-weight: 500; font-size:13px; transition:all .12s;
  position:relative; overflow:hidden;
}
.side-link::before {
  content:''; position:absolute; left:0; top:8px; bottom:8px; width:3px;
  border-radius:0 2px 2px 0; background:transparent; transition:background .15s;
}
.side-link:hover { background: var(--bg); text-decoration: none; }
.side-link:hover::before { background: var(--brand); }
.side-link.active { background: var(--brand); color: #fff; }

.content { flex: 1; padding: 18px 22px; min-width: 0; }

/* ---------- Títulos y acciones de la vista ---------- */
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.page-head { min-width: 0; }
.page-head h1 { min-width: 0; }
.page-head .count { min-width: 0; }
.page-head h1 {
  font-size: 20px; margin: 0; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.page-head .count { color: var(--text-soft); font-weight: 400; }
.page-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 8px; border: 1px solid var(--line-strong);
  background: var(--card); color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: #f1f2f4; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.icon { width: 32px; height: 32px; padding: 0; justify-content: center; }

/* ---------- Icons (sombrados Unicode / georigen) ---------- */
.btn i, .btn .i { font-style: normal; }

/* ---------- Barras de búsqueda / filtros ---------- */
.toolbar {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px;
}
.searchbar {
  position: relative; flex: 1; min-width: 220px; max-width: 420px;
}
.searchbar .icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-soft); font-size: 14px; pointer-events: none;
}
.searchbar input {
  width: 100%; padding: 8px 12px 8px 34px; border: 1px solid var(--line-strong);
  border-radius: 8px; outline: none; font-size: 13px; background: var(--card);
}
.searchbar input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand); }
.fgroup { display: flex; align-items: center; gap: 6px; }
.fgroup select {
  border: 1px solid var(--line-strong); border-radius: 8px; padding: 8px 10px;
  background: var(--card); font-size: 13px; outline: none;
}
.fgroup .fbtn {
  border: 1px solid var(--line-strong); background: var(--card);
  border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 13px;
}
.fgroup .fbtn:hover { background: #f1f2f4; }

/* ---------- Tabla (vista lista) ---------- */
.table-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.o { width: 100%; border-collapse: collapse; }
table.o thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--text-soft); background: var(--table-head);
  padding: 9px 14px; border-bottom: 1px solid var(--line); font-weight: 600;
}
table.o tbody td { padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.o tbody tr:last-child td { border-bottom: none; }
table.o tbody tr:hover { background: #fbfcfe; }
table.o .num { text-align: right; font-variant-numeric: tabular-nums; }
table.o .money { font-variant-numeric: tabular-nums; font-weight: 600; }

/* estados / badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 3px 9px; border-radius: 999px; font-weight: 500;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.draft    { background: #fdf3e0; color: #9a6b00; }
.badge.confirm  { background: #e8f6ee; color: #158a4b; }
.badge.done     { background: #e8f6ee; color: #158a4b; }
.badge.cancel   { background: #fdf0ef; color: #b83c32; }
.badge.void     { background: #f2f3f5; color: #6b7280; }

/* ---------- Tarjetas / panel de acciones ---------- */
.cards-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.kan-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; box-shadow: var(--shadow); cursor: pointer;
  transition: box-shadow .12s, border-color .12s;
}
.kan-card:hover { border-color: var(--brand); box-shadow: var(--shadow-pop); }
.pos-card-body { display: flex; align-items: flex-start; gap: 10px; min-height: 64px; }
.pos-card-info { flex: 1; min-width: 0; }
.pos-card-thumb {
  flex-shrink: 0; width: 64px; height: 64px;
  border-radius: 4px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: var(--line);
}
.pos-card-thumb img { width: 100%; height: 100%; object-fit: contain; }
.kan-card .t { font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.kan-card .sub { color: var(--text-soft); font-size: 12px; margin-top: 2px; }
.kan-card .izq { margin-top: 10px; color: var(--text-soft); font-size: 12px; }
.kan-card .ico { font-size: 16px; opacity: .8; }
.pos-card-img { height: 80px; overflow: hidden; display: flex; align-items: center; justify-content: center; background: #f9f9f9; border-radius: 6px; margin-bottom: 8px; }
.pos-card-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.kan-card .card-field {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.kan-card .card-field:last-child { border-bottom: none; }
.kan-card .card-label { color: var(--text-soft); font-size: 11px; font-weight: 600; text-transform: uppercase; }
.kan-card .card-value { font-weight: 500; text-align: right; }
.kan-card .card-value.money { font-variant-numeric: tabular-nums; font-weight: 700; }

.view-toggle { display: flex; gap: 4px; align-items: center; margin: 0 8px; }
.view-toggle .btn { padding: 4px 10px; font-size: 12px; color: rgba(255,255,255,.85); background: rgba(255,255,255,.1); border-color: transparent; }
.view-toggle .btn:hover { background: rgba(255,255,255,.2); color: #fff; }
.view-toggle .btn.active { background: rgba(255,255,255,.25); color: #fff; }

/* ---------- Vistas formulario ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.form-grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; align-items: start; }
.form-grid-2cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.form-error {
  background: #fdecea; border: 1px solid #e57373; color: #c62828;
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px;
  margin-bottom: 14px; line-height: 1.4;
}
.field input.is-invalid, .field select.is-invalid, .field textarea.is-invalid {
  border-color: #e57373; box-shadow: 0 0 0 3px rgba(229,115,115,.15);
}
.gallery-cover {
  width: 100%; aspect-ratio: 4 / 3; border-radius: 8px; overflow: hidden;
  position: relative; background: #f0f0f0; display: flex; align-items: center;
  justify-content: center; border: 1px solid var(--line); margin-bottom: 10px;
}
.gallery-cover img { width: 100%; height: 100%; object-fit: contain; }
.gallery-cover-empty { text-align: center; color: var(--text-soft); font-size: 12px; line-height: 1.5; }
.gallery-cover-empty span { font-size: 11px; color: var(--text-soft); }
.gallery-cover-tag {
  position: absolute; bottom: 8px; right: 8px; background: var(--brand);
  color: #fff; font-size: 10px; padding: 2px 7px; border-radius: 20px;
}
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.panel .panel-title {
  font-size: 13px; font-weight: 600; color: var(--text-soft);
  text-transform: uppercase; letter-spacing: .5px; margin: 0 0 12px;
}
.panel-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.panel-title-row .panel-title { margin: 0; }
.panel-subtitle { margin: 10px 0 8px; font-size: 12px; font-weight: 700; color: var(--text-soft); text-transform: uppercase; letter-spacing: .5px; }
.col-cards { min-height: 48px; padding: 4px; }
.col-cards.drag-over { background: rgba(178,49,103,.06); border-radius: 6px; }
.form-card {
  background: var(--card); border: 1px solid var(--line); border-radius: 8px;
  margin-bottom: 8px; padding: 10px 10px 6px; display: flex; gap: 8px;
  transition: opacity .12s, box-shadow .12s; cursor: default;
}
.form-card:hover { box-shadow: 0 1px 4px rgba(0,0,0,.06); }
.form-card.is-dragging-card { opacity: .45; }
.card-drag {
  cursor: grab; color: var(--text-soft); font-size: 15px; line-height: 1.2;
  padding: 0 4px; user-select: none; -webkit-user-select: none; flex-shrink: 0;
  border-radius: 4px; display: flex; align-items: center;
}
.card-drag:hover { background: var(--brand-light); color: var(--brand); }
.card-drag:active { cursor: grabbing; }
.card-body { flex: 1; min-width: 0; }
.form-card.drop-before { border-top: 3px solid var(--brand); }
.form-card.drop-after { border-bottom: 3px solid var(--brand); }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong);
  border-radius: 8px; font-size: 13px; outline: none; background: var(--card); color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(178,49,103,.12); }
.field .step { font-size: 11px; color: var(--text-soft); margin-top: 3px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.side-panel .stat { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--line); }
.side-panel .stat:last-child { border-bottom: none; }
.side-panel .stat .v { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Notificaciones / mensajes ---------- */
.alert-error {
  background: #fce4e4;
  border: 1px solid #e57373;
  color: #c62828;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 14px;
  font-size: 13px;
}
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: 8px; box-shadow: var(--shadow-pop); padding: 12px 16px;
  min-width: 260px;
}
.toast.error { border-left-color: var(--danger); }
.toast .msg { font-weight: 500; }
.toast .sub { color: var(--text-soft); font-size: 12px; margin-top: 2px; }

/* ---------- Biblioteca / Mediateca ---------- */
.library-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }
.library-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; position: relative; box-shadow: var(--shadow);
  transition: box-shadow .12s;
}
.library-card:hover { box-shadow: var(--shadow-pop); }
.library-thumb {
  height: 140px; overflow: hidden; background: #f0f0f0;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.library-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.library-info { padding: 8px 10px; }
.library-name {
  font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis;
}
.library-meta { font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.library-delete {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px;
  border: none; border-radius: 4px; background: rgba(0,0,0,.5); color: #fff;
  cursor: pointer; font-size: 12px; display: flex; align-items: center;
  justify-content: center; opacity: 0; transition: opacity .12s;
}
.library-card:hover .library-delete { opacity: 1; }
.library-delete:hover { background: var(--danger); }

.upload-zone {
  background: var(--card); border: 2px dashed var(--line-strong);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px; text-align: center;
}
.upload-zone:hover { border-color: var(--brand); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: var(--card); border-radius: var(--radius); padding: 20px 24px;
  min-width: 300px; box-shadow: var(--shadow-pop);
}

/* ---------- Modales globales (sucursales, devoluciones, etc.) ---------- */
.gs-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1400;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(10, 15, 22, .55);
}
.gs-modal-overlay.show { display: flex; }
.gs-modal-card {
  width: min(620px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line-strong);
  border-radius: 16px;
  box-shadow: 0 16px 50px rgba(0, 0, 0, .30);
}
.gs-modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px 12px;
  border-bottom: 1px solid var(--line);
}
.gs-modal-head h3 { margin: 0; font-size: 17px; }
.gs-modal-x {
  border: 0;
  background: transparent;
  color: var(--text-soft);
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.gs-modal-x:hover { color: var(--text); }
.gs-modal-body { padding: 16px 18px; }
.gs-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
}

/* ---------- Menú contextual (Biblioteca) ---------- */
.ctx-menu {
  position: fixed; z-index: 100; width: 220px;
  background: var(--card); border: 1px solid var(--line-strong);
  border-radius: 8px; box-shadow: 0 4px 20px rgba(0,0,0,.18);
  padding: 6px 0; font-size: 13px; user-select: none;
}
.ctx-header { padding: 8px 14px 6px; border-bottom: 1px solid var(--line); }
.ctx-filename { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ctx-dims { font-size: 11px; color: var(--text-soft); margin-top: 2px; }
.ctx-section { padding: 6px 14px; }
.ctx-row { display: flex; justify-content: space-between; align-items: center; padding: 3px 0; font-size: 12px; }
.ctx-label { color: var(--text-soft); }
.ctx-value { font-weight: 500; text-align: right; }
.ctx-divider { height: 1px; background: var(--line); margin: 4px 0; }
.ctx-action {
  padding: 8px 14px; cursor: pointer; display: flex; align-items: center; gap: 8px;
  transition: background .1s;
}
.ctx-action:hover { background: var(--bg); }
.ctx-danger { color: var(--danger); }
.ctx-danger:hover { background: #fdf0ef; }

/* ---------- Modal de detalle (Biblioteca) ---------- */
.media-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 60;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.media-modal {
  background: var(--card); border-radius: var(--radius);
  width: 100%; max-width: 900px; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: 0 8px 40px rgba(0,0,0,.25);
  overflow: hidden;
}
.media-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; border-bottom: 1px solid var(--line);
}
.media-nav { display: flex; align-items: center; gap: 10px; }
.media-nav-btn {
  background: none; border: 1px solid var(--line-strong); border-radius: 6px;
  padding: 4px 10px; cursor: pointer; font-size: 14px; color: var(--text);
}
.media-nav-btn:hover { background: var(--bg); }
.media-counter { font-size: 12px; color: var(--text-soft); min-width: 60px; text-align: center; }
.media-close {
  background: none; border: none; font-size: 24px; cursor: pointer;
  color: var(--text-soft); padding: 0 4px; line-height: 1;
}
.media-close:hover { color: var(--text); }

.media-modal-body {
  display: flex; flex: 1; overflow-y: auto; min-height: 300px;
}
.media-preview {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  background: #f0f0f0; min-height: 250px;
}
.media-preview .preview-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  width: 100%; padding: 16px; min-height: 0;
}
.media-preview .preview-area img, .media-preview .preview-area canvas {
  max-width: 100%; max-height: 100%; object-fit: contain; display: block;
}
.media-preview.edit-mode .preview-area { flex: 7; }
.media-preview.edit-mode .editor-wrap { flex: 3; display: flex; flex-direction: column; width: 100%; }

.media-sidebar {
  width: 400px; min-width: 320px; padding: 16px;
  border-left: 1px solid var(--line); overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.media-meta-section { display: flex; flex-direction: column; gap: 6px; }
.media-meta-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 12px; padding: 3px 0;
}
.media-meta-label { color: var(--text-soft); font-weight: 600; white-space: nowrap; margin-right: 12px; }
.media-meta-value { text-align: right; font-weight: 500; word-break: break-all; }
.media-divider { height: 1px; background: var(--line); margin: 8px 0; }

.media-fields { display: flex; flex-direction: column; gap: 8px; }
.media-field label { display: block; font-size: 11px; font-weight: 600; color: var(--text-soft); margin-bottom: 3px; }
.media-input {
  width: 100%; padding: 7px 9px; border: 1px solid var(--line-strong);
  border-radius: 6px; font-size: 13px; outline: none; background: var(--card);
  color: var(--text); font-family: inherit;
}
.media-input:focus { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(113,75,103,.15); }
.media-textarea { resize: vertical; min-height: 50px; }
.media-save-status { font-size: 11px; min-height: 18px; text-align: right; }
.media-save-status.saving { color: var(--brand); }
.media-save-status.saved { color: var(--ok); }
.media-save-status.error { color: var(--danger); }
.media-save-status.unsaved { color: var(--warn); }

.media-url-row { display: flex; flex-direction: column; gap: 4px; }
.media-url-box { display: flex; gap: 4px; }
.media-url-input { flex: 1; font-size: 11px; background: var(--bg); cursor: default; }

.media-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.media-actions .btn { flex: 1; justify-content: center; font-size: 12px; padding: 6px 10px; }

@media (max-width: 700px) {
  .media-modal-body { flex-direction: column; }
  .media-sidebar { width: 100%; min-width: 0; border-left: none; border-top: 1px solid var(--line); }
  .media-preview { min-height: 180px; }
  .media-preview img { max-height: 35vh; }
}

/* ---------- Editor de imágenes (Biblioteca) ---------- */
#editor-canvas { max-width: 100%; max-height: 55vh; cursor: default; }
.editor-toolbar {
  display: flex; flex-wrap: wrap; gap: 4px; padding: 8px;
  background: var(--bg); border-top: 1px solid var(--line);
  width: 100%; justify-content: center;
}
.editor-btn {
  padding: 5px 10px; border: 1px solid var(--line-strong); border-radius: 6px;
  background: var(--card); color: var(--text); cursor: pointer;
  font-size: 12px; font-family: inherit; white-space: nowrap;
}
.editor-btn:hover { background: var(--brand-light); border-color: var(--brand); }
.editor-save { background: var(--brand); border-color: var(--brand); color: #fff; }
.editor-save:hover { background: var(--brand-dark); }
.editor-sep { width: 1px; height: 24px; background: var(--line); margin: 0 4px; align-self: center; }
.resize-bar {
  display: flex; flex-flow: row nowrap; align-items: center; gap: 6px;
  padding: 4px 8px; background: var(--card); border-top: 1px solid var(--line);
  font-size: 12px; width: 100%; min-height: 32px;
}
.rz-input { width: 60px; padding: 3px 5px; border: 1px solid var(--line-strong); border-radius: 4px; font-size: 12px; text-align: center; }

/* ---------- Product detail card (modal) ---------- */
tr[data-ext-id], .kan-card[data-ext-id] { cursor: pointer; }
.product-detail-card {
  background: var(--card); border-radius: var(--radius);
  width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto;
  box-shadow: 0 8px 40px rgba(0,0,0,.25); position: relative; padding: 24px;
}
.modal-close {
  position: absolute; top: 12px; right: 14px; background: none; border: none;
  font-size: 22px; cursor: pointer; color: var(--text-soft); line-height: 1;
}
.modal-close:hover { color: var(--text); }
.pdc-loading { text-align: center; color: var(--text-soft); padding: 40px; font-size: 14px; }
.pdc-head { display: flex; align-items: center; gap: 14px; margin-bottom: 16px; padding-right: 24px; }
.pdc-thumb { width: 88px; height: 88px; min-width: 88px; border-radius: 10px; overflow: hidden; background: #f0f0f0; display: flex; align-items: center; justify-content: center; cursor: pointer; border: 1px solid var(--line); }
.pdc-thumb img { width: 100%; height: 100%; object-fit: contain; }
.pdc-thumb:hover { border-color: var(--brand); }
.pdc-noimg { font-size: 24px; color: var(--text-soft); cursor: default; font-weight: 700; }
.pdc-hd { font-size: 18px; font-weight: 700; margin: 0; }
.pdc-status { font-size: 12px; color: var(--ok); margin-top: 2px; }
.pdc-sec { display: flex; flex-direction: column; gap: 0; }
.pdc-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px;
}
.pdc-row:last-child { border-bottom: none; }
.pdc-lbl { color: var(--text-soft); font-weight: 600; font-size: 12px; }
.pdc-val { font-weight: 500; text-align: right; word-break: break-all; }
.pdc-val.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.pdc-desc { flex-direction: column; align-items: flex-start; gap: 4px; }
.pdc-desc .pdc-lbl { margin-bottom: 2px; }
.pdc-gallery { display: flex; gap: 6px; margin-top: 12px; flex-wrap: wrap; }
.pdc-gallery-thumb { width: 48px; height: 48px; object-fit: cover; border-radius: 6px; border: 2px solid var(--line); cursor: pointer; opacity: .6; transition: opacity .12s, border-color .12s; }
.pdc-gallery-thumb:hover { opacity: 1; }
.pdc-gallery-thumb.active { opacity: 1; border-color: var(--brand); }
.pdc-desc .pdc-val { text-align: left; width: 100%; font-weight: 400; font-size: 12px; color: var(--text); }

/* ---------- Galería de imágenes (formulario producto) ---------- */
.gallery-drop { border: 2px dashed var(--line-strong); border-radius: var(--radius); padding: 12px; background: var(--card); transition: border-color .12s; }
.gallery-drop:hover { border-color: var(--brand); }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 8px; margin-bottom: 10px; }
.gallery-item { position: relative; border-radius: 8px; overflow: hidden; border: 2px solid var(--line); cursor: grab; height: 80px; display: flex; align-items: center; justify-content: center; background: #f5f5f5; transition: border-color .12s; }
.gallery-item:hover { border-color: var(--brand); }
.gallery-item.is-dragging { opacity: .45; border-color: var(--brand); }
.gallery-drop.is-drag-over { border-color: var(--brand); background: var(--brand-light); }
.library-card.is-dragging { opacity: .45; }
.gallery-item.is-cover { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(113,75,103,.25); }
.gallery-item img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gallery-badge { position: absolute; top: 2px; left: 2px; font-size: 14px; color: var(--warn); text-shadow: 0 0 3px rgba(0,0,0,.3); line-height: 1; pointer-events: none; }
.gallery-remove { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border: none; border-radius: 4px; background: rgba(0,0,0,.5); color: #fff; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; opacity: 0; transition: opacity .12s; line-height: 1; }
.gallery-item:hover .gallery-remove { opacity: 1; }
.gallery-remove:hover { background: var(--danger); }
.gallery-upload { display: flex; flex-direction: column; align-items: flex-start; }

/* ---------- Selector de medios (modal: subir / biblioteca) ---------- */
.media-modal .media-modal-body { min-height: 260px; }
.media-tabs { display: flex; gap: 6px; }
.media-tab {
  background: none; border: 1px solid transparent; border-bottom: 2px solid transparent;
  padding: 6px 12px; cursor: pointer; font-size: 13px; color: var(--text-soft);
  font-family: inherit; border-radius: 6px 6px 0 0; font-weight: 600;
}
.media-tab:hover { color: var(--text); background: var(--bg); }
.media-tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.media-tab-pane { width: 100%; }

.lib-pick-grid { max-height: 300px; overflow-y: auto; padding-bottom: 4px; }
.lib-pick-card { border-width: 2px; cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.lib-pick-card:hover { box-shadow: var(--shadow-pop); }
.lib-pick-card.is-selected { border-color: var(--brand); box-shadow: 0 0 0 2px rgba(113,75,103,.25); }
.lib-pick-card .library-thumb { height: 80px; }
.lib-pick-check {
  position: absolute; top: 6px; right: 6px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--brand); color: #fff; font-size: 13px; display: flex;
  align-items: center; justify-content: center; line-height: 1; pointer-events: none;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}

/* ---------- Responsivo básico ---------- */
@media (max-width: 1100px) {
  .form-grid-3 { grid-template-columns: 1fr 1fr; }
  .form-grid-3 .panel:last-child { grid-column: 1 / -1; }
  .form-grid-3 .panel:last-child .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  }
}
@media (max-width: 700px) {
  .form-grid-3 { grid-template-columns: 1fr; }
  .form-grid-3 .panel:last-child { grid-column: auto; }
}
@media (max-width: 900px) {
  .form-grid-2cols { grid-template-columns: 1fr; }
  .form-grid-2 { grid-template-columns: 1fr; }
  .form { grid-template-columns: 1fr; }
}

/* ---------- Base responsive global (móvil/tablet/touch) ---------- */
@media (max-width: 1024px) {
  /* Evita overflow por columnas fijas en layouts compartidos */
  .form-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  /* Topbar: permitir wrap real sin overflow */
  .topbar {
    height: auto;
    min-height: 46px;
    padding: 6px 10px;
    flex-wrap: wrap;
    row-gap: 6px;
  }
  .topbar .spacer { display: none; }
  .topbar .menubtn { width: 44px; height: 44px; font-size: 20px; }

  /* Breadcrumb ocupa línea completa y se trunca */
  .o-breadcrumb {
    width: 100%;
    order: 10;
  }

  /* Acciones del topbar (p.ej. view-toggle) no deben forzar overflow */
  .topbar .view-toggle {
    order: 12;
    width: 100%;
    justify-content: flex-start;
  }

  /* Userbox en segunda línea, sin forzar overflow */
  .topbar .userbox {
    width: 100%;
    order: 20;
    justify-content: flex-end;
    padding-left: 0;
  }
  .topbar .userbox > span:not(.avatar):not(.badge) { max-width: 140px; }

  /* Acciones/títulos compartidos */
  .page-head { flex-wrap: wrap; align-items: flex-start; }
  .page-actions {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  /* Sidebar en móvil: limitar ancho al viewport */
  .sidebar { max-width: 85vw; }

  /* Touch targets globales (solo en pantallas pequeñas) */
  .btn { min-height: 44px; padding: 10px 14px; }
  .btn.icon { width: 44px; height: 44px; }
  .side-label { min-height: 44px; padding: 12px 10px; }
  .side-link { padding: 12px 10px; }
}

@media (max-width: 390px) {
  /* Muy pequeño: compactar el header sin perder navegación */
  .topbar .userbox > span:not(.avatar):not(.badge) { display: none; }
  .o-breadcrumb .sep { display: none; }
}

/* --- Atributos de producto --- */
.attr-list { display: flex; flex-direction: column; gap: 10px; }
.attr-group { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; background: var(--bg, #fafafa); }
.attr-header { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.attr-name { font-weight: 600; font-size: 13px; color: var(--text); }
.attr-code { font-size: 11px; color: var(--text-soft); }
.attr-del { background: none; border: none; color: var(--text-soft); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; margin-left: auto; }
.attr-del:hover { color: var(--danger); }
.attr-values { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; }
.attr-tag { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; background: var(--brand-light); color: var(--brand-dark); border-radius: 12px; padding: 2px 8px; white-space: nowrap; }
.attr-tag-del { background: none; border: none; color: var(--brand-dark); cursor: pointer; font-size: 13px; line-height: 1; padding: 0 1px; opacity: .6; }
.attr-tag-del:hover { opacity: 1; color: var(--danger); }
.attr-add-val { display: inline-flex; align-items: center; gap: 4px; }
.attr-val-input { width: 100px !important; padding: 3px 6px !important; font-size: 12px !important; border-radius: 10px !important; }
.attr-new input { padding: 6px 8px !important; font-size: 12px !important; }

/* --- Variantes --- */
.variant-list { display: flex; flex-direction: column; gap: 6px; }
.variant-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg, #fafafa); }
.variant-info { display: flex; align-items: center; gap: 8px; min-width: 180px; }
.variant-name { font-weight: 600; font-size: 13px; color: var(--text); }
.variant-sku { font-size: 11px; color: var(--text-soft); }
.variant-attrs { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.variant-del { margin-left: auto; font-size: 16px; padding: 0 4px !important; }
.variant-attrs-select { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 4px; }
.variant-attr-row { display: flex; align-items: center; gap: 4px; }
.variant-row.variant-edit { flex-direction: column; align-items: stretch; padding: 12px; background: #fff; border-color: var(--brand); }
.variant-edit-form { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.variant-edit-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.variant-edit-row label { font-size: 11px; font-weight: 600; color: var(--text-soft); white-space: nowrap; min-width: 48px; }
.variant-edit-row input { padding: 5px 8px; font-size: 12px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--card); }
.variant-edit-row select { padding: 5px 8px; font-size: 12px; border: 1px solid var(--line-strong); border-radius: 6px; }
.variant-edit-actions { display: flex; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.ve-inherit-label { display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--text-soft); cursor: pointer; }
.ve-inherit-label input { margin: 0; cursor: pointer; }
.variant-price { font-size: 12px; font-weight: 600; color: var(--brand); }
.variant-price.inherited { color: var(--text-soft); font-weight: 400; font-style: italic; }
.variant-status-tag { font-size: 10px; background: var(--warn); color: #fff; border-radius: 4px; padding: 1px 5px; margin-left: 4px; vertical-align: middle; }

/* --- Tabs del formulario --- */
.form-tabs { margin-top: 16px; }
.tab-nav { display: flex; gap: 2px; border-bottom: 2px solid var(--line); margin-bottom: 16px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.tab-btn { padding: 10px 18px; border: none; background: transparent; font-size: 13px; font-weight: 600; color: var(--text-soft); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: color .15s, border-color .15s; white-space: nowrap; }
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* Tabs como acordeón en móvil */
@media (max-width: 700px) {
  .tab-nav { display: none; flex-direction: column; border-bottom: none; margin-bottom: 0; }
  .tab-btn { display: block; width: 100%; text-align: left; padding: 12px 14px; border: 1px solid var(--line); border-bottom: none; border-radius: 0; margin-bottom: 0; font-size: 14px; background: var(--card); }
  .tab-btn:first-child { border-radius: 8px 8px 0 0; }
  .tab-btn:last-child { border-radius: 0 0 8px 8px; border-bottom: 1px solid var(--line); }
  .tab-btn.active { background: var(--brand-light); color: var(--brand-dark); border-color: var(--brand); }
  .tab-content { display: none; border: 1px solid var(--line); border-top: none; border-radius: 0 0 8px 8px; padding: 12px; margin-top: 0; background: var(--bg, #fafafa); }
  .tab-content.active { display: block; }
  .tab-nav.show-mobile { display: flex; }
}

/* ============================================================
   Mejoras contables / tesorería — KPI, badges, inputs, transiciones
   ============================================================ */
.kpi-card {
  background: var(--card); border:1px solid #e8ecf1; border-radius:14px;
  padding:20px 18px; position:relative; overflow:hidden;
}
.kpi-card.green::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; background:linear-gradient(135deg,#22c55e,#158a4b); }
.kpi-card.red::before   { content:''; position:absolute; top:0; left:0; right:0; height:3px; background:linear-gradient(135deg,#ef4444,#b42318); }
.kpi-card.blue::before  { content:''; position:absolute; top:0; left:0; right:0; height:3px; background:linear-gradient(135deg,#6366f1,#1d4ed8); }
.kpi-card .lbl { font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.6px; color:var(--text-soft); margin-bottom:8px; }
.kpi-card .val { font-size:30px; font-weight:800; letter-spacing:-.5px; line-height:1; }
.kpi-card .val.ok{color:#158a4b}.kpi-card .val.rd{color:#b42318}.kpi-card .val.bl{color:#1d4ed8}

.tag { display:inline-block; font-size:10px; font-weight:700; padding:3px 9px; border-radius:6px; }
.tag.asset{background:#e8f0fd;color:#1d4ed8}.tag.liab{background:#fef2dc;color:#9a6b00}
.tag.equity{background:#e8f6ee;color:#158a4b}.tag.income{background:#ede9fe;color:#7c3aed}
.tag.expense{background:#fdecec;color:#b42318}

.f-input { padding:9px 12px; border:1px solid #dfe5ec; border-radius:10px; background:var(--card); color:var(--text); font-size:13px; outline:none; transition:border-color .15s,box-shadow .15s; }
.f-input:focus { border-color:var(--brand); box-shadow:0 0 0 3px rgba(113,75,103,.1); }

.tbl-mod { width:100%; border-collapse:collapse; font-size:13px; }
.tbl-mod th { text-align:left; padding:10px 12px; font-size:11px; font-weight:700; text-transform:uppercase; letter-spacing:.5px; color:var(--text-soft); border-bottom:2px solid #e4e9f0; background:#fafbfc; }
.tbl-mod td { text-align:left; padding:10px 12px; border-bottom:1px solid #f0f3f7; }
.tbl-mod tr:hover { background:#fafbfc; }
.tbl-mod .num { text-align:right; font-variant-numeric:tabular-nums; }
.tbl-mod .row-total td { border-top:2px solid #cfd8e3; background:#fafbfc; padding-top:14px; font-size:15px; font-weight:800; }

.sec-fade { animation:secFade .25s ease; }
@keyframes secFade { from{opacity:.6;transform:translateY(4px)} to{opacity:1;transform:translateY(0)} }
