html,
body {
  height: 100%;
  margin: 0;
  overflow: hidden; /* quita el scroll de la ventana principal */
}

:root {
  --bg: #f5f5f5;
  --bg-card: #ffffff;
  --bg-header: #ffffff;
  --text: #1f2933;
  --text-soft: #6b7280;
  --border: #d1d5db;
  --border-soft: #e5e7eb;
  --accent: #2563eb;
  --accent-soft: #e0ecff;
  --accent-contrast: #ffffff;
  --danger: #ef4444;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 12px 30px rgba(15, 23, 42, 0.18);
  --table-header-bg: #f3f4f6;
  --table-row-alt: #f9fafb;
  --status-draft: #9ca3af;
  --status-pending: #facc15;
  --status-approved: #22c55e;
  --status-rejected: #ef4444;
  --status-pending-review: #fb923c;
  --status-pending-approval: #6366f1;
  --status-published: #10b981;
  --status-archived: #6b7280;
  --overlay-bg: rgba(15, 23, 42, 0.45);
  --input-bg: #ffffff;
}

html[data-theme="dark"] {
  --bg: #020617;
  --bg-card: #0b1220;
  --bg-header: #020617;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --border: #1e293b;
  --border-soft: #111827;
  --accent: #3b82f6;
  --accent-soft: #1d2a45;
  --accent-contrast: #ffffff;
  --table-header-bg: #020617;
  --table-row-alt: #020617;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.65);
  --shadow-md: 0 18px 40px rgba(15, 23, 42, 0.85);
  --overlay-bg: rgba(15, 23, 42, 0.75);
  --input-bg: #020617;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  margin: 0;
  padding: 0;
  background: radial-gradient(
      circle at top left,
      rgba(37, 99, 235, 0.08),
      transparent 55%
    ),
    radial-gradient(
      circle at bottom right,
      rgba(16, 185, 129, 0.08),
      transparent 55%
    ),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* === APP A PANTALLA COMPLETA === */
.app-shell {
  max-width: none;
  width: 100%;
  margin: 0;
  padding: 1.5rem 1.5rem 2.5rem;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  height: 100vh;
}

header.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.25rem;
  padding: 0.75rem 1rem;
  background: rgba(255, 255, 255, 0.75);
  backdrop-filter: blur(16px);
  border-radius: 999px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

html[data-theme="dark"] header.app-header {
  background: rgba(15, 23, 42, 0.85);
}

/* El contenedor de la app ocupa todo el alto restante */
#app {
  flex: 1 1 auto;
  display: flex;
  min-height: 0; /* CLAVE para que el contenido interno pueda hacer scroll */
}

.app-title {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.app-title-icon {
  width: 26px;
  height: 26px;
  border-radius: 9px;
  background: radial-gradient(circle at 20% 20%, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 15px;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.45);
}

.app-title span {
  font-size: 1.1rem;
}

.app-subtitle {
  font-size: 0.8rem;
  color: var(--text-soft);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.chip-env {
  font-size: 0.75rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--text-soft);
}

button {
  font-family: inherit;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  padding: 0.35rem 0.9rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

button:hover {
  box-shadow: 0 4px 10px rgba(15, 23, 42, 0.18);
  transform: translateY(-1px);
  background: #f9fafb;
}

html[data-theme="dark"] button:hover {
  background: #020617;
}

button[disabled] {
  opacity: 0.45;
  cursor: default;
  box-shadow: none;
  transform: none;
  background: var(--bg-card);
}

.btn-accent {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast);
}

.btn-accent:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  padding-inline: 0.5rem;
}

.btn-danger {
  border-color: var(--danger);
  color: var(--danger);
}

.btn-small {
  padding: 0.22rem 0.6rem;
  font-size: 0.8rem;
  border-radius: 999px;
  margin-top: 0.2rem;
}

.btn-icon {
  padding: 0.2rem 0.45rem;
  font-size: 0.9rem;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2rem;
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  padding: 1rem 1.1rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-soft);
}

.card h2 {
  margin-top: 0;
  margin-bottom: 0.6rem;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card h2 span {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-soft);
}

