/* ============================================================================
   PLANNING · InStyle Group — Sistema de diseño (base)
   Colores muestreados píxel a píxel de la maqueta aprobada ui-instylegroup.png.
   Sin dependencias externas: la CSP es script-src/style-src 'self' (regla 10).
   ============================================================================ */

/* ── 1 · Tokens ─────────────────────────────────────────────────────────── */
:root {
    /* Superficies (muestreadas del área de contenido de la maqueta) */
    --bg:              #FAFAFB;
    --surface:         #FFFFFF;
    --surface-alt:     #F7F8F9;
    --surface-sunken:  #F2F3F5;

    /* Líneas */
    --line:            #ECEEF1;
    --line-strong:     #DFE3E8;

    /* Tinta */
    --ink:             #0F1B2D;
    --ink-2:           #3E4A5A;
    --muted:           #949598;
    --ink-invert:      #FFFFFF;

    /* Marca — sidebar (#1D3349 es el pixel dominante del panel lateral) */
    --sidebar-bg:      #1D3349;
    --sidebar-bg-deep: #16283A;
    --sidebar-line:    rgba(255, 255, 255, .09);
    --sidebar-ink:     #C3CEDA;
    --sidebar-ink-dim: #8A97A6;
    --sidebar-ink-on:  #FFFFFF;
    --sidebar-hover:   rgba(255, 255, 255, .06);

    /* Acento dorado (#B49253 dominante; #968264 el relleno del item activo) */
    --accent:          #B49253;
    --accent-strong:   #96825F;
    --accent-soft:     #D0C0A8;
    --accent-wash:     #F7F2E7;
    --accent-ink:      #7A6231;

    /* Azul profundo de botones y series (muestreado del botón «Personalizar») */
    --navy:            #20374F;
    --navy-hover:      #2A4661;

    /* Semáforo (CLAUDE.md · sell-through verde / amarillo / naranja / rojo) */
    --sem-green:       #207838;
    --sem-green-wash:  #E9F3EC;
    --sem-yellow:      #B08848;
    --sem-yellow-wash: #F9F6EA;
    --sem-orange:      #C0621B;
    --sem-orange-wash: #FBF0E7;
    --sem-red:         #A42320;
    --sem-red-wash:    #FAECEB;
    --sem-neutral:     #5B6878;
    --sem-neutral-wash:#F0F2F5;

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

    --fs-xs:   11px;
    --fs-sm:   12px;
    --fs-base: 13px;
    --fs-md:   14px;
    --fs-lg:   16px;
    --fs-xl:   20px;
    --fs-2xl:  26px;

    --lh-tight: 1.25;
    --lh-base:  1.5;

    /* Espaciado */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-7: 32px;
    --sp-8: 40px;

    /* Radios y sombras */
    --r-sm: 4px;
    --r:    8px;
    --r-lg: 12px;
    --r-pill: 999px;
    --shadow-1: 0 1px 2px rgba(15, 27, 45, .06);
    --shadow-2: 0 6px 20px rgba(15, 27, 45, .10);
    --shadow-3: 0 16px 44px rgba(15, 27, 45, .18);

    /* Layout */
    --sidebar-w: 248px;
    --topbar-h:  56px;
    --z-sidebar: 40;
    --z-topbar:  30;
    --z-drawer:  60;
    --z-flash:   70;
}

/* ── 2 · Reset ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font-sans);
    font-size: var(--fs-base);
    line-height: var(--lh-base);
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6, p, figure, blockquote, dl, dd { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

img, svg { max-width: 100%; vertical-align: middle; }

a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}

/* Utilitarias mínimas — no es un framework, solo lo que el shell necesita */
.oculto { display: none !important; }
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.num { font-variant-numeric: tabular-nums; }
.txt-der { text-align: right; }
.txt-cen { text-align: center; }
.txt-mudo { color: var(--muted); }
.txt-sm { font-size: var(--fs-sm); }
.txt-xs { font-size: var(--fs-xs); }
.nowrap { white-space: nowrap; }

