@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* =========================================
     PALETA INSTITUCIONAL PREMIUM
     ========================================= */
  --brand-primary: #1B4F8A;    /* Azul municipal */
  --brand-primary-light: #2A6DB5;
  --brand-primary-dark: #123660;
  
  --brand-secondary: #2E7D58;  /* Verde judicial */
  --brand-accent: #C8992D;     /* Dorado institucional */
  --brand-accent-glow: rgba(200, 153, 45, 0.3);

  /* Superficies (Tema Dark/Elegante) */
  --bg-app: #0B1117;          /* Fondo extremo oscuro */
  --surface-base: #101822;    /* Sidebar/Nav */
  --surface-card: #16202D;    /* Tarjetas principales */
  --surface-elevated: #1D2A3B; /* Modales/Hover */
  --surface-border: #28384E;  /* Divisores tenues */

  /* Texto */
  --text-main: #E8EDF4;
  --text-muted: #8BA4BC;
  --text-inverse: #ffffff;

  /* Estados Funcionales */
  --status-ok: #34D399;       /* Verde vibrante */
  --status-ok-bg: rgba(52, 211, 153, 0.1);
  --status-warning: #FBBF24;  /* Ámbar preventivo */
  --status-warning-bg: rgba(251, 191, 36, 0.1);
  --status-danger: #F87171;   /* Rojo alerta */
  --status-danger-bg: rgba(248, 113, 113, 0.1);
  --status-info: #60A5FA;     /* Azul agua */

  /* Dimensiones y Sombras */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --shadow-drop: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 15px var(--brand-accent-glow);
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* =========================================
   RESET Y BASE
   ========================================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--bg-app) !important; /* Fuerza de aplicacion */
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

code, .mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9em;
  background: var(--surface-elevated);
  padding: 2px 6px;
  border-radius: 4px;
}

a {
  color: var(--status-info);
  text-decoration: none;
  transition: var(--transition);
}

a:hover {
  filter: brightness(1.2);
}

/* =========================================
   TIPOGRAFÍA MODERNA
   ========================================= */
h1, h2, h3, h4 {
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.text-title { font-size: 1.5rem; }
.text-subtitle { font-size: 1.1rem; color: var(--text-muted); }
.text-sm { font-size: 0.85rem; color: var(--text-muted); }

/* =========================================
   SISTEMA DE LAYOUT: SHELL APP
   ========================================= */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background-color: var(--bg-app) !important;
}

/* Sidebar */
.app-sidebar {
  width: 260px;
  background-color: var(--surface-base);
  border-right: 1px solid var(--surface-border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: var(--transition);
}

.sidebar-header {
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--surface-border);
}

.brand-icon {
  width: 32px;
  height: 32px;
  background: linear-gradient(135deg, var(--brand-accent), var(--brand-primary));
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  box-shadow: var(--shadow-glow);
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  margin-bottom: 4px;
  color: var(--text-muted);
  border-radius: var(--radius-md);
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
}

.nav-item:hover, .nav-item.active {
  background-color: var(--surface-elevated);
  color: var(--text-main);
}

.nav-item.active {
  border-left: 3px solid var(--brand-accent);
  background-color: rgba(200, 153, 45, 0.05);
}

.nav-item i {
  font-size: 1.1rem;
  width: 20px;
  text-align: center;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--surface-border);
}

/* Contenido Principal */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  scroll-behavior: smooth;
  background: radial-gradient(circle at top, var(--surface-base) 0%, var(--bg-app) 100%);
}

