/* =====================================================================
   Administración de Fincas · Sistema visual
   Tokens → base → layout → componentes → módulos → utilidades
   ===================================================================== */

:root {
  /* Marca */
  --brand: #0F766E;
  --brand-600: #0D6B64;
  --brand-700: #115E59;
  --brand-50: #F0FDFA;
  --brand-100: #CCFBF1;
  --on-brand: #FFFFFF;

  /* Superficies */
  --bg: #F4F6F8;
  --surface: #FFFFFF;
  --surface-2: #F8FAFC;
  --surface-3: #EEF2F6;
  --border: #E2E8F0;
  --border-strong: #CBD5E1;

  /* Texto */
  --text: #0F172A;
  --text-2: #334155;
  --muted: #64748B;

  /* Estados */
  --ok: #15803D;    --ok-bg: #DCFCE7;
  --warn: #B45309;  --warn-bg: #FEF3C7;
  --danger: #B91C1C; --danger-bg: #FEE2E2;
  --info: #1D4ED8;  --info-bg: #DBEAFE;

  /* Badges de estado */
  --c-amber: #B45309;  --c-amber-bg: #FEF3C7;
  --c-red: #B91C1C;    --c-red-bg: #FEE2E2;
  --c-blue: #1D4ED8;   --c-blue-bg: #DBEAFE;
  --c-indigo: #4338CA; --c-indigo-bg: #E0E7FF;
  --c-violet: #6D28D9; --c-violet-bg: #EDE9FE;
  --c-cyan: #0E7490;   --c-cyan-bg: #CFFAFE;
  --c-orange: #C2410C; --c-orange-bg: #FFEDD5;
  --c-green: #15803D;  --c-green-bg: #DCFCE7;
  --c-gray: #475569;   --c-gray-bg: #E2E8F0;

  /* Forma */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 12px rgba(15, 23, 42, .05);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .16);

  /* Tipografía */
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, monospace;

  /* Espaciado */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px; --s10: 40px;

  --sidebar-w: 264px;
  --topbar-h: 60px;
  --bottom-h: 64px;
  --safe-b: max(env(safe-area-inset-bottom, 0px), 8px);
  --safe-t: env(safe-area-inset-top, 0px);

  --ease: cubic-bezier(.2, .8, .2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand: #2DD4BF; --brand-600: #14B8A6; --brand-700: #5EEAD4; --brand-50: #0B2A28; --brand-100: #0F3B37; --on-brand: #04201D;
    --bg: #0B1220; --surface: #111A2B; --surface-2: #0F1726; --surface-3: #18233A;
    --border: #22304A; --border-strong: #2E3E5C;
    --text: #E6EDF7; --text-2: #C3CEDF; --muted: #8C9AB3;
    --ok: #4ADE80; --ok-bg: #0F2E1D; --warn: #FBBF24; --warn-bg: #33250A; --danger: #F87171; --danger-bg: #3A1414; --info: #93C5FD; --info-bg: #142544;
    --c-amber: #FBBF24; --c-amber-bg: #33250A; --c-red: #F87171; --c-red-bg: #3A1414; --c-blue: #93C5FD; --c-blue-bg: #142544;
    --c-indigo: #A5B4FC; --c-indigo-bg: #1E1F4B; --c-violet: #C4B5FD; --c-violet-bg: #2A1D4D; --c-cyan: #67E8F9; --c-cyan-bg: #0B3040;
    --c-orange: #FDBA74; --c-orange-bg: #3A1F0E; --c-green: #4ADE80; --c-green-bg: #0F2E1D; --c-gray: #CBD5E1; --c-gray-bg: #22304A;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.3); --shadow-lg: 0 12px 34px rgba(0,0,0,.55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand: #2DD4BF; --brand-600: #14B8A6; --brand-700: #5EEAD4; --brand-50: #0B2A28; --brand-100: #0F3B37; --on-brand: #04201D;
  --bg: #0B1220; --surface: #111A2B; --surface-2: #0F1726; --surface-3: #18233A;
  --border: #22304A; --border-strong: #2E3E5C;
  --text: #E6EDF7; --text-2: #C3CEDF; --muted: #8C9AB3;
  --ok: #4ADE80; --ok-bg: #0F2E1D; --warn: #FBBF24; --warn-bg: #33250A; --danger: #F87171; --danger-bg: #3A1414; --info: #93C5FD; --info-bg: #142544;
  --c-amber: #FBBF24; --c-amber-bg: #33250A; --c-red: #F87171; --c-red-bg: #3A1414; --c-blue: #93C5FD; --c-blue-bg: #142544;
  --c-indigo: #A5B4FC; --c-indigo-bg: #1E1F4B; --c-violet: #C4B5FD; --c-violet-bg: #2A1D4D; --c-cyan: #67E8F9; --c-cyan-bg: #0B3040;
  --c-orange: #FDBA74; --c-orange-bg: #3A1F0E; --c-green: #4ADE80; --c-green-bg: #0F2E1D; --c-gray: #CBD5E1; --c-gray-bg: #22304A;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4); --shadow: 0 1px 3px rgba(0,0,0,.4), 0 6px 16px rgba(0,0,0,.3); --shadow-lg: 0 12px 34px rgba(0,0,0,.55);
  color-scheme: dark;
}

/* App instalada (PWA): margen inferior extra para la barra de gestos del sistema */
@media (display-mode: standalone), (display-mode: fullscreen), (display-mode: minimal-ui) {
  :root { --safe-b: max(calc(env(safe-area-inset-bottom, 0px) + 8px), 28px); }
}
:root.is-standalone { --safe-b: max(calc(env(safe-area-inset-bottom, 0px) + 8px), 28px); }

