/* ============================================================
   style.css – Diseño editorial académico · Tema oscuro cálido
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@700;800&family=DM+Sans:wght@300;400;500;600&family=DM+Mono:wght@400;500&display=swap');

/* ── Variables ──────────────────────────────────────────────── */
:root {
  --bg:           #0f1117;
  --bg2:          #161922;
  --bg3:          #1e2230;
  --border:       #2a2f3e;
  --border-light: #363c50;
  --text:         #e8ecf4;
  --text-muted:   #8892a8;
  --text-dim:     #5c6478;
  --accent:       #f5a623;
  --accent2:      #e8854a;
  --accent-glow:  rgba(245,166,35,0.15);
  --success:      #4caf7d;
  --danger:       #e05c5c;
  --info:         #5b9cf6;
  --radius:       10px;
  --radius-lg:    16px;
  --shadow:       0 4px 24px rgba(0,0,0,0.4);
  --transition:   0.22s cubic-bezier(0.4,0,0.2,1);
  --font-display: 'Playfair Display', Georgia, serif;
  --font-body:    'DM Sans', sans-serif;
  --font-mono:    'DM Mono', monospace;
}

/* ── Reset & base ────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout principal ───────────────────────────────────────── */
.app-wrapper {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* ── Header ─────────────────────────────────────────────────── */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 2rem 0 1.5rem;
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-wrap: wrap;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.brand-icon {
  width: 48px;
  height: 48px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  box-shadow: 0 0 20px var(--accent-glow);
}

.brand-text h1 {
  font-family: var(--font-display);
  font-size: 1.65rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
  background: linear-gradient(135deg, var(--text) 60%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.brand-text span {
  font-size: 0.8rem;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.btn-nuevo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.7rem 1.4rem;
  background: var(--accent);
  color: #0f1117;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 16px rgba(245,166,35,0.3);
  white-space: nowrap;
}

.btn-nuevo:hover {
  background: #fdb93a;
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(245,166,35,0.4);
}

/* ── Barra de búsqueda y filtros ─────────────────────────────── */
.toolbar {
  display: flex;
  gap: 0.75rem;
  margin: 1.5rem 0 1.25rem;
  flex-wrap: wrap;
  align-items: center;
}

.search-wrap {
  position: relative;
  flex: 1;
  min-width: 220px;
}

.search-icon {
  position: absolute;
  left: 0.9rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-dim);
  font-size: 1rem;
  pointer-events: none;
}

.input-search {
  width: 100%;
  padding: 0.7rem 1rem 0.7rem 2.5rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: var(--transition);
  outline: none;
}

.input-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg3);
}

.input-search::placeholder { color: var(--text-dim); }

.select-campo {
  padding: 0.7rem 1rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  cursor: pointer;
  outline: none;
  transition: var(--transition);
  min-width: 170px;
}

.select-campo:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.select-campo option { background: var(--bg2); }

.btn-limpiar {
  padding: 0.7rem 1rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}

.btn-limpiar:hover {
  border-color: var(--border-light);
  color: var(--text);
  background: var(--bg2);
}

/* ── Stats bar ───────────────────────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}

.stat-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.3rem 0.9rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-badge strong {
  color: var(--accent);
  font-weight: 600;
}

/* ── Tabla ───────────────────────────────────────────────────── */
.table-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

thead tr {
  background: var(--bg3);
  border-bottom: 2px solid var(--border);
}

thead th {
  padding: 0.9rem 1rem;
  text-align: left;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: var(--transition);
}

thead th:hover { color: var(--accent); }

thead th .sort-arrow {
  display: inline-block;
  margin-left: 0.3rem;
  opacity: 0.4;
  transition: var(--transition);
}

thead th.sorted .sort-arrow { opacity: 1; color: var(--accent); }

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
  animation: rowIn 0.3s ease both;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }

@keyframes rowIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

td {
  padding: 0.85rem 1rem;
  vertical-align: top;
  color: var(--text);
  max-width: 240px;
}

.td-titulo {
  font-weight: 600;
  color: var(--text);
  min-width: 160px;
}

.td-academia {
  font-size: 0.82rem;
  color: var(--info);
  min-width: 130px;
}

.td-modulo {
  font-size: 0.82rem;
  color: var(--text-muted);
  min-width: 130px;
}

