/* Base — sistema de diseño de la web (ver crates/base-web/DISENO.md).
   Tokens en variables CSS; tema claro por defecto, oscuro con prefers-color-scheme o [data-theme="dark"]. */

/* ------------------------------------------------------------------------------------------------ Tokens */

/* Copiadas de web/landing a dist/ por Trunk (index.html): se sirven en /app/ en cualquier anfitrión. */
@font-face { font-family: "Instrument Sans"; src: url(/app/fonts/instrument-sans-2ee17598a98d8a59.woff2) format("woff2"); font-weight: 400 700; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url(/app/fonts/jetbrains-mono-400-14425ba9c695763c.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url(/app/fonts/jetbrains-mono-500-cb182feeed4d798f.woff2) format("woff2"); font-weight: 500; font-display: swap; }

:root {
  color-scheme: light;

  /* Tipografía (misma línea que la landing: Instrument Sans + JetBrains Mono, pesos 550/650) */
  --font: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 20px;
  --text-2xl: 28px;
  --weight-regular: 450;
  --weight-medium: 550;
  --weight-strong: 650;

  /* Espaciado (escala de 4 px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radios (4 px en botones y controles, igual que la guía de la landing) */
  --radius-xs: 4px;
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;
  --radius-pill: 999px;

  /* Superficies y líneas cálidas (#fff / #faf9f8 / #f5f4f2, líneas #e0dcdb, tinta #161616 / #333840) */
  --bg: #f5f4f2;
  --surface: #ffffff;
  --surface-2: #faf9f8;
  --surface-3: #efedea;
  --surface-sunken: #f5f4f2;
  --border: #e0dcdb;
  --border-strong: #c9c4c2;
  --text: #161616;
  --text-2: #333840;
  --text-3: rgba(22, 22, 22, 0.62);

  /* Acento interactivo (#0768f8, enlaces y selección estilo Airtable) y botón primario en tinta (#161616) */
  --accent: #0768f8;
  --accent-hover: #0554cc;
  --accent-text: #0768f8;
  --accent-soft: #e6f0ff;
  --accent-softer: #f2f7ff;
  --on-accent: #ffffff;
  --brand-orange: #ff5b2e;

  /* Estados */
  --danger: #c43d2f;
  --danger-soft: #fbe9e6;
  --warning: #9a5b00;
  --warning-soft: #fef0c7;
  --success: #16803c;
  --success-soft: #dcfce7;

  /* Rejilla */
  --grid-line: #e0dcdb;
  --grid-head: #faf9f8;
  --grid-row-hover: #f7f6f4;
  --grid-sel: color-mix(in srgb, var(--accent) 8%, transparent);
  --grid-active: var(--accent);

  /* Sombras y foco */
  --shadow-sm: 0 0 1px rgba(0, 0, 0, 0.32), 0 0 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 0 1px rgba(0, 0, 0, 0.24), 0 4px 12px -2px rgba(0, 0, 0, 0.08), 0 8px 20px -4px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 0 0 1px rgba(24, 29, 38, 0.06), 0 2px 4px rgba(24, 29, 38, 0.04), 0 24px 48px -16px rgba(24, 29, 38, 0.18);
  --focus: 0 0 0 3px color-mix(in srgb, var(--accent) 24%, transparent);

  /* Movimiento */
  --ease: cubic-bezier(0.2, 0.72, 0.25, 1);
  --fast: 120ms;

  /* Paleta de opciones: intensidad (luminosidad y croma OKLCH) × tono */
  --ch-l0: 0.95; --ch-c0: 0.035; --ch-t0: #181d26;
  --ch-l1: 0.89; --ch-c1: 0.075; --ch-t1: #181d26;
  --ch-l2: 0.66; --ch-c2: 0.15;  --ch-t2: #ffffff;
  --ch-l3: 0.45; --ch-c3: 0.11;  --ch-t3: #ffffff;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121312;
  --surface: #1a1b1a;
  --surface-2: #222423;
  --surface-3: #2c2e2c;
  --surface-sunken: #161716;
  --border: #2d302e;
  --border-strong: #414542;
  --text: #ecebe7;
  --text-2: #aaa8a1;
  --text-3: #7b7a74;
  --accent: #3cb8a4;
  --accent-hover: #58c8b5;
  --accent-text: #6fd3c2;
  --accent-soft: #173a34;
  --accent-softer: #142a26;
  --on-accent: #08201c;
  --danger: #ec6a5c;
  --danger-soft: #3a1e1a;
  --warning: #e3a447;
  --warning-soft: #3a2d17;
  --success: #5ac27c;
  --success-soft: #19301f;
  --grid-line: #262826;
  --grid-head: #1d1f1e;
  --grid-row-hover: #1f2120;
  --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
  --shadow-md: 0 6px 18px rgb(0 0 0 / 45%);
  --shadow-lg: 0 20px 60px rgb(0 0 0 / 60%);
  --ch-l0: 0.32; --ch-c0: 0.05; --ch-t0: #ecebe7;
  --ch-l1: 0.42; --ch-c1: 0.09; --ch-t1: #ffffff;
  --ch-l2: 0.62; --ch-c2: 0.14; --ch-t2: #0d0e0d;
  --ch-l3: 0.78; --ch-c3: 0.11; --ch-t3: #0d0e0d;
}


/* ------------------------------------------------------------------------------------------------ Base */

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

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: var(--weight-strong); letter-spacing: -0.01em; }
h1 { font-size: var(--text-2xl); letter-spacing: -0.02em; }
h2 { font-size: var(--text-lg); }
p { margin: 0; }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }

.icon { flex: none; display: inline-block; vertical-align: middle; }
.muted { color: var(--text-3); }
.hint { color: var(--text-3); font-size: var(--text-sm); }
.empty { color: var(--text-3); padding: var(--space-6) 0; }
.center { display: grid; place-items: center; gap: var(--space-4); padding: var(--space-10); }

/* ------------------------------------------------------------------------------------------------ Botones */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 34px;
  padding: 0 var(--space-4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: var(--weight-medium);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: background var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast);
  text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn.primary { background: #161616; border-color: #161616; color: #ffffff; font-weight: var(--weight-strong); }
.btn.primary:hover { background: #2d3138; border-color: #2d3138; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { filter: brightness(0.95); }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { height: 28px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn.icon { width: 30px; height: 30px; padding: 0; }
.btn.block { width: 100%; height: 40px; }

/* ------------------------------------------------------------------------------------------------ Campos */

.input {
  width: 100%;
  height: 34px;
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  transition: border-color var(--fast), box-shadow var(--fast);
}
textarea.input { height: auto; padding: var(--space-2) var(--space-3); resize: vertical; line-height: 1.45; }
/* Desplegable propio (`widgets::Dropdown`): botón con el valor y lista flotante */
.dd-trigger { display: flex; align-items: center; gap: 6px; min-width: 0; text-align: left; cursor: pointer; }
.dd-trigger:disabled { cursor: default; opacity: 0.6; }
.dd-trigger > .icon:last-child { flex: none; margin-left: auto; color: var(--text-3); }
.dd-trigger[aria-expanded="true"] { border-color: var(--accent); box-shadow: var(--focus); }
.dd-value { flex: 1; display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; white-space: nowrap; }
.dd-value > .icon { flex: none; color: var(--text-3); }
.dd-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dd-placeholder { color: var(--text-3); overflow: hidden; text-overflow: ellipsis; }
.dd-trigger.multi { height: auto; min-height: 34px; padding-top: 4px; padding-bottom: 4px; }
.dd-trigger.multi .dd-value { flex-wrap: wrap; gap: 4px; white-space: normal; }
.dd-backdrop { z-index: 65; }
.dd-pop { position: fixed; z-index: 70; display: grid; align-content: start; gap: 1px; max-width: min(420px, 92vw); max-height: min(340px, 60vh); overflow: auto; padding: var(--space-1); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-md); outline: none; animation: pop var(--fast) var(--ease); }
.dd-search { height: 30px; margin-bottom: var(--space-1); font-size: var(--text-sm); }
.dd-item { display: flex; align-items: center; gap: var(--space-2); min-height: 30px; padding: 2px var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); font: inherit; font-size: var(--text-sm); text-align: left; cursor: pointer; }
.dd-item.hi { background: var(--surface-2); }
.dd-item > .icon { flex: none; color: var(--text-3); }
.dd-item .dd-label { flex: 1; }
.dd-check { display: inline-flex; margin-left: auto; padding-left: var(--space-2); color: var(--accent); }
.dd-empty { margin: 0; padding: var(--space-2); color: var(--text-3); font-size: var(--text-sm); }
.input:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
.input.short { width: 84px; }
.input.inline { height: 30px; min-width: 160px; }
.input::placeholder { color: var(--text-3); }

.form { display: grid; gap: var(--space-4); }
.field-label { display: grid; gap: 6px; font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text-2); }
.check-label { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-md); }
.error-line { display: flex; gap: var(--space-2); align-items: center; color: var(--danger); font-size: var(--text-sm); }

.callout {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.callout.success { background: var(--success-soft); color: var(--success); }
.callout.danger { background: var(--danger-soft); color: var(--danger); }
.callout p { color: var(--text); }

.badge {
  display: inline-flex;
  align-items: center;
  height: 20px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-pill);
  background: var(--surface-3);
  color: var(--text-2);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
}

.switch {
  appearance: none;
  width: 28px;
  height: 16px;
  flex: none;
  border-radius: var(--radius-pill);
  background: var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background var(--fast);
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--fast) var(--ease);
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(12px); }

.spinner-wrap { display: flex; gap: var(--space-3); align-items: center; justify-content: center; padding: var(--space-10); color: var(--text-2); }
.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--surface-3);
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------------------------------------ Capas */

