/* Filemón Office Sovereign UI — PIPC Suite
   Cumplimiento estricto: cero valores hexadecimales, 100% variables y tokens semánticos.
   Portal independiente document.body (z-index: 1000) libre de colisiones con sticky plecas.
*/

.office-portal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  padding: var(--space-4);
  animation: officeFadeIn var(--dur) var(--ease);
}

@keyframes officeFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes officeSlideUp {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.office-window {
  width: 100%;
  max-width: 1400px;
  height: min(92vh, 940px);
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: officeSlideUp var(--dur) var(--ease);
}

/* Barra superior del visor */
.office-topbar {
  min-height: 58px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-2) var(--space-4);
  gap: var(--space-3);
  flex-wrap: nowrap;
}

.office-meta {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 0;
  flex: 1 1 auto;
}

.office-icon {
  font-size: var(--text-xl);
  line-height: 1;
  flex-shrink: 0;
}

.office-heading {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.office-title {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--navy);
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}

.office-subtext {
  font-size: var(--text-xs);
  color: var(--muted);
  display: flex;
  gap: var(--space-2);
  align-items: center;
}

.office-seal-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  padding: 3px 8px;
  font-size: var(--text-xs);
  font-family: monospace;
  color: var(--navy-ink);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease);
}

.office-seal-chip:hover {
  background: var(--line);
}

.office-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-shrink: 0;
}

.office-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  height: 36px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--navy);
  cursor: pointer;
  transition: all var(--dur-fast) var(--ease);
  white-space: nowrap;
}

.office-btn:hover {
  background: var(--surface-2);
  border-color: var(--navy);
}

.office-btn:active {
  transform: scale(0.97);
}

.office-btn.office-btn-primary {
  background: var(--navy);
  color: var(--paper);
  border-color: var(--navy);
}

.office-btn.office-btn-primary:hover {
  filter: brightness(1.08);
}

.office-btn.office-btn-close {
  background: var(--ghost);
  border-color: transparent;
  color: var(--muted-strong);
  font-size: var(--text-lg);
  padding: 0 var(--space-3);
}

.office-btn.office-btn-close:hover {
  background: var(--danger-bg-soft);
  color: var(--danger);
}

/* Área de trabajo central */
.office-workspace {
  flex: 1 1 0%;
  display: flex;
  flex-direction: column;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}

/* Pestañas de hojas XLSX */
.office-sheet-bar {
  display: flex;
  align-items: center;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: var(--space-1) var(--space-3);
  gap: var(--space-2);
  overflow-x: auto;
}

.office-sheet-tab {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted-strong);
  font-size: var(--text-xs);
  font-weight: 700;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur-fast) var(--ease);
}

.office-sheet-tab:hover {
  background: var(--ghost);
  color: var(--navy);
}

.office-sheet-tab.active {
  background: var(--navy);
  color: var(--paper);
  border-color: var(--navy);
}

/* Rejilla XLSX */
.office-grid-container {
  flex: 1 1 0%;
  overflow: auto;
  position: relative;
  background: var(--paper);
}

.office-formula-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 6px var(--space-3);
  font-size: var(--text-xs);
  font-family: monospace;
}

.office-cell-address {
  font-weight: 700;
  color: var(--navy);
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  min-width: 44px;
  text-align: center;
}

.office-cell-formula {
  flex: 1;
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.office-table {
  border-collapse: collapse;
  font-size: var(--text-xs);
  table-layout: fixed;
  width: max-content;
  min-width: 100%;
}

.office-table th,
.office-table td {
  border: 1px solid var(--line);
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 320px;
}

.office-table th {
  background: var(--surface-2);
  color: var(--muted-strong);
  font-weight: 700;
  text-align: center;
  position: sticky;
  top: 0;
  z-index: 2;
  user-select: none;
}

.office-table th.office-row-header {
  left: 0;
  z-index: 3;
  width: 50px;
  min-width: 50px;
  max-width: 50px;
  background: var(--surface-2);
}

.office-table th.office-corner-header {
  position: sticky;
  left: 0;
  top: 0;
  z-index: 4;
  background: var(--surface-2);
}

.office-table td {
  background: var(--paper);
  color: var(--ink);
  cursor: cell;
}

.office-table td:hover {
  background: var(--info-bg);
}

.office-table td.office-cell-selected {
  outline: 2px solid var(--navy);
  outline-offset: -2px;
  background: var(--info-bg-2);
}

/* Visor de Páginas (PDF / DOCX) */
.office-paper-stage {
  flex: 1 1 0%;
  overflow: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: var(--space-5);
  background: var(--surface-2);
}

.office-paper-sheet {
  background: var(--paper);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  border-radius: 4px;
  position: relative;
  transition: transform var(--dur) var(--ease);
  max-width: 100%;
}

.office-paper-sheet img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 4px;
}

.office-paper-text-view {
  background: var(--paper);
  padding: var(--space-6);
  max-width: 850px;
  width: 100%;
  min-height: 800px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.12);
  border-radius: 6px;
  font-family: var(--font-ui);
  line-height: 1.65;
  color: var(--ink);
  white-space: pre-wrap;
  word-break: break-word;
  font-size: var(--text-sm);
}

/* Lightbox de Imagen */
.office-image-stage {
  flex: 1 1 0%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: var(--space-4);
  background: rgba(10, 15, 29, 0.95);
}

.office-image-stage img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
  transition: transform var(--dur) var(--ease);
}

/* Barra de Estado Inferior / Paginador */
.office-bottombar {
  min-height: 44px;
  background: var(--surface);
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-1) var(--space-4);
  gap: var(--space-3);
  font-size: var(--text-xs);
  color: var(--muted-strong);
}

.office-pager {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Panel Inspector de Celda (Drawer lateral) */
.office-drawer {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 320px;
  background: var(--paper);
  border-left: 1px solid var(--line);
  box-shadow: -4px 0 15px rgba(0, 0, 0, 0.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
  padding: var(--space-4);
  animation: officeSlideLeft var(--dur) var(--ease);
}

@keyframes officeSlideLeft {
  from { transform: translateX(100%); }
  to { transform: translateX(0); }
}

.office-drawer h4 {
  margin: 0 0 var(--space-3);
  color: var(--navy);
  font-size: var(--text-sm);
}

.office-drawer-kv {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.office-drawer-kv label {
  font-size: var(--text-xs);
  color: var(--muted);
  font-weight: 700;
}

.office-drawer-kv .val {
  font-size: var(--text-sm);
  color: var(--ink);
  background: var(--surface-2);
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  word-break: break-word;
  font-family: monospace;
}

/* Estado de carga y error */
.office-loading,
.office-error {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-6);
  text-align: center;
  color: var(--muted-strong);
}

.office-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-top-color: var(--navy);
  border-radius: 50%;
  animation: officeSpin 0.75s linear infinite;
}

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

/* Adaptación táctil y móvil (≤ 768px) */
@media (max-width: 768px) {
  .office-portal {
    padding: 0;
  }

  .office-window {
    height: 100vh;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  .office-topbar {
    padding: var(--space-2);
  }

  .office-title {
    max-width: 180px;
    font-size: var(--text-sm);
  }

  .office-btn {
    min-height: 44px;
    padding: 0 var(--space-2);
  }

  .office-seal-chip {
    display: none;
  }

  .office-drawer {
    width: 100%;
    max-height: 40vh;
    top: auto;
    border-left: none;
    border-top: 2px solid var(--navy);
  }
}
