/*
 * Document pages - Tier 2 stylesheet.
 *
 * Copied from the approved terms-of-service.html. Named for the group rather
 * than the page: the `guide-*` vocabulary here is what FAQ, User Guide and
 * Sample Forms are built on, so those pages will need no stylesheet of their
 * own.
 *
 * `tos-prose` styles server-supplied HTML rendered with th:utext, so it has to
 * cover headings, lists, tables and blockquotes without knowing the markup in
 * advance.
 *
 * The design-review state machine on #tosRoot is not carried over: acceptance
 * state comes from the model.
 */

.guide-page { width: min(100%, 72rem); margin-inline: auto; }

/* The contents rail jumps down a long document; smooth keeps the reader
       oriented. Reversed under prefers-reduced-motion below. */
    html { scroll-behavior: smooth; }

.guide-hero { border: 1px solid hsl(var(--border)); border-radius: 1.5rem; background: linear-gradient(120deg, hsl(var(--card)) 0%, hsl(var(--accent) / 0.42) 100%); box-shadow: var(--shadow-card); }

.guide-layout { display: grid; grid-template-columns: minmax(0, 1fr) 15rem; align-items: start; gap: clamp(1rem, 2.5vw, 1.5rem); }

.guide-section, .guide-side-card { border: 1px solid hsl(var(--border)); border-radius: 1.35rem; background: hsl(var(--card)); box-shadow: var(--shadow-card); }

.guide-section { padding: clamp(1.25rem, 3vw, 1.75rem); }

.guide-side-card { padding: 1rem; }

/* The document column is a grid, not `space-y`: grid gap ignores items
       that are display:none, so a hidden state (the placeholder, the
       acceptance card) leaves no phantom gap behind it. An adjacent-sibling
       margin would. */
    .tos-side .guide-link { min-height: 2.5rem; }

.guide-link { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; min-height: 3rem; border-radius: 0.8rem; padding: 0.6rem 0.7rem; color: hsl(var(--foreground)); transition: background-color 120ms ease; }

.guide-link:hover { background: hsl(var(--muted)); }

.guide-link + .guide-link { margin-top: 0.25rem; }

.guide-link-icon { display: grid; width: 2.2rem; height: 2.2rem; flex: 0 0 auto; place-items: center; border-radius: 0.7rem; background: hsl(var(--background)); color: var(--teal-deep); }

.guide-pill { display: inline-flex; align-items: center; min-height: 1.75rem; border-radius: 999px; background: hsl(var(--stone-warm)); padding: 0.25rem 0.6rem; color: hsl(var(--foreground)); font-size: 0.6875rem; font-weight: 700; }

.guide-note { border: 1px solid rgba(13, 92, 117, 0.18); border-radius: 1rem; background: hsl(var(--accent) / 0.42); padding: 0.9rem; }

/* ── The document ──────────────────────────────────────────────────
       This is the one piece of styling on the page that has to be written
       blind. `tosDocument` arrives as raw HTML through th:utext, so nothing
       inside carries a class I chose — and Tailwind's preflight has already
       stripped heading sizes, list markers and margins from every bare
       element. So `.tos-prose` styles ELEMENTS, not classes, and covers the
       tags a pasted legal document actually contains: h2/h3, p, ul/ol/li,
       a, strong, em, hr, blockquote, table. Whatever the server sends
       renders correctly without anyone editing this file. */
    .tos-prose {
      max-width: 72ch;                    /* a legal document needs a measure, not the full card */
      color: hsl(var(--muted-foreground));
      font-size: 0.9375rem;
      line-height: 1.75;
    }

/* Spacing is set on the ELEMENTS, not with `> * + *`.
   `tos_template.html` wraps its whole document in a single <div class="tos-section">,
   so the prose container has exactly one child and a direct-child sibling rule
   matches nothing: every heading, paragraph and list collapsed together with no
   vertical rhythm at all. Descendant rules survive that wrapper, and any other
   the template might grow later. */
.tos-prose p,
.tos-prose ul,
.tos-prose ol,
.tos-prose blockquote,
.tos-prose table,
.tos-prose hr,
.tos-prose > div + div { margin-top: 0.9rem; }

/* The wrapper itself must not add to the first element's spacing. */
.tos-prose > div:first-child > :first-child { margin-top: 0; }

.tos-prose h2 {
      margin-top: 2.25rem;
      font-family: 'Fraunces', ui-serif, Georgia, Cambria, 'Times New Roman', Times, serif;
      font-size: clamp(1.0625rem, 2.2vw, 1.25rem);
      font-weight: 600;
      line-height: 1.35;
      color: hsl(var(--foreground));
      scroll-margin-top: 6.5rem;
    }

.tos-prose h2:first-child { margin-top: 0; }

