/* Estilos de la biblioteca de documentos.
   Reutiliza los tokens de color y el tema oscuro de ../assets/styles.css */

:root {
  --danger: #b3261e;
  --danger-soft: #f9e3e1;
  --t-pdf: #b3261e;      --t-pdf-bg: #fbe5e3;
  --t-word: #2b5797;     --t-word-bg: #e2eaf6;
  --t-excel: #1f7244;    --t-excel-bg: #dff0e6;
  --t-ppt: #c4501b;      --t-ppt-bg: #fbe8dc;
  --t-img: #7a3fa0;      --t-img-bg: #efe4f6;
  --t-txt: #4d5866;      --t-txt-bg: #e7eaee;
}

body.dark {
  --danger: #f08a80;
  --danger-soft: #3a1f1d;
  --t-pdf: #f08a80;      --t-pdf-bg: #3a1f1d;
  --t-word: #8fb2ea;     --t-word-bg: #1d2a3d;
  --t-excel: #7fd1a1;    --t-excel-bg: #183024;
  --t-ppt: #f0a47a;      --t-ppt-bg: #3a2519;
  --t-img: #caa3e6;      --t-img-bg: #2d2238;
  --t-txt: #b4bcc6;      --t-txt-bg: #262d33;
}

.wrap {
  max-width: 1200px;
}

main {
  gap: 20px;
}

code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.92em;
}

/* ---------- Cabecera ---------- */

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.back-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 14px;
}

.back-link:hover {
  text-decoration: underline;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.title-row h1 {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.01em;
}

/* ---------- Botones ---------- */

.btn-primary {
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 14px;
}

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn-ghost:hover {
  border-color: var(--accent);
  opacity: 1;
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  font-weight: 600;
}

.btn-icon {
  background: transparent;
  color: var(--muted);
  padding: 4px 10px;
  font-size: 16px;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 13px;
  border-radius: 6px;
}

.act-ver { background: var(--accent-soft); color: var(--accent); }
.act-editar { background: var(--surface-2); color: var(--ink); border: 1px solid var(--line); }
.act-eliminar { background: var(--danger-soft); color: var(--danger); }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- Alertas ---------- */

.alert {
  background: var(--warn-soft);
  color: var(--ink);
  border: 1px solid var(--warn);
  border-radius: 10px;
  padding: 14px 16px;
  line-height: 1.5;
}

.alert a { color: var(--accent); }

/* ---------- Panel de búsqueda ---------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

#doc-search {
  flex: 1 1 280px;
  min-width: 0;
}

input[type="text"],
input[type="search"],
input[type="date"],
select,
textarea {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  width: 100%;
}

.toolbar select {
  width: auto;
  flex: 0 1 auto;
}

body.dark input[type="date"] {
  color-scheme: dark;
}

.view-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.view-toggle button {
  background: transparent;
  color: var(--muted);
  border-radius: 0;
  padding: 9px 14px;
}

.view-toggle button.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

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

.cat-chip {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 6px 12px;
  font-size: 13px;
}

.cat-chip .n {
  color: var(--muted);
  margin-left: 4px;
  font-size: 12px;
}

.cat-chip.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.cat-chip.is-active .n {
  color: inherit;
  opacity: 0.8;
}

/* ---------- Resultados ---------- */

.result-count {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow-x: auto;
}

.doc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.doc-table th,
.doc-table td {
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.doc-table th {
  background: var(--surface-2);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}

.doc-table tbody tr:last-child td {
  border-bottom: none;
}

.doc-table tbody tr:hover {
  background: var(--surface-2);
}

.doc-name {
  font-weight: 600;
  min-width: 160px;
}

.doc-file {
  display: block;
  font-weight: 400;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}

.doc-date {
  white-space: nowrap;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.doc-desc {
  color: var(--muted);
  max-width: 280px;
  min-width: 160px;
}

.doc-desc span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.col-acciones {
  text-align: right !important;
}

.acciones {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
  white-space: nowrap;
  background: var(--t-txt-bg);
  color: var(--t-txt);
}

.badge.t-PDF { background: var(--t-pdf-bg); color: var(--t-pdf); }
.badge.t-Word { background: var(--t-word-bg); color: var(--t-word); }
.badge.t-Excel { background: var(--t-excel-bg); color: var(--t-excel); }
.badge.t-PowerPoint { background: var(--t-ppt-bg); color: var(--t-ppt); }
.badge.t-Imagen { background: var(--t-img-bg); color: var(--t-img); }

.cat-label {
  font-size: 13px;
  white-space: nowrap;
}

/* Tarjetas */

.doc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}

.doc-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.doc-card h3 {
  margin: 0;
  font-size: 16px;
  word-break: break-word;
}

.doc-card .meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.doc-card .desc {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  flex: 1;
}

.doc-card .dates {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 2px;
}

.doc-card .acciones {
  justify-content: flex-start;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 12px;
}

.empty-state h3 {
  color: var(--ink);
  margin: 0 0 6px;
}

.empty-state p {
  margin: 0 0 16px;
}

/* ---------- Diálogos ---------- */

.dialog {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--ink);
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}

.dialog::backdrop {
  background: rgba(10, 14, 18, 0.55);
}

.dialog-wide {
  width: min(1100px, calc(100vw - 32px));
}

.dialog-small {
  width: min(420px, calc(100vw - 32px));
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 1;
}

.dialog-head h2 {
  margin: 0;
  font-size: 18px;
  word-break: break-word;
}

.dialog-body {
  padding: 18px;
}

.dialog-body h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.dialog-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.confirm-nombre {
  font-weight: 600;
  background: var(--surface-2);
  padding: 8px 12px;
  border-radius: 8px;
  word-break: break-word;
}

/* Formulario */

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 14px;
  min-width: 0;
}