.pop-anchor { position: relative; display: inline-flex; }
.backdrop { position: fixed; inset: 0; z-index: 40; }
.popover {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  min-width: 220px;
  max-height: min(70vh, 560px);
  overflow: auto;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-md);
  animation: pop var(--fast) var(--ease);
}
.popover.right { left: auto; right: 0; }
.popover.wide { min-width: min(640px, 92vw); }
.context-menu, .field-menu { position: fixed; top: 0; left: 0; }
@keyframes pop { from { opacity: 0; transform: translateY(-3px); } }

.menu { display: grid; gap: 1px; min-width: 220px; }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  height: 32px;
  padding: 0 var(--space-3);
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.menu-item:hover:not(:disabled), .menu-item:focus-visible { background: var(--surface-2); }
.menu-item:disabled { opacity: 0.45; cursor: default; }
.menu-item .grow { flex: 1; text-align: left; }
.menu-item.danger { color: var(--danger); }
.menu-item .icon { color: var(--text-3); }
.menu-item.danger .icon { color: var(--danger); }
.menu-sep { height: 1px; margin: var(--space-1) 0; background: var(--border); }
.menu-head { display: grid; padding: var(--space-2) var(--space-3) var(--space-3); }
.menu-title { padding: var(--space-1) var(--space-3) var(--space-2); color: var(--text-3); font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: 0.06em; }
.menu-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-1) var(--space-3); color: var(--text-2); }

.seg { display: inline-flex; padding: 2px; border-radius: var(--radius-sm); background: var(--surface-2); }
.seg-item { display: inline-flex; align-items: center; justify-content: center; min-width: 30px; height: 26px; padding: 0 10px; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--text-3); font-size: var(--text-xs); font-weight: var(--weight-medium); cursor: pointer; }
.seg-item.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: start center;
  padding: 8vh var(--space-4) var(--space-4);
  background: rgb(18 17 15 / 38%);
  backdrop-filter: blur(2px);
  animation: fade var(--fast) var(--ease);
}
@keyframes fade { from { opacity: 0; } }
.dialog {
  width: min(560px, 100%);
  max-height: 84vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.dialog.narrow { width: min(420px, 100%); }
.dialog.record { width: min(720px, 100%); }
.dialog-head { display: flex; align-items: center; gap: var(--space-2); padding: var(--space-4) var(--space-4) var(--space-3) var(--space-5); border-bottom: 1px solid var(--border); }
.dialog-head h2 { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dialog-body { padding: var(--space-5); overflow: auto; }
.dialog-foot { display: flex; justify-content: flex-end; gap: var(--space-2); padding: var(--space-3) var(--space-5) var(--space-5); }
.dialog-body + .dialog-foot { padding-top: 0; }
form.dialog-body .dialog-foot { padding: var(--space-2) 0 0; }

.toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 80; display: grid; gap: var(--space-2); }
.toast {
  max-width: 380px;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--surface);
  box-shadow: var(--shadow-md);
  font-size: var(--text-sm);
  animation: pop var(--fast) var(--ease);
}

/* ------------------------------------------------------------------------------------------------ Marca y cuentas */

.brand { display: inline-flex; align-items: center; gap: var(--space-2); color: var(--text); font-weight: var(--weight-strong); font-size: var(--text-lg); letter-spacing: -0.02em; }
.brand:hover { text-decoration: none; }
.logo {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: url("/app/img/marca.svg") center / contain no-repeat;
}

.auth { min-height: 100%; display: grid; place-items: center; padding: var(--space-8) var(--space-4);
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-softer), transparent 70%), var(--bg); }
.auth-card {
  width: min(400px, 100%);
  display: grid;
  gap: var(--space-5);
  padding: var(--space-8);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.auth-card h1 { font-size: var(--text-xl); }
.auth-card .muted { margin-top: calc(-1 * var(--space-3)); }
.auth-links { display: grid; gap: var(--space-2); justify-items: center; font-size: var(--text-sm); color: var(--text-2); }

.banner { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-2) var(--space-5); background: var(--warning-soft); color: var(--warning); font-size: var(--text-sm); }
.banner span { color: var(--text); flex: 1; }

/* ------------------------------------------------------------------------------------------------ Inicio */

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  height: 52px;
  padding: 0 var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.topbar-middle { flex: 1; min-width: 0; display: flex; align-items: center; }
.avatar {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-strong);
  cursor: pointer;
}
.account-menu { min-width: 260px; }

.home { min-height: 100%; }
.home-main { max-width: 1120px; margin: 0 auto; padding: var(--space-8) var(--space-6) var(--space-10); }
.home-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-6); }
.workspace { margin-bottom: var(--space-8); }
.workspace-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); color: var(--text-2); }
.workspace-head h2 { color: var(--text); }
.base-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(232px, 1fr)); gap: var(--space-3); }
.base-card {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 72px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--fast), box-shadow var(--fast), transform var(--fast) var(--ease);
}
.base-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.base-link { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-10) var(--space-3) var(--space-3); color: var(--text); }
.base-link:hover { text-decoration: none; }
.base-card.new { gap: var(--space-3); padding: var(--space-3); border-style: dashed; background: transparent; box-shadow: none; cursor: pointer; color: var(--text-2); }
.base-card.new .base-tile { background: var(--surface-2); color: var(--text-2); }
.base-name { font-weight: var(--weight-medium); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.base-more { position: absolute; right: var(--space-2); top: 50%; transform: translateY(-50%); opacity: 0; transition: opacity var(--fast); }
.base-card:hover .base-more, .base-more:focus-within { opacity: 1; }
.base-rename { position: absolute; left: 64px; right: 44px; width: auto; }
.base-tile {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 11px;
  color: #fff;
  font-weight: var(--weight-strong);
  font-size: var(--text-md);
  letter-spacing: 0.02em;
}
.base-tile.small { width: 28px; height: 28px; border-radius: 8px; font-size: var(--text-xs); }
.tone-0 { background: oklch(0.58 0.12 180); }
.tone-1 { background: oklch(0.56 0.14 255); }
.tone-2 { background: oklch(0.6 0.15 40); }
.tone-3 { background: oklch(0.55 0.15 310); }
.tone-4 { background: oklch(0.6 0.13 140); }
.tone-5 { background: oklch(0.58 0.16 15); }
.tone-6 { background: oklch(0.62 0.12 85); }
.tone-7 { background: oklch(0.5 0.05 260); }

/* ------------------------------------------------------------------------------------------------ Ajustes */
/* Cuenta, API y tokens, aplicaciones conectadas, facturación y consentimiento OAuth (ui/ajustes.rs). */

.settings-main { display: grid; grid-template-columns: 220px minmax(0, 760px); justify-content: center; gap: var(--space-10); max-width: 1120px; margin: 0 auto; padding: var(--space-8) var(--space-6) var(--space-10); }
.settings-nav { position: sticky; top: var(--space-6); align-self: start; display: grid; gap: 2px; }
.settings-link { display: flex; align-items: center; gap: var(--space-2); height: 32px; padding: 0 var(--space-3); border-radius: var(--radius-md); color: var(--text-2); font-size: var(--text-md); font-weight: var(--weight-medium); text-decoration: none; transition: background var(--fast) var(--ease); }
.settings-link:hover { background: var(--surface-3); color: var(--text); }
.settings-link[aria-current="page"] { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.settings-link:last-child { margin-top: var(--space-3); color: var(--text-3); }
.settings-content { display: grid; gap: var(--space-4); align-content: start; min-width: 0; }
.settings-content h1 { margin: 0 0 var(--space-1); font-size: var(--text-2xl); font-weight: var(--weight-strong); letter-spacing: -0.01em; }
.settings-content h2 { margin: var(--space-6) 0 0; font-size: var(--text-lg); font-weight: var(--weight-strong); }
.settings-content > p { margin: 0; line-height: 1.55; }
.settings-card { display: grid; gap: var(--space-4); padding: var(--space-5); border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface); box-shadow: var(--shadow-sm); }
.settings-card.highlight { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); background: var(--accent-softer); }
.settings-card.highlight > .btn { justify-self: start; }
.settings-card p { margin: 0; }
.settings-card pre { margin: 0; padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
.settings-card > .btn.primary { justify-self: start; }
.settings-card h3 { margin: 0; font-size: var(--text-md); font-weight: var(--weight-strong); }
.settings-card > .seg { justify-self: start; }
.field-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; min-height: 32px; font-size: var(--text-md); }
.field-row + .field-row { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.field-row > .field-label { flex: 0 0 180px; }
.field-row > .input { flex: 1 1 260px; }
.field-row > div:first-child:not(.seg) { display: grid; gap: 2px; flex: 1 1 auto; }
.plan-rows .field-row { justify-content: space-between; }
.mono { font-family: var(--font-mono); font-size: var(--text-xs); }
.settings-card.mono { font-family: var(--font); font-size: var(--text-md); }
.token-value { user-select: all; }
.token-list { display: grid; gap: var(--space-2); }
.token-list > p { margin: var(--space-1) 0 0; }
.token-item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-3) var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); }
.token-item > div { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; min-width: 0; }
.badge.write { background: var(--accent-soft); color: var(--accent-text); }
.badge.read { background: var(--surface-3); color: var(--text-2); }
.consent-client { display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.consent-client code { padding: 1px 6px; border-radius: var(--radius-xs); background: var(--surface-3); font-family: var(--font-mono); font-size: var(--text-xs); }
.usage-row, .usage-base { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: var(--space-2) var(--space-4); font-size: var(--text-md); }
.usage-row + .usage-row, .usage-base + .usage-row { padding-top: var(--space-4); border-top: 1px solid var(--border); }
.usage-base { padding-left: var(--space-4); font-size: var(--text-sm); }
.usage-bar { grid-column: 1 / -1; height: 6px; border-radius: var(--radius-pill); background: var(--surface-3); overflow: hidden; }
.usage-fill { height: 100%; border-radius: inherit; background: var(--accent); transition: width 240ms var(--ease); }
.plan-rows { display: grid; gap: var(--space-4); }
@media (max-width: 760px) {
  .settings-main { grid-template-columns: minmax(0, 1fr); gap: var(--space-5); padding: var(--space-5) var(--space-4) var(--space-8); }
  .settings-nav { position: static; display: flex; flex-wrap: wrap; }
  .settings-link:last-child { margin-top: 0; }
  .field-row > .field-label { flex-basis: 100%; }
}

/* ------------------------------------------------------------------------------------------------ Base abierta */

.base-screen { height: 100%; display: flex; flex-direction: column; overflow: hidden; }
.base-title { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.base-menu-btn { display: flex; align-items: center; gap: var(--space-2); height: 40px; padding: 0 var(--space-2) 0 var(--space-1); border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text); font-size: var(--text-lg); font-weight: var(--weight-strong); cursor: pointer; min-width: 0; }
.base-menu-btn:hover, .base-menu-btn[aria-expanded="true"] { background: var(--surface-2); }
.base-menu-btn .icon { color: var(--text-3); flex: none; }
.base-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 36vw; }
.base-tile-bc { flex: none; display: inline-grid; place-items: center; border-radius: var(--radius-md); background: var(--bc-tile); color: var(--bc-ink); border: 1px solid rgba(0, 0, 0, 0.1); font-size: var(--text-sm); font-weight: var(--weight-strong); }
.base-initials { letter-spacing: -0.02em; line-height: 1; }
.top-nav { display: flex; align-items: stretch; align-self: stretch; gap: var(--space-4); margin-left: var(--space-4); }
.top-nav-item { position: relative; display: flex; align-items: center; padding: 0 var(--space-1); color: var(--text-3); font-weight: var(--weight-medium); }
.top-nav-item.on { color: var(--text); }
.top-nav-item.on::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--bc-dark); }
.base-menu { min-width: 340px; padding: var(--space-3); }
.base-menu-name { font-size: var(--text-lg); font-weight: var(--weight-medium); height: 40px; }
.menu-section { display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: var(--space-2) var(--space-1); border: 0; background: transparent; font-size: var(--text-md); font-weight: var(--weight-medium); color: var(--text); cursor: pointer; }
.sync-pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: var(--radius-pill); font-size: var(--text-xs); font-weight: var(--weight-medium); white-space: nowrap; }
.sync-pill.ok { color: var(--text-3); }
.sync-pill.busy { color: var(--accent-text); background: var(--accent-softer); }
.sync-pill.busy .icon { animation: spin 1.2s linear infinite; }
.sync-pill.offline { color: var(--warning); background: var(--warning-soft); }