.tos-prose h3 { margin-top: 1.5rem; font-size: 0.9375rem; font-weight: 700; color: hsl(var(--foreground)); }

.tos-prose ul, .tos-prose ol { padding-left: 1.2rem; }

.tos-prose ul { list-style: disc; }

.tos-prose ol { list-style: decimal; }

.tos-prose li + li { margin-top: 0.4rem; }

.tos-prose li::marker { color: var(--brass); }

.tos-prose a { color: var(--teal-deep); font-weight: 600; text-decoration: underline; text-decoration-color: rgba(13, 92, 117, 0.3); text-underline-offset: 0.2em; }

.tos-prose a:hover { text-decoration-color: var(--teal-deep); }

.tos-prose strong { color: hsl(var(--foreground)); font-weight: 600; }

.tos-prose em { font-style: italic; }

.tos-prose hr { border: 0; border-top: 1px solid hsl(var(--border)); margin: 1.75rem 0; }

.tos-prose blockquote { border-left: 2px solid var(--brass); padding-left: 0.9rem; color: hsl(var(--muted-foreground)); }

.tos-prose table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

.tos-prose th, .tos-prose td { border: 1px solid hsl(var(--border)); padding: 0.5rem 0.65rem; text-align: left; vertical-align: top; }

.tos-prose th { background: hsl(var(--muted)); color: hsl(var(--foreground)); font-weight: 600; }

/* The document is long by nature; a rule under each heading gives the
       eye somewhere to land when scanning for a clause. */
    .tos-prose h2 { border-top: 1px solid hsl(var(--border)); padding-top: 1.5rem; }

.tos-prose h2:first-child { border-top: 0; padding-top: 0; }

/* ── Acceptance ────────────────────────────────────────────────────
       Its own card, tinted, because the spec makes it a section with its own
       heading rather than a bare action row — and because agreeing to terms
       is a different kind of act from reading them. */
    .accept-card { border-color: rgba(13, 92, 117, 0.22); background: linear-gradient(140deg, hsl(var(--card)) 0%, hsl(var(--accent) / 0.5) 100%); }

.accept-actions { display: flex; flex-wrap: wrap; gap: 0.75rem; }

.accept-actions form { display: contents; }

.accept-actions .btn { flex: 1 1 12rem; }

/* ── Placeholder ───────────────────────────────────────────────────
       tosDocument == null. Not an error and not empty-state furniture — the
       terms simply are not published yet. */
    .tos-placeholder { border: 1px dashed hsl(var(--border)); border-radius: 1.25rem; background: hsl(var(--background)); padding: clamp(2rem, 6vw, 3rem) 1.25rem; text-align: center; }

/* ── Page states ───────────────────────────────────────────────────
       Three, and they come from two server booleans: whether the document
       exists, and whether this account still has to accept it. Everything
       is in the static markup; only visibility changes. */
    .when-document, .when-pending, .when-needs-acceptance, .when-accepted { display: none; }

/* ── Scroll to top (spec feature 3) ────────────────────────────────
       Bottom right, because the design-review tray holds bottom left and the
       mobile nav holds the bottom edge. */
    .scroll-top {
      position: fixed;
      right: 1rem;
      bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
      z-index: 40;
      display: grid;
      place-items: center;
      width: 3rem;
      height: 3rem;
      border-radius: 999px;
      border: 1px solid hsl(var(--border));
      background: hsl(var(--card));
      color: hsl(var(--foreground));
      box-shadow: var(--shadow-card);
      opacity: 0;
      pointer-events: none;
      transform: translateY(0.5rem);
      transition: opacity 160ms ease, transform 160ms ease;
    }

.scroll-top.is-visible { opacity: 1; pointer-events: auto; transform: translateY(0); }

.scroll-top:hover { background: hsl(var(--muted)); }

.scroll-top:focus-visible { outline: 2px solid var(--teal-deep); outline-offset: 2px; }

@media screen and (min-width: 48rem) { .scroll-top { right: 1.5rem; bottom: 1.5rem; } }

/* ── Decline confirmation ──────────────────────────────────────────
       Styled to be the shell's logout modal, because that is exactly what it
       is — see the migration map for why it is a page overlay and not the
       shell one. */
    .tos-modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; background: rgba(0, 0, 0, 0.4); padding: 1rem; opacity: 0; pointer-events: none; transition: opacity 150ms ease; }

.tos-modal.is-open { opacity: 1; pointer-events: auto; }

@media screen and (max-width: 58rem) { .guide-layout { grid-template-columns: 1fr; } .tos-side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; } }

@media screen and (max-width: 38rem) { .guide-hero { border-radius: 1.25rem; } .tos-side { display: block; } .guide-section { border-radius: 1.25rem; } }

