/* ============================================================
   Iris Patents — portfolio site styles
   Typography and palette adapted from portfolio_summary.html,
   extended for full-length disclosure documents and navigation.
   ============================================================ */

/* Iris Labs brand palette — see brand colour reference image.
   All colours used on the site are sourced from this palette. */
:root {
  /* Text */
  --ink: #000000;                  /* TEXT COLOUR / BLACK 100 */
  --muted: #5A5A5A;                /* GREY 02 60 */
  --muted-strong: #3F3F3F;         /* GREY 01 80 */

  /* Brand accents */
  --accent: #165E53;               /* BRAND COLOUR 01 — primary forest teal */
  --accent-soft: #7FAF9E;          /* BRAND COLOUR 02 — softer mint */
  --accent-darker: #003D36;        /* FOREST TEAL 100 — for hover states */
  --slate: #3D5A60;                /* SLATE SEA 60 — alternative brand tone */

  /* Surfaces */
  --bg: #FFFFFF;                   /* PURE WHITE 10 — primary page surface */
  --bg-soft: #B7C9C8;              /* FROSTED MINT 20 — callouts, pull quotes, banners */
  --bg-page: #D9D9D9;              /* BACKGROUND — login page surround */
  --bg-code: #CFCFCF;              /* UI BACKGROUND LIGHTEST — code blocks */

  /* Borders */
  --rule: #CFCFCF;                 /* UI BACKGROUND LIGHTEST */
  --rule-strong: #A6A6A6;          /* GREY 40 */

  /* States */
  --success: #97C45C;              /* SUCCESS AFFIRMATIVE */
  --success-dark: #5A7A36;         /* derived darker tone for success text */
  --error: #B61B2E;                /* ERROR NEGATIVE */
  --alert: #E65F2F;                /* ALERT */
  --warning: #E59045;              /* WARNING */
  --ui-blue: #3A6F97;              /* UI — secondary blue */

  /* Legacy alias — kept for backward references */
  --sidebar-bg: #FFFFFF;
}

* { box-sizing: border-box; }
html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: "Iowan Old Style", "Georgia", "Times New Roman", serif;
  color: var(--ink);
  line-height: 1.55;
  background: #fff;
  margin: 0;
}

/* ------------------------------------------------------------ */
/* Layout — top bar, sidebar, main, right rail                  */
/* ------------------------------------------------------------ */

.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr) 260px;
  grid-template-rows: auto 1fr;
  min-height: 100vh;
}

header.topbar {
  grid-column: 1 / -1;
  border-bottom: 2px solid var(--ink);
  padding: 0.7rem 1.5rem;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  background: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}
header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--ink);
}
header.topbar .brand-logo {
  display: block;
  height: 24px;
  width: auto;
}
header.topbar .brand-text {
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.005em;
}
header.topbar .meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}
header.topbar .topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}
header.topbar .download-btn {
  font-size: 0.82rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.25rem 0.65rem;
  border: 1px solid var(--accent);
  border-radius: 3px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  white-space: nowrap;
}
header.topbar .download-btn:hover {
  background: var(--accent);
  color: #fff;
}
header.topbar .logout-link {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.03em;
  white-space: nowrap;
}
header.topbar .logout-link:hover { color: var(--ink); text-decoration: underline; }

/* ------------------------------------------------------------ */
/* Login page                                                   */
/* ------------------------------------------------------------ */