/* Selector de aspecto (color e ícono) */
.appearance { display: grid; gap: var(--space-3); padding: var(--space-1) 0 var(--space-2); }
.appearance-tabs { display: flex; gap: var(--space-5); border-bottom: 1px solid var(--border); }
.appearance-tab { padding: var(--space-2) 2px; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; color: var(--text-3); font-weight: var(--weight-medium); cursor: pointer; }
.appearance-tab.on { color: var(--text); border-bottom-color: var(--bc-dark, var(--accent)); }
.swatches { display: grid; grid-template-columns: repeat(10, 28px); gap: var(--space-2); }
.swatch { width: 28px; height: 28px; display: grid; place-items: center; border: 0; border-radius: var(--radius-md); color: #fff; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08); }
.swatch:hover:not(:disabled) { transform: scale(1.08); }
.swatch.on { box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2), 0 0 0 2px var(--surface), 0 0 0 4px var(--text-2); }
.swatch:disabled { cursor: default; opacity: 0.6; }
.icon-search { display: flex; align-items: center; gap: var(--space-2); height: 32px; padding: 0 var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-md); color: var(--text-3); }
.icon-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; color: var(--text); }
.icon-grid { display: grid; grid-template-columns: repeat(8, 36px); gap: 2px; max-height: 224px; overflow: auto; padding: 2px; }
.icon-pick { width: 36px; height: 36px; display: grid; place-items: center; border: 0; border-radius: var(--radius-md); background: transparent; color: var(--text-2); cursor: pointer; }
.icon-pick:hover:not(:disabled) { background: var(--surface-3); }
.icon-pick.on { background: var(--bc-tile); color: var(--bc-ink); }
.icon-initials { font-size: var(--text-xs); font-weight: var(--weight-strong); }

/* Pestañas de tablas: la barra se tiñe con el color de la base */
.table-tabs { display: flex; align-items: flex-end; gap: var(--space-2); height: 36px; padding: 4px 0 0 var(--space-3); background: var(--bc-tint); border-bottom: 1px solid var(--bc-line); }
.tabs-scroll { display: flex; align-items: flex-end; overflow-x: auto; min-width: 0; flex: 0 1 auto; scrollbar-width: none; }
.tab-wrap { display: flex; align-items: flex-end; position: relative; }
.tab-wrap + .tab-wrap::before { content: ""; position: absolute; left: 0; bottom: 8px; height: 14px; width: 1px; background: color-mix(in srgb, var(--bc-dark) 25%, transparent); }
.tab { display: flex; align-items: center; height: 32px; padding: 0 2px; border-radius: var(--radius-sm) var(--radius-sm) 0 0; color: color-mix(in srgb, var(--text) 68%, transparent); }
.tab:hover { color: var(--text); background: color-mix(in srgb, var(--bc-line) 55%, transparent); }
.tab.active { background: var(--surface); color: var(--text); box-shadow: 0 0 1px rgba(0, 0, 0, 0.32), 0 0 2px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.08); font-weight: var(--weight-medium); height: 33px; margin-bottom: -1px; }
.tab-btn { display: flex; align-items: center; gap: 6px; height: 100%; padding: 0 var(--space-3); border: 0; background: transparent; cursor: pointer; white-space: nowrap; font: inherit; color: inherit; }
.tab-mark { display: inline-flex; }
.tab-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tab .input.inline { min-width: 120px; height: 26px; }
.tab-more { display: grid; place-items: center; width: 22px; height: 22px; margin-right: 4px; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--text-3); cursor: pointer; }
.tab-more:hover { background: var(--surface-2); color: var(--text); }
.tabs-tail { display: flex; align-items: center; gap: 2px; padding-bottom: 4px; padding-right: var(--space-3); flex: 1; justify-content: flex-start; }
.tab-icon-btn { position: relative; display: grid; place-items: center; width: 28px; height: 28px; border: 0; border-radius: var(--radius-sm); background: transparent; color: color-mix(in srgb, var(--text) 68%, transparent); cursor: pointer; }
.tab-icon-btn:hover { background: color-mix(in srgb, var(--bc-line) 70%, transparent); color: var(--text); }
.tab-badge { position: absolute; top: -2px; right: -2px; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px; background: var(--bc-dark); color: #fff; font-size: 10px; line-height: 14px; text-align: center; }
.tables-menu { min-width: 300px; padding: var(--space-2); }
.menu-search { display: flex; align-items: center; gap: var(--space-2); height: 36px; padding: 0 var(--space-2); border: 1px solid var(--accent); border-radius: var(--radius-md); color: var(--text-3); margin-bottom: var(--space-2); }
.menu-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; color: var(--text); }
.tables-list { display: grid; max-height: 360px; overflow: auto; }
.tables-row { display: flex; align-items: center; border-radius: var(--radius-sm); }
.tables-row:hover { background: var(--surface-2); }
.tables-row.active { background: var(--surface-3); }
.tables-pick { flex: 1; display: flex; align-items: center; gap: var(--space-2); height: 32px; padding: 0 var(--space-2); border: 0; background: transparent; text-align: left; font: inherit; color: var(--text); cursor: pointer; min-width: 0; }
.tables-check { width: 16px; display: inline-grid; place-items: center; flex: none; }
.tables-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: var(--weight-medium); }
.tables-name.dim { color: var(--text-3); font-weight: var(--weight-regular); }
.table-menu { min-width: 372px; }
.add-table-menu { min-width: 280px; }
.create-view-menu { min-width: 240px; }

/* Barra de la vista y herramientas */
.view-bar { display: flex; align-items: center; gap: var(--space-2); height: 48px; padding: 0 var(--space-3); background: var(--surface); border-bottom: 1px solid var(--border); }
.icon-btn { display: grid; place-items: center; width: 32px; height: 32px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover, .icon-btn[aria-pressed="true"] { background: var(--surface-2); color: var(--text); }
.view-current { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-strong); min-width: 0; max-width: 260px; padding: 0 var(--space-2); }
.view-current-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kind-ico { display: inline-flex; flex: none; }
.toolbar { display: flex; align-items: center; gap: 2px; margin-left: var(--space-2); }
.tool { display: flex; align-items: center; gap: 6px; height: 28px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text-2); cursor: pointer; white-space: nowrap; }
.tool > span { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.tool:hover, .tool[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.tool.on { color: var(--text); }
.tool.on.t-hide { background: rgb(209, 226, 255); }
.tool.on.t-filter { background: rgb(207, 245, 209); }
.tool.on.t-group { background: rgb(193, 245, 240); }
.tool.on.t-sort { background: rgb(255, 224, 204); }
.record-count { margin-left: auto; color: var(--text-3); font-size: var(--text-sm); white-space: nowrap; }
.search { display: flex; align-items: center; gap: 6px; height: 30px; padding: 0 var(--space-2); border-radius: var(--radius-sm); color: var(--text-3); transition: background var(--fast); }
.search.open { background: var(--surface-2); color: var(--text-2); }
.search-input { width: 120px; border: 0; background: transparent; color: var(--text); font: inherit; outline: none; transition: width var(--fast) var(--ease); }
.search.open .search-input { width: 200px; }

/* Barra lateral de vistas */
.base-main { flex: 1; min-height: 0; display: flex; }
.view-sidebar { flex: none; width: 280px; display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); background: var(--surface); border-right: 1px solid var(--border); overflow: auto; }
.sidebar-create { display: block; }
.sidebar-create-btn { display: flex; align-items: center; gap: var(--space-2); width: 100%; height: 36px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); font: inherit; cursor: pointer; }
.sidebar-create-btn:hover:not(:disabled) { background: var(--surface-2); }
.sidebar-create-btn:disabled { color: var(--text-3); cursor: default; }
.sidebar-search { display: flex; align-items: center; gap: var(--space-2); height: 32px; padding: 0 var(--space-2); color: var(--text-3); border-bottom: 1px solid transparent; }
.sidebar-search:focus-within { border-bottom-color: var(--accent); }
.sidebar-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; font: inherit; color: var(--text); }
.sidebar-views { list-style: none; margin: var(--space-2) 0 0; padding: 0; display: grid; gap: 1px; }
.sidebar-view { display: flex; align-items: center; border-radius: var(--radius-sm); }
.sidebar-view:hover { background: var(--surface-2); }
.sidebar-view.active { background: var(--surface-3); }
.sidebar-pick { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--space-2); height: 34px; padding: 0 var(--space-2); border: 0; background: transparent; font: inherit; color: var(--text); text-align: left; cursor: pointer; }
.sidebar-view.active .sidebar-name { font-weight: var(--weight-medium); }
.sidebar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-more { display: grid; place-items: center; width: 26px; height: 26px; margin-right: 4px; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--text-3); cursor: pointer; opacity: 0; }
.sidebar-view:hover .sidebar-more, .sidebar-more:focus-visible, .sidebar-more[aria-expanded="true"] { opacity: 1; }
.sidebar-more:hover { background: var(--surface-3); color: var(--text); }
.view-item-menu { right: 0; left: auto; }

