/* mobile.css — Shared responsive + mobile fixes for magic.threadsync.io
   Matches www.threadsync.io header/footer/mobile patterns
   ONE header strategy: position:sticky, in document flow, no offset hacks */

/* ===== PAGE SHELL — sticky footer on short pages ===== */
/* Every page: <div class="page"> wraps header + main + footer.
   flex column + min-height:100vh pushes footer to bottom. */
.page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

#content {
    flex: 1 0 auto;
}

footer, #site-footer {
    flex-shrink: 0;
}

/* ===== GLOBAL MOBILE SAFETY LAYER ===== */

/* iOS Safari text-size fix */
html {
    -webkit-text-size-adjust: 100%;
}

/* Prevent mystery horizontal scroll on any structural element */
main, header, footer {
    max-width: 100%;
    overflow-x: clip;
}

/* Images / media never blow out the viewport */
img, svg, video, canvas {
    max-width: 100%;
    height: auto;
}

/* Text wrapping — long words/URLs/hashes don't force viewport wider */
p, li, dd, figcaption {
    overflow-wrap: anywhere;
}

/* ===== Inline code wrapping (SHA256 hashes, long strings) ===== */
:not(pre) > code {
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* ===== Code blocks: horizontal scroll, never wrap ===== */
pre {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
}
pre code {
    white-space: pre;
    overflow-wrap: normal;
    word-break: normal;
}

/* ===== TABLE SCROLL CONTAINERS ===== */
/* JS wraps tables in .table-scroll; CSS makes them horizontally scrollable */
.table-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1em;
}
.table-scroll table {
    width: 100%;
    border-collapse: collapse;
}

/* ===== HEADER — single sticky container, no offset hacks ===== */
/* All tiers (nav row + optional sub-row) live inside one <header>.
   position:sticky keeps it in document flow — content starts after
   the header naturally, regardless of how tall it is. */

.header, header {
    position: sticky !important;
    top: 0;
    width: 100%;
    z-index: 150;
    background: rgba(14, 14, 18, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: env(safe-area-inset-top);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
    gap: 16px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 24px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    flex-shrink: 0;
}
.logo img, .logo .logo-img {
    height: 36px;
    width: auto;
    max-width: none;
}

.nav {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}
.nav a {
    color: var(--text-muted, #71717a);
    font-weight: 600;
    font-size: 0.875rem;
    padding: 8px 10px;
    border-radius: 8px;
    text-decoration: none;
    border: 1px solid transparent;
    transition: color 0.2s, background 0.2s, border-color 0.2s;
}
.nav a:hover {
    color: var(--text, #e4e4e7);
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.10);
}

/* ===== ENTERPRISE STRIP (sub-row inside header, homepage only) ===== */
/* Strip is inside header — only needs a top separator line, not a bottom border
   (the header's own border-bottom handles the bottom edge) */
.enterprise-strip {
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    margin-top: 0 !important;
    padding: 6px 0 !important; /* Override inline padding to prevent doubling */
}

/* ===== MOBILE TOGGLE — matches ts-mobile-toggle pattern ===== */

.mobile-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 10px;
    color: var(--text, #e4e4e7);
    cursor: pointer;
    font-size: 0;
    transition: background 0.2s;
}
.mobile-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.22);
}

/* ===== MOBILE NAV PANEL ===== */
/* Inside the sticky header — flows below nav row naturally */

