/* css/components.css — piezas reutilizables */

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 40px; padding: 0 16px;
  border-radius: var(--r-md); border: 1px solid transparent;
  font-weight: 600; font-size: var(--fs-sm); white-space: nowrap;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.08s var(--ease);
  text-decoration: none !important;
}
.btn svg { width: 18px; height: 18px; flex: none; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-strong); }
.btn-secondary { background: var(--surface); color: var(--ink); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-sunken); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-sunken); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #E9C4C0; }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); }
.btn-dark { background: var(--ink); color: #fff; }
.btn-dark:hover:not(:disabled) { background: #000; }
.btn:disabled { opacity: 0.5; }
.btn-lg { min-height: 52px; font-size: var(--fs-md); padding: 0 22px; border-radius: var(--r-lg); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: var(--fs-xs); }
.btn-block { width: 100%; }
.btn-icon { width: 36px; min-height: 36px; padding: 0; }
.link-btn { background: none; border: 0; padding: 0; color: var(--brand-strong); font-weight: 600; font-size: inherit; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Superficies ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h2 { font-size: var(--fs-md); }
.card-head .sub { font-size: var(--fs-xs); color: var(--ink-2); margin-top: 2px; }
.card-body { padding: 16px 20px; }
.card-foot { padding: 12px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }

.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-head h1 { font-size: 1.625rem; }
.page-head .lead { color: var(--ink-2); margin-top: 4px; }
.page-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--ink-2); margin-bottom: 10px; font-weight: 600; }
.back-link svg { width: 16px; height: 16px; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.kpi { padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-2); font-weight: 500; }
.kpi-label svg { width: 16px; height: 16px; color: var(--ink-3); }
.kpi-value { font-size: 1.625rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: var(--fs-xs); color: var(--ink-2); }
.kpi.is-danger .kpi-value { color: var(--danger); }
.kpi.is-warn .kpi-value { color: var(--warn); }
.kpi.is-info .kpi-value { color: var(--info); }

/* ---------- Badges y puntos de estado ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2px 9px 2px 8px; border-radius: 999px;
  font-size: var(--fs-xs); font-weight: 600; white-space: nowrap; line-height: 1.6;
  background: var(--muted-bg); color: var(--muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 99px; background: currentColor; flex: none; }
.badge.no-dot::before { display: none; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-info { background: var(--info-bg); color: var(--info); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.badge-danger { background: var(--danger-bg); color: var(--danger); }
.badge-muted { background: var(--muted-bg); color: var(--muted); }
.badge-solid-danger { background: var(--danger); color: #fff; }
.badge-solid-danger::before { background: #fff; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 99px; background: var(--muted); }
.dot-ok { background: var(--ok); } .dot-info { background: var(--info); } .dot-warn { background: var(--warn); } .dot-danger { background: var(--danger); }

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; position: relative; } /* contiene los .sr-only absolutos */
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-weight: 600; color: var(--ink-2); font-size: var(--fs-xs);
  text-transform: uppercase; letter-spacing: 0.05em;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table th.num, .table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tr.is-clickable { cursor: pointer; transition: background 0.12s var(--ease); }
.table tr.is-clickable:hover { background: var(--surface-2); }
.table tr.is-highlight { background: #FFF7EC; box-shadow: inset 3px 0 0 var(--amber); }
.prod-cell { display: flex; align-items: center; gap: 12px; min-width: 220px; }
.prod-cell img { width: 40px; height: 40px; border-radius: 10px; flex: none; background: var(--surface-sunken); }
.prod-cell .name { font-weight: 600; color: var(--ink); }
.prod-cell .meta { font-size: var(--fs-xs); color: var(--ink-2); }
.qty-in { color: var(--ok); font-weight: 650; }
.qty-out { color: var(--danger); font-weight: 650; }

/* Tabla → tarjetas en móvil */
@media (max-width: 767px) {
  .table.responsive thead { display: none; }
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table.responsive td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: right; }
  .table.responsive td::before { content: attr(data-label); color: var(--ink-2); font-size: var(--fs-xs); text-align: left; font-weight: 500; }
  .table.responsive td.cell-main { display: block; text-align: left; padding-bottom: 8px; }
  .table.responsive td.cell-main::before { display: none; }
  .table.responsive td.num { text-align: right; }
  .table.responsive td.cell-hide-m { display: none; }
}

/* ---------- Formularios ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-2); }
.field .error-text { font-size: var(--fs-xs); color: var(--danger); font-weight: 600; }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--r-md); background: var(--surface);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.textarea { min-height: 84px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: var(--focus); }
.input.is-invalid, .select.is-invalid { border-color: var(--danger); background: #FFFAF9; }
.input-num { text-align: right; font-variant-numeric: tabular-nums; }
.input-prefix { position: relative; }
.input-prefix > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.input-prefix .input { padding-left: 26px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid .span-2 { grid-column: span 2; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2 { grid-column: auto; } }
.req { color: var(--danger); }

.segmented { display: inline-flex; background: var(--surface-sunken); padding: 4px; border-radius: var(--r-md); gap: 4px; flex-wrap: wrap; }
.segmented button {
  border: 0; background: transparent; padding: 8px 14px; border-radius: 8px; font-weight: 600;
  font-size: var(--fs-sm); color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px;
}
.segmented button svg { width: 18px; height: 18px; }
.segmented button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- Chips y pestañas ---------- */
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  padding: 7px 14px; border-radius: 999px; font-size: var(--fs-sm); font-weight: 550; white-space: nowrap;
  transition: all 0.15s var(--ease); min-height: 36px;
}
.chip:hover { border-color: var(--ink-3); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.chip .chip-count { margin-left: 6px; opacity: 0.7; font-variant-numeric: tabular-nums; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.tabs button {
  border: 0; background: transparent; padding: 12px 14px; font-weight: 600; color: var(--ink-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-size: var(--fs-sm);
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--brand-strong); border-bottom-color: var(--brand); }
.tabs .tab-count { display: inline-block; margin-left: 6px; padding: 0 7px; border-radius: 99px; background: var(--surface-sunken); color: var(--ink-2); font-size: var(--fs-xs); }
.tabs button[aria-selected="true"] .tab-count { background: var(--brand-soft); color: var(--brand-strong); }

.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.toolbar .search-input { position: relative; flex: 1 1 240px; max-width: 360px; }
.toolbar .search-input svg { position: absolute; left: 11px; top: 12px; width: 18px; height: 18px; color: var(--ink-3); }
.toolbar .search-input .input { padding-left: 36px; }
.toolbar .select { width: auto; min-width: 170px; }

/* ---------- Progreso ---------- */
.progress { height: 8px; background: var(--surface-sunken); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--olive); border-radius: 99px; transition: width 0.5s var(--ease); }
.progress.is-warn > span { background: var(--amber); }
.progress.is-ok > span { background: var(--ok); }
.progress.thin { height: 5px; }

/* ---------- Callouts y vacíos ---------- */
.callout {
  display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r-md);
  background: var(--info-bg); color: #24506D; font-size: var(--fs-sm);
}
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.callout.is-warn { background: var(--warn-bg); color: #7A4508; }
.callout.is-danger { background: var(--danger-bg); color: #8A302A; }
.callout.is-ok { background: var(--ok-bg); color: #2C5C38; }
.callout.is-neutral { background: var(--surface-sunken); color: var(--ink-2); }
.empty { text-align: center; padding: 40px 20px; color: var(--ink-2); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 10px; color: var(--ink-3); }
.empty strong { display: block; color: var(--ink); margin-bottom: 4px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; background: rgba(28, 22, 18, 0.5);
  display: grid; place-items: center; padding: 20px; animation: fade-in 0.16s var(--ease);
  overflow-y: auto;
}
.modal {
  width: min(560px, 100%); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--r-xl); box-shadow: var(--shadow-lg);
  animation: modal-in 0.2s var(--ease);
}
.modal.is-wide { width: min(780px, 100%); }
.modal.is-narrow { width: min(420px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 20px 22px 14px; }
.modal-head h2 { font-size: 1.1875rem; }
.modal-head .sub { color: var(--ink-2); font-size: var(--fs-sm); margin-top: 3px; }
.modal-body { padding: 4px 22px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.modal-close { border: 0; background: transparent; width: 36px; height: 36px; border-radius: 99px; display: grid; place-items: center; color: var(--ink-2); flex: none; }
.modal-close:hover { background: var(--surface-sunken); color: var(--ink); }
.modal-close svg { width: 20px; height: 20px; }
@media (max-width: 767px) {
  .modal-backdrop { padding: 0; place-items: end stretch; }
  .modal, .modal.is-wide, .modal.is-narrow { width: 100%; max-height: 92vh; border-radius: var(--r-xl) var(--r-xl) 0 0; animation: sheet-in 0.22s var(--ease); }
  .modal-foot .btn { flex: 1; }
}
@keyframes sheet-in { from { transform: translateY(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Toasts ---------- */
.toast-root { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; display: flex; align-items: flex-start; gap: 10px; min-width: 280px; max-width: 420px;
  background: var(--ink); color: #fff; padding: 12px 14px; border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  font-size: var(--fs-sm); animation: toast-in 0.22s var(--ease);
}
.toast svg { width: 20px; height: 20px; flex: none; }
.toast.is-ok svg { color: #8FD19E; }
.toast.is-error { background: #5B1F1B; }
.toast.is-error svg { color: #FFB4AC; }
.toast.is-info svg { color: #A9D1EE; }
.toast.is-leaving { opacity: 0; transform: translateY(6px); transition: all 0.2s var(--ease); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@media (max-width: 767px) { .toast-root { left: 12px; right: 12px; bottom: 84px; align-items: stretch; } .toast { max-width: none; } }

/* ---------- Listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item.is-clickable { cursor: pointer; }
.list-item.is-clickable:hover { background: var(--surface-2); }

.dl { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 20px; margin: 0; }
.dl div { min-width: 0; }
.dl dt { font-size: var(--fs-xs); color: var(--ink-2); margin-bottom: 2px; }
.dl dd { margin: 0; font-weight: 600; overflow-wrap: anywhere; }
.dl.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 640px) { .dl.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Stepper de cantidad */
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--border-strong); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.stepper button { width: 34px; height: 34px; border: 0; background: transparent; display: grid; place-items: center; }
.stepper button:hover:not(:disabled) { background: var(--surface-sunken); }
.stepper button svg { width: 16px; height: 16px; }
.stepper button:disabled { opacity: 0.35; }
.stepper input { width: 42px; height: 34px; border: 0; text-align: center; font-weight: 650; font-variant-numeric: tabular-nums; background: transparent; }
.stepper input:focus { outline: none; background: var(--surface-2); }

.divider { height: 1px; background: var(--border); margin: 14px 0; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
@media (max-width: 1099px) { .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }
@media (max-width: 420px) { .kpi-value { font-size: 1.375rem; } .kpi { padding: 14px; } }

/* ---------- Imagen de producto y fallback ---------- */
.pimg { object-fit: cover; background: var(--surface-sunken); }
.img-fallback {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(160deg, #F7F3EC, #ECE5DA); color: var(--ink-3); text-align: center;
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.2; padding: 6px; overflow: hidden;
}
.img-fallback svg { width: 40%; max-width: 44px; height: auto; color: var(--brand); opacity: .75; }

/* Estado principal + dato secundario */
.status-cell { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 3px; }
.status-sub { font-size: var(--fs-xs); color: var(--ink-2); padding-left: 2px; white-space: nowrap; }
.status-sub.is-transit { color: var(--info); font-weight: 600; }
@media (max-width: 767px) { .table.responsive .status-cell { align-items: flex-end; } }
.pcard-img .img-fallback { display: flex; }