/* ---------------------------------------------------------------- Base */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 16px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
img, svg { display: block; max-width: 100%; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); letter-spacing: -0.01em; }
h1 { font-size: clamp(1.35rem, 1.1rem + 1vw, 1.75rem); font-weight: 700; }
h2 { font-size: 1.125rem; font-weight: 650; }
h3 { font-size: 1rem; font-weight: 650; }
p { margin: 0; }
small { font-size: .8125rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: var(--s4) 0; }
code, .mono { font-family: var(--font-mono); font-size: .875em; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; border-radius: 6px; }
.icon { width: 20px; height: 20px; flex: none; }
.icon-sm { width: 16px; height: 16px; flex: none; }
.icon-lg { width: 28px; height: 28px; flex: none; }
[hidden] { display: none !important; }
.skip-link { position: absolute; left: -9999px; top: 8px; z-index: 100; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
.skip-link:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* ---------------------------------------------------------------- Layout */
.app-shell { min-height: 100dvh; display: flex; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: calc(var(--s4) + var(--safe-t)) var(--s3) var(--s4);
  transform: translateX(-100%); transition: transform .28s var(--ease);
  overflow-y: auto; overscroll-behavior: contain;
}
.sidebar.is-open { transform: none; box-shadow: var(--shadow-lg); }
.sidebar-scrim { position: fixed; inset: 0; background: rgba(2, 6, 23, .45); z-index: 35; }
.brand { display: flex; align-items: center; gap: var(--s3); padding: var(--s2); margin-bottom: var(--s4); color: var(--text); }
.brand:hover { text-decoration: none; }
.brand img { border-radius: 10px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brand-text small { color: var(--muted); font-size: .75rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: var(--s5) var(--s3) var(--s2); }
.nav-link {
  display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s3);
  border-radius: var(--radius-sm); color: var(--text-2); font-weight: 550; font-size: .9375rem;
  transition: background-color .15s, color .15s;
}
.nav-link:hover { background: var(--surface-3); text-decoration: none; color: var(--text); }
.nav-link.is-active { background: var(--brand-50); color: var(--brand); }
.nav-link.is-active .icon { color: var(--brand); }
.nav-link .icon { color: var(--muted); }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; display: inline-grid; place-items: center; }
.sidebar-foot { margin-top: auto; padding-top: var(--s4); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
/* Variantes del menú lateral (Sistema → Apariencia) */
:root[data-sidebar="brand"] .sidebar { --sb-fg: var(--on-brand); background: var(--brand); border-right-color: transparent; }
:root[data-sidebar="dark"] .sidebar { --sb-fg: #E2E8F0; background: #0F172A; border-right-color: #1E293B; }
:root[data-sidebar="brand"] .sidebar .brand, :root[data-sidebar="dark"] .sidebar .brand { color: var(--sb-fg); }
:root[data-sidebar="brand"] .sidebar .brand-text small, :root[data-sidebar="dark"] .sidebar .brand-text small,
:root[data-sidebar="brand"] .sidebar .nav-title, :root[data-sidebar="dark"] .sidebar .nav-title { color: color-mix(in srgb, var(--sb-fg) 65%, transparent); }
:root[data-sidebar="brand"] .sidebar .nav-link, :root[data-sidebar="dark"] .sidebar .nav-link { color: color-mix(in srgb, var(--sb-fg) 85%, transparent); }
:root[data-sidebar="brand"] .sidebar .nav-link .icon, :root[data-sidebar="dark"] .sidebar .nav-link .icon { color: color-mix(in srgb, var(--sb-fg) 70%, transparent); }
:root[data-sidebar="brand"] .sidebar .nav-link:hover, :root[data-sidebar="dark"] .sidebar .nav-link:hover { background: color-mix(in srgb, var(--sb-fg) 10%, transparent); color: var(--sb-fg); }
:root[data-sidebar="brand"] .sidebar .nav-link.is-active, :root[data-sidebar="dark"] .sidebar .nav-link.is-active,
:root[data-sidebar="brand"] .sidebar .nav-link.is-active .icon, :root[data-sidebar="dark"] .sidebar .nav-link.is-active .icon { color: var(--sb-fg); }
:root[data-sidebar="brand"] .sidebar .nav-link.is-active { background: color-mix(in srgb, var(--sb-fg) 18%, transparent); }
:root[data-sidebar="dark"] .sidebar .nav-link.is-active { background: color-mix(in srgb, var(--brand) 30%, transparent); }
:root[data-sidebar="brand"] .sidebar .install-btn, :root[data-sidebar="dark"] .sidebar .install-btn { color: var(--sb-fg); }

/* Muestras de color (Sistema → Apariencia) */
.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 10px; max-width: 520px; }
.swatch { position: relative; }
.swatch input { position: absolute; opacity: 0; inset: 0; }
.swatch span { display: block; aspect-ratio: 1; border-radius: 12px; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.08); cursor: pointer; transition: transform .12s; }
.swatch span:hover { transform: scale(1.06); }
.swatch input:checked + span { border-color: var(--text); box-shadow: 0 0 0 3px var(--surface) inset; }
.swatch input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); outline-offset: 2px; }
.color-field { display: flex; align-items: center; gap: 10px; }
.field .color-field input[type="color"] { flex: none; width: 52px !important; min-height: 44px; height: 44px; padding: 2px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); cursor: pointer; }
.field .color-field .input { flex: 0 1 140px; max-width: 140px; font-family: var(--font-mono); text-transform: uppercase; }
.theme-preview { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; display: grid; grid-template-columns: 96px minmax(0, 1fr); min-height: 220px; background: var(--bg); }
.theme-preview .pv-side { padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; background: var(--surface); border-right: 1px solid var(--border); }
.theme-preview .pv-side i { display: block; height: 26px; border-radius: 7px; background: var(--surface-3); }
.theme-preview .pv-side i.on { background: var(--brand-50); box-shadow: inset 3px 0 0 var(--brand); }
.theme-preview[data-sb="brand"] .pv-side { background: var(--brand); border-color: transparent; }
.theme-preview[data-sb="brand"] .pv-side i { background: color-mix(in srgb, var(--on-brand) 14%, transparent); }
.theme-preview[data-sb="brand"] .pv-side i.on { background: color-mix(in srgb, var(--on-brand) 30%, transparent); box-shadow: none; }
.theme-preview[data-sb="dark"] .pv-side { background: #0F172A; border-color: #1E293B; }
.theme-preview[data-sb="dark"] .pv-side i { background: #1E293B; }
.theme-preview[data-sb="dark"] .pv-side i.on { background: color-mix(in srgb, var(--brand) 35%, transparent); box-shadow: none; }
.theme-preview .pv-main { padding: 16px; display: flex; flex-direction: column; gap: 12px; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: calc(var(--topbar-h) + var(--safe-t)); padding: var(--safe-t) var(--s4) 0;
  display: flex; align-items: center; gap: var(--s3);
  background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-title { font-weight: 650; font-size: 1rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: var(--s1); }
.content { flex: 1; width: 100%; max-width: 1440px; margin: 0 auto; padding: var(--s4) var(--s4) calc(var(--bottom-h) + var(--safe-b) + var(--s6)); outline: none; }

.bottom-nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  height: calc(var(--bottom-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
}
.bottom-nav a, .bottom-nav button {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  height: 100%; color: var(--muted); font: inherit; font-size: .6875rem; font-weight: 600; background: none; border: 0; cursor: pointer;
}
.bottom-nav a:hover { text-decoration: none; }
.bottom-nav .is-active { color: var(--brand); }
.bottom-nav .nav-badge { position: absolute; top: 6px; left: calc(50% + 6px); margin: 0; }
.bottom-nav .bottom-cta { justify-self: center; width: 52px !important; height: 52px !important; border-radius: 16px; background: var(--brand); color: var(--on-brand) !important; box-shadow: 0 6px 16px color-mix(in srgb, var(--brand) 40%, transparent); }
.bottom-nav .bottom-cta .icon { width: 26px; height: 26px; }

@media (min-width: 1024px) {
  .sidebar { transform: none; }
  .sidebar-scrim { display: none !important; }
  .main { margin-left: var(--sidebar-w); }
  .topbar .topbar-menu, .bottom-nav { display: none; }
  .content { padding: var(--s6) var(--s8) var(--s10); }
}

/* ---------------------------------------------------------------- Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: 0 var(--s4); border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 600; font-size: .9375rem; line-height: 1; cursor: pointer; white-space: nowrap;
  transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .1s;
  user-select: none; -webkit-user-select: none; text-decoration: none !important;
}
.btn:active { transform: scale(.98); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn-primary { background: var(--brand); color: var(--on-brand); }
.btn-primary:hover { background: var(--brand-600); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-3); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-success { background: var(--ok); color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-sm { min-height: 36px; padding: 0 var(--s3); font-size: .875rem; }
.btn-lg { min-height: 52px; padding: 0 var(--s6); font-size: 1rem; }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent;
  color: var(--text-2); cursor: pointer; position: relative; transition: background-color .15s;
}
.btn-icon:hover { background: var(--surface-3); }
.dot-badge { position: absolute; top: 8px; right: 8px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px; background: var(--danger); color: #fff; font-size: .65rem; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg); }
.is-loading::after { content: ""; width: 16px; height: 16px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.theme-light { display: none; }
:root[data-theme="dark"] .theme-dark { display: none; }
:root[data-theme="dark"] .theme-light { display: block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-dark { display: none; }
  :root:not([data-theme="light"]) .theme-light { display: block; }
}

/* ---------------------------------------------------------------- Menú usuario */
.menu { position: relative; }
.menu > summary { list-style: none; cursor: pointer; }
.menu > summary::-webkit-details-marker { display: none; }
.avatar-btn { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; }
.menu-panel {
  position: absolute; right: 0; top: calc(100% + 6px); width: 260px; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: var(--s2); display: flex; flex-direction: column;
}
.menu-head { padding: var(--s2) var(--s3) var(--s3); border-bottom: 1px solid var(--border); margin-bottom: var(--s2); display: flex; flex-direction: column; }
.menu-head small { color: var(--muted); }
.menu-panel a, .menu-panel button {
  display: flex; align-items: center; gap: var(--s3); min-height: 44px; padding: 0 var(--s3); border-radius: var(--radius-sm);
  color: var(--text); font: inherit; font-size: .9375rem; background: none; border: 0; width: 100%; text-align: left; cursor: pointer;
}
.menu-panel a:hover, .menu-panel button:hover { background: var(--surface-3); text-decoration: none; }
.menu-panel form { margin: 0; }

/* ---------------------------------------------------------------- Avatar */
.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none; overflow: hidden;
  display: grid; place-items: center; background: var(--brand-100); color: var(--brand-700);
  font-weight: 700; font-size: .8125rem; letter-spacing: .02em;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-lg { width: 64px; height: 64px; font-size: 1.25rem; }
.avatar-sm { width: 28px; height: 28px; font-size: .7rem; }

/* ---------------------------------------------------------------- Cabecera de página */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s5); }
.page-head p { color: var(--muted); margin-top: var(--s1); }
.page-head .actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.back-link { display: inline-flex; align-items: center; gap: var(--s1); color: var(--muted); font-size: .875rem; font-weight: 550; margin-bottom: var(--s2); }

/* ---------------------------------------------------------------- Tarjetas */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s4) 0; }
.card-head h2 { display: flex; align-items: center; gap: var(--s2); }
.card-body { padding: var(--s4); }
.card + .card { margin-top: var(--s4); }
.card-foot { padding: var(--s3) var(--s4); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; }
.card-accent { border-left: 4px solid var(--brand); }