.mobile-nav {
    border-top: 1px solid var(--border, #1e1e28);
    border-bottom: 1px solid var(--border, #1e1e28);
    background: rgba(8, 8, 10, 0.98);
}
.mobile-nav[hidden] {
    display: none;
}
.mobile-nav-inner {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 24px 18px;
    max-width: 1100px;
    margin: 0 auto;
}
.mobile-nav-inner a {
    display: block;
    padding: 12px 12px;
    border-radius: 10px;
    color: var(--text, #e4e4e7);
    border: 1px solid rgba(255, 255, 255, 0.08);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    min-height: 44px;
    transition: background 0.2s;
}
.mobile-nav-inner a:hover {
    background: rgba(255, 255, 255, 0.06);
}

/* ===== ANCHOR SCROLL-MARGIN ===== */
/* Works with sticky header — no hardcoded px, uses a comfortable offset */
h1[id], h2[id], h3[id], h4[id],
section[id], div[id],
[id].section-title, [id].card {
    scroll-margin-top: 80px;
}

/* Also set scroll-padding-top on html for find-in-page / URL hash navigation */
html {
    scroll-padding-top: 80px;
}

/* ===== FOOTER — match ts footer__ BEM pattern ===== */
/* Single source of truth for footer layout. No inline footer CSS on pages. */

footer {
    border-top: 1px solid var(--border, #1e1e28);
    background: rgba(14, 14, 18, 0.55);
    padding-bottom: env(safe-area-inset-bottom);
    flex-shrink: 0;
}

.footer__top {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1fr;
    gap: 32px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 48px 24px;
}

.footer__brand {
    max-width: 320px;
}
/* Footer logo: height-driven sizing prevents CLS / height jitter.
   width:auto + max-width:none override the global img constraint
   so the logo keeps its natural aspect ratio at exactly 24px tall. */
.footer__brand img {
    height: 24px;
    width: auto;
    max-width: none;
    margin-bottom: 8px;
    opacity: 0.85;
}
.footer__tagline {
    color: var(--text-muted, #71717a);
    font-size: 0.875rem;
    line-height: 1.5;
    margin-top: 4px;
}

.footer__col h3 {
    color: var(--text, #e4e4e7);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}
.footer__col a {
    display: block;
    color: var(--text-muted, #71717a);
    text-decoration: none;
    padding: 4px 0;
    font-size: 0.875rem;
    font-weight: 500;
    transition: color 0.2s;
}
.footer__col a:hover {
    color: var(--text, #e4e4e7);
}
.footer__meta {
    margin-top: 12px;
    font-size: 0.8rem;
    color: var(--text-dim, #52525b);
}
.footer__meta a {
    display: inline;
    padding: 0;
    font-size: 0.8rem;
}

.footer__bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    max-width: 1100px;
    margin: 0 auto;
    padding: 18px 24px;
    border-top: 1px solid var(--border, #1e1e28);
    font-size: 0.8rem;
    color: var(--text-dim, #52525b);
}
.footer__bottom strong {
    color: var(--text-muted, #71717a);
}
.footer__sep {
    margin: 0 6px;
    opacity: 0.4;
}

/* ===== Touch targets — 44px minimum ===== */
a, button, .mobile-toggle,
input[type="submit"], input[type="button"] {
    min-height: 44px;
}
/* Don't force min-height on inline text links */
p a, li a, td a, span a, .footer__col a, .footer__meta a, .footer__bottom a,
.enterprise-strip a, .nav a {
    min-height: auto;
}

/* ===== MOBILE BREAKPOINT (≤ 900px — matches threadsync.io) ===== */
@media (max-width: 900px) {
    .nav { display: none; }
    .mobile-toggle { display: inline-flex; }

    /* Footer: 2-col on tablet */
    .footer__top {
        grid-template-columns: 1fr 1fr;
    }
}

@media (max-width: 768px) {
    /* Code blocks: tighter on mobile */
    .code-body {
        padding: 12px !important;
    }
    .code-body pre code, pre code {
        font-size: 12px !important;
    }
    .code-header {
        font-size: 12px !important;
        padding: 8px 12px !important;
    }

    /* Typography scaling */
    h1 { font-size: 28px !important; line-height: 1.2 !important; }
    h2 { font-size: 22px !important; }
    h3 { font-size: 18px !important; }

    /* Section padding */
    section, .section {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* Enterprise strip on index: horizontal scroll */
    .enterprise-strip-inner {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        flex-wrap: nowrap !important;
        justify-content: flex-start !important;
        gap: 12px !important;
        padding: 0 16px !important;
    }
    .enterprise-strip-inner a {
        white-space: nowrap;
        font-size: 12px !important;
    }

    /* Reduce scroll-margin for smaller header on mobile */
    h1[id], h2[id], h3[id], h4[id],
    section[id], div[id] {
        scroll-margin-top: 70px;
    }
    html {
        scroll-padding-top: 70px;
    }
}

@media (max-width: 600px) {
    /* Footer: single column on phone */
    .footer__top {
        grid-template-columns: 1fr;
    }
    .footer__bottom {
        flex-direction: column;
        text-align: center;
    }
}

/* ===== SMALL PHONE (iPhone SE) ===== */
@media (max-width: 375px) {
    h1 { font-size: 24px !important; }
    h2 { font-size: 20px !important; }
    .code-body pre code, pre code { font-size: 11px !important; }
    table th, table td {
        padding: 8px 10px !important;
        font-size: 12px !important;
    }
}
