/* ── Design tokens ─────────────────────────────────────────── */
/* Dirección "La Plantilla y el Documento": el producto convierte plantillas ODT
   con {{markers}} en informes de riesgos. Paleta de papel técnico + naranja señal
   + amarillo seguridad (señalética PRL), lejos del cream+terracota genérico. */
:root {
  --paper: #eef0f2;
  --ink: #161b22;
  --ink-soft: #5a6470;
  --signal: #e8590c;
  --hazard: #f0b429;
  --panel: #ffffff;
  --line: rgba(22, 27, 34, 0.1);
  --line-strong: rgba(22, 27, 34, 0.18);
  --shadow: 0 1px 2px rgba(22, 27, 34, 0.04), 0 8px 24px rgba(22, 27, 34, 0.06);

  /* Sidebar */
  --sidebar-width: 260px;
  --sidebar-collapsed-width: 72px;
  --sidebar-bg: #161b22;
  --sidebar-text: rgba(255, 255, 255, 0.72);
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: rgba(255, 255, 255, 0.08);
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);
  --sidebar-brand-height: 84px;
  --sidebar-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);

  /* Typography */
  --font-display: 'Space Grotesk Variable', 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'IBM Plex Sans Variable', 'IBM Plex Sans', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono Variable', 'IBM Plex Mono', ui-monospace, monospace;
}

/* ── Base ─────────────────────────────────────────────────── */
html {
  font-size: 15px;
  min-height: 100%;
}

@media (min-width: 768px) {
  html { font-size: 16px; }
}

body {
  min-height: 100vh;
  display: flex;
  color: var(--ink);
  font-family: var(--font-body);
  background:
    radial-gradient(circle at top right, rgba(232, 89, 12, 0.05), transparent 30%),
    var(--paper);
}

h1, h2, h3, h4, h5, h6,
.display-1, .display-2, .display-3, .display-4, .display-5, .display-6 {
  font-family: var(--font-display);
  color: var(--ink);
  letter-spacing: -0.01em;
}

code, kbd, pre, .font-mono {
  font-family: var(--font-mono);
}

/* ── Firma: sello de marker ───────────────────────────────── */
/* El ADN del producto: {{prefix.markerKey}}. Chip monoespaciado de contorno
   discontinuo que aparece en el chrome de la UI (marca, cabeceras, vacíos). */
.marker-stamp {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--signal);
  border: 1px dashed currentColor;
  border-radius: 4px;
  padding: 0.12rem 0.45rem;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  line-height: 1.4;
}

/* Firma: franja de peligro (amarillo/negro). Un solo uso, muy contenido. */
.hazard-stripe {
  height: 6px;
  background: repeating-linear-gradient(
    -45deg,
    var(--hazard) 0 10px,
    var(--ink) 10px 20px
  );
}

/* ── Cabecera de documento ─────────────────────────────────── */
.doc-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.eyebrow {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--ink-soft);
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform var(--sidebar-transition);
  overflow: hidden;
}

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
}

/* Brand: la marca como plantilla — logo + título + sello {{eval.informe}} */
.sidebar-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
  text-decoration: none;
  position: relative;
}

.sidebar-logo {
  height: 26px;
  width: auto;
  max-width: 100%;
  flex-shrink: 0;
  border-radius: 4px;
}

.sidebar-brand-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 0.85rem;
  line-height: 1.2;
  color: #fff;
  text-align: center;
  white-space: nowrap;
}

.sidebar-brand .marker-stamp {
  color: var(--hazard);
  border-color: rgba(240, 180, 41, 0.45);
  font-size: 0.66rem;
}

/* Nav */
.sidebar-nav {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 0.75rem 0;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.25rem;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 450;
  transition: background 0.2s ease, color 0.2s ease;
  border-left: 3px solid transparent;
}

.sidebar-link:hover {
  background: var(--sidebar-hover-bg);
  color: var(--sidebar-text-active);
}

.sidebar-link.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  border-left-color: var(--signal);
  font-weight: 600;
}

.sidebar-link i {
  font-size: 1.15rem;
  width: 1.25rem;
  text-align: center;
  flex-shrink: 0;
}

/* User zone */
.sidebar-user {
  flex-shrink: 0;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: rgba(255, 255, 255, 0.65);
}

.sidebar-user-info i { font-size: 1.35rem; }

.sidebar-logout-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.55);
  font-size: 0.85rem;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  transition: color 0.2s ease;
}

.sidebar-logout-btn:hover { color: rgba(255, 255, 255, 0.9); }

/* ── Sidebar overlay (mobile) ─────────────────────────────── */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1035;
  transition: opacity 0.3s ease;
}

#sidebar-overlay.show { display: block; }

/* ── Main wrapper ─────────────────────────────────────────── */
.main-wrapper {
  flex: 1 1 auto;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--sidebar-transition);
}

@media (max-width: 991.98px) {
  .main-wrapper { margin-left: 0; }
}

/* ── Mobile topbar ────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}

.topbar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
}

#sidebar-toggle {
  background: none;
  border: none;
  color: var(--ink);
  padding: 0.25rem 0.5rem;
  border-radius: 0.375rem;
  cursor: pointer;
}

#sidebar-toggle:hover {
  background: rgba(232, 89, 12, 0.08);
}

/* ── Content area: hoja de documento ───────────────────────── */
.content-area {
  flex: 1 1 auto;
  padding: 1.5rem;
}

@media (min-width: 992px) {
  .content-area { padding: 2rem 2.5rem; }
}

/* ── Footer ───────────────────────────────────────────────── */
.footer {
  border-top: 1px solid var(--line);
  padding: 1.25rem 1.5rem;
  flex-shrink: 0;
}

