@charset "UTF-8";

/* Styles for PSPs - based on Python PEPs theme */

/* CSS-based theme toggle system */
:root {
    /* Light theme colors (default) */
    --colour-background: white;
    --colour-background-accent-strong: #ccc;
    --colour-background-accent-medium: #ddd;
    --colour-background-accent-light: #eee;
    --colour-text: #333;
    --colour-text-strong: #222;
    --colour-links: #1f2937;
    --colour-links-light: #374151;
    --colour-scrollbar: #ccc;
    --colour-rule-strong: #888;
    --colour-rule-light: #ddd;
    --colour-inline-code-bg: #eee;
    --colour-inline-code-text: #222;
    --colour-error: #faa;
    --colour-warning: #fca;
    --colour-caution: #ffa;
    --colour-attention: #bdf;
    --colour-tip: #bfc;
}

/* Dark theme colors when checkbox is checked OR when initial dark class is present */
body:has(.theme-toggle-input:checked),
html.theme-dark-initial body {
    --colour-background: #111;
    --colour-background-accent-strong: #444;
    --colour-background-accent-medium: #333;
    --colour-background-accent-light: #222;
    --colour-text: #ccc;
    --colour-text-strong: #ddd;
    --colour-links: #60a5fa;
    --colour-links-light: #93c5fd;
    --colour-scrollbar: #333;
    --colour-rule-strong: #777;
    --colour-rule-light: #222;
    --colour-inline-code-bg: #333;
    --colour-inline-code-text: #ccc;
    --colour-error: #800;
    --colour-warning: #840;
    --colour-caution: #550;
    --colour-attention: #045;
    --colour-tip: #041;
}

/* Fallback for browsers without :has() support - use @media prefers-color-scheme */
@media (prefers-color-scheme: dark) {
    :root:not(:has(.theme-toggle-input)) {
        --colour-background: #111;
        --colour-background-accent-strong: #444;
        --colour-background-accent-medium: #333;
        --colour-background-accent-light: #222;
        --colour-text: #ccc;
        --colour-text-strong: #ddd;
        --colour-links: #60a5fa;
        --colour-links-light: #93c5fd;
        --colour-scrollbar: #333;
        --colour-rule-strong: #777;
        --colour-rule-light: #222;
        --colour-inline-code-bg: #333;
        --colour-inline-code-text: #ccc;
        --colour-error: #800;
        --colour-warning: #840;
        --colour-caution: #550;
        --colour-attention: #045;
        --colour-tip: #041;
    }
}

/* Theme toggle button styling */
.theme-toggle-input {
    display: none;
}

.theme-toggle-label {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: 1px solid var(--colour-rule-light);
    color: var(--colour-text);
    cursor: pointer;
    padding: 0.4rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    min-height: 2rem;
}

.theme-toggle-label:hover {
    background: var(--colour-background-accent-medium);
    border-color: var(--colour-rule-strong);
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.theme-toggle-label:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Icon display logic */
.theme-icon {
    color: var(--colour-text);
    height: 1rem;
    width: 1rem;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    display: none;
}

.theme-icon-light {
    fill: currentColor;
}

/* Show light icon when in light theme (checkbox unchecked and no initial dark class) */
.theme-toggle-input:not(:checked) + .theme-toggle-label .theme-icon-light {
    display: block;
}

html.theme-dark-initial .theme-toggle-input:not(:checked) + .theme-toggle-label .theme-icon-light {
    display: none;
}

/* Show dark icon when in dark theme (checkbox checked OR initial dark class) */
.theme-toggle-input:checked + .theme-toggle-label .theme-icon-dark,
html.theme-dark-initial .theme-toggle-input:not(:checked) + .theme-toggle-label .theme-icon-dark {
    display: block;
}

img.invert-in-dark-mode {
    transition: filter 0.2s ease;
}

body:has(.theme-toggle-input:checked) img.invert-in-dark-mode,
html.theme-dark-initial body img.invert-in-dark-mode {
    filter: invert(1) hue-rotate(.5turn);
}

/* Set master rules */
* {box-sizing: border-box}
:root {color-scheme: light dark}
html {
    overflow-y: scroll;
    line-height: 1.5;
    font-size: 1rem;
    font-family: -apple-system, BlinkMacSystemFont, avenir next, avenir, segoe ui, helvetica neue, helvetica, Cantarell, Ubuntu, roboto, noto, arial, sans-serif;
}
body {
    margin: 0;
    color: var(--colour-text);
    background-color: var(--colour-background);
}
section#psp-page-section {
    padding: 0.25rem;
}