body.login-body {
  background: var(--bg-page);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  margin: 0;
  padding: 2rem 1rem;
}
.login-card {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 2.2rem 2.2rem 1.6rem;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 1px 12px rgba(0,0,0,0.04);
}
.login-logo {
  display: block;
  width: 280px;
  max-width: 100%;
  height: auto;
  margin: 0 auto 0.9rem;
}
.login-card h1.login-product {
  font-size: 1.4rem;
  margin: 0 0 0.2rem;
  color: var(--accent);
  letter-spacing: -0.005em;
  text-align: center;
}
.login-card h1 {
  font-size: 1.4rem;
  margin: 0 0 0.2rem;
  color: var(--accent);
  letter-spacing: -0.005em;
}
.login-sub {
  font-size: 0.88rem;
  color: var(--muted);
  font-style: italic;
  margin: 0 0 1.5rem;
  text-align: center;
}
.login-error {
  background: rgba(182, 27, 46, 0.08);
  color: var(--error);
  border-left: 3px solid var(--error);
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  margin: 0 0 1rem;
  border-radius: 0 3px 3px 0;
}
.login-card form label {
  display: block;
  margin-bottom: 0.9rem;
  font-size: 0.82rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-weight: 600;
}
.login-card form input[type="text"],
.login-card form input[type="password"] {
  display: block;
  width: 100%;
  font: inherit;
  font-size: 1rem;
  color: var(--ink);
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  margin-top: 0.3rem;
  background: #fff;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
  box-sizing: border-box;
}
.login-card form input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(22, 94, 83, 0.15);
}
.login-card form button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.55rem 1.2rem;
  cursor: pointer;
  margin-top: 0.4rem;
  transition: background 0.12s;
  width: 100%;
}
.login-card form button:hover { background: var(--accent-darker); }
.login-note {
  margin: 1.4rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
  text-align: center;
}

aside.sidebar {
  border-right: 1px solid var(--rule);
  background: var(--sidebar-bg);
  padding: 1.5rem 1rem 2rem;
  font-size: 0.92rem;
  overflow-y: auto;
  max-height: calc(100vh - 50px);
  position: sticky;
  top: 50px;
  align-self: start;
}
aside.sidebar h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 1.2rem 0 0.3rem;
  font-weight: 700;
}
aside.sidebar h2:first-of-type { margin-top: 0; }
aside.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
aside.sidebar li { margin: 0.15rem 0; }
aside.sidebar a {
  color: var(--ink);
  text-decoration: none;
  display: block;
  padding: 0.18rem 0.5rem;
  border-radius: 3px;
  transition: background 0.12s;
}
aside.sidebar a:hover { background: var(--bg-soft); }
aside.sidebar a.active {
  background: #fff;
  color: var(--accent);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}

/* Nested Leads tree — group label + indented children */
aside.sidebar ul.lead-tree { margin: 0; padding: 0; }
aside.sidebar li.lead-group {
  margin: 0.4rem 0 0.2rem;
  list-style: none;
}
aside.sidebar .lead-group-label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink);
  padding: 0.18rem 0.5rem;
  letter-spacing: -0.005em;
}
aside.sidebar ul.lead-children {
  margin: 0.1rem 0 0.2rem 0.4rem;
  padding-left: 0.6rem;
  border-left: 1px solid var(--rule);
}
aside.sidebar ul.lead-children li { margin: 0.1rem 0; }
aside.sidebar ul.lead-children a {
  font-size: 0.88rem;
  color: var(--muted);
  padding: 0.16rem 0.5rem;
}
aside.sidebar ul.lead-children a:hover { color: var(--ink); }
aside.sidebar ul.lead-children a.active {
  color: var(--accent);
  background: #fff;
  font-weight: 600;
}

main.doc {
  padding: 2.5rem 2.5rem 6rem;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}

