/* =============================================================
   QUALITAS DIGITAL SERVICES — dashboard.css
   Design: deep navy base, electric teal accent, data-dense grid
   Font: Inter (UI) + JetBrains Mono (SQL/code)
   ============================================================= */

:root {
  --bg-base:       #0d1117;
  --bg-surface:    #161b27;
  --bg-elevated:   #1e2533;
  --bg-hover:      #252d3f;
  --border:        #2a3347;
  --border-subtle: #1e2533;

  --accent:        #00d4aa;
  --accent-dim:    rgba(0,212,170,.12);
  --accent-hover:  #00f0c2;
  --blue:          #4f8ef7;
  --blue-dim:      rgba(79,142,247,.12);
  --orange:        #f7934f;
  --orange-dim:    rgba(247,147,79,.12);
  --red:           #f7514f;
  --red-dim:       rgba(247,81,79,.12);
  --yellow:        #f7d44f;
  --yellow-dim:    rgba(247,212,79,.12);

  --text-primary:  #e8eaf0;
  --text-secondary:#8b95aa;
  --text-muted:    #5a6478;

  --sidebar-w:     240px;
  --topbar-h:      56px;
  --radius:        10px;
  --radius-sm:     6px;
  --shadow:        0 4px 24px rgba(0,0,0,.4);
  --transition:    .18s cubic-bezier(.4,0,.2,1);
}

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

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
}

/* ── SCROLLBAR ──────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ── SIDEBAR ────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: width var(--transition), transform var(--transition);
  overflow: hidden;
}

.sidebar.collapsed { width: 64px; }
.sidebar.collapsed .brand-text,
.sidebar.collapsed .nav-item span,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .badge-ai,
.sidebar.collapsed .user-info span { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 10px; }
.sidebar.collapsed .sidebar-brand { padding: 16px 12px; justify-content: center; }
.sidebar.collapsed .brand-icon { margin: 0; }

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}
.brand-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), #00a082);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: #0d1117; font-size: 16px;
  flex-shrink: 0;
}
.brand-name  { display: block; font-weight: 700; font-size: 13px; color: var(--text-primary); }
.brand-sub   { display: block; font-size: 10px; color: var(--text-muted); letter-spacing: .04em; }

.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }

.nav-section-label {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 16px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
  transition: background var(--transition), color var(--transition);
  position: relative;
  margin-bottom: 2px;
}
.nav-item i { font-size: 16px; flex-shrink: 0; width: 18px; text-align: center; }
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 4px; bottom: 4px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}
.badge-ai {
  margin-left: auto;
  background: linear-gradient(135deg, var(--accent), #00a082);
  color: #0d1117;
  font-size: 9px;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: .05em;
}

.sidebar-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.user-info {
  display: flex; align-items: center; gap: 8px;
  color: var(--text-secondary); font-size: 13px;
}
.btn-logout {
  color: var(--text-muted);
  font-size: 18px;
  text-decoration: none;
  transition: color var(--transition);
}
.btn-logout:hover { color: var(--red); }

/* ── MAIN WRAPPER ───────────────────────────────────────────── */
.main-wrapper {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left var(--transition);
}
.main-wrapper.sidebar-collapsed { margin-left: 64px; }

/* ── TOPBAR ─────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
}
.sidebar-toggle {
  background: none; border: none;
  color: var(--text-secondary);
  cursor: pointer; padding: 4px;
  border-radius: var(--radius-sm);
  transition: color var(--transition);
}
.sidebar-toggle:hover { color: var(--accent); }
.topbar-breadcrumb { flex: 1; font-size: 13px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

/* ── CONTENT ────────────────────────────────────────────────── */
.content-area {
  flex: 1;
  padding: 24px;
  max-width: 1600px;
  width: 100%;
}

/* ── PAGE HEADER ────────────────────────────────────────────── */
.page-header {
  margin-bottom: 24px;
}
.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.page-header p { color: var(--text-secondary); font-size: 13px; }

/* ── KPI CARDS ──────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}
.kpi-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.kpi-card::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, var(--accent-dim));
  pointer-events: none;
}
.kpi-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 12px;
}
.kpi-icon.teal   { background: var(--accent-dim);  color: var(--accent);  }
.kpi-icon.blue   { background: var(--blue-dim);    color: var(--blue);    }
.kpi-icon.orange { background: var(--orange-dim);  color: var(--orange);  }
.kpi-icon.red    { background: var(--red-dim);     color: var(--red);     }
.kpi-icon.yellow { background: var(--yellow-dim);  color: var(--yellow);  }

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}
.kpi-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-top: 4px;
}
.kpi-delta {
  font-size: 11px;
  margin-top: 6px;
  display: flex; align-items: center; gap: 3px;
}
.kpi-delta.up   { color: var(--accent); }
.kpi-delta.down { color: var(--red); }

/* ── PANELS / CARDS ─────────────────────────────────────────── */
.panel {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.panel-title i { color: var(--accent); }
.panel-body { padding: 20px; }
.panel-body.p0 { padding: 0; }

/* ── CHART CONTAINERS ───────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 240px;
}
.chart-wrap canvas { max-height: 240px; }

/* ── TABLES ─────────────────────────────────────────────────── */
.qds-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.qds-table thead th {
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .07em;
  text-transform: uppercase;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.qds-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition);
}
.qds-table tbody tr:hover { background: var(--bg-hover); }
.qds-table tbody td { padding: 9px 14px; color: var(--text-primary); }
.qds-table tbody tr:last-child { border-bottom: none; }

