/* ============================================================
   CRM EGTOC — sistema de diseño
   Paleta de marca (la misma del Asistente IA en admin-engine):
   degradé #1f6feb → #22b8e6 → #24d6b4. Estética tipo macOS:
   superficies translúcidas, blur, esquinas suaves, tipografía nítida.
   ============================================================ */

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

:root {
  --brand-1: #1f6feb;
  --brand-2: #22b8e6;
  --brand-3: #24d6b4;
  --brand-gradient: linear-gradient(135deg, var(--brand-1), var(--brand-2) 55%, var(--brand-3));

  --bg: #f2f3f7;
  --bg-elevated: rgba(255, 255, 255, 0.72);
  --surface: rgba(255, 255, 255, 0.86);
  --surface-solid: #ffffff;
  --surface-sunken: #eaecf2;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);

  --ink: #14181f;
  --ink-soft: #5b6472;
  --ink-faint: #8b93a1;

  --danger: #e5484d;
  --warning: #c9a15a;
  --success: #1f9d55;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08), 0 2px 6px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 24px 60px rgba(15, 23, 42, 0.16), 0 8px 20px rgba(15, 23, 42, 0.06);
  --shadow-glow: 0 0 0 1px rgba(34, 184, 230, 0.28), 0 12px 32px rgba(31, 111, 235, 0.22);

  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --blur: saturate(180%) blur(20px);

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0e13;
    --bg-elevated: rgba(22, 25, 33, 0.72);
    --surface: rgba(28, 31, 40, 0.82);
    --surface-solid: #1a1d25;
    --surface-sunken: #14161d;
    --border: rgba(255, 255, 255, 0.08);
    --border-strong: rgba(255, 255, 255, 0.14);

    --ink: #f2f4f8;
    --ink-soft: #a8afbc;
    --ink-faint: #6b7280;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.5;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
::selection { background: var(--brand-2); color: #fff; }

/* ---- Scrollbars, tipo macOS ---- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: rgba(120, 130, 150, 0.35); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: rgba(120, 130, 150, 0.55); background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---- Layout ---- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg-elevated);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 18px;
}
.sidebar__brand-mark {
  width: 30px; height: 30px; border-radius: 9px;
  background: var(--brand-gradient);
  box-shadow: var(--shadow-glow);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.sidebar__brand-mark svg { width: 19px; height: 19px; }
.sidebar__brand-text { font-weight: 800; font-size: 15px; letter-spacing: -0.01em; }
.sidebar__brand-text span { display: block; font-weight: 500; font-size: 11px; color: var(--ink-faint); letter-spacing: 0.02em; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav__item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  font-weight: 500; color: var(--ink-soft);
  cursor: pointer; transition: background 0.15s var(--ease), color 0.15s var(--ease);
  user-select: none;
}
.nav__item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.85; }
.nav__item:hover { background: rgba(120, 130, 150, 0.1); color: var(--ink); }
.nav__item.is-active {
  background: var(--surface-solid);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}
.nav__item.is-active svg { color: var(--brand-1); opacity: 1; }

.sidebar__footer {
  margin-top: auto;
  padding: 10px 8px 4px;
  display: flex; align-items: center; gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.avatar {
  width: 28px; height: 28px; border-radius: 999px;
  background: var(--brand-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px;
  flex-shrink: 0;
}
.sidebar__user { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar__logout { margin-left: auto; color: var(--ink-faint); opacity: 0.7; }
.sidebar__logout:hover { opacity: 1; color: var(--danger); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.topbar__title { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.topbar__spacer { flex: 1; }

.content { flex: 1; overflow-y: auto; padding: 24px; }

/* ---- Cards / surfaces ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  backdrop-filter: var(--blur);
  -webkit-backdrop-filter: var(--blur);
}
.card--solid { background: var(--surface-solid); backdrop-filter: none; -webkit-backdrop-filter: none; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600; font-size: 13px;
  cursor: pointer;
  transition: transform 0.12s var(--ease), box-shadow 0.15s var(--ease), background 0.15s var(--ease), border-color 0.15s var(--ease);
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn--primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: var(--shadow-glow);
}
.btn--primary:hover { filter: brightness(1.06); }
.btn--ghost {
  background: transparent;
  border-color: var(--border-strong);
  color: var(--ink);
}
.btn--ghost:hover { background: rgba(120, 130, 150, 0.1); }
.btn--danger { background: var(--danger); color: #fff; }
.btn--sm { height: 28px; padding: 0 10px; font-size: 12px; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; pointer-events: none; }

/* ---- Inputs ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--ink-soft); }
.input, .textarea, select.input {
  width: 100%;
  border: 1px solid var(--border-strong);
  background: var(--surface-solid);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.textarea { resize: vertical; min-height: 90px; font-family: var(--font-mono); }
.input:focus, .textarea:focus, select.input:focus {
  outline: none;
  border-color: var(--brand-2);
  box-shadow: 0 0 0 3px rgba(34, 184, 230, 0.18);
}

/* ---- Pipeline board ---- */
.board { display: flex; gap: 16px; height: 100%; overflow-x: auto; padding-bottom: 8px; }
.board-column { width: 268px; flex-shrink: 0; display: flex; flex-direction: column; }
.board-column__head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 10px; }
.board-column__dot { width: 8px; height: 8px; border-radius: 999px; flex-shrink: 0; }
.board-column__title { font-weight: 700; font-size: 13px; }
.board-column__count {
  margin-left: auto; font-size: 11px; font-weight: 700; color: var(--ink-faint);
  background: var(--surface-sunken); border-radius: 999px; padding: 1px 7px;
}
.board-column__list { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }

.deal-card {
  padding: 12px 12px 12px 10px;
  cursor: grab;
  border-left-width: 4px;
  border-left-style: solid;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease), border-left-color 0.2s var(--ease);
}
.deal-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.deal-card.is-dragging { opacity: 0.4; }
.deal-card__title { font-weight: 700; font-size: 13px; margin-bottom: 4px; }
.deal-card__contact { font-size: 12px; color: var(--ink-soft); }
.deal-card__meta { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.deal-card__value { font-family: var(--font-mono); font-size: 12px; font-weight: 600; color: var(--brand-1); }

/* ---- Tables / lists ---- */
.list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s var(--ease);
}
.list-row:hover { background: rgba(120, 130, 150, 0.06); }
.list-row:last-child { border-bottom: none; }

