/* Sistema de diseño — monocromo, tipo macOS.
 *
 * Blanco, tinta y grises. El color aparece solo donde significa algo: una cuota
 * atrasada en rojo, un contrato vigente en verde. Todo lo demás —botones,
 * pestañas, menú— es neutro. Eso hace que lo que está en color se note de
 * verdad, que es el punto de un CRM: ver de un vistazo qué necesita atención.
 *
 * Bordes finos, esquinas redondeadas, sombras casi imperceptibles y mucho aire.
 * El modo oscuro redefine los tokens de :root y nada más del archivo cambia.
 */

/* ───────────────────────────── Tokens ───────────────────────────── */

:root {
  --bg:        #F5F5F7;   /* fondo de la app */
  --surface:   #FFFFFF;   /* cards, inputs, modales */
  --surface-2: #F0F0F2;   /* hover, pistas de segmentos, cabeceras */
  --sidebar:   #FBFBFD;

  /* El acento es la tinta: los botones principales son negros sobre blanco.
     --accent-fg es el color del texto que va encima. */
  --accent:     #1D1D1F;
  --accent-alt: #000000;          /* hover del botón principal */
  --accent-fg:  #FFFFFF;
  --accent-dim: rgba(29, 29, 31, 0.07);

  /* Semánticos: desaturados para que convivan con el gris sin gritar. */
  --green:     #157347;
  --green-dim: rgba(21, 115, 71, 0.10);
  --red:       #C7372F;
  --red-dim:   rgba(199, 55, 47, 0.10);
  --amber:     #9A6700;
  --amber-dim: rgba(154, 103, 0, 0.11);
  --blue:      #0071E3;
  --blue-dim:  rgba(0, 113, 227, 0.10);

  /* "sage" quedó del sistema anterior; acá es simplemente el gris neutro.
     Así las vistas que lo piden siguen funcionando sin tocar su código. */
  --sage:     #6E6E73;
  --sage-dim: rgba(110, 110, 115, 0.10);

  --text:  #1D1D1F;
  --muted: #6E6E73;
  --dim:   #86868B;

  --border:      #D2D2D7;
  --border-soft: #E8E8ED;
  --hover:       rgba(0, 0, 0, 0.035);

  --shadow:    0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.14);
  --ring:      0 0 0 4px rgba(0, 0, 0, 0.08);

  --radius:    12px;
  --radius-sm: 8px;

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

  color-scheme: light;
}

:root[data-theme='dark'] {
  /* Grises de macOS oscuro: negro de fondo, superficies que suben de a poco. */
  --bg:        #141416;
  --surface:   #1E1E20;
  --surface-2: #2C2C2E;
  --sidebar:   #19191B;

  /* Se da vuelta: el botón principal es blanco con texto negro. */
  --accent:     #F5F5F7;
  --accent-alt: #FFFFFF;
  --accent-fg:  #1D1D1F;
  --accent-dim: rgba(245, 245, 247, 0.10);

  --green:     #3FBF6F;
  --green-dim: rgba(63, 191, 111, 0.14);
  --red:       #FF6B5E;
  --red-dim:   rgba(255, 107, 94, 0.14);
  --amber:     #E0A42B;
  --amber-dim: rgba(224, 164, 43, 0.14);
  --blue:      #2F93FF;
  --blue-dim:  rgba(47, 147, 255, 0.14);

  --sage:     #98989D;
  --sage-dim: rgba(152, 152, 157, 0.13);

  --text:  #F5F5F7;
  --muted: #98989D;
  --dim:   #6E6E73;

  --border:      #38383A;
  --border-soft: #2A2A2C;
  --hover:       rgba(255, 255, 255, 0.05);

  --shadow:    none;
  --shadow-md: 0 2px 10px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.6);
  --ring:      0 0 0 4px rgba(255, 255, 255, 0.12);

  color-scheme: dark;
}

/* ───────────────────────────── Base ───────────────────────────── */

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

html { -webkit-text-size-adjust: 100%; }