.grid { display: grid; gap: var(--s4); }
.grid-2, .grid-3, .grid-4 { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
.grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--s3); }
/* Dentro de una cuadrícula el espacio lo pone el gap, no el margen entre tarjetas */
.grid > .card, .grid-2 > .card, .grid-3 > .card, .grid-4 > .card, .stack > .card { margin-top: 0; }
.grid-4 > .stat { height: 100%; }
@media (max-width: 639px) {
  .grid-4 .stat { gap: var(--s3); padding: var(--s3); min-height: 76px; }
  .grid-4 .stat-icon { width: 40px; height: 40px; border-radius: 12px; }
  .grid-4 .stat-icon .icon { width: 20px; height: 20px; }
  .grid-4 .stat > div { min-width: 0; }
  .grid-4 .stat-value { font-size: 1.375rem; }
  .grid-4 .stat-label { font-size: .75rem; line-height: 1.25; }
}
@media (min-width: 640px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-4 { grid-template-columns: repeat(2, 1fr); } .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-3 { grid-template-columns: repeat(3, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } }
.layout-aside { display: grid; gap: var(--s4); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 1100px) { .layout-aside { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; } }
.stack { display: flex; flex-direction: column; gap: var(--s4); }
.stack-sm { display: flex; flex-direction: column; gap: var(--s2); }
.row { display: flex; align-items: center; gap: var(--s2); flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); flex-wrap: wrap; }
.mt-2 { margin-top: var(--s2); } .mt-4 { margin-top: var(--s4); } .mt-6 { margin-top: var(--s6); } .mb-4 { margin-bottom: var(--s4); }
.muted { color: var(--muted); }
.text-sm { font-size: .875rem; }
.text-xs { font-size: .75rem; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.w-full { width: 100%; }

/* ---------------------------------------------------------------- KPIs */
.stat { display: flex; align-items: center; gap: var(--s4); padding: var(--s4); }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex: none; background: var(--brand-50); color: var(--brand); }
.stat-icon.is-amber { background: var(--c-amber-bg); color: var(--c-amber); }
.stat-icon.is-orange { background: var(--c-orange-bg); color: var(--c-orange); }
.stat-icon.is-green { background: var(--c-green-bg); color: var(--c-green); }
.stat-icon.is-blue { background: var(--c-blue-bg); color: var(--c-blue); }
.stat-icon.is-violet { background: var(--c-violet-bg); color: var(--c-violet); }
.stat-value { font-size: 1.75rem; font-weight: 750; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .8125rem; font-weight: 550; }
a.stat:hover { text-decoration: none; background: var(--surface-2); }

