/* ============================================================
   VUKA HANDBOOK — style.css
   Minimal, typographic, WCAG 2.2 AAA, GitHub Pages ready
   ============================================================ */

/* ── Custom Properties ─────────────────────────────────────── */
:root {
  /* Typography — all system sans */
  --font-serif: system-ui, -apple-system, "Segoe UI", helvetica, arial, sans-serif;
  --font-sans: system-ui, -apple-system, "Segoe UI", helvetica, arial, sans-serif;
  --font-mono: "SFMono-Regular", consolas, "Liberation Mono", menlo, monospace;

  /* Type scale (fluid) */
  --text-xs:   0.75rem;
  --text-sm:   0.875rem;
  --text-base: 1.0625rem;   /* ~17px */
  --text-lg:   1.25rem;
  --text-xl:   1.5rem;
  --text-2xl:  1.875rem;
  --text-3xl:  2.25rem;
  --text-4xl:  2.75rem;
  --leading-tight:  1.25;
  --leading-snug:   1.4;
  --leading-normal: 1.65;
  --leading-loose:  1.8;

  /* Colours — AAA contrast verified */
  --color-ink:        #111827;   /* 16:1 on white */
  --color-ink-muted:  #374151;   /* 10:1 on white */
  --color-ink-faint:  #6b7280;   /* 4.6:1 on white — AA only on large text */
  --color-bg:         #ffffff;
  --color-bg-subtle:  #f9fafb;
  --color-bg-hover:   #FBE8DA;
  --color-border:     #e5e7eb;
  --color-border-mid: #d1d5db;
  --color-accent:     #ed7d31;
  --color-accent-dark:#D4702C;
  --color-accent-bg:  #FDF3EC;
  --color-callout-bg: #f0fdf4;
  --color-callout-border: #86efac;
  --color-danger:     #b91c1c;
  --color-danger-bg:  #fef2f2;
  --color-comment-dot: #f59e0b;

  /* Layout */
  --sidebar-width:    280px;
  --content-max:      680px;
  --content-padding:  clamp(1.25rem, 5vw, 3rem);
  --comment-btn-gap:  2.75rem;  /* space reserved on right for comment button */
  --gap-section:      3rem;
  --gap-element:      1.25rem;

  /* Radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgb(0 0 0 / 8%), 0 1px 2px rgb(0 0 0 / 6%);
  --shadow-md: 0 4px 12px rgb(0 0 0 / 10%), 0 2px 4px rgb(0 0 0 / 6%);
  --shadow-lg: 0 10px 30px rgb(0 0 0 / 12%), 0 4px 8px rgb(0 0 0 / 6%);

  /* Transitions */
  --transition: 150ms ease;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 100%;
  scroll-behavior: smooth;
  text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-ink);
  background: var(--color-bg);
  display: flex;
  min-height: 100vh;
}

/* ── Skip link ──────────────────────────────────────────────── */
.skip-link {
  position: absolute;
  top: -100%;
  left: 1rem;
  background: var(--color-accent);
  color: #ffffff;
  padding: .5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: 600;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 1rem; }

/* ── Sidebar ────────────────────────────────────────────────── */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  overflow: hidden; /* inner sections handle their own scroll */
  background: linear-gradient(0deg, #E45C64 0%, #ED7D31 100%);
  border-right: 1px solid var(--color-border);
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 1.5rem 1.25rem;
  gap: 1.5rem;
  overflow: hidden;
}

.sidebar-header img {
    width: 100%;
    max-width: 20rem;
    height: auto;
    margin-bottom: 1rem;
}

.sidebar-label {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  margin-bottom: .25rem;
}

.sidebar-title {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: 700;
  line-height: var(--leading-snug);
  color: var(--color-ink);
}

/* Sidebar main content — scrollable, capped so footer is always visible */
.sidebar-scroll {
  overflow-y: auto;
  max-height: calc(100vh - 34rem);
  flex-shrink: 1;
  min-height: 2rem;
}

.sidebar-toc ol {
  list-style: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: .15rem;
}

