/* EZQueue Manual. Built on the app's own design tokens (theme/tokens.css, copied from
   ez_q_frontend/src/core/theme/tokens.css at build time), so every app theme and light/dark mode works.
   Patterns copy the app: Sidebar, PageHeader, Card, Button, StatCard. No colours are hard-coded here.
   tokens.css resets all margins and paddings, so spacing is set explicitly below. */

/* tokens.css sets overflow-x: hidden on html and body. That makes body its own scroll box, so the
   sticky sidebar and top bar scrolled away with the page. clip also stops sideways scrolling but
   does not create a scroll box, so sticky works against the window. */
html,
body {
  overflow-x: clip;
}

/* Jump links (contents, "see …") stop below the sticky top bar */
[id] {
  scroll-margin-top: calc(var(--topbar-height) + var(--space-5));
}

/* ── Shell: sidebar + main, like the app ─────────────────────────────── */
.skip-link {
  position: absolute;
  left: -999px;
  top: var(--space-3);
  z-index: var(--z-toast);
  padding: var(--space-3) var(--space-5);
  background: var(--color-surface);
  color: var(--color-text);
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  left: var(--space-3);
}

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  min-height: 100dvh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  border-right: 1px solid var(--color-border);
  z-index: var(--z-sidebar);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-4);
  color: var(--color-sidebar-text);
}

.sidebar__brand:hover {
  opacity: 1;
}

.sidebar__logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.sidebar__logo--dark,
[data-mode="dark"] .sidebar__logo--light {
  display: none;
}

[data-mode="dark"] .sidebar__logo--dark {
  display: block;
}

.sidebar__brand-text {
  display: flex;
  flex-direction: column;
  line-height: var(--leading-tight);
}

.sidebar__brand-name {
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  font-size: var(--text-body-lg);
}

.sidebar__brand-role {
  font-size: var(--text-caption);
  opacity: 0.8;
}

.sidebar__nav {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--space-6);
}

.sidebar__section {
  margin: var(--space-5) var(--space-5) var(--space-2);
  font-size: var(--text-overline);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.75;
}

.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  margin: var(--space-1) var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: var(--shadow-border-width) solid transparent;
  border-radius: var(--radius-sm);
  color: var(--color-sidebar-text);
  font-size: var(--text-body);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-snug);
}

.sidebar__item:hover {
  opacity: 1;
  background: var(--color-sidebar-hover);
}

.sidebar__item--active,
.sidebar__item--active:hover {
  background: var(--color-sidebar-active);
  color: var(--color-sidebar-active-text);
  border-color: var(--color-sidebar-active-text);
  box-shadow: var(--shadow-sm);
}

.sidebar__item .icon {
  flex-shrink: 0;
}

.sidebar__item--back {
  margin-top: var(--space-5);
}

.sidebar__empty {
  margin: var(--space-2) var(--space-5);
  font-size: var(--text-body);
  opacity: 0.75;
}

.sidebar-backdrop {
  display: none;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* ── Top bar ─────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-sticky);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  min-height: var(--topbar-height);
  padding: var(--space-3) var(--space-6);
  background: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.icon-btn.topbar__menu {
  display: none;
}

.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-body);
  color: var(--color-text-subtle);
}

.crumbs a {
  color: var(--color-text-muted);
  font-weight: var(--weight-medium);
}

.crumbs [aria-current] {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
}

.crumbs__sep {
  color: var(--color-text-subtle);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex-shrink: 0;
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--shadow-border-width) solid var(--shadow-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.icon-btn:hover {
  background: var(--color-hover);
}

/* ── Theme picker (same themes as the app's Theme Customizer) ────────── */
.theme-picker {
  position: relative;
}

.theme-panel {
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-3));
  width: 260px;
  padding: var(--space-4);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-popover);
  z-index: var(--z-dropdown);
}

.theme-panel[hidden] {
  display: none;
}

.theme-panel__title {
  margin-bottom: var(--space-3);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  padding: var(--space-2);
  background: var(--color-surface-alt);
  border-radius: var(--radius-sm);
}

.mode-switch__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3);
  background: transparent;
  color: var(--color-text-muted);
  border: var(--shadow-border-width) solid transparent;
  border-radius: var(--radius-xs);
  font-weight: var(--weight-semibold);
}