.card-header-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem 1rem;
  margin-top: 0.3rem;
}

label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  margin-bottom: 0.15rem;
  color: var(--text-soft);
}

input,
textarea,
select {
  width: 100%;
  padding: 0.42rem 0.5rem;
  margin-top: 0.1rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: all 0.12s ease;
}

textarea {
  border-radius: 10px;
  resize: vertical;
  min-height: 68px;
  font-family: inherit;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.25);
}

input[type="file"] {
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  background: var(--bg);
  font-size: 0.8rem;
}

.field-inline {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  margin-top: 0.4rem;
}

.helper-text {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-top: 0.2rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 0.7rem;
  font-size: 0.83rem;
}

th,
td {
  border: 1px solid var(--border-soft);
  padding: 0.45rem 0.55rem;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  background: var(--table-header-bg);
  text-align: left;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
}

th[data-sort-col] {
  cursor: pointer;
  user-select: none;
}

th[data-sort-dir="asc"]::after {
  content: " ▲";
  font-size: 0.7rem;
}

th[data-sort-dir="desc"]::after {
  content: " ▼";
  font-size: 0.7rem;
}

tbody tr:nth-child(odd) {
  background: transparent;
}

tbody tr:nth-child(even) {
  background: var(--table-row-alt);
}

tbody tr:hover {
  background: rgba(37, 99, 235, 0.04);
}

tbody tr.row-selected {
  background: rgba(37, 99, 235, 0.08);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

/* === ICONOS POR TIPO DE ARCHIVO EN LA COLUMNA TÍTULO === */
.file-cell {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.file-icon {
  font-size: 1rem;
  width: 1.2rem;
  display: inline-flex;
  justify-content: center;
  flex-shrink: 0;
}

.file-title-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-ext-badge {
  font-size: 0.68rem;
  text-transform: uppercase;
  padding: 0.05rem 0.35rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  color: var(--text-soft);
  background: rgba(148, 163, 184, 0.08);
  margin-left: 0.2rem;
}

html[data-theme="dark"] .file-ext-badge {
  background: rgba(15, 23, 42, 0.6);
}
/* === FIN ICONOS === */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-top: 0.3rem;
}

.table-toolbar input {
  max-width: 260px;
  border-radius: 999px;
}

/* pequeño ajuste para el select de categoría en la toolbar */
.table-toolbar select {
  max-width: 220px;
}

.table-actions-bar {
  margin-top: 0.55rem;
  padding: 0.45rem 0.65rem;
  border-radius: 999px;
  border: 1px solid var(--border-soft);
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  align-items: center;
  justify-content: space-between;
  background: rgba(15, 23, 42, 0.02);
}

html[data-theme="dark"] .table-actions-bar {
  background: rgba(15, 23, 42, 0.55);
}

.table-actions-info {
  font-size: 0.8rem;
  color: var(--text-soft);
  min-width: 0;
}

.table-actions-info strong {
  color: var(--text);
}

.table-actions-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.table-actions-buttons .btn-small,
.table-actions-buttons .btn-icon {
  margin-top: 0;
}

/* Base de la tabla: sin scroll aquí, sólo estilado */
.table-wrapper {
  width: 100%;
  border-radius: 12px;
}

.table-wrapper table {
  min-width: 100%;
}

/* Layout tabla + panel de previsualización (base) */
.docs-layout {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  align-items: stretch;
  flex: 1 1 auto;
  min-height: 0;
}

.docs-layout .table-wrapper {
  flex: 1 1 0;
}

.preview-panel {
  flex: 0 0 340px;
  max-width: 380px;
  border-left: 1px solid var(--border-soft);
  padding-left: 0.75rem;
  display: flex;
  flex-direction: column;
  max-height: 100%;
}

.preview-panel.hidden {
  display: none !important;
}

.preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  flex: 0 0 auto;
}

.preview-title {
  font-size: 0.85rem;
  font-weight: 600;
}

.preview-subtitle {
  font-size: 0.75rem;
  color: var(--text-soft);
  margin-top: 0.1rem;
}

.preview-actions {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.preview-body {
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border-soft);
  overflow: hidden; /* lo sobreescribimos dentro de #docsCard */
}

