/* ═══════════════════════════════════════════════════════════════════════
   main.css — Shell · Background · Sidebar · Mobile · Print
   Gold on Midnight redesign — Phase 2
   Owns: layout shell, atmospheric background, sidebar chrome, mobile
         drawer, reading-progress bar, TOC rail, doc-nav, print.
   Does NOT own: typography (typography.css), widget cards (components.css)
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Reset supplement ────────────────────────────────────────────────── */

body {
    background: var(--bg);
    color: var(--ink);
    font-family: var(--serif);
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
    position: relative;
}

/* ── Atmospheric background ──────────────────────────────────────────── */
/* Three radial glows (gold top-left, blue top-right, oxblood bottom)
   layered over the base gradient, plus an SVG fractal-noise grain.     */

body::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -2;
    pointer-events: none;
    background:
        radial-gradient(58% 50% at 78% -8%,  rgba(91,134,232,.16),  transparent 60%),
        radial-gradient(50% 46% at  8%  4%,  rgba(216,179,106,.10), transparent 55%),
        radial-gradient(60% 55% at 50% 108%, rgba(143,52,60,.12),   transparent 60%),
        linear-gradient(180deg, var(--bg), var(--bg-2));
}

body::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    opacity: .045;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Page-enter animation (applied to .content-wrapper in theme.css) ── */

@keyframes pageEnter {
    from { opacity: 0; transform: translateY(16px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Shell grid ──────────────────────────────────────────────────────── */

.shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
}

/* ── Reading-progress bar ────────────────────────────────────────────── */
/* Preserved for document.html / base.html — class: #reading-progress-bar */

#reading-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), var(--blue), #a78bfa);
    z-index: 1000;
    transition: width 100ms linear;
    box-shadow: 0 0 8px rgba(216,179,106,.45);
}

/* ── Sidebar ─────────────────────────────────────────────────────────── */
/* Both new-shell <aside> and existing .sidebar class are styled here so
   the current base.html continues to work while it is awaiting a rewrite. */

.sidebar,
aside {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 248px;
    padding: 26px 16px;
    overflow-y: auto;
    overflow-x: hidden;
    border-right: 1px solid var(--hair);
    background: rgba(8,11,20,.50);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 100;
    transition: transform var(--transition-normal);
}

/* Thin scrollbar */
.sidebar::-webkit-scrollbar,
aside::-webkit-scrollbar {
    width: 3px;
}
.sidebar::-webkit-scrollbar-track,
aside::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar::-webkit-scrollbar-thumb,
aside::-webkit-scrollbar-thumb {
    background: rgba(237,240,248,.10);
    border-radius: 2px;
}

/* ── Brand / logo block ──────────────────────────────────────────────── */
/* New shell uses .brand; existing base.html uses .sidebar-header + .logo */

.brand {
    font-family: var(--disp);
    font-weight: 600;
    font-size: 17px;
    letter-spacing: .01em;
    line-height: 1.2;
    padding: 2px 8px 4px;
    color: var(--ink);
}

.brand .crest {
    color: var(--gold);
}

.brand small {
    display: block;
    font-family: var(--mono);
    font-size: 10.5px;
    letter-spacing: .04em;
    color: var(--faint);
    margin-top: 5px;
    font-weight: 400;
}

.brand-rule {
    height: 1px;
    background: linear-gradient(90deg, var(--gold-dim), transparent);
    margin: 14px 6px 6px;
    flex-shrink: 0;
}

/* Existing base.html brand chrome */
.sidebar-header {
    padding: 1.5rem 1.25rem 1.125rem;
    border-bottom: 1px solid var(--hair);
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--ink);
}

.logo svg {
    flex-shrink: 0;
    opacity: .55;
    color: var(--gold);
}

.logo-title {
    display: block;
    font-family: var(--disp);
    font-size: .9375rem;
    font-weight: 600;
    color: var(--ink);
    letter-spacing: -.01em;
}

.logo-subtitle {
    display: block;
    font-family: var(--mono);
    font-size: .6875rem;
    color: var(--faint);
    text-transform: uppercase;
    letter-spacing: .08em;
    margin-top: 2px;
}