.mode-switch__btn[aria-pressed="true"] {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--shadow-color);
  box-shadow: var(--shadow-xs);
}

.theme-option {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  padding: var(--space-3);
  background: transparent;
  color: var(--color-text);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-align: left;
}

.theme-option:hover {
  background: var(--color-hover);
}

.theme-option[aria-pressed="true"] {
  background: var(--color-active);
  border-color: var(--color-border-strong);
}

.theme-option__swatch {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-strong);
}

.theme-option__name {
  flex: 1;
  font-size: var(--text-body);
  font-weight: var(--weight-medium);
}

.theme-option__check {
  display: inline-flex;
  visibility: hidden;
}

.theme-option[aria-pressed="true"] .theme-option__check {
  visibility: visible;
}

/* ── Page ────────────────────────────────────────────────────────────── */
.page {
  width: 100%;
  max-width: 54rem;
  padding: var(--space-6);
  font-size: 1.0625rem;
  line-height: var(--leading-relaxed);
}

.page-header {
  display: flex;
  align-items: flex-start;
  gap: var(--space-4);
  margin: var(--space-3) 0 var(--space-6);
}

.page-header__icon {
  display: inline-flex;
  margin-top: var(--space-2);
  color: var(--color-text);
}

.page-header__title {
  font-size: var(--text-h1);
}

.page-header__subtitle {
  margin-top: var(--space-2);
  font-size: var(--text-body-lg);
  color: var(--color-text-muted);
}

.site-footer {
  margin-top: auto;
  padding: var(--space-5) var(--space-6);
  font-size: var(--text-caption);
  color: var(--color-text-subtle);
  border-top: 1px solid var(--color-border);
}

/* ── Buttons (app Button component) ──────────────────────────────────── */
.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 48px;
  padding: 0 var(--space-6);
  font-weight: var(--weight-semibold);
  line-height: 1;
  border: var(--shadow-border-width) solid var(--shadow-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.btn:hover {
  opacity: 1;
  border-color: var(--shadow-color-hover);
}

/* The app paints primary buttons in the accent with white text, which is unreadable on the light
   Trailblazer and Friendly themes; here primary + inverted text keeps it readable in all of them. */
.btn--primary {
  background: var(--color-primary);
  color: var(--color-text-invert);
}

.btn--secondary {
  background: var(--color-surface);
  color: var(--color-text);
}

.btn--secondary:hover {
  background: var(--color-hover);
}

/* ── Home: manual cards (like the app's StatCards) ──────────────────── */
.role-group + .role-group {
  margin-top: var(--space-7);
}

.role-group__title {
  margin-bottom: var(--space-4);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-subtle);
}

.card-grid {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
  gap: var(--space-5);
}

.manual-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  height: 100%;
  padding: var(--space-5);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.manual-card:hover {
  opacity: 1;
  border-color: var(--color-border-strong);
  background: var(--color-surface-alt);
}

.manual-card__top {
  display: flex;
  justify-content: space-between;
  gap: var(--space-3);
}

.manual-card__title {
  font-family: var(--font-heading);
  font-size: var(--text-title);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
}

.manual-card__text {
  color: var(--color-text-muted);
  font-size: var(--text-body-lg);
}

.manual-card__meta {
  margin-top: auto;
  font-family: var(--font-mono);
  font-size: var(--text-caption);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-subtle);
}

/* ── Manual page: guide list ────────────────────────────────────────── */
.guide-list {
  list-style: none;
  display: grid;
  gap: var(--space-4);
}

.guide-list__item {
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-5);
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.guide-list__item:hover {
  opacity: 1;
  border-color: var(--color-border-strong);
  background: var(--color-surface-alt);
}

.guide-list__num,
.guide__num,
.guide-section--steps > ol > li::before {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2.25rem;
  height: 2.25rem;
  font-family: var(--font-mono);
  font-weight: var(--weight-bold);
  font-size: var(--text-body-lg);
  /* Primary + inverted text is readable in every theme; the accent shows as a ring */
  background: var(--color-primary);
  color: var(--color-text-invert);
  border-radius: var(--radius-full);
  box-shadow: 0 0 0 3px var(--color-accent);
}

.guide-list__text {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: var(--space-1);
}

.guide-list__title {
  font-weight: var(--weight-bold);
}