@media (prefers-reduced-motion: reduce) { .btn, .guide-link, .scroll-top, .tos-modal { transition: none !important; } html { scroll-behavior: auto !important; } }

@media print { #sidebar, .app-topbar, nav[aria-label="Main navigation"], .sheet-backdrop, .nav-tip, .no-print { display: none !important; } main { padding: 0 !important; } .guide-layout { display: block; } .tos-side, .accept-actions, .scroll-top { display: none !important; } .guide-hero, .guide-section { box-shadow: none; } .tos-prose { max-width: none; } .tos-prose h2 { break-after: avoid; page-break-after: avoid; } }

/* ============================================================
   FAQ, User Guide, and Sample Forms
   ------------------------------------------------------------
   Added when those three pages migrated. They are one group: the
   guide-* vocabulary above is shared with them, and the bilingual
   rules below are shared between User Guide and Sample Forms.
   ============================================================ */

/* ── Bilingual content ───────────────────────────────────────
   The approved user-guide and sample-forms designs switch language with
   CLASSES - .lang-en / .lang-vi, plus .block-copy where the element is a
   block - driven by data-language on <body>. That is not decoration: the
   Sample Forms download rows are labelled "English", "Tiếng Việt" and
   "Español" and carry a real `lang` attribute so a screen reader says them
   correctly, but they are FORM languages, not UI language, and must never
   be filtered by the toggle. Selecting on the bare [lang] attribute, which
   is what the legacy how-to-use.css did, would hide the Vietnamese
   download row whenever the page was in English.

   The preference persists under the same `preferredLang` key the legacy
   script used, so a reader who already chose Vietnamese keeps it. */
.lang-vi { display: none; }

body[data-language="vi"] .lang-en { display: none !important; }

body[data-language="vi"] .lang-vi { display: inline; }

body[data-language="vi"] .lang-vi.block-copy { display: block; }

.language-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    border: 1px solid hsl(var(--border));
    border-radius: 999px;
    padding: 0.2rem;
    background: hsl(var(--card));
}

.language-btn {
    min-height: 2.5rem;
    border-radius: 999px;
    padding: 0.45rem 0.85rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 700;
}

.language-btn[aria-pressed="true"] { background: var(--teal-deep); color: #fff; }

.language-btn:focus-visible { outline: 2px solid var(--teal-deep); outline-offset: 2px; }

/* ── FAQ ─────────────────────────────────────────────────────
   Questions are <details>, not a JS accordion: they open without
   script, they are keyboard operable for free, and the browser's
   own find-in-page can reach a closed answer. */
.faq-toolbar {
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    background: hsl(var(--card));
    box-shadow: var(--shadow-card);
}

.faq-search {
    min-height: 3rem;
    border: 1px solid hsl(var(--input));
    border-radius: 0.75rem;
    background: hsl(var(--background));
    outline: none;
    transition: border-color 120ms ease, box-shadow 120ms ease, background-color 120ms ease;
}

.faq-search:focus {
    border-color: var(--teal-deep);
    background: hsl(var(--card));
    box-shadow: 0 0 0 3px rgb(13 92 117 / 15%);
}

.category-btn {
    min-height: 2.5rem;
    border: 1px solid transparent;
    border-radius: 999px;
    padding: 0.45rem 0.8rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.75rem;
    font-weight: 700;
    transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease;
}

.category-btn:hover { background: hsl(var(--muted)); color: hsl(var(--foreground)); }

.category-btn[aria-pressed="true"] {
    border-color: rgb(13 92 117 / 20%);
    background: hsl(var(--accent));
    color: var(--teal-deep);
}

.faq-section { scroll-margin-top: 6rem; }

.faq-item {
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    background: hsl(var(--card));
    box-shadow: var(--shadow-card);
}

.faq-item + .faq-item { margin-top: 0.65rem; }

.faq-item summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    list-style: none;
}

.faq-item summary::-webkit-details-marker { display: none; }

.faq-item summary:focus-visible {
    outline: 2px solid var(--teal-deep);
    outline-offset: -2px;
    border-radius: 1rem;
}

.faq-chevron {
    flex: 0 0 auto;
    color: hsl(var(--muted-foreground));
    transition: transform 120ms ease;
}

.faq-item[open] .faq-chevron { transform: rotate(180deg); color: var(--teal-deep); }

.faq-answer {
    border-top: 1px solid hsl(var(--border));
    padding: 0.85rem 1rem 1rem;
    color: hsl(var(--muted-foreground));
    font-size: 0.875rem;
    line-height: 1.65;
}

.faq-answer > * + * { margin-top: 0.75rem; }

.faq-answer a,
.doc-link {
    color: var(--teal-deep);
    font-weight: 700;
    text-decoration: underline;
    text-decoration-color: rgb(13 92 117 / 30%);
    text-underline-offset: 0.2em;
}

