/* ============================================================
   Lima Retail Design System v1.0 — CSS maestro
   Alineado al manual lima-retail-manual.html
   ============================================================ */

/* ── TOKENS ── */
:root {
  --sidebar-bg:    #ffffff;
  --sidebar-text:  #0f172a;
  --sidebar-muted: #64748b;
  /* Acento del menú lateral (azul, independiente del rojo de marca) */
  --nav-accent:        #2563eb;
  --nav-accent-text:   #1d4ed8;
  --nav-accent-soft:   #eff6ff;
  --nav-accent-border: #bfdbfe;
  --bg:            #f4f4f5;
  --card:          #FFFFFF;
  --border:        #e5e7eb;
  --brand:         #b91c1c; --brand-soft:  #fee2e2; --brand-text:  #991b1b;
  --green:         #059669; --green-soft:  #D1FAE5; --green-text:  #047857;
  --amber:         #D97706; --amber-soft:  #FEF3C7; --amber-text:  #B45309;
  --red:           #DC2626; --red-soft:    #FEE2E2; --red-text:    #B91C1C;
  --purple:        #7C3AED; --purple-soft: #EDE9FE; --purple-text: #6D28D9;
  --text:          #0f172a;
  --text-2:        #475569;
  --muted:         #94A3B8;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --r-lg: 14px; --r: 8px; --r-sm: 6px; --r-xs: 4px;
  --sh:  0 1px 2px rgba(15,23,42,.06);
  --sh2: 0 4px 14px rgba(15,23,42,.08);
}

