/* BodegaFlex Control — Hoja de estilos móvil-primero (PWA administrativa independiente) */
:root {
  color-scheme: light;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --primary: #1a3a6b;
  --primary-hover: #132c52;
  --gold: #f5c400;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
  --warn: #d97706;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --err: #dc2626;
  --err-bg: #fee2e2;
  --err-ink: #991b1b;
  --info-bg: #dbeafe;
  --info-ink: #1e40af;
  --border: #cbd5e1;
  --shadow: 0 2px 10px rgba(15, 23, 42, 0.07);
}

html[data-tema="noche"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111a2e;
  --surface-soft: #16223b;
  --ink: #e2e8f0;
  --muted: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --ok-bg: #052e16;
  --ok-ink: #86efac;
  --warn-bg: #451a03;
  --warn-ink: #fde68a;
  --err-bg: #450a0a;
  --err-ink: #fca5a5;
  --info-bg: #1e3a8a;
  --info-ink: #bfdbfe;
  --border: #2b3a55;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

[hidden] { display: none !important; }

.sp-topbar {
  background: linear-gradient(135deg, #1a3a6b 0%, #0f2547 100%);
  color: #ffffff;
  padding: calc(10px + env(safe-area-inset-top, 0px)) max(14px, env(safe-area-inset-right, 0px)) 12px max(14px, env(safe-area-inset-left, 0px));
  border-bottom: 3px solid var(--gold);
  position: sticky;
  top: 0;
  z-index: 60;
}

.sp-topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.sp-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1 1 220px;
}

.sp-brand-logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  border: 1px solid rgba(245, 196, 0, 0.55);
  flex-shrink: 0;
}

.sp-brand-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.sp-brand h1 {
  margin: 0;
  font-size: 1.04rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.sp-brand small {
  color: #cbd5e1;
  font-size: 0.76rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.sp-top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.ctrl-env-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(245, 196, 0, 0.22);
  color: #fde047;
  border: 1px solid rgba(245, 196, 0, 0.48);
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.sp-wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px max(12px, env(safe-area-inset-right, 0px)) calc(26px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ctrl-offline-banner {
  background: var(--warn-bg);
  color: var(--warn-ink);
  border: 1px solid var(--warn);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.86rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.sp-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.sp-card h2 { margin: 0 0 8px; font-size: 1.05rem; color: var(--ink); }
.sp-card h3 { margin: 0 0 8px; font-size: 0.95rem; color: var(--ink); }

.sp-muted {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 10px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.sp-login-card {
  max-width: 480px;
  margin: 12px auto;
  width: 100%;
}

.sp-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-bottom: 10px;
  min-width: 0;
}

.sp-field label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--muted);
}

input, select, textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.94rem;
  font-family: inherit;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

.ctrl-check-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  cursor: pointer;
  margin-bottom: 10px;
}

.ctrl-check-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
  min-height: 20px;
  margin: 2px 0 0;
  flex-shrink: 0;
}

.ctrl-check-row span {
  font-size: 0.85rem;
  line-height: 1.38;
  color: var(--ink);
}

.btns {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

button, a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 9px 14px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-family: inherit;
  max-width: 100%;
  text-align: center;
}

button:hover, a.btn:hover { background: var(--primary-hover); }
button.sec, a.btn.sec { background: var(--surface-soft); color: var(--ink); border-color: var(--border); }
button.sec:hover, a.btn.sec:hover { background: var(--bg); }
button.ok, a.btn.ok { background: var(--ok); color: #ffffff; }
button.warn, a.btn.warn { background: var(--warn); color: #ffffff; }
button.err, a.btn.err { background: var(--err); color: #ffffff; }
button.ghost, a.btn.ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.sp-topbar button.ghost, .sp-topbar a.btn.ghost { color: #ffffff; border-color: rgba(255, 255, 255, 0.35); }
button.sm, a.btn.sm { min-height: 40px; padding: 6px 12px; font-size: 0.82rem; border-radius: 9px; }
button:disabled, a.btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }

/* Toolbar rápida superior dentro del panel autenticado */
.ctrl-session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.ctrl-session-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.82rem;
  color: var(--muted);
  min-width: 0;
}

.ctrl-session-info strong {
  color: var(--ink);
  font-size: 0.88rem;
}

/* Acordeón vertical de 8 secciones */
.ctrl-accordion-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ctrl-acc-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  overflow: hidden;
  scroll-margin-top: calc(76px + env(safe-area-inset-top, 0px));
}

.ctrl-acc-item.abierta {
  border-color: var(--primary);
}

.ctrl-acc-trigger {
  width: 100%;
  min-height: 54px;
  padding: 12px 14px;
  border: 0;
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  text-align: left;
  font-size: 0.96rem;
  font-weight: 800;
}

.ctrl-acc-trigger:hover {
  background: var(--surface-soft);
}

.ctrl-acc-item.abierta > .ctrl-acc-trigger {
  background: linear-gradient(90deg, rgba(26, 58, 107, 0.08) 0%, transparent 100%);
  border-bottom: 1px solid var(--border);
}

.ctrl-acc-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.ctrl-acc-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.ctrl-acc-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--ink);
}