.sidebar-toc a {
  display: block;
  font-size: var(--text-sm);
  color: var(--color-ink);
  text-decoration: none;
  padding: .3rem .5rem;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
}

.sidebar-toc a:hover,
.sidebar-toc a:focus-visible {
  background: var(--color-accent-bg);
  color: var(--color-ink);
  outline: none;
}

.sidebar-toc li.toc-sub > a {
  padding-left: 1.25rem;
  font-size: var(--text-xs);
}

/* Comments section */
.sidebar-comments-section {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.sidebar-section-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.sidebar-comment-count {
  font-size: var(--text-sm);
}

.sidebar-comment-list {
  list-style: none;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.sidebar-comment-item {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: .625rem .75rem;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.sidebar-comment-item:hover,
.sidebar-comment-item:focus-visible {
  border-color: var(--color-accent);
  box-shadow: var(--shadow-sm);
  outline: none;
}

.sidebar-comment-item-context {
  font-size: var(--text-xs);
  color: var(--color-ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: .2rem;
}

.sidebar-comment-item-text {
  font-size: var(--text-sm);
  color: var(--color-ink-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sidebar-comment-item-meta {
  font-size: var(--text-xs);
  color: var(--color-ink-faint);
  margin-top: .2rem;
}

/* Sidebar footer — always visible, never pushed off screen */
.sidebar-footer {
  padding-top: 1rem;
  flex-shrink: 0;
  margin-top: auto;
}

.sidebar-footer img {
    width: 10rem;
    height: auto;
    margin-bottom: 1rem;
}

.btn-survey {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  justify-content: center;
  background: var(--color-bg);
  color: var(--color-ink);
  border: none;
  border-radius: var(--radius-md);
  padding: .625rem 1rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  box-shadow: 0 4px 14px 6px rgba(143 31 36 / 20%);
}

.btn-survey:hover { background: var(--color-accent-bg); }
.btn-survey:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }

/* ── Main content ───────────────────────────────────────────── */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: var(--content-padding);
  padding-top: 3rem;
  padding-bottom: 5rem;
}

article {
  max-width: var(--content-max);
  margin: 0 auto;
}

/* ── Document header ────────────────────────────────────────── */
.doc-header {
  margin-bottom: var(--gap-section);
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--color-border);
}

.doc-draft-badge {
  display: inline-block;
  font-size: var(--text-xs);
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--color-danger);
  background: var(--color-danger-bg);
  border: 1px solid #fca5a5;
  border-radius: var(--radius-sm);
  padding: .2rem .6rem;
  margin-bottom: 1rem;
}

.doc-header h1 {
  font-family: var(--font-sans);
  font-size: clamp(var(--text-2xl), 4vw, var(--text-4xl));
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--color-ink);
  letter-spacing: -.02em;
}

/* ── Sections ───────────────────────────────────────────────── */
section {
  margin-bottom: var(--gap-section);
}

section + section {
  padding-top: var(--gap-section);
  border-top: 1px solid var(--color-border);
}

/* ── Headings ───────────────────────────────────────────────── */
h2 {
  font-family: var(--font-sans);
  font-size: clamp(var(--text-xl), 3vw, var(--text-3xl));
  font-weight: 700;
  line-height: var(--leading-tight);
  color: var(--color-ink);
  letter-spacing: -.015em;
  margin-top: 2.5rem;
  margin-bottom: 1rem;
}

h3 {
  font-family: var(--font-sans);
  font-size: clamp(var(--text-lg), 2.5vw, var(--text-xl));
  font-weight: 700;
  line-height: var(--leading-snug);
  color: var(--color-ink);
  margin-top: 2rem;
  margin-bottom: .75rem;
}

h4 {
  font-size: var(--text-base);
  font-weight: 700;
  color: var(--color-ink);
  margin-top: 1.5rem;
  margin-bottom: .5rem;
}

/* ── Body text ──────────────────────────────────────────────── */
p {
  margin-bottom: var(--gap-element);
  max-width: 68ch;
}

p:last-child { margin-bottom: 0; }

/* ── Lists ──────────────────────────────────────────────────── */
ul, ol {
  padding-left: 1.5rem;
  margin-bottom: var(--gap-element);
}

li {
  margin-bottom: .4rem;
  max-width: 65ch;
}

li:last-child { margin-bottom: 0; }

/* ── Blockquote ─────────────────────────────────────────────── */
blockquote {
  border-left: 3px solid var(--color-border-mid);
  padding: .75rem 1.25rem;
  margin: 1.5rem 0;
  color: var(--color-ink-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-loose);
  background: var(--color-bg-subtle);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

blockquote strong { color: var(--color-ink); }

/* ── Callout / In Focus box ─────────────────────────────────── */
.callout {
  background: var(--color-callout-bg);
  border: 1px solid var(--color-callout-border);
  border-radius: var(--radius-md);
  padding: 1.25rem 1.5rem;
  margin: 1.75rem 0;
}

.callout h4 {
  font-size: var(--text-sm);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #166534;
  margin-top: 0;
  margin-bottom: .75rem;
}

.callout p, .callout li { font-size: var(--text-sm); }

/* ── Signpost ───────────────────────────────────────────────── */
.signpost {
  font-size: var(--text-sm);
  color: var(--color-accent);
  font-weight: 500;
}

.signpost a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Links ──────────────────────────────────────────────────── */
a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

a:hover { color: var(--color-accent-dark); }
a:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; border-radius: 2px; }

/* ── Hover-to-comment ───────────────────────────────────────── */

/*
  Strategy: JS adds/removes .is-hovered on both the element and the
  button via mouseenter/mouseleave with a small delay, so moving the
  cursor from the text to the button never hides it.
*/
.commentable {
  position: relative;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.commentable.is-hovered {
  background: var(--color-bg-hover);
}

/* The button is absolutely positioned to the right of the element */
.comment-anchor-btn {
  position: absolute;
  right: -2.1rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.75rem;
  height: 1.75rem;
  background: var(--color-comment-dot);
  border: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
  z-index: 10;
  box-shadow: var(--shadow-sm);
}

.comment-anchor-btn svg { color: #ffffff; }

/* Show button when parent has .is-hovered class (set by JS) */
.commentable.is-hovered .comment-anchor-btn {
  opacity: 1;
  pointer-events: auto;
}

.comment-anchor-btn:hover {
  transform: translateY(-50%) scale(1.1);
}

.comment-anchor-btn:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
  opacity: 1;
  pointer-events: auto;
}

/* Comment dot indicator on elements that have comments */
.has-comment::after {
  content: '';
  position: absolute;
  top: .25rem;
  right: -2.5rem;
  width: .5rem;
  height: .5rem;
  background: var(--color-comment-dot);
  border-radius: 50%;
  pointer-events: none;
}

/* ── Dialogs ────────────────────────────────────────────────── */
dialog {
  position: fixed;
  inset: 0;
  margin: auto;
  width: min(520px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
}

dialog::backdrop {
  background: rgb(0 0 0 / 45%);
  backdrop-filter: blur(2px);
}

.dialog-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--color-ink-faint);
  padding: .25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), background var(--transition);
}