/* ── Navigation ──────────────────────────────────────────────────────── */
/* New shell: nav .g, nav a, nav a .d
   Existing base.html: .sidebar-nav, .nav-group, .nav-group-label,
                       .nav-item, .nav-icon, .nav-label, .nav-read-indicator */

/* New-shell group label */
nav .g {
    font-family: var(--mono);
    font-size: 9.5px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--faint);
    margin: 18px 10px 6px;
}

/* New-shell nav link */
nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 9px;
    color: var(--muted);
    text-decoration: none;
    font-size: 13.5px;
    transition: background .15s, color .15s;
}

/* Glowing dot indicator (new shell) */
nav a .d {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--faint);
    flex: none;
    transition: background .15s, box-shadow .15s;
}

nav a:hover {
    background: rgba(216,179,106,.07);
    color: var(--ink);
}

nav a:hover .d {
    background: var(--gold);
    box-shadow: 0 0 8px var(--gold);
}

nav a.on {
    background: linear-gradient(90deg, rgba(216,179,106,.14), transparent);
    color: var(--ink);
}

nav a.on .d {
    background: var(--gold);
    box-shadow: 0 0 8px var(--gold);
}

nav a.thread {
    color: rgba(237,240,248,.74);
}

/* ── Sidebar nav (existing base.html classes) ────────────────────────── */

.sidebar-nav {
    flex: 1;
    padding: .75rem 0;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: .375rem;
}

.nav-group-label {
    padding: .75rem 1.25rem .375rem;
    font-family: var(--mono);
    font-size: .625rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .12em;
    color: var(--faint);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .625rem;
    padding: .5rem 1.25rem;
    color: var(--muted);
    text-decoration: none;
    font-size: .8125rem;
    font-weight: 400;
    border-radius: 9px;
    border-left: 3px solid transparent;
    transition: background var(--transition-fast), color var(--transition-fast);
    position: relative;
}

.nav-item:hover {
    background: rgba(216,179,106,.07);
    color: var(--ink);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(216,179,106,.14), transparent);
    color: var(--ink);
    border-left-color: var(--gold);
    font-weight: 500;
}

.nav-icon {
    flex-shrink: 0;
    opacity: .40;
    display: flex;
    align-items: center;
    transition: opacity var(--transition-fast), color var(--transition-fast);
}

.nav-item:hover .nav-icon {
    opacity: .70;
}

.nav-item.active .nav-icon {
    opacity: 1;
    color: var(--gold);
}

.nav-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.nav-read-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast), transform var(--transition-spring);
}

.nav-read-indicator.read {
    background: #22c55e;
    opacity: 1;
    box-shadow: 0 0 6px rgba(34,197,94,.4);
}

/* ── Sidebar footer ──────────────────────────────────────────────────── */

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--hair);
    flex-shrink: 0;
}

.reading-tracker {
    margin-bottom: .75rem;
}

.reading-tracker-label {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-family: var(--mono);
    font-size: .75rem;
    color: var(--muted);
    margin-bottom: .5rem;
}

.reading-tracker-label svg {
    opacity: .5;
}

.reading-tracker-bar {
    height: 4px;
    background: var(--hair);
    border-radius: 2px;
    overflow: hidden;
}

.reading-tracker-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--gold), #22c55e);
    border-radius: 2px;
    transition: width var(--transition-normal);
}

.reading-tracker.pulse .reading-tracker-fill {
    box-shadow: 0 0 10px rgba(34,197,94,.5);
}

@keyframes trackerPulse {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.02); }
}

.reading-tracker.pulse {
    animation: trackerPulse .5s ease;
}

.sidebar-admin {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--muted);
    text-decoration: none;
    font-family: var(--mono);
    font-size: .75rem;
    padding: .375rem 0;
    margin-bottom: .25rem;
    transition: color var(--transition-fast);
}

.sidebar-admin:hover {
    color: var(--gold);
}

.sidebar-logout {
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--muted);
    text-decoration: none;
    font-family: var(--mono);
    font-size: .75rem;
    padding: .375rem 0;
    transition: color var(--transition-fast);
}

