/* =============================================================
   SISTEMA USA — Interfaz
   Diseño propio, responsive (móvil primero en navegación) y PWA.
   El color de marca (--brand) viene del color de cada empresa.
   ============================================================= */

:root {
  --brand: #4f46e5;
  --brand-600: color-mix(in srgb, var(--brand) 85%, #000);
  --brand-soft: color-mix(in srgb, var(--brand) 12%, transparent);
  --brand-soft-2: color-mix(in srgb, var(--brand) 20%, transparent);
  --on-brand: #fff;

  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --border: #e5e8f0;
  --ring: color-mix(in srgb, var(--brand) 35%, transparent);

  --ok: #059669;   --ok-soft: #d1fae5;
  --warn: #d97706; --warn-soft: #fef3c7;
  --bad: #dc2626;  --bad-soft: #fee2e2;
  --info: #2563eb; --info-soft: #dbeafe;
  --violet: #7c3aed; --violet-soft: #ede9fe;
  --gray-soft: #eef1f6;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 20px 50px -20px rgba(15, 23, 42, .35);

  --sidebar-w: 268px;
  --topbar-h: 66px;
  --bottom-h: 68px;
  --safe-b: env(safe-area-inset-bottom, 0px);

  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}

/* Tema oscuro: automático según el sistema, o forzado con data-theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1020; --surface: #121a2b; --surface-2: #0f1626;
    --text: #e8ecf5; --text-2: #c3cad8; --muted: #8b95a9; --border: #222c40;
    --ok-soft: rgba(5,150,105,.18); --warn-soft: rgba(217,119,6,.18); --bad-soft: rgba(220,38,38,.2);
    --info-soft: rgba(37,99,235,.2); --violet-soft: rgba(124,58,237,.22); --gray-soft: #1b2436;
    --brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
    --brand-soft-2: color-mix(in srgb, var(--brand) 32%, transparent);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1020; --surface: #121a2b; --surface-2: #0f1626;
  --text: #e8ecf5; --text-2: #c3cad8; --muted: #8b95a9; --border: #222c40;
  --ok-soft: rgba(5,150,105,.18); --warn-soft: rgba(217,119,6,.18); --bad-soft: rgba(220,38,38,.2);
  --info-soft: rgba(37,99,235,.2); --violet-soft: rgba(124,58,237,.22); --gray-soft: #1b2436;
  --brand-soft: color-mix(in srgb, var(--brand) 22%, transparent);
  --brand-soft-2: color-mix(in srgb, var(--brand) 32%, transparent);
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 10px 30px -14px rgba(0,0,0,.6);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5;
  color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
p { margin: 0 0 .8em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ring); outline-offset: 2px; border-radius: 8px; }

.ic { width: 20px; height: 20px; flex: none; display: inline-block; vertical-align: -4px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0 !important; }
.mb-0 { margin-bottom: 0 !important; }
.gap-8 { gap: 8px; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Marca ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: var(--text); letter-spacing: -.02em; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 60%, #a855f7));
  color: #fff; box-shadow: 0 6px 16px -6px var(--brand);
}
.brand-mark .ic { width: 22px; height: 22px; }
.brand-light { color: #fff; }
.brand-light .brand-mark { background: rgba(255,255,255,.18); box-shadow: none; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 42px; padding: 0 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font: inherit; font-weight: 650; font-size: 14px; cursor: pointer; white-space: nowrap;
  background: var(--surface); color: var(--text); border-color: var(--border);
  transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { text-decoration: none; background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn .ic { width: 18px; height: 18px; }
.btn-primary { background: var(--brand); color: var(--on-brand); border-color: var(--brand); box-shadow: 0 6px 16px -8px var(--brand); }
.btn-primary:hover { background: var(--brand-600); }
.btn-soft { background: var(--brand-soft); color: var(--brand); border-color: transparent; }
.btn-soft:hover { background: var(--brand-soft-2); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--gray-soft); }
.btn-danger { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.btn-danger:hover { background: var(--bad); color: #fff; }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-ok:hover { filter: brightness(.95); }
.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; border-radius: 9px; }
.btn-lg { height: 50px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.icon-btn {
  width: 40px; height: 40px; display: inline-grid; place-items: center; border-radius: 11px;
  border: 0; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--gray-soft); color: var(--text); }
.icon-btn.sm { width: 32px; height: 32px; border-radius: 9px; }
.link-btn { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); font-weight: 650; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Layout de la app ---------- */
.app { display: flex; min-height: 100vh; min-height: 100dvh; }
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column; gap: 14px; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
  overflow-y: auto;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 6px; }