.guide-list__summary {
  color: var(--color-text-muted);
  font-size: var(--text-body-lg);
}

.empty-state {
  padding: var(--space-6);
  text-align: center;
  color: var(--color-text-subtle);
  background: var(--color-surface);
  border: 1px dashed var(--color-border-strong);
  border-radius: var(--radius-md);
}

/* ── Guide: one card per section ─────────────────────────────────────── */
.guide {
  display: grid;
  gap: var(--space-5);
}

.guide-section {
  padding: var(--space-5) var(--space-6) var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.guide-section > h2,
.guide-section > h3 {
  margin: 0 calc(var(--space-6) * -1) var(--space-5);
  padding: 0 var(--space-6) var(--space-4);
  font-size: var(--text-title);
  border-bottom: 1px solid var(--color-border);
}

/* Links in text: text colour with a thick underline in the theme colour. Several accents
   (Trailblazer gold, Friendly orange) are too light for text on a light page. */
.guide a:not(.zoom),
.toc a {
  color: var(--color-text);
  font-weight: var(--weight-semibold);
  text-decoration: underline;
  text-decoration-color: var(--color-accent);
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.guide p + p,
.guide p + ul,
.guide ul + p {
  margin-top: var(--space-4);
}

.guide ul {
  padding-left: var(--space-6);
}

.guide ul > li + li {
  margin-top: var(--space-3);
}

.guide ul > li::marker {
  color: var(--color-text-subtle);
}

/* Numbered steps */
.guide-section--steps > ol {
  list-style: none;
  counter-reset: step;
  display: grid;
  gap: var(--space-6);
}

.guide-section--steps > ol > li {
  position: relative;
  min-height: 2.25rem;
  padding-left: calc(2.25rem + var(--space-4));
  counter-increment: step;
}

.guide-section--steps > ol > li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: -0.2rem;
}

.guide-section--steps > ol > li > ul {
  margin-top: var(--space-3);
}

/* Button and screen names look like the app's own labels */
.guide-section--steps strong {
  padding: 0.05em 0.4em;
  font-weight: var(--weight-semibold);
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-xs);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

/* Pictures */
.zoom {
  display: block;
  margin-top: var(--space-4);
  cursor: zoom-in;
}

.zoom:hover {
  opacity: 1;
}

.guide img {
  display: block;
  max-width: 100%;
  height: auto;
  background: #ffffff;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

/* Tip and warning boxes (app status colours) */
.callout {
  margin-top: var(--space-5);
  padding: var(--space-4) var(--space-5);
  border: 1px solid;
  border-left-width: 5px;
  border-radius: var(--radius-sm);
}

.callout--tip {
  background: var(--color-info-soft);
  border-color: var(--color-info);
}

.callout--warning {
  background: var(--color-warning-soft);
  border-color: var(--color-warning);
}

.callout__label {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  margin-right: var(--space-2);
  font-weight: var(--weight-bold);
  /* Plain text colour: the app's --color-info-text / --color-warning-text are light-on-light in
     the light mode of Techy, Playful, Trailblazer and Monochrome. The box colour marks the type. */
  color: var(--color-text);
}

.callout--tip .callout__label .icon {
  color: var(--color-info);
}

.callout--warning .callout__label .icon {
  color: var(--color-warning);
}

/* Previous / next */
.pager {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
  margin-top: var(--space-7);
}

.pager__link {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface);
  color: var(--color-text);
  border: var(--shadow-border-width) solid var(--shadow-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.pager__link:hover {
  opacity: 1;
  background: var(--color-hover);
}

.pager__link--next {
  text-align: right;
  align-items: flex-end;
}

.pager__hint {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-caption);
  font-weight: var(--weight-semibold);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-subtle);
}

.pager__title {
  font-weight: var(--weight-semibold);
}

/* ── All on one page (also the PDF) ─────────────────────────────────── */
.cover {
  display: none;
}

.toc {
  margin-bottom: var(--space-7);
  padding: var(--space-5) var(--space-6);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
}

.toc__title {
  margin-bottom: var(--space-3);
  font-size: var(--text-title);
}

.toc ol {
  padding-left: var(--space-6);
}

.toc li + li {
  margin-top: var(--space-2);
}

.guide--print + .guide--print {
  margin-top: var(--space-8);
}

.guide__title {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-size: var(--text-h2);
}

.guide__summary {
  color: var(--color-text-muted);
}

/* ── Phones and small tablets (the app's --bp-md) ────────────────────── */
@media (max-width: 840px) {
  .shell {
    grid-template-columns: minmax(0, 1fr);
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(var(--sidebar-width), 85vw);
    transform: translateX(-100%);
    transition: transform var(--duration-normal) var(--ease-out);
  }

  .nav-open .sidebar {
    transform: none;
    box-shadow: var(--shadow-popover);
  }

  .nav-open .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-sidebar) - 1);
    background: var(--color-overlay);
  }

  .topbar {
    padding: var(--space-3) var(--space-5);
  }

  .icon-btn.topbar__menu {
    display: inline-flex;
  }

  .page {
    padding: var(--space-5);
  }

  .page-header__title {
    font-size: var(--text-h2);
  }

  .guide-section {
    padding: var(--space-4) var(--space-4) var(--space-5);
  }

  .guide-section > h2,
  .guide-section > h3 {
    margin: 0 calc(var(--space-4) * -1) var(--space-4);
    padding: 0 var(--space-4) var(--space-3);
  }

  .guide-section--steps > ol > li {
    padding-left: calc(2.25rem + var(--space-3));
  }

  .pager {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}