/* ---- Badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 999px;
  background: var(--surface-sunken); color: var(--ink-soft);
}
/* ---- Stage age indicator ---- */
.age-dot {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  color: var(--ink-faint);
}
.age-dot::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0;
}
.age-dot--fresh::before { background: var(--success); }
.age-dot--warn::before { background: var(--warning); }
.age-dot--stale::before { background: var(--danger); box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.14); }
.age-dot--stale { color: var(--danger); }

.age-dot--clickable {
  cursor: pointer;
  font-size: 12px;
  padding: 4px 9px 4px 7px;
  border-radius: 999px;
  background: var(--surface-sunken);
  transition: background 0.15s var(--ease), transform 0.1s var(--ease);
}
.age-dot--clickable::before { width: 7px; height: 7px; }
.age-dot--clickable:hover { background: var(--border-strong); }
.age-dot--clickable:active { transform: scale(0.94); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; flex-shrink: 0;
  border-radius: 999px;
  color: var(--ink-faint);
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s var(--ease), color 0.15s var(--ease), transform 0.1s var(--ease);
}
.icon-btn:hover { background: var(--surface-sunken); color: var(--ink); }
.icon-btn:active { transform: scale(0.92); }

/* ---- Timeline ---- */
.timeline { display: flex; flex-direction: column; gap: 0; }
.timeline-item { display: flex; gap: 12px; padding: 10px 0; position: relative; }
.timeline-item::before {
  content: ''; position: absolute; left: 5px; top: 26px; bottom: -10px; width: 1px;
  background: var(--border-strong);
}
.timeline-item:last-child::before { display: none; }
.timeline-dot { width: 11px; height: 11px; border-radius: 999px; margin-top: 3px; flex-shrink: 0; background: var(--brand-2); box-shadow: 0 0 0 3px var(--bg); z-index: 1; }
.timeline-body { flex: 1; }
.timeline-title { font-size: 13px; font-weight: 600; }
.timeline-meta { font-size: 11.5px; color: var(--ink-faint); margin-top: 1px; }
.timeline-text { font-size: 13px; color: var(--ink-soft); margin-top: 4px; white-space: pre-wrap; }