.sidebar-close { display: none; }
.org-card {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px;
  background: var(--brand-soft); border: 1px solid var(--brand-soft-2);
}
.org-dot {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex: none;
  color: #fff; font-weight: 800; font-size: 13px; background: var(--brand);
}
.org-global .org-dot { background: linear-gradient(135deg, #0f172a, #334155); }
.org-text { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.org-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-text small { color: var(--muted); font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 12px 12px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 11px;
  color: var(--text-2); font-weight: 600; font-size: 14.5px; border: 0; background: none;
  font-family: inherit; cursor: pointer; text-align: left; width: 100%;
}
.nav-link:hover { background: var(--gray-soft); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--brand); color: #fff; box-shadow: 0 8px 18px -10px var(--brand); }
.sidebar-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-text strong { font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-text small { font-size: 12px; color: var(--muted); }

.main { flex: 1; min-width: 0; margin-left: var(--sidebar-w); display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(12px); -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.menu-btn { display: none; }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 { font-size: 19px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title small { color: var(--muted); font-size: 12.5px; display: none; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.topbar-avatar:hover { text-decoration: none; }
.net-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 650; padding: 6px 10px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); }
.net-status .ic { width: 16px; height: 16px; }
.ctx-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 28px 0; padding: 10px 14px;
  border-radius: 12px; background: var(--brand-soft); color: var(--text-2); font-size: 13.5px;
}
.ctx-banner .ic { color: var(--brand); }
.ctx-banner form { margin-left: auto; }
.content { padding: 24px 28px 48px; width: 100%; max-width: 1280px; }

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

/* ---------- Encabezado de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { font-size: 24px; font-weight: 800; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-weight: 600; font-size: 13.5px; margin-bottom: 10px; }
.back-link:hover { color: var(--text); text-decoration: none; }

/* ---------- Tarjetas ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-head h3 { font-size: 16px; font-weight: 750; display: flex; align-items: center; gap: 8px; }
.card-head h3 .ic { color: var(--brand); }
.card-body { padding: 18px 20px; }
.card + .card { margin-top: 18px; }
.grid > .card + .card { margin-top: 0; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr); align-items: start; }

/* Hero de bienvenida */
.hero {
  position: relative; overflow: hidden; border-radius: 22px; padding: 26px 28px; color: #fff; margin-bottom: 20px;
  background:
    radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--brand) 40%, #a855f7) 0%, transparent 55%),
    linear-gradient(135deg, var(--brand), var(--brand-600));
  box-shadow: 0 18px 40px -22px var(--brand);
}
.hero::after {
  content: ""; position: absolute; right: -60px; bottom: -80px; width: 260px; height: 260px; border-radius: 50%;
  border: 40px solid rgba(255,255,255,.08);
}
.hero small { opacity: .85; font-weight: 600; letter-spacing: .02em; }
.hero h2 { font-size: 26px; font-weight: 800; margin: 4px 0 6px; }
.hero p { opacity: .9; margin: 0; max-width: 620px; }
.hero .row { margin-top: 16px; position: relative; z-index: 1; }
.hero .btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.25); }
.hero .btn:hover { background: rgba(255,255,255,.26); }
.hero .btn-white { background: #fff; color: var(--brand); border-color: #fff; }
.hero .btn-white:hover { background: #f1f5f9; }

/* KPIs */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); color: var(--text);
}
a.stat:hover { text-decoration: none; border-color: var(--brand-soft-2); transform: translateY(-1px); }
.stat-ic { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; flex: none; background: var(--brand-soft); color: var(--brand); }
.stat-ic.ok { background: var(--ok-soft); color: var(--ok); }
.stat-ic.warn { background: var(--warn-soft); color: var(--warn); }
.stat-ic.bad { background: var(--bad-soft); color: var(--bad); }
.stat-ic.info { background: var(--info-soft); color: var(--info); }
.stat-ic.violet { background: var(--violet-soft); color: var(--violet); }
.stat-val { font-size: 26px; font-weight: 800; line-height: 1.1; letter-spacing: -.02em; }
.stat-lbl { font-size: 13px; color: var(--muted); font-weight: 600; }

/* Barra de progreso por estados */
.progress-strip { display: flex; height: 10px; border-radius: 999px; overflow: hidden; background: var(--gray-soft); }
.progress-strip span { display: block; height: 100%; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: 0; }

.bar { height: 8px; border-radius: 999px; background: var(--gray-soft); overflow: hidden; }
.bar span { display: block; height: 100%; border-radius: 999px; background: var(--brand); }

/* ---------- Badges / chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--gray-soft); color: var(--text-2);
}
.badge .ic { width: 13px; height: 13px; }
.st-pendiente   { background: var(--gray-soft); color: var(--text-2); }
.st-en_progreso { background: var(--info-soft); color: var(--info); }
.st-en_revision { background: var(--violet-soft); color: var(--violet); }
.st-completada  { background: var(--ok-soft); color: var(--ok); }
.st-cancelada   { background: var(--bad-soft); color: var(--bad); }
.pr-baja    { background: transparent; color: var(--muted); padding-left: 0; }
.pr-media   { background: transparent; color: var(--info); padding-left: 0; }
.pr-alta    { background: var(--warn-soft); color: var(--warn); }
.pr-urgente { background: var(--bad); color: #fff; }
.badge-perfil-superadmin { background: #0f172a; color: #fff; }
.badge-perfil-dueno { background: var(--warn-soft); color: var(--warn); }
.badge-perfil-admin { background: var(--violet-soft); color: var(--violet); }
.badge-perfil-empleado { background: var(--info-soft); color: var(--info); }
.badge-off { background: var(--bad-soft); color: var(--bad); }
.badge-on { background: var(--ok-soft); color: var(--ok); }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 9px; border-radius: 8px;
  font-size: 12px; font-weight: 650; color: var(--c, var(--brand));
  background: color-mix(in srgb, var(--c, var(--brand)) 13%, transparent);
}
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--brand)); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* Avatares */
.avatar {
  --av: var(--brand);
  width: 38px; height: 38px; border-radius: 12px; flex: none; display: inline-grid; place-items: center;
  font-weight: 800; font-size: 13px; color: #fff; background: var(--av);
  background: linear-gradient(135deg, var(--av), color-mix(in srgb, var(--av) 65%, #000));
}
.avatar.sm { width: 32px; height: 32px; border-radius: 10px; font-size: 11.5px; }
.avatar.xs { width: 26px; height: 26px; border-radius: 8px; font-size: 10px; }
.avatar.lg { width: 64px; height: 64px; border-radius: 18px; font-size: 22px; }
.avatars { display: inline-flex; }
.avatars .avatar { border: 2px solid var(--surface); margin-left: -8px; }
.avatars .avatar:first-child { margin-left: 0; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > label, .label { font-size: 13px; font-weight: 700; color: var(--text-2); }
.field .hint { font-size: 12.5px; color: var(--muted); }
.req { color: var(--bad); }
.input, .select, .textarea {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px;
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.5; }
.select { appearance: none; -webkit-appearance: none; padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px var(--ring); }
.input-icon { position: relative; }
.input-icon > .ic { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; pointer-events: none; }
.input-icon .input { padding-left: 42px; }
.input-icon .toggle-pass { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.color-input { width: 58px; height: 46px; padding: 4px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.swatch { width: 30px; height: 30px; border-radius: 9px; border: 2px solid transparent; cursor: pointer; padding: 0; }
.swatch.is-on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--surface); }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border); }
.section-title { font-size: 14px; font-weight: 800; display: flex; align-items: center; gap: 8px; margin: 6px 0 2px; }
.section-title .ic { color: var(--brand); }

/* Segmentado (perfil, prioridad) */
.segmented { display: flex; flex-wrap: wrap; gap: 8px; }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label > span {
  display: inline-flex; align-items: center; gap: 7px; height: 40px; padding: 0 14px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); font-weight: 650; font-size: 13.5px; cursor: pointer; color: var(--text-2);
}
.segmented input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.segmented input:focus-visible + span { box-shadow: 0 0 0 4px var(--ring); }

/* Selector de empleados */
.picker-tools { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pick-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 10px; max-height: 360px; overflow: auto; padding: 2px; }
.pick { position: relative; display: block; }
.pick input { position: absolute; opacity: 0; }
.pick-body {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 13px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); transition: border-color .15s, background .15s;
}
.pick-body strong { display: block; font-size: 14px; }
.pick-body .chips { margin-top: 4px; }
.pick-check { margin-left: auto; width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--border); display: grid; place-items: center; color: transparent; flex: none; }
.pick-check .ic { width: 14px; height: 14px; }
.pick input:checked + .pick-body { border-color: var(--brand); background: var(--brand-soft); }
.pick input:checked + .pick-body .pick-check { background: var(--brand); border-color: var(--brand); color: #fff; }
.pick input:focus-visible + .pick-body { box-shadow: 0 0 0 4px var(--ring); }
.check-list { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill { position: relative; }
.check-pill input { position: absolute; opacity: 0; }
.check-pill span {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--border); font-size: 13.5px; font-weight: 650; color: var(--text-2); background: var(--surface);
}
.check-pill span::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--brand)); }
.check-pill input:checked + span { border-color: var(--c, var(--brand)); background: color-mix(in srgb, var(--c, var(--brand)) 12%, transparent); color: var(--text); }

