/* ============================================================
   RADAR JURÍDICO — Estilos principales
   ============================================================ */

/* === VARIABLES BASE (los colores del despacho se inyectan
       desde base.html después de este archivo) === */
:root {
  --color-primary: #1a1a2e;
  --color-secondary: #ffffff;

  --sidebar-width: 260px;
  --header-height: 64px;

  --color-bg: #f1f5f9;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-light: #94a3b8;

  --color-nueva: #2563eb;
  --color-nueva-bg: #eff6ff;
  --color-revision: #d97706;
  --color-revision-bg: #fffbeb;
  --color-validada: #16a34a;
  --color-validada-bg: #f0fdf4;
  --color-descartada: #6b7280;
  --color-descartada-bg: #f9fafb;

  --color-demo: #92400e;
  --color-demo-bg: #fef3c7;
  --color-demo-border: #fcd34d;

  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .06);
  --shadow: 0 1px 3px rgba(0, 0, 0, .1), 0 1px 2px rgba(0, 0, 0, .06);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07), 0 2px 4px rgba(0, 0, 0, .05);

  --transition: .15s ease;
}

/* === RESET === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
               Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  font-size: .9375rem;
  color: var(--color-text);
  background: var(--color-bg);
  line-height: 1.6;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; border: none; background: none; font: inherit; }
input, button { outline: none; }
ul { list-style: none; }
img { max-width: 100%; display: block; }


/* ============================================================
   LAYOUT
   ============================================================ */

.layout {
  display: flex;
  min-height: 100vh;
}

.layout-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  margin-left: var(--sidebar-width);
  transition: margin-left var(--transition);
}


/* ============================================================
   SIDEBAR
   ============================================================ */

.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--color-primary);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

/* Marca / cabecera del sidebar */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .875rem;
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  min-height: var(--header-height);
}

.brand-logo {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  background: rgba(255, 255, 255, .15);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: -.5px;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-size: .8125rem;
  font-weight: 600;
  color: rgba(255, 255, 255, .9);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.3;
}

.brand-radar {
  font-size: .6875rem;
  color: rgba(255, 255, 255, .45);
  letter-spacing: .04em;
  text-transform: uppercase;
  font-weight: 500;
  margin-top: .1rem;
}

/* Navegación */
.sidebar-nav {
  flex: 1;
  padding: .875rem 0;
}

.nav-section-label {
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: rgba(255, 255, 255, .3);
  padding: .5rem 1.25rem .25rem;
  margin-top: .5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .625rem 1.25rem;
  color: rgba(255, 255, 255, .65);
  font-size: .875rem;
  font-weight: 500;
  border-radius: 0;
  transition: color var(--transition), background var(--transition);
  position: relative;
}

.nav-item:hover {
  color: rgba(255, 255, 255, .95);
  background: rgba(255, 255, 255, .06);
}

.nav-item.active {
  color: #ffffff;
  background: rgba(255, 255, 255, .1);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20%;
  bottom: 20%;
  width: 3px;
  background: rgba(255, 255, 255, .8);
  border-radius: 0 2px 2px 0;
}

.nav-item.disabled {
  opacity: .4;
  pointer-events: none;
}

.nav-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: .8;
}

.nav-soon {
  margin-left: auto;
  font-size: .625rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: rgba(255, 255, 255, .1);
  color: rgba(255, 255, 255, .4);
  padding: .1rem .4rem;
  border-radius: 10px;
}

/* Pie del sidebar */
.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .75rem;
  color: rgba(255, 255, 255, .25);
  text-align: center;
}


/* ============================================================
   HEADER
   ============================================================ */

.header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.75rem;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 1rem;
}

.header-left {
  display: flex;
  align-items: center;
  gap: .875rem;
}

.header-toggle {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: background var(--transition), color var(--transition);
}

.header-toggle:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.header-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
}

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