/* ── 3 · Escala tipográfica ─────────────────────────────────────────────── */
.t-pagina  { font-size: var(--fs-xl);  font-weight: 600; line-height: var(--lh-tight); letter-spacing: -.01em; }
.t-seccion { font-size: var(--fs-lg);  font-weight: 600; line-height: var(--lh-tight); }
.t-tarjeta { font-size: var(--fs-md);  font-weight: 600; }
.t-cifra   { font-size: var(--fs-2xl); font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.t-etiqueta {
    font-size: var(--fs-xs); font-weight: 600; letter-spacing: .07em;
    text-transform: uppercase; color: var(--muted);
}

/* ── 4 · Shell ──────────────────────────────────────────────────────────── */
.shell { min-height: 100vh; }

.contenedor-principal {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.contenido {
    flex: 1;
    padding: var(--sp-5) var(--sp-6) var(--sp-8);
    min-width: 0;
}

/* ── 5 · Sidebar ────────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-w);
    z-index: var(--z-sidebar);
    background: var(--sidebar-bg);
    color: var(--sidebar-ink);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-marca {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--sidebar-line);
    flex: 0 0 auto;
}
.sidebar-marca:hover { text-decoration: none; }
.sidebar-marca .marca-logo { width: 30px; height: 30px; flex: 0 0 30px; }
.sidebar-marca .marca-titulo {
    display: block; color: var(--sidebar-ink-on);
    font-size: var(--fs-lg); font-weight: 700; letter-spacing: .16em; line-height: 1.1;
}
.sidebar-marca .marca-sub {
    display: block; color: var(--sidebar-ink-dim);
    font-size: var(--fs-xs); letter-spacing: .04em; margin-top: 2px;
}

.sidebar-nav {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: var(--sp-3) var(--sp-2) var(--sp-4);
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, .18) transparent;
}
.sidebar-nav::-webkit-scrollbar { width: 8px; }
.sidebar-nav::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .16); border-radius: var(--r-pill); }

.nav-grupo + .nav-grupo { margin-top: 2px; }

.nav-titulo {
    padding: var(--sp-4) var(--sp-3) var(--sp-2);
    font-size: var(--fs-xs);
    font-weight: 600;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--sidebar-ink-dim);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    width: 100%;
    padding: 9px var(--sp-3);
    border: 0;
    background: none;
    border-radius: var(--r-sm);
    color: var(--sidebar-ink);
    font-size: var(--fs-base);
    text-align: left;
    line-height: 1.2;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-on); text-decoration: none; }
.nav-item .nav-icono { flex: 0 0 18px; width: 18px; height: 18px; opacity: .85; }
.nav-item .nav-texto { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item .nav-flecha { flex: 0 0 14px; width: 14px; height: 14px; opacity: .55; transition: transform .15s ease; }

.nav-item.activo {
    background: var(--accent-strong);
    color: var(--sidebar-ink-on);
    font-weight: 600;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .10);
}
.nav-item.activo .nav-icono { opacity: 1; }

.nav-grupo.abierto > .nav-item .nav-flecha { transform: rotate(90deg); }
.nav-grupo.abierto > .nav-item { color: var(--sidebar-ink-on); }

.nav-sub { display: none; margin: 2px 0 var(--sp-2); padding-left: 30px; }
.nav-grupo.abierto > .nav-sub { display: block; }

.nav-subitem {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    padding: 6px var(--sp-3);
    border-radius: var(--r-sm);
    color: var(--sidebar-ink);
    font-size: var(--fs-sm);
    opacity: .82;
}
.nav-subitem:hover { background: var(--sidebar-hover); color: var(--sidebar-ink-on); opacity: 1; text-decoration: none; }
.nav-subitem.activo {
    background: var(--accent-strong);
    color: var(--sidebar-ink-on);
    opacity: 1;
    font-weight: 600;
}
.nav-subitem .nav-texto { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebar-pie {
    flex: 0 0 auto;
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--sidebar-line);
    color: var(--sidebar-ink-dim);
    font-size: var(--fs-xs);
}
.sidebar-pie .firma {
    display: block;
    color: var(--accent-soft);
    font-size: var(--fs-md);
    font-style: italic;
    margin-bottom: 2px;
}

/* Toggle móvil */
.sidebar-velo {
    display: none;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: rgba(15, 27, 45, .45);
}

/* ── 6 · Topbar ─────────────────────────────────────────────────────────── */
.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    height: var(--topbar-h);
    padding: 0 var(--sp-6);
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.btn-menu {
    display: none;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border: 1px solid var(--line-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--ink-2);
}

.buscador { position: relative; flex: 1 1 460px; max-width: 460px; min-width: 0; }
.buscador .buscador-icono {
    position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
    width: 15px; height: 15px; color: var(--muted); pointer-events: none;
}
.buscador input {
    width: 100%;
    height: 34px;
    padding: 0 var(--sp-4) 0 32px;
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    background: var(--surface-sunken);
    font-size: var(--fs-base);
}
.buscador input::placeholder { color: var(--muted); }
.buscador input:focus { outline: none; border-color: var(--accent); background: var(--surface); }

.paleta {
    position: absolute;
    top: calc(100% + 6px);
    left: 0; right: 0;
    max-height: 340px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r);
    box-shadow: var(--shadow-2);
    padding: var(--sp-2);
    z-index: var(--z-drawer);
}
.paleta-item {
    display: flex; align-items: baseline; gap: var(--sp-2);
    padding: 7px var(--sp-3);
    border-radius: var(--r-sm);
    color: var(--ink);
}
.paleta-item:hover, .paleta-item.marcado { background: var(--surface-sunken); text-decoration: none; }
.paleta-item .paleta-ruta { color: var(--muted); font-size: var(--fs-xs); margin-left: auto; }
.paleta-vacio { padding: var(--sp-4); color: var(--muted); text-align: center; }

.topbar-derecha { display: flex; align-items: center; gap: var(--sp-2); margin-left: auto; }

.btn-icono {
    position: relative;
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px;
    border: 0; border-radius: var(--r-sm);
    background: none; color: var(--ink-2);
}
.btn-icono:hover { background: var(--surface-sunken); color: var(--ink); }
.btn-icono .punto {
    position: absolute; top: 5px; right: 5px;
    min-width: 15px; height: 15px; padding: 0 3px;
    border-radius: var(--r-pill);
    background: var(--sem-red); color: #fff;
    font-size: 9px; font-weight: 700; line-height: 15px; text-align: center;
}

.menu-ancla,
.menu-usuario { position: relative; }
.usuario-boton {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: 4px 8px 4px 4px;
    border: 0; border-radius: var(--r-pill);
    background: none;
}
.usuario-boton:hover { background: var(--surface-sunken); }
.usuario-avatar {
    display: flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--navy); color: #fff;
    font-size: var(--fs-sm); font-weight: 700;
}
.usuario-datos { text-align: left; line-height: 1.15; }
.usuario-nombre { display: block; font-size: var(--fs-base); font-weight: 600; }
.usuario-rol { display: block; font-size: var(--fs-xs); color: var(--muted); }

