/* ================================
   Minimal Markdown Docs — style.css
   ================================ */

/* ---------- Theme tokens ---------- */
:root {
    --bg:        #0b0f14;
    --surface:   #111824;
    --border:    #1f2a3a;
    --fg:        #e8eef5;
    --muted:     #9fb3c8;
    --accent:    #4da3ff;
    --accent-2:  #1b2d4a;
    --chip:      #162233;
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.55 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
img { max-width: 100%; display: block; }

/* ---------- Links ---------- */
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.container { max-width: 1000px; margin: 0 auto; padding: 24px; }
.header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 0; border-bottom: 1px solid var(--border);
}
.nav { display: flex; gap: 12px; flex-wrap: wrap; }
.nav a { padding: 4px 0; }

.grid {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 24px;
    margin-top: 16px;
}

/* Cards / surfaces */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}

/* Sidebar */
.sidebar h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); font-weight: 600; }
.sidebar .item {
    display: block; padding: 10px 12px; border-radius: 10px; color: var(--fg);
}
.sidebar .item.active, .sidebar .item:hover { background: var(--chip); }

/* Footer */
.footer { margin-top: 24px; color: var(--muted); font-size: 14px; text-align: center;
    border-top: 1px solid var(--border); padding: 16px 0; }

/* ---------- Buttons & Forms ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 10px 14px; border-radius: 10px;
    border: 1px solid #2a3a55; background: #132034;
    color: var(--fg); cursor: pointer;
}
.btn.primary { background: var(--accent-2); border-color: #28466b; }
.btn:hover { filter: brightness(1.08); }
.no-print { /* utility; hidden in print by CSS below */ }

.input, textarea, select {
    width: 100%; padding: 10px 12px; border-radius: 10px;
    border: 1px solid #2a3a55; background: #0d1522; color: var(--fg);
}
label { display: block; margin: 10px 0 6px; color: var(--muted); }
.form-row { display: grid; gap: 12px; }

/* ---------- Content: headings, text, lists ---------- */
article { font-size: 16px; }
article p { margin: 0 0 1rem; }

article h1, article h2, article h3, article h4, article h5, article h6 {
    font-weight: 700; line-height: 1.25;
    margin-top: 1.25rem; margin-bottom: .75rem;
    display: flex; align-items: center; gap: .5rem; /* for permalink placement */
}

/* Explicit heading scale */
article h1 { font-size: 2rem; }        /* ~32px */
article h2 { font-size: 1.625rem; }    /* ~26px */
article h3 { font-size: 1.375rem; }    /* ~22px */
article h4 { font-size: 1.125rem; }    /* ~18px */
article h5 { font-size: 1rem; }        /* 16px  */
article h6 { font-size: .875rem; }     /* 14px  */

article > h1:first-child,
article > h2:first-child,
article > h3:first-child { margin-top: 0; }

/* Lists */
article ul, article ol { padding-left: 1.25rem; margin: .5rem 0 1rem; }
article li { margin: .25rem 0; }

/* Blockquotes */
article blockquote {
    margin: 1rem 0; padding: .75rem 1rem; border-left: 3px solid var(--accent);
    background: #0e1726; border-radius: 8px; color: #d7e4f2;
}

/* Notices / callouts */
.notice {
    padding: 10px 12px; border-radius: 10px;
    background: #142030; border: 1px solid #2a3a55; margin: 12px 0; color: #cfe1ff;
}
.small { font-size: 12px; color: var(--muted); }