body {
  /* En Mac agarra la tipografía del sistema; en el resto, Inter, que es la que
     más se le parece. */
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Inter',
               'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.47;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 {
  font-weight: 600;
  line-height: 1.16;
  letter-spacing: -0.022em;
}
h1 { letter-spacing: -0.03em; }

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

button, input, select, textarea { font: inherit; color: inherit; letter-spacing: inherit; }
button { cursor: pointer; background: none; border: none; }

code {
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.88em;
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 5px;
}

::selection { background: rgba(0, 113, 227, 0.22); }

/* Scrollbars finas, que aparezcan sin pesar. */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-track { background: transparent; }

/* ───────────────────────────── Shell ───────────────────────────── */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--border-soft);
  padding: 10px 10px 24px;
  position: fixed;
  inset: 0 auto 0 0;
  overflow-y: auto;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 14px;
  margin-bottom: 4px;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  display: grid; place-items: center;
  font-size: 14px; font-weight: 600;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.brand-name {
  font-size: 13.5px; font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.brand-sub {
  font-size: 10.5px;
  color: var(--dim);
  letter-spacing: 0.02em;
}

.nav-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--dim);
  padding: 15px 8px 5px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
  transition: background 0.1s;
}
.nav-item:hover { background: var(--hover); text-decoration: none; }
/* Seleccionado: relleno gris suave, como el sidebar del Finder. */
.nav-item.active { background: var(--surface-2); font-weight: 600; }
.nav-item.active .nav-icon { color: var(--text); }
.nav-icon { width: 17px; text-align: center; color: var(--dim); flex-shrink: 0; font-size: 13px; }

/* Los contadores son avisos: acá sí va color. */
.nav-badge {
  margin-left: auto;
  background: var(--red);
  color: #fff;
  font-size: 10.5px; font-weight: 600;
  min-width: 18px;
  padding: 0 5px;
  line-height: 17px;
  border-radius: 9px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-title { font-size: 14.5px; font-weight: 600; letter-spacing: -0.015em; }
.topbar-sub { font-size: 11.5px; color: var(--muted); }

.search {
  margin-left: auto;
  position: relative;
  width: min(320px, 32vw);
}
.search input {
  width: 100%;
  padding: 6px 12px 6px 30px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 13px;
}
.search input:focus {
  outline: none;
  border-color: var(--border);
  background: var(--surface);
  box-shadow: var(--ring);
}
.search-icon {
  position: absolute; left: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--dim); font-size: 12px; pointer-events: none;
}

.search-results {
  position: absolute;
  top: calc(100% + 6px); left: 0; right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 60;
  padding: 5px;
}
.search-group {
  font-size: 11px; font-weight: 600;
  color: var(--dim); padding: 8px 9px 3px;
}
.search-hit {
  padding: 6px 9px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
}
.search-hit:hover { background: var(--surface-2); }
.search-hit small { display: block; color: var(--muted); font-size: 11.5px; }

.avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--muted);
  display: grid; place-items: center;
  font-size: 11px; font-weight: 600;
  letter-spacing: -0.02em;
  flex-shrink: 0;
}
.avatar-lg { width: 56px; height: 56px; font-size: 19px; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }

.content { padding: 24px; flex: 1; max-width: 1480px; width: 100%; }

/* ───────────────────────────── Cards y KPIs ───────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.card-hd {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  margin-bottom: 15px;
  flex-wrap: wrap;
}
.card-title { font-size: 14.5px; font-weight: 600; letter-spacing: -0.015em; }
.card-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
/* Los botones de la card van a la derecha. El :not(:first-child) importa: sin
   él, una card sin botones empuja su propio título contra el borde. */
.card-hd > :last-child:not(:first-child) { margin-left: auto; }

.page-hd { margin-bottom: 20px; }
.page-hd h1 { font-size: 28px; margin-bottom: 3px; }
.page-hd p { color: var(--muted); font-size: 13.5px; }