.cell-truncate {
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

.cell-truncate:hover {
  white-space: normal;
  overflow: visible;
  position: relative;
  z-index: 2;
  background: var(--bg3);
  box-shadow: var(--shadow);
  border-radius: 6px;
  padding: 0.25rem 0.5rem;
  margin: -0.25rem -0.5rem;
}

.date-chip {
  display: inline-block;
  background: rgba(91,156,246,0.12);
  color: var(--info);
  border: 1px solid rgba(91,156,246,0.25);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.78rem;
  font-family: var(--font-mono);
  white-space: nowrap;
}

.actions-cell {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  white-space: nowrap;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  transition: var(--transition);
  text-decoration: none;
}

.btn-edit {
  background: rgba(245,166,35,0.12);
  color: var(--accent);
  border: 1px solid rgba(245,166,35,0.2);
}

.btn-edit:hover {
  background: var(--accent);
  color: #0f1117;
}

.btn-view {
  background: rgba(91,156,246,0.1);
  color: var(--info);
  border: 1px solid rgba(91,156,246,0.2);
}

.btn-view:hover {
  background: var(--info);
  color: #0f1117;
}

.btn-delete {
  background: rgba(224,92,92,0.1);
  color: var(--danger);
  border: 1px solid rgba(224,92,92,0.2);
}

.btn-delete:hover {
  background: var(--danger);
  color: #fff;
}

/* ── Empty state ─────────────────────────────────────────────── */
.empty-state {
  padding: 4rem 2rem;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; }

.empty-state p {
  font-size: 1rem;
  color: var(--text-muted);
}

.empty-state small {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ── Modal ───────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s, visibility 0.25s;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 680px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
  transform: scale(0.95) translateY(20px);
  transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1);
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
}

.modal-header h2 span {
  color: var(--accent);
}

.btn-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-close:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}

/* ── Formulario ─────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-group.span-full { grid-column: 1 / -1; }

label {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

label .req { color: var(--accent); margin-left: 2px; }

.form-input,
.form-textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  transition: var(--transition);
  outline: none;
  width: 100%;
}

.form-input:focus,
.form-textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: var(--bg3);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-dim); }

.form-textarea {
  resize: vertical;
  min-height: 80px;
  line-height: 1.5;
  font-family: var(--font-mono);
  font-size: 0.82rem;
}

.field-hint {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.15rem;
}

/* ── Botones principales ─────────────────────────────────────── */
.btn {
  padding: 0.65rem 1.25rem;
  border-radius: var(--radius);
  border: none;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.btn-primary {
  background: var(--accent);
  color: #0f1117;
  box-shadow: 0 4px 14px rgba(245,166,35,0.3);
}

.btn-primary:hover {
  background: #fdb93a;
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg3);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text);
}

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

.btn-danger:hover {
  background: #c94848;
}

/* ── Modal detalle (vista) ───────────────────────────────────── */
.detail-grid {
  display: grid;
  gap: 1rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.detail-row:last-child { border-bottom: none; }

.detail-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  padding-top: 0.1rem;
}

.detail-value {
  font-size: 0.875rem;
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-value.links a {
  display: block;
  color: var(--accent);
  font-size: 0.82rem;
}

/* ── Toast ───────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toastIn 0.3s ease both;
  pointer-events: all;
  max-width: 340px;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px) scale(0.95); }
  to   { opacity: 1; transform: none; }
}

.toast-ok    { background: #1a2f22; border: 1px solid var(--success); color: var(--success); }
.toast-error { background: #2e1a1a; border: 1px solid var(--danger);  color: var(--danger); }
.toast-info  { background: #1a2235; border: 1px solid var(--info);    color: var(--info); }

/* ── Loader ──────────────────────────────────────────────────── */
.loader {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

.loading-row td {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

/* ── Modal confirmar ─────────────────────────────────────────── */
.confirm-body {
  padding: 1.5rem;
  text-align: center;
}

.confirm-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

.confirm-body p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.confirm-body strong {
  color: var(--text);
  display: block;
  margin-top: 0.4rem;
}

/* ── Paginación ─────────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.4rem;
  padding: 1rem 1rem 0;
  flex-wrap: wrap;
}

.pag-btn {
  min-width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg2);
  color: var(--text-muted);
  font-size: 0.82rem;
  cursor: pointer;
  transition: var(--transition);
}

.pag-btn:hover { border-color: var(--accent); color: var(--accent); }
.pag-btn.active { background: var(--accent); color: #0f1117; border-color: var(--accent); font-weight: 700; }
.pag-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 700px) {
  .form-grid { grid-template-columns: 1fr; }
  .detail-row { grid-template-columns: 1fr; gap: 0.25rem; }
  .app-header { flex-direction: column; align-items: flex-start; }
  td { max-width: 120px; }
  .btn-nuevo span { display: none; }
}