.dialog-close:hover { color: var(--color-ink); background: var(--color-border); }
.dialog-close:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }

.dialog-title {
  font-family: var(--font-serif);
  font-size: var(--text-xl);
  font-weight: 700;
  color: var(--color-ink);
  margin-bottom: .375rem;
  padding-right: 2rem;
}

.dialog-subtitle {
  font-size: var(--text-sm);
  color: var(--color-ink-muted);
  margin-bottom: 1.25rem;
}

.dialog-context-label {
  font-size: var(--text-xs);
  font-weight: 600;
  color: var(--color-ink-faint);
  background: var(--color-bg-subtle);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: .375rem .625rem;
  margin-bottom: 1rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.dialog-step[hidden] { display: none !important; }
.dialog-context-label[hidden] { display: none !important; }

.dialog-actions {
  display: flex;
  gap: .75rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* ── Form fields ────────────────────────────────────────────── */
.field-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--color-ink);
  margin-bottom: .375rem;
}

.field-input,
.field-textarea,
.field-select {
  width: 100%;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--color-ink);
  background: var(--color-bg);
  border: 1.5px solid var(--color-border-mid);
  border-radius: var(--radius-md);
  padding: .625rem .875rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
}

.field-input:focus,
.field-textarea:focus,
.field-select:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgb(29 78 216 / 15%);
}