/* This is likely very close to the browser default, but we make it a variable
 * so it can be used in other rules. */
:root {
    --paragraph-margin-vertical: 1em;
}
p {
    margin: var(--paragraph-margin-vertical) 0;
}

/* Header rules */
h1 {
    font-size: 2rem;
    font-weight: bold;
}
h2 {
    font-size: 1.6rem;
    font-weight: bold;
}
h3 {
    font-size: 1.4rem;
    font-weight: normal;
}
h4 {
    font-size: 1.2rem;
    font-weight: normal;
}
h5,
h6 {
    font-size: 1rem;
    font-weight: bold;
}

/* Anchor link rules */
a,
a:active,
a:visited {
    color: var(--colour-links);
    text-decoration: underline;
    display: inline;
    overflow-wrap: anywhere;
    text-decoration-color: var(--colour-background-accent-strong);
}
a:hover,
a:focus {
    text-decoration-color: var(--colour-rule-strong);
}

/* Breadcrumbs rules */
section#psp-page-section > header {
    border-bottom: 1px solid var(--colour-rule-light);
    position: relative;
}
section#psp-page-section > header > h1 {
    font-size: 1.1rem;
    margin: 0;
    display: inline-block;
    padding-right: .6rem;
    border-right: 1px solid var(--colour-rule-strong);
}
ul.breadcrumbs {
    margin: 0;
    padding: .5rem 0 .5rem .4rem;
    list-style: none;
    display: inline-block;
}
ul.breadcrumbs li {
    display: inline;
}
ul.breadcrumbs a {
    text-decoration: none;
}

/* Layout structure */
.psp-layout {
    display: flex;
    min-height: calc(100vh - 4rem);
    gap: 0;
}

#psp-sidebar {
    width: 280px;
    flex-shrink: 0;
    background-color: var(--colour-background-accent-light);
    border-right: 1px solid var(--colour-rule-light);
    padding: 1.5rem 1rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    box-shadow: 1px 0 3px rgba(0, 0, 0, 0.1);
}

#psp-content {
    flex: 1;
    padding: 2rem 3rem;
    max-width: calc(100% - 280px);
    overflow-x: auto;
    line-height: 1.6;
}

/* Improve main content typography */
#psp-content h1 {
    margin-top: 0;
    margin-bottom: 1.5rem;
    color: var(--colour-text-strong);
    border-bottom: 2px solid var(--colour-rule-light);
    padding-bottom: 0.5rem;
}

#psp-content h2 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    color: var(--colour-text-strong);
    border-bottom: 1px solid var(--colour-rule-light);
    padding-bottom: 0.25rem;
}

#psp-content h3,
#psp-content h4,
#psp-content h5,
#psp-content h6 {
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--colour-text-strong);
}

/* Sidebar TOC styling */
.toc-container {
    flex: 1;
}

.toc-container .toc-title {
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: var(--colour-text-strong);
    border-bottom: 1px solid var(--colour-rule-light);
    padding-bottom: 0.5rem;
}

.toc-container .toc-content {
    font-size: 0.9rem;
}

.toc-container .toc-content ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc-container .toc-content li {
    margin: 0.2rem 0;
    padding-left: 0;
}

