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

/* Contenedores Patagonia · Panel Pati
   Réplica estática de las clases de Tailwind de apps/crm-frontend.
   Usa las variables de tokens.css (--primary, --patagonia-900, --radius-lg...). */

.cp-root {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--foreground);
  background: var(--background);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: 'rlig' 1, 'calt' 1;
}
.cp-root *, .cp-root *::before, .cp-root *::after { box-sizing: border-box; }
.cp-root :focus-visible { outline: 3px solid var(--focus-outline); outline-offset: 3px; }
.cp-icon { width: 16px; height: 16px; flex: none; display: inline-block; }
.cp-icon svg { width: 100%; height: 100%; display: block; }
.cp-icon-sm { width: 14px; height: 14px; }
.cp-icon-xs { width: 12px; height: 12px; }
.cp-icon-lg { width: 24px; height: 24px; }

/* ── Botón (ui/button.tsx) ── */
.cp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  white-space: nowrap; border-radius: var(--radius-lg); font: inherit; font-size: 14px;
  line-height: 20px; font-weight: 500; height: 40px; padding: 8px 16px; border: 0;
  cursor: pointer; transition: all 150ms; background: transparent; color: var(--foreground);
}
.cp-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--card), 0 0 0 4px var(--ring); }
.cp-btn:active { transform: scale(0.98); }
.cp-btn[disabled] { opacity: 0.5; pointer-events: none; }
.cp-btn--default { background: var(--primary); color: var(--primary-foreground); box-shadow: var(--shadow-sm); }
.cp-btn--default:hover { box-shadow: var(--shadow-md); background: color-mix(in srgb, var(--primary) 90%, transparent); }
.cp-btn--destructive { background: var(--destructive); color: var(--destructive-foreground); }
.cp-btn--destructive:hover { background: color-mix(in srgb, var(--destructive) 90%, transparent); }
.cp-btn--outline { background: var(--card); border: 1px solid var(--input); box-shadow: var(--shadow-xs); }
.cp-btn--outline:hover, .cp-btn--ghost:hover { background: var(--accent); color: var(--accent-foreground); }
.cp-btn--secondary { background: var(--secondary); color: var(--secondary-foreground); }
.cp-btn--secondary:hover { background: color-mix(in srgb, var(--secondary) 80%, transparent); }
.cp-btn--link { color: var(--primary); padding-inline: 0; height: auto; }
.cp-btn--link:hover { text-decoration: underline; text-underline-offset: 4px; }
.cp-btn--sm { height: 36px; padding: 0 12px; border-radius: var(--radius-md); }
.cp-btn--lg { height: 44px; padding: 0 32px; border-radius: var(--radius-md); }
.cp-btn--icon { width: 40px; padding: 0; }

/* ── Badge (ui/badge.tsx) ── */
.cp-badge {
  display: inline-flex; align-items: center; gap: 4px; white-space: nowrap;
  border-radius: var(--radius-full); border: 1px solid transparent;
  padding: 2px 10px; font-size: 12px; line-height: 16px; font-weight: 600;
  background: var(--primary); color: var(--primary-foreground);
}
.cp-badge--sm { padding: 0 8px; font-size: 10px; }
.cp-badge--lg { padding: 4px 12px; font-size: 14px; line-height: 20px; }
.cp-badge--secondary { background: var(--secondary); color: var(--secondary-foreground); }
.cp-badge--success { background: var(--success); color: var(--success-foreground); }
.cp-badge--warning { background: var(--warning); color: var(--warning-foreground); }
.cp-badge--danger { background: var(--danger); color: var(--danger-foreground); }
.cp-badge--info { background: var(--info); color: var(--info-foreground); }
.cp-badge--success-muted { background: var(--success-muted); color: var(--success-muted-foreground); }
.cp-badge--warning-muted { background: var(--warning-muted); color: var(--warning-muted-foreground); }
.cp-badge--danger-muted { background: var(--danger-muted); color: var(--danger-muted-foreground); }
.cp-badge--info-muted { background: var(--info-muted); color: var(--info-muted-foreground); }
.cp-badge--outline { background: transparent; color: var(--foreground); border-color: var(--border); }
.cp-badge--outline-muted { background: transparent; color: var(--muted-foreground); border-color: var(--border); }
.cp-badge--stage { position: relative; isolation: isolate; background: transparent; }
.cp-badge--stage::before { content: ''; position: absolute; inset: -1px; border-radius: inherit; background: currentColor; opacity: 0.1; z-index: -1; }
.cp-badge--lead-nuevo { color: var(--stage-lead-nuevo); }
.cp-badge--calificado { color: var(--stage-calificado); }
.cp-badge--cotizado { color: var(--stage-cotizado); }
.cp-badge--negociando { color: var(--stage-negociando); }
.cp-badge--ganado { color: var(--stage-ganado); }
.cp-badge--perdido { color: var(--stage-perdido); }