.base-body { flex: 1; min-width: 0; min-height: 0; position: relative; background: var(--surface); }

/* ------------------------------------------------------------------------------------------------ Rejilla */

.grid {
  position: absolute;
  inset: 0 0 34px 0;
  overflow: auto;
  outline: none;
  user-select: none;
  -webkit-user-select: none;
  font-size: var(--text-md);
  overscroll-behavior: contain;
  contain: strict;
}
.grid-canvas { position: relative; min-height: 100%; }
.grid-head {
  position: sticky;
  top: 0;
  z-index: 6;
  width: 100%;
  background: var(--grid-head);
  border-bottom: 1px solid var(--border);
}
.grid-head .frozen { position: sticky; left: 0; z-index: 2; display: flex; height: 100%; background: var(--grid-head); }
.head-gutter { border-right: 1px solid var(--grid-line); }
.head-cell {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 var(--space-2) 0 var(--space-3);
  border-right: 1px solid var(--grid-line);
  color: var(--text-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  cursor: pointer;
}
.head-cell.frozen-cell { position: relative; flex: none; border-right-color: var(--border-strong); }
.head-cell:hover { background: var(--surface-2); color: var(--text); }
.head-cell.sel-col { background: color-mix(in srgb, var(--accent) 7%, var(--grid-head)); color: var(--text); }
.head-cell > .icon:first-child { color: var(--text-3); }
.head-cell > .icon:last-of-type { margin-left: auto; opacity: 0; color: var(--text-3); }
.head-cell:hover > .icon:last-of-type { opacity: 1; }
.head-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.col-resize { position: absolute; top: 0; right: -4px; width: 8px; height: 100%; cursor: col-resize; z-index: 1; }
.col-resize:hover { background: linear-gradient(to right, transparent 3px, var(--accent) 3px, var(--accent) 5px, transparent 5px); }
.head-add { position: absolute; top: 0; width: 44px; height: 100%; border: 0; border-right: 1px solid var(--grid-line); background: transparent; color: var(--text-3); cursor: pointer; display: grid; place-items: center; }
.head-add:hover { background: var(--surface-2); color: var(--text); }

.grid-rows { position: relative; }
.grid-row { position: absolute; left: 0; width: 100%; height: 34px; }
.grid-row:hover .cell, .grid-row:hover .frozen { background-color: var(--grid-row-hover); }
.grid-row.editing-row { z-index: 3; }
.grid-row > .frozen { position: sticky; left: 0; z-index: 2; display: flex; height: 100%; background: var(--surface); }
.gutter { flex: none; width: 64px; display: flex; align-items: center; justify-content: space-between; padding: 0 var(--space-2) 0 var(--space-3); border-bottom: 1px solid var(--grid-line); border-right: 1px solid var(--grid-line); color: var(--text-3); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }
.grid-head .gutter { border-bottom: 0; }
.row-sel .gutter { background: var(--grid-sel); color: var(--accent-text); }
.row-expand { display: grid; place-items: center; width: 22px; height: 22px; border: 0; border-radius: var(--radius-xs); background: transparent; color: var(--accent-text); cursor: pointer; opacity: 0; }
.grid-row:hover .row-expand, .row-expand:focus-visible { opacity: 1; }
.row-expand:hover { background: var(--accent-soft); }

.cell {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: center;
  padding: 0 var(--space-3);
  border-right: 1px solid var(--grid-line);
  border-bottom: 1px solid var(--grid-line);
  background: var(--surface);
  white-space: nowrap;
  overflow: visible;
  cursor: default;
}
.cell.frozen-cell { position: relative; flex: none; border-right-color: var(--border-strong); font-weight: var(--weight-medium); }
.cell.sel { background-color: var(--grid-sel) !important; }
.cell.active { box-shadow: inset 0 0 0 2px var(--grid-active); border-radius: 2px; z-index: 1; }
.cv { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.cv.num { text-align: right; font-variant-numeric: tabular-nums; }
.cv.muted { color: var(--text-3); font-variant-numeric: tabular-nums; }
.link-text { color: var(--accent-text); text-decoration: underline; text-decoration-color: color-mix(in srgb, var(--accent) 35%, transparent); text-underline-offset: 2px; }

.check {
  display: grid;
  place-items: center;
  width: 17px;
  height: 17px;
  padding: 0;
  border: 1.5px solid var(--border-strong);
  border-radius: 5px;
  background: var(--surface);
  color: var(--on-accent);
  cursor: pointer;
}
.check.on { background: var(--accent); border-color: var(--accent); }

.chips { display: flex; gap: 4px; min-width: 0; overflow: hidden; }
.chip {
  --h: 250;
  --cm: 1;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: none;
  max-width: 220px;
  height: 22px;
  padding: 0 9px;
  border: 0;
  border-radius: var(--radius-pill);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  line-height: 22px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.link { border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text); cursor: pointer; }
.chip.link:hover { filter: brightness(0.97); }
.chip-x { display: grid; place-items: center; width: 16px; height: 16px; margin-right: -4px; padding: 0; border: 0; border-radius: 50%; background: transparent; color: inherit; opacity: 0.7; cursor: pointer; }
.chip-x:hover { opacity: 1; background: rgb(0 0 0 / 10%); }
.chip.toggle { cursor: pointer; }
.chip.toggle.off { opacity: 0.45; }
.chip.swatch { width: 22px; padding: 0; cursor: pointer; }

/* Paleta de 40: tono (0–9: azul, cian, verde azulado, verde, amarillo, naranja, rojo, rosa, morado, gris) × intensidad */
.ch-h0 { --h: 258; } .ch-h1 { --h: 222; } .ch-h2 { --h: 186; } .ch-h3 { --h: 148; } .ch-h4 { --h: 96; }
.ch-h5 { --h: 62; } .ch-h6 { --h: 25; } .ch-h7 { --h: 350; } .ch-h8 { --h: 300; } .ch-h9 { --h: 260; --cm: 0.12; }
.ch-i0 { background: oklch(var(--ch-l0) calc(var(--ch-c0) * var(--cm)) var(--h)); color: var(--ch-t0); }
.ch-i1 { background: oklch(var(--ch-l1) calc(var(--ch-c1) * var(--cm)) var(--h)); color: var(--ch-t1); }
.ch-i2 { background: oklch(var(--ch-l2) calc(var(--ch-c2) * var(--cm)) var(--h)); color: var(--ch-t2); }
.ch-i3 { background: oklch(var(--ch-l3) calc(var(--ch-c3) * var(--cm)) var(--h)); color: var(--ch-t3); }

.stars { display: inline-flex; gap: 1px; }
.star { display: grid; place-items: center; padding: 1px; border: 0; background: transparent; color: var(--border-strong); cursor: pointer; }
.star.on { color: #e5a00d; }
.star.on svg { fill: currentColor; }

.group-row > .frozen { background: var(--surface-2); border-bottom: 1px solid var(--border); width: max(100%, 480px); }
.group-row.depth-1 > .frozen { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.group-row.depth-2 > .frozen { background: var(--surface); }
.group-toggle { display: flex; align-items: center; gap: var(--space-2); width: 100%; height: 100%; border: 0; background: transparent; cursor: pointer; text-align: left; }
.group-field { color: var(--text-3); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.05em; }
.group-label { font-weight: var(--weight-strong); }
.group-count { color: var(--text-3); font-size: var(--text-sm); font-variant-numeric: tabular-nums; }

.add-record { display: flex; align-items: center; gap: var(--space-2); width: 320px; height: 100%; padding: 0 var(--space-3); border: 0; border-bottom: 1px solid var(--grid-line); border-right: 1px solid var(--grid-line); background: var(--surface); color: var(--text-3); cursor: pointer; }
.add-record:hover { color: var(--accent-text); background: var(--accent-softer); }

/* ------------------------------------------------------------------------------------------------ Editores */

.editor.inline { position: absolute; left: -1px; top: -1px; z-index: 10; min-width: calc(100% + 2px); }
.editor.inline .input { height: 36px; border: 2px solid var(--accent); border-radius: 3px; box-shadow: var(--shadow-md); padding: 0 calc(var(--space-3) - 1px); }
.editor.inline.long { width: max(100%, 340px); }
.editor.inline.long .input { height: auto; min-height: 120px; padding: var(--space-2) var(--space-3); }
.editor-error { margin-top: 4px; padding: 4px 8px; border-radius: var(--radius-xs); background: var(--danger-soft); color: var(--danger); font-size: var(--text-sm); white-space: normal; box-shadow: var(--shadow-sm); }

.picker { position: absolute; left: -1px; top: calc(100% + 2px); z-index: 10; }
.record-value .picker { top: calc(100% + 4px); left: 0; }
.picker-panel { position: relative; z-index: 45; width: 280px; display: grid; gap: var(--space-2); padding: var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-md); white-space: normal; }
.picker-panel.wide { width: 340px; }
.picker-selected { display: flex; flex-wrap: wrap; gap: 4px; }
.picker-selected:empty { display: none; }
.picker-list { display: grid; max-height: 260px; overflow: auto; }
.picker-item { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); min-height: 32px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; cursor: pointer; }
.picker-item:hover, .picker-item.hi { background: var(--surface-2); }
.picker-item .icon { color: var(--accent); }
.picker-item.create { color: var(--accent-text); justify-content: flex-start; }
.picker-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-empty { padding: var(--space-2); color: var(--text-3); }

/* ------------------------------------------------------------------------------------------------ Paneles */

.panel { display: grid; gap: var(--space-3); min-width: 300px; padding: var(--space-2); }
.panel-list { display: grid; gap: var(--space-2); }
.panel-foot { display: flex; justify-content: space-between; gap: var(--space-2); }
.panel-foot.start { justify-content: flex-start; }
.panel-empty { color: var(--text-3); font-size: var(--text-sm); padding: var(--space-1) var(--space-1); }
.toggle-row { display: flex; align-items: center; gap: var(--space-3); height: 30px; padding: 0 var(--space-1); border-radius: var(--radius-sm); cursor: pointer; }
.toggle-row:hover { background: var(--surface-2); }
.toggle-row .icon { color: var(--text-3); }
/* Filas de filtro, orden y agrupación: «Donde» y, unidos como en Airtable, campo · operador · valor */
.filter-head { margin: 0; padding: 0 var(--space-1); color: var(--text-3); font-size: var(--text-sm); }
.rule-row { display: flex; align-items: flex-start; gap: var(--space-2); }
.rule-lead { flex: none; width: 72px; padding: 7px 0 0 var(--space-1); color: var(--text-2); font-size: var(--text-sm); }
.dd-trigger.rule-lead { height: 34px; padding: 0 var(--space-2); }
.rule-lead.wide { width: 96px; }
.rule-cond { flex: 1; display: flex; align-items: stretch; min-width: 0; }
.rule-cond > * { flex: 1; width: auto; min-width: 0; height: auto; min-height: 34px; margin-left: -1px; border-radius: 0; }
.filter-panel { min-width: min(720px, 90vw); }
.rule-cond > :first-child { margin-left: 0; border-top-left-radius: var(--radius-sm); border-bottom-left-radius: var(--radius-sm); }
.rule-cond > :last-child { border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
.rule-cond > .rule-field { flex: 1.1; }
.rule-cond > .rule-op { flex: 1; min-width: 150px; }
.rule-cond > .rule-value { flex: 1.6; }
.rule-cond > .rule-days { flex: 0 0 72px; }
.rule-cond > .rule-date { flex: 1; }
.rule-cond > :focus, .rule-cond > :focus-within, .rule-cond > [aria-expanded="true"] { position: relative; z-index: 1; }
.rule-cond > .rule-blank { border: 0; }
.rule-cond:has(> .rule-blank) > .rule-op { border-top-right-radius: var(--radius-sm); border-bottom-right-radius: var(--radius-sm); }
.rule-static { display: flex; align-items: center; flex: 0 0 auto !important; padding: 0 var(--space-3); background: var(--surface-2); color: var(--text-2); }
.rule-check { display: flex; align-items: center; cursor: pointer; }
.rule-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.rule-num { display: flex; align-items: center; gap: 6px; }
.rule-num:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.rule-num input { flex: 1; min-width: 0; height: 32px; padding: 0; border: 0; outline: none; background: transparent; color: inherit; font: inherit; }
.rule-unit { flex: none; color: var(--text-3); }
.rule-group { flex: 1; display: grid; gap: var(--space-2); padding: var(--space-2); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-2); }
.rule-group .rule-cond > * { background: var(--surface); }
.rule-group-foot { display: flex; gap: var(--space-2); }

/* ------------------------------------------------------------------------------------------------ Campos */

.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px; }
.type-option { display: flex; align-items: center; gap: var(--space-2); height: 32px; padding: 0 var(--space-2); border: 1px solid transparent; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text); font-weight: var(--weight-regular); text-align: left; cursor: pointer; }
.type-option .icon { color: var(--text-3); }
.type-option:hover { border-color: var(--border-strong); }
.type-option.on { border-color: var(--accent); background: var(--accent-softer); color: var(--accent-text); }
.type-option.on .icon { color: var(--accent); }
.choices-edit { display: grid; gap: 6px; justify-items: start; }
.choice-row { display: flex; align-items: center; gap: var(--space-2); width: 100%; }
.dialog.field-dialog { width: min(620px, 100%); }