/* ── RESET ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ── SHELL ── */
.shell {
  min-height: 100vh;
  display: flex;
}
.sidebar {
  width: 264px;
  min-width: 264px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: sticky;
  top: 0;
  max-height: 100vh;
  overflow-y: auto;
}
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── SIDEBAR ── */
.s-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 24px 20px 18px;
  flex-shrink: 0;
}
.s-brand-text { min-width: 0; }
.s-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
  line-height: 1.15;
}
.s-sub {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 4px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 8px;
  white-space: normal;
}
.s-ver {
  font-size: 10px;
  font-weight: 700;
  color: var(--nav-accent-text);
  background: var(--nav-accent-soft);
  border: 1px solid var(--nav-accent-border);
  border-radius: 20px;
  padding: 1px 7px;
}
.s-group-lbl {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--sidebar-muted);
  letter-spacing: 0.12em;
  padding: 4px 22px 0;
  font-weight: 700;
}
.s-item {
  display: grid;
  grid-template-columns: 44px 1fr 16px;
  gap: 12px;
  align-items: center;
  padding: 10px 12px 10px 10px;
  min-height: 66px;
  margin: 0 14px;
  border-radius: 12px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  color: var(--sidebar-text);
  cursor: pointer;
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease, transform .16s ease;
  user-select: none;
  width: calc(100% - 28px);
  text-align: left;
}
.s-item:hover { background: #f8fafc; border-color: #cbd5e1; transform: translateY(-1px); }
.s-item:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(37,99,235,0.3); }
.s-item.disabled,
.s-item:disabled {
  opacity: .45;
  cursor: not-allowed;
  filter: grayscale(.4);
}
.s-item.disabled:hover,
.s-item:disabled:hover {
  background: #ffffff;
  border-color: #e2e8f0;
  transform: none;
}
.s-item.disabled .s-chevron,
.s-item:disabled .s-chevron {
  display: none;
}
/* Activo: fondo azul suave + contorno oscuro (sin mover el layout) */
.s-item.active { background: var(--nav-accent-soft); border-color: var(--nav-accent-border); }
.s-item.active:hover { transform: none; }
.s-item.active .s-icon { background: #ffffff; border-color: var(--nav-accent-border); color: var(--nav-accent); }

.s-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #f8fafc;
  color: #475569;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.s-icon svg { width: 20px; height: 20px; stroke-width: 1.75; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.s-text { min-width: 0; }
.s-title-nav {
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  color: var(--text);
}
.s-desc-nav {
  margin-top: 3px;
  font-size: 12px;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.35;
}
.s-item.active .s-title-nav { color: var(--nav-accent); }
.s-item.active .s-desc-nav { color: #64748b; }
.s-chevron { color: #94a3b8; flex-shrink: 0; display: flex; align-items: center; }
.s-chevron svg { width: 16px; height: 16px; stroke-width: 2; fill: none; stroke: currentColor; stroke-linecap: round; stroke-linejoin: round; }
.s-item.active .s-chevron { color: var(--nav-accent); }

/* ── TOPBAR ── */
.topbar {
  padding: 16px 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.topbar-pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #F1F5F9;
  border-radius: 20px;
  padding: 3px 12px;
  font-size: 11px;
  color: var(--text-2);
  font-weight: 500;
}
.topbar-meta { display: flex; align-items: center; gap: 10px; }
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.topbar-left .topbar-title { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Sidebar minimizable ──
   Estado: .shell.sidebar-collapsed (lo pone wireSidebarToggle() en main.js).
   Desktop: tira de 88px solo con íconos. ≤900px: el panel se oculta. */
.sidebar-toggle {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.sidebar-toggle:hover { background: #fafafa; border-color: #fecaca; color: var(--brand); }
.sidebar-toggle:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(185,28,28,.25); }
.sidebar-toggle svg {
  width: 18px; height: 18px;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.sidebar-toggle .st-arrow {
  transform-box: fill-box;
  transform-origin: center;
  transition: transform .2s ease;
}
.shell.sidebar-collapsed .sidebar-toggle .st-arrow { transform: scaleX(-1); }

.sidebar { overflow-x: hidden; white-space: nowrap; transition: width .2s ease, min-width .2s ease, padding .2s ease; }
.shell.no-anim .sidebar,
.shell.no-anim .sidebar-toggle .st-arrow { transition: none; }

/* Logo Casiopia: imagen cuadrada (img/casiopia-logo.jpg, 1020×1020)
   completa dentro de un recuadro de esquinas redondeadas. Minimizado,
   el mismo recuadro queda como único elemento de la marca. */
.s-logo {
  width: 64px;
  height: 64px;
  flex-shrink: 0;
  border-radius: 14px;
  background: #011f07 url("../img/casiopia-logo.jpg") no-repeat center / cover;
  box-shadow: 0 1px 2px rgba(15,23,42,.08), 0 4px 12px rgba(15,23,42,.10);
}
.s-group-bottom { margin-top: auto; }

.shell.sidebar-collapsed .sidebar { width: 88px; min-width: 88px; padding-bottom: 16px; }
.shell.sidebar-collapsed .s-brand { padding: 20px 0 14px; justify-content: center; }
.shell.sidebar-collapsed .s-logo { width: 52px; height: 52px; border-radius: 12px; }
.shell.sidebar-collapsed .s-brand-text,
.shell.sidebar-collapsed .s-text,
.shell.sidebar-collapsed .s-chevron,
.shell.sidebar-collapsed .s-modulo-activo { display: none; }
/* Las etiquetas de grupo se aplanan (no display:none) para que
   "Sistema" siga empujando "Usuarios y Claves" al fondo con margin-top:auto. */
.shell.sidebar-collapsed .s-group-lbl {
  height: 0; padding: 0; overflow: hidden; visibility: hidden;
}
.shell.sidebar-collapsed .s-item {
  grid-template-columns: 44px;
  justify-content: center;
  padding: 10px 0;
  min-height: 60px;
  margin: 0 14px;
  width: calc(100% - 28px);
}

/* Tooltip con el nombre del módulo en la tira minimizada */
.s-tip {
  position: fixed;
  z-index: 50;
  padding: 6px 10px;
  border-radius: var(--r-sm);
  background: #111111;
  color: #fff;
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--sh2);
  pointer-events: none;
  opacity: 0;
  transform: translate(-4px, -50%);
  transition: opacity .12s ease, transform .12s ease;
}
.s-tip.show { opacity: 1; transform: translate(0, -50%); }

/* ── CONTENT ── */
.content {
  padding: 28px 32px;
  display: flex;
  flex-direction: column;
  gap: 32px;
  flex: 1;
}
.section { min-width: 0; }
.sec-lbl {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: #64748b;
  border-bottom: 1px solid var(--border);
  padding-bottom: 9px;
  margin-bottom: 18px;
}
.section-title {
  font-size: 20px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.section-desc {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
  margin-bottom: 22px;
  max-width: 720px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: #fff;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-2);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn:hover { background: #F8FAFC; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { background: var(--brand-text); }
.btn.danger { color: var(--red); border-color: #FCA5A5; }
.btn.danger:hover { background: var(--red-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #F1F5F9; }
.btn:disabled { opacity: .4; pointer-events: none; }
.btn svg { width: 13px; height: 13px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn.loading svg { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── INPUTS ── */
.inp {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid #CBD5E1;
  border-radius: var(--r-sm);
  font-size: 13px;
  background: #F8FAFC;
  color: var(--text);
  outline: none;
  font-family: inherit;
  transition: background .15s, border-color .15s;
}
.inp:focus { background: #fff; border-color: #dc2626; box-shadow: 0 0 0 2px #fee2e2; }
.inp-wrap { position: relative; }
.inp-pre {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  pointer-events: none;
}
.inp-wrap .inp { padding-left: 28px; }

/* ── PANEL ── */
.panel {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 20px;
  box-shadow: var(--sh);
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.01em;
}
.panel-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}
.panel-meta { font-size: 11px; color: var(--text-2); }

/* ── KPI CARDS ── */
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  box-shadow: var(--sh);
  position: relative;
}
.kpi-icon {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
}
.kpi-icon svg { width: 16px; height: 16px; stroke-width: 2; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.kpi-icon.blue   { background: var(--brand-soft);  color: var(--brand-text); }
.kpi-icon.blue svg   { stroke: var(--brand-text); }
.kpi-icon.green  { background: var(--green-soft);  color: var(--green-text); }
.kpi-icon.green svg  { stroke: var(--green-text); }
.kpi-icon.amber  { background: var(--amber-soft);  color: var(--amber-text); }
.kpi-icon.amber svg  { stroke: var(--amber-text); }
.kpi-icon.red    { background: var(--red-soft);    color: var(--red-text); }
.kpi-icon.red svg    { stroke: var(--red-text); }
.kpi-icon.purple { background: var(--purple-soft); color: var(--purple-text); }
.kpi-icon.purple svg { stroke: var(--purple-text); }
.kpi-icon.slate  { background: #F1F5F9;            color: #475569; }
.kpi-icon.slate svg  { stroke: #475569; }

.kpi-lbl {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: #64748b;
  padding-right: 42px;
}
.kpi-val {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
  margin-top: 6px;
  letter-spacing: -0.02em;
  line-height: 1;
}
.kpi-val.blue   { color: var(--brand); }
.kpi-val.green  { color: var(--green); }
.kpi-val.amber  { color: var(--amber); }
.kpi-val.red    { color: var(--red); }
.kpi-val.purple { color: var(--purple); }
.kpi-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

/* ── PILLS ── */
.pill {
  font-size: 10px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
}
.pill.blue   { background: var(--brand-soft);  color: var(--brand-text); }
.pill.green  { background: var(--green-soft);  color: var(--green-text); }
.pill.amber  { background: var(--amber-soft);  color: var(--amber-text); }
.pill.red    { background: var(--red-soft);    color: var(--red-text); }
.pill.purple { background: var(--purple-soft); color: var(--purple-text); }
.pill.gray   { background: #F1F5F9;            color: #475569; }

/* ── INSIGHTS ── */
.insight {
  border-left: 3px solid;
  border-radius: var(--r-xs);
  padding: 10px 14px;
  font-size: 12px;
  line-height: 1.6;
}
.insight.info { background: #EFF6FF; border-color: var(--brand); color: #1E3A8A; }
.insight.ok   { background: #ECFDF5; border-color: var(--green); color: #065F46; }
.insight.warn { background: #FFFBEB; border-color: var(--amber); color: #78350F; }
.insight.err  { background: #FEF2F2; border-color: var(--red);   color: #7F1D1D; }
.insight b { filter: brightness(.75); }

/* ── TABLAS ── */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
th {
  background: #F8FAFC;
  padding: 9px 12px;
  text-align: left;
  font-size: 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.24em;
  color: #64748b;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 10px 12px;
  border-bottom: 1px solid #F1F5F9;
  color: var(--text);
  font-weight: 400;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #FAFBFC; }
th.r, td.r { text-align: right; }
th.c, td.c { text-align: center; }
td.brand { color: var(--brand); font-weight: 600; }
td.green { color: var(--green); font-weight: 600; }
td.amber { color: var(--amber); font-weight: 600; }
td.red   { color: var(--red);   font-weight: 600; }
.mono { font-family: "SF Mono", "Cascadia Code", Consolas, ui-monospace, monospace; }

/* ── STEPPER (custom, usado en tabla de Objetivos) ── */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid #CBD5E1;
  border-radius: var(--r-sm);
  overflow: hidden;
  background: #F8FAFC;
  height: 30px;
}
.stepper .step-btn {
  width: 26px;
  border: none;
  background: transparent;
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  transition: background .12s, color .12s;
  font-family: inherit;
  line-height: 1;
}
.stepper .step-btn:hover { background: var(--brand); color: #fff; }
.stepper .obj-input {
  width: 80px;
  font-size: 14px;
  font-family: inherit;
  padding: 0 6px;
  border: none;
  border-left: 1px solid #CBD5E1;
  border-right: 1px solid #CBD5E1;
  background: #fff;
  color: var(--text);
  text-align: center;
  -moz-appearance: textfield;
}
.stepper .obj-input::-webkit-outer-spin-button,
.stepper .obj-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.stepper .obj-input:focus { outline: none; background: var(--brand-soft); }

/* ── PROGRESS BAR ── */
.pb-wrap { display: flex; align-items: center; gap: 8px; }
.pb-bg {
  position: relative;
  flex: 1;
  height: 8px;
  background-color: #E2E8F0;
  /* Ticks verticales en 25% / 50% / 75%. El del 50% más marcado. */
  background-image: linear-gradient(
    to right,
    transparent calc(25% - 1px), #94A3B8 calc(25% - 1px),
    #94A3B8 calc(25% + 1px), transparent calc(25% + 1px),
    transparent calc(50% - 1px), #475569 calc(50% - 1px),
    #475569 calc(50% + 1px), transparent calc(50% + 1px),
    transparent calc(75% - 1px), #94A3B8 calc(75% - 1px),
    #94A3B8 calc(75% + 1px), transparent calc(75% + 1px)
  );
  border-radius: 4px;
  overflow: hidden;
  min-width: 56px;
}
.pb-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s ease, background .3s;
  background: var(--brand);
  position: relative;
  z-index: 1;
}
.pct-val {
  font-size: 14px;
  font-weight: 500;
  min-width: 34px;
  text-align: right;
}
.gap-val { font-size: 14px; }
.g-pos { color: var(--green-text); font-weight: 500; }
.g-neg { color: var(--red-text);   font-weight: 500; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  opacity: 0; pointer-events: none;
  transition: opacity .15s;
}
.modal-overlay.visible { opacity: 1; pointer-events: auto; }
.modal {
  background: var(--card);
  border-radius: var(--r);
  padding: 22px 24px;
  max-width: 480px;
  width: 92%;
  box-shadow: var(--sh2);
}
.modal h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }
.modal p  { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.modal .modal-actions {
  display: flex; justify-content: flex-end; gap: 10px;
  margin-top: 16px;
}

/* ── UTILIDADES ── */
.muted   { color: var(--muted); }
.text-2  { color: var(--text-2); }
.hidden  { display: none !important; }
.grid-2  { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3  { display: grid; grid-template-columns: repeat(3,1fr); gap: 14px; }
.grid-4  { display: grid; grid-template-columns: repeat(4,1fr); gap: 12px; }
.row     { display: flex; gap: 12px; align-items: center; }

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; position: relative; max-height: none; }
  .content { padding: 20px 18px; gap: 24px; }
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
  .topbar { padding: 12px 18px; flex-wrap: wrap; row-gap: 10px; }
  .shell.sidebar-collapsed .sidebar { display: none; }
}
