:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --primary: #0f172a;
  --primary-hover: #1e293b;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #06b6d4;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 10px 25px -5px rgba(15, 23, 42, 0.1), 0 8px 10px -6px rgba(15, 23, 42, 0.05);
  --sidebar-w: 240px;
}

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

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ============ LAYOUT ============ */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--primary);
  color: white;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-header .logo-icon {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 14px;
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.sidebar-header .sub {
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  margin-top: 1px;
}

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

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255, 255, 255, 0.7);
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 2px;
  transition: all 0.15s;
}

.sidebar nav a:hover {
  background: rgba(255, 255, 255, 0.06);
  color: white;
}

.sidebar nav a.active {
  background: rgba(59, 130, 246, 0.15);
  color: white;
  box-shadow: inset 3px 0 0 var(--accent);
}

.sidebar nav a svg { flex-shrink: 0; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-sm);
}

.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-info .name { font-size: 13px; font-weight: 600; color: white; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-info .role { font-size: 11px; color: rgba(255, 255, 255, 0.5); }

.logout-btn {
  color: rgba(255, 255, 255, 0.5);
  padding: 6px;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}
.logout-btn:hover { background: rgba(239, 68, 68, 0.15); color: #fca5a5; }

/* Main */
.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-height: 100vh;
}

.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar h2 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.topbar .sub {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

.hamburger {
  display: none;
  padding: 6px;
  margin-right: 12px;
}

.content { padding: 28px 32px; max-width: 1600px; }

/* ============ KPI Cards ============ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  transition: transform 0.15s;
}

.kpi:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.kpi-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}

.kpi-icon {
  width: 36px; height: 36px;
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
}
.kpi-icon.blue { background: rgba(59, 130, 246, 0.1); color: var(--accent); }
.kpi-icon.green { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.kpi-icon.orange { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.kpi-icon.purple { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }
.kpi-icon.cyan { background: rgba(6, 182, 212, 0.1); color: var(--info); }
.kpi-icon.red { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

.kpi-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin-top: 4px;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ============ Cards / Sections ============ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-head h3 {
  font-size: 15.5px;
  font-weight: 600;
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; margin-bottom: 20px; }

@media (max-width: 1024px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}

/* ============ Buttons ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }

.btn-dark { background: var(--primary); color: white; }
.btn-dark:hover { background: var(--primary-hover); }

.btn-outline { background: white; color: var(--text); border-color: var(--border); }
.btn-outline:hover { background: var(--bg); border-color: #cbd5e1; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }

.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-icon { padding: 6px; }

/* ============ Forms ============ */
.form-group { margin-bottom: 14px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 5px;
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="time"], input[type="tel"], input[type="url"],
select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: white;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

textarea { resize: vertical; min-height: 70px; }

.checkbox-label {
  display: flex; align-items: center; gap: 8px;
  cursor: pointer;
}
.checkbox-label input { width: auto; }

/* ============ Tables ============ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky; top: 0;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

.table-actions { display: flex; gap: 6px; }

.no-data {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 13.5px;
}

/* ============ Badges ============ */
.badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 12px;
  font-size: 11.5px;
  font-weight: 600;
  text-transform: capitalize;
}
.badge.blue { background: rgba(59, 130, 246, 0.12); color: var(--accent); }
.badge.green { background: rgba(16, 185, 129, 0.12); color: var(--success); }
.badge.orange { background: rgba(245, 158, 11, 0.12); color: var(--warning); }
.badge.red { background: rgba(239, 68, 68, 0.12); color: var(--danger); }
.badge.gray { background: rgba(100, 116, 139, 0.12); color: var(--text-muted); }
.badge.purple { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }

/* ============ Toolbar ============ */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.toolbar .search-input {
  min-width: 240px;
  flex: 1;
  max-width: 380px;
}

.toolbar select { max-width: 220px; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.active { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius);
  max-width: 640px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.2s ease-out;
}

.modal.wide { max-width: 900px; }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(-10px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-head h3 { font-size: 16px; font-weight: 600; }
.modal-close {
  padding: 6px;
  border-radius: 6px;
  color: var(--text-muted);
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body { padding: 22px; }

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  background: #f8fafc;
}

/* ============ Toast ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--primary);
  color: white;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  font-size: 13.5px;
  font-weight: 500;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.25s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ============ Login page ============ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
  padding: 20px;
}

.login-card {
  background: white;
  border-radius: 14px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}

.login-logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 22px;
  margin: 0 auto 22px;
  box-shadow: 0 8px 20px rgba(59, 130, 246, 0.35);
}

.login-card h1 {
  text-align: center;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}
.login-card p.subtitle {
  text-align: center;
  color: var(--text-muted);
  font-size: 13.5px;
  margin-bottom: 28px;
}

.login-hint {
  background: #eff6ff;
  border: 1px solid #dbeafe;
  color: #1e40af;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 16px;
  text-align: center;
}

.login-btn {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  margin-top: 6px;
}

.login-error {
  background: #fee2e2;
  color: #991b1b;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 14px;
  display: none;
}
.login-error.show { display: block; }

/* ============ Chart container ============ */
.chart-container {
  position: relative;
  width: 100%;
}
.chart-container.h280 { height: 280px; }
.chart-container.h240 { height: 240px; }

/* ============ Product card grid ============ */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.product-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: transform 0.15s, box-shadow 0.15s;
  cursor: pointer;
}

.product-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }

.product-image {
  width: 100%;
  height: 160px;
  object-fit: cover;
  background: #f1f5f9;
}

.product-body { padding: 14px; }
.product-body .ref { font-size: 11.5px; color: var(--text-muted); font-family: monospace; letter-spacing: 0.03em; }
.product-body h4 { font-size: 14.5px; font-weight: 600; margin: 4px 0 6px; line-height: 1.3; }
.product-body .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; }
.product-body .price { font-size: 16px; font-weight: 700; color: var(--text); }
.product-body .badges { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

/* ============ Agenda / Calendar ============ */
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.calendar-head {
  background: var(--primary);
  color: white;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
}

.calendar-day {
  background: white;
  min-height: 90px;
  padding: 8px;
  position: relative;
  font-size: 12.5px;
}

.calendar-day.other-month { background: #f8fafc; color: var(--text-muted); }
.calendar-day.today { background: #eff6ff; }
.calendar-day .day-num { font-weight: 600; margin-bottom: 4px; }

.calendar-event {
  background: var(--accent);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 10.5px;
  margin-bottom: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.calendar-event.visita { background: var(--success); }
.calendar-event.demo { background: var(--warning); }
.calendar-event.llamada { background: var(--info); }
.calendar-event.formacion { background: #8b5cf6; }

.calendar-controls {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.calendar-controls h3 { font-size: 18px; font-weight: 600; text-transform: capitalize; }

/* ============ Admin tabs ============ */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 16px;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-color: var(--accent); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* ============ Detail view ============ */
.detail-header {
  display: flex; align-items: flex-start; gap: 20px; margin-bottom: 24px;
}
.detail-header .avatar {
  width: 64px; height: 64px;
  border-radius: 14px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; font-weight: 700;
  flex-shrink: 0;
}
.detail-header h2 { font-size: 22px; margin-bottom: 4px; }
.detail-header .meta { color: var(--text-muted); font-size: 13.5px; }

.info-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; }
.info-list dt { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; font-weight: 600; margin-bottom: 2px; }
.info-list dd { font-size: 13.5px; }

.timeline { border-left: 2px solid var(--border); padding-left: 16px; margin-left: 6px; }
.timeline-item { position: relative; margin-bottom: 16px; }
.timeline-item::before {
  content: ''; position: absolute; left: -22px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid white; box-shadow: 0 0 0 2px var(--accent);
}
.timeline-item .date { font-size: 11.5px; color: var(--text-muted); }
.timeline-item .content { margin-top: 3px; font-size: 13.5px; }

/* ============ Responsive ============ */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .hamburger { display: inline-flex; }
  .content { padding: 20px 16px; }
  .topbar { padding: 14px 16px; }
  .kpi-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .kpi-value { font-size: 22px; }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .calendar-day { min-height: 60px; padding: 4px; font-size: 11px; }
  .toolbar .search-input { min-width: 100%; }
}

/* ============ Utilities ============ */
.txt-muted { color: var(--text-muted); }
.txt-right { text-align: right; }
.txt-center { text-align: center; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 12px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.hidden { display: none; }
.overflow-x { overflow-x: auto; }