.sidebar-logout:hover {
    color: var(--ink);
}

/* ── Temp-access bar ─────────────────────────────────────────────────── */

.temp-access-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .4rem 1.25rem;
    background: rgba(143,52,60,.85);
    backdrop-filter: blur(6px);
    font-family: var(--mono);
    font-size: .75rem;
    color: var(--ink);
    border-bottom: 1px solid rgba(193,84,92,.4);
}

.temp-access-label {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.temp-timer {
    font-weight: 600;
    letter-spacing: .05em;
}

/* ── Mobile sidebar toggle / overlay ─────────────────────────────────── */
/* These classes are used by the current base.html. The new base.html will
   use the .topbar pattern defined below.                                */

.sidebar-toggle {
    display: none;
    position: fixed;
    top: .75rem;
    left: .75rem;
    z-index: 200;
    width: 42px;
    height: 42px;
    border: none;
    background: var(--bg);
    color: var(--ink);
    border-radius: var(--r);
    cursor: pointer;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--hair);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.60);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 90;
}

/* ── Main content area ────────────────────────────────────────────────── */
/* New shell: <main> inside .shell grid
   Existing base.html: .main-content + .content-wrapper               */

main {
    padding: 0;
    min-height: 100vh;
    max-width: 1040px;
}

.wrap {
    padding: 40px clamp(20px, 5vw, 56px) 80px;
}

.main-content {
    margin-left: var(--sidebar-width, 280px);
    margin-right: var(--right-rail-width, 240px);
    min-height: 100vh;
    padding: 2.5rem 3rem 4rem;
}

.content-wrapper {
    max-width: calc(var(--content-max-width, 72ch) + 6rem);
    margin: 0 auto;
    animation: pageEnter .45s cubic-bezier(.4,0,.2,1);
}

/* ── Right rail (TOC) ─────────────────────────────────────────────────── */
/* Preserved for base.html / document.html                               */

.right-rail {
    position: fixed;
    top: 0;
    right: 0;
    width: var(--right-rail-width, 240px);
    height: 100vh;
    padding: 2rem 1.25rem;
    overflow-y: auto;
    background: transparent;
}

.right-rail::-webkit-scrollbar {
    width: 3px;
}

.right-rail::-webkit-scrollbar-thumb {
    background: var(--hair);
    border-radius: 2px;
}

.toc {
    position: sticky;
    top: 1rem;
}

.toc-title {
    font-family: var(--mono);
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--muted);
    margin-bottom: .75rem;
    padding-bottom: .5rem;
    border-bottom: 1px solid var(--hair);
}

.toc-list {
    list-style: none;
}

.toc-item {
    margin-bottom: 2px;
}

.toc-level-3 {
    padding-left: .875rem;
}

.toc-link {
    display: block;
    padding: .3rem .5rem;
    font-family: var(--mono);
    font-size: .75rem;
    color: var(--muted);
    text-decoration: none;
    border-left: 2px solid transparent;
    border-radius: 0 5px 5px 0;
    transition: all var(--transition-fast);
    line-height: 1.4;
}

.toc-link:hover {
    color: var(--ink);
    background: rgba(216,179,106,.05);
}

.toc-link.active {
    color: var(--gold);
    border-left-color: var(--gold);
    background: rgba(216,179,106,.08);
    font-weight: 500;
}

/* ── Back to top ─────────────────────────────────────────────────────── */

.back-to-top {
    position: fixed;
    bottom: 2rem;
    right: calc(var(--right-rail-width, 240px) + 1rem);
    width: 42px;
    height: 42px;
    border: 1px solid var(--hair);
    background: var(--panel);
    color: var(--muted);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all var(--transition-normal);
}

.back-to-top.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.back-to-top:hover {
    color: var(--gold);
    border-color: var(--line);
    box-shadow: var(--shadow-gold);
    transform: translateY(-2px);
}

/* ── Topbar (new-shell mobile bar, hidden on desktop) ─────────────────── */

.topbar {
    display: none;
}