/* ── BADGES ─────────────────────────────────────────────────── */
.badge-qds {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.badge-activo, .badge-cobrada, .badge-completado, .badge-ganado, .badge-resuelto, .badge-cerrado {
  background: rgba(0,212,170,.15); color: var(--accent);
}
.badge-cancelado, .badge-baja, .badge-impagada, .badge-perdido {
  background: var(--red-dim); color: var(--red);
}
.badge-moroso, .badge-vencida, .badge-alta, .badge-critico {
  background: var(--orange-dim); color: var(--orange);
}
.badge-pendiente, .badge-en_curso, .badge-medio, .badge-media {
  background: var(--blue-dim); color: var(--blue);
}
.badge-prospecto, .badge-inactivo, .badge-bajo, .badge-baja-p {
  background: rgba(255,255,255,.06); color: var(--text-muted);
}

/* ── CHURN METER ────────────────────────────────────────────── */
.churn-bar {
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
  width: 80px;
  display: inline-block;
  vertical-align: middle;
}
.churn-fill {
  height: 100%;
  border-radius: 2px;
  transition: width .4s;
}

/* ── LOGIN PAGE ─────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  background: var(--bg-base);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.login-logo {
  display: flex; flex-direction: column; align-items: center;
  margin-bottom: 28px;
}
.login-logo .logo-icon {
  width: 52px; height: 52px;
  background: linear-gradient(135deg, var(--accent), #00a082);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; color: #0d1117;
  margin-bottom: 10px;
}
.login-logo h1 { font-size: 18px; font-weight: 700; margin: 0; }
.login-logo p  { font-size: 12px; color: var(--text-muted); margin: 2px 0 0; }

/* ── FORM CONTROLS ──────────────────────────────────────────── */
.form-control, .form-select {
  background: var(--bg-elevated) !important;
  border: 1px solid var(--border) !important;
  color: var(--text-primary) !important;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--accent) !important;
  box-shadow: 0 0 0 2px var(--accent-dim) !important;
}
.form-label { color: var(--text-secondary); font-size: 12px; font-weight: 600; }

/* ── BUTTONS ────────────────────────────────────────────────── */
.btn-accent {
  background: var(--accent);
  color: #0d1117;
  border: none;
  font-weight: 700;
  border-radius: var(--radius-sm);
  padding: 8px 18px;
  font-size: 13.5px;
  transition: background var(--transition), transform var(--transition);
}
.btn-accent:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-outline-primary { border-color: var(--accent) !important; color: var(--accent) !important; }
.btn-outline-primary:hover { background: var(--accent-dim) !important; }
.btn-outline-success { border-color: var(--blue) !important; color: var(--blue) !important; }
.btn-outline-success:hover { background: var(--blue-dim) !important; }

/* ── IA SECTION ─────────────────────────────────────────────── */
.ia-prompt-area {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.ia-textarea {
  width: 100%;
  min-height: 72px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 14px;
  resize: vertical;
  font-family: inherit;
  transition: border-color var(--transition);
}
.ia-textarea:focus { outline: none; border-color: var(--accent); }

.sql-block {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: 'JetBrains Mono', monospace;
  font-size: 12.5px;
  color: #a8d8c8;
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
}

.ia-interpretation {
  background: var(--accent-dim);
  border: 1px solid rgba(0,212,170,.2);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-size: 13.5px;
  color: var(--text-primary);
  line-height: 1.7;
  margin-bottom: 16px;
}

.ia-suggestions {
  display: flex; flex-wrap: wrap; gap: 8px;
  margin-top: 12px;
}
.ia-suggestion-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  cursor: pointer;
  transition: all var(--transition);
}
.ia-suggestion-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── LOADING SPINNER ────────────────────────────────────────── */
.spinner-qds {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 24px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FICHA CLIENTE 360 ──────────────────────────────────────── */
.cliente-360-header {
  background: linear-gradient(135deg, var(--bg-elevated), var(--bg-surface));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  display: flex; align-items: flex-start; gap: 20px;
}
.cliente-avatar {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, var(--accent), #00a082);
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; color: #0d1117; font-weight: 700;
  flex-shrink: 0;
}
.cliente-meta h2 { font-size: 20px; font-weight: 700; margin-bottom: 4px; }
.cliente-meta p  { color: var(--text-secondary); font-size: 13px; }

/* ── PAGINATION ─────────────────────────────────────────────── */
.pagination .page-link {
  background: var(--bg-elevated);
  border-color: var(--border);
  color: var(--text-secondary);
  font-size: 12px;
}
.pagination .page-link:hover  { background: var(--bg-hover); color: var(--accent); }
.pagination .page-item.active .page-link {
  background: var(--accent); border-color: var(--accent); color: #0d1117;
}

/* ── RISK INDICATOR ─────────────────────────────────────────── */
.risk-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}
.risk-dot.critico { background: var(--red);    box-shadow: 0 0 6px var(--red); }
.risk-dot.alto    { background: var(--orange); box-shadow: 0 0 6px var(--orange); }
.risk-dot.medio   { background: var(--blue);   }
.risk-dot.bajo    { background: var(--text-muted); }

/* ── RESPONSIVE ─────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.mobile-open { transform: translateX(0); }
  .main-wrapper { margin-left: 0 !important; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .content-area { padding: 16px; }
}

/* ── UTILS ──────────────────────────────────────────────────── */
.fw-500 { font-weight: 500; }
.font-mono { font-family: 'JetBrains Mono', monospace; }
.text-accent { color: var(--accent) !important; }
.text-dim    { color: var(--text-muted); }
.gap-row { display: flex; flex-direction: column; gap: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }
@media (max-width: 1024px) { .grid-3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 768px)  { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
