/* ================================================================
   CRM Cartfy — Componentes base
   ================================================================ */

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'ss01', 'cv01';
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }

/* Tipografia editorial */
h1, .h1 { font-family: var(--font-display); font-size: 32px; font-weight: 700; line-height: 1.2; letter-spacing: -0.6px; margin: 0; color: var(--ink); }
h2, .h2 { font-family: var(--font-display); font-size: 24px; font-weight: 700; line-height: 1.25; letter-spacing: -0.4px; margin: 0; color: var(--ink); }
h3, .h3 { font-family: var(--font-display); font-size: 20px; font-weight: 600; line-height: 1.3; letter-spacing: -0.3px; margin: 0; color: var(--ink); }
.card-title { font-family: var(--font-display); font-size: 16px; font-weight: 600; line-height: 1.3; letter-spacing: -0.1px; color: var(--ink); }
.body-lg { font-size: 16px; line-height: 1.55; color: var(--ink-secondary); }
.body-sm { font-size: 13px; color: var(--ink-muted); }
.label { font-size: 12px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; color: var(--ink-muted); }
.micro-cap { font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.tabular { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); }

/* ============ BUTTONS ============ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: var(--r-sm); font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: -0.1px; border: 1px solid transparent; transition: background 150ms, box-shadow 150ms, transform 150ms; }
.btn:focus-visible { outline: none; box-shadow: var(--sh-focus); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }

.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-pressed); }

.btn-secondary { background: var(--surface); color: var(--ink); border: 1px solid var(--hairline); }
.btn-secondary:hover:not(:disabled) { background: var(--canvas-soft); border-color: var(--hairline-strong); }

.btn-ghost { background: transparent; color: var(--primary); }
.btn-ghost:hover:not(:disabled) { background: var(--primary-soft); }

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

/* ============ INPUTS ============ */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12px; font-weight: 600; letter-spacing: 0.02em; color: var(--ink-secondary); text-transform: uppercase; }
.field small { font-size: 12px; color: var(--ink-muted); }

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--hairline-input);
  border-radius: var(--r-sm);
  font-size: 14px;
  line-height: 1.5;
  transition: border-color 150ms, box-shadow 150ms;
}
.input::placeholder, .textarea::placeholder { color: var(--ink-subtle); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--sh-focus); }
.input.error, .select.error { border-color: var(--danger); }
.input.error:focus { box-shadow: var(--sh-focus-danger); }
.textarea { min-height: 96px; resize: vertical; }

/* ============ CARDS ============ */
.card { background: var(--surface); border: 1px solid var(--hairline); border-radius: var(--r-lg); padding: 24px; box-shadow: var(--sh-xs); }
.card-elevated { box-shadow: var(--sh-md); }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

/* ============ BADGES / TAGS ============ */
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: var(--r-pill); font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; }
.tag-primary { background: var(--primary-soft); color: var(--primary); }
.tag-success { background: var(--success-soft); color: var(--success); }
.tag-warning { background: var(--warning-soft); color: var(--warning); }
.tag-danger { background: var(--danger-soft); color: var(--danger); }
.tag-neutral { background: var(--canvas-soft); color: var(--ink-secondary); border: 1px solid var(--hairline); }

/* ============ APP SHELL (sidebar + topbar + canvas) ============ */
.app-shell { display: grid; grid-template-columns: var(--sidebar-width) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--inverse-canvas);
  color: var(--inverse-ink);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 8px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--inverse-surface);
}
.sidebar .brand img { width: 32px; height: 32px; border-radius: 50%; }
.sidebar .brand strong { font-family: var(--font-display); font-size: 16px; font-weight: 800; letter-spacing: -0.02em; color: var(--inverse-ink); }
.sidebar .brand span { display: block; font-size: 10px; font-weight: 700; letter-spacing: 0.1em; color: var(--inverse-ink-muted); text-transform: uppercase; margin-top: 2px; }