.field-textarea { resize: vertical; min-height: 120px; }

/* ── Buttons ────────────────────────────────────────────────── */

/* Generic .btn base (used with modifier classes) */
.btn {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-md);
  padding: .625rem 1.25rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
  border: 1.5px solid transparent;
}

.btn.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
  border-color: var(--color-accent);
}
.btn.btn-primary:hover { background: var(--color-accent-dark); border-color: var(--color-accent-dark); }
.btn.btn-primary:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.btn.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn.btn-ghost {
  background: transparent;
  color: var(--color-ink-muted);
  border-color: var(--color-border-mid);
}
.btn.btn-ghost:hover { background: var(--color-bg-subtle); border-color: var(--color-ink-faint); }
.btn.btn-ghost:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }

.btn.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border-color: #fca5a5;
}
.btn.btn-danger:hover { background: #fee2e2; }
.btn.btn-danger:focus-visible { outline: 3px solid var(--color-danger); outline-offset: 2px; }

.btn.btn-full { width: 100%; justify-content: center; }

.btn-primary {
  background: var(--color-accent);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: .625rem 1.25rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.btn-primary:hover { background: var(--color-accent-dark); }
.btn-primary:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-secondary {
  background: var(--color-bg);
  color: var(--color-ink-muted);
  border: 1.5px solid var(--color-border-mid);
  border-radius: var(--radius-md);
  padding: .625rem 1.25rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  white-space: nowrap;
}

.btn-secondary:hover { background: var(--color-bg-subtle); border-color: var(--color-ink-faint); }
.btn-secondary:focus-visible { outline: 3px solid var(--color-accent); outline-offset: 2px; }

.btn-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  border: 1.5px solid #fca5a5;
  border-radius: var(--radius-md);
  padding: .625rem 1.25rem;
  font-size: var(--text-sm);
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition);
  white-space: nowrap;
}

.btn-danger:hover { background: #fee2e2; }
.btn-danger:focus-visible { outline: 3px solid var(--color-danger); outline-offset: 2px; }

/* ── Survey-specific ────────────────────────────────────────── */
.survey-progress-bar {
  height: 4px;
  background: var(--color-border);
  border-radius: 2px;
  margin-bottom: .5rem;
  overflow: hidden;
}

#survey-progress-fill {
  height: 100%;
  background: var(--color-accent);
  border-radius: 2px;
  transition: width .3s ease;
}

.survey-progress-label {
  display: block;
  font-size: var(--text-xs);
  color: var(--color-ink-faint);
  margin-bottom: 1.25rem;
}

.survey-question-title {
  font-size: var(--text-lg);
  font-weight: 700;
  line-height: var(--leading-snug);
  color: var(--color-ink);
  margin-bottom: 1.25rem;
}

.survey-question-body {
  margin-bottom: .5rem;
}

.survey-question-body .field-label {
  font-size: var(--text-base);
  font-weight: 400;
  color: var(--color-ink-muted);
  margin-bottom: 1rem;
}

