/* ============================================================
   CRM ARTERIA — Estilos globales
   Paleta: negro profundo + rojo coral Arteria + blanco roto
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700;800&family=DM+Sans:wght@300;400;500;600&display=swap');

/* ---- Variables ---- */
:root {
  --bg:          #0e0e0e;
  --bg-card:     #161616;
  --bg-hover:    #1e1e1e;
  --border:      rgba(255,255,255,0.07);
  --border-acc:  rgba(220,60,30,0.35);

  --rojo:        #dc3c1e;       /* rojo Arteria */
  --rojo-claro:  #ff5535;
  --rojo-oscuro: #a82a0e;
  --rojo-glow:   rgba(220,60,30,0.18);

  --blanco:      #f5f0ec;
  --gris-1:      #c8c0bb;
  --gris-2:      #857e79;
  --gris-3:      #3a3530;

  --verde:       #2ecc71;
  --amarillo:    #f0b429;
  --azul:        #4a9eff;

  --fuente-titulo: 'Inter', sans-serif;
  --fuente-body:   'Martel Sans', sans-serif;

  --radio:       12px;
  --radio-lg:    20px;
  --sombra:      0 4px 24px rgba(0,0,0,0.45);
  --trans:       0.2s ease;

  --sidebar-w:   240px;
  --topbar-h:    64px;
}

/* ---- Tema claro ---- */
[data-theme="light"] {
  --bg:          #f4f4f6;
  --bg-card:     #ffffff;
  --bg-hover:    #eaeaed;
  --border:      rgba(0,0,0,0.08);
  --border-acc:  rgba(220,60,30,0.3);
  --rojo-glow:   rgba(220,60,30,0.10);
  --blanco:      #1a1a1a;
  --gris-1:      #4a4a4a;
  --gris-2:      #888888;
  --gris-3:      #cccccc;
  --sombra:      0 4px 24px rgba(0,0,0,0.08);
}
[data-theme="light"] body { background: var(--bg); color: var(--blanco); }
[data-theme="light"] input,
[data-theme="light"] textarea,
[data-theme="light"] select { color: var(--blanco); }
[data-theme="light"] ::-webkit-scrollbar-track { background: var(--bg); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: var(--gris-3); }

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; scroll-behavior: smooth; }
body {
  font-family: var(--fuente-body);
  background: var(--bg);
  color: var(--blanco);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea, select {
  font-family: inherit;
  background: transparent;
  color: var(--blanco);
  border: none;
  outline: none;
}
img { display: block; max-width: 100%; }

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--gris-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--rojo); }

/* ============================================================
   LAYOUT
   ============================================================ */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ---- Sidebar ---- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  position: relative;
  z-index: 100;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}
.sidebar-logo-img {
  height: 24px;
  width: auto;
  display: block;
}
.sidebar-logo .logo-sub {
  font-size: 0.65rem;
  color: var(--gris-2);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 500;
}

.sidebar-nav {
  padding: 16px 10px;
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gris-2);
  padding: 12px 10px 4px;
  margin-top: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--gris-1);
  font-size: 0.9rem;
  font-weight: 400;
  transition: all var(--trans);
  position: relative;
}
.nav-item svg { opacity: 0.7; flex-shrink: 0; }
.nav-item:hover {
  background: var(--bg-hover);
  color: var(--blanco);
}
.nav-item:hover svg { opacity: 1; }
.nav-item.activo {
  background: var(--rojo-glow);
  color: var(--rojo-claro);
  font-weight: 500;
}
.nav-item.activo svg { opacity: 1; color: var(--rojo-claro); }
.nav-item.activo::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 60%;
  background: var(--rojo);
  border-radius: 0 2px 2px 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--rojo);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

.sidebar-user {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar-user .avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--rojo-oscuro);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.8rem;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-user .avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user .user-info { flex: 1; min-width: 0; }
.sidebar-user .user-name {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .user-role {
  font-size: 0.68rem;
  color: var(--gris-2);
}
.sidebar-user .logout-btn {
  background: none;
  border: none;
  color: var(--gris-2);
  transition: color var(--trans);
  padding: 4px;
  border-radius: 6px;
}
.sidebar-user .logout-btn:hover { color: var(--rojo-claro); }

/* ---- Main ---- */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ---- Topbar ---- */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 28px;
  gap: 16px;
  flex-shrink: 0;
}
.topbar-title {
  font-family: var(--fuente-titulo);
  font-weight: 700;
  font-size: 1.1rem;
  flex: 1;
}
.topbar-breadcrumb {
  font-size: 0.78rem;
  color: var(--gris-2);
  flex: 1;
}
.topbar-breadcrumb span { color: var(--blanco); }

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ---- Content area ---- */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
}

