/* ══════════════════════════════════════════════════════════════
   shared.css — Design tokens y componentes comunes
   Contra-Archivo · Colectivo Viento Norte
   Usado por: landing.html, buscador.html, login.html, privado.html, tesis.html
   ══════════════════════════════════════════════════════════════ */

/* ── Tokens ── */
/* Nav legado: ocultar cuando shell unificado inyectó bottom nav */
body.ca-has-bottom-nav > header.site-header,
body.ca-has-bottom-nav > footer.site-footer:not([data-ca-unified-footer]) {
    display: none !important;
}

:root {
    --bg: #0c0c0c;
    --s1: #131313;
    --s2: #1a1a1a;
    --s3: #222222;
    --border: rgba(255, 255, 255, .07);
    --text: #e2e2e2;
    --muted: #888;
    --dim: #8a8a8a;
    --etica: #c8a96e;
    --inst: #4a7fa5;
    --mat: #7a9e6e;
    --crit: #c85f4a;
    --warn: #e8b84b;
    --r: 8px;
    --r-lg: 12px;
    --font-sans: -apple-system, 'Helvetica Neue', sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', monospace;

    /* ── Spacing (4px base) ── */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;

    /* ── Shadows ── */
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,.5);

    /* ── Z-Index ── */
    --z-dropdown: 10;
    --z-sticky: 20;
    --z-overlay: 80;
    --z-drawer: 90;
    --z-nav: 100;

    /* ── Transitions ── */
    --ease: cubic-bezier(.4, 0, .2, 1);
    --dur: .2s;
    --dur-slow: .3s;

    /* ── Touch ── */
    --touch-min: 44px;
}

/* ── Reset ── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-sans);
    font-size: 15px;
    line-height: 1.55;
    overflow-x: hidden;
}

a {
    color: var(--etica);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

button {
    font-family: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
    font-size: inherit;
}

input, select, textarea {
    font-family: inherit;
    font-size: inherit;
    color: var(--text);
    background: var(--s2);
    border: 1px solid var(--border);
    border-radius: var(--r);
    padding: 8px 12px;
    outline: none;
    width: 100%;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--etica);
}

/* ── Scrollbar ── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: var(--s1); }
::-webkit-scrollbar-thumb { background: var(--dim); border-radius: 3px; }

/* ── Skip link ── */
.skip-link {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}
.skip-link:focus {
    position: fixed;
    top: 12px;
    left: 12px;
    width: auto;
    height: auto;
    overflow: visible;
    padding: 10px 18px;
    background: var(--etica);
    color: var(--bg);
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    z-index: 9999;
    outline: 2px solid var(--bg);
    text-decoration: none;
}

/* ── Site Header ── */
.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
}

.site-logo {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text);
    text-decoration: none;
}

.site-logo span {
    color: var(--etica);
}

.site-nav {
    display: flex;
    gap: 20px;
    font-size: 13px;
    align-items: center;
}

.site-nav a {
    color: var(--muted);
    transition: color .2s;
}

.site-nav a:hover {
    color: var(--text);
    text-decoration: none;
}

.site-nav a[aria-current="page"] {
    color: var(--etica);
}

/* ── Nav CTA (call-to-action pill in nav) ── */
.nav-cta {
    background: var(--etica);
    color: #000 !important;
    padding: 5px 14px;
    border-radius: var(--r);
    font-weight: 600;
    text-decoration: none !important;
    transition: background .2s !important;
}

.nav-cta:hover {
    background: #b8966a !important;
    text-decoration: none !important;
}

.nav-cta[aria-current="page"],
.nav-cta[aria-current="page"]:hover {
    background: var(--etica) !important;
    cursor: default;
}

/* ── Site Footer ── */
.site-footer {
    text-align: center;
    padding: 24px;
    border-top: 1px solid var(--border);
    margin-top: auto;
    font-size: 13px;
    color: var(--dim);
}

.site-footer a {
    color: var(--muted);
}

/* ── Badges/Pills ── */
.badge-etica {
    background: rgba(200, 169, 110, .15);
    color: var(--etica);
}

.badge-inst {
    background: rgba(74, 127, 165, .15);
    color: var(--inst);
}

.badge-mat {
    background: rgba(122, 158, 110, .15);
    color: var(--mat);
}

.badge-crit {
    background: rgba(200, 95, 74, .15);
    color: var(--crit);
}

