@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* Capa de refinamiento visual global (apple-design + emil-design-eng).
   Solo CSS, sin cambiar la estructura de las vistas. Se carga desde el sidebar
   y desde las pocas vistas que no lo incluyen. */

:root {
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
    --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
    --ui-shadow-sm: 0 1px 2px rgb(15 23 42 / 0.04), 0 1px 1px rgb(15 23 42 / 0.03);
    --ui-shadow-md: 0 1px 2px rgb(15 23 42 / 0.04), 0 4px 12px -2px rgb(15 23 42 / 0.07);
    --ui-ring: 0 0 0 3px rgb(30 90 153 / 0.18);
}

/* ---- Tipografía: render nítido, tracking según tamaño, cifras alineadas ---- */
html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}
body, .font-display, .font-sans, button, input, select, textarea {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}
body { font-feature-settings: 'cv05', 'ss03'; }
:is(h1, h2, h3, h4, .font-bold, .font-black, .font-extrabold) { font-weight: 650; }
h1.font-black, h1.font-extrabold, h2.font-black, h2.font-extrabold { font-weight: 700; }

h1, h2 { letter-spacing: -0.015em; }
h3, h4 { letter-spacing: -0.01em; }
.uppercase { letter-spacing: 0.04em; }

table, input, .tabular { font-variant-numeric: tabular-nums; }
td, th { font-variant-numeric: tabular-nums; }
th { letter-spacing: 0.03em; }

/* ---- Respuesta inmediata: feedback al presionar ---- */
body :is(button, [role="button"], input[type="submit"], input[type="button"], a.rounded-lg, a.rounded-xl, a.rounded-full, a.rounded):not(:disabled) {
    transition-property: background-color, border-color, color, box-shadow, transform, opacity;
    transition-duration: 160ms;
    transition-timing-function: var(--ease-out);
}
body :is(button, [role="button"], input[type="submit"], input[type="button"], a.rounded-lg, a.rounded-xl, a.rounded-full):not(:disabled):active {
    transform: scale(0.97);
    transition-duration: 100ms;
}
/* Los links del menú lateral y del texto corrido no se encogen */
body :is(.sidebar-link, p a, td a, li a):active { transform: none; }

button:disabled, input:disabled, select:disabled { cursor: not-allowed; }

/* ---- Menú lateral: material y respuesta ---- */
#app-sidebar .sidebar-link {
    transition-property: background-color, color, transform;
    transition-duration: 140ms;
    transition-timing-function: var(--ease-out);
}
#app-sidebar .sidebar-link:active { transform: scale(0.98); }

/* ---- Encabezado: material translúcido con borde suave ---- */
body header.h-16 {
    background-color: rgb(255 255 255 / 0.82);
    -webkit-backdrop-filter: saturate(180%) blur(16px);
    backdrop-filter: saturate(180%) blur(16px);
    border-bottom-color: rgb(15 23 42 / 0.07);
}
.dark body header.h-16, html.dark header.h-16 {
    background-color: rgb(15 23 42 / 0.78);
    border-bottom-color: rgb(255 255 255 / 0.07);
}

/* ---- Tarjetas y superficies ---- */
body :is(section, div, form).rounded-xl.border:not(.shadow-lg):not(.shadow-xl) {
    border-color: rgb(15 23 42 / 0.08);
    box-shadow: var(--ui-shadow-sm);
}
html.dark body :is(section, div, form).rounded-xl.border:not(.shadow-lg):not(.shadow-xl) {
    border-color: rgb(255 255 255 / 0.08);
    box-shadow: none;
}
body :is(section, div, a).rounded-xl.border.hover\:shadow-md,
body a.rounded-xl.border {
    transition: box-shadow 200ms var(--ease-out), transform 200ms var(--ease-out), border-color 200ms var(--ease-out);
}
@media (hover: hover) and (pointer: fine) {
    body a.rounded-xl.border:hover { box-shadow: var(--ui-shadow-md); transform: translateY(-1px); }
}

/* ---- Tablas: encabezado sutil y filas con hover suave ---- */
body table thead th { font-weight: 600; }
body table tbody tr { transition: background-color 120ms ease; }
body table tbody tr:last-child td { border-bottom-width: 0; }

/* ---- Formularios: foco claro y consistente ---- */
body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="file"]) {
    transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}
body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):focus {
    outline: none;
    border-color: #1E5A99;
    box-shadow: var(--ui-ring);
}
body :is(input[type="checkbox"], input[type="radio"]):focus-visible,
body :is(button, a, [role="button"]):focus-visible {
    outline: 2px solid #1E5A99;
    outline-offset: 2px;
}
.sidebar-link:focus-visible { outline-color: rgb(255 255 255 / 0.7); outline-offset: -2px; }

