/* ============================================================
   Inventario CECYTEM — hoja de estilos compartida
   Sistema funcional utilitario (nivel "sobrio").
   Paleta sistematizada desde los estilos previos de las plantillas:
   acento violeta #7c3aed/#8b5cf6, neutrales gris-frío, tema claro/oscuro.
   Sin dependencias externas (CSP: style-src 'self' 'unsafe-inline').
   ============================================================ */

/* ---------- 1. Tokens ---------- */
:root {
  /* Color */
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-soft: rgba(124, 58, 237, 0.12);
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #10b981;
  --error: #ef4444;
  --warn: #b45309;
  --warn-bg: #fef3c7;

  --bg-body: linear-gradient(160deg, #eef1f6 0%, #d8dfea 100%);
  --bg-body-solid: #e6eaf1;
  --surface: #ffffff;
  --surface-alt: #f9fafb;
  --text: #1f2937;
  --text-soft: #4b5563;
  --border: #d1d5db;

  --nav-bg: #1f2937;
  --nav-text: #e5e7eb;
  --table-head-bg: #1f2937;
  --table-head-text: #f9fafb;

  --input-bg: #f9fafb;
  --input-text: #1f2937;
  --input-border: #d1d5db;
  --focus-ring: rgba(124, 58, 237, 0.35);

  /* Forma */
  --r-sm: 0.375rem;
  --r-md: 0.625rem;
  --r-lg: 0.875rem;
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.12);
  --shadow-md: 0 6px 18px rgba(15, 23, 42, 0.14);

  /* Espaciado */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;

  /* Tipografía: pila de sistema (CSP font-src 'self'; sin fuentes externas) */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, "Noto Sans", sans-serif;
}

[data-theme="dark"] {
  --accent: #8b5cf6;
  --accent-hover: #7c3aed;
  --accent-soft: rgba(139, 92, 246, 0.18);
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warn: #fbbf24;
  --warn-bg: rgba(180, 83, 9, 0.25);

  --bg-body: linear-gradient(160deg, #111827 0%, #1f2937 100%);
  --bg-body-solid: #111827;
  --surface: #1f2937;
  --surface-alt: #273244;
  --text: #e5e7eb;
  --text-soft: #9ca3af;
  --border: #4b5563;

  --nav-bg: #111827;
  --nav-text: #d1d5db;
  --table-head-bg: #111827;
  --table-head-text: #e5e7eb;

  --input-bg: #374151;
  --input-text: #e5e7eb;
  --input-border: #4b5563;
  --focus-ring: rgba(139, 92, 246, 0.45);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
}

/* ---------- 2. Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-body-solid);
  background-image: var(--bg-body);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 0.9375rem;
  line-height: 1.5;
}

h1,
h2,
h3 {
  line-height: 1.25;
  margin: 0 0 var(--sp-4);
}

h2 {
  font-size: 1.125rem;
}

h3 {
  font-size: 1rem;
}

p {
  margin: 0 0 var(--sp-4);
}

img {
  max-width: 100%;
  height: auto;
}

a {
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
  vertical-align: -0.25em;
}

/* ---------- 3. Navegación ---------- */
.navbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  background-color: var(--nav-bg);
  color: var(--nav-text);
  box-shadow: var(--shadow-sm);
}

.navbar-inner {
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--sp-2) var(--sp-4);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-2);
}

.navbar-brand {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0;
  color: #ffffff;
  margin-right: auto;
}

.nav-burger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--nav-text);
  cursor: pointer;
}

.nav-burger:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.nav-burger .icon {
  width: 1.5rem;
  height: 1.5rem;
}

.nav-burger .icon-close,
.navbar.open .nav-burger .icon-menu {
  display: none;
}

.navbar.open .nav-burger .icon-close {
  display: block;
}

.nav-links {
  display: none;
  flex-direction: column;
  width: 100%;
  order: 4;
  padding-bottom: var(--sp-2);
  gap: var(--sp-1);
}

/* Variante sin menú colapsable (páginas de acceso: pocos enlaces) */
.nav-links-inline {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--sp-1);
  margin-left: auto;
}