.sidebar .section-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--inverse-ink-muted); padding: 0 10px; margin: 16px 0 4px;
}
.sidebar .nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--r-sm);
  color: var(--inverse-ink-muted); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background 120ms, color 120ms;
}
.sidebar .nav-item svg { width: 18px; height: 18px; opacity: 0.8; }
.sidebar .nav-item:hover { background: var(--inverse-surface); color: var(--inverse-ink); }
.sidebar .nav-item.active { background: var(--primary); color: white; }
.sidebar .nav-item.active svg { opacity: 1; }

.sidebar .user-mini {
  margin-top: auto; padding: 12px 8px 4px; border-top: 1px solid var(--inverse-surface);
  display: flex; align-items: center; gap: 10px;
}
.sidebar .user-mini .avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }
.sidebar .user-mini .info { flex: 1; }
.sidebar .user-mini .info strong { display: block; font-size: 13px; color: var(--inverse-ink); }
.sidebar .user-mini .info span { display: block; font-size: 11px; color: var(--inverse-ink-muted); }

.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--hairline);
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.topbar .breadcrumb { color: var(--ink-secondary); font-size: 14px; font-weight: 500; }
.topbar .topbar-actions { display: flex; align-items: center; gap: 12px; }

/* Check-in toggle no topbar */
.checkin-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface); color: var(--ink-secondary);
  border: 1px solid var(--hairline);
  border-radius: var(--r-pill); padding: 7px 14px;
  font-family: var(--font-body); font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all 150ms;
}
.checkin-toggle:hover { border-color: var(--hairline-strong); background: var(--canvas-soft); }
.checkin-toggle .checkin-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ink-tertiary);
  box-shadow: 0 0 0 3px transparent;
  transition: all 150ms;
}
.checkin-toggle.on { color: var(--success); border-color: rgba(11,179,125,0.35); background: var(--success-soft); }
.checkin-toggle.on .checkin-dot { background: var(--success); box-shadow: 0 0 0 3px rgba(11,179,125,0.2); animation: pulse-dot 2s infinite; }
.checkin-toggle.off { color: var(--ink-muted); }

@keyframes pulse-dot {
  0%, 100% { box-shadow: 0 0 0 3px rgba(11,179,125,0.2); }
  50%      { box-shadow: 0 0 0 5px rgba(11,179,125,0.35); }
}

.canvas-content { padding: 32px; }

/* ============ LOGIN ============ */
.login-page {
  min-height: 100vh;
  display: grid; place-items: center;
  background: var(--canvas);
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border-radius: var(--r-xl);
  box-shadow: var(--sh-lg);
  padding: 40px 32px;
  border: 1px solid var(--hairline);
}
.login-card .brand-block { text-align: center; margin-bottom: 32px; }
.login-card .brand-block img { width: 56px; height: 56px; border-radius: 50%; margin-bottom: 12px; }
.login-card .brand-block h1 { font-size: 22px; font-weight: 800; letter-spacing: -0.3px; margin-bottom: 4px; }
.login-card .brand-block p { color: var(--ink-muted); font-size: 13px; margin: 0; }

.login-card .btn-primary { width: 100%; padding: 12px; }

.login-error {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--r-sm);
  font-size: 13px;
  border: 1px solid rgba(229,72,77,0.2);
}

/* ============ TABLES ============ */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--sh-xs); border: 1px solid var(--hairline); }
.table thead th { background: var(--canvas-soft); padding: 10px 16px; text-align: left; font-size: 11px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted); border-bottom: 1px solid var(--hairline-strong); }
.table tbody td { padding: 12px 16px; font-size: 14px; color: var(--ink); border-bottom: 1px solid var(--hairline); }
.table tbody tr:hover { background: var(--canvas-soft); }
.table tbody tr:last-child td { border-bottom: none; }

/* ============ EMPTY STATE ============ */
.empty { text-align: center; padding: 60px 24px; color: var(--ink-muted); }
.empty h3 { margin: 12px 0 4px; color: var(--ink); }
.empty p { font-size: 14px; }