aside.rightrail {
  border-left: 1px solid var(--rule);
  padding: 1.5rem 1.2rem 2rem;
  font-size: 0.85rem;
  overflow-y: auto;
  max-height: calc(100vh - 50px);
  position: sticky;
  top: 50px;
  align-self: start;
}
aside.rightrail h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.5rem;
  font-weight: 700;
}
aside.rightrail .toc { list-style: none; margin: 0; padding: 0; }
aside.rightrail .toc li { margin: 0.18rem 0; }
aside.rightrail .toc a {
  color: var(--ink);
  text-decoration: none;
  display: block;
  padding: 0.1rem 0.4rem;
  border-left: 2px solid transparent;
  line-height: 1.35;
}
aside.rightrail .toc a:hover { color: var(--accent); border-left-color: var(--accent-soft); }
aside.rightrail .toc a.active { color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
aside.rightrail .toc .lvl-2 { padding-left: 0.4rem; }
aside.rightrail .toc .lvl-3 { padding-left: 1.2rem; font-size: 0.82rem; }
aside.rightrail .toc .lvl-4 { padding-left: 2rem; font-size: 0.78rem; color: var(--muted); }

/* ------------------------------------------------------------ */
/* Document typography                                          */
/* ------------------------------------------------------------ */

main.doc h1 {
  font-size: 1.7rem;
  letter-spacing: -0.01em;
  margin: 0 0 1rem;
  line-height: 1.25;
  border-bottom: 2px solid var(--ink);
  padding-bottom: 0.7rem;
}
main.doc h2 {
  font-size: 1.32rem;
  margin: 2.4rem 0 0.5rem;
  color: var(--accent);
  letter-spacing: -0.005em;
  scroll-margin-top: 70px;
}
main.doc h3 {
  font-size: 1.05rem;
  margin: 1.6rem 0 0.4rem;
  font-variant: small-caps;
  letter-spacing: 0.04em;
  color: var(--ink);
  scroll-margin-top: 70px;
}
main.doc h4 {
  font-size: 0.95rem;
  margin: 1.2rem 0 0.3rem;
  color: var(--accent-soft);
  font-style: italic;
  scroll-margin-top: 70px;
}
main.doc h5, main.doc h6 {
  font-size: 0.9rem;
  margin: 1rem 0 0.3rem;
  color: var(--muted);
  scroll-margin-top: 70px;
}

main.doc p { margin: 0.65rem 0; }
main.doc ul, main.doc ol { margin: 0.4rem 0 0.8rem; padding-left: 1.4rem; }
main.doc li { margin: 0.25rem 0; }

main.doc strong { font-weight: 600; }
main.doc em { font-style: italic; }

main.doc blockquote {
  background: var(--bg-soft);
  border-left: 3px solid var(--accent);
  padding: 0.8rem 1rem;
  margin: 1rem 0;
  font-style: italic;
  color: var(--ink);
}
main.doc blockquote p:first-child { margin-top: 0; }
main.doc blockquote p:last-child { margin-bottom: 0; }

main.doc hr {
  border: none;
  border-top: 1px solid var(--rule);
  margin: 2rem 0;
}

main.doc code {
  background: var(--bg-code);
  padding: 0.1rem 0.35rem;
  border-radius: 3px;
  font-size: 0.92em;
  font-family: "SF Mono", Monaco, Consolas, monospace;
}
main.doc pre {
  background: var(--bg-code);
  padding: 0.8rem 1rem;
  border-radius: 4px;
  overflow-x: auto;
}
main.doc pre code { background: none; padding: 0; }

/* Mermaid diagram blocks — centred, with breathing room */
main.doc .mermaid {
  display: flex;
  justify-content: center;
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 1.2rem 0.6rem;
  margin: 1.2rem 0;
  overflow-x: auto;
}
main.doc .mermaid svg { max-width: 100%; height: auto; }

/* tables */
main.doc table {
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
  width: 100%;
}
main.doc th, main.doc td {
  border: 1px solid var(--rule);
  padding: 0.5rem 0.7rem;
  vertical-align: top;
  text-align: left;
}
main.doc th {
  background: var(--bg-soft);
  font-weight: 600;
  letter-spacing: 0.01em;
}

/* ------------------------------------------------------------ */
/* Headings — anchor permalinks (#)                             */
/* ------------------------------------------------------------ */

/* Permalink chain icon next to every heading. Always faintly visible so
   reviewers know each paragraph is shareable; click copies the URL to the
   clipboard (handled in app.js). */
.header-anchor {
  margin-left: 0.5rem;
  color: var(--accent-soft);
  text-decoration: none;
  opacity: 0.6;
  transition: opacity 0.15s, color 0.15s;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  cursor: pointer;
  position: relative;
}
.header-anchor svg {
  width: 14px;
  height: 14px;
  display: block;
}
h2 .header-anchor svg,
h3 .header-anchor svg { width: 13px; height: 13px; }
h4 .header-anchor svg,
h5 .header-anchor svg,
h6 .header-anchor svg { width: 12px; height: 12px; }
h1:hover .header-anchor,
h2:hover .header-anchor,
h3:hover .header-anchor,
h4:hover .header-anchor,
h5:hover .header-anchor,
h6:hover .header-anchor,
.header-anchor:hover { opacity: 1; color: var(--accent); }

/* Toast that appears after the URL is copied. */
.copy-toast {
  position: absolute;
  top: 50%;
  left: calc(100% + 6px);
  transform: translateY(-50%);
  background: var(--ink);
  color: #fff;
  font-family: "Iowan Old Style", "Georgia", "Times New Roman", serif;
  font-size: 0.78rem;
  font-weight: 400;
  font-style: normal;
  font-variant: normal;
  letter-spacing: 0;
  text-transform: none;
  padding: 0.18rem 0.55rem;
  border-radius: 3px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease-out;
}
.copy-toast.show { opacity: 1; }

/* ------------------------------------------------------------ */
/* Cross-reference links (resolved by build.js)                 */
/* ------------------------------------------------------------ */

a.xref {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px dotted var(--accent-soft);
  padding-bottom: 1px;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
a.xref:hover {
  color: #fff;
  background: var(--accent);
  border-bottom-color: var(--accent);
  border-radius: 2px;
}
a.xref.broken {
  color: var(--muted);
  border-bottom-style: dashed;
  border-bottom-color: var(--muted);
  cursor: help;
}
a.xref.broken:hover {
  background: var(--muted);
  color: #fff;
  border-bottom-color: var(--muted);
}

/* general links — excludes "button-style" links so their own styling wins */
main.doc a:not(.xref):not(.header-anchor):not(.card-btn):not(.primary-link) {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
main.doc a:not(.xref):not(.header-anchor):not(.card-btn):not(.primary-link):hover {
  border-bottom-color: var(--accent);
}

/* ------------------------------------------------------------ */
/* Index (home) page                                            */
/* ------------------------------------------------------------ */

.index-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.2rem;
  margin: 1.5rem 0;
}
.index-card {
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 1.1rem 1.3rem;
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
}
.index-card:hover {
  border-color: var(--accent-soft);
  box-shadow: 0 1px 4px rgba(22, 94, 83, 0.10);
}
.index-card h3 {
  margin: 0 0 0.3rem;
  font-size: 1.05rem;
  font-variant: normal;
  letter-spacing: -0.005em;
  color: var(--accent);
}
.index-card h3 a {
  color: inherit;
  text-decoration: none;
}
.index-card .tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.index-card .desc {
  font-size: 0.92rem;
  color: var(--ink);
  margin: 0;
}
.index-card .meta-line {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.6rem;
  font-style: italic;
}

/* Big tappable buttons at the bottom of each index card. Three across for
   lead cards; one across for existing-IP cards. Pinned to the bottom of the
   card so all cards in a row line up regardless of description length. */
.index-card .card-actions {
  margin-top: auto;
  padding-top: 0.95rem;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.45rem;
}
.index-card .card-actions.card-actions-single {
  grid-template-columns: 1fr;
}
.card-btn {
  display: block;
  text-align: center;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: -0.005em;
  padding: 0.65rem 0.4rem;
  border-radius: 4px;
  color: var(--accent);
  background: var(--bg-soft);
  border: 1.5px solid var(--accent);
  transition: background 0.12s, color 0.12s, transform 0.05s;
  line-height: 1.15;
}
.card-btn:hover {
  background: var(--accent);
  color: #fff;
}
.card-btn:active { transform: translateY(1px); }

@media (max-width: 760px) {
  .index-card .card-actions {
    /* Stack vertically on narrow phones so each button is a comfortable tap target */
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.4rem;
  }
  .card-btn {
    padding: 0.7rem 0.3rem;
    font-size: 0.88rem;
  }
}
@media (max-width: 420px) {
  .index-card .card-actions { grid-template-columns: 1fr; }
}

.section-heading {
  font-size: 1.15rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink);
  font-weight: 700;
  margin: 2.8rem 0 0.9rem;
  padding-bottom: 0.55rem;
  border-bottom: 2px solid var(--accent);
}
.section-heading:first-of-type { margin-top: 1.5rem; }

/* Issues panel on the index page */
.issues-panel { margin: 0.5rem 0 2.5rem; }
.issues-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  margin-bottom: 0.7rem;
}
.issues-summary {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}
.issues-toggle {
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--bg-soft);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0.35rem 0.8rem;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.issues-toggle:hover { background: var(--accent); color: #fff; }
.issues-toggle[aria-pressed="true"] {
  background: var(--accent);
  color: #fff;
}
.issues-toggle[aria-pressed="true"]:hover {
  background: var(--accent-darker);
  border-color: var(--accent-darker);
}

.issues-list {
  list-style: none;
  padding: 0;
  margin: 0;
  border-top: 1px solid var(--rule);
}
.issue-item {
  padding: 0.7rem 0.2rem;
  border-bottom: 1px solid var(--rule);
}
.issues-panel.hide-resolved .issue-closed { display: none; }

.issue-row {
  display: flex;
  align-items: flex-start;
  gap: 0.7rem;
}
.issue-state-pill {
  flex-shrink: 0;
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  min-width: 70px;
  text-align: center;
}
.issue-open .issue-state-pill {
  background: var(--accent);
  color: #fff;
}
.issue-closed .issue-state-pill {
  background: var(--bg-soft);
  color: var(--muted);
  border: 1px solid var(--rule);
}
.issue-closed .issue-title { color: var(--muted); }
.issue-closed .issue-excerpt { color: var(--muted); }

.issue-body { flex: 1; min-width: 0; }
.issue-title {
  font-weight: 600;
  color: var(--ink);
  line-height: 1.35;
  margin-bottom: 0.15rem;
}
.issue-excerpt {
  font-size: 0.88rem;
  color: var(--ink);
  line-height: 1.4;
  margin: 0.1rem 0 0.25rem;
  /* clamp to two lines so excerpts don't dominate the list */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.issue-meta {
  font-size: 0.78rem;
  color: var(--muted);
  font-style: italic;
}
.issue-filer {
  font-style: normal;
  font-weight: 600;
  color: var(--ink);
}
.issue-label-chip {
  display: inline-block;
  font-style: normal;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-soft);
  color: var(--accent);
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  margin-left: 0.3rem;
}

.issues-empty {
  padding: 1.2rem;
  background: var(--bg-soft);
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}

@media (max-width: 600px) {
  .issue-state-pill { min-width: 60px; font-size: 0.65rem; padding: 0.2rem 0.45rem; }
}

/* ------------------------------------------------------------ */
/* Lead landing page — banner, primary link, callout, back link */
/* ------------------------------------------------------------ */

.lead-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin: -0.5rem 0 1.5rem;
  padding: 0.6rem 0.9rem;
  background: var(--bg-soft);
  border-left: 3px solid var(--accent);
  border-radius: 0 3px 3px 0;
}
.lead-banner-lead {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  font-weight: 600;
}
.lead-banner-actions { font-size: 0.95rem; }