.toc-container .toc-content a {
    text-decoration: none;
    color: var(--colour-links);
    padding: 0.3rem 0.5rem;
    display: block;
    border-radius: 4px;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.toc-container .toc-content a:hover {
    background-color: var(--colour-background-accent-medium);
    text-decoration: none;
    border-left-color: var(--colour-links);
    transform: translateX(2px);
}

.toc-container .toc-content a:focus {
    outline: 2px solid var(--colour-links);
    outline-offset: 2px;
}

/* Current page indicator */
.toc-container .toc-content a[href="#"] {
    background-color: var(--colour-background-accent-medium);
    border-left-color: var(--colour-links);
    font-weight: 600;
}

/* Nested TOC levels */
.toc-container .toc-content ul ul {
    margin-left: 1rem;
    margin-top: 0.2rem;
    border-left: 1px solid var(--colour-rule-light);
    padding-left: 0.5rem;
}

.toc-container .toc-content ul ul li {
    font-size: 0.85rem;
}

.toc-container .toc-content ul ul a {
    padding: 0.2rem 0.5rem;
    color: var(--colour-links-light);
}

/* Sidebar bottom section */
.sidebar-bottom {
    margin-top: auto;
    padding-top: 1rem;
    border-top: 1px solid var(--colour-rule-light);
}

.sidebar-bottom a {
    font-size: 0.8rem;
    color: var(--colour-links-light);
    text-decoration: none;
}

.sidebar-bottom a:hover {
    text-decoration: underline;
}

/* Table rules */
.table-wrapper {
    overflow-x: auto;
    margin: 1rem 0;
    border-radius: 4px;
    border: 1px solid var(--colour-background-accent-strong);
}

table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.9rem;
}
table th,
table td {
    text-align: left;
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--colour-background-accent-strong);
    border-right: 1px solid var(--colour-background-accent-strong);
}
table th:last-child,
table td:last-child {
    border-right: none;
}
table tbody tr:last-child td {
    border-bottom: none;
}
table thead tr {
    background-color: var(--colour-background-accent-medium);
    color: var(--colour-text-strong);
}
table tbody tr:hover {
    background-color: var(--colour-background-accent-light);
}

/* Code rules */
code,
pre {
    font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
    font-size: 0.875rem;
}
code.literal {
    background-color: var(--colour-inline-code-bg);
    color: var(--colour-inline-code-text);
    font-size: .8em;
    padding: 1px 2px 1px;
}
pre {
    background-color: var(--colour-background-accent-light);
    border: 1px solid var(--colour-background-accent-strong);
    overflow-x: auto;
    padding: .5rem .75rem;
    white-space: pre;
}

/* Sidebar formatting */
#psp-sidebar {
    overflow-y: auto;
    position: sticky;
    top: 0;
    height: 100vh;
}
#psp-sidebar > h2 {
    font-size: 1.4rem;
}
#psp-sidebar ul {
    font-size: .9rem;
    margin-left: 1rem;
}
#psp-sidebar ul a {
    text-decoration: none;
}
#source {
    padding-bottom: 2rem;
    font-weight: bold;
}

/* Admonitions rules */
div.admonition {
    background-color: var(--colour-background-accent-medium);
    margin-bottom: 1rem;
    margin-top: 1rem;
    padding: 0.5rem 0.75rem;
}
div.admonition a {
    color: var(--colour-links-light);
}

div.danger,
div.error {
    background-color: var(--colour-error);
}
div.warning {
    background-color: var(--colour-warning);
}
div.attention,
div.caution {
    background-color: var(--colour-caution);
}
div.important {
    background-color: var(--colour-attention);
}
div.hint,
div.tip {
    background-color: var(--colour-tip);
}

p.admonition-title {
    font-weight: bold;
}

/* PSP Header / references rules */
dl.rfc2822,
dl.footnote {
    display: grid;
    grid-template-columns: fit-content(30%) auto;
    width: 100%;
}
dl.rfc2822 > dt,
dl.rfc2822 > dd {
    padding: .1rem .3rem .1rem;
}
dl.rfc2822 > dt {
    text-align: right;
}
dl.rfc2822 > dd {
    margin: 0;
}

/* PSP Preamble Table Styling */
.psp-preamble-table {
    margin: 2em 0 3em 0;
    max-width: 700px;
    /* Ensure left alignment */
    margin-left: 0;
    margin-right: auto;
}

table.psp-preamble {
    border: none;
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    background: none;
    margin: 0;
}

table.psp-preamble td {
    border: none;
    padding: 0.3em 0;
    vertical-align: baseline;
    background: none;
}

table.psp-preamble td.psp-field {
    font-weight: bold;
    color: var(--colour-text-strong);
    text-align: right;
    padding-right: 1em;
    width: 150px;
    white-space: nowrap;
}

table.psp-preamble td.psp-value {
    color: var(--colour-text);
    text-align: left;
    width: auto;
}