.bars { display: flex; flex-direction: column; gap: var(--s3); }
.bar-row { display: grid; grid-template-columns: minmax(90px, 160px) 1fr 40px; gap: var(--s3); align-items: center; font-size: .875rem; }
.bar-track { height: 10px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--brand); border-radius: 999px; }
.bar-row .num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
.spark { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: var(--s2); }
.spark-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.spark-bar { width: 100%; max-width: 34px; background: var(--brand); border-radius: 6px 6px 2px 2px; min-height: 3px; }
.spark-col small { color: var(--muted); font-size: .7rem; }
.spark-col b { font-size: .7rem; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- Badges */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: .75rem; font-weight: 650; white-space: nowrap; background: var(--c-gray-bg); color: var(--c-gray);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.no-dot::before { display: none; }
.badge-amber { background: var(--c-amber-bg); color: var(--c-amber); }
.badge-red { background: var(--c-red-bg); color: var(--c-red); }
.badge-blue { background: var(--c-blue-bg); color: var(--c-blue); }
.badge-indigo { background: var(--c-indigo-bg); color: var(--c-indigo); }
.badge-violet { background: var(--c-violet-bg); color: var(--c-violet); }
.badge-cyan { background: var(--c-cyan-bg); color: var(--c-cyan); }
.badge-orange { background: var(--c-orange-bg); color: var(--c-orange); }
.badge-green { background: var(--c-green-bg); color: var(--c-green); }
.badge-gray { background: var(--c-gray-bg); color: var(--c-gray); }
.prio-urgente { color: var(--c-red); font-weight: 700; }
.prio-alta { color: var(--c-orange); font-weight: 650; }
.prio-media { color: var(--text-2); }
.prio-baja { color: var(--muted); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: .8125rem; font-weight: 550; }
.cat-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

/* ---------------------------------------------------------------- Alertas */
.flashes:empty { display: none; }
.flashes { display: flex; flex-direction: column; gap: var(--s2); margin-bottom: var(--s4); }
.alert { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius-sm); border: 1px solid transparent; font-size: .9375rem; }
.alert > span { flex: 1; padding-top: 1px; }
.alert-success { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-error { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-warning { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-close { background: none; border: 0; color: inherit; cursor: pointer; padding: 2px; border-radius: 6px; opacity: .7; }
.alert-close:hover { opacity: 1; }

/* ---------------------------------------------------------------- Formularios */
.form-grid { display: grid; gap: var(--s4); grid-template-columns: 1fr; }
@media (min-width: 720px) { .form-grid { grid-template-columns: repeat(2, 1fr); } .form-grid .span-2 { grid-column: span 2; } }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-weight: 600; font-size: .875rem; color: var(--text-2); }
.field .req { color: var(--danger); }
.hint { color: var(--muted); font-size: .8125rem; }
.field-error { color: var(--danger); font-size: .8125rem; font-weight: 550; display: flex; gap: 4px; align-items: center; }
.input, .select, .textarea,
.field input:not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="hidden"]), .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 16px; /* evita el zoom en iOS */
  transition: border-color .15s, box-shadow .15s;
}
.field textarea, .textarea { min-height: 110px; resize: vertical; line-height: 1.5; }
.field select, .select { appearance: none; -webkit-appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; }
.input:focus, .select:focus, .textarea:focus, .field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); }
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon > input { padding-left: 40px !important; }
.check { display: flex; align-items: flex-start; gap: var(--s3); min-height: 44px; padding: 10px 0; cursor: pointer; font-size: .9375rem; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
.check small { display: block; color: var(--muted); }
.form-actions { display: flex; flex-wrap: wrap; gap: var(--s2); justify-content: flex-end; margin-top: var(--s5); }
.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px !important; }
.password-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s4); margin: 0; min-width: 0; }
legend { font-weight: 650; padding: 0 var(--s2); }

.segmented { display: inline-flex; padding: 4px; background: var(--surface-3); border-radius: 12px; gap: 4px; flex-wrap: wrap; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; inset: 0; }
.segmented span { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 9px; font-size: .875rem; font-weight: 600; color: var(--text-2); cursor: pointer; }
.segmented input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.segmented input:focus-visible + span { outline: 3px solid color-mix(in srgb, var(--brand) 55%, transparent); }

/* Sugerencias rápidas bajo un campo (p. ej. zona del edificio) */
.suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }
.suggest-chip {
  min-height: 36px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text-2); font: inherit; font-size: .8125rem; font-weight: 600; cursor: pointer;
  transition: background-color .15s, border-color .15s, color .15s;
}
.suggest-chip:hover { border-color: var(--brand); color: var(--brand); }
.suggest-chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }

/* ---------------------------------------------------------------- Toolbar / filtros */
.toolbar { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; margin-bottom: var(--s4); }
.toolbar .input-icon { flex: 1 1 220px; }
.toolbar select { width: auto; min-width: 150px; flex: 0 1 auto; }
.toolbar .field { flex: 1 1 160px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; border-bottom: 1px solid var(--border); margin-bottom: var(--s4); -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 var(--s3); color: var(--muted); font-weight: 600; font-size: .9rem; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { color: var(--brand); border-color: var(--brand); }
.tabs .count { background: var(--surface-3); color: var(--text-2); border-radius: 999px; padding: 0 7px; font-size: .72rem; line-height: 18px; }

/* ---------------------------------------------------------------- Tablas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 650; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
.table td { padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table th.text-right, .table td.text-right { text-align: right; }
.table td.actions, .table th.actions { text-align: right; white-space: nowrap; width: 1%; }
.table td.actions > *:not(dialog) { display: inline-flex; vertical-align: middle; margin: 0 0 0 4px; }
.table td.actions dialog { white-space: normal; text-align: left; }
.table td.actions > form { margin-top: 0; margin-bottom: 0; }
.table th:last-child, .table td:last-child { padding-right: var(--s5); }
.table th:first-child, .table td:first-child { padding-left: var(--s5); }
@media (max-width: 720px) {
  .table-cards thead { display: none; }
  .table-cards tr { display: block; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
  .table-cards td { display: flex; justify-content: space-between; gap: var(--s3); padding: 4px 0; border: 0; text-align: right; }
  .table-cards td::before { content: attr(data-label); color: var(--muted); font-size: .8rem; font-weight: 600; text-align: left; }
  .table.table-cards td.actions { display: flex; justify-content: flex-end; width: auto; }
  .table.table-cards td:first-child, .table.table-cards td:last-child { padding-left: 0; padding-right: 0; }
  .table-cards td.actions::before { display: none; }
}

/* ---------------------------------------------------------------- Listas */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); color: var(--text); min-height: 60px; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .meta { color: var(--muted); font-size: .8125rem; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.list-item.is-unread { background: color-mix(in srgb, var(--brand-50) 70%, transparent); }
.list-item.is-unread .title::after { content: ""; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-left: 8px; vertical-align: middle; }

/* Tarjeta de incidencia */
.inc-card { display: block; padding: var(--s4); color: var(--text); border-bottom: 1px solid var(--border); }
.inc-card:last-child { border-bottom: 0; }
.inc-card:hover { background: var(--surface-2); text-decoration: none; }
.inc-card .top { display: flex; justify-content: space-between; align-items: center; gap: var(--s2); margin-bottom: 6px; }
.inc-card .code { font-family: var(--font-mono); font-size: .75rem; color: var(--muted); }
.inc-card .title { font-weight: 650; display: block; margin-bottom: 4px; }
.inc-card .meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: .8125rem; }
.inc-card .meta span { display: inline-flex; align-items: center; gap: 4px; }

/* ---------------------------------------------------------------- Vacío / paginación */
.empty { text-align: center; padding: var(--s10) var(--s4); color: var(--muted); }
.empty .icon-lg { margin: 0 auto var(--s3); width: 44px; height: 44px; color: var(--border-strong); }
.empty h3 { color: var(--text); margin-bottom: var(--s1); }
.empty .btn { margin-top: var(--s4); }
.pagination { display: flex; justify-content: center; align-items: center; gap: var(--s2); margin-top: var(--s4); }
.pagination span { color: var(--muted); font-size: .875rem; }

/* ---------------------------------------------------------------- Timeline */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 var(--s4) 28px; }
.timeline li::before { content: ""; position: absolute; left: 7px; top: 18px; bottom: 0; width: 2px; background: var(--border); }
.timeline li:last-child::before { display: none; }
.timeline .tl-dot { position: absolute; left: 0; top: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--surface); border: 3px solid var(--brand); }
.timeline .tl-dot.is-comment { border-color: var(--border-strong); }
.timeline .tl-dot.is-internal { border-color: var(--c-violet); }
.timeline .tl-head { font-size: .8125rem; color: var(--muted); }
.timeline .tl-head strong { color: var(--text); }
.timeline .tl-body { margin-top: 2px; font-size: .9375rem; white-space: pre-line; overflow-wrap: anywhere; }
.timeline .tl-body.is-comment { background: var(--surface-2); border: 1px solid var(--border); padding: var(--s2) var(--s3); border-radius: 10px; margin-top: 6px; }