a.primary-link {
  display: inline-block;
  color: var(--accent);
  text-decoration: none;
  font-weight: 600;
  padding: 0.35rem 0.8rem;
  border: 1.5px solid var(--accent);
  border-radius: 4px;
  background: var(--bg-soft);
  transition: background 0.12s, color 0.12s;
}
a.primary-link:hover {
  background: var(--accent);
  color: #fff;
}

.back-link {
  margin: -0.5rem 0 1.2rem;
  font-size: 0.88rem;
}
.back-link a {
  color: var(--accent);
  text-decoration: none;
  font-style: italic;
}
.back-link a:hover { text-decoration: underline; }

.callout {
  background: var(--bg-soft);
  border: 1px solid var(--rule);
  border-left: 3px solid var(--accent-soft);
  padding: 0.9rem 1.1rem;
  margin: 1.2rem 0;
  border-radius: 0 3px 3px 0;
}
.callout strong { color: var(--accent); }

.patent-actions {
  margin: 0 0 1.5rem;
}

/* ------------------------------------------------------------ */
/* Ask-a-question button (injected after h2/h3 in landing/disc) */
/* ------------------------------------------------------------ */

.ask-action {
  margin: 0.1rem 0 1rem;
}
.ask-btn {
  font: inherit;
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--bg-soft);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.25rem 0.8rem;
  cursor: pointer;
  font-weight: 600;
  transition: color 0.12s, border-color 0.12s, background 0.12s;
}
.ask-btn:hover,
.ask-btn:focus-visible {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
  outline: none;
}
.ask-btn:focus-visible {
  box-shadow: 0 0 0 2px rgba(22, 94, 83, 0.18);
}

