/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:      #ff1800;
  --red-dark: #cc1200;
  --black:    #111111;
  --white:    #ffffff;
  --grey-100: #f5f5f5;
  --grey-200: #ebebeb;
  --grey-300: #d1d1d1;
  --grey-500: #888888;
  --grey-700: #444444;
  --green:    #22c55e;
  --orange:   #f97316;
  --urgent:   #7c3aed;
  --sidebar-w: 240px;
  --radius:   8px;
  --shadow:   0 2px 12px rgba(0,0,0,0.10);
}

html, body { height: 100%; }

body {
  font-family: 'Avenir Next', 'Avenir', -apple-system, BlinkMacSystemFont,
    'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  color: var(--black);
  background: var(--grey-100);
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--grey-300); border-radius: 99px; }

/* ── Typography ────────────────────────────────────────────── */
h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.3px; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 14px; font-weight: 600; }

/* ── Utilities ─────────────────────────────────────────────── */
.hidden   { display: none !important; }
.flex     { display: flex; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.gap-16   { gap: 16px; }
.mt-8     { margin-top: 8px; }
.mt-16    { margin-top: 16px; }
.mt-24    { margin-top: 24px; }
.mb-16    { margin-bottom: 16px; }
.text-sm  { font-size: 12px; }
.text-muted { color: var(--grey-500); }
.font-semibold { font-weight: 600; }
.w-full   { width: 100%; }
.center   { text-align: center; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-weight: 500;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn:hover  { opacity: .88; }

.btn-primary   { background: var(--red); color: #fff; }
.btn-secondary { background: var(--black); color: #fff; }
.btn-ghost     { background: transparent; color: var(--grey-700); border: 1px solid var(--grey-300); }
.btn-danger    { background: #fee2e2; color: #b91c1c; }
.btn-sm        { padding: 5px 10px; font-size: 12px; }
.btn-icon      { padding: 6px; border-radius: 6px; }

/* ── Inputs ────────────────────────────────────────────────── */
.input, input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--grey-300);
  border-radius: var(--radius);
  background: var(--white);
  color: var(--black);
  transition: border-color .15s;
  outline: none;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--red);
}
label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--grey-700);
  margin-bottom: 4px;
}
.form-group { margin-bottom: 14px; }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card-sm { padding: 14px 16px; }

/* ── Badge ─────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}
.badge-ecommerce    { background: #dbeafe; color: #1d4ed8; }
.badge-leads        { background: #dcfce7; color: #15803d; }
.badge-infoproducto { background: #fef3c7; color: #b45309; }
.badge-admin        { background: #f3e8ff; color: #7c3aed; }
.badge-user         { background: #e0f2fe; color: #0369a1; }

/* ── Traffic Light ─────────────────────────────────────────── */
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.dot-green  { background: var(--green); }
.dot-orange { background: var(--orange); }
.dot-red    { background: var(--red); }
.dot-grey   { background: var(--grey-300); }