/* ============ MODAL ============ */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10,22,40,0.45); z-index: 50; display: grid; place-items: center; padding: 24px; }
.modal { background: var(--surface); border-radius: var(--r-xl); padding: 32px; box-shadow: var(--sh-xl); width: 100%; max-width: 480px; }
.modal-header { margin-bottom: 20px; }
.modal-header h2 { margin-bottom: 4px; }
.modal-header p { color: var(--ink-muted); font-size: 14px; margin: 0; }
.modal-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 24px; }

/* ============ TOAST ============ */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 60; display: flex; flex-direction: column; gap: 8px; }
.toast { padding: 12px 16px; border-radius: var(--r-md); font-size: 13px; font-weight: 500; box-shadow: var(--sh-md); animation: slideIn 200ms ease-out; max-width: 400px; }
.toast-success { background: var(--success-soft); color: var(--success); border: 1px solid rgba(11,179,125,0.25); }
.toast-error { background: var(--danger-soft); color: var(--danger); border: 1px solid rgba(229,72,77,0.25); }
.toast-info { background: var(--info-soft); color: var(--info); border: 1px solid rgba(55,138,221,0.25); }

@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}

/* ============ UTILITIES ============ */
.flex { display: flex; }
.flex-1 { flex: 1; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 4px; } .gap-2 { gap: 8px; } .gap-3 { gap: 12px; } .gap-4 { gap: 16px; } .gap-6 { gap: 24px; }
.mt-2 { margin-top: 8px; } .mt-3 { margin-top: 12px; } .mt-4 { margin-top: 16px; } .mt-6 { margin-top: 24px; } .mt-8 { margin-top: 32px; }
.mb-2 { margin-bottom: 8px; } .mb-4 { margin-bottom: 16px; } .mb-6 { margin-bottom: 24px; }
.text-center { text-align: center; }
.hidden { display: none !important; }
.grid { display: grid; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }

/* ============ TABS ============ */
.tabs {
  display: flex; gap: 4px;
  border-bottom: 1px solid var(--hairline);
  padding: 0 0 0 4px;
}
.tab {
  padding: 10px 18px; border-radius: var(--r-md) var(--r-md) 0 0;
  color: var(--ink-muted); font-size: 14px; font-weight: 600;
  text-decoration: none;
  border-bottom: 2px solid transparent;
  transition: color 120ms, border-color 120ms;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); background: var(--primary-soft); }

/* ============ KANBAN ============ */
.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: calc(100vh - 160px);
}
.kanban-column {
  flex-shrink: 0;
  width: 300px;
  background: var(--canvas-soft);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: 12px;
  display: flex;
  flex-direction: column;
}
.kanban-col-header {
  display: flex; align-items: center; justify-content: space-between;
  padding-bottom: 12px; margin-bottom: 8px;
  border-bottom: 1px solid var(--hairline);
}
.kanban-count {
  background: var(--surface); color: var(--ink-muted);
  border-radius: var(--r-pill); padding: 2px 10px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
}
.kanban-col-body {
  display: flex; flex-direction: column; gap: 8px;
  min-height: 100px;
  transition: background 150ms;
  border-radius: var(--r-sm);
  padding: 4px;
}
.kanban-col-body.drag-over {
  background: var(--primary-soft);
  outline: 2px dashed var(--primary);
  outline-offset: -4px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
  padding: 12px;
  cursor: pointer;
  transition: box-shadow 150ms, transform 150ms;
  box-shadow: var(--sh-xs);
}
.kanban-card:hover {
  box-shadow: var(--sh-sm);
  transform: translateY(-1px);
}
.kanban-card.dragging {
  opacity: 0.4;
  transform: rotate(-1deg);
}

/* Responsive */
@media (max-width: 768px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: -240px; z-index: 100; transition: left 200ms; }
  .sidebar.open { left: 0; }
  .canvas-content { padding: 16px; }
  .kanban-column { width: 280px; }
}