/* Source-specific badge colors */
.badge-infolobby       { background: rgba(200,169,110,.18); color: var(--etica); }
.badge-transparencia   { background: rgba(74,127,165,.18);  color: var(--inst); }
.badge-leychile        { background: rgba(122,158,110,.18); color: var(--mat); }
.badge-seia            { background: rgba(122,158,110,.18); color: var(--mat); }
.badge-compraspublicas { background: rgba(200,95,74,.18);   color: var(--crit); }
.badge-cmf             { background: rgba(74,127,165,.18);  color: var(--inst); }
.badge-bcn             { background: rgba(122,158,110,.18); color: var(--mat); }
.badge-etnografia      { background: rgba(200,169,110,.18); color: var(--etica); }

/* ── Layer chips ── */
.capa-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 10px;
    font-family: var(--font-mono);
    font-weight: 600;
    letter-spacing: .05em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
}

.capa-etica         { background: rgba(200,169,110,.15); color: var(--etica); }
.capa-institucional { background: rgba(74,127,165,.15);  color: var(--inst); }
.capa-material      { background: rgba(122,158,110,.15); color: var(--mat); }

/* ── Search Input (shared) ── */
.search-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--s1);
    border: 1px solid var(--border);
    border-radius: var(--r);
    color: var(--text);
    font-size: 16px;
    transition: border-color .2s, box-shadow .2s;
}

.search-input:focus {
    border-color: var(--etica);
    box-shadow: 0 0 0 3px rgba(200, 169, 110, .15);
}

.search-input::placeholder {
    color: var(--dim);
}

/* ── Friction bar ── */
.friction-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.friction-label {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--dim);
    min-width: 42px;
}

.friction-track {
    flex: 1;
    height: 4px;
    background: var(--s2);
    border-radius: 2px;
    overflow: hidden;
}

.friction-fill {
    height: 100%;
    border-radius: 2px;
    transition: width .3s ease;
}

.friction-value {
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--dim);
    min-width: 28px;
    text-align: right;
}

/* ── Buttons ── */
.btn-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--etica);
    color: #000;
    font-weight: 600;
    font-size: 15px;
    border-radius: var(--r);
    border: none;
    cursor: pointer;
    font-family: inherit;
    transition: background .2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary:hover {
    background: #b8966a;
    text-decoration: none;
}

.btn-primary:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--s2);
    color: var(--text);
    font-size: 13px;
    border-radius: var(--r);
    border: 1px solid var(--border);
    cursor: pointer;
    font-family: inherit;
    transition: background .2s, border-color .2s;
    text-decoration: none;
}

.btn-secondary:hover {
    background: var(--s3);
    border-color: var(--dim);
    text-decoration: none;
}

/* ── Utilities ── */
.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;
}

.hidden { display: none !important; }

/* ── Accessible focus ── */
:focus-visible {
    outline: 2px solid var(--etica);
    outline-offset: 2px;
}

/* ── Hamburger button (visible solo en móvil) ── */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    border-radius: var(--r);
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    color: var(--text);
    flex-shrink: 0;
}

.nav-toggle:focus-visible {
    outline: 2px solid var(--etica);
    outline-offset: 2px;
}

.nav-toggle-bar {
    display: block;
    width: 22px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: transform .2s var(--ease), opacity .2s var(--ease);
    pointer-events: none;
}

/* X cuando abierto */
.nav-open .nav-toggle .nav-toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}
.nav-open .nav-toggle .nav-toggle-bar:nth-child(2) {
    opacity: 0;
}
.nav-open .nav-toggle .nav-toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ── Responsive nav ── */
@media (max-width: 640px) {
    .site-header {
        padding: 12px 16px;
        flex-wrap: wrap;
        gap: 0;
        position: relative;
    }

    .nav-toggle {
        display: flex;
        order: 2;
        margin-left: auto;
    }

    .site-logo {
        order: 1;
    }

    .site-nav {
        order: 3;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
        /* Oculto por defecto */
        max-height: 0;
        overflow: hidden;
        transition: max-height .3s var(--ease), padding .3s var(--ease);
        padding: 0 0;
        border-top: 1px solid transparent;
    }

    /* Abierto */
    .nav-open .site-nav {
        max-height: 320px;
        padding: 10px 0 12px;
        border-top-color: var(--border);
    }

    .site-nav a {
        display: block;
        width: 100%;
        padding: 10px 4px;
        font-size: 14px;
        border-bottom: 1px solid var(--border);
    }

    .site-nav a:last-child {
        border-bottom: none;
    }

    .site-nav a.nav-cta {
        margin-top: 6px;
        border-radius: var(--r);
        padding: 10px 14px;
        border: none;
        width: auto;
        align-self: flex-start;
    }
}

