:root {
  --bg: #070a0f;
  --bg-soft: #0c1118;
  --panel: rgba(14, 20, 29, 0.92);
  --panel-soft: rgba(18, 25, 35, 0.78);
  --border: rgba(255, 255, 255, 0.09);
  --border-strong: rgba(255, 255, 255, 0.14);
  --text: #f5f7fa;
  --muted: #8e9aaa;
  --muted-light: #b7c0cc;
  --accent: #cfd7e3;
  --danger: #ff9b9b;
  --sidebar-width: 280px;
  --radius: 16px;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at 50% -10%, #17202c 0, transparent 42%),
    var(--bg);
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

/* Loading */

.loading-view {
  min-height: 100vh;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 16px;
  color: var(--muted);
}

.loading-mark {
  width: 32px;
  height: 32px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--text);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Login */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

.login-panel {
  width: min(100%, 420px);
  padding: 34px 38px 38px;
  background: linear-gradient(
    180deg,
    rgba(18, 25, 35, 0.94),
    rgba(10, 15, 22, 0.96)
  );
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
}

.brand-login {
  display: flex;
  justify-content: center;
  margin-bottom: 26px;
}

.brand-logo {
  display: block;
  width: min(100%, 290px);
  height: 190px;
  object-fit: contain;
}

.login-form {
  display: grid;
  gap: 18px;
}

.field {
  display: grid;
  gap: 8px;
}

.field label {
  color: var(--muted-light);
  font-size: 0.85rem;
  font-weight: 600;
}

.field input {
  width: 100%;
  height: 48px;
  padding: 0 14px;
  color: var(--text);
  background: rgba(4, 8, 13, 0.72);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  outline: none;
  transition:
    border-color 150ms ease,
    box-shadow 150ms ease;
}

.field input:focus {
  border-color: rgba(255, 255, 255, 0.38);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.05);
}

.primary-button {
  min-height: 48px;
  margin-top: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 10px;
  background: #eef2f7;
  color: #0a0e14;
  font-weight: 700;
  transition:
    transform 120ms ease,
    opacity 120ms ease;
}

.primary-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.form-message {
  margin: -2px 0 0;
  font-size: 0.85rem;
}

.error-message {
  color: var(--danger);
}

/* Application shell */

.app-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 22px 16px 18px;
  background: rgba(8, 12, 18, 0.96);
  border-right: 1px solid var(--border);
}

.sidebar-brand {
  display: flex;
  justify-content: center;
  min-height: 118px;
  padding: 0 8px 20px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  width: 190px;
  height: 105px;
  object-fit: contain;
}

.sidebar-nav {
  display: grid;
  gap: 6px;
  margin-top: 22px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--muted-light);
  text-align: left;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.nav-item.active {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--border);
  color: var(--text);
}

.nav-icon {
  width: 20px;
  color: var(--muted);
  font-size: 1.15rem;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.user-summary {
  display: flex;
  align-items: center;
  gap: 11px;
}

.user-avatar {
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  background: var(--panel-soft);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 700;
}

.user-data {
  min-width: 0;
  display: grid;
  gap: 2px;
}

.user-data strong,
.user-data span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-data strong {
  font-size: 0.85rem;
}

.user-data span {
  color: var(--muted);
  font-size: 0.72rem;
}

.logout-button {
  width: 100%;
  min-height: 40px;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: transparent;
  color: var(--muted-light);
}

.logout-button:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.workspace {
  min-width: 0;
  padding: 34px 42px;
}

.workspace-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 42px;
}

.workspace-header h1 {
  margin: 5px 0 0;
  font-size: 1.8rem;
  font-weight: 650;
}