.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(188px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 15px 17px;
  box-shadow: var(--shadow);
}
.kpi-top {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 8px; margin-bottom: 7px;
}
.kpi-label {
  font-size: 12px; color: var(--muted); font-weight: 500;
  line-height: 1.3;
}
.kpi-icon { font-size: 13px; color: var(--dim); }
.kpi-val {
  font-size: 27px; font-weight: 600;
  letter-spacing: -0.03em;
  color: var(--kpi-color, var(--text));
  line-height: 1.08;
  /* Los números son columnas visuales: tabular evita que bailen de ancho
     cuando se refrescan los datos. */
  font-variant-numeric: tabular-nums;
}
.kpi-note { font-size: 11.5px; color: var(--dim); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-21 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
@media (max-width: 1000px) {
  .grid-2, .grid-21, .grid-3 { grid-template-columns: 1fr; }
}

/* ───────────────────────────── Botones ───────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.1s, border-color 0.1s;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:active { transform: translateY(0.5px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn:disabled { opacity: 0.4; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover { background: var(--accent-alt); border-color: var(--accent-alt); }

.btn-danger { color: var(--red); border-color: var(--border); }
.btn-danger:hover { background: var(--red-dim); border-color: var(--red-dim); }

.btn-sm { padding: 3px 9px; font-size: 12px; }
.btn-icon { padding: 5px 9px; }
.btn-link {
  background: none; border: none; padding: 0;
  color: var(--blue); font-size: 13px; font-weight: 400;
}
.btn-link:hover { text-decoration: underline; }

/* ───────────────────────────── Filtros ───────────────────────────── */

.filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 15px;
}
.filters input[type='search'],
.filters input[type='text'],
.filters select {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13px;
  min-width: 130px;
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--text); box-shadow: var(--ring);
}
.filters .grow { flex: 1; min-width: 170px; }

/* Pestañas: control segmentado de macOS — pista gris, seleccionado en blanco. */
.tabs {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  background: var(--surface-2);
  border-radius: 9px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  max-width: 100%;
}
.tab {
  padding: 5px 13px;
  border: none;
  border-radius: 7px;
  background: transparent;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  transition: background 0.1s, color 0.1s;
}
.tab:hover { color: var(--text); }
.tab.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-md);
}