.nav-links-inline a {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.65rem var(--sp-3);
  min-height: 44px;
  border-radius: var(--r-sm);
  color: var(--nav-text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-links-inline a:hover {
  background-color: var(--accent);
  color: #ffffff;
}

.navbar.open .nav-links {
  display: flex;
}

.nav-links a,
.nav-user {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0.65rem var(--sp-3);
  min-height: 44px;
  border-radius: var(--r-sm);
  color: var(--nav-text);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
}

.nav-links a:hover {
  background-color: var(--accent);
  color: #ffffff;
}

.nav-user {
  color: #9ca3af;
  font-weight: 400;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--nav-text);
  cursor: pointer;
}

.theme-toggle:hover {
  background-color: rgba(255, 255, 255, 0.08);
}

.theme-toggle .icon {
  width: 1.35rem;
  height: 1.35rem;
}

/* Sol visible en tema oscuro (acción: cambiar a claro) y viceversa */
.theme-toggle .icon-sun {
  display: none;
}

[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

@media (min-width: 48rem) {
  .nav-burger {
    display: none;
  }

  .navbar-brand {
    margin-right: 0;
  }

  .nav-links {
    display: flex;
    flex-direction: row;
    align-items: center;
    width: auto;
    order: 0;
    padding-bottom: 0;
    margin-left: auto;
    flex-wrap: wrap;
  }

  .nav-links a,
  .nav-user {
    min-height: 40px;
    padding: var(--sp-2) var(--sp-3);
  }
}

/* ---------- 4. Layout de página ---------- */
.page {
  flex: 1;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
  padding: var(--sp-4);
}

.page-logo {
  display: block;
  margin: var(--sp-4) auto var(--sp-5);
  width: min(200px, 55vw);
  height: auto;
}

.section {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  padding: var(--sp-4);
  margin-bottom: var(--sp-5);
}

.section > h2:first-child {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}

@media (min-width: 48rem) {
  .page {
    padding: var(--sp-5) var(--sp-6);
  }

  .section {
    padding: var(--sp-5);
  }
}

/* ---------- 5. Layout auth (cajas centradas) ---------- */
.auth-main {
  flex: 1;
  display: grid;
  place-items: center;
  padding: var(--sp-4);
}

.auth-card {
  width: 100%;
  max-width: 26rem;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--accent);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  padding: var(--sp-6) var(--sp-5);
  text-align: center;
}

.auth-card .page-logo {
  margin-top: 0;
  width: min(170px, 50vw);
}

.auth-card h1 {
  font-size: 1.35rem;
  margin-bottom: var(--sp-5);
}

.auth-link {
  display: inline-block;
  margin-top: var(--sp-4);
  color: var(--accent);
  font-weight: 600;
  text-decoration: none;
}

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

.error-code {
  font-size: 4.5rem;
  font-weight: 700;
  line-height: 1;
  color: var(--accent);
  margin-bottom: var(--sp-3);
}

/* ---------- 6. Formularios ---------- */
.input-field {
  display: block;
  width: 100%;
  padding: 0.65rem var(--sp-3);
  font-family: inherit;
  font-size: 1rem;
  color: var(--input-text);
  background-color: var(--input-bg);
  border: 1px solid var(--input-border);
  border-radius: var(--r-sm);
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
}

select.input-field {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 55%, calc(100% - 0.8rem) 55%;
  background-size: 0.35rem 0.35rem;
  background-repeat: no-repeat;
  padding-right: 2.25rem;
}

textarea.input-field {
  min-height: 6rem;
  resize: vertical;
}

.field {
  margin-bottom: var(--sp-4);
  text-align: left;
}

.field > label {
  display: block;
  margin-bottom: var(--sp-1);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-soft);
}

.radio-group {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-4);
}

.radio-option {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 44px;
  cursor: pointer;
  font-weight: 400;
  color: var(--text);
}

.radio-option input {
  accent-color: var(--accent);
  width: 1.1rem;
  height: 1.1rem;
}

/* Nota aclaratoria bajo campos o botones (p.ej. registro de administrador,
   descarga del manual): texto secundario, hereda tokens de tema claro/oscuro. */