/* ── Print and PDF: always the default light theme (site.js), no app chrome ── */
@media print {
  body {
    font-size: 11pt;
    background: #ffffff;
  }

  .shell {
    display: block;
  }

  .sidebar,
  .sidebar-backdrop,
  .topbar,
  .site-footer,
  .page-header,
  .pager,
  .actions,
  .skip-link {
    display: none;
  }

  .page {
    max-width: none;
    padding: 0;
    font-size: 11pt;
  }

  .cover {
    display: block;
    padding-top: 28vh;
    break-after: page;
  }

  .cover__app {
    font-family: var(--font-mono);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-text-subtle);
  }

  .cover__title {
    margin: var(--space-4) 0;
    font-family: var(--font-heading);
    font-size: 30pt;
    font-weight: var(--weight-bold);
    line-height: var(--leading-tight);
  }

  .cover__text {
    font-size: 14pt;
    color: var(--color-text-muted);
  }

  .toc {
    break-after: page;
  }

  .guide--print {
    break-before: page;
  }

  .guide--print + .guide--print {
    margin-top: 0;
  }

  .guide img,
  .btn,
  .pager__link {
    box-shadow: none;
  }

  /* On paper a section is a plain block, not a card: a card frame cut across two pages looked broken */
  .guide-section {
    padding: 0;
    background: none;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .guide-section + .guide-section {
    margin-top: 8mm;
  }

  .guide-section > h2,
  .guide-section > h3 {
    margin: 0 0 4mm;
    padding: 0 0 2mm;
    break-after: avoid;
  }

  /* A step (number, text and picture) always moves to the next page as one piece */
  .guide-section--steps > ol {
    gap: 6mm;
  }

  .guide-section--steps > ol > li,
  .zoom,
  .callout {
    break-inside: avoid;
  }

  /* The badge sits inside its step: the ring stuck out above the step and was cut at page ends */
  .guide-section--steps > ol > li::before {
    top: 2mm;
    box-shadow: none;
  }

  /* The accent ring (box-shadow) printed as a clipped, lopsided circle next to guide titles */
  .guide__num {
    box-shadow: none;
  }

  /* Chromium paints the top 1-2pt of a block it moves to the next page at the bottom of the page it
     left (a thin line from a picture edge or a badge). A little blank space at the top of every block
     that can move keeps that sliver empty. */
  .guide-section--steps > ol > li {
    padding-top: 2mm;
    /* Tall enough for the badge below the 2mm, or a one-line step lets the badge stick out of its
       bottom and get cut at the page end */
    min-height: calc(2.25rem + 2mm);
  }

  .zoom,
  .guide--print {
    padding-top: 2mm;
  }

  .guide__title {
    break-after: avoid;
  }

  /* With "clone", Chromium left a stray piece of a label's frame on the page a step was pushed off */
  .guide-section--steps strong {
    box-decoration-break: slice;
    -webkit-box-decoration-break: slice;
  }

  .guide img {
    max-height: 9cm;
    width: auto;
    border: 0;
  }
}