/* ── Unified shell nav (shared-shell.js) ── */
.ca-unified-nav {
    position: sticky;
    top: 0;
    z-index: 4000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    padding: 10px var(--sp-4);
    border-bottom: 1px solid var(--border);
    background: rgba(12, 12, 12, .92);
    backdrop-filter: blur(8px);
    font-family: var(--font-mono);
}

.ca-unified-nav__brand {
    color: var(--etica);
    text-decoration: none;
    font-size: 12px;
    letter-spacing: .08em;
    text-transform: uppercase;
    white-space: nowrap;
    flex-shrink: 0;
}

.ca-unified-nav__links {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.ca-unified-nav__link {
    color: var(--text);
    text-decoration: none;
    padding: 5px var(--sp-2);
    border: 1px solid transparent;
    border-radius: 4px;
    font-size: 11px;
    letter-spacing: .04em;
}

.ca-unified-nav__link:hover,
.ca-unified-nav__link:focus-visible,
.ca-unified-nav__link.is-active {
    border-color: rgba(200, 169, 110, .5);
    color: var(--etica);
    text-decoration: none;
}

.ca-unified-nav__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-shrink: 0;
}

.ca-unified-nav__toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    width: var(--touch-min);
    height: var(--touch-min);
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    flex-shrink: 0;
}

.ca-unified-nav__toggle:focus-visible {
    outline: 2px solid var(--etica);
    outline-offset: 2px;
}

.ca-unified-nav__toggle-bar {
    display: block;
    width: 20px;
    height: 2px;
    background: currentColor;
    border-radius: 2px;
    transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}

.ca-unified-nav.is-open .ca-unified-nav__toggle-bar:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.ca-unified-nav.is-open .ca-unified-nav__toggle-bar:nth-child(2) {
    opacity: 0;
}

.ca-unified-nav.is-open .ca-unified-nav__toggle-bar:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

.ca-unified-footer {
    margin-top: var(--sp-6);
    padding: 14px var(--sp-4);
    border-top: 1px solid var(--border);
    color: var(--dim);
    background: rgba(12, 12, 12, .92);
    font-family: var(--font-mono);
    font-size: 10px;
    letter-spacing: .03em;
    display: flex;
    justify-content: space-between;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.ca-unified-footer a {
    color: var(--etica);
    text-decoration: none;
}

.ca-unified-footer a:hover {
    text-decoration: underline;
}

.ca-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 3900;
    background: rgba(12, 12, 12, .95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(200, 169, 110, .18);
    padding: 4px 6px calc(4px + env(safe-area-inset-bottom));
    justify-content: space-around;
    align-items: stretch;
    gap: 2px;
}

.ca-bottom-nav__link {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1 1 0;
    min-height: var(--touch-min);
    padding: 6px 2px 4px;
    color: var(--dim);
    text-decoration: none;
    font-size: 9px;
    letter-spacing: .04em;
    text-transform: uppercase;
    border-radius: 8px;
    -webkit-tap-highlight-color: transparent;
    position: relative;
}

.ca-bottom-nav__link:active {
    transform: scale(.94);
}

.ca-bottom-nav__icon {
    font-size: 16px;
    line-height: 1;
}

.ca-bottom-nav__link.is-active {
    color: var(--etica);
}

.ca-bottom-nav__link.is-active::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 50%;
    transform: translateX(-50%);
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--etica);
}

body.ca-has-bottom-nav {
    padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

[data-ca-legacy-hidden="true"] {
    display: none !important;
}

@media (max-width: 640px) {
    .ca-unified-nav {
        flex-direction: column;
        align-items: stretch;
    }

    .ca-unified-nav__row {
        width: 100%;
    }

    .ca-unified-nav__toggle {
        display: flex;
    }

    .ca-unified-nav__links {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        border-top: 1px solid var(--border);
        padding-top: var(--sp-2);
    }

    .ca-unified-nav.is-open .ca-unified-nav__links {
        display: flex;
    }

    .ca-unified-nav__link {
        display: block;
        width: 100%;
        padding: 10px 4px;
        border-bottom: 1px solid rgba(255, 255, 255, .08);
    }

    .ca-unified-footer {
        flex-direction: column;
        align-items: flex-start;
    }
}

@media (max-width: 768px) {
    .ca-bottom-nav {
        display: flex;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}
