/* ── Override global page styles ── */
body {
    text-align: left !important;
}
h1 {
    margin-bottom: 0.25rem !important;
}
h2 {
    text-transform: none !important;
    letter-spacing: normal !important;
    color: var(--color-primary) !important;
    border-bottom: none !important;
    padding-bottom: 0 !important;
    margin: 0 !important;
}

/* ── Page layout ── */
.cs-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem 1.5rem 4rem;
}
.toc {
    column-count: 3;
    column-gap: 2rem;
    margin: 1rem 0 2rem;
    font-size: 0.85rem;
}
.toc a {
    display: block;
    color: var(--color-primary);
    text-decoration: none;
    padding: 0.1rem 0;
}
.toc a:hover {
    text-decoration: underline;
}

/* ── Section headings ── */
.cs-section {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 2px solid var(--color-border);
}
.cs-section h2 {
    margin-bottom: 1.25rem;
    font-size: 1.2rem;
    color: var(--color-primary);
}
.cs-section h3 {
    margin: 1.5rem 0 0.5rem;
    font-size: 0.95rem;
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* ── Demo grid ── */
.demo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}
.demo-block {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1rem;
}
.demo-block > label {
    font-size: 0.75rem;
    color: var(--color-muted);
    display: block;
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* ── Code snippet ── */
.snippet {
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: monospace;
    font-size: 0.78rem;
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    margin-top: 0.75rem;
    overflow-x: auto;
    white-space: pre;
}

/* ── Colour swatches ── */
.swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}
.swatch {
    width: 80px;
    text-align: center;
}
.swatch-box {
    height: 44px;
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    margin-bottom: 0.25rem;
}
.swatch span {
    font-size: 0.7rem;
    color: var(--color-muted);
}

/* ── Typography scale ── */
.type-scale > * {
    margin: 0.25rem 0;
}

/* ── Flex row helper ── */
.row {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.5rem;
}

/* ── Badge/pill ── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-blue {
    background: var(--color-primary-tint);
    color: var(--color-primary);
}
.badge-green {
    background: var(--color-success-tint);
    color: var(--color-success);
}
.badge-red {
    background: var(--color-error-tint);
    color: var(--color-error);
}
.badge-orange {
    background: var(--color-warning-tint);
    color: var(--color-warning);
}
.badge-gray {
    background: var(--color-bg);
    color: var(--color-muted);
    border: 1px solid var(--color-border);
}

/* ── Stepper ── */
.stepper {
    display: flex;
    align-items: center;
}
.stepper button {
    width: 2rem;
    height: 2rem;
    border: 1px solid var(--color-border);
    background: var(--color-bg-card);
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--color-text);
    transition: background var(--transition);
}
.stepper button:hover {
    background: var(--color-primary-tint);
    color: var(--color-primary);
}
.stepper button:first-child {
    border-radius: var(--radius) 0 0 var(--radius);
}
.stepper button:last-child {
    border-radius: 0 var(--radius) var(--radius) 0;
}
.stepper input {
    width: 3.5rem;
    height: 2rem;
    text-align: center;
    border: 1px solid var(--color-border);
    border-left: none;
    border-right: none;
    background: var(--color-bg-card);
    color: var(--color-text);
    font-size: 0.95rem;
}

/* ── Slider ── */
.slider-wrap {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.slider-wrap input[type='range'] {
    flex: 1;
}
.slider-val {
    min-width: 2.5rem;
    text-align: right;
    font-weight: 600;
    color: var(--color-primary);
    font-size: 0.9rem;
}

/* ── Toggle switch ── */
.toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    cursor: pointer;
    user-select: none;
}
.toggle input[type='checkbox'] {
    appearance: none;
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
    padding: 0;
}
.toggle-track {
    position: relative;
    flex-shrink: 0;
    width: 2.6rem;
    height: 1.5rem;
    background: var(--color-border);
    border-radius: 999px;
    transition: background 0.2s;
}
.toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    transition: left 0.2s;
}
.toggle.on .toggle-track {
    background: var(--color-primary);
}
.toggle.on .toggle-track::after {
    left: calc(100% - 21px);
}
.toggle-label {
    font-size: 0.9rem;
}

/* ── Progress bar ── */
.progress-bar {
    height: 8px;
    background: var(--color-border);
    border-radius: 999px;
    overflow: hidden;
}
.progress-fill {
    height: 100%;
    background: var(--color-primary);
    border-radius: 999px;
    transition: width 0.4s ease;
}
.progress-fill.success {
    background: var(--color-success);
}
.progress-fill.warning {
    background: var(--color-warning);
}
.progress-fill.error {
    background: var(--color-error);
}