/* ============================================================
   COMPONENTES BASE
   ============================================================ */

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radio-lg);
  padding: 20px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-family: var(--fuente-titulo);
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.01em;
}

/* ---- Stat cards ---- */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radio-lg);
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--trans);
}
.stat-card:hover { border-color: var(--border-acc); }
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 80px; height: 80px;
  background: radial-gradient(circle at top right, var(--rojo-glow), transparent 70%);
}
.stat-number {
  font-family: var(--fuente-titulo);
  font-weight: 800;
  font-size: 2rem;
  letter-spacing: -0.03em;
  line-height: 1;
}
.stat-label {
  font-size: 0.78rem;
  color: var(--gris-2);
  margin-top: 4px;
}
.stat-change {
  font-size: 0.72rem;
  font-weight: 600;
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 7px;
  border-radius: 20px;
}
.stat-change.pos { background: rgba(46,204,113,0.12); color: var(--verde); }
.stat-change.neg { background: rgba(220,60,30,0.12); color: var(--rojo-claro); }

/* ---- Botones ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 9px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all var(--trans);
  border: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--rojo);
  color: #fff;
}
.btn-primary:hover { background: var(--rojo-claro); transform: translateY(-1px); box-shadow: 0 4px 16px rgba(220,60,30,0.4); }
.btn-secondary {
  background: var(--bg-hover);
  color: var(--gris-1);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: #252525; color: var(--blanco); }
.btn-ghost {
  background: transparent;
  color: var(--gris-1);
  padding: 7px 12px;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--blanco); }
.btn-sm { padding: 6px 12px; font-size: 0.78rem; }
.btn-icon { padding: 8px; border-radius: 8px; }

/* ---- Badges ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}
.badge-green  { background: rgba(46,204,113,0.12); color: #2ecc71; }
.badge-red    { background: rgba(220,60,30,0.12);  color: var(--rojo-claro); }
.badge-yellow { background: rgba(240,180,41,0.12); color: var(--amarillo); }
.badge-blue   { background: rgba(74,158,255,0.12); color: var(--azul); }
.badge-gray   { background: rgba(255,255,255,0.06); color: var(--gris-1); }

/* ---- Formularios ---- */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--gris-1);
  margin-bottom: 6px;
}
.form-control {
  width: 100%;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 0.88rem;
  color: var(--blanco);
  transition: border-color var(--trans);
}
.form-control:focus { border-color: var(--rojo); outline: none; }
.form-control::placeholder { color: var(--gris-3); }
select.form-control { appearance: none; cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ---- Tabla ---- */
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}
thead th {
  padding: 10px 14px;
  text-align: left;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--gris-2);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--gris-1);
  vertical-align: middle;
}
tbody tr:hover td { background: var(--bg-hover); color: var(--blanco); }
tbody tr:last-child td { border-bottom: none; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--trans);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radio-lg);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  transform: translateY(16px);
  transition: transform var(--trans);
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.modal-title {
  font-family: var(--fuente-titulo);
  font-weight: 700;
  font-size: 1.1rem;
}
.modal-close {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--gris-1);
  width: 30px; height: 30px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--trans);
}
.modal-close:hover { background: var(--rojo); color: #fff; border-color: var(--rojo); }

/* ---- Toast ---- */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  box-shadow: var(--sombra);
  animation: slideUp 0.25s ease forwards;
}
.toast.success { border-left: 3px solid var(--verde); }
.toast.error   { border-left: 3px solid var(--rojo); }
.toast.info    { border-left: 3px solid var(--azul); }
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Gráficas simples ---- */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
}
.bar-chart .bar {
  flex: 1;
  background: var(--border);
  border-radius: 4px 4px 0 0;
  position: relative;
  transition: background var(--trans);
  min-height: 4px;
}
.bar-chart .bar.highlight { background: var(--rojo); }
.bar-chart .bar:hover { background: var(--rojo-claro); }

/* ---- Progress bars ---- */
.progress-bar-wrap {
  background: var(--bg-hover);
  border-radius: 99px;
  height: 6px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--rojo);
  transition: width 0.4s ease;
}

/* ---- Chips / filtros ---- */
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  padding: 4px 12px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 500;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--gris-1);
  cursor: pointer;
  transition: all var(--trans);
}
.chip.activo, .chip:hover {
  background: var(--rojo-glow);
  border-color: var(--border-acc);
  color: var(--rojo-claro);
}