/* PSP Preamble Styling - Simple and effective two-column layout */
article > ul.simple:first-of-type {
    margin: 2em 0 3em 0;
    padding: 0;
    border: none;
    list-style: none;
    max-width: 700px;
    margin-left: 0;
    margin-right: auto;
    font-size: 0.95rem;
}

article > ul.simple:first-of-type li {
    display: flex;
    margin: 0.4em 0;
    padding: 0;
    align-items: baseline;
}

article > ul.simple:first-of-type li p {
    margin: 0;
    padding: 0;
    flex: 1;
}

/* Extract and position the field name */
article > ul.simple:first-of-type li p strong {
    display: inline-block;
    width: 150px;
    font-weight: bold;
    color: var(--colour-text-strong);
    text-align: right;
    padding-right: 1em;
    flex-shrink: 0;
    margin-right: 0;
}

/* Make the text after the colon start properly */
article > ul.simple:first-of-type li p {
    color: var(--colour-text);
    text-align: left;
}

/* PSP Preamble Styling - like Python PEPs using field lists */
dl.field-list,
dl.simple {
    margin: 2em 0 3em 0;
    padding: 0;
    border: none;
    display: grid;
    grid-template-columns: minmax(120px, max-content) 1fr;
    gap: 0.2em 1em;
    max-width: 700px;
    align-items: baseline;
    justify-content: start;
}

dl.field-list dt,
dl.simple dt {
    font-weight: bold;
    color: var(--colour-text-strong);
    margin: 0;
    padding: 0.3em 0;
    text-align: right;
    justify-self: start;
}

dl.field-list dt::after,
dl.simple dt::after {
    content: ":";
}

dl.field-list dd,
dl.simple dd {
    margin: 0;
    padding: 0.3em 0;
    color: var(--colour-text);
    text-align: left;
    justify-self: start;
}

/* Responsive field list for mobile */
@media (max-width: 640px) {
    /* Responsive for new table structure */
    .psp-preamble-table {
        max-width: 100%;
    }
    
    table.psp-preamble {
        display: block;
    }
    
    table.psp-preamble tr {
        display: block;
        margin-bottom: 0.5em;
    }
    
    table.psp-preamble td.psp-field {
        display: block;
        text-align: left;
        width: auto;
        padding-right: 0;
        font-size: 0.9em;
        margin-bottom: 0.2em;
    }
    
    table.psp-preamble td.psp-value {
        display: block;
        padding-left: 1em;
        margin-bottom: 0.3em;
    }
    
    /* Responsive for legacy structures */
    dl.field-list,
    dl.simple {
        display: block;
        max-width: 100%;
    }
    
    dl.field-list dt,
    dl.simple dt {
        display: block;
        text-align: left;
        font-size: 0.9em;
        margin-bottom: 0.2em;
        padding: 0;
        justify-self: auto;
    }
    
    dl.field-list dd,
    dl.simple dd {
        display: block;
        padding: 0 0 0.8em 1em;
        margin-bottom: 0.3em;
        justify-self: auto;
    }
    
    article > ul.simple:first-of-type {
        max-width: 100%;
    }
    
    article > ul.simple:first-of-type li {
        display: block;
        margin-bottom: 0.6em;
    }
    
    article > ul.simple:first-of-type li p strong {
        display: block;
        width: auto;
        text-align: left;
        padding-right: 0;
        font-size: 0.9em;
        margin-bottom: 0.2em;
    }
    
    article > ul.simple:first-of-type li p {
        display: block;
        padding-left: 1em;
        margin-bottom: 0.3em;
    }
}