/* ---- Entrada de página: fundido muy breve, sin bloquear nada ---- */
@keyframes ui-page-in {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: none; }
}
body main { animation: ui-page-in 220ms var(--ease-out) both; }

/* ---- Selección y barras de desplazamiento ---- */
::selection { background: rgb(30 90 153 / 0.18); }
* { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }
html.dark * { scrollbar-color: #475569 transparent; }
#sidebar-nav { scrollbar-color: rgb(255 255 255 / 0.2) transparent; }

/* ---- Accesibilidad ---- */
@media (prefers-reduced-motion: reduce) {
    body main { animation: none; }
    body *, body *::before, body *::after {
        transition-duration: 1ms !important;
        animation-duration: 1ms !important;
    }
    body :is(button, a, [role="button"]):active { transform: none !important; }
}
@media (prefers-reduced-transparency: reduce) {
    body header.h-16 { background-color: #fff; -webkit-backdrop-filter: none; backdrop-filter: none; }
    html.dark header.h-16 { background-color: #0f172a; }
}
@media print {
    body main { animation: none; }
    body header.h-16 { backdrop-filter: none; }
}

/* =====================================================================
   Capa 2 — escala tipográfica, paleta, radios y espaciado
   ===================================================================== */

:root {
    --ink: #1d1d1f;          /* texto principal (Apple label) */
    --ink-2: #424a57;        /* texto secundario fuerte */
    --ink-3: #5f6b7a;        /* secundario / etiquetas */
    --ink-4: #7d8897;        /* terciario / placeholders */
    --canvas: #f5f5f7;       /* fondo de la app */
    --hairline: rgb(15 23 42 / 0.08);
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 14px;
}

/* ---- Paleta de texto: más contraste, jerarquía clara ---- */
html:not(.dark) body { background-color: var(--canvas); color: var(--ink); }
html:not(.dark) body :is(.text-slate-900, .text-gray-900, .text-\[\#111418\], .text-\[\#0d141b\]) { color: var(--ink); }
html:not(.dark) body :is(.text-slate-800, .text-gray-800, .text-slate-700, .text-gray-700) { color: var(--ink-2); }
html:not(.dark) body :is(.text-slate-600, .text-gray-600, .text-slate-500, .text-gray-500, .text-\[\#60728a\]) { color: var(--ink-3); }
html:not(.dark) body :is(.text-slate-400, .text-gray-400) { color: var(--ink-4); }
body ::placeholder { color: var(--ink-4); opacity: 1; }

/* ---- Escala tipográfica (tamaño / interlineado / tracking por tamaño) ---- */
body .text-xs   { font-size: 0.75rem;   line-height: 1.125rem; letter-spacing: 0.005em; }
body .text-sm   { font-size: 0.875rem;  line-height: 1.375rem; letter-spacing: -0.003em; }
body .text-base { font-size: 0.9375rem; line-height: 1.5rem;   letter-spacing: -0.006em; }
body .text-lg   { font-size: 1.0625rem; line-height: 1.6rem;   letter-spacing: -0.012em; }
body .text-xl   { font-size: 1.25rem;   line-height: 1.75rem;  letter-spacing: -0.016em; }
body .text-2xl  { font-size: 1.5rem;    line-height: 1.95rem;  letter-spacing: -0.02em; }
body .text-3xl  { font-size: 1.875rem;  line-height: 2.2rem;   letter-spacing: -0.024em; }
body .text-4xl  { font-size: 2.25rem;   line-height: 2.5rem;   letter-spacing: -0.028em; }
/* Etiquetas en mayúsculas: pequeñas pero con aire */
body .uppercase.text-xs, body .uppercase.text-\[10px\], body .uppercase.text-\[11px\] { letter-spacing: 0.06em; }
/* Pesos: menos "pesado", más Apple */
body .font-bold { font-weight: 600; }
body :is(h1, h2).font-bold, body :is(h1, h2).font-black { font-weight: 700; }
body .font-black, body .font-extrabold { font-weight: 700; }
body .font-medium { font-weight: 500; }

/* ---- Radios: esquinas más amplias y consistentes ---- */
body .rounded    { border-radius: var(--radius-sm); }
body .rounded-lg { border-radius: var(--radius-md); }
body .rounded-xl { border-radius: var(--radius-lg); }
body .rounded-2xl { border-radius: 18px; }
body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="color"]) {
    border-radius: var(--radius-md);
}

/* ---- Controles: altura táctil cómoda ---- */
body :is(input, select):not([type="checkbox"]):not([type="radio"]):not([type="file"]):not([type="color"]):not([type="range"]):not(.ts-control) {
    min-height: 2.5rem;
}
body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]) {
    border-color: rgb(15 23 42 / 0.14);
}
body :is(input, select, textarea):not([type="checkbox"]):not([type="radio"]):hover:not(:focus) {
    border-color: rgb(15 23 42 / 0.28);
}
/* Botones primarios: sombra suave y brillo superior (material) */
body button.bg-primary, body a.bg-primary {
    box-shadow: 0 1px 2px rgb(30 90 153 / 0.35), inset 0 1px 0 rgb(255 255 255 / 0.14);
    font-weight: 600;
}
@media (hover: hover) and (pointer: fine) {
    body button.bg-primary:hover, body a.bg-primary:hover { filter: brightness(1.06); }
}

/* ---- Espaciado: contenido con más aire ---- */
body main { padding: 1.5rem; }
@media (min-width: 1024px) { body main { padding: 2rem 2.5rem; } }
body main > div.grid, body main > div.max-w-\[1600px\] { row-gap: 1.75rem; }
body .gap-6 { gap: 1.75rem; }
body .space-y-6 > :not([hidden]) ~ :not([hidden]) { margin-top: 1.75rem; }
body .p-6 { padding: 1.5rem; }
body .p-5 { padding: 1.375rem; }
body .p-8 { padding: 2rem; }

/* ---- Tablas: más respiro y encabezado discreto ---- */
body table th {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--ink-3);
    font-weight: 600;
    padding-top: 0.75rem;
    padding-bottom: 0.75rem;
}
body table td { padding-top: 0.8125rem; padding-bottom: 0.8125rem; }
html:not(.dark) body table thead { background-color: rgb(15 23 42 / 0.025); }
html:not(.dark) body table :is(tbody, thead) tr { border-color: var(--hairline); }
html:not(.dark) body :is(.divide-y, .divide-slate-100, .divide-slate-200, .divide-gray-100, .divide-gray-200) > * + * { border-color: var(--hairline); }
@media (hover: hover) and (pointer: fine) {
    html:not(.dark) body table tbody tr:hover { background-color: rgb(30 90 153 / 0.04); }
}

/* ---- Insignias / etiquetas de estado: más compactas y legibles ---- */
body span.rounded-full.text-xs, body span.rounded-full.text-\[10px\], body span.rounded-full.text-\[11px\] {
    font-weight: 600;
    letter-spacing: 0.01em;
}

/* ---- Menú lateral: texto algo más fino y legible ---- */
#app-sidebar .sidebar-link { padding-top: 0.5625rem; padding-bottom: 0.5625rem; border-radius: var(--radius-md); }
#app-sidebar .sidebar-text { letter-spacing: -0.005em; }
#app-sidebar .sidebar-section-label p { letter-spacing: 0.08em; font-size: 0.6875rem; }

/* =====================================================================
   Capa 3 — Menú lateral claro (estilo Finder / Ajustes de macOS)
   ===================================================================== */
#app-sidebar {
    background-color: #fbfbfd !important;
    border-right: 1px solid var(--hairline);
    box-shadow: none;
}
#app-sidebar > div:first-child {            /* franja del logo */
    background: transparent;
    border-bottom: 0;
    height: 4.5rem;
}
#app-sidebar > div:first-child button { color: var(--ink-4); }
#app-sidebar > div:first-child button:hover { background: rgb(15 23 42 / 0.06); color: var(--ink); }