/* ---- Loader ---- */
.loader {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--rojo);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 60% 50% at 70% 40%, rgba(220,60,30,0.08), transparent),
    radial-gradient(ellipse 40% 30% at 20% 80%, rgba(220,60,30,0.04), transparent);
  padding: 20px;
}
.login-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}
.login-logo .mark {
  width: 40px; height: 40px;
  background: var(--rojo);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--fuente-titulo);
  font-weight: 800; font-size: 18px; color: #fff;
}
.login-logo .text { font-family: var(--fuente-titulo); font-size: 1.3rem; font-weight: 800; }
.login-logo .sub  { font-size: 0.72rem; color: var(--gris-2); letter-spacing: 0.05em; text-transform: uppercase; }
.login-heading { font-family: var(--fuente-titulo); font-size: 1.5rem; font-weight: 800; margin-bottom: 6px; }
.login-sub { font-size: 0.85rem; color: var(--gris-2); margin-bottom: 28px; }

/* ============================================================
   DASHBOARD GRID
   ============================================================ */
.dash-grid { display: grid; gap: 16px; }
.dash-grid-4 { grid-template-columns: repeat(4,1fr); }
.dash-grid-3 { grid-template-columns: repeat(3,1fr); }
.dash-grid-2 { grid-template-columns: repeat(2,1fr); }
.dash-grid-auto { grid-template-columns: 2fr 1fr; }

/* ---- Timer display ---- */
.timer-display {
  font-family: var(--fuente-titulo);
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--rojo-claro);
  line-height: 1;
}

/* ---- Circle progress ---- */
.circle-progress {
  position: relative;
  width: 100px; height: 100px;
}
.circle-progress svg { transform: rotate(-90deg); }
.circle-progress .circle-bg { fill: none; stroke: var(--bg-hover); stroke-width: 8; }
.circle-progress .circle-fill { fill: none; stroke: var(--rojo); stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.circle-progress .circle-text {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-family: var(--fuente-titulo);
  font-weight: 800; font-size: 1.1rem;
}

/* ============================================================
   HAMBURGER + THEME TOGGLE BUTTONS
   ============================================================ */
.btn-hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--gris-1);
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: color var(--trans), background var(--trans);
  flex-shrink: 0;
}
.btn-hamburger:hover { background: var(--bg-hover); color: var(--blanco); }

.btn-theme {
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--gris-1);
  width: 34px; height: 34px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: all var(--trans);
  flex-shrink: 0;
  font-size: 16px;
  line-height: 1;
}
.btn-theme:hover { background: var(--bg-hover); color: var(--blanco); border-color: var(--border-acc); }

/* ---- Backdrop sidebar móvil ---- */
#sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 99;
  backdrop-filter: blur(2px);
}
#sidebar-backdrop.visible { display: block; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1100px) {
  .dash-grid-4 { grid-template-columns: repeat(2,1fr); }
  .dash-grid-auto { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  /* Sidebar como overlay deslizante */
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 260px !important;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
    box-shadow: 4px 0 24px rgba(0,0,0,0.35);
  }
  .sidebar.sidebar-open { transform: translateX(0); }

  /* Ocultar hamburger en layout principal */
  .btn-hamburger { display: flex; }

  .content { padding: 14px; }
  .topbar { padding: 0 14px; gap: 10px; }

  /* Grids en columna única */
  .dash-grid-4,
  .dash-grid-3,
  .dash-grid-2 { grid-template-columns: 1fr; }

  /* Grid central del dashboard en columna */
  .dash-grid[style*="1fr 320px"],
  .dash-grid[style*="1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* Modales a pantalla completa en móvil */
  .modal {
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    margin: 0;
    border-radius: 16px 16px 0 0;
  }
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  /* Tablas: scroll horizontal */
  .table-wrap { -webkit-overflow-scrolling: touch; }

  /* Timer widget en columna */
  .card [style*="display:flex"][style*="gap:20px"] {
    flex-direction: column;
    gap: 12px;
  }

  /* Ocultar breadcrumb en móvil si hay poco espacio */
  .topbar-breadcrumb { display: none; }
}

/* ---- Utilidades ---- */
.text-rojo   { color: var(--rojo-claro); }
.text-gris   { color: var(--gris-2); }
.text-sm     { font-size: 0.8rem; }
.text-xs     { font-size: 0.72rem; }
.font-titulo { font-family: var(--fuente-titulo); }
.font-bold   { font-weight: 700; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.w-full { width: 100%; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