#previewFrame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--bg);
}

#previewMessage {
  font-size: 0.75rem;
  color: var(--text-soft);
  padding: 0.35rem 0.5rem;
  flex: 0 0 auto;
}

.hidden {
  display: none !important;
}

.status-badge {
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.68rem;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.04em;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.status-badge::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: currentColor;
}

.status-draft {
  background: rgba(156, 163, 175, 0.15);
  color: var(--status-draft);
}
.status-pending {
  background: rgba(250, 204, 21, 0.18);
  color: var(--status-pending);
}
.status-approved {
  background: rgba(34, 197, 94, 0.18);
  color: var(--status-approved);
}
.status-rejected {
  background: rgba(239, 68, 68, 0.2);
  color: var(--status-rejected);
}
.status-pending_review {
  background: rgba(251, 146, 60, 0.2);
  color: var(--status-pending-review);
}
.status-changes_requested {
  background: rgba(251, 113, 133, 0.24);
  color: #fb7185;
}
.status-pending_approval {
  background: rgba(99, 102, 241, 0.2);
  color: var(--status-pending-approval);
}
.status-published {
  background: rgba(16, 185, 129, 0.2);
  color: var(--status-published);
}
.status-archived {
  background: rgba(107, 114, 128, 0.22);
  color: var(--status-archived);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay-bg);
  display: flex; /* se oculta con la clase .hidden */
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card);
  padding: 1rem 1.1rem;
  border-radius: 16px;
  width: 90%;
  max-width: 680px;
  max-height: 80vh;
  overflow: auto;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-soft);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 0.5rem;
}

.modal-header h3 {
  margin: 0;
  font-size: 1rem;
}

.modal-header small {
  display: block;
  font-size: 0.78rem;
  color: var(--text-soft);
}

.modal-footer {
  text-align: right;
  margin-top: 0.9rem;
}

#newVersionForm {
  margin-top: 0.4rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

#newVersionForm input[type="file"] {
  max-width: 220px;
}

#newVersionMsg {
  font-size: 0.78rem;
  color: var(--text-soft);
}

#loginError,
#uploadMsg,
#uploadFolderMsg {
  font-size: 0.78rem;
  margin-top: 0.3rem;
}

#loginError {
  color: var(--danger);
}

/* Layout principal */
.app-layout {
  display: flex;
  gap: 1.25rem;
  align-items: flex-start;
  flex: 1 1 auto;
  min-height: 0; /* para que el contenido no fuerce más alto que la ventana */
}

/* ==== SIDEBAR LAYOUT NUEVO ==== */
.sidebar {
  background: linear-gradient(
    180deg,
    rgba(15, 23, 42, 0.96),
    rgba(15, 23, 42, 0.98)
  );
  border-radius: 18px;
  padding: 0.9rem 0.85rem;
  box-shadow: var(--shadow-md);
  color: #e5e7eb;
  min-height: 540px;
  flex: 0 0 auto;
  width: 260px;
  max-width: 480px;
  min-width: 180px;
  overflow: hidden; /* el scroll se gestiona dentro de folders-scroll */
  height: 100%;
  max-height: 100%;
  display: flex;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  min-height: 0;
}

.sidebar-resizer {
  flex: 0 0 6px;
  align-self: stretch;
  cursor: col-resize;
  background: transparent;
  border-radius: 999px;
  transition: background 0.12s ease;
}

.sidebar-resizer:hover {
  background: rgba(148, 163, 184, 0.25);
}

body.resizing {
  cursor: col-resize;
  user-select: none;
}

.main-panel {
  min-width: 0;
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  min-height: 0; /* para que el card-docs pueda hacer scroll interno */
}

.card-compact {
  padding: 0.7rem 0.9rem;
}