.kpi-status-green  { background: #dcfce7; color: #15803d; }
.kpi-status-orange { background: #fff7ed; color: #c2410c; }
.kpi-status-red    { background: #fee2e2; color: #b91c1c; }
.kpi-status-grey   { background: var(--grey-100); color: var(--grey-500); }

/* ── Alerts ────────────────────────────────────────────────── */
.alert-card {
  border-radius: var(--radius);
  padding: 14px 16px;
  border-left: 4px solid transparent;
  background: var(--white);
  box-shadow: var(--shadow);
  margin-bottom: 10px;
}
.alert-card.urgent   { border-left-color: var(--urgent); background: #f5f0fe; }
.alert-card.critical { border-left-color: var(--red); background: #fff5f5; }
.alert-card.high     { border-left-color: var(--orange); background: #fffaf5; }
.alert-card.medium   { border-left-color: #eab308; background: #fefdf0; }

.alert-title   { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.alert-message { font-size: 12px; color: var(--grey-700); margin-bottom: 6px; }
.alert-action  { font-size: 12px; color: var(--black); font-weight: 500; }
.alert-badge   {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
  margin-top: 6px;
}
.alert-badge.escalate    { background: #fee2e2; color: #b91c1c; }
.alert-badge.self-resolve { background: #dcfce7; color: #15803d; }

/* ── Checklist ─────────────────────────────────────────────── */
.checklist-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: background .1s;
  border: 1px solid transparent;
}
.checklist-item:hover { background: var(--grey-100); }
.checklist-item.checked { opacity: .6; }
.checklist-item input[type=checkbox] {
  width: 16px; height: 16px;
  accent-color: var(--green);
  cursor: pointer;
  flex-shrink: 0;
}
.checklist-item span { font-size: 13px; }
.checklist-item.checked span { text-decoration: line-through; color: var(--grey-500); }
.checklist-meta { font-size: 10px; color: var(--grey-500); margin-left: auto; white-space: nowrap; }

/* ── Modal ─────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}
.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--grey-500);
  line-height: 1;
}
.modal-close:hover { color: var(--black); }

/* ── Toast ─────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  padding: 12px 18px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
  animation: slideIn .2s ease;
  min-width: 220px;
}
.toast.success { background: #16a34a; }
.toast.error   { background: var(--red); }
.toast.info    { background: var(--black); }
@keyframes slideIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }

/* ── Login Page ────────────────────────────────────────────── */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--black);
  padding: 24px;
}
.login-box {
  background: var(--white);
  border-radius: 16px;
  padding: 48px 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}
.login-logo .logo-mark {
  width: 36px; height: 36px;
  background: var(--red);
  border-radius: 8px;
}
.login-logo .logo-text {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--black);
  line-height: 1.3;
}
.login-logo .logo-sub {
  font-size: 10px;
  font-weight: 400;
  color: var(--grey-500);
  letter-spacing: .3px;
}
.login-title { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-sub   { font-size: 13px; color: var(--grey-500); margin-bottom: 28px; }
#login-error {
  background: #fee2e2;
  color: #b91c1c;
  padding: 10px 12px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 16px;
}
.login-btn {
  width: 100%;
  padding: 12px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
  transition: background .15s;
}
.login-btn:hover { background: var(--red-dark); }

/* ── App Shell ─────────────────────────────────────────────── */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: var(--black);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 30px; height: 30px;
  background: var(--red);
  border-radius: 6px;
  flex-shrink: 0;
}
.brand-text {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .5px;
  text-transform: uppercase;
  color: var(--white);
  line-height: 1.3;
}
.brand-sub {
  font-size: 10px;
  font-weight: 400;
  color: rgba(255,255,255,.4);
  letter-spacing: .3px;
}
.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: rgba(255,255,255,.3);
  padding: 14px 20px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: rgba(255,255,255,.6);
  cursor: pointer;
  transition: all .15s;
  font-size: 13px;
  font-weight: 500;
  border-radius: 0;
  position: relative;
}
.nav-item:hover { color: var(--white); background: rgba(255,255,255,.06); }
.nav-item.active {
  color: var(--white);
  background: rgba(255,255,255,.1);
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--red);
  border-radius: 0 2px 2px 0;
}
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--red);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 12px; font-weight: 600; color: var(--white); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 10px; color: rgba(255,255,255,.4); }
.btn-logout {
  width: 100%;
  padding: 7px;
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.5);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  padding-left: 12px;
  transition: all .15s;
}
.btn-logout:hover { background: rgba(255,255,255,.1); color: var(--white); }

