/* ─────────────────────────────────────────────────────────────────
   IJS CRM — sistema de diseño
   Tokens tomados de DESSIGN/DESIGN (1).md. No inventar colores nuevos
   aquí: si hace falta uno, se añade como variable y se razona.

   Nota: de momento solo tema claro. La paleta del documento de diseño
   está calibrada para claro; un modo oscuro improvisado a ojo quedaría
   peor que no tenerlo. Cuando se haga, será con su propia paleta.
   ───────────────────────────────────────────────────────────────── */

:root {
  /* Marca */
  --primary:        #0066cc;
  --primary-bright: #0070c0;
  --primary-deep:   #004e9f;
  --primary-tint:   rgba(0, 102, 204, 0.08);
  --primary-ring:   rgba(0, 102, 204, 0.20);

  /* Superficies */
  --canvas:    #f5f5f7;
  --surface:   #ffffff;
  --surface-2: #f9f9fb;
  --surface-3: #ebebee;

  /* Tinta */
  --ink:        #1d1d1f;
  --ink-soft:   #424245;
  --ink-muted:  #86868b;
  --ink-onDark: #ffffff;

  /* Líneas */
  --hairline:        #e5e5ea;
  --hairline-strong: #d1d1d6;

  /* Estado */
  --ok:      #28cd41;
  --ok-tint: rgba(40, 205, 65, 0.10);
  --warn:      #ff9f0a;
  --warn-tint: rgba(255, 159, 10, 0.12);
  --danger:      #ff3b30;
  --danger-tint: rgba(255, 59, 48, 0.10);

  /* Formas */
  --r-sm: 6px;
  --r:    8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-full: 9999px;

  /* Elevación: capas tonales y hairlines, no sombras teatrales */
  --shadow-menu:  0 4px 20px rgba(0, 0, 0, 0.06);
  --shadow-modal: 0 12px 36px rgba(0, 0, 0, 0.12);

  /* Ritmo 8pt con medios pasos de 4 */
  --s-xs: 4px;
  --s-sm: 8px;
  --s-md: 12px;
  --s-lg: 16px;
  --s-xl: 24px;
  --s-2xl: 40px;

  --sidebar-w: 240px;
  --topbar-h: 56px;

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 20px;
  letter-spacing: -0.005em;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ── Tipografía ─────────────────────────────────────────────────── */
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }
h1 { font-size: 28px; line-height: 34px; letter-spacing: -0.025em; }
h2 { font-size: 21px; line-height: 26px; }
h3 { font-size: 17px; line-height: 25px; }

.body-lg { font-size: 17px; line-height: 25px; letter-spacing: -0.015em; }
.caption { font-size: 12px; line-height: 16px; letter-spacing: 0.01em; font-weight: 500; color: var(--ink-muted); }
.muted   { color: var(--ink-muted); }

/* Códigos: SIEMPRE monoespaciado. Un CardCode o una referencia OEM se leen
   comparando carácter a carácter, y en proporcional 0 y O se confunden. */
.code, .mono { font-family: var(--mono); font-size: 13px; font-weight: 500; letter-spacing: 0; }
.code-sm { font-family: var(--mono); font-size: 11px; font-weight: 500; letter-spacing: 0.02em; }

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

/* ── Botones ────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-sm);
  height: 36px;
  padding: 0 var(--s-lg);
  border-radius: var(--r);
  border: 1px solid transparent;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-bright); }

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

.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn-ghost:hover:not(:disabled) { background: rgba(0,0,0,.04); color: var(--ink); }

.btn-danger { background: var(--danger); color: #fff; }

/* Objetivo táctil de 44px en móvil: el pulgar no acierta en 36. */
@media (max-width: 767px) {
  .btn { height: 44px; }
}

/* ── Formularios ────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 6px; }
.label { font-size: 12px; font-weight: 500; color: var(--ink-soft); letter-spacing: .01em; }

.input, .select, .textarea {
  width: 100%;
  height: 36px;
  padding: 0 var(--s-md);
  border: 1px solid var(--hairline-strong);
  border-radius: var(--r);
  background: var(--surface);
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.textarea { height: auto; min-height: 88px; padding: var(--s-md); line-height: 20px; resize: vertical; }

/* Foco tipo CAD: anillo nítido, sin desenfoque. */
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-ring);
}
.input::placeholder { color: var(--ink-muted); }

@media (max-width: 767px) {
  /* 16px o menos → iOS hace zoom al enfocar el campo. */
  .input, .select, .textarea { font-size: 16px; height: 44px; }
}