/* ---------- Filtros / barra de herramientas ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .input-icon { flex: 1 1 240px; }
.toolbar .select { width: auto; min-width: 150px; flex: 0 1 190px; height: 42px; }
.toolbar .input { height: 42px; }
.toolbar-more { display: contents; }
.filters-btn { display: none !important; }
.tabs { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; margin-bottom: 14px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 14px; border-radius: 999px; white-space: nowrap;
  font-size: 13.5px; font-weight: 650; color: var(--text-2); background: var(--surface); border: 1px solid var(--border);
}
.tab:hover { text-decoration: none; border-color: var(--brand-soft-2); }
.tab.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.tab .count { font-size: 11.5px; opacity: .75; }
.view-switch { display: inline-flex; padding: 3px; border-radius: 12px; background: var(--gray-soft); }
.view-switch a { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 9px; font-size: 13px; font-weight: 650; color: var(--muted); }
.view-switch a:hover { text-decoration: none; color: var(--text); }
.view-switch a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

/* ---------- Listas de datos ---------- */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: 14px; padding: 14px 20px; border-top: 1px solid var(--border); color: var(--text); }
.list-item:first-child { border-top: 0; }
a.list-item:hover { background: var(--surface-2); text-decoration: none; }
.list-main { min-width: 0; flex: 1; }
.list-title { font-weight: 700; font-size: 14.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.list-sub { color: var(--muted); font-size: 13px; margin-top: 2px; display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.list-sub .ic { width: 15px; height: 15px; vertical-align: -3px; margin-right: 3px; }
.list-meta { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.is-inactive { opacity: .6; }

/* ---------- Tareas ---------- */
.task-list { display: grid; gap: 12px; }
.task {
  position: relative; display: block; padding: 16px 18px 16px 22px; border-radius: var(--radius); color: var(--text);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); transition: transform .12s, border-color .12s;
}
.task::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 0 4px 4px 0; background: var(--rc, var(--border)); }
.task:hover { text-decoration: none; border-color: var(--brand-soft-2); transform: translateY(-1px); }
.task-top { display: flex; gap: 10px; align-items: flex-start; justify-content: space-between; }
.task-title { font-weight: 750; font-size: 15.5px; line-height: 1.35; }
.task-desc { color: var(--muted); font-size: 13.5px; margin: 6px 0 0; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-meta { display: flex; align-items: center; gap: 8px 14px; flex-wrap: wrap; margin-top: 12px; font-size: 13px; color: var(--muted); }
.task-meta .ic { width: 15px; height: 15px; vertical-align: -3px; margin-right: 3px; }
.task-meta .push { margin-left: auto; }
.due.is-late { color: var(--bad); font-weight: 700; }
.due.is-today { color: var(--warn); font-weight: 700; }
.due.is-soon { color: var(--text-2); font-weight: 650; }
.task.is-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-flag-open { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; color: var(--violet); }

/* Tablero Kanban */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(270px, 1fr); gap: 14px; overflow-x: auto; padding-bottom: 10px; scroll-snap-type: x mandatory; }
.col { background: var(--surface-2); border: 1px solid var(--border); border-radius: 18px; padding: 12px; scroll-snap-align: start; min-height: 200px; }
.col-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 6px 12px; font-weight: 750; font-size: 14px; }
.col-head .badge { height: 22px; }
.col .task { padding: 13px 14px 13px 18px; box-shadow: var(--shadow-sm); }
.col .task + .task { margin-top: 10px; }
.col .task-title { font-size: 14.5px; }
.col-empty { text-align: center; color: var(--muted); font-size: 13px; padding: 24px 8px; border: 1.5px dashed var(--border); border-radius: 12px; }