.header-user {
  display: flex;
  align-items: center;
  gap: .625rem;
  color: var(--color-text-muted);
  font-size: .875rem;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.header-logout-form { margin: 0; }

.btn-logout {
  display: flex;
  align-items: center;
  gap: .375rem;
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
  padding: .375rem .75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border);
  background: var(--color-surface);
  transition: background var(--transition), color var(--transition),
              border-color var(--transition);
}

.btn-logout:hover {
  background: #fef2f2;
  color: #dc2626;
  border-color: #fecaca;
}


/* ============================================================
   CONTENIDO PRINCIPAL
   ============================================================ */

.content {
  flex: 1;
  padding: 1.75rem;
}

.content-header {
  margin-bottom: 1.5rem;
}

.content-header h1 {
  font-size: 1.375rem;
  font-weight: 700;
  color: var(--color-text);
}

.content-header p {
  font-size: .875rem;
  color: var(--color-text-muted);
  margin-top: .25rem;
}


/* ============================================================
   BANNER DE DEMOSTRACIÓN
   ============================================================ */

.demo-banner {
  display: flex;
  align-items: center;
  gap: .75rem;
  background: var(--color-demo-bg);
  border: 1px solid var(--color-demo-border);
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1.5rem;
  font-size: .8125rem;
  color: var(--color-demo);
}

.demo-banner svg { flex-shrink: 0; }

.demo-banner strong { font-weight: 700; }


/* ============================================================
   TARJETAS DE ESTADÍSTICAS
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.75rem;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.375rem;
  display: flex;
  flex-direction: column;
  gap: .875rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition);
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.stat-card-label {
  font-size: .8125rem;
  font-weight: 500;
  color: var(--color-text-muted);
}

.stat-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon.sentencias { background: #eff6ff; color: #2563eb; }
.stat-icon.nuevas     { background: #f0fdf4; color: #16a34a; }
.stat-icon.revision   { background: #fffbeb; color: #d97706; }
.stat-icon.validadas  { background: #f5f3ff; color: #7c3aed; }

.stat-card-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1;
}

.stat-card-sub {
  font-size: .75rem;
  color: var(--color-text-light);
}


/* ============================================================
   TABLA DE OPORTUNIDADES
   ============================================================ */

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.125rem 1.375rem;
  border-bottom: 1px solid var(--color-border);
}

.card-header h2 {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}

.card-header p {
  font-size: .8125rem;
  color: var(--color-text-muted);
  margin-top: .15rem;
}

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

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  font-size: .75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--color-text-muted);
  padding: .75rem 1.375rem;
  text-align: left;
  background: #fafafa;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

tbody tr:last-child { border-bottom: none; }

tbody tr:hover { background: #f8fafc; }

tbody td {
  padding: .9375rem 1.375rem;
  font-size: .875rem;
  vertical-align: middle;
}

.td-titulo {
  font-weight: 500;
  color: var(--color-text);
  max-width: 340px;
}

.td-muted {
  color: var(--color-text-muted);
  white-space: nowrap;
}

/* Badges de estado */
.badge {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: .25rem .625rem;
  border-radius: 20px;
  white-space: nowrap;
}

.badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.badge-nueva {
  background: var(--color-nueva-bg);
  color: var(--color-nueva);
}

.badge-revision {
  background: var(--color-revision-bg);
  color: var(--color-revision);
}

.badge-validada {
  background: var(--color-validada-bg);
  color: var(--color-validada);
}

.badge-descartada {
  background: var(--color-descartada-bg);
  color: var(--color-descartada);
}

/* Tabla vacía */
.table-empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--color-text-muted);
  font-size: .875rem;
}

.table-empty svg {
  margin: 0 auto .75rem;
  opacity: .3;
}


/* ============================================================
   PÁGINA DE LOGIN
   ============================================================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-primary);
  padding: 1.5rem;
  position: relative;
  overflow: hidden;
}

/* Decoración de fondo */
.login-page::before,
.login-page::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, .03);
}

