/* ── Variables Kolder ────────────────────────────────────────────────────── */
:root {
  --bg:        #f0f4f8;
  --card:      #ffffff;
  --text:      #0d1b2a;
  --muted:     #5a6a7e;
  --border:    #d0dce8;
  --accent:    #d3ebfb;
  --btn:       #084999;
  --btn-text:  #ffffff;
  --btn2:      #eef5ff;
  --btn2-text: #084999;
  --danger:    #c0392b;
  --ok:        #0a7c4e;
  --chip-bg:   #eef5ff;
  --chip-text: #084999;
  --header-bg: #084999;
}

/* ── Reset y base ─────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

/* ── Layout ───────────────────────────────────────────────────────────────── */
.wrap { max-width: 1400px; margin: 0 auto; padding: 0 16px 40px; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header {
  background: var(--header-bg);
  color: #ffffff;
  padding: 22px 28px 20px;
  border-radius: 14px;
  margin: 20px 0 0;
}
.header h1 { font-size: 22px; font-weight: 800; color: #ffffff; margin-bottom: 4px; }
.header .muted { color: #b8d4f0; font-size: 14px; }
.header strong { color: #ffffff; }

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px 24px;
  margin: 14px 0;
  box-shadow: 0 1px 4px rgba(8,73,153,.06);
}
.card h2 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 2px solid var(--accent);
}

/* ── Botones ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-block;
  text-decoration: none;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 700;
  background: var(--btn);
  color: var(--btn-text);
  transition: background .15s, box-shadow .15s;
  line-height: 1.4;
}
.btn:hover { background: #063d80; box-shadow: 0 2px 8px rgba(8,73,153,.2); }
.btn-secondary {
  background: var(--btn2);
  color: var(--btn2-text);
  border: 1.5px solid #b8d4f0;
}
.btn-secondary:hover { background: #d3ebfb; border-color: #084999; }
.btn-danger { background: var(--danger); color: #fff; border: none; }
.btn-danger:hover { background: #a93226; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
.input {
  width: 100%;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}
.input:focus {
  outline: none;
  border-color: var(--btn);
  box-shadow: 0 0 0 3px rgba(8,73,153,.1);
}
.input[readonly] { background: #f0f6fc; color: var(--muted); cursor: not-allowed; }
select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%235a6a7e' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}
select.input option { background: #ffffff; color: var(--text); }
.label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Tabla ────────────────────────────────────────────────────────────────── */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 12px; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
  text-align: left;
  white-space: nowrap;
  padding: 11px 14px;
  background: #f0f6fc;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  border-bottom: 1px solid var(--border);
}
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: top; color: var(--text); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f5f9ff; }
.table a { color: var(--btn); }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.toolbar .left, .toolbar .right { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ── Chip ─────────────────────────────────────────────────────────────────── */
.chip {
  background: var(--chip-bg);
  color: var(--chip-text);
  border: 1px solid #b8d4f0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

/* ── Grilla KV ────────────────────────────────────────────────────────────── */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) { .grid2 { grid-template-columns: 1fr; } }
.kv {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: #f8fbff;
}
.kv .k { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kv .v { margin-top: 5px; font-weight: 700; white-space: pre-wrap; word-break: break-word; color: var(--text); }

/* ── Preview texto ────────────────────────────────────────────────────────── */
pre.preview {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fbff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  min-height: 120px;
  font-size: 13px;
  color: var(--text);
}

/* ── Status ───────────────────────────────────────────────────────────────── */
.status { margin-top: 12px; min-height: 18px; font-size: 14px; font-weight: 600; }
.status.ok  { color: var(--ok); }
.status.err { color: var(--danger); }

/* ── KPI cards ────────────────────────────────────────────────────────────── */
.kpi-wrap { display: flex; gap: 12px; flex-wrap: wrap; }
.kpi {
  flex: 1;
  min-width: 140px;
  background: #f0f7ff;
  border: 1px solid #b8d4f0;
  border-radius: 12px;
  padding: 14px 16px;
}
.kpi .kpi-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-value { font-size: 22px; font-weight: 800; color: var(--btn); margin-top: 4px; }

/* ── Badges de estado ─────────────────────────────────────────────────────── */
.estado-liberado   { background: #d1fae5; color: #065f46; }
.estado-bloqueado  { background: #fee2e2; color: #991b1b; }
.estado-cuarentena { background: #fef3c7; color: #92400e; }
.estado-despachado { background: #dbeafe; color: #1e40af; }
.estado-agotado    { background: #ede9fe; color: #5b21b6; }

/* ── Misceláneos ──────────────────────────────────────────────────────────── */
.small { font-size: 12px; color: var(--muted); }
.row { display: grid; gap: 8px; margin: 12px 0; }
.filter-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-box {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 24px rgba(8,73,153,.1);
}
.login-box h1 { font-size: 24px; font-weight: 800; color: var(--btn); text-align: center; margin-bottom: 4px; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 14px; margin-bottom: 24px; }
.login-box .field { margin-bottom: 16px; }
.login-box .field label { display: block; font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }

/* ── Spinner de carga ─────────────────────────────────────────────────────── */
.loading-overlay { display: none; flex-direction: column; align-items: center; justify-content: center; padding: 48px 0; gap: 14px; }
.loading-overlay.visible { display: flex; }
.spinner { width: 38px; height: 38px; border: 4px solid var(--accent); border-top-color: var(--btn); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); font-size: 14px; font-weight: 600; }

/* ── Paginación ───────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.pagination button { background: var(--btn2); border: 1.5px solid #b8d4f0; color: var(--btn2-text); border-radius: 8px; padding: 8px 18px; cursor: pointer; font-size: 13px; font-weight: 700; transition: background .15s; }
.pagination button:hover:not(:disabled) { background: #d3ebfb; }
.pagination button:disabled { opacity: .4; cursor: not-allowed; }
.pagination-info { font-size: 13px; color: var(--muted); font-weight: 600; }

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE — max-width: 768px
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* Layout */
  .wrap { padding: 0 10px 32px; }

  /* Header */
  .header { padding: 16px 16px 14px; border-radius: 12px; margin: 10px 0 0; }
  .header h1 { font-size: 18px; }
  .header .muted { font-size: 13px; }

  /* Card */
  .card { padding: 14px 14px; border-radius: 12px; margin: 10px 0; }

  /* Botones — más fáciles de tocar */
  .btn { padding: 11px 14px; font-size: 13px; }
  .actions { gap: 8px; }
  .actions .btn { flex: 1; text-align: center; min-width: 0; }

  /* Toolbar — apila verticalmente */
  .toolbar { flex-direction: column; align-items: stretch; gap: 8px; }
  .toolbar .left, .toolbar .right { flex-wrap: wrap; width: 100%; }
  .toolbar .right input.input { max-width: 100% !important; width: 100%; }

  /* Tablas — scroll horizontal con indicador visual */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 10px;
  }
  .table { font-size: 13px; min-width: 520px; }
  .table th { padding: 9px 10px; font-size: 10px; }
  .table td { padding: 9px 10px; }

  /* Grillas de 2 columnas → 1 columna */
  .grid2 { grid-template-columns: 1fr; gap: 8px; }
  .form-grid { grid-template-columns: 1fr !important; }
  .form-grid-3 { grid-template-columns: 1fr !important; }

  /* Filtros */
  .filters-grid { grid-template-columns: 1fr 1fr !important; gap: 8px; }

  /* KPI cards */
  .kpi-wrap { gap: 8px; }
  .kpi { min-width: 120px; padding: 12px 12px; }
  .kpi .kpi-value { font-size: 18px; }

  /* Tabs — scroll horizontal si hay muchas */
  .tabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 4px; gap: 6px; }
  .tab-btn { white-space: nowrap; padding: 8px 12px; font-size: 12px; flex-shrink: 0; }

  /* Login */
  .login-box { padding: 28px 18px; border-radius: 14px; }

  /* Paginación */
  .pagination { gap: 8px; }
  .pagination button { padding: 9px 14px; font-size: 12px; }

  /* Chip */
  .chip { font-size: 11px; padding: 5px 10px; }

  /* Barra usuario (nombre + cerrar sesión) */
  .header > div[style*="flex-end"] {
    flex-wrap: wrap;
    gap: 8px;
  }
}

/* ══════════════════════════════════════════════════════════════════════════
   MOBILE PEQUEÑO — max-width: 480px
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {

  .header h1 { font-size: 16px; }

  /* Filtros en 1 columna */
  .filters-grid { grid-template-columns: 1fr !important; }

  /* Tabla más compacta */
  .table { font-size: 12px; }
  .table th, .table td { padding: 8px 8px; }

  /* Botones de acción apilados */
  .actions { flex-direction: column; }
  .actions .btn { width: 100%; text-align: center; }

  /* Tabs con scroll */
  .tabs { gap: 4px; }
  .tab-btn { padding: 7px 10px; font-size: 11px; }
}


/* ══════════════════════════════════════════════════════════════════════════
   ERP SHELL — Layout principal
   ══════════════════════════════════════════════════════════════════════════ */
#erp-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── TOPBAR ────────────────────────────────────────────────────────────── */
#erp-topbar {
  position: sticky;
  top: 0;
  z-index: 200;
  height: 56px;
  flex-shrink: 0;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(8,73,153,.06);
}
.tb-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 20px;
}
.tb-left {
  display: flex;
  align-items: center;
  gap: 12px;
}
.tb-logo img {
  height: 30px;
  width: auto;
  display: block;
}
.tb-burger {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: none;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  color: var(--btn);
  transition: background .15s;
}
.tb-burger svg { width: 22px; height: 22px; }
.tb-burger:hover { background: var(--accent); }
.tb-right {
  display: flex;
  align-items: center;
  gap: 14px;
}
.tb-user {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.tb-logout {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: 1.5px solid var(--border);
  color: var(--muted);
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s, background .15s;
}
.tb-logout svg { width: 16px; height: 16px; }
.tb-logout:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: #fef2f2;
}