/* Radio / checkbox options */
.survey-options {
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.survey-option {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .625rem .875rem;
  border: 1.5px solid var(--color-border-mid);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  font-size: var(--text-sm);
  color: var(--color-ink);
}

.survey-option:hover { border-color: var(--color-accent); background: var(--color-accent-bg); }

.survey-option input[type="radio"],
.survey-option input[type="checkbox"] {
  accent-color: var(--color-accent);
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.survey-option input:checked ~ span { font-weight: 600; }

.survey-option:has(input:checked) {
  border-color: var(--color-accent);
  background: var(--color-accent-bg);
}

/* Matrix table */
.survey-matrix {
  overflow-x: auto;
  margin-top: 1rem;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
  border: 1.5px solid var(--color-border-mid);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.matrix-table thead {
  background: var(--color-bg-subtle);
}

.matrix-table th {
  padding: .75rem .875rem;
  text-align: left;
  font-weight: 600;
  color: var(--color-ink);
  border-bottom: 1.5px solid var(--color-border-mid);
}

.matrix-table th:not(:first-child) {
  text-align: center;
}

.matrix-table tbody tr {
  border-bottom: 1px solid var(--color-border);
  transition: background var(--transition);
}

.matrix-table tbody tr:last-child {
  border-bottom: none;
}

.matrix-table tbody tr:hover {
  background: var(--color-bg-subtle);
}

.matrix-table td {
  padding: .625rem .875rem;
  vertical-align: middle;
}

.matrix-item-label {
  font-weight: 500;
  color: var(--color-ink);
  max-width: 300px;
}

.matrix-radio-cell {
  text-align: center;
  width: 80px;
}

.matrix-radio-cell input[type="radio"] {
  accent-color: var(--color-accent);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

.matrix-note-cell {
  width: 200px;
}

.matrix-note-input {
  width: 100%;
  padding: .375rem .5rem;
  border: 1.5px solid var(--color-border);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  font-family: var(--font-sans);
  color: var(--color-ink);
  transition: border-color var(--transition);
}

.matrix-note-input:focus {
  outline: none;
  border-color: var(--color-accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Done icon */
.survey-done-icon {
  display: flex;
  justify-content: center;
  margin-bottom: 1rem;
  color: #16a34a;
}

/* ── Inline error ────────────────────────────────────────────── */
.field-error {
  font-size: var(--text-xs);
  color: var(--color-danger);
  margin-top: .25rem;
  display: none;
}

.field-error.visible { display: block; }

/* ── Toast notification ─────────────────────────────────────── */
#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--color-ink);
  color: #ffffff;
  font-size: var(--text-sm);
  padding: .625rem 1rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  z-index: 2000;
  opacity: 0;
  transform: translateY(.5rem);
  transition: opacity .2s ease, transform .2s ease;
  pointer-events: none;
}

#toast.show { opacity: 1; transform: translateY(0); }

/* ── Text-selection comment tooltip ───────────────────────── */
.sel-comment-tooltip {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  background: var(--color-ink);
  color: #ffffff;
  font-size: var(--text-xs);
  font-weight: 600;
  font-family: var(--font-sans);
  padding: .3rem .65rem;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  z-index: 500;
  transition: background var(--transition);

  /* Positioned by JS via inline style */
}

.sel-comment-tooltip:hover {
  background: var(--color-accent);
}

.sel-comment-tooltip svg {
  flex-shrink: 0;
}

/* ── Responsive: collapse sidebar on mobile ───────────────── */
@media (width <= 768px) {
  body { flex-direction: column; }

  #sidebar {
    position: static;
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
    overflow: visible;
  }

  .sidebar-inner {
    padding: 1rem;
    gap: 1rem;
  }

  .sidebar-comments-section { display: none; }

  #main-content {
    margin-left: 0;
    padding: 1.25rem 1rem 4rem;
  }

  .comment-anchor-btn {
    right: -1.75rem;
    width: 1.5rem;
    height: 1.5rem;
  }
}

/* ── Handbook resource link ─────────────────────────────────── */
article p:has(> a > img) {
  margin-top: 3rem;
  text-align: center;
}

article a > img {
  max-width: 200px;
  height: auto;
  transition: transform 0.2s ease;
}

article a:hover > img {
  transform: scale(1.05);
}

/* ── Print ──────────────────────────────────────────────────── */
@media print {
  #sidebar, .comment-anchor-btn, dialog, #toast { display: none !important; }
  #main-content { margin-left: 0; }
  body { font-size: 11pt; }
  h2 { font-size: 18pt; }
  h3 { font-size: 14pt; }
}

/* ── Focus visible global ───────────────────────────────────── */
:focus-visible {
  outline: 3px solid var(--color-accent);
  outline-offset: 2px;
}

/* ── Language Picker ───────────────────────────────────────── */
.language-picker {
  position: relative;
  margin-bottom: 1rem;
}

.lang-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.375rem 0.625rem;
  border: 1px solid var(--color-border-mid);
  border-radius: 0.375rem;
  background: var(--color-bg);
  color: var(--color-ink);
  font-size: var(--text-sm);
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
}

.lang-toggle:hover {
  background: var(--color-bg-subtle);
  border-color: var(--color-accent);
}

.lang-toggle[aria-expanded="true"] {
  background: var(--color-bg-subtle);
  border-color: var(--color-accent);
}

.lang-toggle svg {
  flex-shrink: 0;
}

.lang-menu {
  position: absolute;
  top: calc(100% + 0.25rem);
  left: 0;
  z-index: 100;
  min-width: 10rem;
  margin: 0;
  padding: 0.25rem;
  list-style: none;
  border: 1px solid var(--color-border-mid);
  border-radius: 0.5rem;
  background: var(--color-bg);
  box-shadow: 0 4px 12px rgb(0 0 0 / 10%);
}

.lang-option {
  display: block;
  padding: 0.5rem 0.75rem;
  border-radius: 0.375rem;
  color: var(--color-ink);
  font-size: var(--text-sm);
  text-decoration: none;
  transition: background 150ms ease;
}

.lang-option:hover {
  background: var(--color-bg-subtle);
}

.lang-option.active {
  background: var(--color-accent-bg);
  color: var(--color-accent-dark);
  font-weight: 600;
}

/* RTL support for Arabic */
[dir="rtl"] {
  text-align: right;
}

[dir="rtl"] #sidebar {
  left: auto;
  right: 0;
  border-right: none;
  border-left: 1px solid var(--color-border);
}

[dir="rtl"] #main-content {
  margin-left: 0;
  margin-right: var(--sidebar-width);
}

