/* MSA page styles - loaded only on /MSA */

/* Anchor target offset for the fixed/sticky header */
[id^="section-"],
[id^="clause-"],
[id="annexure-a"] {
    scroll-margin-top: 8rem;
}

/* Deeper sub-headings (e.g. 3.2.1) */
main section h5 {
    font: 600 1.25rem/1.4 var(--fh);
    color: var(--text);
    margin: 1.5rem 0 0.5rem;
}

/* Clause cross-reference link */
.msa-ref {
    color: var(--secondary);
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
    cursor: pointer;
    font-weight: 600;
    transition: color var(--transition), text-decoration-color var(--transition);
}

.msa-ref:hover,
.msa-ref:focus {
    color: var(--text);
    text-decoration-style: solid;
    outline: none;
}

/* Hover preview tooltip */
.msa-tooltip {
    position: fixed;
    z-index: 1200;
    max-width: min(340px, calc(100vw - 2rem));
    max-height: 220px;
    overflow-y: auto;
    padding: 1rem 1.2rem;
    background: var(--bg-light);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    font: var(--small);
    line-height: 1.6;
    pointer-events: none;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity var(--transition), transform var(--transition);
    visibility: hidden;
}

.msa-tooltip.show {
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
}

.msa-tooltip .msa-tooltip-title {
    display: block;
    font: var(--a);
    color: var(--secondary);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.msa-tooltip .msa-tooltip-hint {
    display: block;
    margin-top: 0.5rem;
    font-style: italic;
    color: var(--text-muted);
}

/* Highlight flash on the jumped-to clause */
.msa-target-flash {
    animation: msaFlash 2s ease-out;
    border-radius: 6px;
}

@keyframes msaFlash {
    0% {
        background-color: rgba(102, 217, 204, 0.35);
    }
    100% {
        background-color: transparent;
    }
}

/* --- Service Tiers (clause 3.4) --- */
.tier-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.5rem;
    margin: 2rem 0;
    max-width: 1120px;
}

/* Scale legend above the tier grid */
.tier-scale {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin: 1.5rem 0 0.25rem;
    max-width: 1120px;
}

.scale-end {
    flex: 0 0 auto;
    text-align: left;
}

.scale-end.scale-high {
    text-align: right;
}

.scale-head {
    display: block;
    font: var(--big);
    font-weight: 700;
}

.scale-sub {
    display: block;
    font: var(--small);
    color: var(--text-muted);
}

.scale-track {
    flex: 1 1 auto;
    position: relative;
    height: 16px;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--success), var(--secondary), var(--warning), var(--danger));
    border: 1px solid var(--border);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25);
}

.scale-step {
    position: absolute;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--bg-dark);
    border: 2px solid var(--border);
    color: var(--text);
    font: var(--small);
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.scale-s1 { left: 12.5%; }
.scale-s2 { left: 37.5%; }
.scale-s3 { left: 62.5%; }
.scale-s4 { left: 87.5%; }

@media (max-width: 700px) {
    .scale-sub {
        display: none;
    }

    .tier-scale {
        gap: 0.5rem;
    }
}

.tier-card {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-left: 4px solid var(--tier-accent, var(--secondary));
    border-radius: 8px;
    padding: 1.1rem 1rem 1.1rem 1.25rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: left;
    gap: 0.6rem;
}

.tier-card > * {
    width: 100%;
    text-align: left;
}