/* ------------------------------------------------------------ */
/* Modal overlay + chat dialog                                  */
/* ------------------------------------------------------------ */

body.modal-open { overflow: hidden; }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 100;
}
.modal-overlay[hidden] { display: none; }

.modal {
  background: #fff;
  border-radius: 6px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.25);
  max-width: 640px;
  width: 100%;
  display: flex;
  flex-direction: column;
}
.modal-chat {
  max-height: min(80vh, 720px);
}

.modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.2rem 0.7rem;
  border-bottom: 1px solid var(--rule);
}
.modal-title {
  font-weight: 600;
  font-size: 1rem;
  color: var(--ink);
  letter-spacing: -0.005em;
}
.modal-context {
  font-size: 0.82rem;
  color: var(--muted);
  font-style: italic;
  margin-top: 0.15rem;
}
.modal-close {
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  color: var(--muted);
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 0 0.3rem;
  margin: -0.2rem -0.3rem 0 0;
}
.modal-close:hover { color: var(--ink); }

.modal-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.2rem;
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: var(--bg);
  min-height: 160px;
}

.chat-msg {
  max-width: 80%;
  padding: 0.55rem 0.85rem;
  border-radius: 10px;
  font-size: 0.93rem;
  line-height: 1.45;
  word-wrap: break-word;
  white-space: pre-wrap;   /* preserve newlines in the DRAFT ISSUE layout */
}
.chat-assistant {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--rule);
  color: var(--ink);
  border-bottom-left-radius: 2px;
}
.chat-user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 2px;
}
.chat-system {
  align-self: stretch;
  max-width: none;
  background: var(--bg-soft);
  border: 1px solid var(--accent-soft);
  color: var(--ink);
  font-size: 0.88rem;
  text-align: center;
}
.chat-system a { color: var(--accent); font-weight: 600; }
.chat-user a { color: #fff; text-decoration: underline; }

.modal-status {
  padding: 0.35rem 1.2rem;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
  border-top: 1px solid var(--rule);
  min-height: 1.2rem;
}
.modal-status.info    { color: var(--accent); }
.modal-status.success { color: var(--success-dark); }
.modal-status.error   { color: var(--error); font-style: normal; }
.modal-status a { color: inherit; text-decoration: underline; }

.modal-input {
  display: flex;
  gap: 0.6rem;
  padding: 0.7rem 1.2rem;
  border-top: 1px solid var(--rule);
  background: #fff;
}
.modal-input textarea {
  flex: 1;
  font: inherit;
  font-size: 0.95rem;
  resize: none;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--rule);
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  min-height: 44px;
  max-height: 120px;
}
.modal-input textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(22, 94, 83, 0.15);
}
.modal-input textarea:disabled {
  background: var(--bg-soft);
  color: var(--muted);
  cursor: not-allowed;
}
.modal-input button.submit {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 0 1.2rem;
  cursor: pointer;
  transition: background 0.12s;
}
.modal-input button.submit:hover:not(:disabled) {
  background: var(--accent-darker);
}
.modal-input button.submit:disabled {
  background: var(--muted);
  border-color: var(--muted);
  cursor: not-allowed;
}