/* ── Card (ui/card.tsx) ── */
.cp-card {
  border-radius: var(--radius-2xl); border: 1px solid color-mix(in srgb, var(--border) 80%, transparent);
  background: var(--card); color: var(--card-foreground); box-shadow: var(--shadow-card);
}
.cp-card__header { display: flex; flex-direction: column; gap: 6px; padding: 24px; }
.cp-card__title { margin: 0; font-size: 18px; line-height: 1; font-weight: 600; letter-spacing: -0.025em; }
.cp-card__description { margin: 0; font-size: 14px; line-height: 20px; color: var(--muted-foreground); }
.cp-card__content { padding: 0 24px 24px; }
.cp-card__footer { display: flex; align-items: center; gap: 8px; padding: 0 24px 24px; }

/* ── Tarjeta de cifra (.pati-stat) ── */
.cp-stat {
  border: 1px solid var(--hairline); background: var(--card); border-radius: var(--radius-panel);
  padding: 20px; box-shadow: var(--shadow-stat);
}
.cp-stat__label { font-size: 14px; line-height: 20px; font-weight: 500; color: var(--foreground); }
.cp-stat__value { display: block; font-size: 36px; font-weight: 700; color: var(--patagonia-900); letter-spacing: -0.05em; margin-top: 8px; line-height: 1.55; font-variant-numeric: tabular-nums; }
.cp-stat__caption { color: var(--stat-caption); font-size: 14px; }

/* ── Conversación (.pati-conversation) ── */
.cp-conversation { border: 1px solid var(--hairline); border-radius: var(--radius-panel); background: var(--card); overflow: hidden; box-shadow: var(--shadow-conversation); }
.cp-conversation__head { padding: 20.8px; display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.cp-conversation__who { display: flex; align-items: center; gap: 12px; min-width: 0; }
.cp-initials { display: grid; place-items: center; width: 44.8px; height: 44.8px; flex: none; background: var(--chip-bg); color: var(--patagonia-900); border-radius: 12.8px; font-weight: 700; }
.cp-status { display: inline-flex; border-radius: 32px; padding: 4.8px 11.2px; font-size: 14px; background: var(--chip-bg); color: var(--chip-ink); }
.cp-status--attention { background: var(--attention-bg); color: var(--attention-ink); }
.cp-human-form { padding: 20px; background: var(--surface-soft); border-top: 1px solid var(--hairline-soft); }
.cp-human-form summary { cursor: pointer; font-weight: 600; color: var(--summary-ink); }

/* ── Campos (ui/input.tsx, ui/select.tsx) ── */
.cp-field { display: grid; gap: 6px; }
.cp-label { font-size: 14px; line-height: 20px; font-weight: 500; }
.cp-input, .cp-select {
  display: flex; width: 100%; height: 36px; border-radius: var(--radius-lg); border: 1px solid var(--input);
  background: var(--card); padding: 4px 12px; font: inherit; font-size: 14px; line-height: 20px;
  color: var(--foreground); box-shadow: var(--shadow-xs); transition: color 150ms, background 150ms, border-color 150ms;
  accent-color: var(--patagonia-900);
}
.cp-select { appearance: none; padding-right: 32px; box-shadow: var(--shadow-sm); }
.cp-select-wrap { position: relative; }
.cp-select-wrap .cp-icon { position: absolute; right: 10px; top: 10px; color: var(--muted-foreground); pointer-events: none; }
.cp-input::placeholder { color: var(--muted-foreground); }
.cp-input:focus-visible, .cp-select:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--card), 0 0 0 3px var(--patagonia-500); }
.cp-input[disabled] { cursor: not-allowed; opacity: 0.5; }