/* Mobile responsive layout */
@media (max-width: 768px) {
    .psp-layout {
        flex-direction: column;
    }
    
    #psp-sidebar {
        width: 100%;
        position: static;
        height: auto;
        order: 2;
        border-right: none;
        border-top: 1px solid var(--colour-rule-light);
        max-height: 400px;
        overflow-y: auto;
        padding: 1rem;
        box-shadow: none;
    }
    
    #psp-content {
        max-width: 100%;
        order: 1;
        padding: 1rem;
    }
    
    section#psp-page-section > header {
        padding: 0.5rem;
    }
    
    .theme-toggle-label {
        position: static;
        float: right;
        margin-top: 0.5rem;
    }
    
    ul.breadcrumbs {
        padding: 0.5rem 0;
        display: block;
        clear: both;
    }
    
    section#psp-page-section > header > h1 {
        display: block;
        border-right: none;
        padding-right: 0;
        margin-bottom: 0.5rem;
    }
    
    /* Adjust content typography for mobile */
    #psp-content {
        line-height: 1.5;
    }
    
    #psp-content h1 {
        font-size: 1.6rem;
        margin-bottom: 1rem;
    }
    
    #psp-content h2 {
        font-size: 1.4rem;
        margin-top: 1.5rem;
        margin-bottom: 0.75rem;
    }
}

/* Collapsible Table of Contents - similar to Python PEPs */
#table-of-contents {
    margin: 1.5em 0;
    border: 1px solid var(--colour-rule-light);
    border-radius: 4px;
    background-color: var(--colour-background-accent-light);
}

#table-of-contents summary.toc-title {
    padding: 0.75em 1em;
    font-weight: bold;
    color: var(--colour-text-strong);
    cursor: pointer;
    list-style: none;
    user-select: none;
    border-bottom: 1px solid var(--colour-rule-light);
    background-color: var(--colour-background-accent-medium);
    border-radius: 4px 4px 0 0;
}

#table-of-contents[open] summary.toc-title {
    border-bottom: 1px solid var(--colour-rule-light);
    border-radius: 4px 4px 0 0;
}

#table-of-contents:not([open]) summary.toc-title {
    border-bottom: none;
    border-radius: 4px;
}

#table-of-contents summary.toc-title::before {
    content: "▶";
    display: inline-block;
    margin-right: 0.5em;
    transition: transform 0.2s ease;
}

#table-of-contents[open] summary.toc-title::before {
    transform: rotate(90deg);
}

#table-of-contents .toc-content {
    padding: 1em;
}

#table-of-contents .toc-content ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

#table-of-contents .toc-content li {
    margin: 0.3em 0;
}

#table-of-contents .toc-content a {
    text-decoration: none;
    color: var(--colour-links);
    padding: 0.2em 0;
    display: block;
}

#table-of-contents .toc-content a:hover {
    text-decoration: underline;
    color: var(--colour-links-light);
}

/* Nested TOC levels */
#table-of-contents .toc-content ul ul {
    margin-left: 1.5em;
    margin-top: 0.2em;
}

#table-of-contents .toc-content ul ul li {
    font-size: 0.9em;
}

/* WebKit-specific styles for the disclosure triangle */
#table-of-contents summary::-webkit-details-marker {
    display: none;
}

/* Firefox-specific styles */
#table-of-contents summary::marker {
    content: "";
}

/* Accessibility */
.visually-hidden {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

/* PSP Preamble styling - similar to Python PEPs */
/* Style the first bullet list in the document (which should be the preamble) */
article > ul:first-of-type {
    margin: 2rem auto 3rem auto;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.6;
    list-style: none;
    max-width: 600px;
    text-align: center;
}

article > ul:first-of-type li {
    margin: 0.2rem 0;
    padding-left: 0;
}

article > ul:first-of-type li::before {
    content: none;
}

.psp-preamble {
    margin: 2rem auto 3rem auto;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1.4;
    max-width: 600px;
    text-align: center;
}

.psp-preamble .line-block {
    margin: 0;
}

.psp-preamble .line {
    margin: 0.3rem 0;
}

/* Style for table of contents directive */
.contents {
    background-color: var(--colour-background-accent-light);
    border: 1px solid var(--colour-rule-light);
    border-radius: 4px;
    padding: 1rem;
    margin: 1rem 0 2rem 0;
}

.contents .topic-title {
    font-weight: bold;
    font-size: 1.1rem;
    margin-bottom: 0.5rem;
    color: var(--colour-text-strong);
}

.contents ul {
    margin: 0.5rem 0;
    padding-left: 1.5rem;
}

.contents li {
    margin: 0.3rem 0;
}

.contents a {
    text-decoration: none;
    color: var(--colour-links);
}

.contents a:hover {
    text-decoration: underline;
    color: var(--colour-links-light);
}