.modal-footnote {
  padding: 0.4rem 1.2rem 0.9rem;
  font-size: 0.72rem;
  color: var(--muted);
  font-style: italic;
  border-top: 1px solid var(--rule);
  background: var(--bg-soft);
  border-radius: 0 0 6px 6px;
}
.modal-footnote code {
  font-style: normal;
  font-size: 0.92em;
  padding: 0 0.25rem;
  background: rgba(22, 94, 83, 0.10);
  border-radius: 2px;
}

/* ------------------------------------------------------------ */
/* Source-paragraph modal (Mermaid flow-chart → disclosure)     */
/* ------------------------------------------------------------ */

.modal-para {
  max-width: 760px;
  max-height: min(85vh, 820px);
}
.modal-para-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem 1.4rem 0.5rem;
  background: var(--bg);
  font-size: 0.95rem;
  line-height: 1.55;
  color: var(--ink);
}
.modal-para-content > :first-child { margin-top: 0; }
.modal-para-content h1,
.modal-para-content h2,
.modal-para-content h3,
.modal-para-content h4,
.modal-para-content h5,
.modal-para-content h6 {
  margin-top: 1.0rem;
  margin-bottom: 0.4rem;
  color: var(--ink);
}
.modal-para-content h1 { font-size: 1.15rem; }
.modal-para-content h2 { font-size: 1.08rem; }
.modal-para-content h3 { font-size: 1.00rem; }
.modal-para-content h4 { font-size: 0.92rem; }
.modal-para-content p { margin: 0.5rem 0; }
.modal-para-content ul,
.modal-para-content ol { margin: 0.5rem 0; padding-left: 1.4rem; }
.modal-para-content li { margin: 0.2rem 0; }
.modal-para-content code {
  font-size: 0.88em;
  background: rgba(22, 94, 83, 0.08);
  padding: 0 0.25em;
  border-radius: 2px;
}
.modal-para-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.6rem 0;
  font-size: 0.9rem;
}
.modal-para-content th,
.modal-para-content td {
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}
.modal-para-content th { background: var(--bg-soft); }
.modal-para-content blockquote {
  border-left: 3px solid var(--accent-soft);
  margin: 0.6rem 0;
  padding: 0.1rem 0.8rem;
  color: var(--muted);
}
.modal-para-content a { color: var(--accent); }
.modal-para-content .ask-btn,
.modal-para-content .header-anchor { display: none !important; }