/* Pasos del flujo */
.steps { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.steps::-webkit-scrollbar { display: none; }
.step { flex: 1 0 auto; min-width: 82px; display: flex; flex-direction: column; gap: 6px; font-size: .7rem; font-weight: 600; color: var(--muted); }
.step::before { content: ""; height: 5px; border-radius: 999px; background: var(--surface-3); }
.step.is-done::before { background: var(--brand); }
.step.is-current { color: var(--brand); }
.step.is-current::before { background: linear-gradient(90deg, var(--brand) 50%, var(--surface-3) 50%); }

/* Datos clave/valor */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: 8px 16px; margin: 0; font-size: .9375rem; }
.dl dt { color: var(--muted); font-weight: 550; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---------------------------------------------------------------- Fotos */
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: var(--s2); }
.photo { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-3); border: 1px solid var(--border); }
.photo img { width: 100%; height: 100%; object-fit: cover; }
.photo a { display: block; height: 100%; }
.photo .photo-del { position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 50%; border: 0; background: rgba(2,6,23,.6); color: #fff; display: grid; place-items: center; cursor: pointer; }
.photo .progress-ring { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(2,6,23,.55); color: #fff; font-weight: 750; font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.photo .photo-bar { position: absolute; left: 6px; right: 6px; bottom: 6px; height: 6px; border-radius: 999px; background: rgba(255,255,255,.35); overflow: hidden; }
.photo .photo-bar i { display: block; height: 100%; width: 0; background: #fff; transition: width .15s linear; }
.photo.is-error .progress-ring { background: rgba(185, 28, 28, .75); font-size: .8rem; text-align: center; padding: 6px; }
.photo-add { aspect-ratio: 1; border: 2px dashed var(--border-strong); border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; color: var(--muted); font-size: .75rem; font-weight: 650; cursor: pointer; background: var(--surface-2); text-align: center; padding: 4px; }
.photo-add:hover { border-color: var(--brand); color: var(--brand); }
.photo-add input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.phase-title { display: flex; align-items: center; gap: var(--s2); font-weight: 650; font-size: .875rem; margin: var(--s4) 0 var(--s2); }

.lightbox { position: fixed; inset: 0; z-index: 90; background: rgba(2,6,23,.92); display: grid; place-items: center; padding: var(--s4); }
.lightbox img { max-width: 100%; max-height: 88vh; border-radius: 8px; }
.lightbox button { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; color: #fff; background: rgba(255,255,255,.12); }

/* ---------------------------------------------------------------- Firma */
.signature-pad { position: relative; border: 2px dashed var(--border-strong); border-radius: var(--radius); background: #fff; touch-action: none; height: 220px; }
.signature-pad canvas { width: 100%; height: 100%; display: block; border-radius: var(--radius); cursor: crosshair; }
.signature-pad .sig-hint { position: absolute; left: 0; right: 0; bottom: 38px; text-align: center; color: #94A3B8; font-size: .85rem; pointer-events: none; }
.signature-pad .sig-line { position: absolute; left: 24px; right: 24px; bottom: 56px; border-top: 1px solid #CBD5E1; pointer-events: none; }

/* ---------------------------------------------------------------- Panel de trabajo del técnico */
.work-panel { background: linear-gradient(135deg, var(--brand), var(--brand-700)); color: var(--on-brand); border-radius: var(--radius-lg); padding: var(--s5); box-shadow: var(--shadow); }
.work-panel h2, .work-panel p { color: inherit; }
.work-panel .timer { font-size: 2.25rem; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.02em; margin: var(--s2) 0; }
.work-panel .btn-light { background: rgba(255,255,255,.95); color: #0F172A; }
.work-panel .btn-outline-light { background: transparent; color: inherit; border-color: rgba(255,255,255,.6); }
:root[data-theme="dark"] .work-panel { color: #04201D; }

/* ---------------------------------------------------------------- Chat */
.chat-layout { display: grid; grid-template-columns: 1fr; height: calc(100dvh - var(--topbar-h) - var(--safe-t) - var(--bottom-h) - var(--safe-b) - var(--s8)); min-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
@media (min-width: 900px) { .chat-layout { grid-template-columns: 340px 1fr; } }
@media (min-width: 1024px) { .chat-layout { height: calc(100dvh - var(--topbar-h) - 64px); } }
.chat-list { border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; min-height: 0; }
.chat-list-head { padding: var(--s3); border-bottom: 1px solid var(--border); display: flex; gap: var(--s2); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.chat-item { display: flex; gap: var(--s3); padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); color: var(--text); align-items: center; }
.chat-item:hover { background: var(--surface-2); text-decoration: none; }
.chat-item.is-active { background: var(--brand-50); }
.chat-item .grow { flex: 1; min-width: 0; }
.chat-item .name { font-weight: 650; display: flex; justify-content: space-between; gap: var(--s2); }
.chat-item .name time { color: var(--muted); font-weight: 500; font-size: .75rem; flex: none; }
.chat-item .preview { color: var(--muted); font-size: .85rem; display: flex; justify-content: space-between; gap: var(--s2); }
.chat-item .preview span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .unread { background: var(--brand); color: var(--on-brand); border-radius: 999px; min-width: 20px; height: 20px; font-size: .7rem; font-weight: 700; display: grid; place-items: center; padding: 0 6px; flex: none; }
.chat-group-icon { background: var(--c-indigo-bg); color: var(--c-indigo); }
.chat-room { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.chat-room-head { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s3); border-bottom: 1px solid var(--border); min-height: 60px; }
.chat-room-head .grow { flex: 1; min-width: 0; }
.chat-room-head small { color: var(--muted); display: block; }
.chat-messages { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: 6px; background: var(--surface-2); overscroll-behavior: contain; }
.msg { max-width: min(78%, 560px); display: flex; flex-direction: column; align-self: flex-start; }
.msg.is-mine { align-self: flex-end; align-items: flex-end; }
.msg-author { font-size: .75rem; font-weight: 650; color: var(--brand); margin: 6px 0 2px 10px; }
.msg-bubble { background: var(--surface); border: 1px solid var(--border); padding: 8px 12px; border-radius: 16px 16px 16px 4px; overflow-wrap: anywhere; white-space: pre-wrap; font-size: .9375rem; box-shadow: var(--shadow-sm); }
.msg.is-mine .msg-bubble { background: var(--brand); color: var(--on-brand); border-color: transparent; border-radius: 16px 16px 4px 16px; }
.msg-bubble img { border-radius: 10px; max-height: 260px; margin: 2px 0 4px; cursor: zoom-in; }
.msg-time { font-size: .68rem; color: var(--muted); margin: 2px 8px 0; }
.msg.is-deleted .msg-bubble { font-style: italic; opacity: .6; }
.msg.is-pending { opacity: .6; }
.chat-day { align-self: center; font-size: .72rem; font-weight: 650; color: var(--muted); background: var(--surface); border: 1px solid var(--border); padding: 2px 10px; border-radius: 999px; margin: var(--s2) 0; }
.chat-compose { display: flex; gap: var(--s2); align-items: flex-end; padding: var(--s2) var(--s3); border-top: 1px solid var(--border); background: var(--surface); }
.chat-compose textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; padding: 10px 14px; border-radius: 22px; border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text); font: inherit; font-size: 16px; }
.chat-compose textarea:focus { outline: none; border-color: var(--brand); }
.chat-compose .send { background: var(--brand); color: var(--on-brand); border-radius: 50%; }
.chat-empty { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: var(--s6); }
@media (max-width: 899px) {
  .chat-layout.has-room .chat-list { display: none; }
  .chat-layout:not(.has-room) .chat-room { display: none; }
}


/* Chat a pantalla completa en móvil y tablet: fijado entre la barra superior y la inferior */
@media (max-width: 1023px) {
  .content.is-chat { padding: 0; max-width: none; }
  .content.is-chat .flashes:not(:has(.alert)) { display: none; }
  .content.is-chat .chat-layout {
    position: fixed; left: 0; right: 0;
    top: calc(var(--topbar-h) + var(--safe-t));
    bottom: calc(var(--bottom-h) + var(--safe-b));
    height: auto; min-height: 0; border: 0; border-radius: 0; z-index: 5;
  }
  .content.is-chat .chat-list, .content.is-chat .chat-room { min-height: 0; }
}
@media (min-width: 1024px) {
  .content.is-chat { padding-top: var(--s4); padding-bottom: var(--s4); max-width: none; }
  .content.is-chat .chat-layout { height: calc(100dvh - var(--topbar-h) - var(--safe-t) - var(--s8)); }
}

/* ---------------------------------------------------------------- Modal */
.modal { border: 0; padding: 0; border-radius: var(--radius-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.modal::backdrop { background: rgba(2, 6, 23, .5); backdrop-filter: blur(2px); }
.modal[open] { animation: modal-in .2s var(--ease); }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-box { padding: var(--s5); display: flex; flex-direction: column; gap: var(--s3); }
.modal-title { font-size: 1.125rem; }
.modal-text { color: var(--text-2); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--s2); flex-wrap: wrap; margin-top: var(--s2); }
@media (max-width: 560px) {
  .modal { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; padding-bottom: var(--safe-b); }
  .modal-actions .btn { flex: 1; }
}

/* ---------------------------------------------------------------- Toasts */
.toasts { position: fixed; z-index: 80; left: 50%; transform: translateX(-50%); bottom: calc(var(--bottom-h) + var(--safe-b) + 12px); display: flex; flex-direction: column; gap: var(--s2); width: min(440px, calc(100vw - 24px)); pointer-events: none; }
@media (min-width: 1024px) { .toasts { left: auto; right: 24px; transform: none; bottom: 24px; } }
.toast { pointer-events: auto; display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius); background: #0F172A; color: #F8FAFC; box-shadow: var(--shadow-lg); font-size: .9375rem; animation: toast-in .25s var(--ease); }
.toast a { color: #5EEAD4; font-weight: 650; margin-left: auto; }
.toast.is-error { background: #7F1D1D; }
.toast.is-success .icon { color: #4ADE80; }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------------------------------------------------------------- Banner (push / instalación) */
.banner { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); border-radius: var(--radius); background: var(--brand-50); border: 1px solid color-mix(in srgb, var(--brand) 25%, transparent); margin-bottom: var(--s4); }
.banner .grow { flex: 1; min-width: 0; }
.banner strong { display: block; }
.banner small { color: var(--text-2); }

/* ---------------------------------------------------------------- Autenticación */
.auth-page { min-height: 100dvh; display: grid; place-items: center; padding: var(--s4); background:
  radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--brand) 18%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--brand) 12%, transparent), transparent 60%), var(--bg); }
.auth-card { width: min(420px, 100%); background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: var(--s8) var(--s6); }
.auth-card .brand { justify-content: center; flex-direction: column; text-align: center; margin-bottom: var(--s6); }
.auth-card .brand img { width: 64px; height: 64px; border-radius: 16px; }
.auth-card h1 { font-size: 1.35rem; text-align: center; }
.auth-card .sub { text-align: center; color: var(--muted); margin: var(--s1) 0 var(--s6); }
.auth-foot { text-align: center; margin-top: var(--s5); font-size: .875rem; color: var(--muted); }
.code-input { text-align: center; letter-spacing: .5em; font-size: 1.5rem !important; font-family: var(--font-mono); }

/* ---------------------------------------------------------------- Visor PDF */
.pdf-body { margin: 0; background: #525659; min-height: 100dvh; }
.pdf-bar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: var(--s2);
  padding: calc(var(--s2) + var(--safe-t)) var(--s3) var(--s2); background: #1F2937; color: #F9FAFB; box-shadow: 0 2px 10px rgba(0,0,0,.3);
}
.pdf-bar .btn-icon { color: #F9FAFB; }
.pdf-bar .btn-icon:hover { background: rgba(255,255,255,.12); }
.pdf-bar .title { flex: 1; min-width: 0; font-weight: 650; font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pdf-bar .pdf-actions { display: flex; gap: 4px; align-items: center; }
.pdf-bar .btn-label { display: none; }
@media (min-width: 640px) { .pdf-bar .btn-label { display: inline; } .pdf-bar .pdf-actions .btn { min-height: 40px; } }
.pdf-bar .btn { background: rgba(255,255,255,.1); color: #fff; border: 0; }
.pdf-bar .btn:hover { background: rgba(255,255,255,.2); }
.pdf-bar .btn-primary { background: #14B8A6; color: #04201D; }
.pdf-pages { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 16px 8px calc(24px + var(--safe-b)); }
.pdf-pages canvas { background: #fff; box-shadow: 0 4px 18px rgba(0,0,0,.35); max-width: 100%; height: auto !important; }
.pdf-loading { color: #E5E7EB; padding: 48px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.pdf-zoom { color: #E5E7EB; font-size: .8rem; font-variant-numeric: tabular-nums; min-width: 42px; text-align: center; }

/* ---------------------------------------------------------------- Errores */
.error-page { min-height: 70dvh; display: grid; place-items: center; text-align: center; padding: var(--s6); }
.error-code { font-size: 4.5rem; font-weight: 800; color: var(--brand); line-height: 1; letter-spacing: -0.04em; }

/* ---------------------------------------------------------------- Permisos (roles) */
.perm-group { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--s3) var(--s4); }
.perm-group h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: var(--s1); }

/* ---------------------------------------------------------------- Impresión */
@media print {
  .sidebar, .topbar, .bottom-nav, .toasts, .page-head .actions, .no-print { display: none !important; }
  .main { margin: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

/* =====================================================================
   Subidas en segundo plano
   ===================================================================== */
.upl-tray { position: fixed; right: 16px; bottom: 24px; z-index: 75; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; max-width: calc(100vw - 32px); }
@media (max-width: 1023px) { .upl-tray { right: 12px; bottom: calc(var(--bottom-h) + var(--safe-b) + 12px); } }
/* En el chat, por encima de la caja de escribir */
body:has(.content.is-chat) .upl-tray { bottom: 96px; }
@media (max-width: 1023px) { body:has(.content.is-chat) .upl-tray { bottom: calc(var(--bottom-h) + var(--safe-b) + 76px); } }
.upl-pill {
  display: inline-flex; align-items: center; gap: 10px; min-height: 48px; padding: 6px 16px 6px 8px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg);
  font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
}
.upl-ring { position: relative; width: 34px; height: 34px; flex: none; }
.upl-ring svg { width: 34px; height: 34px; transform: rotate(-90deg); }
.upl-ring circle { fill: none; stroke-width: 3.5; }
.upl-ring .bg { stroke: var(--surface-3); }
.upl-ring .fg { stroke: var(--brand); stroke-linecap: round; stroke-dasharray: 97.4; stroke-dashoffset: 97.4; transition: stroke-dashoffset .3s ease; }
.upl-arrow { position: absolute; inset: 0; display: grid; place-items: center; color: var(--brand); font-weight: 800; }
.upl-tray:not(.is-done):not(.has-error) .upl-arrow { animation: upl-bounce 1.4s ease-in-out infinite; }
@keyframes upl-bounce { 50% { transform: translateY(-2px); } }
.upl-tray.is-done .upl-ring .fg { stroke: var(--ok); }
.upl-tray.is-done .upl-arrow { color: var(--ok); }
.upl-tray.has-error .upl-ring .fg { stroke: var(--danger); }
.upl-tray.has-error .upl-arrow { color: var(--danger); }
.upl-panel { width: min(380px, calc(100vw - 24px)); max-height: min(60dvh, 460px); overflow-y: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow-lg); animation: modal-in .2s var(--ease); }
.upl-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 8px 4px 16px; position: sticky; top: 0; background: var(--surface); }
.upl-list { list-style: none; margin: 0; padding: 0 8px 8px; }
.upl-item { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; }
.upl-item + .upl-item { border-top: 1px solid var(--border); border-radius: 0; }
.upl-thumb { width: 44px; height: 44px; border-radius: 10px; overflow: hidden; flex: none; display: grid; place-items: center; background: var(--surface-3); color: var(--muted); }
.upl-thumb img { width: 100%; height: 100%; object-fit: cover; }
.upl-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.upl-info strong { font-size: .875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upl-info small { color: var(--muted); font-size: .75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upl-item.is-error small { color: var(--danger); }
.upl-item.is-done small { color: var(--ok); }
.upl-bar { display: block; height: 4px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.upl-bar i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 999px; transition: width .25s linear; }
.upl-item.is-done .upl-bar i { background: var(--ok); }
.upl-item.is-error .upl-bar i { background: var(--danger); }
.upl-actions { display: flex; gap: 2px; }
.upl-actions .btn { min-height: 36px; padding: 0 10px; }

/* Miniaturas de galería: subida en curso, vídeo y reintento */
.photo.is-uploading img { filter: saturate(.6) brightness(.85); }
.photo .progress-ring { pointer-events: none; }
.photo.is-new { animation: fade-in .4s var(--ease); }
.photo-retry { position: absolute; left: 6px; right: 6px; bottom: 6px; min-height: 30px; border: 0; border-radius: 8px; background: #fff; color: var(--danger); font: inherit; font-size: .75rem; font-weight: 700; cursor: pointer; }
.photo-video-ph { display: grid; place-items: center; width: 100%; height: 100%; background: #0F172A; color: #fff; font-size: 1.5rem; }
.photo-play { position: absolute; left: 6px; bottom: 6px; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: rgba(2, 6, 23, .65); color: #fff; font-size: .7rem; pointer-events: none; }
.photo-play .icon-sm { width: 12px; height: 12px; }
.lightbox video { max-width: 100%; max-height: 88vh; border-radius: 8px; background: #000; }

/* Chat: burbuja de subida con progreso y vídeos */
.msg-bubble video { display: block; max-width: 100%; max-height: 300px; border-radius: 10px; margin: 2px 0 4px; background: #000; }
.msg.is-upload { opacity: 1; }
.msg.is-upload .msg-bubble img { max-height: 160px; opacity: .8; }
.msg-upload { display: flex; flex-direction: column; gap: 5px; min-width: 160px; font-size: .8125rem; font-weight: 600; }
.msg.is-mine .msg-upload .upl-bar { background: rgba(255, 255, 255, .3); }
.msg.is-mine .msg-upload .upl-bar i { background: var(--on-brand); }
.msg.is-failed .msg-bubble { background: var(--danger-bg); color: var(--danger); }

/* =====================================================================
   Instalar la app (página /app y aviso de descarga)
   ===================================================================== */
.is-app .install-btn { display: none; }
.app-banner {
  display: flex; align-items: center; gap: var(--s3); padding: var(--s3); margin-bottom: var(--s4);
  border-radius: 16px; background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.app-banner img { width: 44px; height: 44px; border-radius: 11px; flex: none; }
.app-banner .grow { flex: 1; min-width: 0; }
.app-banner strong { display: block; font-size: .9375rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-banner small { color: var(--muted); display: block; line-height: 1.3; }
.auth-card .app-banner { margin: 0 0 var(--s5); box-shadow: none; background: var(--surface-2); }
.install-page { display: flex; flex-direction: column; gap: var(--s4); max-width: 640px; }
.install-page.is-guest { gap: var(--s3); }
.install-page.is-guest h1 { text-align: center; }
.install-page.is-guest .sub { margin-bottom: var(--s2); }
.install-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: var(--s5); display: flex; flex-direction: column; gap: var(--s4); }
.auth-card .install-card { padding: var(--s4); background: var(--surface-2); }
.install-card.is-current { border-color: color-mix(in srgb, var(--brand) 45%, transparent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 12%, transparent); }
.install-head { display: flex; align-items: center; gap: var(--s3); }
.install-head img { border-radius: 15px; box-shadow: var(--shadow-sm); }
.install-steps { margin: 0; padding-left: 1.3em; display: flex; flex-direction: column; gap: 8px; color: var(--text-2); font-size: .9375rem; }
.install-steps li::marker { color: var(--brand); font-weight: 700; }
.ios-share { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--info-bg); color: var(--info); vertical-align: middle; }

/* =====================================================================
   Menús en móvil y tablet: hojas inferiores al estilo iOS
   ===================================================================== */
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.sheet-head, .menu-panel .sheet-grabber { display: none; }
@keyframes sheet-up { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

@media (max-width: 1023px) {
  :root { --sheet-ease: cubic-bezier(.32, .72, 0, 1); --sheet-radius: 22px; }

  /* Fondo oscurecido y desenfocado */
  .sidebar-scrim { z-index: 44; background: rgba(2, 6, 23, .38); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); opacity: 0; transition: opacity .35s var(--sheet-ease); }
  .sidebar-scrim.is-open { opacity: 1; }

  /* Menú principal: 100 % de ancho, 70 % de alto, sube desde abajo */
  :root[data-sidebar] .sidebar {
    inset: auto 0 0 0; width: 100%; height: 70dvh; max-height: calc(100dvh - var(--safe-t) - 24px);
    background: var(--bg); color: var(--text);
    border: 0; border-radius: var(--sheet-radius) var(--sheet-radius) 0 0;
    padding: 0 var(--s4) calc(var(--s4) + var(--safe-b));
    box-shadow: 0 -12px 40px rgba(2, 6, 23, .22);
    transform: translateY(calc(100% + 40px)); visibility: hidden;
    transition: transform .45s var(--sheet-ease), visibility 0s linear .45s;
    z-index: 45; overscroll-behavior: contain;
  }
  :root[data-sidebar] .sidebar.is-open { transform: translateY(var(--drag, 0px)); visibility: visible; transition: transform .45s var(--sheet-ease), visibility 0s; }
  :root[data-sidebar] .sidebar.is-dragging { transition: none; }

  .sheet-head {
    display: flex; align-items: center; justify-content: center; position: sticky; top: 0; z-index: 2;
    height: 36px; margin: 0 calc(-1 * var(--s4)); background: var(--bg); touch-action: none; cursor: grab;
  }
  .sheet-grabber { width: 38px; height: 5px; border-radius: 999px; background: var(--border-strong); display: block; }
  .sheet-close {
    position: absolute; right: 14px; top: 8px; width: 30px; height: 30px; border-radius: 50%; border: 0;
    display: grid; place-items: center; background: var(--surface-3); color: var(--muted); cursor: pointer;
  }

  :root[data-sidebar] .sidebar .brand { margin: 0 0 var(--s3); padding: var(--s2) var(--s1); color: var(--text); }
  :root[data-sidebar] .sidebar .brand-text small { color: var(--muted); }
  :root[data-sidebar] .sidebar .nav-title {
    color: var(--muted); font-size: .75rem; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
    margin: var(--s5) var(--s4) 6px;
  }

  /* Lista agrupada (como Ajustes del iPhone) */
  .sidebar .nav { gap: 0; }
  .sidebar .nav-group { gap: 0; background: var(--surface); border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1px var(--border); }
  :root[data-sidebar] .sidebar .nav-link {
    position: relative; min-height: 50px; padding: 0 var(--s4) 0 var(--s3); gap: var(--s3);
    border-radius: 0; font-size: 1rem; font-weight: 500; color: var(--text); background: transparent;
  }
  :root[data-sidebar] .sidebar .nav-link + .nav-link::before {
    content: ""; position: absolute; top: 0; right: 0; left: 54px; height: 1px; background: var(--border);
  }
  :root[data-sidebar] .sidebar .nav-link > span:first-of-type { flex: 1; min-width: 0; }
  :root[data-sidebar] .sidebar .nav-link::after {
    content: ""; width: 8px; height: 8px; flex: none; margin-left: 4px;
    border-right: 2px solid var(--border-strong); border-top: 2px solid var(--border-strong); transform: rotate(45deg);
  }
  :root[data-sidebar] .sidebar .nav-link:hover, :root[data-sidebar] .sidebar .nav-link:active { background: var(--surface-3); text-decoration: none; color: var(--text); }
  :root[data-sidebar] .sidebar .nav-link.is-active { background: var(--brand-50); color: var(--text); font-weight: 600; }
  :root[data-sidebar] .sidebar .nav-link .icon {
    width: 30px; height: 30px; padding: 6px; border-radius: 8px; flex: none;
    background: var(--ic, var(--brand)); color: #fff;
  }
  :root[data-sidebar] .sidebar .nav-link.is-active .icon { color: #fff; }
  .sidebar .nav-badge { margin-left: 0; }
  .sidebar .nav-group a:nth-of-type(12n+1) { --ic: #0A84FF; }
  .sidebar .nav-group a:nth-of-type(12n+2) { --ic: #FF9F0A; }
  .sidebar .nav-group a:nth-of-type(12n+3) { --ic: #30B0C7; }
  .sidebar .nav-group a:nth-of-type(12n+4) { --ic: #34C759; }
  .sidebar .nav-group a:nth-of-type(12n+5) { --ic: #FF3B30; }
  .sidebar .nav-group a:nth-of-type(12n+6) { --ic: #5E5CE6; }
  .sidebar .nav-group a:nth-of-type(12n+7) { --ic: #8E8E93; }
  .sidebar .nav-group a:nth-of-type(12n+8) { --ic: #AF52DE; }
  .sidebar .nav-group a:nth-of-type(12n+9) { --ic: #FF2D55; }
  .sidebar .nav-group a:nth-of-type(12n+10) { --ic: #64D2FF; }
  .sidebar .nav-group a:nth-of-type(12n+11) { --ic: #A2845E; }
  .sidebar .nav-group a:nth-of-type(12n+12) { --ic: #FFD60A; }
  .sidebar-foot { padding-top: var(--s4); }
  :root[data-sidebar] .sidebar .install-btn { background: var(--surface); color: var(--brand); box-shadow: 0 0 0 1px var(--border); border-radius: 14px; min-height: 50px; }

  /* Menú de usuario: hoja inferior */
  .menu[open]::before {
    content: ""; position: fixed; inset: 0; z-index: 59; background: rgba(2, 6, 23, .38);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); animation: fade-in .3s var(--sheet-ease);
  }
  .menu-panel {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-height: 70dvh; overflow-y: auto; z-index: 60;
    border: 0; border-radius: var(--sheet-radius) var(--sheet-radius) 0 0; background: var(--bg);
    padding: 0 var(--s4) calc(var(--s4) + var(--safe-b)); box-shadow: 0 -12px 40px rgba(2, 6, 23, .22);
    animation: sheet-up .45s var(--sheet-ease);
  }
  .menu-panel .sheet-grabber { display: block; margin: 8px auto 10px; }
  .menu-head { text-align: center; align-items: center; border: 0; padding: var(--s2) 0 var(--s4); margin: 0; }
  .menu-head strong { font-size: 1.125rem; }
  .menu-panel > a, .menu-panel > form {
    background: var(--surface); box-shadow: 0 0 0 1px var(--border);
  }
  .menu-panel > a:first-of-type { border-radius: 14px 14px 0 0; }
  .menu-panel > form { border-radius: 0 0 14px 14px; margin-bottom: var(--s2); }
  .menu-panel a, .menu-panel button { min-height: 52px; font-size: 1rem; padding: 0 var(--s4); border-radius: 0; }
  .menu-panel form button { color: var(--danger); }

  /* Ventanas (confirmar, nuevo chat, salida…): hoja inferior */
  .modal {
    width: 100vw; max-width: 100vw; margin: auto 0 0; max-height: 85dvh;
    border-radius: var(--sheet-radius) var(--sheet-radius) 0 0; padding-bottom: var(--safe-b);
  }
  .modal[open] { animation: sheet-up .45s var(--sheet-ease); }
  .modal::backdrop { background: rgba(2, 6, 23, .38); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px); }
  .modal::before { content: ""; display: block; width: 38px; height: 5px; border-radius: 999px; background: var(--border-strong); margin: 8px auto 0; }
  .modal-box { padding-top: var(--s3); }
  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; min-height: 50px; border-radius: 14px; }
}

@media (max-width: 1023px) {
  /* El desenfoque de la barra superior convierte los elementos fijos en relativos a ella:
     mientras el menú de usuario está abierto se desactiva para que la hoja salga abajo. */
  .has-user-sheet .topbar { backdrop-filter: none; -webkit-backdrop-filter: none; background: var(--bg); z-index: 70; }
}

@media (max-width: 1023px) and (prefers-reduced-motion: reduce) {
  :root[data-sidebar] .sidebar, .menu-panel, .modal[open] { transition: none; animation: none; }
}
