:root {
  /* Paleta principal (indigo, mas contemporaneo que el azul plano anterior) */
  --azul: #4f46e5;
  --azul-oscuro: #4338ca;
  --azul-suave: #eef2ff;
  --azul-suave-texto: #4338ca;

  --gris-borde: #e5e7f0;
  --gris-texto: #64748b;
  --gris-texto-fuerte: #334155;

  --rojo: #e11d48;
  --rojo-suave: #fff1f2;
  --rojo-suave-texto: #be123c;

  --verde: #10b981;
  --verde-suave: #ecfdf5;
  --verde-suave-texto: #047857;

  --naranja: #ea580c;
  --naranja-suave: #fff7ed;
  --naranja-suave-texto: #c2410c;

  --amarillo: #d97706;
  --amarillo-suave: #fffbeb;
  --amarillo-suave-texto: #b45309;

  --morado: #7c3aed;
  --morado-suave: #f5f3ff;
  --morado-suave-texto: #6d28d9;

  --neutro-suave: #f1f5f9;
  --neutro-suave-texto: #475569;

  --superficie: #ffffff;
  --fondo: #f5f6fa;
  --texto: #0f172a;

  --radio-sm: 8px;
  --radio: 12px;
  --radio-lg: 16px;
  --sombra-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
  --sombra: 0 1px 2px rgba(15,23,42,0.04), 0 8px 20px -10px rgba(15, 23, 42, 0.12);
  --sombra-lg: 0 20px 45px -20px rgba(15, 23, 42, 0.25);
}

* { box-sizing: border-box; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  margin: 0;
  background: var(--fondo);
  color: var(--texto);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--azul); }

:focus-visible {
  outline: 2px solid var(--azul);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------- Navegacion ---------- */

nav {
  background: linear-gradient(180deg, #12172b 0%, #0b0f1f 100%);
  color: white;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  flex-wrap: wrap;
  gap: 0.5rem;
  box-shadow: 0 1px 0 rgba(255,255,255,0.06);
}

.nav-bar { display: flex; align-items: center; justify-content: space-between; }
.nav-menu { display: flex; align-items: center; justify-content: space-between; flex: 1; gap: 1rem; flex-wrap: wrap; }
.nav-toggle {
  display: none;
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.3rem 0.5rem;
  border-radius: var(--radio-sm);
}
.nav-toggle:hover { background: rgba(255,255,255,0.08); }

nav .navlinks { display: flex; align-items: center; gap: 0.3rem; flex-wrap: wrap; }
nav form { display: inline; }

.brand-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
  margin-right: 0.9rem;
  padding-right: 1.1rem;
  border-right: 1px solid rgba(255,255,255,0.10);
}
.brand-icon {
  font-size: 1.05rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--azul), #7c6cf6);
  box-shadow: 0 4px 10px -2px rgba(79,70,229,0.55);
}
.brand-link .brand { font-weight: 700; font-size: 1.02rem; color: white; letter-spacing: -0.01em; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  color: #b6bcd6;
  text-decoration: none;
  font-size: 0.87rem;
  font-weight: 500;
  padding: 0.5rem 0.8rem;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.nav-icon { font-size: 1rem; line-height: 1; }
.nav-link:hover { color: white; background: rgba(255,255,255,0.08); }
.nav-link.active { color: white; background: rgba(124, 108, 246, 0.28); box-shadow: inset 0 0 0 1px rgba(124,108,246,0.35); }

nav button.link-btn {
  background: none; border: none; color: #b6bcd6; cursor: pointer; font-size: 0.87rem; padding: 0.5rem 0.8rem;
  border-radius: 999px; transition: background 0.15s, color 0.15s;
}
nav button.link-btn:hover { color: white; background: rgba(255,255,255,0.08); }
nav .userchip { font-size: 0.82rem; color: #8b92b3; margin-right: 0.3rem; }
.bell-link { position: relative; }

@media (max-width: 900px) {
  nav { padding: 0.6rem 1rem; }
  .nav-bar { width: 100%; justify-content: space-between; }
  .brand-link { border-right: none; padding-right: 0; margin-right: 0; }
  .nav-toggle { display: block; }
  .nav-menu {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 0.2rem;
    padding-bottom: 0.8rem;
  }
  .nav-menu.open { display: flex; }
  nav .navlinks { flex-direction: column; align-items: stretch; width: 100%; gap: 0.15rem; }
  .nav-link, nav button.link-btn { width: 100%; border-radius: var(--radio-sm); }
  nav .userchip { margin: 0.5rem 0 0.2rem 0; padding: 0 0.75rem; }
  .navlinks + .navlinks { margin-top: 0.5rem; padding-top: 0.5rem; border-top: 1px solid rgba(255,255,255,0.08); }
}

.badge-count {
  display: inline-block;
  background: var(--rojo);
  color: white;
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.05rem 0.42rem;
  border-radius: 999px;
  margin-left: 0.3rem;
  box-shadow: 0 0 0 2px rgba(11,15,31,1);
}
.notif-item { padding: 0.8rem 0.2rem; border-bottom: 1px solid var(--gris-borde); }
.notif-item.unread { background: var(--azul-suave); border-radius: var(--radio-sm); padding: 0.8rem 0.9rem; }
.notif-item .notif-fecha { font-size: 0.8rem; color: var(--gris-texto); }
.notif-item .notif-texto { margin-bottom: 0.15rem; }
.link-btn-inline {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--rojo);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
}
.link-btn-inline:hover { color: var(--rojo-suave-texto); }

/* ---------- Layout general ---------- */

.container { max-width: 1600px; margin: 0 auto; padding: 2.2rem 1.5rem; }
@media (max-width: 700px) {
  .container { padding: 1.2rem 0.9rem; }
}

h1 { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.015em; margin-bottom: 1.3rem; color: var(--texto); }
h2 { font-size: 1.08rem; font-weight: 650; letter-spacing: -0.005em; margin-bottom: 0.9rem; color: var(--texto); }

.card {
  background: var(--superficie);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-lg);
  box-shadow: var(--sombra);
  padding: 1.6rem;
  margin-bottom: 1.5rem;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.75rem 0.8rem; border-bottom: 1px solid var(--gris-borde); font-size: 0.88rem; }