/* ── Pestañas (ui/tabs.tsx) ── */
.cp-tabs { display: inline-flex; height: 40px; align-items: center; gap: 4px; border-radius: var(--radius-md); background: var(--muted); padding: 4px; color: var(--muted-foreground); }
.cp-tab {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; white-space: nowrap;
  border-radius: var(--radius-sm); padding: 6px 12px; font: inherit; font-size: 14px; line-height: 20px;
  font-weight: 500; border: 0; background: transparent; color: inherit; cursor: pointer; transition: all 150ms;
}
.cp-tab:hover { background: color-mix(in srgb, var(--background) 50%, transparent); color: var(--foreground); }
.cp-tab[aria-selected='true'] { background: var(--background); color: var(--foreground); box-shadow: var(--shadow-sm); }
.cp-tab:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--patagonia-500); }
.cp-count {
  margin-left: 4px; display: inline-flex; height: 20px; min-width: 20px; align-items: center; justify-content: center;
  border-radius: var(--radius-full); padding: 0 6px; font-size: 10px; font-weight: 600; font-variant-numeric: tabular-nums;
  background: color-mix(in srgb, var(--muted-foreground) 20%, transparent);
}
.cp-tab[aria-selected='true'] .cp-count { background: var(--patagonia-100); color: var(--patagonia-700); }
.cp-count--urgent, .cp-tab[aria-selected='true'] .cp-count--urgent { background: var(--danger); color: var(--danger-foreground); }

/* ── Tabla (ui/table.tsx) ── */
.cp-table-wrap { width: 100%; overflow-x: auto; }
.cp-table { width: 100%; border-collapse: collapse; font-size: 14px; line-height: 20px; }
.cp-table thead { background: color-mix(in srgb, var(--muted) 40%, transparent); }
.cp-table thead tr { border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.cp-table th { height: 40px; padding: 0 12px; text-align: left; vertical-align: middle; font-size: 12px; line-height: 16px; font-weight: 500; text-transform: uppercase; letter-spacing: 0.025em; color: var(--muted-foreground); }
.cp-table td { padding: 10px 12px; vertical-align: middle; }
.cp-table tbody tr { border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent); transition: background 150ms; }
.cp-table tbody tr:last-child { border-bottom: 0; }
.cp-table tbody tr:hover { background: color-mix(in srgb, var(--muted) 40%, transparent); }
.cp-num { font-variant-numeric: tabular-nums; }
.cp-muted { color: var(--muted-foreground); }

/* ── Encabezado de página (admin/PageHeader.tsx) ── */
.cp-page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; border-bottom: 1px solid var(--hairline); padding-bottom: 24px; }
.cp-page-header__main { min-width: 0; flex: 1; }
.cp-page-header__title-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cp-page-header__title { margin: 0; font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.025em; color: var(--foreground); }
.cp-page-header__title--md { font-size: 24px; line-height: 32px; }
.cp-page-header__description { margin: 6px 0 0; color: var(--muted-foreground); font-size: 16px; line-height: 24px; max-width: 768px; }
.cp-page-header__actions { display: flex; align-items: center; gap: 8px; flex: none; }
@media (max-width: 639px) {
  .cp-page-header__title { font-size: 24px; line-height: 32px; }
  .cp-page-header__title--md { font-size: 20px; line-height: 28px; }
  .cp-page-header__description { font-size: 14px; line-height: 20px; }
}