/* El card de Documentos ocupa el resto del alto */
.card-docs {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.card-docs h2,
.card-docs .table-toolbar,
.card-docs .table-actions-bar {
  flex: 0 0 auto;
}

.card-docs .docs-layout {
  flex: 1 1 auto;
  min-height: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.8rem;
  flex: 0 0 auto;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.avatar-circle {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  background: radial-gradient(circle at 20% 20%, #60a5fa, #2563eb);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: white;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.5);
}

.sidebar-user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.sidebar-user-role {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
}

.sidebar-section {
  margin-top: 0.9rem;
}

.sidebar-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #9ca3af;
  margin-bottom: 0.35rem;
}

/* sección carpetas ocupa la parte “elástica” */
.sidebar-section-folders {
  flex: 1 1 auto;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* scroll interno del árbol */
.folders-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto; /* vertical + horizontal */
}

/* sección de filtros abajo */
.sidebar-section-filters {
  flex: 0 0 auto;
  padding-top: 0.6rem;
  border-top: 1px solid rgba(148, 163, 184, 0.35);
  margin-top: 0.3rem;
}

/* resizer vertical entre carpetas y filtros */
.sidebar-v-resizer {
  flex: 0 0 4px;
  margin: 4px 0;
  border-radius: 999px;
  cursor: row-resize;
  background: transparent;
  transition: background 0.12s ease;
}

.sidebar-v-resizer:hover {
  background: rgba(148, 163, 184, 0.35);
}

body.resizing-vert {
  cursor: row-resize;
  user-select: none;
}

.folder-tree {
  list-style: none;
  padding-left: 0;
  margin: 0;
  font-size: 0.82rem;
}

.folder-item {
  margin: 2px 0;
}

.folder-row {
  padding: 0.25rem 0.45rem;
  border-radius: 999px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  color: #e5e7eb;
  position: relative;
  padding-right: 0.4rem;
}

.folder-row:hover {
  background: rgba(15, 23, 42, 0.7);
}

.folder-row-drop-target {
  background: rgba(37, 99, 235, 0.4) !important;
}

.folder-item-active > .folder-row {
  background: rgba(37, 99, 235, 0.25);
}

.folder-icon {
  font-size: 0.9rem;
}

.folder-label {
  flex: 1;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.folder-caret {
  font-size: 0.6rem;
  width: 0.9rem;
  display: inline-flex;
  justify-content: center;
  transition: transform 0.15s ease;
  opacity: 0.8;
}

.folder-caret.collapsed {
  transform: rotate(-90deg);
  opacity: 0.6;
}

.folder-children {
  list-style: none;
  margin: 2px 0 2px 0.75rem;
  padding-left: 0.5rem;
  border-left: 1px solid rgba(148, 163, 184, 0.35);
}

.folder-children.collapsed {
  display: none;
}

.btn-chip {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: transparent;
  color: #e5e7eb;
  font-size: 0.75rem;
  padding: 0.2rem 0.65rem;
  margin: 0.1rem 0.1rem 0 0;
  cursor: pointer;
}

.btn-chip:hover {
  background: rgba(148, 163, 184, 0.16);
}

.btn-chip-active {
  background: rgba(37, 99, 235, 0.38);
  border-color: rgba(37, 99, 235, 0.7);
}

.folder-more {
  opacity: 0;
  font-size: 0.9rem;
  cursor: pointer;
  border-radius: 999px;
  padding: 0 0.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
}

.folder-row:hover .folder-more {
  opacity: 1;
}

.folder-more:hover {
  background: rgba(148, 163, 184, 0.3);
  color: #e5e7eb;
}

.folder-context-menu {
  position: fixed;
  z-index: 1500;
  min-width: 170px;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 0.3rem 0;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-soft);
  font-size: 0.8rem;
}

.folder-context-item {
  padding: 0.3rem 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
  white-space: nowrap;
}

.folder-context-item:hover {
  background: rgba(148, 163, 184, 0.16);
}

.folder-context-item.danger {
  color: var(--danger);
}

.folder-context-item.disabled {
  opacity: 0.4;
  cursor: default;
  pointer-events: none;
}

.folder-context-icon {
  width: 1.1rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Mini árbol del modal de mover documento */
.move-doc-tree {
  border-radius: 10px;
  border: 1px solid var(--border-soft);
  padding: 0.35rem 0.5rem;
  max-height: 260px;
  overflow: auto;
  background: var(--bg);
  margin-top: 0.4rem;
}

.move-doc-item {
  margin: 1px 0;
}

.move-doc-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.4rem;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.82rem;
}

.move-doc-row:hover {
  background: rgba(37, 99, 235, 0.06);
}

.move-doc-row.selected {
  background: rgba(37, 99, 235, 0.14);
  color: var(--accent);
  font-weight: 600;
}

.move-doc-icon {
  font-size: 0.9rem;
}

.move-doc-label {
  flex: 1;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.move-doc-children {
  border-left: 1px solid var(--border-soft);
  margin-left: 0.7rem;
  padding-left: 0.6rem;
}

/* El panel lateral comparte el alto disponible y también puede scrollear */
#docsCard .preview-panel {
  flex: 0 0 340px;
  max-height: 100%;
  display: flex;
  flex-direction: column;
}

#docsCard .preview-panel .preview-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto; /* scroll interno si el contenido crece */
}

/* ==========================
   CARD DE DOCUMENTOS (#docsCard)
   ========================== */

#docsCard {
  display: flex;
  flex-direction: column;
  /* ALTURA FIJA DEL CARD */
  height: 700px;
  max-height: 700px;
}