.para-modal-open {
  color: var(--accent);
  text-decoration: none;
  font-style: normal;
  font-weight: 500;
}
.para-modal-open:hover { text-decoration: underline; }

/* Mermaid nodes that have a click directive get role=button via securityLevel=loose. */
.mermaid g.node[role="button"] { cursor: pointer; }
.mermaid g.node[role="button"]:hover > rect,
.mermaid g.node[role="button"]:hover > polygon,
.mermaid g.node[role="button"]:hover > path,
.mermaid g.node[role="button"]:hover > circle,
.mermaid g.node[role="button"]:hover > ellipse {
  stroke: var(--accent);
  stroke-width: 2px;
}

@media (max-width: 600px) {
  .modal-overlay { padding: 0; }
  .modal { border-radius: 0; max-height: 100vh; height: 100vh; max-width: none; }
}

/* ------------------------------------------------------------ */
/* Responsive                                                   */
/* ------------------------------------------------------------ */

@media (max-width: 1100px) {
  .app { grid-template-columns: 220px minmax(0, 1fr); }
  aside.rightrail { display: none; }
}
@media (max-width: 760px) {
  /* Hide the sidebar on mobile entirely — the index-page cards (each with
     Main Quest / Disclosure / Flow Charts buttons) are the navigation. Tap
     the brand in the topbar to return to the index from any page. */
  .app { grid-template-columns: 1fr; }
  aside.sidebar { display: none; }
  main.doc { padding: 1.5rem 1.2rem 4rem; }

  /* Compact topbar — keep brand on the left, Markdown + Sign out on the right
     without overlap on narrow viewports. */
  header.topbar { padding: 0.6rem 0.9rem; }
  header.topbar .topbar-actions { gap: 0.7rem; }
  header.topbar .download-btn {
    font-size: 0.78rem;
    padding: 0.2rem 0.55rem;
  }
  header.topbar .brand-text { font-size: 1rem; }
}
@media (max-width: 380px) {
  /* On the narrowest phones, shrink the brand text and the Markdown button
     label so all three topbar elements stay on one line. */
  header.topbar { padding: 0.55rem 0.7rem; }
  header.topbar .topbar-actions { gap: 0.55rem; }
  header.topbar .brand-text { font-size: 0.95rem; }
  header.topbar .download-btn { font-size: 0.74rem; padding: 0.18rem 0.45rem; }
  header.topbar .logout-link { font-size: 0.74rem; }
}

/* ------------------------------------------------------------ */
/* Print                                                        */
/* ------------------------------------------------------------ */

@media print {
  .app { display: block; }
  header.topbar, aside.sidebar, aside.rightrail { display: none; }
  main.doc { max-width: none; padding: 0; }
}
