/* ==========================================================================
   NeuroClinic — Sistema de diseño
   Estilo: SaaS médico moderno. Tokens en variables CSS, mobile-first,
   modales propios (.modal / .modal-overlay), cards con jerarquía clara.
   ========================================================================== */

/* ---------- Tipografía (auto-alojada) ---------- */
@font-face { font-family: 'Figtree'; font-weight: 400; font-style: normal; font-display: swap; src: url('../fonts/figtree-latin-400-normal.woff2') format('woff2'); }
@font-face { font-family: 'Figtree'; font-weight: 500; font-style: normal; font-display: swap; src: url('../fonts/figtree-latin-500-normal.woff2') format('woff2'); }
@font-face { font-family: 'Figtree'; font-weight: 600; font-style: normal; font-display: swap; src: url('../fonts/figtree-latin-600-normal.woff2') format('woff2'); }
@font-face { font-family: 'Figtree'; font-weight: 700; font-style: normal; font-display: swap; src: url('../fonts/figtree-latin-700-normal.woff2') format('woff2'); }
@font-face { font-family: 'Figtree'; font-weight: 800; font-style: normal; font-display: swap; src: url('../fonts/figtree-latin-800-normal.woff2') format('woff2'); }

/* ---------- Tokens ---------- */
:root {
    --font: 'Figtree', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;

    --primary-50: #eef2ff;
    --primary-100: #e0e7ff;
    --primary-200: #c7d2fe;
    --primary-300: #a5b4fc;
    --primary-400: #818cf8;
    --primary-500: #6366f1;
    --primary-600: #4f46e5;
    --primary-700: #4338ca;
    --primary-800: #3730a3;
    --primary-color: var(--primary-600);
    --secondary-color: #7c3aed;
    --accent: #06b6d4;
    --primary-rgb: 79, 70, 229;
    --secondary: #6d28d9;
    --gradient: linear-gradient(135deg, var(--primary-600) 0%, var(--secondary) 100%);
    --gradient-soft: linear-gradient(135deg, var(--primary-50) 0%, color-mix(in srgb, var(--secondary) 7%, white) 100%);
    --glow-a: rgba(6, 182, 212, .35);
    --glow-b: rgba(236, 72, 153, .25);

    /* Barra lateral (tema oscuro por defecto; el tema claro redefine estas variables) */
    --sidebar-bg: linear-gradient(180deg, #14173a 0%, #0c0e22 100%);
    --sidebar-glow: rgba(var(--primary-rgb), .22);
    --sidebar-text: #c7cbe6;
    --sidebar-strong: #ffffff;
    --sidebar-muted: #9aa0c8;
    --sidebar-section: #6f76a8;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --sidebar-active-bg: linear-gradient(90deg, rgba(var(--primary-rgb), .32), rgba(var(--primary-rgb), .10));
    --sidebar-active-text: #ffffff;
    --sidebar-active-icon: var(--primary-300);
    --sidebar-border: rgba(255, 255, 255, .06);

    /* Cuadro del logo y panel de acceso */
    --brand-mark-bg: var(--gradient);
    --brand-mark-shadow: 0 8px 20px -6px rgba(var(--primary-rgb), .7), inset 0 1px 0 rgba(255,255,255,.25);
    --auth-bg: linear-gradient(160deg, #1e1b4b 0%, #312e81 45%, #4c1d95 100%);

    --ink-900: #0f172a;
    --ink-800: #1e293b;
    --ink-700: #334155;
    --ink-600: #475569;
    --ink-500: #64748b;
    --ink-400: #94a3b8;
    --ink-300: #cbd5e1;
    --ink-200: #e2e8f0;
    --ink-100: #f1f5f9;
    --ink-50: #f8fafc;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8f9fc;
    --border: #e7eaf3;
    --border-strong: #d8dce8;

    --green: #10b981;  --green-bg: #ecfdf5;  --green-ink: #047857;
    --red: #ef4444;    --red-bg: #fef2f2;    --red-ink: #b91c1c;
    --amber: #f59e0b;  --amber-bg: #fffbeb;  --amber-ink: #b45309;
    --blue: #3b82f6;   --blue-bg: #eff6ff;   --blue-ink: #1d4ed8;
    --violet: #8b5cf6; --violet-bg: #f5f3ff; --violet-ink: #6d28d9;
    --cyan: #06b6d4;   --cyan-bg: #ecfeff;   --cyan-ink: #0e7490;
    --pink: #ec4899;   --pink-bg: #fdf2f8;   --pink-ink: #be185d;
    --slate: #64748b;  --slate-bg: #f1f5f9;  --slate-ink: #334155;

    --success-color: var(--green);
    --danger-color: var(--red);
    --warning-color: var(--amber);
    --info-color: var(--blue);
    --dark-color: var(--ink-800);

    --radius-xs: 6px;
    --radius-sm: 8px;
    --radius: 12px;
    --radius-lg: 16px;
    --radius-xl: 22px;

    --shadow-xs: 0 1px 2px rgba(15, 23, 42, .05);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .07), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow: 0 6px 18px -6px rgba(15, 23, 42, .10), 0 2px 6px -2px rgba(15, 23, 42, .05);
    --shadow-lg: 0 24px 56px -16px rgba(15, 23, 42, .25);
    --ring: 0 0 0 4px rgba(var(--primary-rgb), .18);

    --sidebar-w: 268px;
    --topbar-h: 68px;
    --bottom-nav-h: 64px;
    --ease: cubic-bezier(.2, .8, .2, 1);
    --t: .2s var(--ease);

    color-scheme: light;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--ink-800);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}
img, svg, video { max-width: 100%; }
a { color: var(--primary-600); text-decoration: none; }
a:hover { color: var(--primary-700); }
h1, h2, h3, h4, h5, h6 { margin: 0; color: var(--ink-900); line-height: 1.25; font-weight: 700; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.25rem 0; }
button { font: inherit; }
[hidden] { display: none !important; }
[x-cloak] { display: none !important; }
::selection { background: var(--primary-100); color: var(--primary-800); }

.icon { width: 1.15em; height: 1.15em; flex-shrink: 0; vertical-align: -0.2em; }
.icon-sm { width: .95em; height: .95em; }
.icon-lg { width: 1.5em; height: 1.5em; }
.icon-xl { width: 2rem; height: 2rem; }

/* Scrollbar discreta */
* { scrollbar-width: thin; scrollbar-color: var(--ink-300) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--ink-300); border-radius: 10px; border: 3px solid transparent; background-clip: content-box; }

/* ==========================================================================
   Layout de aplicación
   ========================================================================== */
