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

:root {
  --bg:           #000000;
  --surface:      #111111;
  --card:         #1a1a1a;
  --nav:          #2b2d30;
  --accent:       #143FA5;
  --accent-hover: #0d2d7a;
  --accent-text:  #ffffff;
  --text:         #ffffff;
  --text-muted:   #aaaaaa;
  --text-dim:     #555555;
  --border:       #2a2a2a;
}

html, body {
  height: 100%;
  background-color: var(--bg);
  font-family: sans-serif;
  color: var(--text);
}

/* ── Bubble Navbar ─────────────────────────────────────── */
.bubble-nav {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  background-color: var(--nav);
  border-radius: 9999px;
  padding: 10px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  z-index: 100;
}

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

.nav-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.nav-user {
  color: var(--text-muted);
  font-size: 0.875rem;
}

/* ── Layout ────────────────────────────────────────────── */
.dash-layout {
  display: block;
  min-height: 100vh;
}

/* Fila de navegación (una .side-item por herramienta) — reusada dentro del
   menú flotante "Herramientas" (#apps-list, ver tools.css). Antes vivían en
   el drawer. */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.side-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.side-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.side-item:hover {
  background: var(--card);
  color: var(--text);
}

.side-item.active {
  background: var(--nav);
  color: var(--accent);
}

/* ── Main ──────────────────────────────────────────────── */
.dash-main {
  padding: 40px 48px;
  max-width: 860px;
}

/* ── Panel ─────────────────────────────────────────────── */
.panel {
  display: none;
  flex-direction: column;
  gap: 28px;
}

.panel.active {
  display: flex;
}

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

.panel-sub {
  font-size: 0.9rem;
  color: #888;
  margin-top: 4px;
}

/* ── Card / Form ───────────────────────────────────────── */
.card-form, .card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
}

.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.form-row .field {
  flex: 1;
  min-width: 140px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.label-hint {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-dim);
  font-size: 0.78rem;
}

.field input,
.field select,
.field textarea {
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 0.92rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field input::placeholder,
.field textarea::placeholder {
  color: var(--text-dim);
}

.hidden {
  display: none !important;
}


/* ── Actions ───────────────────────────────────────────── */
.form-actions {
  display: flex;
  justify-content: flex-end;
}

.primary-btn {
  background-color: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 9999px;
  padding: 11px 28px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.primary-btn:hover {
  background-color: var(--accent-hover);
  transform: translateY(-1px);
}

.form-feedback {
  font-size: 0.85rem;
  text-align: right;
  color: var(--accent);
  font-weight: 600;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 10px;
}


/* Wider main area for tables */
.dash-main {
  max-width: none !important;
  padding: 112px 36px 32px;
}

/* ── KPI Cards ─────────────────────────────────────────── */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
}
.kpi-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px 20px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
.kpi-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 1.35rem;
  font-weight: 800;
  line-height: 1.1;
}
.kpi-sub {
  font-size: 0.73rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── CRM Grid & Cards ──────────────────────────────────── */
.crm-grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 800px) { .crm-grid2 { grid-template-columns: 1fr; } }

.crm-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
}
.crm-section-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 12px;
}
.chart-wrap { overflow-x: auto; }


/* ── Toolbar ───────────────────────────────────────────── */
.crm-toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}
.crm-toolbar input,
.crm-toolbar select {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s;
}
.crm-toolbar input:focus,
.crm-toolbar select:focus { border-color: var(--accent); }
.crm-toolbar input { min-width: 180px; }

/* ── Table ─────────────────────────────────────────────── */
.crm-table-wrap { overflow-x: auto; }
.crm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.crm-table th {
  background: var(--surface);
  color: var(--text-muted);
  font-weight: 700;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 2px solid var(--border);
}
.crm-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}
.crm-table tr:hover td { background: var(--card); }

.crm-muted  { color: var(--text-dim) !important; }
.crm-link   { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: none; }
.crm-link:hover { text-decoration: underline; }

/* ── POS total row ─────────────────────────────────────── */
.pos-total-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 12px;
  margin-top: 8px;
  border-top: 2px solid var(--border);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}
.crm-action-btn { cursor: pointer; font-size: 1rem; }