/* ------------------------------------------------------------------------------------------------ Ficha */

.record-title { flex: 1; min-width: 0; }
.record-title h2 { font-size: var(--text-xl); }
.eyebrow { color: var(--text-3); font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: 0.06em; }
.record-body { display: grid; gap: var(--space-5); padding: var(--space-5) var(--space-6) var(--space-8); overflow: auto; }
.record-field { display: grid; gap: 6px; }
.record-label { display: flex; align-items: center; gap: 6px; color: var(--text-2); font-size: var(--text-sm); font-weight: var(--weight-medium); }
.record-label .icon { color: var(--text-3); }
.record-value { position: relative; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; min-height: 34px; padding: 4px var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); }
.record-value .chips { flex-wrap: wrap; overflow: visible; }
.record-value.editable { cursor: pointer; }
.record-value.editable:hover { border-color: var(--border-strong); }
.placeholder { color: var(--text-3); }
.record-field .editor .input { min-height: 34px; }
.record-slot { position: relative; }
.edit-mark.mark-field { border-radius: var(--radius-sm); }
.btn.icon.on { background: var(--surface-3); color: var(--text); }

/* Ficha con el panel «Actividad» a la derecha (360 px); en pantallas estrechas, debajo de los campos. */
.dialog.record.with-activity {
  width: min(1080px, 100%);
  height: 84vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-rows: auto minmax(0, 1fr);
}
.dialog.record.with-activity > .dialog-head { grid-column: 1 / -1; }
.dialog.record.with-activity > .record-body { min-height: 0; align-content: start; }
.activity { grid-column: 2; grid-row: 2; display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); background: var(--surface-2); }
.activity-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border); }
.activity-head h3 { margin: 0; font-size: var(--text-md); font-weight: var(--weight-strong); }
.activity-feed { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.activity-feed .spinner-wrap { padding: var(--space-6); }
.activity-more { align-self: center; }
.activity-empty { margin: auto 0 0; display: grid; justify-items: center; gap: var(--space-2); padding: var(--space-6) var(--space-2); color: var(--text-3); text-align: center; font-size: var(--text-sm); }
.activity-foot { display: grid; gap: var(--space-1); padding: var(--space-3) var(--space-4) var(--space-4); border-top: 1px solid var(--border); background: var(--surface); }
.activity-foot .hint { margin: 0; }

.act-item { display: flex; gap: var(--space-2); align-items: flex-start; min-width: 0; }
.act-item:first-of-type { margin-top: auto; }
.act-avatar { --who: #5c6470; flex: none; display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--who); color: #fff; font-size: var(--text-xs); font-weight: var(--weight-strong); }
.act-avatar.small { width: 20px; height: 20px; font-size: 10.5px; }
.act-main { flex: 1; min-width: 0; display: grid; gap: 4px; }
.act-line { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; min-height: 24px; font-size: var(--text-sm); color: var(--text-2); }
.act-who { color: var(--text); font-weight: var(--weight-strong); }
.act-who.agent { color: var(--brand-orange); }
.act-time { color: var(--text-3); font-size: var(--text-xs); white-space: nowrap; }
.act-edited { color: var(--text-3); font-size: var(--text-xs); }
.act-menu { margin-left: auto; opacity: 0; transition: opacity var(--fast); }
.act-item:hover .act-menu, .act-menu:focus-within { opacity: 1; }
.icon-btn.small { width: 24px; height: 24px; }
.act-body { margin: 0; padding: var(--space-2) var(--space-3); border: 1px solid var(--border); border-radius: 2px var(--radius-md) var(--radius-md) var(--radius-md); background: var(--surface); color: var(--text); white-space: pre-wrap; overflow-wrap: anywhere; }
.mention { display: inline-block; padding: 0 5px; border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text); font-weight: var(--weight-medium); }
.mention.me { background: var(--accent); color: var(--on-accent); }
.act-what strong { color: var(--text); font-weight: var(--weight-medium); }
.act-diff { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
/* Cambio: autor, «cambió Campo» y la hora en una línea; debajo, anterior → nuevo. */
.act-item.revision .act-time { order: 1; }
.act-item.revision .act-diff { order: 2; }
.act-diff > .icon { color: var(--text-3); flex: none; }
.act-old, .act-new { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px; max-width: 100%; min-height: 24px; padding: 1px 6px; border-radius: var(--radius-xs); }
.act-old { background: var(--danger-soft); text-decoration: line-through; text-decoration-color: color-mix(in srgb, var(--danger) 70%, transparent); opacity: 0.85; }
.act-old .cv, .act-old .placeholder { color: var(--danger); }
.act-new { background: var(--success-soft); }
.chip.act-link { border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text); }
.act-new .cv:not(.link-text), .act-new .placeholder { color: var(--success); }
.act-old .chips, .act-new .chips { flex-wrap: wrap; overflow: visible; }
.act-old .cv, .act-new .cv { white-space: normal; overflow-wrap: anywhere; }
.act-confirm { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); padding: var(--space-2); border-radius: var(--radius-sm); background: var(--danger-soft); font-size: var(--text-sm); }
.act-confirm span { flex: 1; color: var(--text); }