.app-shell { min-height: 100vh; min-height: 100dvh; }

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    background:
        radial-gradient(120% 60% at 0% 0%, var(--sidebar-glow) 0%, transparent 60%),
        var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 60;
    transition: transform var(--t), width var(--t);
    padding-bottom: env(safe-area-inset-bottom);
}
.sidebar-brand {
    display: flex; align-items: center; gap: .8rem;
    padding: 1.35rem 1.35rem 1.1rem;
    color: var(--sidebar-strong);
}
.brand-mark {
    width: 42px; height: 42px; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--brand-mark-bg);
    box-shadow: var(--brand-mark-shadow);
    flex-shrink: 0; overflow: hidden;
}
.brand-mark img { width: 100%; height: 100%; object-fit: var(--brand-mark-fit, cover); padding: var(--brand-mark-pad, 0); }
.brand-mark .icon { width: 24px; height: 24px; color: var(--brand-mark-fg, #fff); }
.brand-text { min-width: 0; }
.brand-name { display: block; font-weight: 800; font-size: 1.02rem; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { display: block; font-size: .75rem; color: var(--sidebar-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .85rem 1rem; }
.nav-section { font-size: .68rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; color: var(--sidebar-section); padding: 1.1rem .75rem .45rem; }
.nav-link {
    position: relative;
    display: flex; align-items: center; gap: .8rem;
    padding: .66rem .8rem;
    margin: 2px 0;
    border-radius: 10px;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: .93rem;
    transition: background var(--t), color var(--t), transform var(--t);
}
.nav-link .icon { width: 20px; height: 20px; opacity: .85; }
.nav-link:hover { background: var(--sidebar-hover); color: var(--sidebar-strong); }
.nav-link.active { background: var(--sidebar-active-bg); color: var(--sidebar-active-text); }
.nav-link.active::before {
    content: ''; position: absolute; left: -.85rem; top: 8px; bottom: 8px; width: 4px;
    border-radius: 0 4px 4px 0; background: var(--primary-400);
}
.nav-link.active .icon { opacity: 1; color: var(--sidebar-active-icon); }
.nav-count { margin-left: auto; min-width: 22px; padding: 0 7px; height: 20px; border-radius: 10px; background: rgba(245, 158, 11, .2); color: #fcd34d; font-size: .72rem; font-weight: 700; display: grid; place-items: center; }

.sidebar-footer { padding: .9rem; border-top: 1px solid var(--sidebar-border); }
.sidebar-user { display: flex; align-items: center; gap: .7rem; padding: .55rem; border-radius: 12px; color: var(--sidebar-strong); }
.sidebar-user:hover { background: var(--sidebar-hover); color: var(--sidebar-strong); }
.sidebar-user .meta { min-width: 0; flex: 1; }
.sidebar-user .name { display: block; font-weight: 600; font-size: .88rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { display: block; font-size: .74rem; color: var(--sidebar-muted); }

/* ---------- Main ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; transition: margin var(--t); }

.topbar {
    position: sticky; top: 0; z-index: 40;
    height: var(--topbar-h);
    display: flex; align-items: center; gap: 1rem;
    padding: 0 1.75rem;
    padding-top: env(safe-area-inset-top);
    background: rgba(244, 246, 251, .82);
    backdrop-filter: saturate(180%) blur(14px);
    -webkit-backdrop-filter: saturate(180%) blur(14px);
    border-bottom: 1px solid transparent;
    transition: border-color var(--t), background var(--t);
}
.topbar.scrolled { border-bottom-color: var(--border); background: rgba(255, 255, 255, .86); }
.topbar-title { min-width: 0; flex: 1; }
.topbar-title h1 { font-size: 1.28rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title .crumbs { font-size: .8rem; color: var(--ink-500); display: flex; gap: .35rem; align-items: center; white-space: nowrap; overflow: hidden; }
.topbar-title .crumbs a { color: var(--ink-500); }
.topbar-title .crumbs a:hover { color: var(--primary-600); }
.topbar-actions { display: flex; align-items: center; gap: .6rem; }
.btn.menu-toggle { display: none; }

.global-search {
    position: relative; display: flex; align-items: center;
    width: min(340px, 32vw);
}
.global-search .icon { position: absolute; left: .85rem; color: var(--ink-400); pointer-events: none; }
.global-search input {
    width: 100%; height: 42px; border-radius: 12px;
    border: 1px solid var(--border); background: var(--surface);
    padding: 0 3.2rem 0 2.5rem; font: inherit; font-size: .9rem; color: var(--ink-800);
    transition: border-color var(--t), box-shadow var(--t);
}
.global-search input:focus { outline: none; border-color: var(--primary-400); box-shadow: var(--ring); }
.global-search kbd { position: absolute; right: .6rem; }
.global-search .search-open-btn { display: none; }
.search-results {
    position: absolute; top: calc(100% + 8px); left: 0; right: 0;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
    box-shadow: var(--shadow-lg); padding: .4rem; max-height: 60vh; overflow-y: auto; z-index: 80;
}
.search-results .result { display: flex; align-items: center; gap: .75rem; padding: .6rem .7rem; border-radius: 10px; color: var(--ink-800); }
.search-results .result:hover, .search-results .result.active { background: var(--primary-50); }
.search-results .result .sub { font-size: .78rem; color: var(--ink-500); }
.search-results .empty { padding: 1rem; text-align: center; color: var(--ink-500); font-size: .9rem; }

.content { flex: 1; padding: 1.5rem 1.75rem 2.5rem; width: 100%; max-width: 1560px; margin: 0 auto; }
.content-narrow { max-width: 980px; }

/* ---------- Bottom nav (móvil) ---------- */
.bottom-nav { display: none; }

/* ---------- Backdrop del menú ---------- */
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); backdrop-filter: blur(2px); z-index: 55; opacity: 0; pointer-events: none; transition: opacity var(--t); }

/* ==========================================================================
   Componentes
   ========================================================================== */

/* ---------- Encabezado de página ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.35rem; }
.page-head h2 { font-size: 1.45rem; }
.page-head .lead { color: var(--ink-500); margin: .25rem 0 0; font-size: .93rem; }
.page-head .actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* ---------- Botones ---------- */
.btn {
    --btn-bg: var(--surface); --btn-fg: var(--ink-700); --btn-bd: var(--border-strong);
    display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    height: 42px; padding: 0 1.1rem;
    border-radius: 11px; border: 1px solid var(--btn-bd);
    background: var(--btn-bg); color: var(--btn-fg);
    font-weight: 600; font-size: .92rem; line-height: 1; white-space: nowrap;
    cursor: pointer; user-select: none; text-decoration: none;
    transition: transform var(--t), box-shadow var(--t), background var(--t), border-color var(--t), color var(--t);
    -webkit-tap-highlight-color: transparent;
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); color: var(--btn-fg); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn[disabled], .btn.is-loading { opacity: .6; pointer-events: none; }
.btn .icon { width: 18px; height: 18px; }
.btn-primary, .btn-primary-custom { --btn-bg: var(--gradient); --btn-fg: #fff; --btn-bd: transparent; background: var(--gradient); box-shadow: 0 6px 16px -6px rgba(var(--primary-rgb), .55); }
.btn-primary:hover, .btn-primary-custom:hover { box-shadow: 0 10px 22px -8px rgba(var(--primary-rgb), .65); }
.btn-secondary, .btn-light { --btn-bg: var(--surface); --btn-fg: var(--ink-700); --btn-bd: var(--border-strong); }
.btn-soft { --btn-bg: var(--primary-50); --btn-fg: var(--primary-700); --btn-bd: transparent; }
.btn-soft:hover { --btn-bg: var(--primary-100); }
.btn-ghost { --btn-bg: transparent; --btn-fg: var(--ink-600); --btn-bd: transparent; }
.btn-ghost:hover { --btn-bg: var(--ink-100); box-shadow: none; }
.btn-danger { --btn-bg: var(--red); --btn-fg: #fff; --btn-bd: transparent; }
.btn-danger-soft { --btn-bg: var(--red-bg); --btn-fg: var(--red-ink); --btn-bd: transparent; }
.btn-success { --btn-bg: var(--green); --btn-fg: #fff; --btn-bd: transparent; }
.btn-success-soft { --btn-bg: var(--green-bg); --btn-fg: var(--green-ink); --btn-bd: transparent; }
.btn-warning-soft { --btn-bg: var(--amber-bg); --btn-fg: var(--amber-ink); --btn-bd: transparent; }
.btn-dark { --btn-bg: var(--ink-900); --btn-fg: #fff; --btn-bd: transparent; }
.btn-sm { height: 34px; padding: 0 .8rem; font-size: .84rem; border-radius: 9px; }
.btn-sm .icon { width: 16px; height: 16px; }
.btn-xs { height: 28px; padding: 0 .6rem; font-size: .78rem; border-radius: 8px; gap: .35rem; }
.btn-xs .icon { width: 14px; height: 14px; }
.btn-lg { height: 50px; padding: 0 1.5rem; font-size: 1rem; border-radius: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; padding: 0; }
.btn-icon.btn-sm { width: 34px; }
.btn-icon.btn-xs { width: 28px; }
.btn .spinner { width: 16px; height: 16px; }
.btn-group { display: inline-flex; gap: .5rem; flex-wrap: wrap; }

.spinner { width: 20px; height: 20px; border-radius: 50%; border: 2.5px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    min-width: 0;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1.05rem 1.25rem; border-bottom: 1px solid var(--border); }
.card-header.flat { border-bottom: 0; padding-bottom: .25rem; }
.card-title { display: flex; align-items: center; gap: .6rem; font-size: 1rem; font-weight: 700; color: var(--ink-900); }
.card-title .icon-wrap { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--primary-50); color: var(--primary-600); }
.card-title .icon-wrap .icon { width: 18px; height: 18px; }
.card-sub { font-size: .8rem; color: var(--ink-500); font-weight: 500; }
.card-body { padding: 1.25rem; }
.card-body.tight { padding: .5rem; }
.card-footer { padding: .9rem 1.25rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-hover { transition: transform var(--t), box-shadow var(--t), border-color var(--t); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary-200); }
.card-accent { border-left: 4px solid var(--primary-color); }
.card-accent.accent-red { border-left-color: var(--red); }
.card-accent.accent-amber { border-left-color: var(--amber); }
.card-accent.accent-green { border-left-color: var(--green); }
.card-link { color: inherit; display: block; }
.card-link:hover { color: inherit; }

/* Tarjetas de estadística */
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat {
    position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
    padding: 1.1rem 1.2rem; box-shadow: var(--shadow-sm);
    display: flex; align-items: center; gap: 1rem;
    transition: transform var(--t), box-shadow var(--t);
}
a.stat:hover { transform: translateY(-3px); box-shadow: var(--shadow); color: inherit; }
.stat .stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; }
.stat .stat-icon .icon { width: 24px; height: 24px; }
.stat .stat-value { font-size: 1.65rem; font-weight: 800; color: var(--ink-900); line-height: 1.1; letter-spacing: -.02em; }
.stat .stat-label { font-size: .82rem; color: var(--ink-500); font-weight: 500; }
.stat::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; background: currentColor; opacity: .04; }

.tone-indigo { color: var(--primary-600); } .bg-indigo { background: var(--primary-50); color: var(--primary-600); }
.tone-green { color: var(--green); }   .bg-green { background: var(--green-bg); color: var(--green-ink); }
.tone-red { color: var(--red); }       .bg-red { background: var(--red-bg); color: var(--red-ink); }
.tone-amber { color: var(--amber); }   .bg-amber { background: var(--amber-bg); color: var(--amber-ink); }
.tone-blue { color: var(--blue); }     .bg-blue { background: var(--blue-bg); color: var(--blue-ink); }
.tone-violet { color: var(--violet); } .bg-violet { background: var(--violet-bg); color: var(--violet-ink); }
.tone-cyan { color: var(--cyan); }     .bg-cyan { background: var(--cyan-bg); color: var(--cyan-ink); }
.tone-pink { color: var(--pink); }     .bg-pink { background: var(--pink-bg); color: var(--pink-ink); }
.tone-slate { color: var(--slate); }   .bg-slate { background: var(--slate-bg); color: var(--slate-ink); }

/* Hero del dashboard */
.hero {
    position: relative; overflow: hidden;
    border-radius: var(--radius-xl);
    padding: 1.6rem 1.75rem;
    background:
        radial-gradient(80% 140% at 100% 0%, var(--glow-a) 0%, transparent 55%),
        radial-gradient(60% 120% at 0% 100%, var(--glow-b) 0%, transparent 60%),
        var(--gradient);
    color: #fff;
    box-shadow: 0 18px 40px -18px rgba(var(--primary-rgb), .65);
    margin-bottom: 1.25rem;
    display: flex; align-items: center; justify-content: space-between; gap: 1.5rem; flex-wrap: wrap;
}
.hero h2 { color: #fff; font-size: 1.55rem; }
.hero p { margin: .35rem 0 0; color: rgba(255, 255, 255, .85); }
.hero .hero-pattern { position: absolute; right: -40px; bottom: -60px; width: 280px; opacity: .14; pointer-events: none; }
.hero .btn { --btn-bg: rgba(255, 255, 255, .16); --btn-fg: #fff; --btn-bd: rgba(255, 255, 255, .28); backdrop-filter: blur(6px); }
.hero .btn:hover { --btn-bg: rgba(255, 255, 255, .26); }
.hero .btn-white { --btn-bg: #fff; --btn-fg: var(--primary-700); --btn-bd: transparent; }
.hero-actions { display: flex; gap: .6rem; flex-wrap: wrap; position: relative; }

/* Próximo paciente */
.next-patient {
    display: flex; align-items: center; gap: 1rem; padding: 1.15rem 1.25rem;
    border-radius: var(--radius-lg); background: var(--gradient-soft); border: 1px solid var(--primary-100);
}
.next-patient .time { text-align: center; min-width: 76px; padding: .6rem .5rem; background: #fff; border-radius: 12px; box-shadow: var(--shadow-xs); }
.next-patient .time strong { display: block; font-size: 1.25rem; color: var(--primary-700); }
.next-patient .time span { font-size: .72rem; color: var(--ink-500); text-transform: uppercase; letter-spacing: .06em; }

/* ---------- Grids ---------- */
.grid { display: grid; gap: 1.25rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 1fr) 360px; }
.grid-main-lg { grid-template-columns: minmax(0, 1fr) 400px; }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); }
.stack { display: flex; flex-direction: column; gap: 1.25rem; }
.stack-sm { display: flex; flex-direction: column; gap: .6rem; }
.row { display: flex; align-items: center; gap: .75rem; }
.row-wrap { flex-wrap: wrap; }
.row-between { justify-content: space-between; }
.row-end { justify-content: flex-end; }
.grow { flex: 1; min-width: 0; }
.span-2 { grid-column: span 2; }
.span-full { grid-column: 1 / -1; }

/* ---------- Badges / chips ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    height: 24px; padding: 0 .6rem; border-radius: 999px;
    font-size: .74rem; font-weight: 700; letter-spacing: .01em; white-space: nowrap;
    background: var(--slate-bg); color: var(--slate-ink);
}
.badge .icon { width: 13px; height: 13px; }
.badge-green { background: var(--green-bg); color: var(--green-ink); }
.badge-red { background: var(--red-bg); color: var(--red-ink); }
.badge-amber { background: var(--amber-bg); color: var(--amber-ink); }
.badge-blue { background: var(--blue-bg); color: var(--blue-ink); }
.badge-violet { background: var(--violet-bg); color: var(--violet-ink); }
.badge-cyan { background: var(--cyan-bg); color: var(--cyan-ink); }
.badge-pink { background: var(--pink-bg); color: var(--pink-ink); }
.badge-indigo { background: var(--primary-50); color: var(--primary-700); }
.badge-slate { background: var(--slate-bg); color: var(--slate-ink); }
.badge-solid-red { background: var(--red); color: #fff; }
.badge-lg { height: 28px; font-size: .8rem; padding: 0 .75rem; }
.badge-dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.chip {
    display: inline-flex; align-items: center; gap: .4rem;
    padding: .38rem .75rem; border-radius: 999px;
    background: var(--surface); border: 1px solid var(--border-strong);
    font-size: .84rem; font-weight: 600; color: var(--ink-700); cursor: pointer;
    transition: all var(--t);
}
.chip:hover { border-color: var(--primary-300); color: var(--primary-700); }
.chip.active { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
.chip .count { font-size: .72rem; opacity: .75; }
label.chip:has(input:checked) { background: var(--primary-600); border-color: var(--primary-600); color: #fff; }
label.chip.chip-flag:has(input:checked) { background: var(--red); border-color: var(--red); color: #fff; }
label.chip { user-select: none; -webkit-tap-highlight-color: transparent; }
.chips { display: flex; gap: .5rem; flex-wrap: wrap; }

kbd { display: inline-flex; align-items: center; height: 22px; padding: 0 .45rem; border-radius: 6px; border: 1px solid var(--border-strong); border-bottom-width: 2px; background: var(--surface-2); font-family: inherit; font-size: .72rem; font-weight: 600; color: var(--ink-500); }

/* ---------- Avatares ---------- */
.avatar {
    --h: 240;
    width: 40px; height: 40px; border-radius: 12px; flex-shrink: 0;
    display: grid; place-items: center;
    font-weight: 700; font-size: .88rem; letter-spacing: .02em;
    background: hsl(var(--h) 85% 94%); color: hsl(var(--h) 55% 38%);
}
.avatar-sm { width: 32px; height: 32px; border-radius: 10px; font-size: .75rem; }
.avatar-lg { width: 64px; height: 64px; border-radius: 18px; font-size: 1.3rem; }
.avatar-xl { width: 84px; height: 84px; border-radius: 22px; font-size: 1.7rem; }
.avatar-round { border-radius: 50%; }

/* ---------- Formularios ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem 1.1rem; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .4rem; min-width: 0; }
.form-label, .label { display: block; font-weight: 600; font-size: .85rem; color: var(--ink-700); }
.label .req { color: var(--red); }
.label .hint { font-weight: 500; color: var(--ink-400); }
.help { font-size: .78rem; color: var(--ink-500); margin: 0; }
.field-error { font-size: .78rem; color: var(--red-ink); margin: 0; font-weight: 600; }
.form-section { padding: 1.25rem 0; border-top: 1px solid var(--border); }
.form-section:first-child { border-top: 0; padding-top: 0; }
.form-section-title { display: flex; align-items: center; gap: .5rem; font-size: .8rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-500); margin-bottom: .9rem; }

.form-control, .form-select, .input, textarea.input, select.input {
    width: 100%; min-height: 44px;
    padding: .62rem .9rem;
    border: 1.5px solid var(--border-strong); border-radius: 11px;
    background: var(--surface); color: var(--ink-900);
    font: inherit; font-size: .93rem;
    transition: border-color var(--t), box-shadow var(--t), background var(--t);
    -webkit-appearance: none; appearance: none;
}
textarea.input, textarea.form-control { min-height: 96px; resize: vertical; line-height: 1.55; }
select.input, select.form-select {
    padding-right: 2.4rem;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='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 .7rem center; background-size: 18px;
}
.input:hover, .form-control:hover { border-color: var(--ink-300); }
.input:focus, .form-control:focus, .form-select:focus { outline: none; border-color: var(--primary-500); box-shadow: var(--ring); }
.input::placeholder { color: var(--ink-400); }
.input[readonly], .input:disabled { background: var(--ink-50); color: var(--ink-500); }
.input.is-invalid { border-color: var(--red); }
.input-sm { min-height: 36px; padding: .4rem .7rem; font-size: .86rem; border-radius: 9px; }
input[type="date"].input, input[type="time"].input, input[type="datetime-local"].input { min-height: 44px; }
input[type="color"].input { padding: 4px; height: 44px; cursor: pointer; }

.input-icon { position: relative; }
.input-icon > .icon { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--ink-400); pointer-events: none; }
.input-icon > .input { padding-left: 2.55rem; }
.input-icon > .input-action { position: absolute; right: .35rem; top: 50%; transform: translateY(-50%); }

.check { display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; font-size: .92rem; font-weight: 500; color: var(--ink-700); user-select: none; }
.check input { width: 20px; height: 20px; accent-color: var(--primary-600); cursor: pointer; }
.check-card {
    display: flex; align-items: flex-start; gap: .75rem; padding: .85rem 1rem;
    border: 1.5px solid var(--border-strong); border-radius: 12px; cursor: pointer; transition: all var(--t);
}
.check-card:hover { border-color: var(--primary-300); }
.check-card:has(input:checked) { border-color: var(--primary-500); background: var(--primary-50); }
.check-card input { margin-top: 2px; width: 18px; height: 18px; accent-color: var(--primary-600); }

/* Interruptor */
.switch { position: relative; display: inline-flex; align-items: center; gap: .65rem; cursor: pointer; font-weight: 500; font-size: .92rem; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track { width: 44px; height: 26px; border-radius: 99px; background: var(--ink-300); position: relative; transition: background var(--t); flex-shrink: 0; }
.switch .track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform var(--t); }
.switch input:checked + .track { background: var(--primary-600); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { box-shadow: var(--ring); }

/* Control segmentado */
.segmented { display: inline-flex; padding: 4px; gap: 2px; border-radius: 12px; background: var(--ink-100); border: 1px solid var(--border); }
.segmented button, .segmented a, .segmented label {
    border: 0; background: transparent; padding: .45rem .9rem; border-radius: 9px;
    font-weight: 600; font-size: .85rem; color: var(--ink-600); cursor: pointer; white-space: nowrap;
    display: inline-flex; align-items: center; gap: .4rem; transition: all var(--t);
}
.segmented .active, .segmented button[aria-pressed="true"], .segmented label:has(input:checked) { background: var(--surface); color: var(--ink-900); box-shadow: var(--shadow-sm); }
.segmented input { display: none; }

/* Escala 0-10 (EVA) */
.scale { display: grid; grid-template-columns: repeat(11, minmax(0, 1fr)); gap: 4px; }
.scale label { display: grid; place-items: center; height: 40px; border-radius: 9px; background: var(--ink-100); font-weight: 700; font-size: .88rem; cursor: pointer; color: var(--ink-600); transition: all var(--t); }
.scale input { display: none; }
.scale label:has(input:checked) { color: #fff; transform: scale(1.06); box-shadow: var(--shadow); }
.scale label:nth-child(-n+4):has(input:checked) { background: var(--green); }
.scale label:nth-child(n+5):nth-child(-n+7):has(input:checked) { background: var(--amber); }
.scale label:nth-child(n+8):has(input:checked) { background: var(--red); }

/* ---------- Tabs ---------- */
.tabs {
    display: flex; gap: .25rem; overflow-x: auto; scrollbar-width: none;
    border-bottom: 1px solid var(--border); margin-bottom: 1.25rem;
    -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    position: relative; display: inline-flex; align-items: center; gap: .5rem;
    padding: .85rem 1rem; border: 0; background: none; cursor: pointer; white-space: nowrap;
    font-weight: 600; font-size: .9rem; color: var(--ink-500); transition: color var(--t);
}
.tab .icon { width: 17px; height: 17px; }
.tab:hover { color: var(--ink-800); }
.tab.active { color: var(--primary-700); }
.tab.active::after { content: ''; position: absolute; left: .6rem; right: .6rem; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--primary-600); }
.tab .count { font-size: .7rem; padding: 1px 7px; border-radius: 99px; background: var(--ink-100); color: var(--ink-600); }
.tab.active .count { background: var(--primary-100); color: var(--primary-700); }
.tab-panel { display: none; animation: fadeUp .25s var(--ease); }
.tab-panel.active { display: block; }

/* ---------- Listas ---------- */
.list { display: flex; flex-direction: column; }
.list-item {
    display: flex; align-items: center; gap: .9rem;
    padding: .85rem 1.25rem; border-top: 1px solid var(--border);
    color: inherit; transition: background var(--t);
}
.list-item:first-child { border-top: 0; }
a.list-item:hover, .list-item.clickable:hover { background: var(--surface-2); color: inherit; cursor: pointer; }
.list-item .title { font-weight: 600; color: var(--ink-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .sub { font-size: .82rem; color: var(--ink-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .meta { margin-left: auto; text-align: right; flex-shrink: 0; display: flex; align-items: center; gap: .6rem; }
.list-compact .list-item { padding: .65rem 1rem; }

.time-pill { min-width: 64px; text-align: center; padding: .35rem .5rem; border-radius: 10px; background: var(--ink-100); font-weight: 700; font-size: .85rem; color: var(--ink-800); flex-shrink: 0; }
.time-pill small { display: block; font-size: .68rem; font-weight: 600; color: var(--ink-500); }

/* ---------- Tabla ---------- */
.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: .74rem; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-500); font-weight: 700; padding: .75rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: .8rem 1rem; 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 .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Estado vacío ---------- */
.empty {
    text-align: center; padding: 2.5rem 1.5rem; color: var(--ink-500);
    display: flex; flex-direction: column; align-items: center; gap: .6rem;
}
.empty .empty-icon { width: 64px; height: 64px; border-radius: 20px; display: grid; place-items: center; background: var(--gradient-soft); color: var(--primary-500); margin-bottom: .25rem; }
.empty .empty-icon .icon { width: 30px; height: 30px; }
.empty h4 { color: var(--ink-800); }
.empty p { max-width: 380px; margin: 0; font-size: .9rem; }

/* ---------- Alertas ---------- */
.alert { display: flex; gap: .75rem; align-items: flex-start; padding: .9rem 1.05rem; border-radius: 12px; border: 1px solid transparent; font-size: .9rem; }
.alert .icon { width: 20px; height: 20px; margin-top: 1px; }
.alert strong { display: block; }
.alert-info { background: var(--blue-bg); color: var(--blue-ink); border-color: #dbeafe; }
.alert-success { background: var(--green-bg); color: var(--green-ink); border-color: #d1fae5; }
.alert-warning { background: var(--amber-bg); color: var(--amber-ink); border-color: #fde68a; }
.alert-danger { background: var(--red-bg); color: var(--red-ink); border-color: #fecaca; }

/* Banda de alergias en el expediente */
.allergy-band {
    display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
    padding: .7rem 1rem; border-radius: 12px;
    background: linear-gradient(90deg, #fef2f2, #fff1f2); border: 1px solid #fecaca; color: var(--red-ink);
}
.allergy-band .label-strong { display: inline-flex; align-items: center; gap: .4rem; font-weight: 800; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; }
.allergy-band .pill { background: #fff; border: 1px solid #fecaca; border-radius: 999px; padding: .2rem .65rem; font-weight: 700; font-size: .82rem; }
.allergy-band .pill.severe { background: var(--red); color: #fff; border-color: var(--red); }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 1.75rem; }
.timeline::before { content: ''; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--border); border-radius: 2px; }
.tl-item { position: relative; padding-bottom: 1.25rem; }
.tl-item:last-child { padding-bottom: 0; }
.tl-dot { position: absolute; left: -1.75rem; top: 4px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 3px solid var(--primary-500); box-shadow: 0 0 0 4px var(--bg); }
.tl-dot.muted { border-color: var(--ink-300); }
.tl-dot.green { border-color: var(--green); }
.tl-date { font-size: .78rem; font-weight: 700; color: var(--ink-500); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .35rem; }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px); min-width: 220px; z-index: 90;
    background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
    padding: .4rem; display: none; animation: pop .16s var(--ease);
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu.left { right: auto; left: 0; }
.dropdown-item {
    display: flex; align-items: center; gap: .65rem; width: 100%;
    padding: .6rem .75rem; border-radius: 9px; border: 0; background: none; cursor: pointer; text-align: left;
    color: var(--ink-700); font-weight: 500; font-size: .9rem;
}
.dropdown-item:hover { background: var(--ink-100); color: var(--ink-900); }
.dropdown-item.danger { color: var(--red-ink); }
.dropdown-item.danger:hover { background: var(--red-bg); }
.dropdown-item .icon { width: 17px; height: 17px; color: var(--ink-400); }
.dropdown-item.danger .icon { color: var(--red); }
.dropdown-divider { height: 1px; background: var(--border); margin: .35rem 0; }
.dropdown-header { padding: .5rem .75rem; font-size: .75rem; color: var(--ink-500); }

/* ==========================================================================
   Modales (sistema propio: .modal + .modal-overlay, openModal/closeModal)
   ========================================================================== */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 9998;
    background: rgba(15, 23, 42, .5);
    backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.modal-overlay.active { display: block; animation: fadeIn .2s ease; }
.modal {
    display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    width: 92%; max-width: 600px; max-height: 92vh; max-height: 92dvh;
    background: var(--surface); border-radius: 20px; box-shadow: 0 30px 80px -20px rgba(15, 23, 42, .45);
    z-index: 9999; overflow: hidden; flex-direction: column;
}
.modal.active { display: flex; animation: modalIn .28s var(--ease); }
.modal.modal-sm { max-width: 440px; }
.modal.modal-lg { max-width: 820px; }
.modal.modal-xl { max-width: 1100px; }
.modal-header {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: 1.1rem 1.4rem;
    background: var(--gradient); color: #fff;
}
.modal-header.plain { background: var(--surface); color: var(--ink-900); border-bottom: 1px solid var(--border); }
.modal-header h3, .modal-header h5 { color: inherit; font-size: 1.08rem; display: flex; align-items: center; gap: .6rem; margin: 0; }
.modal-header .subtitle { font-size: .8rem; opacity: .85; font-weight: 500; }
.modal-header .btn-close {
    width: 36px; height: 36px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .14);
    color: inherit; display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
    transition: transform var(--t), background var(--t);
}
.modal-header.plain .btn-close { background: var(--ink-100); }
.modal-header .btn-close:hover { background: rgba(255, 255, 255, .26); transform: rotate(90deg); }
.modal-header .btn-close .icon { width: 18px; height: 18px; }
.modal-body { padding: 1.4rem; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.modal-footer { padding: .95rem 1.4rem; border-top: 1px solid var(--border); display: flex; gap: .6rem; justify-content: flex-end; background: var(--surface-2); flex-wrap: wrap; }
.modal-footer .left { margin-right: auto; }
.modal form { display: flex; flex-direction: column; min-height: 0; flex: 1; }

@keyframes modalIn { from { opacity: 0; transform: translate(-50%, -46%) scale(.98); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes sheetIn { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(.98); } to { opacity: 1; transform: none; } }

/* ---------- Diálogo de confirmación ---------- */
.dialog-icon { width: 60px; height: 60px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 1rem; }
.dialog-icon .icon { width: 28px; height: 28px; }
.dialog-body { text-align: center; padding: 1.8rem 1.6rem 1.2rem; }
.dialog-body h3 { margin-bottom: .45rem; }
.dialog-body p { color: var(--ink-500); margin: 0; }
.dialog-body .input { margin-top: 1rem; text-align: left; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; top: calc(1rem + env(safe-area-inset-top)); right: 1rem; z-index: 10050; display: flex; flex-direction: column; gap: .6rem; pointer-events: none; }
.toast {
    pointer-events: auto; display: flex; align-items: flex-start; gap: .75rem;
    min-width: 280px; max-width: 400px; padding: .85rem 1rem .85rem .9rem;
    background: var(--ink-900); color: #fff; border-radius: 14px; box-shadow: var(--shadow-lg);
    animation: toastIn .3s var(--ease); font-size: .9rem; font-weight: 500;
}
.toast .t-icon { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.toast .t-icon .icon { width: 16px; height: 16px; }
.toast.success .t-icon { background: var(--green); }
.toast.error .t-icon { background: var(--red); }
.toast.warning .t-icon { background: var(--amber); }
.toast.info .t-icon { background: var(--blue); }
.toast .t-msg { flex: 1; padding-top: 2px; }
.toast .t-close { background: none; border: 0; color: rgba(255, 255, 255, .6); cursor: pointer; padding: 2px; }
.toast.leaving { animation: toastOut .25s ease forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateX(24px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { to { opacity: 0; transform: translateX(24px); } }

/* ---------- Skeleton ---------- */
.skeleton { background: linear-gradient(90deg, var(--ink-100) 25%, var(--ink-50) 50%, var(--ink-100) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 8px; }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ==========================================================================
   Pacientes / expediente
   ========================================================================== */
.patient-card { display: flex; flex-direction: column; gap: .9rem; padding: 1.1rem 1.2rem; }
.patient-card .top { display: flex; gap: .85rem; align-items: center; }
.patient-card .name { font-weight: 700; color: var(--ink-900); font-size: 1rem; line-height: 1.3; }
.patient-card .code { font-size: .78rem; color: var(--ink-500); font-weight: 600; }
.patient-card .facts { display: flex; gap: .45rem; flex-wrap: wrap; }
.patient-card .foot { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding-top: .8rem; border-top: 1px dashed var(--border); font-size: .8rem; color: var(--ink-500); }
.fact { display: inline-flex; align-items: center; gap: .35rem; font-size: .8rem; color: var(--ink-600); background: var(--ink-100); padding: .22rem .55rem; border-radius: 7px; font-weight: 500; }
.fact .icon { width: 13px; height: 13px; color: var(--ink-400); }

.record-header {
    position: relative; overflow: hidden;
    display: flex; gap: 1.25rem; align-items: center; flex-wrap: wrap;
    padding: 1.35rem 1.5rem; margin-bottom: 1rem;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-xl); box-shadow: var(--shadow-sm);
}
.record-header::before { content: ''; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--gradient); }
.record-header .who { flex: 1; min-width: 220px; }
.record-header .who h2 { font-size: 1.45rem; }
.record-header .facts { margin-top: .5rem; display: flex; gap: .45rem; flex-wrap: wrap; }
.record-header .actions { display: flex; gap: .55rem; flex-wrap: wrap; }

.kv { display: grid; grid-template-columns: minmax(120px, 38%) 1fr; gap: .55rem 1rem; font-size: .9rem; }
.kv dt { color: var(--ink-500); font-weight: 500; }
.kv dd { margin: 0; color: var(--ink-900); font-weight: 600; word-break: break-word; }
.kv-stack { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.kv-stack .k { font-size: .76rem; color: var(--ink-500); font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
.kv-stack .v { font-weight: 600; color: var(--ink-900); margin-top: .15rem; word-break: break-word; }

.item-row { display: flex; gap: .85rem; padding: .9rem 0; border-top: 1px solid var(--border); align-items: flex-start; }
.item-row:first-child { border-top: 0; padding-top: 0; }
.item-row .ico { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; }
.item-row .ico .icon { width: 18px; height: 18px; }
.item-row .body { flex: 1; min-width: 0; }
.item-row .body .t { font-weight: 700; color: var(--ink-900); }
.item-row .body .d { font-size: .86rem; color: var(--ink-600); margin-top: .15rem; white-space: pre-line; }
.item-row .body .m { font-size: .78rem; color: var(--ink-400); margin-top: .3rem; }
.item-row .tools { display: flex; gap: .3rem; flex-shrink: 0; opacity: .7; transition: opacity var(--t); }
.item-row:hover .tools { opacity: 1; }

.med-card { display: flex; gap: .85rem; padding: 1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.med-card .ico { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--cyan-bg); color: var(--cyan-ink); flex-shrink: 0; }
.med-card .name { font-weight: 700; color: var(--ink-900); }
.med-card .dose { font-size: .86rem; color: var(--ink-600); }

/* Consultas en línea de tiempo */
.consult-card { padding: 1.1rem 1.25rem; }
.consult-card .head { display: flex; justify-content: space-between; gap: .75rem; align-items: flex-start; flex-wrap: wrap; }
.consult-card .dx { margin-top: .6rem; display: flex; gap: .4rem; flex-wrap: wrap; }
.consult-card .excerpt { color: var(--ink-600); font-size: .9rem; margin-top: .55rem; }

/* ---------- Documentos ---------- */
.doc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 1rem; }
.doc-card {
    position: relative; display: flex; flex-direction: column;
    border: 1px solid var(--border); border-radius: 14px; overflow: hidden; background: var(--surface);
    transition: transform var(--t), box-shadow var(--t), border-color var(--t); cursor: pointer;
}
.doc-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary-200); }
.doc-thumb { aspect-ratio: 4 / 3; background: var(--ink-100); display: grid; place-items: center; overflow: hidden; position: relative; }
.doc-thumb img { width: 100%; height: 100%; object-fit: cover; }
.doc-thumb .ext { position: absolute; left: .55rem; top: .55rem; }
.doc-thumb .icon { width: 42px; height: 42px; opacity: .55; }
.doc-info { padding: .75rem .85rem .85rem; }
.doc-info .t { font-weight: 700; font-size: .88rem; color: var(--ink-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-info .m { font-size: .76rem; color: var(--ink-500); margin-top: .15rem; display: flex; justify-content: space-between; gap: .4rem; }

.dropzone {
    display: block;
    border: 2px dashed var(--primary-200); border-radius: 16px; background: var(--gradient-soft);
    padding: 1.75rem 1rem; text-align: center; cursor: pointer; transition: all var(--t);
}
.dropzone:hover, .dropzone.dragover { border-color: var(--primary-500); background: var(--primary-50); }
.dropzone .dz-icon { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto .75rem; display: grid; place-items: center; background: #fff; color: var(--primary-600); box-shadow: var(--shadow-sm); }
.dropzone .dz-icon .icon { width: 26px; height: 26px; }
.dropzone strong { display: block; color: var(--ink-900); }
.dropzone p { text-align: center; }
.dropzone p { margin: .35rem 0 0; font-size: .82rem; color: var(--ink-500); }
.upload-list { display: flex; flex-direction: column; gap: .55rem; margin-top: 1rem; }
.upload-item { display: flex; align-items: center; gap: .75rem; padding: .65rem .8rem; border: 1px solid var(--border); border-radius: 12px; }
.upload-item .bar { height: 5px; border-radius: 5px; background: var(--ink-100); overflow: hidden; margin-top: .35rem; }
.upload-item .bar span { display: block; height: 100%; width: 0; background: var(--gradient); transition: width .2s; }
.upload-item.done .bar span { background: var(--green); }
.upload-item.failed .bar span { background: var(--red); }

/* Visor de documentos */
.viewer { position: fixed; inset: 0; z-index: 10000; background: rgba(9, 11, 26, .94); display: none; flex-direction: column; color: #fff; }
.viewer.active { display: flex; animation: fadeIn .2s ease; }
.viewer-bar { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; padding-top: calc(.75rem + env(safe-area-inset-top)); background: rgba(255, 255, 255, .04); border-bottom: 1px solid rgba(255, 255, 255, .08); }
.viewer-bar .title { flex: 1; min-width: 0; }
.viewer-bar .title strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.viewer-bar .title span { font-size: .8rem; color: rgba(255, 255, 255, .6); }
.viewer-bar .btn { --btn-bg: rgba(255, 255, 255, .08); --btn-fg: #fff; --btn-bd: rgba(255, 255, 255, .12); }
.viewer-bar .btn:hover { --btn-bg: rgba(255, 255, 255, .16); }
.viewer-stage { flex: 1; position: relative; overflow: hidden; display: grid; place-items: center; touch-action: none; }
.viewer-stage img { max-width: 100%; max-height: 100%; transform-origin: center; user-select: none; -webkit-user-drag: none; will-change: transform; cursor: grab; }
.viewer-stage img.grabbing { cursor: grabbing; }
.viewer-stage iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.viewer-stage .unsupported { text-align: center; padding: 2rem; }
.pdf-pages { position: absolute; inset: 0; overflow: auto; -webkit-overflow-scrolling: touch; padding: .75rem .5rem 5rem; display: flex; flex-direction: column; align-items: center; gap: .75rem; touch-action: pan-x pan-y pinch-zoom; }
.pdf-page { background: #fff; box-shadow: 0 6px 24px rgba(0, 0, 0, .4); border-radius: 4px; overflow: hidden; }
.pdf-page canvas { display: block; }
.pdf-loading { display: flex; align-items: center; gap: .6rem; margin-top: 30vh; color: rgba(255, 255, 255, .8); }
.viewer-zoom { position: absolute; bottom: calc(1rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; gap: .4rem; background: rgba(0, 0, 0, .55); padding: .35rem; border-radius: 14px; backdrop-filter: blur(8px); }
.viewer-zoom button { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: #fff; cursor: pointer; display: grid; place-items: center; }
.viewer-zoom button:hover { background: rgba(255, 255, 255, .12); }
.viewer-zoom .level { min-width: 56px; display: grid; place-items: center; font-size: .82rem; font-weight: 600; }

/* ==========================================================================
   Calendario
   ========================================================================== */
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); overflow: hidden; display: flex; flex-direction: column; }
.cal-toolbar { display: flex; align-items: center; gap: .75rem; padding: .9rem 1.1rem; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.cal-toolbar .cal-title { font-size: 1.15rem; font-weight: 800; color: var(--ink-900); min-width: 0; flex: 1; }
.cal-toolbar .cal-title::first-letter { text-transform: uppercase; }
.cal-toolbar .nav { display: flex; gap: .35rem; }
.cal-legend { display: flex; gap: .9rem; flex-wrap: wrap; padding: .6rem 1.1rem; border-bottom: 1px solid var(--border); font-size: .76rem; color: var(--ink-500); background: var(--surface-2); }
.cal-legend span { display: inline-flex; align-items: center; gap: .35rem; }
.cal-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* Mes */
.cal-month { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-month .dow { padding: .6rem; font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-500); text-align: center; border-bottom: 1px solid var(--border); background: var(--surface-2); }
.cal-day { min-height: 118px; padding: .45rem; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--t); position: relative; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day:hover { background: var(--surface-2); }
.cal-day.other { background: repeating-linear-gradient(-45deg, transparent 0 6px, rgba(148, 163, 184, .06) 6px 12px); }
.cal-day.other .num { color: var(--ink-300); }
.cal-day.closed { background: var(--ink-50); }
.cal-day .num { font-size: .84rem; font-weight: 700; color: var(--ink-700); width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; }
.cal-day.today .num { background: var(--primary-600); color: #fff; }
.cal-day .dots { display: flex; flex-direction: column; gap: 3px; margin-top: .25rem; }
.cal-day .mini {
    display: flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 600; padding: 2px 6px; border-radius: 6px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; background: var(--primary-50); color: var(--primary-700);
}
.cal-day .more { font-size: .72rem; font-weight: 700; color: var(--ink-500); padding-left: 4px; }
.cal-day .free { position: absolute; right: .45rem; top: .55rem; font-size: .68rem; font-weight: 700; color: var(--green-ink); background: var(--green-bg); padding: 1px 6px; border-radius: 6px; }

/* Semana / día (rejilla horaria) */
.cal-scroller { overflow: auto; max-height: calc(100vh - 250px); max-height: calc(100dvh - 250px); position: relative; -webkit-overflow-scrolling: touch; }
.cal-time { display: grid; grid-template-columns: 64px repeat(var(--days, 7), minmax(120px, 1fr)); min-width: 100%; position: relative; }
.cal-time.days-1 { grid-template-columns: 64px minmax(0, 1fr); }
.cal-head { position: sticky; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--border); padding: .55rem .4rem; text-align: center; }
.cal-head .d { font-size: .72rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-500); }
.cal-head .n { font-size: 1.25rem; font-weight: 800; color: var(--ink-900); line-height: 1.2; }
.cal-head.today .n { color: var(--primary-600); }
.cal-head.today { box-shadow: inset 0 -3px 0 var(--primary-500); }
.cal-head.corner { left: 0; z-index: 7; }
.cal-gutter { position: relative; border-right: 1px solid var(--border); background: var(--surface); }
.cal-gutter .h { position: absolute; right: .5rem; transform: translateY(-50%); font-size: .7rem; font-weight: 600; color: var(--ink-400); white-space: nowrap; }
.cal-col { position: relative; border-right: 1px solid var(--border); cursor: crosshair; }
.cal-col:last-child { border-right: 0; }
.cal-col .line { position: absolute; left: 0; right: 0; border-top: 1px solid var(--border); pointer-events: none; }
.cal-col .line.half { border-top-style: dashed; border-top-color: #eef0f6; }
.cal-off { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(-45deg, rgba(148, 163, 184, .08) 0 6px, rgba(148, 163, 184, .16) 6px 12px); pointer-events: none; }
.cal-block {
    position: absolute; left: 2px; right: 2px; border-radius: 8px; z-index: 2;
    background: repeating-linear-gradient(-45deg, rgba(239, 68, 68, .08) 0 6px, rgba(239, 68, 68, .16) 6px 12px);
    border: 1px dashed rgba(239, 68, 68, .5); color: var(--red-ink); font-size: .72rem; font-weight: 700; padding: 4px 6px; overflow: hidden; cursor: pointer;
}
.cal-hover { position: absolute; left: 3px; right: 3px; border-radius: 8px; background: var(--primary-50); border: 1.5px dashed var(--primary-400); color: var(--primary-700); font-size: .72rem; font-weight: 700; padding: 3px 7px; pointer-events: none; z-index: 1; display: none; }
.cal-col:hover .cal-hover { display: block; }
.cal-event {
    --ev: var(--primary-600);
    position: absolute; left: 3px; right: 3px; z-index: 3;
    border-radius: 9px; padding: 4px 8px; overflow: hidden; cursor: pointer;
    background: color-mix(in srgb, var(--ev) 12%, white);
    border-left: 4px solid var(--ev);
    color: var(--ink-900); font-size: .76rem; line-height: 1.3;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .06);
    transition: box-shadow var(--t), transform var(--t);
    touch-action: none;
}
.cal-event:hover { box-shadow: var(--shadow); z-index: 4; }
.cal-event .t { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event .s { color: var(--ink-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-event.status-pendiente { --ev: var(--amber); }
.cal-event.status-confirmada { --ev: var(--blue); }
.cal-event.status-atendida { --ev: var(--green); }
.cal-event.status-no_asistio { --ev: var(--slate); opacity: .75; }
.cal-event.status-cancelada, .cal-event.status-reprogramada { --ev: var(--ink-300); opacity: .55; text-decoration: line-through; }
.cal-event.dragging { opacity: .85; box-shadow: var(--shadow-lg); z-index: 20; transform: scale(1.02); }
.cal-event.ghost { opacity: .35; }
.cal-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--red); z-index: 5; pointer-events: none; }
.cal-now::before { content: ''; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--red); }

/* Agenda (lista) */
.cal-agenda .ag-day { padding: .6rem 1.1rem; background: var(--surface-2); font-weight: 700; font-size: .82rem; color: var(--ink-600); text-transform: capitalize; border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.cal-agenda .ag-item { display: flex; gap: .85rem; align-items: center; padding: .8rem 1.1rem; border-bottom: 1px solid var(--border); cursor: pointer; }
.cal-agenda .ag-item:hover { background: var(--surface-2); }
.cal-agenda .ag-bar { width: 4px; align-self: stretch; border-radius: 4px; background: var(--primary-500); }
.cal-agenda .ag-slot { display: flex; gap: .85rem; align-items: center; padding: .6rem 1.1rem; border-bottom: 1px dashed var(--border); color: var(--green-ink); font-weight: 600; font-size: .86rem; cursor: pointer; }
.cal-agenda .ag-slot:hover { background: var(--green-bg); }

/* Selector de horarios (slots) */
.slot-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: .45rem; }
.slot {
    height: 40px; border-radius: 10px; border: 1.5px solid var(--border-strong); background: var(--surface);
    font-weight: 700; font-size: .86rem; color: var(--ink-700); cursor: pointer; transition: all var(--t);
}
.slot:hover { border-color: var(--primary-400); color: var(--primary-700); }
.slot.active { background: var(--primary-600); border-color: var(--primary-600); color: #fff; box-shadow: 0 6px 14px -6px rgba(var(--primary-rgb), .6); }
.slot[disabled] { opacity: .35; cursor: not-allowed; text-decoration: line-through; }

/* Horario semanal (configuración) */
.week-schedule { display: flex; flex-direction: column; gap: .75rem; }
.ws-day { display: grid; grid-template-columns: 150px 1fr auto; gap: 1rem; align-items: start; padding: 1rem; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); }
.ws-day.off { background: var(--surface-2); }
.ws-day .ranges { display: flex; flex-direction: column; gap: .5rem; }
.ws-range { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.ws-range .input { width: 130px; }

/* ==========================================================================
   Consulta
   ========================================================================== */
.consult-layout { display: grid; grid-template-columns: 250px minmax(0, 1fr) 320px; gap: 1.25rem; align-items: start; }
.consult-nav { position: sticky; top: calc(var(--topbar-h) + 1rem); }
.consult-nav a { display: flex; align-items: center; gap: .6rem; padding: .6rem .8rem; border-radius: 10px; color: var(--ink-600); font-weight: 600; font-size: .88rem; }
.consult-nav a:hover { background: var(--surface); color: var(--ink-900); }
.consult-nav a.active { background: var(--surface); color: var(--primary-700); box-shadow: var(--shadow-sm); }
.consult-nav a .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-300); margin-left: auto; }
.consult-nav a.filled .dot { background: var(--green); }
.consult-aside { position: sticky; top: calc(var(--topbar-h) + 1rem); display: flex; flex-direction: column; gap: 1rem; }
.section-card { scroll-margin-top: calc(var(--topbar-h) + 1rem); }
.section-card .card-header { cursor: pointer; }
.section-card.collapsed .card-body { display: none; }
.section-card .chev { transition: transform var(--t); color: var(--ink-400); }
.section-card.collapsed .chev { transform: rotate(-90deg); }
.save-state { display: inline-flex; align-items: center; gap: .4rem; font-size: .8rem; font-weight: 600; color: var(--ink-500); }
.save-state.saving { color: var(--amber-ink); }
.save-state.saved { color: var(--green-ink); }
.save-state.error { color: var(--red-ink); }
.locked-banner { display: flex; align-items: center; gap: .75rem; padding: .85rem 1rem; border-radius: 12px; background: var(--slate-bg); color: var(--slate-ink); font-weight: 600; margin-bottom: 1rem; }

/* Rejilla de exploración neurológica */
.exam-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: .86rem; }
.exam-table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-500); font-weight: 700; padding: .45rem; text-align: center; }
.exam-table th:first-child { text-align: left; }
.exam-table td { padding: .3rem; border-top: 1px solid var(--border); }
.exam-table td:first-child { font-weight: 600; color: var(--ink-700); padding-left: .2rem; white-space: nowrap; }
.exam-table select.input { min-height: 36px; padding: .3rem 1.8rem .3rem .55rem; font-size: .85rem; background-position: right .4rem center; background-size: 15px; }

.dx-item { display: flex; align-items: center; gap: .6rem; padding: .6rem .75rem; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); }
.dx-item .code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .8rem; font-weight: 700; color: var(--primary-700); background: var(--primary-50); padding: .15rem .45rem; border-radius: 6px; }

.autocomplete { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 50; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; padding: .3rem; }
.ac-item { padding: .55rem .7rem; border-radius: 8px; cursor: pointer; font-size: .88rem; }
.ac-item:hover, .ac-item.active { background: var(--primary-50); }
.ac-item small { color: var(--ink-500); display: block; }

/* ==========================================================================
   Pizarra corporal
   ========================================================================== */
.bodymap { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 1rem; }
.bodymap-stage-wrap { position: relative; background: radial-gradient(circle at 50% 30%, #ffffff 0%, #f1f4fb 70%); border: 1px solid var(--border); border-radius: 18px; overflow: hidden; }
.bodymap-tools { display: flex; align-items: center; gap: .35rem; padding: .6rem; border-bottom: 1px solid var(--border); background: rgba(255, 255, 255, .8); backdrop-filter: blur(6px); flex-wrap: wrap; }
.bodymap-tools .tool { width: 40px; height: 40px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--ink-600); display: grid; place-items: center; cursor: pointer; transition: all var(--t); }
.bodymap-tools .tool:hover { background: var(--ink-100); }
.bodymap-tools .tool.active { background: var(--primary-600); color: #fff; box-shadow: 0 6px 14px -6px rgba(var(--primary-rgb), .6); }
.bodymap-tools .sep { width: 1px; height: 26px; background: var(--border); margin: 0 .25rem; }
.bodymap-tools .swatch { width: 26px; height: 26px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--border-strong); cursor: pointer; }
.bodymap-tools .swatch.active { box-shadow: 0 0 0 2px var(--ink-900); }
.bodymap-views { display: grid; grid-template-columns: 1fr 1fr; }
.bodymap-view { position: relative; padding: .5rem; }
.bodymap-view .caption { position: absolute; top: .75rem; left: 50%; transform: translateX(-50%); font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-400); background: rgba(255, 255, 255, .8); padding: 2px 10px; border-radius: 99px; }
.bodymap-view svg { width: 100%; height: auto; display: block; touch-action: none; user-select: none; -webkit-user-select: none; }
.bodymap-view + .bodymap-view { border-left: 1px dashed var(--border); }
.bm-silhouette { fill: #e9edf7; stroke: #b8c0d9; stroke-width: 1.2; }
.bm-detail { fill: none; stroke: #c9d0e4; stroke-width: 1; stroke-linecap: round; }
.bm-dermatome { fill-opacity: .0; stroke: var(--primary-300); stroke-width: .6; stroke-dasharray: 2 2; }
.bodymap.show-dermatomes .bm-dermatome { fill-opacity: .10; }
.bm-label { font-size: 5px; fill: var(--primary-500); font-weight: 700; pointer-events: none; opacity: 0; }
.bodymap.show-dermatomes .bm-label { opacity: .9; }
.bm-side { font-size: 9px; font-weight: 800; fill: #94a3b8; }
.bm-marker { cursor: pointer; }
.bodymap-view svg .bm-hit { cursor: crosshair; }
.bodymap[data-editable="0"] .bodymap-view svg { pointer-events: none; }
.bm-marker text { font-size: 7px; font-weight: 800; fill: #fff; pointer-events: none; }
.bm-notes { display: flex; flex-direction: column; gap: .5rem; max-height: 520px; overflow-y: auto; }
.bm-note { display: flex; gap: .6rem; padding: .6rem .7rem; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); align-items: flex-start; }
.bm-note .n { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: .72rem; font-weight: 800; flex-shrink: 0; }
.bm-note textarea { border: 0; padding: 0; resize: none; min-height: 38px; width: 100%; font: inherit; font-size: .86rem; background: transparent; }
.bm-note textarea:focus { outline: none; }

/* ==========================================================================
   Autenticación
   ========================================================================== */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1.1fr 1fr; background: var(--surface); }
.auth-art {
    position: relative; overflow: hidden; color: #fff; padding: 3rem;
    display: flex; flex-direction: column; justify-content: space-between;
    background:
        radial-gradient(90% 70% at 100% 0%, var(--glow-a) 0%, transparent 60%),
        radial-gradient(70% 60% at 0% 100%, var(--glow-b) 0%, transparent 60%),
        var(--auth-bg);
}
.auth-art .brand { display: flex; align-items: center; gap: .85rem; position: relative; z-index: 2; }
.auth-art .brand .brand-mark { width: 48px; height: 48px; }
.auth-art h1 { color: #fff; font-size: clamp(1.8rem, 3vw, 2.6rem); line-height: 1.15; max-width: 520px; letter-spacing: -.02em; position: relative; z-index: 2; }
.auth-art p { color: rgba(255, 255, 255, .78); max-width: 460px; font-size: 1.02rem; position: relative; z-index: 2; }
.auth-art .features { display: grid; gap: .75rem; margin-top: 1.5rem; position: relative; z-index: 2; }
.auth-art .feature { display: flex; gap: .75rem; align-items: center; color: rgba(255, 255, 255, .9); font-weight: 500; }
.auth-art .feature .ico { width: 36px; height: 36px; border-radius: 10px; background: rgba(255, 255, 255, .12); display: grid; place-items: center; backdrop-filter: blur(6px); }
.auth-art .network { position: absolute; inset: 0; width: 100%; height: 100%; opacity: .35; z-index: 1; }
.auth-art .foot { font-size: .8rem; color: rgba(255, 255, 255, .55); position: relative; z-index: 2; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.5rem; padding-bottom: calc(2rem + env(safe-area-inset-bottom)); }
.auth-card { width: 100%; max-width: 410px; }
.auth-card h2 { font-size: 1.75rem; letter-spacing: -.02em; }
.auth-card .lead { color: var(--ink-500); margin: .4rem 0 1.75rem; }
.auth-card .field + .field { margin-top: 1rem; }
.auth-card .mobile-brand { display: none; align-items: center; gap: .7rem; margin-bottom: 2rem; }
.password-toggle { position: absolute; right: .4rem; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; border: 0; background: none; color: var(--ink-400); cursor: pointer; border-radius: 8px; display: grid; place-items: center; }
.password-toggle:hover { color: var(--ink-700); background: var(--ink-100); }
.secure-note { display: flex; align-items: center; gap: .5rem; justify-content: center; margin-top: 1.5rem; font-size: .8rem; color: var(--ink-400); }

/* Instalador / páginas mínimas */
.minimal { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1rem; background: radial-gradient(80% 60% at 50% 0%, var(--primary-100) 0%, var(--bg) 60%); }
.installer { width: 100%; max-width: 860px; }
.installer-head { display: flex; align-items: center; gap: .85rem; margin-bottom: 1.5rem; }
.stepper { display: flex; gap: .4rem; margin-bottom: 1.25rem; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.stepper::-webkit-scrollbar { display: none; }
.step { flex: 1; min-width: 108px; display: flex; flex-direction: column; gap: .45rem; font-size: .76rem; font-weight: 700; color: var(--ink-400); }
.step .bar { height: 5px; border-radius: 5px; background: var(--ink-200); }
.step.done { color: var(--green-ink); }
.step.done .bar { background: var(--green); }
.step.current { color: var(--primary-700); }
.step.current .bar { background: var(--gradient); }
.req-list { display: flex; flex-direction: column; gap: .15rem; }
.req-item { display: flex; align-items: center; gap: .75rem; padding: .6rem .25rem; border-bottom: 1px solid var(--border); font-size: .9rem; }
.req-item:last-child { border-bottom: 0; }
.req-item .state { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.req-item .state .icon { width: 15px; height: 15px; }
.req-item .detail { margin-left: auto; font-size: .8rem; color: var(--ink-500); text-align: right; }

.error-page { text-align: center; max-width: 520px; margin: 3rem auto; }
.error-page .code { font-size: 5rem; font-weight: 800; letter-spacing: -.04em; background: var(--gradient); -webkit-background-clip: text; background-clip: text; color: transparent; line-height: 1; }

/* ==========================================================================
   Utilidades
   ========================================================================== */
.muted { color: var(--ink-500); }
.text-sm { font-size: .86rem; }
.text-xs { font-size: .76rem; }
.text-lg { font-size: 1.1rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.fw-800 { font-weight: 800; }
.text-red { color: var(--red-ink); }
.text-green { color: var(--green-ink); }
.text-amber { color: var(--amber-ink); }
.text-primary { color: var(--primary-600); }
.text-center { text-align: center; }
.text-right { text-align: right; }
.nowrap { white-space: nowrap; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pre { white-space: pre-line; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: .5rem; } .mt-2 { margin-top: 1rem; } .mt-3 { margin-top: 1.5rem; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: .5rem; } .mb-2 { margin-bottom: 1rem; } .mb-3 { margin-bottom: 1.5rem; }
.ml-auto { margin-left: auto; }
.p-0 { padding: 0 !important; }
.w-full { width: 100%; }
.hide-desktop { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; }
.divider-label { display: flex; align-items: center; gap: .75rem; color: var(--ink-400); font-size: .78rem; font-weight: 600; margin: 1rem 0; }
.divider-label::before, .divider-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.pill-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--red); color: #fff; font-size: .7rem; font-weight: 800; }
.progress { height: 8px; border-radius: 8px; background: var(--ink-100); overflow: hidden; }
.progress span { display: block; height: 100%; background: var(--gradient); border-radius: 8px; }
.install-banner { display: flex; align-items: center; gap: .75rem; padding: .75rem 1rem; border-radius: 14px; background: var(--ink-900); color: #fff; margin-bottom: 1rem; }
.install-banner .btn { --btn-bg: #fff; --btn-fg: var(--ink-900); --btn-bd: transparent; }
.offline-bar { position: fixed; left: 50%; bottom: calc(var(--bottom-nav-h) + 1rem + env(safe-area-inset-bottom)); transform: translateX(-50%); background: var(--ink-900); color: #fff; padding: .6rem 1rem; border-radius: 12px; box-shadow: var(--shadow-lg); display: flex; gap: .5rem; align-items: center; z-index: 9990; font-size: .86rem; font-weight: 600; }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1360px) {
    .consult-layout { grid-template-columns: 210px minmax(0, 1fr); }
    .consult-aside { grid-column: 2; position: static; }
}
@media (max-width: 1200px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-main, .grid-main-lg { grid-template-columns: minmax(0, 1fr); }
    .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bodymap { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 1024px) {
    :root { --topbar-h: 60px; }
    .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
    .main { margin-left: 0; }
    .btn.menu-toggle { display: inline-flex; }
    .topbar { padding: 0 1rem; gap: .6rem; }
    .content { padding: 1.1rem 1rem calc(var(--bottom-nav-h) + 1.75rem + env(safe-area-inset-bottom)); }
    .global-search { width: auto; }
    .global-search .search-open-btn { display: inline-flex; }
    .global-search input, .global-search kbd, .global-search .search-ico { display: none; }
    .global-search.open input { display: block; position: fixed; top: calc(8px + env(safe-area-inset-top)); left: 12px; right: 12px; width: auto; height: 48px; z-index: 95; box-shadow: var(--shadow-lg); padding-left: 1rem; }
    .global-search.open .search-results { position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 12px; right: 12px; }
    .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .consult-layout { grid-template-columns: minmax(0, 1fr); }
    .consult-nav { display: none; }
    .consult-aside { grid-column: auto; }

    .bottom-nav {
        display: grid; grid-template-columns: repeat(5, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 50;
        height: calc(var(--bottom-nav-h) + env(safe-area-inset-bottom));
        padding-bottom: env(safe-area-inset-bottom);
        background: rgba(255, 255, 255, .94); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
        border-top: 1px solid var(--border);
    }
    .bottom-nav a, .bottom-nav button {
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
        font-size: .68rem; font-weight: 600; color: var(--ink-500); background: none; border: 0; cursor: pointer;
        -webkit-tap-highlight-color: transparent;
    }
    .bottom-nav .icon { width: 22px; height: 22px; }
    .bottom-nav .active { color: var(--primary-600); }
    .bottom-nav .fab { position: relative; }
    .bottom-nav .fab span.circle { width: 50px; height: 50px; margin-top: -22px; border-radius: 16px; background: var(--gradient); color: #fff; display: grid; place-items: center; box-shadow: 0 10px 20px -8px rgba(var(--primary-rgb), .7); }
    .hide-desktop { display: initial !important; }
    .hide-tablet { display: none !important; }
    .toast-stack { top: auto; bottom: calc(var(--bottom-nav-h) + .75rem + env(safe-area-inset-bottom)); left: 1rem; right: 1rem; align-items: stretch; }
    .toast { max-width: none; min-width: 0; }
    .cal-scroller { max-height: none; }
}
@media (max-width: 720px) {
    body { font-size: 14.5px; }
    .hide-mobile { display: none !important; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .stat { padding: .9rem; gap: .7rem; flex-direction: column; align-items: flex-start; }
    .stat .stat-icon { width: 40px; height: 40px; border-radius: 12px; }
    .stat .stat-value { font-size: 1.4rem; }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: minmax(0, 1fr); }
    .span-2 { grid-column: auto; }
    .form-grid, .form-grid-3, .form-grid-4 { grid-template-columns: minmax(0, 1fr); }
    .page-head { align-items: stretch; }
    .page-head .actions { width: 100%; }
    .page-head .actions .btn { flex: 1; }
    .hero { padding: 1.3rem; border-radius: 18px; }
    .hero h2 { font-size: 1.3rem; }
    .hero-actions { width: 100%; }
    .hero-actions .btn { flex: 1; }
    .card-header { padding: .9rem 1rem; }
    .card-body { padding: 1rem; }
    .list-item { padding: .8rem 1rem; }
    .record-header { padding: 1.1rem; gap: .9rem; }
    .record-header .actions { width: 100%; }
    .record-header .actions .btn, .record-header .actions form { flex: 1; }
    .record-header .actions form .btn { width: 100%; }
    .record-header .actions .dropdown { flex: 0; }
    .kv { grid-template-columns: minmax(0, 1fr); gap: .15rem; }
    .kv dd { margin-bottom: .55rem; }
    .doc-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .7rem; }
    .ws-day { grid-template-columns: minmax(0, 1fr); gap: .6rem; }
    .ws-range .input { width: auto; flex: 1; }
    .scale label { height: 36px; font-size: .8rem; }
    .bodymap-views { grid-template-columns: minmax(0, 1fr); }
    .bodymap-view + .bodymap-view { border-left: 0; border-top: 1px dashed var(--border); }
    .cal-toolbar { gap: .5rem; padding: .75rem; }
    .cal-toolbar .cal-title { order: -1; flex-basis: 100%; font-size: 1.02rem; }
    .cal-toolbar .segmented { flex: 1; }
    .cal-toolbar .segmented button { flex: 1; justify-content: center; padding: .45rem .5rem; }
    .cal-legend { display: none; }
    .cal-day { min-height: 74px; padding: .3rem; }
    .cal-day .mini { display: none; }
    .cal-day .dots { flex-direction: row; flex-wrap: wrap; gap: 3px; }
    .cal-day .dots::after { content: attr(data-count); }
    .cal-day .free { position: static; display: inline-block; margin-top: 2px; }
    .cal-time { grid-template-columns: 50px repeat(var(--days, 7), minmax(110px, 1fr)); }
    .cal-time.days-1 { grid-template-columns: 50px minmax(0, 1fr); }
    .topbar-title h1 { font-size: 1.08rem; }
    .topbar-title .crumbs { display: none; }

    /* Modales como hoja inferior (bottom sheet) en móvil */
    .modal { top: auto; bottom: 0; left: 0; transform: none; width: 100%; max-width: none !important; max-height: 94vh; max-height: 94dvh; border-radius: 22px 22px 0 0; padding-bottom: env(safe-area-inset-bottom); }
    .modal.active { animation: sheetIn .32s var(--ease); }
    .modal-header { padding: 1rem 1.1rem; }
    .modal-body { padding: 1.1rem; }
    .modal-footer { padding: .85rem 1.1rem; }
    .modal-footer .btn { flex: 1; }
    .modal-footer .left { flex-basis: 100%; margin: 0; }
    .modal::before { content: ''; position: absolute; top: 7px; left: 50%; transform: translateX(-50%); width: 40px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .55); z-index: 2; }

    .auth { grid-template-columns: minmax(0, 1fr); }
    .auth-art { display: none; }
    .auth-card .mobile-brand { display: flex; }
    .auth-form { align-items: flex-start; padding-top: 3rem; }
}
@media (hover: none) {
    .btn:hover, .card-hover:hover, a.stat:hover, .doc-card:hover { transform: none; }
    .item-row .tools { opacity: 1; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Impresión ---------- */
@media print {
    .sidebar, .topbar, .bottom-nav, .no-print, .toast-stack { display: none !important; }
    .main { margin: 0; }
    .content { padding: 0; }
    .card { box-shadow: none; border-color: #ddd; }
    body { background: #fff; }
}