.faq-answer a:hover,
.doc-link:hover { text-decoration-color: var(--teal-deep); }

/* ── Sample Forms document cards ─────────────────────────────── */
.doc-card {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-height: 4.5rem;
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    background: hsl(var(--card));
    padding: 0.85rem 1rem;
    color: hsl(var(--foreground));
    box-shadow: var(--shadow-card);
    transition: border-color 120ms ease, background-color 120ms ease;
}

.doc-card:hover { border-color: var(--teal-deep); background: hsl(var(--accent) / 0.35); }

.doc-card:focus-visible { outline: 2px solid var(--teal-deep); outline-offset: 2px; }

.doc-card-icon {
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 0.8rem;
    background: hsl(var(--accent));
    color: var(--teal-deep);
}

/* ── Placeholder state, used by the CA and GA variants ───────── */
.doc-placeholder {
    border: 1px dashed hsl(var(--border));
    border-radius: 1.35rem;
    background: hsl(var(--card));
    padding: clamp(2rem, 6vw, 3.5rem) 1.25rem;
    text-align: center;
}

@media print {
    .faq-toolbar,
    .lang-toggle { display: none !important; }

    .faq-item,
    .doc-card { box-shadow: none; }

    /* Paper has no disclosure triangle to click. */
    .faq-item .faq-answer { display: block !important; }

    .faq-chevron { display: none !important; }
}

/* ── User Guide ──────────────────────────────────────────────
   The step numbering and the "getting started" cards are shared by
   the TX and GENERAL guides. */
.gs-card {
    display: block;
    border: 1px solid hsl(var(--border));
    border-radius: 1.1rem;
    background: hsl(var(--background));
    padding: 1rem;
    transition: border-color 120ms ease, background-color 120ms ease;
}

.gs-card:hover { border-color: var(--teal-deep); background: hsl(var(--accent) / 0.3); }

.gs-card:focus-visible { outline: 2px solid var(--teal-deep); outline-offset: 2px; }

.gs-step {
    display: grid;
    width: 2rem;
    height: 2rem;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 999px;
    background: var(--teal-deep);
    color: hsl(var(--primary-foreground));
    font-size: 0.8125rem;
    font-weight: 700;
}

.step-row {
    display: flex;
    align-items: flex-start;
    gap: 0.85rem;
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    background: hsl(var(--background));
    padding: 0.9rem 1rem;
}

.feature-row {
    border: 1px solid hsl(var(--border));
    border-radius: 1rem;
    background: hsl(var(--background));
    padding: 0.9rem 1rem;
}

/* Names a real button in the app, so it is styled to read as one. */
.ui-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 0.5rem;
    border: 1px solid rgb(13 92 117 / 20%);
    background: hsl(var(--accent));
    padding: 0.1rem 0.45rem;
    color: var(--teal-deep);
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

/* ── Sample Forms: state switching and download rows ─────────
   All four state blocks are rendered; one is active. The approved design
   toggles them in CSS so the chooser is instant and needs no round trip. */
.state-copy { display: none; }

.state-copy.is-active { display: block; }

.guide-layout { display: grid; grid-template-columns: minmax(0, 1fr) 15rem; align-items: start; gap: clamp(1rem, 2.5vw, 1.5rem); }

/* A download row needs its own surface: the equipment cards it sits in are
   tinted, and a transparent row on a tint reads as text, not as a thing you
   tap. */
.guide-link.is-file {
    border: 1px solid hsl(var(--border));
    background: hsl(var(--card));
}

.guide-link.is-file:hover {
    border-color: rgb(13 92 117 / 35%);
    background: hsl(var(--card));
}

.guide-link.is-file:focus-visible { outline: 2px solid var(--teal-deep); outline-offset: 2px; }

.guide-link.is-file + .guide-link.is-file { margin-top: 0.4rem; }

/* Deliberately not styled as an error. Nothing is broken - the forms are
   simply not published for that board yet. */
.forms-placeholder {
    border: 1px dashed hsl(var(--border));
    border-radius: 1.25rem;
    background: hsl(var(--background));
    padding: clamp(2rem, 6vw, 2.75rem) 1.25rem;
    text-align: center;
}

@media screen and (max-width: 58rem) {
    .guide-layout { grid-template-columns: 1fr; }

    .forms-side {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 1rem;
    }
}

@media screen and (max-width: 38rem) {
    .guide-hero { border-radius: 1.25rem; }
    .guide-section { border-radius: 1.25rem; }
    .forms-side { display: block; }
}

@media print {
    .guide-layout { display: block; }
    .forms-side { display: none; }
    .language-toggle { display: none !important; }
}