/* Caja de comentario: el texto se escribe en el textarea transparente; detrás, una copia resalta las menciones. */
.composer { position: relative; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: var(--space-2); }
.composer-box { position: relative; grid-column: 1; border: 1px solid var(--border-strong); border-radius: var(--radius-md); background: var(--surface); transition: border-color var(--fast), box-shadow var(--fast); }
.composer-box:focus-within { border-color: var(--accent); box-shadow: var(--focus); }
.composer.disabled .composer-box { background: var(--surface-2); }
.composer-mirror, .composer-input {
  margin: 0; padding: 7px 10px;
  font: inherit; font-size: var(--text-md); line-height: 20px; letter-spacing: normal;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal;
  scrollbar-gutter: stable;
}
.composer-mirror { position: absolute; inset: 0; overflow: hidden; color: transparent; pointer-events: none; }
.mention-hl { border-radius: 3px; background: var(--accent-soft); box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 30%, transparent); }
.composer-input { position: relative; display: block; width: 100%; min-height: 36px; max-height: 160px; border: 0; outline: none; resize: none; overflow-y: auto; background: transparent; color: var(--text); }
.composer-input::placeholder { color: var(--text-3); }
.composer-input:disabled { cursor: not-allowed; }
.composer-send { display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--accent); color: var(--on-accent); cursor: pointer; }
.composer-send:disabled { background: var(--surface-3); color: var(--text-3); cursor: default; }
.composer-actions { grid-column: 1 / -1; display: flex; justify-content: flex-end; gap: var(--space-2); }
.mention-list { position: absolute; left: 0; bottom: calc(100% + 6px); z-index: 50; width: min(320px, 100%); display: grid; gap: 1px; padding: var(--space-1); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-md); animation: pop var(--fast) var(--ease); }
.mention-item { display: flex; align-items: center; gap: var(--space-2); min-width: 0; height: 34px; padding: 0 var(--space-2); border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; cursor: pointer; }
.mention-item.hi, .mention-item:hover { background: var(--surface-2); }
.mention-name { font-weight: var(--weight-medium); white-space: nowrap; }
.mention-email { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-3); font-size: var(--text-xs); }

@media (max-width: 860px) {
  .dialog.record.with-activity { height: auto; display: flex; overflow: auto; }
  .dialog.record.with-activity > .record-body { overflow: visible; }
  .activity { flex: none; border-left: 0; border-top: 1px solid var(--border); }
  .activity-feed { max-height: 420px; }
}

/* Campana de avisos (barra superior) */
.bell { position: relative; display: grid; place-items: center; width: 34px; height: 34px; border: 0; border-radius: 50%; background: transparent; color: var(--text-2); cursor: pointer; }
.bell:hover, .bell[aria-expanded="true"] { background: var(--surface-2); color: var(--text); }
.bell-badge { position: absolute; top: 1px; right: 0; min-width: 17px; height: 17px; padding: 0 4px; border: 2px solid var(--surface); border-radius: var(--radius-pill); background: var(--danger); color: #fff; font-size: 10px; font-weight: var(--weight-strong); line-height: 13px; text-align: center; font-variant-numeric: tabular-nums; }
.bell-pop { width: min(380px, 92vw); padding: 0; }
.bell-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); border-bottom: 1px solid var(--border); }
.bell-list { display: grid; max-height: min(60vh, 460px); overflow: auto; padding: var(--space-1); }
.bell-item { position: relative; display: flex; align-items: flex-start; gap: var(--space-3); width: 100%; padding: var(--space-2) var(--space-6) var(--space-2) var(--space-3); border: 0; border-radius: var(--radius-sm); background: transparent; text-align: left; cursor: pointer; }
.bell-item:hover { background: var(--surface-2); }
.bell-item.unread { background: var(--accent-softer); }
.bell-item.unread:hover { background: var(--accent-soft); }
.bell-text { display: grid; gap: 2px; min-width: 0; font-size: var(--text-sm); color: var(--text-2); }
.bell-text strong { color: var(--text); font-weight: var(--weight-strong); }
.bell-excerpt { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--text-2); }
.bell-dot { position: absolute; top: 50%; right: var(--space-3); width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--accent); }
.bell-empty { padding: var(--space-6) var(--space-4); color: var(--text-3); text-align: center; }

@media (max-width: 720px) {
  .toolbar .tool span { display: none; }
  .record-count { display: none; }
  .home-main { padding: var(--space-5) var(--space-4); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ------------------------------------------------------------------------------------------------ Vistas No-Rejilla */

/* ── Kanban ── */
.kanban {
  position: absolute; inset: 0;
  display: flex; gap: var(--space-4);
  padding: var(--space-4);
  overflow-x: auto; overflow-y: hidden;
  background: var(--bg);
}
.kanban-stack {
  width: 290px; min-width: 290px; max-height: 100%;
  display: flex; flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.kanban-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  height: 42px; padding: 0 var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-size: var(--text-sm); font-weight: var(--weight-strong);
}
.kanban-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kanban-head .count { font-size: var(--text-xs); color: var(--text-3); font-weight: var(--weight-medium); }
.kanban-cards {
  flex: 1; overflow-y: auto; padding: var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-2);
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: border-color var(--fast), box-shadow var(--fast), transform var(--fast);
  user-select: none;
  display: flex; flex-direction: column; gap: 6px;
}
.kanban-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
/* Arrastre de tarjetas (como Airtable): la tarjeta sale de su pila, la copia sigue al puntero y el hueco marca dónde cae */
.kanban.dragging, .kanban.dragging * { cursor: grabbing !important; user-select: none; }
.kanban-card.lifted { display: none; }
.kanban-gap { flex: none; border-radius: var(--radius-sm); background: color-mix(in srgb, var(--text) 6%, transparent); }
.kanban-ghost { position: fixed; z-index: 80; pointer-events: none; }
.kanban-ghost .kanban-card { border-color: var(--border-strong); box-shadow: 0 12px 28px rgb(0 0 0 / 16%), var(--shadow-md); }
.kanban-name { font-weight: var(--weight-strong); font-size: var(--text-sm); color: var(--text); }
.kanban-card-fields { display: flex; flex-wrap: wrap; gap: 4px; }
.kanban-field-chip {
  font-size: var(--text-xs); color: var(--text-2); background: var(--surface-2);
  padding: 2px 6px; border-radius: var(--radius-xs); border: 1px solid var(--border);
}
.kanban-empty-notice {
  margin: auto; max-width: 440px; padding: var(--space-8);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); text-align: center;
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: var(--space-3);
  align-items: center;
}
.kanban-empty-notice h3 { font-size: var(--text-lg); font-weight: var(--weight-strong); }
.kanban-empty-notice p { color: var(--text-2); font-size: var(--text-sm); line-height: 1.5; }

/* ── Calendario ── */
.calendar {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--surface);
  overflow: hidden;
}
.calendar-head {
  height: 48px; padding: 0 var(--space-4);
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.calendar-title { font-size: var(--text-lg); font-weight: var(--weight-strong); color: var(--text); }
.calendar-grid {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: 32px repeat(6, 1fr);
  border-left: 1px solid var(--border); border-top: 1px solid var(--border);
  overflow-y: auto;
}
.cal-weekday {
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xs); font-weight: var(--weight-strong); color: var(--text-3);
  text-transform: uppercase; background: var(--surface-2);
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.cal-cell {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 4px 6px; overflow-y: auto; background: var(--surface);
  min-height: 80px; position: relative;
}
.cal-cell.today { background: color-mix(in srgb, var(--brand-orange) 6%, var(--surface)); }
.cal-day { height: 100%; display: flex; flex-direction: column; }
.cal-day-num {
  font-size: var(--text-xs); font-family: var(--font-mono); font-weight: 500;
  color: var(--text-3); margin-bottom: 2px;
}
.cal-cell.today .cal-day-num { color: var(--brand-orange); font-weight: 700; }
.cal-event {
  width: 100%; margin-top: 3px; padding: 3px 6px;
  border-radius: var(--radius-xs); background: var(--accent-soft); color: var(--accent-text);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  font-size: var(--text-xs); font-weight: var(--weight-medium);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; text-align: left; display: block;
  transition: background var(--fast);
}
.cal-event:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }

/* ── Galería ── */
.gallery {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; gap: var(--space-4);
  padding: var(--space-4); overflow-y: auto; background: var(--bg);
}
.gallery-toolbar { display: flex; align-items: center; justify-content: space-between; }
.gallery-grid {
  display: grid; gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
}
.gallery-grid.small { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.gallery-grid.large { grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); }
.gallery-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); overflow: hidden;
  cursor: pointer; box-shadow: var(--shadow-sm);
  transition: border-color var(--fast), box-shadow var(--fast), transform var(--fast);
  display: flex; flex-direction: column;
}
.gallery-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.gallery-cover {
  height: 140px; background: var(--surface-2);
  display: flex; align-items: center; justify-content: center;
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.gallery-initials { font-size: 36px; font-weight: var(--weight-strong); color: var(--text-3); }
.gallery-text { font-size: var(--text-md); font-weight: var(--weight-medium); color: var(--text-2); padding: var(--space-3); }
.gallery-body { padding: var(--space-3); display: flex; flex-direction: column; gap: 6px; }
.gallery-name { font-weight: var(--weight-strong); font-size: var(--text-md); color: var(--text); }

/* ── Cronograma / Gantt ── */
.timeline {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--surface); overflow: auto;
}
.timeline-header-track {
  position: sticky; top: 0; z-index: 5;
  display: flex; height: 38px;
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
.timeline-day-header {
  flex: none; width: 60px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  border-right: 1px solid var(--border); font-size: 11px; color: var(--text-3);
  font-family: var(--font-mono);
}
.timeline-body { position: relative; min-height: 100%; padding: var(--space-3) 0; }
.timeline-row { position: relative; height: 34px; border-bottom: 1px solid var(--surface-2); }
.timeline-bar {
  position: absolute; top: 4px; height: 26px;
  background: #181d26; color: #ffffff;
  border-radius: var(--radius-xs);
  padding: 0 10px; font-size: var(--text-xs); font-weight: var(--weight-medium);
  display: flex; align-items: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; box-shadow: var(--shadow-sm);
}
.timeline-bar:hover { background: #2f3542; }
.timeline-bar.accent { background: var(--brand-orange); }

/* ── Lista ── */
.list {
  position: absolute; inset: 0;
  overflow-y: auto; background: var(--surface);
  padding: var(--space-2) 0;
}
.list-row {
  display: flex; align-items: center; gap: var(--space-4);
  height: 38px; padding: 0 var(--space-4);
  border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background var(--fast);
}
.list-row:hover { background: var(--surface-2); }
.list-name { min-width: 200px; font-weight: var(--weight-strong); font-size: var(--text-sm); color: var(--text); }
.list-fields { display: flex; align-items: center; gap: var(--space-3); flex: 1; overflow: hidden; }
.list-cell { font-size: var(--text-sm); color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Formulario ── */
.form-view {
  position: absolute; inset: 0;
  overflow-y: auto; padding: var(--space-8) var(--space-4);
  background: var(--bg); display: flex; flex-direction: column; align-items: center; gap: var(--space-4);
}
.form-share-banner {
  width: min(640px, 100%);
  padding: 12px 16px; border-radius: var(--radius-md);
  background: var(--surface); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  font-size: var(--text-sm); box-shadow: var(--shadow-sm);
}
.form-preview {
  width: min(640px, 100%);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-8);
  box-shadow: var(--shadow-md); display: flex; flex-direction: column; gap: var(--space-5);
}
.form-title { font-size: var(--text-2xl); font-weight: var(--weight-strong); color: var(--text); border-bottom: 1px solid var(--border); padding-bottom: var(--space-3); }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field .field-label { font-weight: var(--weight-strong); font-size: var(--text-sm); color: var(--text-2); }
.form-field .input { width: 100%; }

/* Tema oscuro: la barra de pestañas y el menú de la base usan el color de la base mezclado con la superficie */
:root[data-theme="dark"] .base-screen { --bc-tint: color-mix(in srgb, var(--bc-tile) 16%, var(--surface)); --bc-line: color-mix(in srgb, var(--bc-tile) 30%, var(--surface)); --bc-dark: var(--bc-tile); }
:root[data-theme="dark"] .tool.on.t-hide { background: #1f3358; }
:root[data-theme="dark"] .tool.on.t-filter { background: #1c3a22; }
:root[data-theme="dark"] .tool.on.t-group { background: #153b38; }
:root[data-theme="dark"] .tool.on.t-sort { background: #4a2d17; }

@media (max-width: 720px) {
  .view-sidebar { position: absolute; z-index: 30; top: 0; bottom: 0; left: 0; box-shadow: var(--shadow-md); }
  .base-main { position: relative; }
  .top-nav { display: none; }
}

.grid-footer { position: absolute; left: 0; right: 0; bottom: 0; height: 34px; display: flex; align-items: center; padding: 0 var(--space-3); background: var(--surface); border-top: 1px solid var(--border); z-index: 2; }
.grid-footer .record-count { margin: 0; font-size: var(--text-xs); }
/* Barra de resumen bajo la cuadrícula: recuento y resumen de cada columna (las no fijas se desplazan con la rejilla) */
.grid-footer.summary-bar { padding: 0; }
.summary-frozen { flex: none; display: flex; align-items: center; gap: var(--space-2); height: 100%; min-width: 0; padding-left: var(--space-3); border-right: 1px solid var(--border-strong); }
.summary-track { position: relative; flex: 1; height: 100%; overflow: hidden; }
.summary-cell { position: absolute; top: 0; display: flex; align-items: center; justify-content: flex-end; gap: 6px; height: 100%; min-width: 0; padding: 0 var(--space-2); border: 0; background: transparent; color: var(--text); font: inherit; font-size: var(--text-xs); white-space: nowrap; cursor: pointer; transition: background var(--fast); }
.summary-cell.frozen-cell { position: relative; flex: 1; }
.summary-cell:hover:not(:disabled), .summary-cell.open { background: var(--surface-2); }
.summary-cell:disabled { cursor: default; }
.summary-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; color: var(--text-3); }
.summary-value { flex: none; font-variant-numeric: tabular-nums; font-weight: var(--weight-medium); }
.summary-hint { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); opacity: 0; transition: opacity var(--fast); }
.summary-cell:hover:not(:disabled) .summary-hint, .summary-cell.open .summary-hint { opacity: 1; }
.summary-menu { min-width: 200px; max-height: min(70vh, 560px); overflow: auto; }
.summary-menu .menu-item.on { color: var(--accent-text); font-weight: var(--weight-medium); }
.summary-menu .menu-item.on .icon { color: var(--accent-text); }
.spacer { flex: 1; }

/* Formulario público (/shr…) y enlace para compartirlo */
.share-pop { min-width: 380px; display: grid; gap: var(--space-3); padding: var(--space-4); }
.share-title { margin: 0; font-weight: var(--weight-medium); }
.share-url { font-family: var(--font-mono); font-size: var(--text-sm); }
.share-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.public-form { min-height: 100%; display: flex; flex-direction: column; align-items: center; gap: var(--space-6); padding: var(--space-8) var(--space-4); background: var(--bg); }
.pf-card { width: min(640px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); overflow: hidden; }
.pf-cover { height: 10px; }
.pf-form, .pf-done { display: grid; gap: var(--space-5); padding: var(--space-8); }
.pf-form h1, .pf-done h1, .pf-card > h1 { margin: 0; font-size: var(--text-2xl); letter-spacing: -0.02em; }
.pf-card > h1, .pf-card > p { padding: var(--space-8) var(--space-8) 0; }
.pf-card > p:last-child { padding-bottom: var(--space-8); }
.pf-desc { margin: 0; color: var(--text-2); white-space: pre-wrap; }
.pf-field { display: grid; gap: var(--space-2); }
.pf-label { font-weight: var(--weight-strong); }
.pf-req { color: var(--danger); }
.pf-help { margin: 0; color: var(--text-3); font-size: var(--text-sm); }
.pf-options { display: grid; gap: var(--space-2); }
.pf-check-row { display: flex; align-items: center; gap: var(--space-2); }
.pf-trap { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.pf-done { justify-items: center; text-align: center; }
.pf-check { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 50%; background: var(--success-soft); color: var(--success); }
.pf-foot { display: flex; align-items: center; gap: var(--space-2); color: var(--text-3); font-size: var(--text-sm); }
.pf-foot .logo { width: 18px; height: 18px; }
.spinner-line { display: flex; align-items: center; gap: var(--space-2); color: var(--text-3); }

/* Color de los registros (vista → Color) */
.grid-row.tinted .cell, .grid-row.tinted > .frozen, .grid-row.tinted .gutter { background-color: var(--row-tint); }
.grid-row.tinted:hover .cell, .grid-row.tinted:hover > .frozen { filter: brightness(0.97); }
.kanban-card.tinted, .gallery-card.tinted, .list-row.tinted, .cal-event.tinted { background: var(--row-tint); }
.tool.on.t-color { background: rgb(250, 210, 252); }
.panel-title { margin: 0 0 var(--space-2); font-weight: var(--weight-strong); }
.panel-hint { margin: var(--space-2) 0 0; font-size: var(--text-sm); }
.radio-row { display: flex; align-items: center; gap: var(--space-2); padding: 6px var(--space-2); border-radius: var(--radius-sm); cursor: pointer; }
.radio-row:hover { background: var(--surface-2); }

/* Marcas de cambios ajenos: marco del color del autor (--mark) y etiqueta con su nombre, ~4 s y fundido de
   0,6 s (la tienda las quita a los 4,65 s). Con «reducir movimiento» no hay animaciones: aparece y desaparece. */
.edit-mark {
  position: absolute; inset: 0; z-index: 1;
  border-radius: 2px;
  box-shadow: inset 0 0 0 2px var(--mark);
  pointer-events: none;
  animation: mark-in 150ms ease-out both, mark-out 600ms ease-in 4000ms forwards;
}
.mark-tag {
  position: absolute; top: -8px; right: 4px; z-index: 1;
  display: inline-flex; align-items: center; gap: 3px;
  height: 16px; max-width: 160px; padding: 0 6px;
  border-radius: 999px;
  background: var(--mark); color: #fff;
  font-size: 10.5px; font-weight: 600; line-height: 16px; letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
  pointer-events: auto; cursor: default;
  transform-origin: 100% 100%;
  animation: tag-pop 180ms cubic-bezier(0.2, 0.9, 0.3, 1.35) both;
}
/* El nombre va en data-label: no se mezcla con el texto de la celda. */
.mark-tag::after { content: attr(data-label); display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.mark-tag .icon { flex: none; }
@keyframes mark-in { from { opacity: 0; } }
@keyframes mark-out { to { opacity: 0; } }
@keyframes tag-pop { from { opacity: 0; transform: translateY(3px) scale(0.6); } }

/* Agentes: halo suave y un único barrido de luz. */
.edit-mark.agent {
  box-shadow: inset 0 0 0 2px var(--mark), 0 0 10px 1px color-mix(in srgb, var(--mark) 40%, transparent);
}
.edit-mark.agent::before {
  content: ""; position: absolute; inset: 2px; border-radius: inherit;
  background: linear-gradient(100deg, transparent 35%, color-mix(in srgb, var(--mark) 22%, transparent) 50%, transparent 65%) 0 0 / 250% 100% no-repeat;
  animation: mark-sweep 900ms ease-out 150ms both;
}
@keyframes mark-sweep { from { background-position: 100% 0; } to { background-position: 0 0; } }

/* Rejilla: la celda marcada sube para que la etiqueta pise la fila de arriba (en la primera fila, la de abajo). */
.cell.marked { z-index: 1; }
.grid-row > .frozen:has(.edit-mark) { z-index: 3; }
.grid-row.first-row .edit-mark > .mark-tag { top: auto; bottom: -8px; transform-origin: 100% 0; }
/* Registro creado por otro: marco de toda la fila; la etiqueta, en la parte fija. */
.row-span { position: absolute; top: 0; left: 0; height: 100%; z-index: 1; pointer-events: none; }
.edit-mark.mark-row, .edit-mark.mark-row-head { border-radius: 0; }
.edit-mark.mark-row-head { box-shadow: inset 2px 2px 0 var(--mark), inset 0 -2px 0 var(--mark); }

/* Tarjetas de las otras vistas: anillo del registro; la etiqueta dentro si la tarjeta recorta lo que sobresale. */
.kanban-card, .gallery-card, .list-row, .cal-event { position: relative; }
.edit-mark.mark-card { border-radius: inherit; }
.kanban-card .edit-mark > .mark-tag, .list-row .edit-mark > .mark-tag { right: 8px; }
.gallery-card .edit-mark > .mark-tag, .timeline-bar .edit-mark > .mark-tag { top: 5px; right: 5px; }
.cal-event .edit-mark > .mark-tag { top: 50%; right: 2px; margin-top: -8px; }

/* Editor del formulario */
.form-editor-pop { width: 420px; max-height: min(78vh, 640px); }
.form-editor { display: grid; gap: var(--space-3); }
.fe-row { display: grid; gap: 4px; }
.fe-label, .fe-section { font-size: var(--text-xs); font-weight: var(--weight-strong); text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); }
.fe-section { margin-top: var(--space-2); }
.fe-fields { display: grid; gap: 2px; }
.fe-field { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 2px var(--space-2); border-radius: var(--radius-sm); }
.fe-field:hover { background: var(--surface-2); }
.fe-check { display: flex; align-items: center; gap: var(--space-2); cursor: pointer; min-width: 0; }
.fe-req { color: var(--text-2); font-size: var(--text-sm); white-space: nowrap; }
.fe-req.dim { opacity: 0.45; }
.fe-cover { grid-template-columns: repeat(11, 24px); }
.fe-cover .swatch { width: 24px; height: 24px; }
.swatch-none { background: var(--surface-2); color: var(--text-3); }

.show-more { display: block; margin: var(--space-4) auto; }

/* ------------------------------------------------------------------------------------------------ Marketplace */

.ws-marketplace { margin-left: auto; }
.mk-back { display: inline-flex; align-items: center; gap: var(--space-1); margin-bottom: var(--space-3); color: var(--text-3); font-size: var(--text-sm); }
.mk-back:hover { color: var(--text); text-decoration: none; }
.marketplace .home-head { margin-bottom: var(--space-4); }
.marketplace .home-head .muted { margin: var(--space-1) 0 0; }
.mk-tabs { display: flex; gap: var(--space-5); margin-bottom: var(--space-5); border-bottom: 1px solid var(--border); }
.mk-tab { position: relative; height: 38px; padding: 0; border: 0; background: transparent; color: var(--text-3); font: inherit; font-weight: var(--weight-medium); cursor: pointer; }
.mk-tab:hover { color: var(--text); }
.mk-tab[aria-selected="true"] { color: var(--text); }
.mk-tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 2px; border-radius: 2px; background: var(--brand-orange); }
.mk-tab:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-xs); }
.mk-lead { margin: 0 0 var(--space-5); color: var(--text-2); }
.mk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: var(--space-3); align-items: start; }
.mk-card { display: grid; gap: var(--space-3); padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface); box-shadow: var(--shadow-sm); transition: border-color var(--fast), box-shadow var(--fast); }
.mk-card:hover { border-color: var(--border-strong); }
.mk-card-head { display: flex; align-items: center; gap: var(--space-3); }
.mk-tile { border-radius: var(--radius-sm); }
.mk-card-title { flex: 1; min-width: 0; display: grid; }
.mk-card-title h3 { font-size: var(--text-md); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mk-card-title .muted { font-size: var(--text-sm); }
.mk-status { gap: 4px; white-space: nowrap; }
.mk-status.ok { background: var(--success-soft); color: var(--success); }
.mk-desc { margin: 0; color: var(--text-2); font-size: var(--text-sm); line-height: 1.5; }
.mk-meta { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2) var(--space-3); font-size: var(--text-sm); }
.mk-cat { display: inline-flex; align-items: center; height: 22px; padding: 0 var(--space-2); border-radius: var(--radius-xs); background: var(--surface-3); color: var(--text-2); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.mk-link { display: inline-flex; align-items: center; gap: 4px; font-size: var(--text-sm); }
.mk-view { margin-left: auto; }
.mk-actions { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.btn.mk-danger { color: var(--danger); }
.btn.mk-danger:hover { background: var(--danger-soft); color: var(--danger); }
.mk-warn { margin: 0; padding: var(--space-2) var(--space-3); border-radius: var(--radius-xs); background: var(--warning-soft); color: var(--warning); font-size: var(--text-sm); }
.mk-agent { display: flex; align-items: center; gap: var(--space-2); margin: 0; padding-top: var(--space-3); border-top: 1px solid var(--border); }
.mk-agent .icon { color: var(--brand-orange); }
.mk-mcp, .mk-install { display: grid; gap: 6px; }
.mk-copy { display: flex; align-items: center; gap: var(--space-2); min-width: 0; padding: 3px 3px 3px var(--space-3); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.mk-copy code { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); font-size: var(--text-xs); color: var(--text); }
.mk-copy .btn { flex: none; }

.mk-conn { display: grid; gap: var(--space-3); padding: var(--space-3); border-radius: var(--radius-sm); background: var(--surface-2); }
.mk-conn-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); min-width: 0; }
.mk-state { display: inline-flex; align-items: center; gap: 6px; font-size: var(--text-sm); font-weight: var(--weight-medium); white-space: nowrap; }
.mk-state.ok { color: var(--success); }
.mk-state.busy { color: var(--text-2); }
.mk-state.error { color: var(--danger); }
.mk-account { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: var(--text-sm); }
.mk-conn .error-line { margin: 0; }
.mk-counts { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: var(--space-1) var(--space-3); margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); }
.mk-counts:empty { display: none; }
.mk-counts li { display: flex; justify-content: space-between; gap: var(--space-2); color: var(--text-2); }
.mk-counts strong { color: var(--text); font-variant-numeric: tabular-nums; }
.spinner.small { width: 14px; height: 14px; }