.pos  { color: #16a34a; font-weight: 700; }
.neg  { color: #dc2626; font-weight: 700; }
.warn { color: #d97706; font-weight: 700; }

.cuotas-badge {
  display: inline-block;
  background: rgba(20, 63, 165, 0.12);
  color: var(--accent);
  border-radius: 20px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 700;
}

/* ── Badges ────────────────────────────────────────────── */
.crm-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-green  { background: rgba(74, 222, 128, 0.15); color: #4ade80; }
.badge-yellow { background: rgba(251, 191, 36, 0.15); color: #fbbf24; }
.badge-red    { background: rgba(248, 113, 113, 0.15); color: #f87171; }
.badge-gray   { background: rgba(156, 163, 175, 0.15); color: #9ca3af; }
.badge-purple { background: rgba(167, 139, 250, 0.15); color: #a78bfa; }
.badge-blue   { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }

/* ── Movimientos Resumen ───────────────────────────────── */
.mov-resumen {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.mov-kpi {
  flex: 1;
  min-width: 100px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.3);
}
.mov-kpi-label { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.mov-kpi-value { font-size: 1.05rem; font-weight: 800; margin-top: 2px; color: var(--accent); }

/* ── Pagination ────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  padding-top: 8px;
}
.page-info {
  font-size: 0.78rem;
  color: #888;
  margin-right: 8px;
}
.page-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 0.82rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.page-btn:hover:not([disabled]) { background: var(--nav); color: var(--text); }
.page-btn.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.page-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.page-ellipsis { padding: 5px 4px; font-size: 0.82rem; color: #888; }

/* ── Modals ────────────────────────────────────────────── */
.crm-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.crm-overlay.open { display: flex; }

.crm-modal {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
}
.crm-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.crm-modal-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text);
}
.crm-modal-close {
  font-size: 1.2rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.15s;
}
.crm-modal-close:hover { color: var(--text); }

/* ── Modal Form ────────────────────────────────────────── */
.crm-form-group {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.crm-form-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.crm-label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 130px;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.crm-label input,
.crm-label select {
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  width: 100%;
  transition: border-color 0.2s;
}
.crm-label input:focus,
.crm-label select:focus { border-color: var(--accent); }

/* ── Ghost & Danger buttons ────────────────────────────── */
.ghost-btn {
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 9999px;
  padding: 9px 20px;
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.ghost-btn:hover { background: var(--nav); color: var(--text); }
.btn-danger { border-color: rgba(248, 113, 113, 0.4); color: #f87171; }
.btn-danger:hover { background: rgba(239, 68, 68, 0.15); }

/* ── Toast ─────────────────────────────────────────────── */
.crm-toast {
  position: fixed;
  bottom: 28px;
  right: 28px;
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 18px;
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  transform: translateY(20px);
  opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
  pointer-events: none;
  z-index: 1000;
}
.crm-toast.show { transform: translateY(0); opacity: 1; }

/* ── Responsive adjustments ────────────────────────────── */
@media (max-width: 768px) {
  .dash-main { padding: 20px 16px; }
  .crm-toolbar input { min-width: 140px; }
}

/* ── AI Assistant (floating bubble + chat panel) ──────────── */
.assistant-bubble {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0, 0, 0, .5);
  z-index: 998;
  transition: background-color 0.15s, transform 0.15s;
}
.assistant-bubble:hover { background: var(--accent-hover); transform: translateY(-2px); }
.assistant-bubble svg { width: 26px; height: 26px; }

.assistant-panel {
  position: fixed;
  bottom: 96px;
  right: 28px;
  width: 360px;
  max-width: calc(100vw - 40px);
  height: 480px;
  max-height: calc(100vh - 140px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .6);
  display: none;
  flex-direction: column;
  overflow: hidden;
  z-index: 999;
}
.assistant-panel.open { display: flex; }

.assistant-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.assistant-panel-title { font-size: 1rem; font-weight: 800; color: var(--text); }

.assistant-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.assistant-msg {
  max-width: 85%;
  padding: 9px 14px;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.4;
  white-space: pre-wrap;
}
.assistant-msg-user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-text);
  border-bottom-right-radius: 4px;
}
.assistant-msg-assistant {
  align-self: flex-start;
  background: var(--nav);
  color: #ffffff;
  border-bottom-left-radius: 4px;
}
.assistant-msg-pending {
  align-self: flex-start;
  max-width: 95%;
  background: var(--nav);
  color: #ffffff;
  border: 1px dashed var(--accent);
}

.assistant-msg-actions { display: flex; gap: 8px; margin-top: 10px; }
.assistant-msg-actions button { padding: 6px 14px; font-size: 0.8rem; }

.assistant-input-row {
  display: flex;
  gap: 8px;
  padding: 14px 16px;
  border-top: 1px solid var(--border);
}
.assistant-input-row input {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: 0.88rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 0.2s;
}
.assistant-input-row input:focus { border-color: var(--accent); }
.assistant-send-btn { padding: 8px 18px; font-size: 0.85rem; }

@media (max-width: 480px) {
  .assistant-panel { right: 12px; left: 12px; width: auto; bottom: 88px; }
  .assistant-bubble { right: 16px; bottom: 16px; }
}