/* ── Superficies ────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-md);
}
.card-pad { padding: var(--s-lg); }

.panel {
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--r-lg);
  padding: var(--s-xl);
}

/* ── Distintivos ────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 22px;
  padding: 0 10px;
  border-radius: var(--r-full);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid transparent;
}
.badge-primary { color: var(--primary); background: var(--primary-tint); border-color: var(--primary-ring); }
.badge-ok      { color: #1a7f2e; background: var(--ok-tint); }
.badge-warn    { color: #9a6000; background: var(--warn-tint); }
.badge-danger  { color: #a3261f; background: var(--danger-tint); }
.badge-neutral { color: var(--ink-soft); background: var(--surface-3); }

/* ── Estructura de la aplicación ────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--canvas);
  border-right: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  transition: width .18s ease, flex-basis .18s ease;
}
.sidebar.collapsed { width: 64px; flex-basis: 64px; }

.sidebar-head {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: var(--s-sm);
  padding: 0 var(--s-lg);
  border-bottom: 1px solid var(--hairline);
}
.sidebar-logo { height: 22px; width: auto; display: block; }

.nav { padding: var(--s-md) var(--s-sm); overflow-y: auto; flex: 1; }
.nav-section { padding: var(--s-md) var(--s-sm) var(--s-xs); }

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s-md);
  height: 34px;
  padding: 0 var(--s-md);
  border-radius: var(--r);
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
}
.nav-item:hover { background: rgba(0,0,0,.04); color: var(--ink); text-decoration: none; }
.nav-item.active { background: var(--primary-tint); color: var(--primary); }
.nav-item .icon { width: 20px; text-align: center; flex: 0 0 20px; }
.sidebar.collapsed .nav-item span:not(.icon),
.sidebar.collapsed .nav-section { display: none; }

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

.topbar {
  height: var(--topbar-h);
  flex: 0 0 var(--topbar-h);
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(20px) saturate(180%);
  border-bottom: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: var(--s-md);
  padding: 0 var(--s-xl);
}
.topbar-title { font-size: 17px; font-weight: 600; letter-spacing: -0.02em; }
.spacer { flex: 1; }

.content { flex: 1; overflow-y: auto; padding: var(--s-xl); }

.avatar {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: var(--primary);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600;
  flex: 0 0 28px;
}

/* ── Móvil: una columna y barra inferior al alcance del pulgar ──── */
.bottom-bar { display: none; }

@media (max-width: 767px) {
  .sidebar { display: none; }
  .content { padding: var(--s-lg) var(--s-lg) 76px; }
  .topbar { padding: 0 var(--s-lg); }
  .bottom-bar {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 60px;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(20px) saturate(180%);
    border-top: 1px solid var(--hairline);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 40;
  }
  .bottom-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    font-size: 11px; font-weight: 500;
    color: var(--ink-muted);
    text-decoration: none;
  }
  .bottom-item.active { color: var(--primary); }
}

/* ── Utilidades ─────────────────────────────────────────────────── */
/* OJO: aquí NO puede haber una clase `.hidden`.
 *
 * Este fichero nació antes de adoptar Tailwind y traía
 * `.hidden { display: none !important }`. Ese `!important` pisaba TODAS las
 * variantes responsive de Tailwind: `hidden sm:flex`, `hidden md:table-cell`
 * y compañía se quedaban invisibles en cualquier tamaño de pantalla.
 *
 * Se notó en la campana de notificaciones, que no aparecía ni a 1500 px, pero
 * afectaba a veinte sitios: las columnas de CIF, teléfono, correo, última
 * actividad y responsable del directorio de clientes nunca se veían. Parecía
 * una decisión de diseño responsive y era un fallo.
 *
 * Tailwind ya trae su propia `hidden`, sin `!important`, que sí convive con
 * los breakpoints. No hace falta ninguna aquí.
 */
.row { display: flex; align-items: center; gap: var(--s-md); }
.col { display: flex; flex-direction: column; gap: var(--s-md); }
.grow { flex: 1; }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--s-md);
  padding: var(--s-2xl) var(--s-xl);
  text-align: center;
  color: var(--ink-muted);
}

.toast {
  position: fixed;
  bottom: var(--s-xl);
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: var(--s-md) var(--s-xl);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-modal);
  z-index: 100;
  font-size: 14px;
  max-width: calc(100vw - 32px);
}
.toast.error { background: var(--danger); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: var(--r-full); border: 3px solid var(--canvas); }
::-webkit-scrollbar-track { background: transparent; }