/* La zona tabla + previsualización rellena el card */
#docsCard .docs-layout {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  gap: 0.75rem;
  align-items: stretch;
}

/* El wrapper es el que tiene el scroll */
#docsCard .table-wrapper {
  flex: 1 1 auto;
  min-height: 0;
  height: 100%;
  max-height: none;
  overflow-x: auto; /* horizontal */
  overflow-y: auto; /* vertical */
  display: block;
  margin-top: 0rem; /* el margen que antes tenía la tabla */
  padding-bottom: 2.5rem; /* 🆕 deja hueco para el bloque de paginación */
  box-sizing: border-box;
}

/* El div intermedio no hace nada raro, sólo ocupa todo */
#docsCard .docs-scroll {
  width: 100%;
  height: 100%;
}

/* La tabla se adapta al ancho, pero tiene un mínimo para que haya scroll */
#docsCard .docs-scroll > table {
  width: 100%; /* se estira con el card */
  min-width: 700px; /* cuando el panel es más estrecho que esto, aparece scroll horizontal */
  border-collapse: separate; /* para sticky + z-index */
  border-spacing: 0;
  margin-top: 0;
}

/* Cabecera fija al hacer scroll en la tabla */
#docsCard thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--bg-card); /* fondo sólido para tapar las filas */
}

/* Columna 3 = TÍTULO, sin ancho fijo */
#docsCard th:nth-child(3),
#docsCard td:nth-child(3) {
  white-space: normal; /* se puede partir en varias líneas */
}

/* El texto del título puede ocupar varias líneas y partir palabras largas */
#docsCard td:nth-child(3) .file-title-text {
  white-space: normal;
  word-break: break-word;
  overflow: visible;
  text-overflow: clip;
}

/* ==== PAGINACIÓN (debajo de la tabla) ==== */

.table-pagination {
  margin-top: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: left;
  gap: 0.75rem;
  font-size: 0.8rem;
  color: var(--text-soft);
}

.table-pagination .btn-small {
  white-space: nowrap;
}

.table-page-info {
  min-width: 0;
}

/* ==== BÚSQUEDA AVANZADA ==== */

.advanced-search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 0.9rem;
  margin-top: 0.4rem;
}

/* ==========================
   RESPONSIVE
   ========================== */

@media (max-width: 900px) {
  .app-shell {
    padding: 1rem 1rem 2rem;
  }
  .app-layout {
    flex-direction: column;
  }
  .sidebar {
    order: 2;
    width: 100% !important;
    max-width: 100%;
  }
  .main-panel {
    order: 1;
  }
  .table-actions-bar {
    border-radius: 12px;
  }
  .sidebar-resizer {
    display: none;
  }
  .docs-layout {
    flex-direction: column;
  }
  .preview-panel {
    flex: 1 1 auto;
    max-width: none;
    padding-left: 0;
    border-left: none;
    margin-top: 0.6rem;
  }
  .card-docs {
    min-height: 0;
  }
}