@media (min-width: 992px) {
  .footer { padding: 1.25rem 2.5rem; }
}

/* ── Focus styles ─────────────────────────────────────────── */
.btn:focus,
.btn:active:focus,
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
  box-shadow: 0 0 0 0.2rem rgba(232, 89, 12, 0.15);
  border-color: rgba(232, 89, 12, 0.4);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background-color: var(--signal);
  border-color: var(--signal);
  color: #fff;
}

.btn-primary:hover {
  background-color: #c94a08;
  border-color: #c94a08;
  color: #fff;
}

.btn-outline-dark {
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-outline-dark:hover {
  background-color: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

/* ── Paneles de papel ─────────────────────────────────────── */
.hero-panel,
.glass-card,
.table-card,
.form-shell {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  transition: box-shadow 0.25s ease, transform 0.25s ease;
}

.glass-card:hover,
.table-card:hover {
  box-shadow: 0 12px 32px rgba(22, 27, 34, 0.1);
  transform: translateY(-1px);
}

.glass-card,
.table-card,
.form-shell {
  border-radius: 0.9rem;
}

.table-card { overflow: hidden; }
.table-card .table { margin-bottom: 0; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.form-shell {
  padding: 2rem;
  overflow: hidden;
}

/* ── Home: hoja de plantilla ──────────────────────────────── */
.template-sheet {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.9rem;
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.template-sheet-inner {
  padding: 2.5rem;
}

@media (max-width: 575.98px) {
  .template-sheet-inner { padding: 1.5rem; }
}

.template-sheet h1 {
  font-size: clamp(1.6rem, 3.2vw, 2.4rem);
  font-weight: 600;
  margin-bottom: 0.75rem;
}

.template-sheet .lead {
  color: var(--ink-soft);
  max-width: 46rem;
}

/* Pipeline de markers: el flujo del producto como sellos */
.pipeline {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin: 1.5rem 0;
}

.pipeline-arrow {
  color: var(--ink-soft);
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ── Entrance animation ──────────────────────────────────── */
@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.content-area > * {
  animation: fadeSlideUp 0.35s ease-out both;
}

@media (prefers-reduced-motion: reduce) {
  .content-area > * {
    animation: none;
  }
}

/* ── Utility overrides ────────────────────────────────────── */
.text-secondary {
  color: var(--ink-soft) !important;
}

/* ── Prompt preview truncation ────────────────────────────── */
.prompt-preview {
  max-width: 360px;
}

/* ── Collapsible sidebar (desktop) ──────────────────────── */
.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
}

.sidebar.collapsed .sidebar-brand-title,
.sidebar.collapsed .sidebar-brand .marker-stamp,
.sidebar.collapsed .sidebar-link span,
.sidebar.collapsed .sidebar-user-info span {
  display: none;
}

.sidebar.collapsed .sidebar-brand {
  justify-content: center;
  padding: 0;
}

.sidebar.collapsed .sidebar-logo {
  height: 26px;
}

.sidebar.collapsed .sidebar-link {
  justify-content: center;
  padding: 0.6rem 0;
  border-left-color: transparent;
}

.sidebar.collapsed .sidebar-link.active {
  border-left-color: transparent;
  border-right: 3px solid var(--signal);
}

.sidebar.collapsed .sidebar-user {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.sidebar.collapsed .sidebar-user-info {
  margin-bottom: 0;
}

.sidebar.collapsed .sidebar-logout-btn span {
  display: none;
}

.main-wrapper.sidebar-collapsed {
  margin-left: var(--sidebar-collapsed-width);
}

/* Collapse toggle button (desktop only) */
#sidebar-collapse-toggle {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  padding: 0.5rem 1.25rem;
  cursor: pointer;
  font-size: 1rem;
  transition: color 0.2s ease;
  display: none;
}

@media (min-width: 992px) {
  #sidebar-collapse-toggle { display: block; }
}

#sidebar-collapse-toggle:hover {
  color: rgba(255, 255, 255, 0.9);
}

/* ── Pre scrollable ──────────────────────────────────────── */
.pre-scrollable {
  max-height: 480px;
  max-width: 100%;
  overflow: auto;
}

/* Prevent long content from expanding the layout */
.row > [class*="col-"] {
  min-width: 0;
}

pre {
  max-width: 100%;
  overflow-x: auto;
  word-break: break-word;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Code elements inside tables should not break layout */
code {
  word-break: break-all;
  overflow-wrap: break-word;
}

textarea.form-control,
input[type="text"].form-control,
input[type="url"].form-control {
  max-width: 100%;
}

/* ── Section collapse toggle ─────────────────────────────── */
.section-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: none;
  padding: 0;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.section-toggle i {
  transition: transform 0.25s ease;
}

.section-toggle[aria-expanded="false"] i {
  transform: rotate(-90deg);
}

/* ── Form loading state ──────────────────────────────────── */
form.loading button[type="submit"] {
  pointer-events: none;
  opacity: 0.7;
}

form.loading button[type="submit"]::after {
  content: '';
  display: inline-block;
  width: 0.85rem;
  height: 0.85rem;
  margin-left: 0.5rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

form.loading button[type="submit"].btn-outline-dark::after {
  border-color: rgba(0, 0, 0, 0.15);
  border-top-color: var(--ink);
}

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

/* ── Severity badges ─────────────────────────────────────── */
.badge-severity-error {
  background: #dc3545;
  color: #fff;
}

.badge-severity-warning {
  background: #ffc107;
  color: #212529;
}

/* ── Print ────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, #sidebar-overlay, #sidebar-collapse-toggle { display: none; }
  .main-wrapper { margin-left: 0; }
}