.menu-flotante {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 210px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--r);
    box-shadow: var(--shadow-2);
    padding: var(--sp-2);
    z-index: var(--z-drawer);
}
.menu-flotante a,
.menu-flotante button {
    display: flex; align-items: center; gap: var(--sp-2);
    width: 100%;
    padding: 8px var(--sp-3);
    border: 0; border-radius: var(--r-sm);
    background: none; color: var(--ink);
    font-size: var(--fs-base); text-align: left;
}
.menu-flotante a:hover, .menu-flotante button:hover { background: var(--surface-sunken); text-decoration: none; }
.menu-flotante .separador { height: 1px; margin: var(--sp-2) 0; background: var(--line); }
.menu-flotante .encabezado { padding: var(--sp-2) var(--sp-3); color: var(--muted); font-size: var(--fs-xs); }

/* ── 7 · Encabezado de página y breadcrumb ──────────────────────────────── */
.migas {
    display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
    margin-bottom: var(--sp-2);
    font-size: var(--fs-sm); color: var(--muted);
}
.migas a { color: var(--muted); }
.migas a:hover { color: var(--ink-2); }
.migas .sep { opacity: .6; }
.migas .actual { color: var(--ink-2); font-weight: 600; }

.encabezado-pagina {
    display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--sp-4);
    margin-bottom: var(--sp-5);
}
.encabezado-pagina .titulo-bloque { flex: 1 1 320px; min-width: 0; }
.encabezado-pagina .subtitulo { margin-top: 2px; color: var(--muted); font-size: var(--fs-base); }
.encabezado-pagina .acciones { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }

/* ── 8 · Login ──────────────────────────────────────────────────────────── */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--sp-6);
    background: var(--sidebar-bg);
}
.auth-caja { width: 100%; max-width: 400px; }
.auth-marca { text-align: center; margin-bottom: var(--sp-6); }
.auth-marca svg { width: 52px; height: 52px; }
.auth-marca .marca-titulo {
    display: block; margin-top: var(--sp-3);
    color: #fff; font-size: var(--fs-xl); font-weight: 700; letter-spacing: .18em;
}
.auth-marca .marca-sub { display: block; margin-top: 2px; color: var(--accent-soft); font-size: var(--fs-sm); letter-spacing: .05em; }

.auth-tarjeta {
    background: var(--surface);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-3);
    padding: var(--sp-7) var(--sp-6);
}
.auth-tarjeta h1 { font-size: var(--fs-lg); font-weight: 600; margin-bottom: var(--sp-1); }
.auth-tarjeta .auth-ayuda { color: var(--muted); font-size: var(--fs-sm); margin-bottom: var(--sp-5); }
.auth-pie { margin-top: var(--sp-5); text-align: center; color: rgba(255, 255, 255, .55); font-size: var(--fs-xs); }

/* ── 9 · Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform .2s ease;
        box-shadow: var(--shadow-3);
    }
    body.sidebar-abierta .sidebar { transform: translateX(0); }
    body.sidebar-abierta .sidebar-velo { display: block; }
    .contenedor-principal { margin-left: 0; }
    .btn-menu { display: inline-flex; }
    .topbar { padding: 0 var(--sp-4); gap: var(--sp-3); }
    .contenido { padding: var(--sp-4) var(--sp-4) var(--sp-8); }
}

@media (max-width: 900px) {
    .topbar .chip-alcance { display: none; }
}

@media (max-width: 640px) {
    .usuario-datos { display: none; }
    .buscador { flex: 1 1 auto; max-width: none; }
    .encabezado-pagina { gap: var(--sp-3); }
    .encabezado-pagina .acciones { width: 100%; }
}

/* ── 10 · Impresión ─────────────────────────────────────────────────────── */
@media print {
    .sidebar, .topbar, .sidebar-velo, .flash-zona, .no-imprimir { display: none !important; }
    .contenedor-principal { margin-left: 0; }
    body { background: #fff; }
}