/* Detalle de tarea */
.detail-title { font-size: 24px; font-weight: 800; line-height: 1.3; margin: 8px 0 10px; }
.detail-desc { white-space: pre-wrap; color: var(--text-2); line-height: 1.65; }
.kv { display: grid; gap: 14px; }
.kv-row { display: flex; gap: 12px; align-items: flex-start; }
.kv-row > .ic { color: var(--muted); margin-top: 2px; }
.kv-row small { display: block; font-size: 12px; color: var(--muted); font-weight: 650; }
.kv-row strong { font-size: 14px; }
.people { display: flex; flex-direction: column; gap: 10px; }
.person { display: flex; align-items: center; gap: 10px; }
.person strong { display: block; font-size: 14px; }
.person small { color: var(--muted); font-size: 12.5px; }
.action-bar { display: flex; gap: 10px; flex-wrap: wrap; }
.status-flow { display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0 2px; }
.status-flow .step { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 650; color: var(--muted); }
.status-flow .step::after { content: "›"; margin-left: 6px; color: var(--border); }
.status-flow .step:last-child::after { content: ""; }
.status-flow .step.done { color: var(--ok); }
.status-flow .step.now { color: var(--brand); }

/* Comentarios y actividad */
.thread { display: flex; flex-direction: column; gap: 14px; }
.msg { display: flex; gap: 10px; }
.msg-bubble { background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px 14px 14px 14px; padding: 10px 14px; min-width: 0; flex: 1; }
.msg.mine { flex-direction: row-reverse; }
.msg.mine .msg-bubble { background: var(--brand-soft); border-color: var(--brand-soft-2); border-radius: 14px 4px 14px 14px; }
.msg-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-bottom: 3px; }
.msg-head strong { color: var(--text); font-size: 13.5px; }
.msg-text { white-space: pre-wrap; word-wrap: break-word; font-size: 14px; }
.composer { display: flex; gap: 10px; align-items: flex-end; margin-top: 16px; }
.composer .textarea { min-height: 48px; height: 48px; resize: none; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13.5px; }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.timeline li::after { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline small { display: block; color: var(--muted); font-size: 12px; }

/* Empresas */
.company-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.company { display: flex; flex-direction: column; padding: 18px; gap: 14px; }
.company-top { display: flex; gap: 12px; align-items: center; }
.company-logo { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; color: #fff; font-weight: 800; flex: none; background: var(--c); box-shadow: 0 8px 18px -10px var(--c); }
.company-top h3 { font-size: 16px; font-weight: 750; }
.company-top small { color: var(--muted); font-size: 12.5px; }
.company-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.company-stats div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 8px 10px; }
.company-stats b { display: block; font-size: 18px; }
.company-stats span { font-size: 11.5px; color: var(--muted); font-weight: 650; }
.company-foot { display: flex; gap: 8px; align-items: center; margin-top: auto; }

/* Roles */
.role-row { display: flex; align-items: center; gap: 12px; padding: 14px 20px; border-top: 1px solid var(--border); }
.role-row:first-child { border-top: 0; }
.role-dot { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); flex: none; }