/* ── Estado vacío (ui/empty-state.tsx) ── */
.cp-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 24px; text-align: center; }
.cp-empty__icon { margin-bottom: 12px; display: inline-flex; width: 48px; height: 48px; align-items: center; justify-content: center; border-radius: var(--radius-full); background: var(--muted); color: var(--muted-foreground); }
.cp-empty__title { margin: 0; font-size: 16px; line-height: 24px; font-weight: 600; color: var(--foreground); }
.cp-empty__description { margin: 4px 0 0; max-width: 384px; font-size: 14px; line-height: 20px; color: var(--muted-foreground); }
.cp-empty__action { margin-top: 16px; }

/* ── Aviso (ui/toast.tsx) ── */
.cp-toast { display: flex; align-items: flex-start; gap: 8px; min-width: 280px; max-width: 448px; border-radius: var(--radius-md); border: 1px solid; padding: 8px 12px; box-shadow: var(--shadow-md); font-size: 14px; line-height: 20px; }
.cp-toast--success { background: #f0fdf4; color: #14532d; border-color: #bbf7d0; }
.cp-toast--error { background: #fef2f2; color: #7f1d1d; border-color: #fecaca; }
.cp-toast--info { background: #eff6ff; color: #1e3a8a; border-color: #bfdbfe; }

/* ── Menú lateral (admin/AdminShell.tsx) ── */
.cp-sidebar {
  width: var(--sidebar-width); height: 100%; display: flex; flex-direction: column; color: #fff;
  background: linear-gradient(to bottom, var(--patagonia-900), var(--patagonia-900), var(--patagonia-800));
  border-right: 1px solid rgb(255 255 255 / 0.05);
}
.cp-sidebar--collapsed { width: var(--sidebar-collapsed-width); }
.cp-sidebar__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; height: var(--sidebar-header-height); padding: 0 20px; border-bottom: 1px solid rgb(255 255 255 / 0.1); flex: none; }
.cp-sidebar--collapsed .cp-sidebar__header { justify-content: center; padding: 0 12px; }
.cp-sidebar__logo { height: 36px; width: auto; display: block; }
.cp-sidebar__mark { display: flex; width: 40px; height: 40px; align-items: center; justify-content: center; border-radius: var(--radius-lg); background: color-mix(in srgb, var(--accent-500) 15%, transparent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent-500) 30%, transparent); color: var(--accent-500); font-weight: 700; font-size: 18px; }
.cp-sidebar__workspace { color: var(--sidebar-eyebrow); font-size: 12px; letter-spacing: 0.13em; text-transform: uppercase; padding: 14.4px 20px 4.8px; }
.cp-sidebar__workspace strong { color: #fff; font-size: 17.6px; text-transform: none; letter-spacing: 0; display: block; }
.cp-sidebar__nav { flex: 1; padding: 8px; display: flex; flex-direction: column; gap: 16px; overflow-y: auto; }
.cp-sidebar__section-label { padding: 4px 12px; font-size: 10px; line-height: 15px; text-transform: uppercase; letter-spacing: 0.05em; color: rgb(255 255 255 / 0.4); font-weight: 600; }
.cp-sidebar__items { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
.cp-nav-item {
  position: relative; display: flex; align-items: center; gap: 12px; padding: 8px 12px; border-radius: var(--radius-lg);
  font-size: 14px; line-height: 20px; color: rgb(255 255 255 / 0.7); text-decoration: none; transition: all 150ms;
}
.cp-nav-item:hover { background: rgb(255 255 255 / 0.08); color: #fff; }
.cp-nav-item[aria-current='page'] { background: rgb(255 255 255 / 0.1); color: #fff; font-weight: 500; }
.cp-nav-item[aria-current='page']::before { content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%); height: 20px; width: 3px; border-radius: var(--radius-full); background: var(--accent-500); }
.cp-nav-item[aria-current='page'] .cp-icon { color: var(--accent-500); }
.cp-sidebar--collapsed .cp-nav-item { justify-content: center; padding: 8px; }
.cp-nav-item__label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-nav-item__count { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--radius-full); font-size: 10px; font-weight: 700; font-variant-numeric: tabular-nums; background: color-mix(in srgb, var(--warning) 90%, transparent); color: var(--warning-foreground); }
.cp-nav-item[aria-current='page'] .cp-nav-item__count { background: var(--warning); }
.cp-nav-item__dot { position: absolute; top: -2px; right: -2px; width: 8px; height: 8px; border-radius: var(--radius-full); background: var(--warning); box-shadow: 0 0 0 2px var(--patagonia-900); }
.cp-sidebar__footer { padding: 8px; border-top: 1px solid rgb(255 255 255 / 0.1); display: flex; flex-direction: column; gap: 4px; }
.cp-sidebar__footer-btn { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 12px; border-radius: var(--radius-md); font: inherit; font-size: 14px; line-height: 20px; color: rgb(255 255 255 / 0.7); background: transparent; border: 0; cursor: pointer; }
.cp-sidebar__footer-btn:hover { background: rgb(255 255 255 / 0.1); color: #fff; }
.cp-sidebar--collapsed .cp-sidebar__footer-btn { justify-content: center; padding: 8px; }

/* ── Barra superior (AdminShell header, Breadcrumbs, búsqueda, campana, Nuevo) ── */
.cp-topbar { position: sticky; top: 0; z-index: 30; height: var(--topbar-height); display: flex; align-items: center; gap: 12px; padding: 0 24px; background: color-mix(in srgb, var(--background) 85%, transparent); backdrop-filter: blur(16px); border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent); }
.cp-breadcrumbs { flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; font-size: 12px; line-height: 16px; color: var(--muted-foreground); overflow: hidden; }
.cp-breadcrumbs a { color: inherit; text-decoration: none; display: flex; align-items: center; gap: 4px; }
.cp-breadcrumbs a:hover { color: var(--foreground); }
.cp-breadcrumbs .cp-sep { color: color-mix(in srgb, var(--muted-foreground) 50%, transparent); }
.cp-breadcrumbs__current { color: var(--foreground); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cp-search { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: var(--radius-md); border: 1px solid var(--border); background: color-mix(in srgb, var(--muted) 40%, transparent); color: var(--muted-foreground); font: inherit; font-size: 12px; line-height: 16px; cursor: pointer; }
.cp-search:hover { background: var(--muted); color: var(--foreground); }
.cp-kbd { display: inline-flex; align-items: center; gap: 2px; padding: 2px 6px; font-size: 10px; font-weight: 600; background: var(--card); border: 1px solid var(--border); border-radius: 4px; }
.cp-bell { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-md); color: var(--muted-foreground); background: transparent; border: 0; cursor: pointer; }
.cp-bell:hover { background: var(--muted); color: var(--foreground); }
.cp-bell__count { position: absolute; top: -2px; right: -2px; min-width: 16px; height: 16px; padding: 0 4px; display: inline-flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; font-variant-numeric: tabular-nums; background: var(--warning); color: var(--warning-foreground); border-radius: var(--radius-full); box-shadow: 0 0 0 2px var(--background); }
.cp-new { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: var(--radius-md); font: inherit; font-size: 12px; line-height: 16px; font-weight: 500; background: var(--patagonia-900); color: #fff; border: 0; cursor: pointer; transition: background 150ms; }
.cp-new:hover { background: var(--patagonia-800); }
@media (max-width: 639px) { .cp-search__label, .cp-new__label { display: none; } }
@media (max-width: 767px) { .cp-kbd { display: none; } }

@media (prefers-reduced-motion: reduce) {
  .cp-root *, .cp-root *::before, .cp-root *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