/* ── BODY = sidebar + main ─────────────────────────────────────────────── */
#erp-body {
  display: flex;
  flex: 1;
  min-height: 0;
}

/* ── SIDEBAR ───────────────────────────────────────────────────────────── */
#erp-sidebar {
  width: 240px;
  flex-shrink: 0;
  background: #ffffff;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  position: sticky;
  top: 56px;
  height: calc(100vh - 56px);
}
#erp-sidebar::-webkit-scrollbar { width: 4px; }
#erp-sidebar::-webkit-scrollbar-track { background: transparent; }
#erp-sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sb-nav {
  padding: 12px 10px 24px;
}

/* ── Item base ─────── */
.sb-link {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border: none;
  background: none;
  cursor: pointer;
  font-family: inherit;
  transition: background .12s, color .12s;
  position: relative;
}
.sb-link:hover {
  background: #f0f6fc;
  color: var(--text);
}
.sb-link.active {
  background: #eef5ff;
  color: var(--btn);
  font-weight: 700;
}
.sb-link.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--btn);
  border-radius: 0 3px 3px 0;
}

/* ── Iconos ─────── */
.sb-ico {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}
.sb-ico svg { width: 18px; height: 18px; }
.sb-txt {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Grupo expandible ─────── */
.sb-toggle.grp-active {
  color: var(--btn);
  font-weight: 700;
}
.sb-arr {
  display: flex;
  align-items: center;
  margin-left: auto;
  transition: transform .2s ease;
}
.sb-arr svg { width: 16px; height: 16px; opacity: .5; }
.sb-grp.open .sb-arr { transform: rotate(180deg); }
.sb-kids {
  max-height: 0;
  overflow: hidden;
  transition: max-height .25s ease;
}
.sb-grp.open .sb-kids {
  max-height: 300px;
}

/* ── Subitem ─────── */
.sb-sub {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px 8px 26px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  transition: background .12s, color .12s;
  position: relative;
}
.sb-sub:hover {
  background: #f0f6fc;
  color: var(--text);
}
.sb-sub.active {
  background: #eef5ff;
  color: var(--btn);
  font-weight: 700;
}
.sb-sub.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  background: var(--btn);
  border-radius: 0 3px 3px 0;
}
.sb-sub .sb-ico svg {
  width: 16px;
  height: 16px;
  opacity: .7;
}

/* ── MAIN CONTENT ──────────────────────────────────────────────────────── */
#erp-main {
  flex: 1;
  min-width: 0;
  background: var(--bg);
}
.wrap {
  padding-top: 16px;
}

/* ── Overlay (mobile) ──────────────────────────────────────────────────── */
#erp-overlay {
  display: none;
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (max 768px)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  .tb-burger { display: flex; }
  .tb-logout-txt { display: none; }
  .tb-logout { padding: 6px 10px; }

  #erp-sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 280px;
    height: auto;
    z-index: 300;
    transform: translateX(-100%);
    transition: transform .25s ease, box-shadow .25s ease;
    box-shadow: none;
  }
  #erp-sidebar.open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(8,73,153,.15);
  }

  #erp-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: 56px;
    background: rgba(0,0,0,.3);
    z-index: 250;
    backdrop-filter: blur(2px);
  }
  #erp-overlay.show {
    display: block;
  }
}

/* ── Tablet ────────────────────────────────────────────────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  #erp-sidebar { width: 210px; }
  .sb-link { font-size: 12px; padding: 8px 12px; }
  .sb-sub { font-size: 12px; padding: 7px 12px 7px 22px; }
}