[dir="rtl"] .home-language-picker {
  left: 1.5rem;
  right: unset;
}

[dir="rtl"] .lang-menu {
  left: auto;
  right: 0;
}

/* ── Homepage Styles ──────────────────────────────────────────── */
.home-body {
  background: #f8fafc;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  margin: 0;
  padding: 1rem;
}

.home-container {
  max-width: 800px;
  width: 100%;
  background: white;
  padding: 1.5rem;
  border-radius: 12px;
  box-shadow: 0 4px 6px -1px rgb(0 0 0 / 10%), 0 2px 4px -2px rgb(0 0 0 / 10%);
  position: relative;
}

@media (width >= 768px) {
    .home-body {
        padding: 2rem;
    }

    .home-container {
        padding: 3rem;
    }
}

.home-language-picker {
  position: absolute;
  top: 1.5rem;
  right: 1.5rem;
}

.home-header {
  margin-bottom: 2rem;
}

.home-title {
  font-size: 2.5rem;
  color: #1e293b;
  margin-bottom: 0.5rem;
  font-weight: 800;
  font-family: system-ui, -apple-system, sans-serif;
}

.home-subtitle {
  color: #64748b;
  margin-bottom: 0;
  font-size: 1.125rem;
  font-family: system-ui, -apple-system, sans-serif;
}

.home-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}

.home-card {
  display: block;
  text-decoration: none;
  padding: 1.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  transition: all 0.2s;
  color: inherit;
}

.home-card:hover {
    border-color: #ed7d31;
    background: #FDF3EC;
  transform: translateY(-2px);
}

.home-card-title {
  margin: 0 0 0.5rem;
  color: #D4702C;
  font-size: 1.25rem;
  font-family: system-ui, -apple-system, sans-serif;
}

.home-card-description {
  margin: 0;
  color: #475569;
  line-height: 1.5;
  font-family: system-ui, -apple-system, sans-serif;
}

@media (width <= 768px) {
  .home-language-picker {
    position: static;
    margin-bottom: 1.5rem;
  }
}