.login-page::before {
  width: 600px;
  height: 600px;
  top: -200px;
  right: -200px;
}

.login-page::after {
  width: 400px;
  height: 400px;
  bottom: -150px;
  left: -100px;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
  padding: 2.5rem 2.25rem;
  width: 100%;
  max-width: 400px;
  position: relative;
  z-index: 1;
}

.login-brand {
  text-align: center;
  margin-bottom: 2rem;
}

.login-brand-logo {
  width: 56px;
  height: 56px;
  background: var(--color-primary);
  border-radius: var(--radius-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto .875rem;
  font-size: 1.5rem;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -.5px;
}

.login-brand h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: .2rem;
}

.login-brand .login-subtitle {
  font-size: .8125rem;
  color: var(--color-text-muted);
}

.login-brand .login-despacho {
  font-size: .875rem;
  font-weight: 600;
  color: var(--color-text);
  margin-top: .1rem;
}

.login-errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: .75rem 1rem;
  margin-bottom: 1.25rem;
  font-size: .8125rem;
  color: #dc2626;
}

.form-group {
  margin-bottom: 1rem;
}

.form-label {
  display: block;
  font-size: .8125rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: .4rem;
}

.form-input {
  width: 100%;
  padding: .6875rem .875rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .9375rem;
  color: var(--color-text);
  background: var(--color-surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  -webkit-appearance: none;
}

.form-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(26, 26, 46, .08);
}

.form-input::placeholder { color: var(--color-text-light); }

.btn-primary {
  width: 100%;
  padding: .75rem 1.25rem;
  background: var(--color-primary);
  color: #ffffff;
  font-size: .9375rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  transition: opacity var(--transition), transform var(--transition);
  margin-top: .5rem;
}

.btn-primary:hover { opacity: .9; }
.btn-primary:active { transform: scale(.99); }

.login-footer {
  text-align: center;
  margin-top: 1.5rem;
  font-size: .75rem;
  color: var(--color-text-light);
}


/* ============================================================
   MOBILE OVERLAY (fondo oscuro cuando el sidebar está abierto)
   ============================================================ */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .4);
  z-index: 90;
}

.sidebar-overlay.active { display: block; }


/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1024px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

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

  .sidebar.open {
    transform: translateX(0);
  }

  .layout-main {
    margin-left: 0;
  }

  .header-toggle {
    display: flex;
  }

  .header-user-name {
    display: none;
  }

  .content {
    padding: 1.25rem 1rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: .75rem;
  }

  .stat-card-value { font-size: 1.625rem; }

  thead th:nth-child(3),
  tbody td:nth-child(3),
  thead th:nth-child(4),
  tbody td:nth-child(4) {
    display: none;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .login-card {
    padding: 2rem 1.5rem;
  }
}


/* ============================================================
   ENLACES EN TABLAS
   ============================================================ */

.td-link {
  color: var(--color-text);
  text-decoration: none;
  font-weight: 500;
}

.td-link:hover {
  color: var(--color-primary);
  text-decoration: underline;
}


/* ============================================================
   BOTÓN SECUNDARIO (enlaces externos, volver, acciones)
   ============================================================ */

.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: .375rem;
  padding: .4rem .875rem;
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  color: var(--color-text);
  text-decoration: none;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  cursor: pointer;
  white-space: nowrap;
}

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

.page-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
}


/* ============================================================
   PÁGINAS DE DETALLE (ficha de sentencia / oportunidad)
   ============================================================ */

.detail-card + .detail-card {
  margin-top: 1.25rem;
}

/* ── Rejilla de metadatos (tribunal, fecha, materia…) ─────── */

.detail-meta-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 1.5rem;
  gap: 1.75rem 2rem;
}

.detail-meta-item {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.detail-meta-label {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-light);
  line-height: 1;
}

.detail-meta-value {
  font-size: 1rem;
  font-weight: 600;
  color: var(--color-text);
  line-height: 1.4;
}