@media (max-width: 640px) {
  header.app-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.6rem;
    border-radius: 18px;
  }

  .header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .card {
    padding: 0.9rem 0.8rem;
  }

  th,
  td {
    font-size: 0.78rem;
  }
}

/* =====================================
   TABLA DE DOCUMENTOS SIMILARES (preview)
   ===================================== */

.similar-docs-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.similar-docs-table th,
.similar-docs-table td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--border-soft);
}

.sim-doc-title {
  font-weight: 500;
}

.sim-doc-meta {
  font-size: 0.7rem;
  color: var(--text-soft);
}

/* =========================
   AUTOCOMPLETE / SUGERENCIAS
   ========================= */

.search-with-suggestions {
  position: relative;
  flex: 1 1 260px;
  max-width: 420px;
}

.table-toolbar .search-with-suggestions input {
  width: 100%;
  max-width: none;
}

/* Panel flotante */
.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  padding: 0.35rem 0;
  background: var(--bg-card);
  border: 1px solid var(--border-soft);
  border-radius: 0.7rem;
  box-shadow: 0 18px 35px rgba(15, 23, 42, 0.45);
  max-height: 320px;
  overflow-y: auto;
  z-index: 40;
  font-size: 0.8rem;
}

.search-suggestions.hidden {
  display: none;
}

/* Separación por secciones (categorías, tags, propietarios, docs...) */
.sugg-section {
  padding: 0.25rem 0.6rem 0.4rem;
  border-top: 1px solid rgba(148, 163, 184, 0.18);
}

.sugg-section:first-child {
  border-top: none;
}

.sugg-section-title {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  margin-bottom: 0.18rem;
}

/* Items clicables */
.sugg-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.25rem 0.4rem;
  border-radius: 0.45rem;
  cursor: pointer;
}

.sugg-item:hover {
  background: rgba(148, 163, 184, 0.12);
}

.sugg-item-main {
  flex: 1;
  min-width: 0;
}

.sugg-item-label {
  font-size: 0.8rem;
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
}

/* “Tags” de información: tipo, scope, etc. */
.sugg-item-badge {
  font-size: 0.7rem;
  padding: 0.08rem 0.6rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.16);
  color: var(--text-soft);
  white-space: nowrap;
}

/* Documentos dentro del panel */
.sugg-doc-title {
  font-size: 0.8rem;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sugg-doc-snippet {
  font-size: 0.72rem;
  color: var(--text-soft);
  margin-top: 0.08rem;
  display: -webkit-box;
  line-clamp: 2;              /* ← propiedad estándar */
  -webkit-line-clamp: 2;    /* máximo 2 líneas */
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
}

/* Texto resaltado (si usas <mark>) */
.sugg-doc-snippet mark,
.sugg-item-label mark {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
}

/* Badge de similitud semántica */
.semantic-badge {
  margin-left: 0.3rem;
  padding: 0 0.4rem;
  border-radius: 999px;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(132, 94, 247, 0.18);
  color: rgb(196, 181, 253);
}

.sidebar-nav {
  list-style: none;
  margin: 0.4rem 0 0;
  padding: 0;
}

.sidebar-nav li + li {
  margin-top: 0.25rem;
}

.sidebar-link {
  display: block;
  font-size: 0.85rem;
  padding: 0.35rem 0.4rem;
  border-radius: 0.35rem;
  color: var(--text-soft);
  text-decoration: none;
}

.sidebar-link:hover {
  background: var(--bg-soft, rgba(148, 163, 184, 0.12));
  color: var(--text-strong, #e5e7eb);
}

/* =========================
   Modal explicación LLM
   ========================= */

#docExplainBody {
  font-size: 0.86rem;
  line-height: 1.45;
  color: var(--text);
  max-height: 60vh;
  overflow-y: auto;
  padding-right: 0.2rem;
}

.doc-explain-section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-soft);
  margin-top: 0.6rem;
  margin-bottom: 0.2rem;
}

.doc-explain-section {
  margin-bottom: 0.5rem;
}

.doc-explain-bullet {
  margin-left: 1rem;
  list-style: disc;
}