.dialog.mk-connect .callout { align-items: flex-start; }
.dialog.mk-connect .callout p { margin: var(--space-1) 0 var(--space-2); font-size: var(--text-sm); }
.mk-tables { display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; list-style: none; }
.mk-tables li { padding: 2px var(--space-2); border-radius: var(--radius-xs); background: var(--surface); color: var(--text); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.dialog.mk-connect .hint { margin: 0; font-weight: var(--weight-regular); line-height: 1.5; }

.mk-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.mk-search { position: relative; display: flex; align-items: center; width: min(360px, 100%); color: var(--text-3); }
.mk-search .icon { position: absolute; left: var(--space-3); pointer-events: none; }
.mk-search .input { padding-left: 32px; }

/* Detalle de una skill: el diálogo se pega al borde derecho como panel lateral. */
.dialog.mk-drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(760px, 100%); max-height: none; border-radius: var(--radius-lg) 0 0 var(--radius-lg); animation: drawer-in var(--fast) var(--ease); }
@keyframes drawer-in { from { transform: translateX(24px); opacity: 0; } }
.mk-drawer-body { display: grid; gap: var(--space-4); align-content: start; flex: 1; }
.mk-drawer-body .mk-desc { font-size: var(--text-md); }
.mk-md { margin: 0; padding: var(--space-4); border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); font-family: var(--font-mono); font-size: var(--text-xs); line-height: 1.6; white-space: pre-wrap; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) { .dialog.mk-drawer { animation: none; } }

/* ------------------------------------------------------------------------------------------------ Historial de versiones */

.dialog.versions { width: min(640px, 100%); }
.versions-body { display: grid; gap: var(--space-4); align-content: start; }
.versions-intro { margin: 0; color: var(--text-2); font-size: var(--text-md); line-height: 1.5; }
.versions-save { display: flex; }
.versions-error, .versions-note, .versions-empty { margin: 0; }
.versions-error { align-items: center; font-size: var(--text-sm); }
.versions-note { font-size: var(--text-sm); }
.versions-empty { padding: var(--space-4) 0; text-align: center; }
.versions-upsell { align-items: flex-start; background: var(--accent-softer); }
.versions-upsell > .icon { flex: none; margin-top: 2px; color: var(--accent-text); }
.versions-upsell p { margin: var(--space-2) 0 var(--space-3); font-size: var(--text-sm); line-height: 1.55; }
.versions-upsell p.muted { margin-bottom: 0; color: var(--text-3); }
.versions-safe { margin: var(--space-3) 0 0; font-size: var(--text-sm); line-height: 1.5; }
.versions-list { display: grid; margin: 0; padding: 0; list-style: none; border: 1px solid var(--border); border-radius: var(--radius-md); }
.version-row { display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) var(--space-4); }
.version-row + .version-row { border-top: 1px solid var(--border); }
.version-icon { display: grid; place-items: center; flex: none; width: 28px; height: 28px; border-radius: var(--radius-pill); background: var(--accent-soft); color: var(--accent-text); }
.version-icon.auto { background: var(--surface-3); color: var(--text-3); }
.version-main { display: grid; gap: 4px; flex: 1; min-width: 0; }
.version-main strong { font-size: var(--text-md); font-weight: var(--weight-medium); }
.version-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px var(--space-2); color: var(--text-3); font-size: var(--text-xs); }
.version-meta > span:not(.badge) + span::before { content: "·"; margin-right: var(--space-2); }
.version-actions { display: flex; flex-direction: column; align-items: stretch; gap: 4px; flex: none; }
.version-actions .btn { justify-content: flex-start; gap: 6px; }
@media (max-width: 560px) {
  .version-row { flex-wrap: wrap; }
  .version-actions { flex-direction: row; width: 100%; }
}