/* Estado vacío */
.empty { text-align: center; padding: 42px 20px; color: var(--muted); }
.empty-ic { width: 60px; height: 60px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 14px; background: var(--brand-soft); color: var(--brand); }
.empty-ic .ic { width: 28px; height: 28px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }
.empty p { max-width: 380px; margin: 0 auto 16px; }

/* Avisos */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; font-size: 13.5px; background: var(--info-soft); color: var(--text-2); }
.alert .ic { color: var(--info); margin-top: 1px; }
.alert-warn { background: var(--warn-soft); }
.alert-warn .ic { color: var(--warn); }

/* Toasts */
.toasts { position: fixed; top: 16px; right: 16px; z-index: 100; display: flex; flex-direction: column; gap: 10px; width: min(400px, calc(100vw - 32px)); }
.toast {
  display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 14px; border-radius: 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: toast-in .25s ease-out;
}
.toast-ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.toast-ic .ic { width: 17px; height: 17px; }
.toast-success .toast-ic { background: var(--ok-soft); color: var(--ok); }
.toast-error .toast-ic { background: var(--bad-soft); color: var(--bad); }
.toast-info .toast-ic { background: var(--info-soft); color: var(--info); }
.toast-msg { flex: 1; font-size: 14px; font-weight: 550; }
.toast-x { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 8px; display: grid; }
.toast-x .ic { width: 16px; height: 16px; }
.toast.is-out { opacity: 0; transform: translateY(-8px); transition: .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } }

/* Diálogo de confirmación */
.dialog-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(15, 23, 42, .45); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
.dialog { width: min(420px, 100%); background: var(--surface); border-radius: 20px; padding: 22px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.dialog h3 { font-size: 17px; margin-bottom: 8px; }
.dialog p { color: var(--muted); }
.dialog .row { justify-content: flex-end; margin-top: 18px; }
@keyframes fade { from { opacity: 0; } }

/* ---------- Pantallas de acceso ---------- */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-hero {
  position: relative; overflow: hidden; color: #fff; padding: 48px; display: flex; align-items: center;
  background:
    radial-gradient(80% 60% at 90% 10%, rgba(168, 85, 247, .55), transparent 60%),
    radial-gradient(70% 60% at 0% 100%, rgba(14, 165, 233, .45), transparent 60%),
    linear-gradient(135deg, #312e81, #4f46e5 60%, #6d28d9);
}
.auth-hero-inner { position: relative; z-index: 1; max-width: 520px; }
.auth-hero h1 { font-size: clamp(28px, 3.2vw, 40px); font-weight: 800; letter-spacing: -.03em; margin: 36px 0 14px; }
.auth-hero p { font-size: 16.5px; opacity: .88; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-points li { display: flex; gap: 12px; align-items: center; font-weight: 600; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); padding: 12px 14px; border-radius: 14px; backdrop-filter: blur(4px); }
.auth-hero-shape { position: absolute; right: -120px; bottom: -120px; width: 420px; height: 420px; border-radius: 50%; border: 70px solid rgba(255,255,255,.07); }
.auth-main { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 20px; }
.auth-card { width: min(420px, 100%); }
.auth-card h2 { font-size: 28px; font-weight: 800; letter-spacing: -.02em; }
.auth-card .lead { color: var(--muted); margin: 6px 0 26px; }
.auth-card form { display: grid; gap: 16px; }
.auth-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 13.5px; }
.auth-row label { display: flex; gap: 8px; align-items: center; color: var(--text-2); cursor: pointer; }
.auth-foot { color: var(--muted); font-size: 12.5px; margin-top: 28px; }
.auth-mobile-brand { display: none; margin-bottom: 28px; }
.auth-back { display: inline-flex; align-items: center; gap: 6px; margin-top: 18px; font-weight: 650; font-size: 14px; }
.checkbox { width: 18px; height: 18px; accent-color: var(--brand); }

/* Instalar app */
.install-card {
  display: flex; align-items: center; gap: 14px; margin-top: 22px; padding: 14px; border-radius: 16px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
}
.install-card img { width: 46px; height: 46px; border-radius: 12px; flex: none; }
.install-card div { flex: 1; min-width: 0; }
.install-card strong { display: block; font-size: 14.5px; }
.install-card small { color: var(--muted); font-size: 12.5px; line-height: 1.35; display: block; }
.pwa-banner {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; margin-bottom: 18px; border-radius: 16px;
  background: var(--surface); border: 1px dashed var(--brand-soft-2);
}
.pwa-banner img { width: 40px; height: 40px; border-radius: 11px; flex: none; }
.pwa-banner div { flex: 1; min-width: 0; font-size: 13.5px; }
.pwa-banner strong { display: block; font-size: 14px; }
.pwa-banner small { color: var(--muted); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 95; background: rgba(15,23,42,.5); display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
.sheet-backdrop.is-out { opacity: 0; transition: opacity .2s; }
.sheet {
  width: min(480px, 100%); background: var(--surface); color: var(--text); border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(20px + var(--safe-b)); box-shadow: var(--shadow-lg); animation: sheet-up .28s ease-out;
}
@keyframes sheet-up { from { transform: translateY(100%); } }
.sheet-grip { width: 42px; height: 5px; border-radius: 99px; background: var(--border); margin: 0 auto 16px; }
.sheet-head { display: flex; gap: 14px; align-items: center; margin-bottom: 16px; }
.sheet-head img { border-radius: 14px; }
.sheet-head h3 { font-size: 18px; }
.sheet-head p { margin: 2px 0 0; color: var(--muted); font-size: 13.5px; }
.sheet-note { background: var(--warn-soft); color: var(--text-2); border-radius: 12px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.sheet-steps { list-style: none; margin: 0 0 18px; padding: 0; display: grid; gap: 10px; }
.sheet-steps li { display: flex; gap: 12px; align-items: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-radius: 14px; padding: 12px; font-size: 14.5px; line-height: 1.45; }
.step-n { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none; background: var(--brand); color: #fff; font-weight: 800; font-size: 13px; }
.step-ic { display: inline-grid; place-items: center; vertical-align: -5px; width: 30px; height: 30px; border-radius: 8px; background: var(--brand-soft); color: var(--brand); margin-left: 2px; }
@media (min-width: 600px) { .sheet-backdrop { align-items: center; } .sheet { border-radius: 24px; } .sheet-grip { display: none; } }

/* =============================================================
   RESPONSIVE
   ============================================================= */
@media (max-width: 1180px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 960px) {
  /* Menú lateral como panel deslizable */
  .sidebar { transform: translateX(-102%); transition: transform .25s ease; box-shadow: var(--shadow-lg); width: min(300px, 86vw); padding-bottom: calc(18px + var(--safe-b)); }
  .drawer-open .sidebar { transform: none; }
  .scrim { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(15,23,42,.45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  .drawer-open .scrim { opacity: 1; pointer-events: auto; }
  .drawer-open { overflow: hidden; }
  .sidebar-close { display: inline-grid; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; margin-left: -8px; }
  .topbar { padding: 0 16px; padding-top: env(safe-area-inset-top, 0px); height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px)); }
  .topbar-title small { display: block; }
  .topbar-title h1 { font-size: 17px; }
  .content { padding: 16px 16px calc(var(--bottom-h) + var(--safe-b) + 28px); }
  .ctx-banner { margin: 12px 16px 0; }
  .hide-sm { display: none !important; }

  /* Barra inferior */
  .bottom-nav {
    display: flex; align-items: stretch; justify-content: space-around; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    height: calc(var(--bottom-h) + var(--safe-b)); padding: 6px 8px var(--safe-b);
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
    border-top: 1px solid var(--border);
  }
  .bn-item {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    font-size: 11px; font-weight: 650; color: var(--muted); border: 0; background: none; font-family: inherit; cursor: pointer; border-radius: 12px;
  }
  .bn-item:hover { text-decoration: none; }
  .bn-item .ic { width: 23px; height: 23px; }
  .bn-item.active { color: var(--brand); }
  .bn-item.active .ic { filter: drop-shadow(0 4px 8px var(--brand-soft-2)); }
  .bn-fab {
    width: 54px; height: 54px; margin-top: -22px; border-radius: 18px; display: grid; place-items: center; flex: none;
    background: linear-gradient(135deg, var(--brand), color-mix(in srgb, var(--brand) 65%, #a855f7)); color: #fff;
    box-shadow: 0 12px 24px -10px var(--brand), 0 0 0 5px var(--bg);
  }
  .bn-fab .ic { width: 26px; height: 26px; }
  .toasts { top: auto; bottom: calc(var(--bottom-h) + var(--safe-b) + 12px); right: 12px; left: 12px; width: auto; }

  .auth { grid-template-columns: 1fr; }
  .auth-hero { display: none; }
  .auth-mobile-brand { display: inline-flex; }
  .auth-main { justify-content: flex-start; padding-top: max(48px, env(safe-area-inset-top)); }
  .auth-body .toasts { bottom: 16px; }
}

@media (max-width: 720px) {
  .grid-2, .grid-3, .form-grid { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-ic { width: 36px; height: 36px; border-radius: 11px; }
  .stat-ic .ic { width: 18px; height: 18px; }
  .stat-val { font-size: 21px; }
  .stat-lbl { font-size: 12px; line-height: 1.3; }
  .hero .btn { height: 38px; padding: 0 13px; font-size: 13px; }
  .action-bar .btn { flex: 1 1 100%; height: 48px; }
  .toolbar-more { display: none; width: 100%; gap: 10px; flex-wrap: wrap; }
  .toolbar.show-more .toolbar-more { display: flex; }
  .filters-btn { display: inline-flex !important; }
  .page-head h2 { font-size: 21px; }
  .page-head { margin-bottom: 14px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .hero { padding: 22px 20px; border-radius: 18px; }
  .hero h2 { font-size: 22px; }
  .card-head, .card-body, .card-pad { padding-left: 16px; padding-right: 16px; }
  .list-item { padding: 13px 16px; align-items: flex-start; flex-wrap: wrap; }
  .list-meta { width: 100%; justify-content: flex-start; padding-left: 52px; }
  .role-row { padding: 13px 16px; flex-wrap: wrap; }
  .toolbar .input-icon { flex: 1 1 0; }
  .toolbar .select { flex: 1 1 calc(50% - 5px); min-width: 0; }
  .toolbar .btn { flex: 1; }
  .pwa-banner { flex-wrap: wrap; }
  .pwa-banner div { flex: 1 1 calc(100% - 100px); }
  .pwa-banner .btn-primary { order: 3; flex: 1 1 100%; height: 40px; }
  .install-card { flex-wrap: wrap; }
  .install-card .btn { flex: 1 1 100%; height: 42px; }
  .board { grid-auto-columns: 86%; margin: 0 -16px; padding: 0 16px 10px; scroll-padding: 16px; }
  .detail-title { font-size: 20px; }
  .form-actions .btn { flex: 1; }
  .pick-list { grid-template-columns: 1fr; max-height: none; }
}

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

/* Modo app instalada: sin márgenes extra del navegador */
@media (display-mode: standalone) {
  body { overscroll-behavior-y: none; }
}