th {
  color: var(--gris-texto);
  font-weight: 650;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: transparent;
  border-bottom: 1.5px solid var(--gris-borde);
}
tbody tr { transition: background 0.1s; }
tr:hover td { background: #fafbff; }
tr:last-child td { border-bottom: none; }

label { display: block; font-size: 0.84rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--gris-texto-fuerte); }
input[type=text], input[type=password], input[type=email], input[type=file], input[type=date], input[type=time], input[type=number], select, textarea {
  width: 100%;
  padding: 0.6rem 0.8rem;
  border: 1.5px solid var(--gris-borde);
  border-radius: var(--radio-sm);
  font-size: 0.92rem;
  margin-bottom: 1rem;
  background: var(--superficie);
  font-family: inherit;
  color: var(--texto);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul);
  box-shadow: 0 0 0 3.5px rgba(79, 70, 229, 0.14);
}
textarea { min-height: 90px; resize: vertical; }

.btn {
  display: inline-block;
  background: var(--azul);
  color: white;
  border: none;
  padding: 0.6rem 1.15rem;
  border-radius: var(--radio-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 1px 2px rgba(79,70,229,0.05), 0 4px 10px -4px rgba(79,70,229,0.45);
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn:hover { background: var(--azul-oscuro); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn.secondary { background: var(--superficie); color: var(--gris-texto-fuerte); border: 1.5px solid var(--gris-borde); box-shadow: var(--sombra-sm); }
.btn.secondary:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn.small { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn.danger { background: var(--rojo); box-shadow: 0 1px 2px rgba(225,29,72,0.05), 0 4px 10px -4px rgba(225,29,72,0.5); }
.btn.danger:hover { background: #be123c; }

/* ---------- Insignias tipo "chip" (fondo suave + texto de color) ---------- */

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
}
.badge.baja { background: var(--neutro-suave); color: var(--neutro-suave-texto); }
.badge.normal { background: var(--azul-suave); color: var(--azul-suave-texto); }
.badge.alta { background: var(--naranja-suave); color: var(--naranja-suave-texto); }
.badge.urgente { background: var(--rojo-suave); color: var(--rojo-suave-texto); }

.badge.pendiente { background: var(--neutro-suave); color: var(--neutro-suave-texto); }
.badge.en_proceso { background: var(--amarillo-suave); color: var(--amarillo-suave-texto); }
.badge.completada { background: var(--verde-suave); color: var(--verde-suave-texto); }
.badge.info { background: var(--morado-suave); color: var(--morado-suave-texto); }

.error-box {
  background: var(--rojo-suave);
  border: 1px solid #fecdd3;
  color: var(--rojo-suave-texto);
  padding: 0.75rem 1rem;
  border-radius: var(--radio-sm);
  margin-bottom: 1rem;
  font-size: 0.88rem;
}
.ok-box {
  background: var(--verde-suave);
  border: 1px solid #a7f3d0;
  color: var(--verde-suave-texto);
  padding: 0.75rem 1rem;
  border-radius: var(--radio-sm);
  margin-bottom: 1rem;
  font-size: 0.88rem;
}

.login-wrap {
  max-width: 400px;
  margin: 9vh auto;
}
.login-wrap .card { box-shadow: var(--sombra-lg); }

.filters { display: flex; gap: 0.8rem; margin-bottom: 1rem; align-items: end; flex-wrap: wrap; }
.filters select, .filters input[type=text] { margin-bottom: 0; }

.attachment-row { display: flex; justify-content: space-between; align-items: center; padding: 0.6rem 0.1rem; border-bottom: 1px solid var(--gris-borde); font-size: 0.9rem; flex-wrap: wrap; gap: 0.4rem; }
.attachment-row:last-child { border-bottom: none; }
.row-actions { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.thread-meta .row-actions { margin-left: auto; }
.muted { color: var(--gris-texto); font-size: 0.85rem; }

.inline-form { display: flex; gap: 0.6rem; align-items: center; flex-wrap: wrap; }
.inline-form select { margin-bottom: 0; }

.thread { margin: 1rem 0; }
.thread-item {
  border-left: 3px solid var(--azul);
  background: #fafbff;
  border-radius: 0 var(--radio-sm) var(--radio-sm) 0;
  padding: 0.7rem 1rem;
  margin-bottom: 0.9rem;
}
.thread-meta { font-size: 0.85rem; margin-bottom: 0.3rem; display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }
.thread-text { font-size: 0.92rem; margin-bottom: 0.4rem; }
.thread-attachments { margin-top: 0.3rem; }

.cliente-picker { position: relative; margin-bottom: 1rem; }
.cliente-picker input[type=text] { margin-bottom: 0; }
.cliente-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--superficie);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio);
  max-height: 240px;
  overflow-y: auto;
  z-index: 20;
  display: none;
  box-shadow: var(--sombra-lg);
  margin-top: 8px;
}
.cliente-suggestion { padding: 0.6rem 0.8rem; cursor: pointer; font-size: 0.88rem; border-bottom: 1px solid #f1f5f9; }
.cliente-suggestion:last-child { border-bottom: none; }
.cliente-suggestion:hover, .cliente-suggestion.active { background: var(--azul-suave); }

/* ---------- Agenda / calendario ---------- */

.cal-vistas { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.cal-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; gap: 0.5rem; }
.cal-nav-group { display: flex; gap: 0.4rem; align-items: center; }
.calendar { width: 100%; border-collapse: separate; border-spacing: 4px; table-layout: fixed; }
.calendar th, .calendar td { width: 14.2857%; }
.calendar th { background: transparent; padding: 0.5rem; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; text-align: center; color: var(--gris-texto); border-bottom: none; }
.calendar td { border: 1px solid var(--gris-borde); border-radius: var(--radio-sm); vertical-align: top; height: 110px; padding: 0.4rem; font-size: 0.78rem; overflow: hidden; }
.calendar-semana td { height: 420px; overflow-y: auto; }
.cal-vacia { background: #fafbfc; border-color: transparent !important; }
.cal-dia { background: var(--superficie); }
.cal-hoy { background: var(--azul-suave); border-color: var(--azul) !important; }
.cal-dia-num { font-weight: 650; margin-bottom: 0.35rem; display: flex; justify-content: space-between; align-items: center; }
.cal-add {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  text-decoration: none;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  line-height: 1;
  border-radius: 50%;
  background: var(--azul);
  box-shadow: 0 1px 3px rgba(79,70,229,0.4);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.cal-add:hover { background: var(--azul-oscuro); transform: scale(1.1); box-shadow: 0 2px 6px rgba(79,70,229,0.5); }
.cal-add:active { transform: scale(0.96); }
.cal-eventos-lista { display: flex; flex-direction: column; gap: 0.25rem; }
.cal-evento {
  display: block;
  background: var(--azul);
  color: white;
  border-radius: 6px;
  padding: 0.2rem 0.45rem;
  font-size: 0.72rem;
  line-height: 1.3;
  text-decoration: none;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: normal;
  word-break: break-word;
}
.cal-evento .cal-evento-hora { display: block; font-weight: 650; opacity: 0.9; font-size: 0.68rem; }
.cal-evento:hover { opacity: 0.85; }
.cal-evento-solo-lectura { background: #94a3b8; cursor: default; }
@media (max-width: 800px) {
  .calendar td { height: 70px; font-size: 0.68rem; padding: 0.25rem; }
  .calendar-semana td { height: 160px; }
  .calendar { border-spacing: 2px; }
}

.color-swatches { display: flex; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.color-swatch {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2px solid transparent;
  box-shadow: 0 0 0 1px rgba(0,0,0,0.08);
  position: relative;
  transition: transform 0.1s;
}
.color-swatch:hover { transform: scale(1.08); }
.color-swatch input[type=radio] {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}
.color-swatch:has(input:checked) {
  border-color: #0f172a;
  box-shadow: 0 0 0 2px white inset, 0 0 0 1px #0f172a;
}

/* ---------- Panel de inicio ---------- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--superficie);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-lg);
  box-shadow: var(--sombra);
  padding: 1.3rem 1.4rem;
  text-decoration: none;
  color: inherit;
  display: block;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.15s, transform 0.15s;
}
.stat-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 4px;
  background: var(--azul);
}
.stat-card:hover { box-shadow: var(--sombra-lg); transform: translateY(-2px); }
.stat-card.pendiente::before { background: #94a3b8; }
.stat-card.en_proceso::before { background: var(--amarillo); }
.stat-card.urgente::before { background: var(--rojo); }
.stat-card.info::before { background: var(--verde); }
.stat-card.notif::before { background: var(--morado); }
.stat-number { font-size: 2.15rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1; margin-bottom: 0.4rem; color: var(--texto); }
.stat-label { font-size: 0.85rem; color: var(--gris-texto); font-weight: 600; }

.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1.5rem; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: 1fr; } }

.dash-list-item {
  display: block;
  padding: 0.65rem 0.1rem;
  border-bottom: 1px solid var(--gris-borde);
  font-size: 0.86rem;
  text-decoration: none;
  color: inherit;
  border-radius: var(--radio-sm);
  transition: background 0.1s;
}
.dash-list-item:hover { color: var(--azul); background: #fafbff; padding-left: 0.5rem; }
.dash-list-item:last-child { border-bottom: none; }
.dash-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 0.45rem; }

.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem 1.5rem;
}
.data-field { display: flex; flex-direction: column; gap: 0.2rem; }
.data-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--gris-texto); font-weight: 650; }
.data-value { font-size: 0.95rem; color: var(--texto); }

.badge-tag {
  display: inline-block;
  color: white;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 0.18rem 0.6rem;
  border-radius: 999px;
  margin-right: 0.3rem;
  margin-bottom: 0.2rem;
  box-shadow: var(--sombra-sm);
}
.tag-checks { display: flex; flex-wrap: wrap; gap: 0.6rem; margin-bottom: 1.2rem; }
.tag-check { display: flex; align-items: center; gap: 0.4rem; cursor: pointer; font-weight: 400; }
.tag-check input[type=checkbox] { width: auto; margin: 0; }

.barchart { display: flex; flex-direction: column; gap: 0.7rem; }
.barchart-row { display: grid; grid-template-columns: 140px 1fr 40px; align-items: center; gap: 0.7rem; }
.barchart-label { font-size: 0.85rem; color: var(--gris-texto-fuerte); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.barchart-label:hover { color: var(--azul); text-decoration: underline; }
.barchart-track { background: var(--neutro-suave); border-radius: 999px; height: 12px; overflow: hidden; }
.barchart-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.barchart-value { font-size: 0.82rem; font-weight: 650; color: var(--gris-texto-fuerte); text-align: right; }
@media (max-width: 700px) {
  .barchart-row { grid-template-columns: 90px 1fr 30px; }
  .barchart-label { font-size: 0.78rem; }
}

/* ---------- Panel de Configuracion: tarjetas de acceso rapido ---------- */

.config-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 1rem;
  margin-bottom: 1.6rem;
}
.config-link-card {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  background: var(--superficie);
  border: 1px solid var(--gris-borde);
  border-radius: var(--radio-lg);
  box-shadow: var(--sombra);
  padding: 1.3rem 1.4rem;
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}
.config-link-card:hover { box-shadow: var(--sombra-lg); transform: translateY(-2px); border-color: #c7d2fe; }
.config-link-icon {
  font-size: 1.5rem;
  line-height: 1;
  width: 40px;
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radio-sm);
  background: var(--azul-suave);
  margin-bottom: 0.3rem;
}
.config-link-title { font-weight: 700; font-size: 0.96rem; color: var(--texto); }
.config-link-desc { font-size: 0.82rem; color: var(--gris-texto); line-height: 1.35; }

/* ---------- Proximos vencimientos: color segun cuantos dias quedan ---------- */

.venc-lista {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
}
.venc-item {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.7rem 0.9rem;
  border-radius: var(--radio-sm);
  border-left: 4px solid var(--gris-borde);
  background: #fafbfc;
}
.venc-item .data-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 650; }
.venc-item .data-value { font-size: 0.92rem; color: var(--texto); }

.venc-critico { border-left-color: var(--rojo); background: var(--rojo-suave); }
.venc-critico .data-label { color: var(--rojo-suave-texto); }

.venc-alto { border-left-color: var(--naranja); background: var(--naranja-suave); }
.venc-alto .data-label { color: var(--naranja-suave-texto); }

.venc-medio { border-left-color: var(--amarillo); background: var(--amarillo-suave); }
.venc-medio .data-label { color: var(--amarillo-suave-texto); }

.venc-bajo { border-left-color: var(--verde); background: var(--verde-suave); }
.venc-bajo .data-label { color: var(--verde-suave-texto); }