/* ---------- Tables ---------- */
table { border-collapse: collapse; width: 100%; margin: 1rem 0; }
td, th { border: 1px solid #2a3a55; padding: 8px; text-align: left; }
th { background: #0e1726; }

/* ---------- Code blocks ---------- */
/* Let Highlight.js theme control the colors; we just frame the container. */
pre {
    background: #0e1b2c; border: 1px solid #21324e;
    padding: 12px; border-radius: 12px; overflow: auto;
}
pre code { background: transparent; border: none; padding: 0; display: block;}
code { background: #0e1b2c; border: 1px solid #21324e; border-radius: 8px; padding: 2px 6px; }

/* ---------- Heading permalink (CommonMark extension) ---------- */
/* The extension injects <a class="heading-permalink" href="#...">…</a>. Place it at end, show on hover. */
.heading-permalink {
    order: 2;
    visibility: hidden;
    text-decoration: none;
    font-size: .9em;
    color: var(--muted);
    padding: 0 .25rem; border-radius: 6px;
}
article h1:hover .heading-permalink,
article h2:hover .heading-permalink,
article h3:hover .heading-permalink,
article h4:hover .heading-permalink,
article h5:hover .heading-permalink,
article h6:hover .heading-permalink,
article h1:focus-within .heading-permalink,
article h2:focus-within .heading-permalink,
article h3:focus-within .heading-permalink,
article h4:focus-within .heading-permalink,
article h5:focus-within .heading-permalink,
article h6:focus-within .heading-permalink { visibility: visible; }

.heading-permalink:hover { background: #1a2940; }
/* Ensure only one icon (avoid UA glyphs); define the symbol here */
.heading-permalink::before { content: none !important; }
.heading-permalink::after  { content: "¶"; }

/* ---------- Responsiveness ---------- */
@media (max-width: 860px) {
    .grid { grid-template-columns: 1fr; }
}

/* ---------- Print / PDF ---------- */
@media print {
    body { background: #fff; color: #000; }
    .container { max-width: 100%; padding: 0; }
    .header, .sidebar, .nav, .footer, .no-print { display: none !important; }
    .grid { display: block; margin: 0; }
    .card { background: #fff !important; border: none; box-shadow: none; padding: 0; }

    /* Headings black for clarity */
    h1, h2, h3, h4, h5, h6 { color: #000 !important; }

    /* Table borders for print */
    table { border-collapse: collapse; width: 100%; }
    td, th { border: 1px solid #000 !important; color: #000 !important; padding: 4px; }

    /* Code blocks readable on white */
    pre, code { background: #f5f5f5 !important; color: #000 !important; border: 1px solid #ccc !important; }

    /* Footnotes smaller */
    .footnotes { font-size: 0.85em; color: #000; }

    /* Hide permalink icons in print */
    .heading-permalink { display: none !important; }

    /* Show link URLs after text */
    a[href]:after { content: " (" attr(href) ")"; font-size: 0.8em; color: #555; }

    .no-print { display: none !important; }
    /* (optional extra) */
    .attachments { display: none !important; }
}

/* Page size/margins for PDF exports (browsers that honor @page) */
@page { size: A4; margin: 16mm 14mm; }


/* ==== Fix: horizontal scroll for code blocks (no color changes) ==== */

/* Prevent wrapping inside fenced blocks so long lines scroll horizontally */
article pre,
article pre code,
code.hljs {
    white-space: pre !important;      /* no wrapping */
    word-break: normal !important;
    overflow-wrap: normal !important;
}

/* Contain long lines to the code box and show a horizontal scrollbar */
article pre {
    overflow-x: auto !important;
    overflow-y: hidden;               /* avoid double scrollbars */
    max-width: 100%;
}

/* Keep inline code inline (wrapping allowed), only fenced blocks scroll */
article p code,
article li code,
article td code,
article th code {
    white-space: normal !important;   /* allow wrapping for inline snippets */
    display: inline;
}

/* If a theme adds extra padding/background on hljs, preserve container sizing */
article pre code.hljs {
    display: block;
}

/* Optional: avoid layout shift when scrollbar appears */
article pre { scrollbar-gutter: stable both-edges; }

/* === Code blocks: contain width + horizontal scroll, without changing colors === */

/* 1) Allow the grid/card column to actually shrink when children are wide */
.grid, .card, .card * {
    min-width: 0;
}

/* 2) Make fenced code scroll horizontally instead of expanding the layout */
article pre {
    overflow-x: auto !important;  /* show a horizontal scrollbar if needed */
    overflow-y: hidden;           /* avoid double scrollbars */
    max-width: 100%;
    -webkit-overflow-scrolling: touch; /* smooth on trackpads/mobile */
}

/* 3) Keep long lines intact inside fences; inline code still wraps */
article pre code,
code.hljs {
    display: block;
    white-space: pre !important;      /* no wrapping inside fenced blocks */
    word-break: normal !important;
    overflow-wrap: normal !important;
}

/* Inline code (paragraphs, lists, tables) can wrap normally */
article p code,
article li code,
article td code,
article th code {
    white-space: normal !important;
    display: inline;
}

/* (Optional) keep layout stable when the scrollbar appears */
article pre { scrollbar-gutter: stable both-edges; }