.detail-meta-value--empty {
  font-size: .9375rem;
  font-weight: 400;
  color: var(--color-text-light);
  font-style: italic;
}

/* ── Lista de accesos a documentos (vertical) ─────────────── */

.detail-doc-list {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1.5rem;
}

/* Cuando sigue a la rejilla, añadir separador */
.detail-meta-grid + .detail-doc-list {
  border-top: 1px solid var(--color-border);
}

.detail-doc-item-label {
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-light);
  margin-bottom: .5rem;
}

.detail-doc-unavailable {
  font-size: .875rem;
  color: var(--color-text-light);
  font-style: italic;
}

/* ── Barra de acciones al pie de una tarjeta ──────────────── */

.detail-doc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .625rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border);
  background: var(--color-bg);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Campos apilados (descripción, fundamento, alcance…) ───── */

.detail-body {
  padding: 0 1.5rem;   /* horizontal: 24 px; vertical aportado por detail-field */
}

/* Cuando sigue a otros bloques, añadir separador */
.detail-meta-grid + .detail-body,
.detail-doc-list   + .detail-body {
  border-top: 1px solid var(--color-border);
}

.detail-field {
  padding: 1.5rem 0;   /* 24 px arriba y abajo de cada campo */
  border-bottom: 1px solid var(--color-border);
}

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

.detail-field-label {
  display: block;
  font-size: .6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--color-text-light);
  margin-bottom: .5rem;   /* 8 px entre etiqueta y valor */
}

.detail-field-value {
  font-size: .9375rem;
  color: var(--color-text);
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.detail-field-value--empty {
  font-size: .9375rem;
  color: var(--color-text-light);
  font-style: italic;
}

/* Campo destacado (afectados, qué se puede reclamar, contra quién) */
.detail-field--highlight {
  background: var(--color-bg);
  margin: 0 -1.5rem;         /* sangría hasta el borde de la tarjeta */
  padding: 1.5rem 1.5rem;    /* 24 px en los cuatro lados */
  border-bottom: 1px solid var(--color-border);
}

.detail-field--highlight .detail-field-label {
  color: var(--color-text-muted);
}

/* ── Bloque de resumen ────────────────────────────────────── */

.detail-resumen {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-primary);
  border-radius: var(--radius);
  padding: 1.125rem 1.25rem;
  color: var(--color-text);
  font-size: .9375rem;
  line-height: 1.8;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Texto completo ───────────────────────────────────────── */

.detail-texto {
  color: var(--color-text);
  font-size: .9375rem;
  line-height: 1.85;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── Lista de fuentes para afectados ─────────────────────────── */

.fuente-list {
  display: flex;
  flex-direction: column;
}

.fuente-list + .detail-body {
  border-top: 1px solid var(--color-border);
}

.fuente-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.125rem 1.5rem;
  border-bottom: 1px solid var(--color-border);
}

.fuente-item:last-child {
  border-bottom: none;
}

.fuente-info {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  min-width: 0;
}

.fuente-nombre {
  font-size: .9375rem;
  font-weight: 600;
  color: var(--color-text);
}

.fuente-tipo {
  display: inline-block;
  font-size: .6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--color-text-muted);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 20px;
  padding: .1rem .5rem;
  align-self: flex-start;
}

.fuente-utilidad {
  font-size: .875rem;
  color: var(--color-text-muted);
  line-height: 1.55;
  margin-top: .2rem;
}

.fuente-actions {
  flex-shrink: 0;
  padding-top: .125rem;
}

/* ── Responsive ───────────────────────────────────────────── */

@media (max-width: 768px) {
  .detail-meta-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 600px) {
  .detail-meta-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    padding: 1.25rem 1rem;
  }

  .detail-body { padding: 0 1rem; }

  .detail-field--highlight {
    margin: 0 -1rem;
    padding: 1.375rem 1rem;
  }

  .detail-doc-list { padding: 1.25rem 1rem; }
  .detail-doc-actions { padding: 1rem; }
}