/* ---- Modal / sheet ---- */
.overlay {
  position: fixed; inset: 0; background: rgba(10, 12, 18, 0.4);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; animation: fade-in 0.18s var(--ease);
}
.sheet {
  width: min(520px, 92vw); max-height: 86vh; overflow-y: auto;
  background: var(--surface-solid);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 22px;
  animation: sheet-in 0.22s var(--ease);
}
.sheet__head { display: flex; align-items: center; margin-bottom: 16px; }
.sheet__title { font-weight: 800; font-size: 16px; }
.sheet__close { margin-left: auto; width: 30px; height: 30px; font-size: 20px; line-height: 1; }
.sheet__foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes sheet-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ---- Empty / loading states ---- */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 60px 20px; color: var(--ink-faint); text-align: center; gap: 6px; }
.spinner {
  width: 20px; height: 20px; border-radius: 999px;
  border: 2px solid var(--border-strong); border-top-color: var(--brand-2);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-stack { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--surface-solid); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
  padding: 10px 14px; font-size: 13px; font-weight: 600;
  animation: sheet-in 0.2s var(--ease);
}
.toast--error { border-color: rgba(229, 72, 77, 0.4); color: var(--danger); }

/* ---------- Web (contador de visitas) ---------- */
.web-mini { display: flex; gap: 18px; text-align: right; }
.web-mini div { display: flex; flex-direction: column; min-width: 58px; }
.web-mini b { font-size: 16px; font-variant-numeric: tabular-nums; }
.web-mini span { font-size: 11px; color: var(--ink-faint); }
.web-head { margin-bottom: 12px; }
.web-kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 12px; }
.web-kpi { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.web-kpi b { font-size: 28px; font-weight: 800; letter-spacing: -0.5px; background: var(--brand-gradient); -webkit-background-clip: text; background-clip: text; color: transparent; font-variant-numeric: tabular-nums; }
.web-kpi span { font-size: 12px; color: var(--ink-soft); }
.web-box { padding: 16px; margin-bottom: 12px; }
.web-box__title { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); margin-bottom: 12px; }
.web-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.web-grid .web-box { margin-bottom: 0; }
.web-chart { width: 100%; height: auto; display: block; }
.web-chart rect { fill: var(--brand-1); opacity: .85; }
.web-chart text { font-size: 11px; fill: var(--ink-faint); text-anchor: middle; }
.web-chart__gap { fill: var(--surface-sunken); opacity: .7; }
.web-chart .web-chart__gapt { font-size: 12px; font-weight: 600; fill: var(--ink-faint); }
.web-rank { display: grid; grid-template-columns: minmax(0, 1.4fr) 1fr auto; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; }
.web-rank__label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.web-rank__bar { height: 8px; background: var(--surface-sunken); border-radius: 999px; overflow: hidden; }
.web-rank__bar i { display: block; height: 100%; background: var(--brand-gradient); border-radius: 999px; }
.web-rank__val { color: var(--ink-soft); font-variant-numeric: tabular-nums; white-space: nowrap; }
@media (max-width: 860px) {
  .web-kpis { grid-template-columns: repeat(2, 1fr); }
  .web-grid { grid-template-columns: 1fr; }
  .web-mini { gap: 10px; }
}