.topbar {
  height: 70px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(16, 24, 34, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-content {
  padding: 32px;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* =========================================
   COMPONENTES UI: TARJETAS (CARDS)
   ========================================= */
.card {
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
  transition: var(--transition);
  color: var(--text-main);
}

.card:hover {
  transform: translateY(-2px);
  border-color: rgba(200, 153, 45, 0.3);
  box-shadow: var(--shadow-drop);
}

/* =========================================
   BOTONES E INPUTS
   ========================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  font-size: 0.95rem;
}

.btn-primary {
  background: var(--brand-primary);
  color: white;
  box-shadow: 0 4px 12px rgba(27, 79, 138, 0.4);
}
.btn-primary:hover {
  background: var(--brand-primary-light);
  transform: translateY(-1px);
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
}

/* Tooltips de Explicación (Botón 'i') */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface-border);
  color: var(--text-muted);
  font-size: 0.75rem;
  margin-left: 8px;
  cursor: help;
  position: relative;
  transition: var(--transition);
}

/* Dash stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
  margin-bottom: 32px;
}
.stat-card {
  display: flex;
  flex-direction: column;
}
.stat-value {
  font-size: 2.5rem;
  font-weight: 700;
  margin: 8px 0;
  background: linear-gradient(135deg, #fff, var(--text-muted));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

[x-cloak] {
  display: none !important;
}

.nav-section-title {
  margin-top: 24px;
  margin-bottom: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
  padding-left: 16px;
  text-transform: uppercase;
}

.avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--brand-accent);
  color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.loading-box,
.empty-construction {
  text-align: center;
  padding: 40px;
}

.single-column-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 24px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.section-header-top {
  align-items: flex-start;
}

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.info-card,
.account-card {
  padding: 15px;
  background: var(--surface-base);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.03);
}

.account-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.info-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.muted-row {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.form-input {
  min-height: 42px;
  background: #0f1720;
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.95rem;
  outline: none;
  transition: var(--transition);
}

.form-input:focus {
  border-color: var(--brand-primary-light);
  box-shadow: 0 0 0 3px rgba(42, 109, 181, 0.16);
}

.form-input-wide {
  min-width: 280px;
  width: 320px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.badge-info {
  background: rgba(96, 165, 250, 0.14);
  color: #9dc8ff;
  border: 1px solid rgba(96, 165, 250, 0.24);
}

.badge-warn {
  background: rgba(251, 191, 36, 0.16);
  color: #ffd980;
  border: 1px solid rgba(251, 191, 36, 0.24);
}

.badge-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--surface-border);
}

.expediente-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.expediente-card {
  width: 100%;
  text-align: left;
  background: var(--surface-base);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-left: 4px solid var(--brand-accent);
  border-radius: 12px;
  padding: 18px;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition);
}

.expediente-card:hover {
  transform: translateY(-2px);
  border-color: rgba(200, 153, 45, 0.22);
  box-shadow: var(--shadow-drop);
}

.expediente-card-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.expediente-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.expediente-number {
  color: #60A5FA;
  font-size: 1.25rem;
  font-weight: 700;
}

.expediente-title {
  margin-top: 8px;
  font-size: 1rem;
  font-weight: 600;
}

.expediente-subtitle {
  margin-top: 8px;
  color: var(--text-muted);
  font-size: 0.92rem;
}

.metric-row {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.metric-pill {
  min-width: 160px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 10px;
  padding: 10px 12px;
}

.metric-label,
.summary-label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 18px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px dashed rgba(255, 255, 255, 0.08);
  border-radius: 12px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 9, 15, 0.78);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-panel {
  width: min(1180px, 100%);
  max-height: min(92vh, 960px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(29, 42, 59, 0.98), rgba(16, 24, 34, 0.98));
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.45);
}

.modal-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
  padding: 22px 24px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.modal-body {
  padding: 22px 24px 24px;
  overflow-y: auto;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--surface-border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover {
  border-color: var(--brand-primary-light);
  background: rgba(42, 109, 181, 0.14);
}

.modal-loading,
.error-box {
  margin: 20px 24px 24px;
  padding: 18px;
  border-radius: 12px;
}

.modal-loading {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.03);
}

.error-box {
  color: #ffd4d4;
  background: rgba(248, 113, 113, 0.12);
  border: 1px solid rgba(248, 113, 113, 0.24);
}

.detail-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.summary-card {
  padding: 16px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.detail-columns {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.detail-section {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.05);
  border-radius: 14px;
  padding: 18px;
}

.detail-section-head,
.detail-item-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.detail-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

.detail-item {
  padding: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-radius: 12px;
}

.spinning {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

@media (max-width: 1100px) {
  .detail-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .detail-columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  .app-sidebar {
    width: 84px;
  }

  .sidebar-header h3,
  .sidebar-header .badge,
  .sidebar-nav .nav-item,
  .nav-section-title,
  .sidebar-footer .nav-item,
  .hide-mobile {
    display: none;
  }

  .sidebar-header {
    justify-content: center;
  }

  .page-content {
    padding: 20px;
  }

  .section-header,
  .section-header-top,
  .info-card-head,
  .account-card,
  .expediente-card-head {
    flex-direction: column;
  }

  .toolbar-row {
    width: 100%;
  }

  .form-input,
  .form-input-wide,
  .btn {
    width: 100%;
  }

  .expediente-badges {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .topbar {
    padding: 0 18px;
  }

  .modal-backdrop {
    padding: 12px;
  }

  .modal-header-bar,
  .modal-body {
    padding-left: 16px;
    padding-right: 16px;
  }

  .detail-summary {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* =========================================
   CONFLICT SHIELD AGAINST LEGACY styles.css
   ========================================= */
body.app-shell {
  --brand-primary: #1B4F8A;
  --brand-primary-light: #2A6DB5;
  --brand-primary-dark: #123660;
  --brand-secondary: #2E7D58;
  --brand-accent: #C8992D;
  --brand-accent-glow: rgba(200, 153, 45, 0.3);
  --bg-app: #0B1117;
  --surface-base: #101822;
  --surface-card: #16202D;
  --surface-elevated: #1D2A3B;
  --surface-border: #28384E;
  --text-main: #E8EDF4;
  --text-muted: #8BA4BC;
  --text-inverse: #ffffff;
  --status-ok: #34D399;
  --status-warning: #FBBF24;
  --status-danger: #F87171;
  --status-info: #60A5FA;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
}

body.app-shell,
body.app-shell .app-main,
body.app-shell .app-sidebar,
body.app-shell .topbar,
body.app-shell .page-content,
body.app-shell .card,
body.app-shell .stat-card,
body.app-shell .info-card,
body.app-shell .account-card,
body.app-shell .expediente-card,
body.app-shell .modal-panel,
body.app-shell .summary-card,
body.app-shell .detail-section,
body.app-shell .detail-item,
body.app-shell .metric-pill,
body.app-shell .empty-state {
  color: var(--text-main);
}

body.app-shell .sidebar-header,
body.app-shell .sidebar-footer,
body.app-shell .nav-item,
body.app-shell .stats-grid,
body.app-shell .stat-card,
body.app-shell .btn,
body.app-shell .btn-primary,
body.app-shell .btn-outline,
body.app-shell .form-input,
body.app-shell .badge,
body.app-shell .modal-body {
  font-family: 'Inter', sans-serif;
}

body.app-shell .sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px;
  border-bottom: 1px solid var(--surface-border);
  background: transparent;
}