.field-hint {
  margin: var(--sp-2) 0 var(--sp-3);
  font-size: 0.8rem;
  line-height: 1.5;
  color: var(--text-soft);
  text-align: left;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-3);
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

@media (min-width: 40rem) {
  .form-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    flex-direction: row;
  }

  .form-row .input-field {
    flex: 1;
    min-width: 0;
  }

  .form-row .btn {
    flex: none;
  }
}

/* ---------- 7. Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.55rem 1rem;
  min-height: 44px;
  font-family: inherit;
  font-size: 0.925rem;
  font-weight: 600;
  color: #ffffff;
  background-color: var(--accent);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.btn:hover {
  background-color: var(--accent-hover);
  color: #ffffff;
}

.btn:active {
  transform: translateY(1px);
}

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

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

.btn-block {
  display: flex;
  width: 100%;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2) var(--sp-3);
}

/* ---------- 8. Mensajes flash ---------- */
.mensaje {
  display: block;
  padding: var(--sp-3) var(--sp-4);
  margin-bottom: var(--sp-4);
  border-radius: var(--r-sm);
  color: #ffffff;
  font-size: 0.925rem;
  font-weight: 600;
}

.mensaje.success {
  background-color: var(--success);
}

.mensaje.error {
  background-color: var(--error);
}

/* ---------- 9. Tablas ---------- */
.table-wrap {
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th {
  background-color: var(--table-head-bg);
  color: var(--table-head-text);
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: var(--sp-3);
  white-space: nowrap;
}

td {
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:nth-child(even) {
  background-color: var(--surface-alt);
}

.warn-row td {
  background-color: var(--warn-bg);
}

/* Edición inline dentro de la celda de acciones */
.row-edit {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}

.row-edit .input-field {
  padding: 0.45rem var(--sp-2);
  font-size: 0.875rem;
}

.row-edit .btn {
  min-height: 40px;
  font-size: 0.85rem;
}

.row-delete {
  display: inline-block;
}

/* Móvil: tabla apilada como tarjetas (usa data-label en cada td) */
@media (max-width: 47.98rem) {
  .table-stack table,
  .table-stack tbody,
  .table-stack tr,
  .table-stack td {
    display: block;
    width: 100%;
  }

  .table-stack thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .table-stack tr {
    padding: var(--sp-3) var(--sp-4);
    border-top: 1px solid var(--border);
  }

  .table-stack tr:first-child {
    border-top: none;
  }

  .table-stack td {
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: var(--sp-1) 0;
    border: none;
    text-align: right;
  }

  .table-stack td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-soft);
    text-align: left;
  }

  .table-stack td.td-actions {
    display: block;
    text-align: left;
    padding-top: var(--sp-3);
  }

  .table-stack td.td-actions::before {
    display: block;
    margin-bottom: var(--sp-2);
  }
}

/* ---------- 10. Modal ---------- */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1100;
  background-color: rgba(0, 0, 0, 0.55);
  padding: var(--sp-4);
  overflow-y: auto;
}

.modal.is-open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

.modal-content {
  width: 100%;
  max-width: 30rem;
  margin: 10vh auto;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  padding: var(--sp-5);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}

.modal-head h2 {
  margin: 0;
}

.modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  background: none;
  border: none;
  border-radius: var(--r-sm);
  color: var(--text-soft);
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  background-color: var(--surface-alt);
}

/* ---------- 11. Piezas sueltas ---------- */
.queja-item {
  background-color: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: var(--sp-4);
  margin-bottom: var(--sp-3);
}

.queja-item p {
  margin: 0 0 var(--sp-1);
}

.help-list {
  margin: 0 0 var(--sp-4);
  padding-left: 1.25rem;
}

.help-list li {
  margin-bottom: var(--sp-1);
}

.text-soft {
  color: var(--text-soft);
}

.mt-4 {
  margin-top: var(--sp-4);
}

.mb-0 {
  margin-bottom: 0;
}

/* ---------- 12. Accesibilidad / movimiento ---------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