.tier-card .tier-head {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.tier-card .tier-tag {
    font: var(--a);
    font-weight: 700;
    color: var(--tier-accent, var(--secondary));
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.tier-card .tier-time {
    font: var(--small);
    color: var(--text-muted);
    white-space: nowrap;
}

.tier-card .tier-meta {
    font: var(--a);
    font-weight: 600;
    color: var(--text);
    margin: 0;
    padding-bottom: 0.6rem;
    border-bottom: 1px solid var(--border);
}

.tier-card .tier-exp {
    color: var(--tier-accent, var(--secondary));
    font-weight: 700;
}

.tier-card .tier-dot {
    margin: 0 0.35rem;
    color: var(--text-muted);
}

.tier-card .tier-list {
    list-style: none;
    margin: 0;
    padding-left: 0;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.tier-card .tier-list li {
    position: relative;
    padding-left: 1.1rem;
    line-height: 1.6;
    margin: 0;
    text-align: left;
}

.tier-card .tier-list li::before {
    content: "\2013";
    position: absolute;
    left: 0;
    top: 0;
    color: var(--tier-accent, var(--secondary));
    font-weight: 700;
}

.tier-1 {
    --tier-accent: var(--success);
}

.tier-2 {
    --tier-accent: var(--secondary);
}

.tier-3 {
    --tier-accent: var(--warning);
}

.tier-4 {
    --tier-accent: var(--danger);
}

/* Darker accent colours for clarity on the light background */
body.light .tier-3 {
    --tier-accent: #9a6b00;
}

body.light .tier-4 {
    --tier-accent: #c62828;
}

/* --- Priority level badges (clause 7.7) --- */
.priority-badge {
    display: inline-block;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font: var(--small);
    font-weight: 700;
    line-height: 1.4;
    white-space: nowrap;
    border: 1px solid transparent;
    text-align: center;
    min-width: 4.2rem;
}

.p-vl {
    background: rgba(138, 143, 141, 0.16);
    color: #9aa2a0;
    border-color: rgba(138, 143, 141, 0.4);
}

.p-low {
    background: rgba(145, 214, 165, 0.16);
    color: var(--success);
    border-color: rgba(145, 214, 165, 0.4);
}

.p-med {
    background: rgba(100, 181, 246, 0.16);
    color: #64b5f6;
    border-color: rgba(100, 181, 246, 0.4);
}

.p-high {
    background: rgba(255, 167, 38, 0.16);
    color: #ffa726;
    border-color: rgba(255, 167, 38, 0.4);
}

.p-crit {
    background: rgba(239, 83, 80, 0.16);
    color: #ef5350;
    border-color: rgba(239, 83, 80, 0.4);
}

.p-quick {
    background: rgba(179, 157, 219, 0.16);
    color: #b39ddb;
    border-color: rgba(179, 157, 219, 0.45);
}

/* Darker badge colours for clarity on the light background */
body.light .p-vl {
    color: #4b5450;
    border-color: rgba(75, 84, 80, 0.5);
}

body.light .p-low {
    color: #2e7d4f;
    border-color: rgba(46, 125, 79, 0.5);
}

body.light .p-med {
    color: #1565c0;
    border-color: rgba(21, 101, 192, 0.5);
}

body.light .p-high {
    color: #bb6b00;
    border-color: rgba(187, 107, 0, 0.55);
}

body.light .p-crit {
    color: #b71c1c;
    border-color: rgba(183, 28, 28, 0.55);
}

body.light .p-quick {
    color: #4527a0;
    border-color: rgba(69, 39, 160, 0.55);
}

.table-note {
    font: var(--small);
    color: var(--text-muted);
    margin: 0.5rem 0 0;
}

/* --- Letterhead (party block) --- */
.msa-letterhead {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
    margin-bottom: 2rem;
}

.msa-letterhead-name {
    font: var(--h4);
    color: var(--text);
    margin: 0 0 0.5rem;
}

.msa-letterhead ul {
    margin: 0;
    padding-left: 1.2rem;
}

.msa-letterhead li {
    margin: 0.15rem 0;
    line-height: 1.6;
}

/* --- Dock TOC shared styles --- */
.msa-toc-title {
    font: var(--a);
    font-weight: 700;
    color: var(--secondary);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0;
}

.msa-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.35rem 1.5rem;
}

.msa-toc-list li a {
    color: var(--text);
    text-decoration: none;
    font: var(--a);
}

.msa-toc-list li a:hover,
.msa-toc-list li a:focus {
    color: var(--secondary);
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* --- Floating "Contents" button --- */
.msa-toc-fab {
    position: fixed;
    top: 33%;
    right: 0.75rem;
    left: auto;
    transform: translateY(-50%);
    z-index: 1100;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.9rem;
    height: 2.9rem;
    background: var(--secondary);
    color: var(--bg-dark);
    border: none;
    border-radius: 50%;
    opacity: 0.7;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    transition: background var(--transition), color var(--transition), transform var(--transition), opacity var(--transition);
}

.msa-toc-fab i {
    color: var(--bg-dark);
    font-size: 1.2rem;
    line-height: 0;
}

.msa-toc-fab:hover {
    background: var(--secondary);
    color: var(--text);
    opacity: 1;
    transform: translateY(calc(-50% - 2px));
}

.msa-toc-fab:hover i {
    color: var(--text);
}

.msa-toc-fab.hidden {
    opacity: 0;
    pointer-events: none;
}

/* --- Inline "Table of Contents" button under the version line --- */
.msa-top-actions {
    display: flex;
    justify-content: center;
    gap: 0.9rem;
    flex-wrap: wrap;
    margin-bottom: 2rem;
}

.msa-toc-inline {
    cursor: pointer;
    background: var(--secondary);
    color: var(--bg-dark);
    height: fit-content;
    min-width: 13rem;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.4rem;
    font-size: 1rem;
    font-weight: 600;
    transition: background 0.3s, color 0.3s;
}

.msa-toc-inline:hover {
    background: var(--secondary);
    color: var(--text);
}

.msa-download {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    cursor: pointer;
    background: var(--secondary);
    color: var(--bg-dark);
    height: fit-content;
    min-width: 13rem;
    border: none;
    border-radius: 8px;
    padding: 0.6rem 1.4rem;
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    line-height: normal;
    text-decoration: none;
    transition: background 0.3s, color 0.3s;
}

.msa-download:hover {
    background: var(--secondary);
    color: var(--text);
}

.msa-download i {
    color: var(--bg-dark);
    font-size: 1.15rem;
}

/* --- Backdrop behind the open dock (click to close) --- */
.msa-toc-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1140;
    background: rgba(0, 0, 0, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition), visibility var(--transition);
}

.msa-toc-backdrop.show {
    opacity: 1;
    visibility: visible;
}

/* --- Dockable Table of Contents panel --- */
.msa-toc-dock {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: min(320px, 85vw);
    background: var(--bg-light);
    border-left: 1px solid var(--border);
    box-shadow: -12px 0 32px rgba(0, 0, 0, 0.3);
    z-index: 1150;
    transform: translateX(100%);
    visibility: hidden;
    display: flex;
    flex-direction: column;
    padding: 1.25rem;
    overflow-y: auto;
}

.msa-toc-dock.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform var(--transition), visibility var(--transition);
}

.msa-toc-dock-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.msa-toc-close {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 0.35rem;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    font: var(--small);
    font-weight: 600;
    line-height: normal;
}

.msa-toc-close:hover,
.msa-toc-close:focus {
    background: var(--danger);
    color: var(--bg-dark);
    border-color: transparent;
}

.msa-toc-close i {
    font-size: 1.1rem;
}

.msa-toc-close span {
    margin: 0;
}

.msa-toc-dock .msa-toc-list {
    grid-template-columns: 1fr;
}

/* --- Clickable heading numbers --- */
.hnum {
    cursor: pointer;
    color: var(--secondary);
    text-decoration: underline dotted;
    text-underline-offset: 3px;
    font-weight: 700;
}

.hnum:hover {
    color: var(--text);
    text-decoration-style: solid;
}

body.light .hnum {
    color: #1ea296;
}

body.light .hnum:hover {
    color: #0f1512;
}

/* --- Clause number affordance --- */
.clause-num {
    cursor: pointer;
    border-radius: 4px;
    padding: 0 0.15rem;
}

.clause-num:hover {
    background: var(--bg);
}

/* --- Context menu --- */
.msa-ctxmenu {
    position: fixed;
    z-index: 1250;
    min-width: 230px;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
    padding: 0.35rem;
    display: none;
}

.msa-ctxmenu.open {
    display: block;
}

.msa-ctxmenu button {
    display: flex;
    width: 100%;
    align-items: center;
    gap: 0.6rem;
    background: none;
    border: none;
    color: var(--text);
    font: var(--a);
    text-align: left;
    padding: 0.6rem 0.9rem;
    border-radius: 6px;
    cursor: pointer;
}

.msa-ctxmenu button:hover {
    background: var(--bg);
}

.msa-ctxmenu button i {
    color: var(--secondary);
    font-size: 1.15rem;
}

/* --- Heading rhythm (consistent visual depth) --- */
main section h3 {
    margin-top: 3rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

main section h3:first-of-type {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
}

main section h4 {
    margin-top: 2.25rem;
}

main section h5 {
    margin-top: 1.6rem;
}

/* --- Unified paragraph layout ---
   All clause paragraphs and clause bodies share the same left edge as the
   headings above them, and the same bottom spacing. */
main section p {
    margin: 0 0 1rem;
}

main section p.msa-clause {
    margin-bottom: 1rem;
}

/* Clause number: inline accent, no displacement, so body text stays flush left */
.clause-num {
    color: var(--secondary);
    font-weight: 700;
    margin-right: 0.4rem;
}

/* Darker clause numbers for light background */
body.light .clause-num {
    color: #1ea296;
}