.eyebrow {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.header-user {
  color: var(--muted-light);
  font-size: 0.85rem;
}

.workspace-section {
  max-width: 1080px;
}

.welcome-card,
.empty-state {
  padding: 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.welcome-card h2,
.empty-state h2 {
  margin: 8px 0 10px;
  font-size: 1.55rem;
}

.welcome-card p,
.empty-state p {
  max-width: 680px;
  margin: 0;
  color: var(--muted-light);
  line-height: 1.65;
}

.partner-assistant {
  padding: clamp(20px, 4vw, 36px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.partner-assistant p,
.partner-assistant li {
  color: var(--muted-light);
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.partner-assistant .partner-notice {
  padding: 14px;
  border-left: 3px solid var(--accent);
  background: var(--bg-soft);
}

.partner-search-form { display: grid; gap: 18px; max-width: 640px; }
.partner-actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 16px; }
.partner-actions button { padding: 12px 20px; margin: 0; }
.secondary-button {
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  color: var(--text);
  background: var(--bg-soft);
}
.partner-assistant select {
  width: 100%;
  min-height: 48px;
  padding: 10px 14px;
  font: inherit;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
}
.partner-assistant button:focus-visible,
.partner-assistant select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
.partner-results { list-style: none; padding: 0; display: grid; gap: 12px; }
.partner-results li { padding: 16px; border: 1px solid var(--border); border-radius: 10px; }
.partner-results strong { display: block; color: var(--text); }
.partner-results p { margin: 6px 0 0; }
.partner-assistant .error-message { color: var(--danger); }

/* Responsive */

@media (max-width: 820px) {
  .app-view {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    width: 100%;
    height: auto;
  }

  .sidebar-brand {
    min-height: 90px;
  }

  .sidebar-logo {
    height: 78px;
  }

  .sidebar-footer {
    margin-top: 24px;
  }

  .workspace {
    padding: 28px 22px;
  }
}

@media (max-width: 480px) {
  .login-panel {
    padding: 26px 22px 28px;
  }

  .brand-logo {
    height: 160px;
  }

  .workspace-header {
    align-items: flex-start;
    flex-direction: column;
  }
}


/* BLACK ERP Utilities */
.nav-group-label {
  margin: 18px 16px 7px;
  color: #8fa4b8;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.utility-panel {
  max-width: 900px;
  padding: 28px;
  border: 1px solid rgba(150, 170, 190, 0.2);
  border-radius: 12px;
  background: rgba(150, 170, 190, 0.05);
}

.utility-panel h2 {
  margin-top: 10px;
}

.utility-panel .field {
  margin-top: 24px;
}

.utility-panel input[type="file"] {
  display: block;
  max-width: 100%;
  margin-top: 10px;
}

.utility-note {
  margin-top: 24px;
  color: #9aafc2;
  font-size: 13px;
}


/* Resultados de prevalidación de productos */
.utility-actions {
  display: flex;
  gap: 12px;
  margin-top: 18px;
}

.utility-results {
  margin-top: 24px;
  padding: 20px;
  border: 1px solid rgba(150, 170, 190, 0.2);
  border-radius: 10px;
  background: rgba(150, 170, 190, 0.05);
}

.utility-results h3 {
  margin-top: 0;
}

.utility-results li {
  margin-bottom: 8px;
  overflow-wrap: anywhere;
}


/* Presentación de resultados del resolutor */

.utility-actions {
  flex-wrap: wrap;
}

.utility-resolution-item {
  margin-bottom: 20px;
  padding: 14px;
  border: 1px solid rgba(150, 170, 190, 0.2);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

.utility-resolution-item p {
  margin: 8px 0;
}

.utility-json {
  margin-top: 12px;
  padding: 14px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  overflow-x: auto;
  white-space: pre;
  font-size: 12px;
  line-height: 1.6;
}

/* Historial de cargas masivas de productos */

.utility-history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.utility-history-list {
  display: grid;
  gap: 12px;
  padding: 0;
  margin: 16px 0;
  list-style: none;
}

.utility-history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  padding: 16px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 10px;
}

.utility-history-information {
  display: grid;
  gap: 6px;
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.utility-history-information small {
  opacity: 0.75;
}

#products-job-details-text {
  white-space: pre-line;
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .utility-history-item {
    align-items: stretch;
    flex-direction: column;
  }
}

/* Validación autónoma de productos */
.utility-job-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-start;
}

.utility-job-progress {
  display: block;
  width: 100%;
  max-width: 24rem;
  height: 0.6rem;
  margin-top: 0.35rem;
}

#products-validation-status {
  white-space: pre-wrap;
}

/* ============================================================
   CITADEL — WORKSPACE CARGAS MASIVAS
   ============================================================ */

.utility-panel:has(.products-workspace-grid) {
  width: 100%;
  max-width: 1480px;
  box-sizing: border-box;
}

.products-workspace-grid {
  display: grid;
  grid-template-columns:
    minmax(0, 0.95fr)
    minmax(0, 1.1fr);
  gap: 24px;
  align-items: start;
  margin-top: 24px;
}

.products-workspace-column {
  min-width: 0;
  padding: 22px;
  border: 1px solid rgba(150, 170, 190, 0.2);
  border-radius: 12px;
  background: rgba(150, 170, 190, 0.04);
}

.products-workspace-column > h3 {
  margin: 0 0 20px;
  font-size: 18px;
}

.products-stage {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid rgba(150, 170, 190, 0.16);
  border-radius: 10px;
  background: rgba(150, 170, 190, 0.035);
}

.products-stage:first-of-type {
  margin-top: 0;
}

.products-stage-number {
  margin: 0 0 8px;
  color: #93afc8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
}

.products-stage h4 {
  margin: 0 0 10px;
  font-size: 15px;
}

.products-stage > p:not(.products-stage-number) {
  color: #a7bbce;
  font-size: 13px;
}

.products-stage .field {
  margin-top: 12px;
}

.products-stage .utility-results {
  margin-top: 16px;
}

.products-advanced {
  width: 100%;
  margin-top: 12px;
}

.products-advanced summary {
  cursor: pointer;
  color: #a7bdd3;
  font-size: 13px;
}

.products-advanced button {
  margin-top: 12px;
}

.products-workspace-right > .utility-results {
  margin-top: 14px;
}

.products-workspace-right > .utility-note {
  margin-top: 18px;
}

.products-workspace-right .utility-history-item {
  gap: 16px;
}

.products-workspace-right .utility-history-information {
  flex: 1;
}

.products-workspace-right .utility-job-progress {
  max-width: none;
}

@media (max-width: 1100px) {
  .products-workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 640px) {
  .products-workspace-column {
    padding: 14px;
  }

  .products-stage {
    padding: 14px;
  }
}

/* CITADEL RESPONSIVE PRODUCTS V2 */

/* El workspace puede adaptar sus columnas a su propio ancho. */
.utility-panel:has(.products-workspace-grid) {
  container-type: inline-size;
  min-width: 0;
}

/* Pantallas amplias: aprovechar el espacio junto al menú lateral. */
@media (min-width: 1101px) {
  .utility-panel:has(.products-workspace-grid) {
    width: min(1480px, calc(100vw - 320px));
    max-width: none;
  }
}

/* La cuadrícula se adapta al ancho disponible del workspace. */
.products-workspace-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr);
}