/* Main content */
#main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#page-header {
  background: var(--white);
  padding: 16px 28px;
  border-bottom: 1px solid var(--grey-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#page-header h1 { font-size: 18px; }
#content { flex: 1; overflow-y: auto; padding: 24px 28px; }

/* Sections */
.section { display: none; }
.section.active { display: block; }

/* ── Client List ───────────────────────────────────────────── */
.client-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-top: 20px;
}
.client-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, box-shadow .15s;
  border: 1.5px solid transparent;
}
.client-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,.13);
  border-color: var(--grey-200);
}
.client-card-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 10px; }
.client-card-name { font-weight: 700; font-size: 15px; }
.client-card-buyer { font-size: 11px; color: var(--grey-500); margin-top: 2px; }
.client-card-kpis { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.kpi-pill {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 99px;
  font-weight: 500;
}
.kpi-pill-green  { background: #dcfce7; color: #15803d; }
.kpi-pill-orange { background: #fff7ed; color: #c2410c; }
.kpi-pill-red    { background: #fee2e2; color: #b91c1c; }
.kpi-pill-grey   { background: var(--grey-100); color: var(--grey-500); }

/* ── Client Detail ─────────────────────────────────────────── */
.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.back-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 20px;
  color: var(--grey-500);
  padding: 0;
  line-height: 1;
}
.back-btn:hover { color: var(--black); }
.detail-title { font-size: 22px; font-weight: 700; }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--grey-200);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 18px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  color: var(--grey-500);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.tab:hover { color: var(--black); }
.tab.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }
.tab-badge {
  background: var(--red);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 99px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
}

/* KPI Table */
.kpi-section-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .7px;
  color: var(--grey-500);
  margin: 20px 0 10px;
}
.kpi-section-title:first-child { margin-top: 0; }
.kpi-table { width: 100%; border-collapse: collapse; }
.kpi-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--grey-500);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--grey-200);
}
.kpi-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--grey-100);
  vertical-align: middle;
}
.kpi-table tr:last-child td { border-bottom: none; }
.kpi-table tr:hover td { background: var(--grey-100); }
.kpi-name-cell { font-weight: 500; font-size: 13px; }
.kpi-value { font-size: 15px; font-weight: 700; }
.kpi-value.empty { color: var(--grey-300); font-weight: 400; }
.kpi-objective { font-size: 12px; color: var(--grey-500); }
.kpi-status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 99px;
}
.editable-val {
  cursor: pointer;
  border-bottom: 1px dashed var(--grey-300);
}
.editable-val:hover { border-bottom-color: var(--red); }
.meta-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  background: #dbeafe;
  color: #1d4ed8;
  padding: 1px 5px;
  border-radius: 3px;
  margin-left: 4px;
  text-transform: uppercase;
  letter-spacing: .3px;
}

/* ── Period Selector ───────────────────────────────────────── */
.period-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}
.period-selector select {
  width: auto;
  padding: 6px 10px;
  font-size: 13px;
}

/* ── Users Page ─────────────────────────────────────────────── */
.users-table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.users-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--grey-500);
  text-transform: uppercase;
  letter-spacing: .5px;
  padding: 12px 16px;
  border-bottom: 2px solid var(--grey-200);
  background: var(--grey-100);
}
.users-table td { padding: 12px 16px; border-bottom: 1px solid var(--grey-100); font-size: 13px; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--grey-100); }
.table-actions { display: flex; gap: 6px; }

/* ── Empty State ────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--grey-500);
}
.empty-state .empty-icon { font-size: 40px; margin-bottom: 16px; }
.empty-state h3 { color: var(--black); margin-bottom: 6px; }
.empty-state p { font-size: 13px; max-width: 300px; margin: 0 auto; }

/* ── Loading Spinner ────────────────────────────────────────── */
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--grey-200);
  border-top-color: var(--red);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Log ────────────────────────────────────────────────────── */
.log-list { display: flex; flex-direction: column; gap: 6px; }
.log-item {
  padding: 10px 14px;
  background: var(--grey-100);
  border-radius: 6px;
  font-size: 12px;
}
.log-item-header { display: flex; justify-content: space-between; margin-bottom: 2px; gap: 8px; }
.log-item-user { font-weight: 600; }
.log-item-date { color: var(--grey-500); white-space: nowrap; }
.log-item-detail { color: var(--grey-700); }
.log-item-source {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 10px;
  margin-right: 6px;
  background: var(--grey-200);
  color: var(--grey-700);
}
.log-item.meta.automated .log-item-source { background: var(--grey-200); color: var(--grey-500); }
.log-item.meta:not(.automated) .log-item-source { background: #e0e7ff; color: #3730a3; }

/* ── Marketing dashboard ───────────────────────────────────── */
.filter-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-pill {
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: var(--grey-100);
  color: var(--grey-700);
  border: 1px solid transparent;
  cursor: pointer;
}
.filter-pill:hover { background: var(--grey-200); }
.filter-pill.active { background: var(--red); color: var(--white); }

.mkt-row { cursor: pointer; }
.mkt-row.selected td { background: var(--grey-100); }
.mkt-metric-real { font-weight: 700; font-size: 13px; }
.mkt-metric-obj { font-size: 11px; color: var(--grey-500); }

.mkt-chart-legend { display: flex; gap: 18px; flex-wrap: wrap; padding: 12px 20px 4px; border-top: 1px solid var(--grey-100); }
.mkt-chart-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--grey-700); white-space: nowrap; }
.mkt-chart-swatch { display: inline-block; width: 14px; height: 3px; border-radius: 2px; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 200px; }
  #content { padding: 16px; }
  .client-grid { grid-template-columns: 1fr; }
}