#sidebar-nav { padding: 0.5rem 0.75rem 1.5rem; gap: 2px; scrollbar-color: rgb(15 23 42 / 0.15) transparent; }
#sidebar-nav::-webkit-scrollbar-thumb { background-color: rgb(15 23 42 / 0.15); }

/* Etiquetas de sección */
#app-sidebar .sidebar-section-label { padding: 1.25rem 0.75rem 0.375rem; }
#app-sidebar .sidebar-section-label p {
    color: var(--ink-4);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.07em;
}

/* Ítems */
#app-sidebar .sidebar-link {
    position: relative;
    color: var(--ink-2);
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    gap: 0.75rem;
    border-radius: var(--radius-md);
}
#app-sidebar .sidebar-link .material-symbols-outlined {
    font-size: 1.375rem;
    color: var(--ink-3);
    transition: color 140ms var(--ease-out);
}
#app-sidebar .sidebar-link-sub { color: var(--ink-3); font-size: 0.8125rem; }
@media (hover: hover) and (pointer: fine) {
    #app-sidebar .sidebar-link:hover { background-color: rgb(15 23 42 / 0.05); color: var(--ink); }
    #app-sidebar .sidebar-link:hover .material-symbols-outlined { color: var(--ink); }
}
/* Activo: tinte de la marca + barra lateral */
#app-sidebar .sidebar-link.bg-white\/20 {
    background-color: rgb(30 90 153 / 0.10);
    color: #1E5A99;
    font-weight: 600;
}
#app-sidebar .sidebar-link.bg-white\/20 .material-symbols-outlined { color: #1E5A99; }
#app-sidebar .sidebar-link.bg-white\/20::before {
    content: '';
    position: absolute;
    left: -0.75rem;
    top: 50%;
    width: 3px;
    height: 1.25rem;
    margin-top: -0.625rem;
    border-radius: 0 3px 3px 0;
    background: #1E5A99;
}
#app-sidebar .sidebar-link:focus-visible { outline: 2px solid #1E5A99; outline-offset: -2px; }