/* ── Alert / callout ── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    border-left: 4px solid;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}
.alert-info {
    background: var(--color-primary-tint);
    border-color: var(--color-primary);
    color: var(--color-primary);
}
.alert-success {
    background: var(--color-success-tint);
    border-color: var(--color-success);
    color: var(--color-success);
}
.alert-warning {
    background: var(--color-warning-tint);
    border-color: var(--color-warning);
    color: var(--color-warning);
}
.alert-error {
    background: var(--color-error-tint);
    border-color: var(--color-error);
    color: var(--color-error);
}

/* ── Table ── */
.cs-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}
.cs-table th {
    background: var(--color-bg);
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
}
.cs-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid var(--color-border);
}
.cs-table tr:hover td {
    background: var(--color-primary-tint);
}

/* ── Tabs ── */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--color-border);
    margin-bottom: 1rem;
}
.tab-btn {
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--color-muted);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition:
        color var(--transition),
        border-color var(--transition);
}
.tab-btn.active {
    color: var(--color-primary);
    border-bottom-color: var(--color-primary);
    font-weight: 600;
}
.tab-panel {
    display: none;
    padding: 0.75rem;
    background: var(--color-bg);
    border-radius: var(--radius);
}
.tab-panel.active {
    display: block;
}

/* ── Accordion ── */
.accordion-item {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    overflow: hidden;
}
.accordion-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--color-bg-card);
    border: none;
    text-align: left;
    font-size: 0.9rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--color-text);
    transition: background var(--transition);
}
.accordion-btn:hover {
    background: var(--color-primary-tint);
}
.accordion-btn .chevron {
    transition: transform var(--transition);
}
.accordion-item.open .accordion-btn .chevron {
    transform: rotate(180deg);
}
.accordion-body {
    max-height: 0;
    overflow: hidden;
    transition:
        max-height 0.3s ease,
        padding 0.3s ease;
    padding: 0 1rem;
    font-size: 0.9rem;
}
.accordion-item.open .accordion-body {
    max-height: 200px;
    padding: 0.75rem 1rem;
}

/* ── Tooltip ── */
.tooltip-wrap {
    position: relative;
    display: inline-block;
}
.tooltip-wrap .tooltip-text {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    font-size: 0.75rem;
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius);
    white-space: nowrap;
    transition: opacity var(--transition);
    pointer-events: none;
    z-index: 100;
}
.tooltip-wrap:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* ── Modal ── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}
.modal-backdrop.open {
    display: flex;
}
.modal-box {
    background: var(--color-bg-card);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}
.modal-header h3 {
    margin: 0;
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-muted);
}

/* ── Skeleton loader ── */
.skeleton {
    background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s infinite;
    border-radius: var(--radius);
}
@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

/* ── Copy button ── */
.copy-btn {
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    cursor: pointer;
    color: var(--color-muted);
    transition: all var(--transition);
}
.copy-btn:hover {
    background: var(--color-primary-tint);
    color: var(--color-primary);
    border-color: var(--color-primary);
}
.copy-btn.copied {
    background: var(--color-success-tint);
    color: var(--color-success);
    border-color: var(--color-success);
}

/* ── Star rating ── */
.stars {
    display: flex;
    gap: 0.15rem;
}
.star {
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--color-border);
    transition: color var(--transition);
}
.star.on {
    color: #f59e0b;
}

/* ── Knob ── */
.knob-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

/* ── Tag input ── */
.tag-input-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    padding: 0.4rem;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-bg-card);
    min-height: 2.4rem;
    cursor: text;
}
.tag-chip {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.15rem 0.5rem;
    background: var(--color-primary-tint);
    color: var(--color-primary);
    border-radius: 999px;
    font-size: 0.8rem;
}
.tag-chip button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    font-size: 0.9rem;
    line-height: 1;
}
.tag-input-wrap input {
    border: none;
    outline: none;
    background: none;
    min-width: 80px;
    font-size: 0.9rem;
    color: var(--color-text);
}

/* ── Big number ── */
.big-number {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--color-primary);
    font-variant-numeric: tabular-nums;
}
.big-unit {
    font-size: 1rem;
    color: var(--color-muted);
    margin-left: 0.25rem;
}

/* ── Formula box ── */
.formula-box {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 0.75rem 1rem;
    font-family: serif;
    font-size: 1rem;
    line-height: 1.8;
}
