/* ============================================================
 * OptimOS · PDF ↔ Word — Estilos
 * ============================================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --red: #E31E24;
  --red-dark: #B71C1C;
  --black: #1a1a1a;
  --dark-gray: #2d2d2d;
  --medium-gray: #555;
  --light-gray: #f5f6f8;
  --line: #e6e8ec;
  --white: #ffffff;
  --pdf: #E31E24;
  --word: #2563eb;
  --ok: #16a34a;
  --warn: #d97706;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--light-gray);
  min-height: 100vh;
  color: var(--black);
}

/* ---------- Auth loader ---------- */
#authLoader {
  position: fixed; inset: 0; z-index: 9999;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: var(--light-gray); color: var(--medium-gray);
}
#authLoader .spin {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid #e0e0e0; border-top-color: var(--red);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
body:not(.auth-ok) .app-shell { display: none; }
#authLoader.hidden { opacity: 0; pointer-events: none; transition: opacity 0.35s ease; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 92px; background: #3a4a54; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center;
  padding: 18px 0; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.side-logo {
  width: 46px; height: 46px; border-radius: 12px; object-fit: cover;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
}
.side-nav { display: flex; flex-direction: column; gap: 8px; width: 100%; align-items: center; margin-top: 4px; }
.side-btn {
  width: 74px; padding: 10px 4px; border: none; background: transparent;
  border-radius: 12px; cursor: pointer; color: #cbd5db;
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  font-size: 0.66rem; font-weight: 600; transition: all 0.18s;
}
.side-btn i { font-size: 1.15rem; }
.side-btn:hover { background: rgba(255,255,255,0.08); color: #fff; }
.side-btn.active { background: var(--red); color: #fff; box-shadow: 0 4px 12px rgba(227,30,36,0.35); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar-accent { height: 4px; background: linear-gradient(90deg, var(--red), #ff5a5f); }

/* ---------- Header ---------- */
.header {
  background: var(--white); border-bottom: 1px solid var(--line);
  padding: 16px 28px; display: flex; align-items: center; justify-content: space-between;
  gap: 18px; flex-wrap: wrap;
}
.h-title h1 { font-size: 1.28rem; font-weight: 800; }
.h-title span { font-size: 0.82rem; color: var(--medium-gray); }
.h-user {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid rgba(227,30,36,0.28); border-radius: 40px; padding: 5px 14px 5px 5px;
  box-shadow: 0 1px 6px rgba(227,30,36,0.06);
}
.h-user-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  background-size: cover; background-position: center; font-size: 0.85rem;
}
.h-user-info { line-height: 1.15; }
.h-user-info b { font-size: 0.85rem; }
.h-user-info small { display: block; color: var(--medium-gray); font-size: 0.72rem; }
.h-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.btn-volver { white-space: nowrap; }

/* ---------- Content ---------- */
.content { padding: 26px 28px; flex: 1; }

/* ---------- Conversor card ---------- */
.conv-hero {
  background: var(--white); border: 1px solid var(--line); border-radius: 18px;
  padding: 30px; margin-bottom: 26px; box-shadow: 0 4px 20px rgba(0,0,0,0.04);
}
.conv-hero h2 { font-size: 1.15rem; margin-bottom: 4px; }
.conv-hero p.sub { color: var(--medium-gray); font-size: 0.88rem; margin-bottom: 20px; }

.dropzone {
  border: 2px dashed #cfd4dc; border-radius: 16px; padding: 40px 20px;
  text-align: center; cursor: pointer; transition: all 0.2s; background: #fafbfc;
}
.dropzone:hover, .dropzone.drag { border-color: var(--red); background: #fff5f5; }
.dropzone .dz-icon {
  width: 66px; height: 66px; border-radius: 50%; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center; font-size: 1.7rem; color: #fff;
}
.mode-pdf2word .dz-icon { background: var(--pdf); }
.mode-word2pdf .dz-icon { background: var(--word); }
.dropzone h3 { font-size: 1rem; margin-bottom: 4px; }
.dropzone p { color: var(--medium-gray); font-size: 0.82rem; }
.dropzone .formats { margin-top: 10px; font-size: 0.74rem; color: #9aa0aa; }

.file-preview {
  display: none; align-items: center; gap: 14px; margin-top: 18px;
  background: #f6f8fb; border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
}
.file-preview.show { display: flex; }
.file-preview .fp-icon {
  width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 1.1rem; flex-shrink: 0;
}
.fp-pdf { background: var(--pdf); } .fp-word { background: var(--word); }
.file-preview .fp-info { flex: 1; min-width: 0; }
.file-preview .fp-info b { display: block; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-preview .fp-info small { color: var(--medium-gray); font-size: 0.76rem; }
.fp-remove { background: none; border: none; color: #b0b5bd; cursor: pointer; font-size: 1.1rem; }
.fp-remove:hover { color: var(--red); }

/* Selector de motor */
.motor-select { margin-top: 18px; }
.motor-label { font-size: 0.8rem; font-weight: 600; color: var(--medium-gray); display: block; margin-bottom: 8px; }
.motor-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.motor-opt { cursor: pointer; }
.motor-opt input { display: none; }
.motor-card {
  display: flex; flex-direction: column; gap: 2px; padding: 14px 16px;
  border: 2px solid var(--line); border-radius: 12px; transition: all 0.15s; background: #fff;
}
.motor-card i { font-size: 1.1rem; color: var(--medium-gray); margin-bottom: 4px; }
.motor-card b { font-size: 0.86rem; }
/* Tooltip de info del motor */
.motor-info {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; cursor: help;
  color: var(--medium-gray); font-size: 0.7rem; position: relative;
  vertical-align: middle; margin-left: 4px;
}
.motor-info:hover { color: var(--red); }
.motor-info::after {
  content: attr(data-tooltip);
  position: absolute; bottom: calc(100% + 8px); left: 50%; transform: translateX(-50%);
  width: 240px; padding: 10px 12px; border-radius: 10px;
  background: var(--dark-gray); color: #fff; font-size: 0.72rem; font-weight: 400;
  line-height: 1.4; text-align: left; white-space: normal;
  box-shadow: 0 6px 20px rgba(0,0,0,0.2);
  pointer-events: none; opacity: 0; transition: opacity 0.18s;
  z-index: 10;
}
.motor-info:hover::after, .motor-info:focus::after { opacity: 1; }

.motor-card small { font-size: 0.72rem; color: var(--medium-gray); }
.motor-count {
  margin-top: 6px; font-size: 0.72rem; font-weight: 700; color: var(--red);
  background: #fff0f0; border-radius: 20px; padding: 2px 10px; align-self: flex-start;
}
.motor-opt input[value="servidor"]:checked + .motor-card .motor-count,
.motor-card .motor-count { }
.motor-opt input:checked + .motor-card { border-color: var(--red); background: #fff5f5; box-shadow: 0 2px 10px rgba(227,30,36,0.1); }
.motor-opt input:checked + .motor-card i { color: var(--red); }
@media (max-width: 620px) { .motor-options { grid-template-columns: 1fr; } }

.conv-actions { margin-top: 20px; display: flex; gap: 12px; align-items: center; }

/* ---------- Buttons ---------- */
.btn {
  border: none; border-radius: 10px; padding: 11px 20px; font-weight: 600;
  font-size: 0.88rem; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; transition: all 0.18s;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--red-dark); }
.btn-word { background: var(--word); color: #fff; }
.btn-word:hover:not(:disabled) { background: #1d4ed8; }
.btn-ghost { background: #fff; border: 1px solid var(--line); color: var(--medium-gray); }
.btn-ghost:hover { border-color: var(--red); color: var(--red); }
.btn-sm { padding: 7px 12px; font-size: 0.8rem; }

/* ---------- Tabla conversiones ---------- */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 1.05rem; }
.tabs { display: flex; gap: 8px; }
.tab {
  padding: 8px 16px; border-radius: 40px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; font-size: 0.82rem; font-weight: 600; color: var(--medium-gray);
}
.tab.active { background: var(--red); color: #fff; border-color: var(--red); }

.table-wrap { background: var(--white); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; }
table.conv-table { width: 100%; border-collapse: collapse; }
.conv-table thead th {
  text-align: left; padding: 13px 16px; font-size: 0.74rem; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--medium-gray); background: #fafbfc; border-bottom: 1px solid var(--line);
}
.conv-table tbody td { padding: 13px 16px; border-bottom: 1px solid #f0f1f4; font-size: 0.87rem; vertical-align: middle; }
.conv-table tbody tr:last-child td { border-bottom: none; }
.conv-table tbody tr:hover { background: #fcfcfd; }

.doc-cell { display: flex; align-items: center; gap: 10px; }
.doc-badge {
  width: 34px; height: 34px; border-radius: 8px; display: flex; align-items: center;
  justify-content: center; color: #fff; font-size: 0.72rem; font-weight: 700; flex-shrink: 0;
}
.doc-badge.pdf { background: var(--pdf); } .doc-badge.word { background: var(--word); }
.doc-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.doc-sub { font-size: 0.74rem; color: var(--medium-gray); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 30px;
  font-size: 0.72rem; font-weight: 600;
}
.chip.estado-listo { background: #e7f6ec; color: var(--ok); }
.chip.estado-procesando { background: #fff4e5; color: var(--warn); }
.chip.estado-pendiente { background: #eef1f5; color: var(--medium-gray); }
.chip.estado-error { background: #fdecec; color: var(--red); }
.chip.tipo { background: #eef2ff; color: var(--word); }
.chip.motor-adobe { background: #fbe9e7; color: #d9480f; }
.chip.motor-servidor { background: #eef6f0; color: #16a34a; }
.chip.compartido { background: #f3e8ff; color: #7c3aed; }
.chip.propietario { background: #e7f6ec; color: var(--ok); }

.acciones { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #fff;
  cursor: pointer; color: var(--medium-gray); display: inline-flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.icon-btn:hover { border-color: var(--red); color: var(--red); }
.icon-btn.word:hover { border-color: var(--word); color: var(--word); }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.icon-btn.reintentar { border-color: var(--warn); color: var(--warn); }
.icon-btn.reintentar:hover { background: #fff4e5; }

.empty { text-align: center; padding: 46px 20px; color: var(--medium-gray); }
.empty i { font-size: 2.2rem; color: #cfd4dc; margin-bottom: 10px; display: block; }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .search { flex: 1; min-width: 200px; position: relative; }
.toolbar .search i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9aa0aa; }
.toolbar .search input {
  width: 100%; padding: 10px 14px 10px 36px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 0.86rem; font-family: inherit; background: #fff;
}

/* ---------- Share modal (usuarios) ---------- */
.share-list { max-height: 340px; overflow-y: auto; text-align: left; margin-top: 6px; padding: 2px; }
.share-item {
  display: flex; align-items: center; gap: 12px; padding: 11px 14px; border-radius: 12px;
  cursor: pointer; border: 1px solid var(--line); margin-bottom: 8px; transition: all 0.15s; background: #fff;
}
.share-item:hover { background: #fff5f5; border-color: rgba(227,30,36,0.35); }
.share-item input {
  width: 18px; height: 18px; accent-color: var(--red); cursor: pointer; flex-shrink: 0;
}
.share-item .si-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--red); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
  font-size: 0.82rem; flex-shrink: 0;
}
.share-item .si-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.share-item .si-name { font-size: 0.9rem; font-weight: 600; color: var(--black); }
.share-item .si-mail { font-size: 0.78rem; color: var(--medium-gray); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-item .si-rol {
  font-size: 0.68rem; font-weight: 600; color: var(--word); text-transform: capitalize;
  margin-top: 2px;
}
.share-empty { color: #777; padding: 16px; text-align: center; }

/* ---------- Footer ---------- */
.footer {
  padding: 20px 28px; border-top: 1px solid var(--line); background: #fff;
  display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: auto;
}
.footer img { height: 34px; object-fit: contain; }
.footer img.footer-logo-codeflex { height: 22px; }
.footer .sep { color: #cfd4dc; font-size: 1.3rem; }

/* ---------- Progress ---------- */
.progress-note { font-size: 0.82rem; color: var(--medium-gray); display: flex; align-items: center; gap: 8px; }
.progress-note .spin-sm {
  width: 16px; height: 16px; border: 2px solid #e0e0e0; border-top-color: var(--red);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .sidebar { width: 100%; height: auto; flex-direction: row; position: static; padding: 10px; justify-content: center; }
  .app-shell { flex-direction: column; }
  .side-logo { display: none; }
  .side-nav { flex-direction: row; }
  .conv-table thead { display: none; }
  .conv-table tbody td { display: block; border: none; padding: 6px 16px; }
  .conv-table tbody tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
  .acciones { justify-content: flex-start; margin-top: 6px; }
  .content { padding: 18px 14px; }
}

/* ============================================================
 * Módulo de Permisos (solo admin / super admin)
 * ============================================================ */
.side-btn-admin {
  margin-top: 8px;
  border-top: 1px solid rgba(255,255,255,0.12);
  padding-top: 14px;
}
.perm-section { margin-top: 4px; }
.perm-intro {
  color: var(--medium-gray);
  font-size: 0.92rem;
  line-height: 1.55;
  margin-bottom: 18px;
  max-width: 760px;
}
#permScopeNote { display: block; margin-top: 4px; font-size: 0.85rem; color: var(--warn); }

.perm-table th { white-space: nowrap; }
.perm-table td { padding-top: 8px; padding-bottom: 8px; }
.perm-user {
  display: flex;
  align-items: center;
  gap: 10px;
}
.perm-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.72rem;
  background-size: cover; background-position: center;
  flex-shrink: 0;
}
.perm-user-info { display: flex; flex-direction: column; gap: 0; min-width: 0; line-height: 1.25; }
.perm-user-name { font-weight: 600; color: var(--black); font-size: 0.88rem; }
.perm-user-mail { font-size: 0.74rem; color: var(--medium-gray); }
.perm-user-rol {
  font-size: 0.66rem; color: var(--red); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.4px;
}
.perm-badge {
  display: inline-block; font-size: 0.62rem; font-weight: 700;
  padding: 1px 7px; border-radius: 20px; margin-top: 2px;
  background: rgba(227,30,36,0.1); color: var(--red);
  text-transform: uppercase; letter-spacing: 0.4px; width: fit-content;
}
/* Toggles y botón más compactos */
.perm-switch { width: 38px; height: 20px; }
.perm-slider::before { height: 14px; width: 14px; }
.perm-switch input:checked + .perm-slider::before { transform: translateX(18px); }
.perm-save-btn { padding: 6px 12px; font-size: 0.78rem; }

/* Switch (toggle) para cada permiso */
.perm-switch {
  position: relative;
  display: inline-block;
  width: 44px; height: 24px;
}
.perm-switch input { opacity: 0; width: 0; height: 0; }
.perm-slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #cfd4da; border-radius: 24px;
  transition: 0.25s;
}
.perm-slider::before {
  content: ''; position: absolute;
  height: 18px; width: 18px; left: 3px; bottom: 3px;
  background: #fff; border-radius: 50%; transition: 0.25s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.25);
}
.perm-switch input:checked + .perm-slider { background: var(--ok); }
.perm-switch input:checked + .perm-slider::before { transform: translateX(20px); }
.perm-switch input:disabled + .perm-slider { opacity: 0.5; cursor: not-allowed; }

.perm-save-btn {
  padding: 8px 16px; font-size: 0.85rem;
}
.perm-cell { text-align: center; }
.perm-row-dirty { background: rgba(214,151,6,0.06); }

@media (max-width: 820px) {
  .perm-table thead { display: none; }
  .perm-table tbody td { display: flex; justify-content: space-between; align-items: center; border: none; padding: 8px 16px; }
  .perm-table tbody td::before {
    content: attr(data-label);
    font-weight: 600; color: var(--medium-gray); font-size: 0.85rem;
  }
  .perm-table tbody tr { display: block; border: 1px solid var(--line); border-radius: 12px; margin-bottom: 14px; padding: 8px 0; }
  .perm-table tbody td:first-child { border-bottom: 1px solid var(--line); padding-bottom: 12px; margin-bottom: 4px; }
  .perm-table tbody td:first-child::before { content: ''; }
}

/* Elementos deshabilitados por falta de permiso interno */
.side-btn.disabled-perm {
  opacity: 0.4;
  position: relative;
}
.side-btn.disabled-perm::after {
  content: '\f023'; /* candado */
  font-family: 'Font Awesome 6 Free'; font-weight: 900;
  position: absolute; top: 6px; right: 8px; font-size: 0.7rem;
}
.motor-opt.disabled-perm {
  opacity: 0.5;
  pointer-events: none;
  position: relative;
}
.motor-opt.disabled-perm::after {
  content: 'Sin permiso';
  position: absolute; top: 8px; right: 10px;
  font-size: 0.68rem; font-weight: 700; color: var(--red);
  background: rgba(227,30,36,0.1); padding: 2px 8px; border-radius: 10px;
}