/* Modo oscuro: grafito neutro con acento azul claro */
html.dark #app-sidebar { background-color: #111722 !important; border-right-color: rgb(255 255 255 / 0.06); }
html.dark #app-sidebar > div:first-child { background: #fff; }
html.dark #app-sidebar .sidebar-section-label p { color: rgb(255 255 255 / 0.4); }
html.dark #app-sidebar .sidebar-link { color: rgb(255 255 255 / 0.78); }
html.dark #app-sidebar .sidebar-link .material-symbols-outlined { color: rgb(255 255 255 / 0.6); }
@media (hover: hover) and (pointer: fine) {
    html.dark #app-sidebar .sidebar-link:hover { background-color: rgb(255 255 255 / 0.07); color: #fff; }
    html.dark #app-sidebar .sidebar-link:hover .material-symbols-outlined { color: #fff; }
}
html.dark #app-sidebar .sidebar-link.bg-white\/20 { background-color: rgb(96 165 250 / 0.16); color: #93c5fd; }
html.dark #app-sidebar .sidebar-link.bg-white\/20 .material-symbols-outlined { color: #93c5fd; }
html.dark #app-sidebar .sidebar-link.bg-white\/20::before { background: #60a5fa; }
html.dark #sidebar-nav { scrollbar-color: rgb(255 255 255 / 0.2) transparent; }

/* Colapsado: ícono centrado, la barra queda en el borde */
#app-sidebar.sidebar-collapsed .sidebar-link.bg-white\/20::before { left: -0.75rem; }

/* ---- Subítems: sangría, línea guía y jerarquía visual ---- */
#app-sidebar .sidebar-link.sidebar-link-sub {
    margin-left: 1.625rem;
    padding: 0.375rem 0.625rem 0.375rem 0.75rem;
    gap: 0.5rem;
    font-size: 0.8125rem;
    font-weight: 450;
    color: var(--ink-3);
    border-radius: var(--radius-sm);
}
#app-sidebar .sidebar-link.sidebar-link-sub .material-symbols-outlined {
    font-size: 1.0625rem;
    color: var(--ink-4);
}
/* Línea vertical que une los hijos con el padre */
#app-sidebar .sidebar-link.sidebar-link-sub::after {
    content: '';
    position: absolute;
    left: -0.5rem;
    top: -1px;
    bottom: -1px;
    width: 1px;
    background: rgb(15 23 42 / 0.12);
    pointer-events: none;
}
/* Activo hijo: más liviano que el padre, sin barra lateral */
#app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20 {
    background-color: rgb(30 90 153 / 0.07);
    color: #1E5A99;
    font-weight: 600;
}
#app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20::before { display: none; }
#app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20::after { background: #1E5A99; width: 2px; left: -0.5625rem; }
#app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20 .material-symbols-outlined { color: #1E5A99; }
#app-sidebar.sidebar-collapsed .sidebar-link-sub { display: none !important; }

html.dark #app-sidebar .sidebar-link.sidebar-link-sub { color: rgb(255 255 255 / 0.62); }
html.dark #app-sidebar .sidebar-link.sidebar-link-sub::after { background: rgb(255 255 255 / 0.14); }
html.dark #app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20 { background-color: rgb(96 165 250 / 0.12); color: #93c5fd; }
html.dark #app-sidebar .sidebar-link.sidebar-link-sub.bg-white\/20::after { background: #60a5fa; }

/* ---- Cabecera del menú: logo centrado, botón de colapsar a la derecha ---- */
#app-sidebar > div:first-child { position: relative; justify-content: center; padding: 0 0.75rem; }
#app-sidebar > div:first-child .sidebar-logo { height: 3.5rem; max-width: 11rem; margin: 0 auto; }
#app-sidebar > div:first-child #sidebar-toggle-btn { position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%); }
#app-sidebar > div:first-child #sidebar-toggle-btn:active { transform: translateY(-50%) scale(0.94); }
#app-sidebar.sidebar-collapsed > div:first-child { padding: 0; }
#app-sidebar.sidebar-collapsed > div:first-child #sidebar-toggle-btn { position: static; transform: none; }