/* ── Responsive ──────────────────────────────────────────────────────── */

/* At 1400px, hide the right rail so content has room */
@media (max-width: 1400px) {
    .right-rail {
        display: none;
    }
    .main-content {
        margin-right: 0;
    }
    .back-to-top {
        right: 1.5rem;
    }
}

/* At 1024px, collapse sidebar behind the toggle button */
@media (max-width: 1024px) {
    /* Existing-base.html sidebar collapse */
    .sidebar {
        position: fixed;
        transform: translateX(-100%);
        top: 0;
        left: 0;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-toggle {
        display: flex;
    }

    .sidebar-overlay.visible {
        display: block;
    }

    .main-content {
        margin-left: 0;
        padding: 3.5rem 1.5rem 3rem;
    }
}

/* At 880px — new-shell mobile drawer pattern */
@media (max-width: 880px) {
    .shell {
        grid-template-columns: 1fr;
    }

    /* Hide the sidebar in normal flow; show as overlay drawer */
    .shell > aside {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: 200;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }

    /* JS adds .nav-open to <body> to open the drawer */
    body.nav-open .shell > aside {
        display: flex;
        transform: translateX(0);
    }

    /* Scrim behind open drawer */
    body.nav-open::before {
        content: "";
        position: fixed;
        inset: 0;
        z-index: 190;
        background: rgba(0,0,0,.60);
        backdrop-filter: blur(3px);
    }

    /* Topbar: sticky bar that replaces the sidebar on mobile */
    .topbar {
        display: flex;
        align-items: center;
        justify-content: space-between;
        position: sticky;
        top: 0;
        z-index: 5;
        padding: 14px 18px;
        background: rgba(8,11,20,.85);
        backdrop-filter: blur(8px);
        -webkit-backdrop-filter: blur(8px);
        border-bottom: 1px solid var(--hair);
    }

    .topbar .brand {
        padding: 0;
        font-size: 15px;
    }

    .topbar .menu {
        font-family: var(--mono);
        font-size: 12px;
        color: var(--gold);
        border: 1px solid var(--line);
        border-radius: 8px;
        padding: 7px 12px;
        background: transparent;
        cursor: pointer;
        letter-spacing: .02em;
    }

    main {
        max-width: 100%;
    }

    .wrap {
        padding: 24px 18px 60px;
    }
}

@media (max-width: 640px) {
    .main-content {
        padding: 3.5rem 1rem 2rem;
    }

    .wrap {
        padding: 20px 14px 48px;
    }
}

/* ── Print ────────────────────────────────────────────────────────────── */

@media print {
    /* Hide all chrome */
    .sidebar,
    aside,
    .sidebar-toggle,
    .sidebar-overlay,
    .right-rail,
    .back-to-top,
    .topbar,
    .temp-access-bar,
    .nav-group,
    .nav-item,
    .reading-tracker,
    .sidebar-logout,
    .sidebar-admin,
    .document-footer,
    #reading-progress-bar {
        display: none !important;
    }

    /* Restore layout — full width, no margins */
    .shell {
        display: block;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }

    .content-wrapper {
        max-width: 100% !important;
        animation: none !important;
    }

    main {
        max-width: 100% !important;
    }

    .wrap {
        padding: 0 !important;
    }

    /* Ink-on-white adjustments */
    body {
        background: #fff !important;
        color: #111 !important;
    }

    body::before,
    body::after {
        display: none !important;
    }

    .document-body {
        font-family: 'Spectral', Georgia, serif;
        font-size: 11pt;
        line-height: 1.65;
        color: #111;
    }

    .document-body h2 {
        page-break-before: auto;
        margin-top: 1.5rem;
        color: #111;
    }

    .callout-advogado {
        border: 2px solid #b45309 !important;
        background: #fff !important;
        page-break-inside: avoid;
    }

    .table-container {
        overflow: visible !important;
    }

    a.internal-link::after {
        content: " [link]";
        font-size: .8em;
        color: #555;
    }

    /* Don't print the TOC rail */
    .toc,
    .toc-title,
    .toc-list {
        display: none !important;
    }
}