.ctrl-acc-sub {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ctrl-acc-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ctrl-acc-chevron {
  display: inline-flex;
  width: 24px;
  height: 24px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  transition: transform 0.18s ease;
}

.ctrl-acc-item.abierta .ctrl-acc-chevron {
  transform: rotate(180deg);
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}

.ctrl-acc-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}

.ctrl-sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.sp-kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 10px;
}

.sp-kpi {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.sp-kpi span { font-size: 0.74rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.sp-kpi strong { font-size: 1.24rem; color: var(--ink); line-height: 1.15; }
.sp-kpi small { font-size: 0.73rem; color: var(--muted); }

.sp-fin-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}

.sp-fin-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-soft);
  min-width: 0;
}

.sp-fin-box h3 { margin: 0 0 8px; font-size: 0.9rem; }
.sp-fin-row { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; font-size: 0.85rem; }
.sp-fin-real { border-left: 4px solid var(--ok); }
.sp-fin-proj { border-left: 4px solid var(--warn); }

.sp-filtros {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: 8px;
}

@media (max-width: 780px) {
  .sp-filtros { grid-template-columns: 1fr; }
}

.sp-lista {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.item {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface-soft);
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.87rem;
  min-width: 0;
  overflow-wrap: anywhere;
}

.item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.tag {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  background: var(--info-bg);
  color: var(--info-ink);
  white-space: nowrap;
}

.tag.ok { background: var(--ok-bg); color: var(--ok-ink); }
.tag.warn { background: var(--warn-bg); color: var(--warn-ink); }
.tag.err { background: var(--err-bg); color: var(--err-ink); }
.tag.muted { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }

.msg {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 0.86rem;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.msg.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: var(--warn); }
.msg.err { background: var(--err-bg); color: var(--err-ink); border-color: var(--err); }

.sp-ficha-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(265px, 1fr));
  gap: 10px;
}

.sp-accion-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  overflow-wrap: anywhere;
}

.ctrl-acceso-card {
  border-left: 4px solid var(--primary);
}

.ctrl-danger-card {
  border-left: 4px solid var(--err);
}

.ctrl-details-group {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-soft);
  overflow: hidden;
}

.ctrl-details-group > summary {
  padding: 12px 14px;
  font-weight: 800;
  font-size: 0.9rem;
  cursor: pointer;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-height: 46px;
}

.ctrl-details-group > summary::-webkit-details-marker { display: none; }

.ctrl-details-body {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  background: var(--bg);
  padding: 2px 5px;
  border-radius: 5px;
  word-break: break-all;
}

.sp-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(15, 23, 42, 0.74);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.sp-modal-card {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sp-modal-img {
  max-width: 100%;
  max-height: 62vh;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #0f172a;
}

.ctrl-switch-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
}

.ctrl-conteos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 6px;
}

.ctrl-conteo-chip {
  padding: 6px 8px;
  border-radius: 8px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  font-size: 0.78rem;
}

@media (max-width: 520px) {
  .sp-card, .ctrl-acc-body { padding: 12px; }
  .btns > button, .btns > a.btn { flex: 1 1 auto; }
  .sp-top-actions button, .sp-top-actions a.btn { min-height: 38px; padding: 6px 10px; font-size: 0.78rem; }
}