.field > span,
.field > label {
  font-weight: 600;
}

.field em {
  color: var(--danger);
  font-style: normal;
}

.full {
  grid-column: 1 / -1;
}

.inline {
  display: flex;
  gap: 8px;
}

.inline select,
.inline input {
  flex: 1;
  min-width: 0;
}

.dropzone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 18px;
  text-align: center;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s ease;
}

.dropzone:hover,
.dropzone.is-over {
  border-color: var(--accent);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
}

.dropzone p {
  margin: 0;
  font-weight: 400;
  word-break: break-all;
}

.dropzone .hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.current-file {
  color: var(--muted);
  font-weight: 400;
}

.form-error {
  margin: 0;
  color: var(--danger);
  background: var(--danger-soft);
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.progress {
  height: 6px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.1s linear;
}

/* Visor */

.visor-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  min-height: 60vh;
}

.visor-preview {
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
  overflow: auto;
}

.visor-preview iframe {
  width: 100%;
  height: 75vh;
  border: none;
  background: #fff;
}

.visor-preview img {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
}

.visor-preview video,
.visor-preview audio {
  max-width: 100%;
}

.visor-preview pre {
  align-self: stretch;
  width: 100%;
  margin: 0;
  padding: 16px;
  max-height: 75vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 13px;
}

.no-preview {
  text-align: center;
  padding: 32px;
  color: var(--muted);
}

.no-preview .big-badge {
  font-size: 20px;
  padding: 10px 18px;
  margin-bottom: 14px;
}

.no-preview p {
  margin: 0 0 6px;
}

.visor-info {
  border-left: 1px solid var(--line);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  font-size: 14px;
}

.visor-info dl {
  margin: 0;
  display: grid;
  gap: 10px;
}

.visor-info dt {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.visor-info dd {
  margin: 2px 0 0;
  word-break: break-word;
}

.visor-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.visor-actions a,
.visor-actions button {
  text-align: center;
  text-decoration: none;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
}

.visor-actions a.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.visor-actions a.btn-ghost {
  color: var(--ink);
}

/* Toast */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--ink);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 100;
  max-width: calc(100vw - 32px);
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

/* ---------- Responsive ---------- */

@media (max-width: 760px) {
  .visor-layout {
    grid-template-columns: 1fr;
  }
  .visor-info {
    border-left: none;
    border-top: 1px solid var(--line);
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .toolbar select,
  .view-toggle {
    flex: 1 1 45%;
  }
  .view-toggle button {
    flex: 1;
  }
}

@media (max-width: 480px) {
  .title-row .btn-primary {
    width: 100%;
  }
}