.products-workspace-column,
.products-stage,
.products-workspace-right .utility-results {
  min-width: 0;
}

/* Historial: evitar que el nombre del archivo comprima los botones. */
.products-workspace-right .utility-history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 14px;
}

.products-workspace-right .utility-history-information {
  min-width: 0;
  width: 100%;
}

.products-workspace-right .utility-history-information strong {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
  overflow-wrap: anywhere;
  line-clamp: 2;
}

.products-workspace-right .utility-job-actions {
  min-width: 0;
  max-width: 100%;
}

.products-workspace-right .utility-job-actions button {
  max-width: 100%;
  white-space: normal;
}

.products-workspace-column input[type="file"] {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

/* El cambio a una columna depende del espacio real del panel. */
@container (max-width: 1050px) {
  .products-workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Cuando el panel de seguimiento sea estrecho,
   los controles pasan debajo de la información. */
@container (max-width: 670px) {
  .products-workspace-right .utility-history-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .products-workspace-right .utility-job-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* Tablets y pantallas pequeñas. */
@media (max-width: 1100px) {
  .utility-panel:has(.products-workspace-grid) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
}

/* Móvil: reducir márgenes y evitar desbordamientos. */
@media (max-width: 640px) {
  .utility-panel:has(.products-workspace-grid) {
    padding: 14px;
  }

  .products-workspace-grid {
    gap: 12px;
  }

  .products-workspace-column {
    padding: 12px;
  }

  .products-stage {
    padding: 12px;
  }

  .products-workspace-right .utility-results {
    padding: 12px;
  }

  .products-workspace-right .utility-history-item {
    padding: 12px;
  }

  .products-workspace-column .utility-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .products-workspace-column .utility-actions button {
    width: 100%;
  }
}

/* ============================================================
   CITADEL — NAVEGACIÓN RESPONSIVE GLOBAL
   ============================================================ */

.mobile-menu-toggle,
.mobile-menu-close,
.mobile-menu-backdrop {
  display: none;
}

.mobile-header-start {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.mobile-header-start > div {
  min-width: 0;
}

.mobile-menu-toggle,
.mobile-menu-close {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: var(--text);
  background: var(--panel-soft);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  font-size: 22px;
}

.mobile-menu-toggle:focus-visible,
.mobile-menu-close:focus-visible,
.mobile-menu-backdrop:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

/* Tablet y móvil: menú lateral deslizable. */
@media (max-width: 900px) {

  .app-view {
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
  }

  .workspace {
    grid-column: 1;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .workspace-section,
  .products-workspace-grid,
  .products-workspace-column {
    min-width: 0;
    max-width: 100%;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 1002;
    width: min(310px, 86vw);
    height: 100vh;
    height: 100dvh;
    overflow-y: auto;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-105%);
    transition:
      transform 220ms ease,
      visibility 220ms ease;
    box-shadow: 14px 0 40px rgba(0, 0, 0, 0.4);
  }

  .sidebar.mobile-open {
    visibility: visible;
    pointer-events: auto;
    transform: translateX(0);
  }

  .mobile-menu-toggle,
  .mobile-menu-close {
    display: inline-flex;
  }

  .sidebar-brand {
    position: relative;
  }

  .mobile-menu-close {
    position: absolute;
    top: 0;
    right: 0;
  }

  .mobile-menu-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1001;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    background: rgba(0, 0, 0, 0.65);
  }

  .mobile-menu-backdrop:not(.hidden) {
    display: block;
  }

  body.citadel-mobile-menu-open {
    overflow: hidden;
  }

  .utility-panel:has(.products-workspace-grid) {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  .products-workspace-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Teléfonos */
@media (max-width: 600px) {

  .workspace {
    padding: 20px 14px 36px;
  }

  .workspace-header {
    gap: 12px;
    min-width: 0;
  }

  .workspace-header h1 {
    font-size: clamp(20px, 5.5vw, 28px);
    overflow-wrap: anywhere;
  }

  .header-user {
    display: none;
  }

  .utility-panel:has(.products-workspace-grid) {
    padding: 14px;
  }

  .products-workspace-column {
    padding: 12px;
  }

  .utility-history-list,
  .utility-history-item,
  .utility-history-information {
    min-width: 0;
    max-width: 100%;
  }

  .products-workspace-right .utility-history-item {
    grid-template-columns: minmax(0, 1fr);
  }

  .products-workspace-right .utility-job-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }
}

/* Protección contra desbordamiento horizontal accidental. */
@media (max-width: 900px) {
  body {
    overflow-x: clip;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}

/* Motivo de pausa de importaciones */
.utility-job-pause-reason {
  display: block;
  margin-top: 8px;
  padding: 10px 12px;
  color: var(--danger);
  background: rgba(255, 155, 155, 0.07);
  border: 1px solid rgba(255, 155, 155, 0.2);
  border-radius: 8px;
  overflow-wrap: anywhere;
}

/* CITADEL - DESKTOP SIDEBAR TOGGLE v1 */
/* En tablet/móvil permanece intacto el menú superpuesto actual. */
@media (min-width: 901px) {
  .mobile-menu-toggle {
    display: inline-flex;
  }

  .app-view.citadel-sidebar-collapsed {
    grid-template-columns: minmax(0, 1fr);
  }

  .app-view.citadel-sidebar-collapsed > .sidebar {
    display: none;
  }

  .app-view.citadel-sidebar-collapsed > .workspace {
    grid-column: 1;
    min-width: 0;
  }
}