/* Atajos con contador. */
.chips { display: flex; gap: 7px; flex-wrap: wrap; margin-bottom: 13px; }
.chip-count {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 11px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  font-size: 12.5px; color: var(--muted);
}
.chip-count:hover { background: var(--surface-2); color: var(--text); }
.chip-count.active {
  border-color: var(--accent); color: var(--accent-fg);
  background: var(--accent);
}
.chip-count b { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ───────────────────────────── Tablas ───────────────────────────── */

.table-wrap { overflow-x: auto; margin: 0 -20px -18px; padding: 0 20px 2px; }

table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th {
  text-align: left;
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 500;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}
table.t td {
  padding: 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
table.t tbody tr { cursor: pointer; transition: background 0.08s; }
table.t tbody tr:hover td { background: var(--hover); }
table.t tbody tr:last-child td { border-bottom: none; }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t .actions { text-align: right; white-space: nowrap; }
table.t .strong { font-weight: 600; }

.t-main { font-weight: 500; }
.t-sub { font-size: 11.5px; color: var(--muted); }

/* ───────────────────────────── Píldoras de estado ───────────────────────────── */

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 11px;
  font-size: 11.5px;
  font-weight: 500;
  white-space: nowrap;
  background: var(--surface-2);
  color: var(--muted);
}
.pill-accent { background: var(--accent-dim); color: var(--text); }
.pill-green  { background: var(--green-dim);  color: var(--green); }
.pill-red    { background: var(--red-dim);    color: var(--red); }
.pill-sage   { background: var(--sage-dim);   color: var(--sage); }
.pill-amber  { background: var(--amber-dim);  color: var(--amber); }

/* ───────────────────────────── Grilla de propiedades ───────────────────────────── */

.prop-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(238px, 1fr));
  gap: 15px;
}
.prop-card {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: box-shadow 0.15s, transform 0.15s;
}
.prop-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.prop-cover {
  aspect-ratio: 4 / 3;
  background: var(--surface-2) center / cover no-repeat;
  display: grid; place-items: center;
  color: var(--dim); font-size: 26px;
  position: relative;
}
.prop-cover .pill {
  position: absolute; top: 9px; left: 9px;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(8px);
}
.prop-cover .photo-count {
  position: absolute; bottom: 9px; right: 9px;
  background: rgba(0, 0, 0, 0.55); color: #fff;
  font-size: 10.5px; padding: 2px 7px; border-radius: 9px;
  backdrop-filter: blur(8px);
}
.prop-body { padding: 12px 14px 14px; }
.prop-title {
  font-weight: 600; font-size: 13.5px;
  letter-spacing: -0.015em;
  line-height: 1.3; margin-bottom: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.prop-meta { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.prop-price {
  font-size: 18px; font-weight: 600;
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
}
.prop-specs {
  display: flex; gap: 11px; flex-wrap: wrap;
  font-size: 11.5px; color: var(--muted);
  margin-top: 9px; padding-top: 9px;
  border-top: 1px solid var(--border-soft);
}

/* ───────────────────────────── Formularios ───────────────────────────── */

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field > label {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
}
.field input, .field select, .field textarea {
  padding: 7px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 13.5px;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--text);
  box-shadow: var(--ring);
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.55; }
.field-hint { font-size: 11.5px; color: var(--dim); }

/* Chips en vez de <select> para los enums cortos: se ven todas las opciones de
   una y se elige con un toque, que en el celular es la diferencia entre cargar
   una propiedad y no cargarla. */
.chip-group { display: flex; gap: 6px; flex-wrap: wrap; }
.chip-opt { position: relative; cursor: pointer; }
.chip-opt input { position: absolute; opacity: 0; pointer-events: none; }
.chip-opt span {
  display: inline-block;
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 15px;
  background: var(--surface);
  font-size: 12.5px;
  color: var(--muted);
  transition: all 0.1s;
}
.chip-opt:hover span { background: var(--surface-2); color: var(--text); }
.chip-opt input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
  font-weight: 500;
}
.chip-opt input:focus-visible + span { box-shadow: var(--ring); }

.form-err {
  color: var(--red);
  font-size: 12.5px;
  background: var(--red-dim);
  border-radius: var(--radius-sm);
  padding: 8px 11px;
  margin-top: 11px;
}
.form-err:empty { display: none; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; }
.switch input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }

/* ───────────────────────────── Modales ───────────────────────────── */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 6vh 18px;
  z-index: 100;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 620px;
  padding: 20px 22px 22px;
  animation: pop 0.14s ease-out;
}
.modal-lg { max-width: 920px; }
@keyframes pop { from { opacity: 0; transform: scale(0.985) translateY(-6px); } }