body.app-shell .nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  background: transparent;
}

body.app-shell .nav-item:hover,
body.app-shell .nav-item.active {
  color: var(--text-main);
}

body.app-shell .page-content {
  max-width: 1400px;
}

body.app-shell .card {
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

body.app-shell .stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 24px;
}

body.app-shell .stat-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  box-shadow: none;
  overflow: visible;
}

body.app-shell .stat-card::before {
  content: none;
}

body.app-shell .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
}

body.app-shell .btn-primary {
  background: var(--brand-primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(27, 79, 138, 0.4);
}

body.app-shell .btn-outline {
  background: transparent;
  color: var(--text-main);
  border: 1px solid var(--surface-border);
}

body.app-shell .form-input {
  width: auto;
  min-height: 42px;
  background: #0f1720;
  color: var(--text-main);
  border: 1px solid var(--surface-border);
}

body.app-shell .form-input::placeholder {
  color: var(--text-muted);
}

body.app-shell .badge {
  display: inline-flex;
}

body.app-shell .expediente-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

body.app-shell .expediente-card {
  appearance: none;
  -webkit-appearance: none;
  display: block;
  width: 100%;
  text-align: left;
  background: var(--surface-base);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.04);
  border-left: 4px solid var(--brand-accent);
  border-radius: 12px;
  padding: 18px;
}

body.app-shell .expediente-card * {
  text-align: inherit;
}

body.app-shell .metric-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

body.app-shell .modal-backdrop {
  position: fixed;
  inset: 0;
  display: flex;
}

body.app-shell .modal-panel {
  background: linear-gradient(180deg, rgba(29, 42, 59, 0.98), rgba(16, 24, 34, 0.98));
  color: var(--text-main);
}

body.app-shell .modal-body {
  padding: 22px 24px 24px;
  overflow-y: auto;
  background: transparent;
}

body.app-shell .detail-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

body.app-shell .detail-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

body.app-shell .detail-section-head,
body.app-shell .detail-item-head,
body.app-shell .expediente-card-head,
body.app-shell .info-card-head,
body.app-shell .account-card,
body.app-shell .section-header {
  display: flex;
}

@media (max-width: 1100px) {
  body.app-shell .detail-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.app-shell .detail-columns {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 900px) {
  body.app-shell .section-header,
  body.app-shell .info-card-head,
  body.app-shell .account-card,
  body.app-shell .expediente-card-head {
    flex-direction: column;
  }

  body.app-shell .form-input,
  body.app-shell .form-input-wide,
  body.app-shell .btn {
    width: 100%;
  }
}

@media (max-width: 640px) {
  body.app-shell .detail-summary {
    grid-template-columns: minmax(0, 1fr);
  }
}