.modal-hd {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 17px;
}
.modal-title { font-size: 16px; font-weight: 600; letter-spacing: -0.02em; }
.modal-close {
  margin-left: auto;
  font-size: 19px; line-height: 1;
  color: var(--dim);
  padding: 0 4px;
}
.modal-close:hover { color: var(--text); }
.modal-ft {
  display: flex; justify-content: flex-end; gap: 8px;
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

/* ───────────────────────────── Ficha de detalle ───────────────────────────── */

.detail-hd {
  display: flex; align-items: flex-start; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.detail-hd h1 { font-size: 25px; }
.detail-hd .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }

.back-link {
  display: inline-block;
  font-size: 13px; color: var(--muted);
  margin-bottom: 14px;
}
.back-link:hover { color: var(--text); }

.spec-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 10px;
}
.spec {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.spec-val { font-size: 17px; font-weight: 600; letter-spacing: -0.025em; font-variant-numeric: tabular-nums; }
.spec-lbl { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(128px, 1fr));
  gap: 9px;
}
.gallery figure {
  position: relative;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.gallery img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .rm {
  position: absolute; top: 5px; right: 5px;
  background: rgba(0, 0, 0, 0.6); color: #fff;
  width: 21px; height: 21px; border-radius: 50%;
  display: grid; place-items: center; font-size: 12px;
  opacity: 0; transition: opacity 0.12s;
  backdrop-filter: blur(6px);
}
.gallery figure:hover .rm { opacity: 1; }

/* ───────────────────────────── Listas e ítems ───────────────────────────── */

.list-row {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
}
.list-row:last-child { border-bottom: none; }
.list-row .grow { flex: 1; min-width: 0; }
.list-title { font-size: 13px; font-weight: 500; }
.list-sub { font-size: 11.5px; color: var(--muted); }
.list-row.clickable { cursor: pointer; border-radius: var(--radius-sm); }
.list-row.clickable:hover { background: var(--hover); margin: 0 -9px; padding: 10px 9px; }

.empty {
  text-align: center;
  padding: 36px 18px;
  color: var(--muted);
  font-size: 13px;
}
.empty-icon { font-size: 26px; color: var(--dim); margin-bottom: 10px; }

/* Barras para pipeline, embudo y distribución. */
.bar-row {
  display: grid;
  grid-template-columns: 105px 1fr 46px;
  align-items: center;
  gap: 11px;
  margin-bottom: 8px;
  font-size: 12.5px;
}
.bar-track { height: 7px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent); border-radius: 4px; transition: width 0.3s; }
.bar-num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* Columnas por mes. */
.chart { display: flex; align-items: flex-end; gap: 7px; height: 128px; padding-top: 8px; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.chart-stack { flex: 1; width: 100%; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; }
.chart-bar { border-radius: 3px 3px 0 0; min-height: 2px; }
.chart-label { font-size: 10.5px; color: var(--muted); }

.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 11.5px; color: var(--muted); }
.legend i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* ───────────────────────────── Avisos ───────────────────────────── */

.toast-host {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200;
}
.toast {
  background: color-mix(in srgb, var(--text) 92%, transparent);
  color: var(--bg);
  padding: 9px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(12px);
  animation: slide-in 0.16s ease-out;
  max-width: 330px;
}
.toast.err { background: var(--red); color: #fff; }
@keyframes slide-in { from { opacity: 0; transform: translateY(8px); } }

.loading { text-align: center; padding: 44px; color: var(--muted); font-size: 13px; }

/* ───────────────────────────── Login ───────────────────────────── */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 372px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  padding: 34px 32px;
  box-shadow: var(--shadow-lg);
}
.auth-brand { text-align: center; margin-bottom: 26px; }
.auth-brand .brand-mark { margin: 0 auto 14px; width: 44px; height: 44px; font-size: 19px; border-radius: 11px; }
.auth-brand h1 { font-size: 21px; }
.auth-brand p { font-size: 13px; color: var(--muted); margin-top: 4px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .field input { padding: 9px 12px; }
.auth-card .btn { width: 100%; justify-content: center; padding: 9px; }
.auth-hint {
  margin-top: 20px; padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  font-size: 12px; color: var(--muted);
  text-align: center; line-height: 1.6;
}

/* ───────────────────────────── Responsive ───────────────────────────── */

.menu-btn { display: none; font-size: 17px; padding: 4px 8px; color: var(--text); }
.sidebar-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
  z-index: 35;
}

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: block; }
  .content { padding: 16px; }
  .search { width: auto; flex: 1; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-text { display: none; }
  .table-wrap { margin: 0 -20px; padding: 0 20px; }
  .modal { padding: 17px; }
  .page-hd h1 { font-size: 23px; }
}

@media print {
  .sidebar, .topbar, .btn, .filters, .tabs { display: none !important; }
  .main { margin-left: 0; }
  .card { break-inside: avoid; box-shadow: none; border-color: #ddd; }
}
