:root {
  --bg: #f6f7f9;
  --fg: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --accent: #1f6feb;
  --accent-fg: #ffffff;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family:
    -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--fg);
  background: var(--bg);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: stretch;
  gap: 2rem;
  padding: 0 1.25rem;
  background: white;
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  min-width: 0;
  padding: 1rem 1rem 1rem 0.5rem;
}

.topbar__logo {
  height: 1.75rem;
  width: auto;
  display: block;
  flex-shrink: 0;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding-left: 1.125rem;
  border-left: 1px solid var(--border);
}

.topbar__eyebrow {
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1;
  margin-bottom: 0.25rem;
}

.topbar__model {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.15;
  color: var(--fg);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-combobox {
  position: relative;
  display: inline-flex;
}

.lang-combobox__trigger {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 11rem;
  height: 2.25rem;
  padding: 0 0.7rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  color: var(--fg);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease, box-shadow 0.12s ease, border-color 0.12s ease;
}

.lang-combobox__trigger:hover {
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.lang-combobox__trigger:focus-visible {
  outline: 0;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.18);
}

.lang-combobox__trigger > svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  color: var(--muted);
}

.lang-combobox__current {
  flex: 1;
  display: inline-flex;
  align-items: baseline;
  gap: 0.45rem;
  min-width: 0;
  text-align: left;
}

.lang-combobox__current-code {
  flex-shrink: 0;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.lang-combobox__current-native {
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-combobox__caret {
  width: 0.75rem !important;
  height: 0.75rem !important;
  color: var(--muted);
}

.lang-combobox__panel {
  position: absolute;
  top: calc(100% + 0.375rem);
  right: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: 16rem;
  max-width: calc(100vw - 1.5rem);
  max-height: min(22rem, calc(100vh - 6rem));
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12), 0 2px 6px rgba(15, 23, 42, 0.05);
  overflow: hidden;
}

.lang-combobox__panel[hidden] {
  display: none;
}

.lang-combobox__search {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
}

.lang-combobox__search svg {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.lang-combobox__input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 0.875rem;
  color: var(--fg);
  padding: 0;
}

.lang-combobox__list {
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  overflow-y: auto;
  flex: 1;
}

.lang-combobox__option {
  display: flex;
  align-items: baseline;
  gap: 0.625rem;
  padding: 0.5rem 0.875rem;
  cursor: pointer;
  user-select: none;
}

.lang-combobox__option.is-hidden {
  display: none;
}

.lang-combobox__option.is-active {
  background: rgba(31, 111, 235, 0.08);
}

.lang-combobox__option.is-selected {
  font-weight: 600;
}

.lang-combobox__option.is-selected.is-active,
.lang-combobox__option:hover {
  background: rgba(31, 111, 235, 0.08);
}

.lang-combobox__code {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
  min-width: 1.75rem;
  flex-shrink: 0;
}

.lang-combobox__option.is-selected .lang-combobox__code {
  color: var(--accent);
}

.lang-combobox__name {
  font-size: 0.875rem;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lang-combobox__empty {
  margin: 0;
  padding: 1rem 0.875rem;
  text-align: center;
  font-size: 0.8125rem;
  color: var(--muted);
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 0;
  border-radius: 0.375rem;
  background: var(--accent);
  color: var(--accent-fg);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

.btn svg {
  width: 0.95rem;
  height: 0.95rem;
}

.btn:hover {
  filter: brightness(0.95);
}

.tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
}

.tabs__link {
  position: relative;
  display: inline-flex;
  align-items: center;
  padding: 0 0.85rem;
  text-decoration: none;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition:
    color 0.12s ease,
    border-color 0.12s ease;
}

.tabs__link:hover {
  color: var(--fg);
}

.tabs__link.is-active {
  color: var(--fg);
  border-bottom-color: var(--accent);
  cursor: default;
}

.toolbar {
  display: flex;
  align-items: center;
  margin-left: auto;
  gap: 0.75rem;
}

.toolbar__group {
  display: inline-flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 0.125rem;
  gap: 0.125rem;
}

.toolbar__btn,
.toolbar__zoom {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  border-radius: 0.375rem;
  cursor: pointer;
  color: var(--fg);
  font: inherit;
  font-size: 0.8125rem;
  padding: 0;
  text-decoration: none;
}

.toolbar__btn {
  width: 2rem;
  height: 2rem;
}

.toolbar__btn svg {
  width: 1rem;
  height: 1rem;
}

.toolbar__zoom {
  min-width: 3.5rem;
  height: 2rem;
  padding: 0 0.5rem;
  font-variant-numeric: tabular-nums;
}

.toolbar__btn:hover:not(:disabled),
.toolbar__zoom:hover {
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.toolbar__btn:disabled {
  color: var(--muted);
  cursor: not-allowed;
}

.viewer {
  flex: 1;
  display: flex;
  justify-content: safe center;
  padding: 1rem;
  overflow: auto;
}

.viewer__pdf {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
}

.viewer__error {
  display: none;
  margin: 4rem 0;
  color: #b91c1c;
  font-size: 0.875rem;
}

.viewer__pdf[data-state='error'] .viewer__error {
  display: block;
}

.viewer__pdf--reloading .pdf-page {
  opacity: 0.55;
  transition: opacity 0.15s ease;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: #fef3c7;
  color: #78350f;
  font-size: 0.8125rem;
  border-bottom: 1px solid #fde68a;
}

.banner svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.banner strong {
  font-weight: 600;
}

.progress {
  position: sticky;
  top: 0;
  height: 2px;
  background: transparent;
  overflow: hidden;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.progress[data-state='loading'] {
  opacity: 1;
}

.progress[data-state='done'] {
  opacity: 0;
  transition: opacity 0.4s ease 0.2s;
}

.progress__bar {
  height: 100%;
  width: 100%;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 0.18s ease-out;
}

.pdf-page {
  display: block;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border-radius: 0.25rem;
}

.footer {
  display: flex;
  gap: 1rem;
  padding: 0.5rem 1.25rem;
  background: white;
  border-top: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--muted);
}

.empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.25rem;
}

.empty__card {
  width: 100%;
  max-width: 30rem;
  padding: 2.5rem 2rem 2rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.875rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 12px 32px rgba(17, 24, 39, 0.06);
  text-align: center;
}

.empty__icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 4rem;
  height: 4rem;
  margin: 0 auto 1.25rem;
  border-radius: 999px;
  background: var(--bg);
  color: var(--muted);
}

.empty__icon svg {
  width: 1.75rem;
  height: 1.75rem;
}

.empty__title {
  margin: 0 0 0.5rem;
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.empty__message {
  margin: 0;
  color: var(--muted);
  font-size: 0.9375rem;
  line-height: 1.5;
}

.empty__suggest {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.empty__suggest-label {
  margin: 0 0 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted);
}

.lang-chips {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.lang-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3rem;
  padding: 0.4rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: white;
  color: var(--fg);
  font-size: 0.8125rem;
  font-weight: 500;
  text-decoration: none;
  letter-spacing: 0.02em;
  transition:
    border-color 0.12s ease,
    color 0.12s ease,
    background 0.12s ease,
    box-shadow 0.12s ease;
}

.lang-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 1px 2px rgba(31, 111, 235, 0.12);
}

.home {
  flex: 1;
  padding: 2rem 1.25rem 3rem;
  width: 100%;
  max-width: 72rem;
  margin: 0 auto;
}

.home-section {
  margin-top: 2rem;
}

.home-section:first-of-type {
  margin-top: 0;
}

.home-section.is-hidden {
  display: none;
}

.home-section__title {
  margin: 0 0 0.875rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.device-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr));
  gap: 0.75rem;
}

.device-card {
  display: flex;
  align-items: center;
  gap: 0.875rem;
  padding: 0.75rem 0.875rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  text-decoration: none;
  color: var(--fg);
  transition:
    border-color 0.12s ease,
    box-shadow 0.12s ease,
    transform 0.12s ease;
}

.device-card:hover {
  border-color: var(--accent);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 20px rgba(31, 111, 235, 0.08);
  transform: translateY(-1px);
}

.device-card__thumb {
  flex-shrink: 0;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.device-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.device-card__thumb--placeholder {
  background: var(--bg);
}

.device-card__body {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.device-card__title {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.25;
  color: var(--fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-card__subtitle {
  font-size: 0.8125rem;
  color: var(--muted);
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.home-search {
  margin-bottom: 1.5rem;
}

.home-search__field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.85rem;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.625rem;
  color: var(--muted);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.home-search__field:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.12);
}

.home-search__field svg {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
}

.home-search__field input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  font: inherit;
  font-size: 0.9375rem;
  color: var(--fg);
}

.home-search__empty {
  text-align: center;
  color: var(--muted);
  font-size: 0.9375rem;
  margin: 2rem 0;
}

.is-hidden {
  display: none !important;
}

.share-dialog {
  border: 0;
  border-radius: 0.75rem;
  padding: 0;
  max-width: 22rem;
  width: 90vw;
  background: white;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.share-dialog::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

.share-dialog__inner {
  padding: 1rem 1.25rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.share-dialog__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.share-dialog__header h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 600;
}

.share-dialog__close {
  background: transparent;
  border: 0;
  width: 1.75rem;
  height: 1.75rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.375rem;
  cursor: pointer;
  color: var(--muted);
}

.share-dialog__close:hover {
  background: var(--bg);
  color: var(--fg);
}

.share-dialog__close svg {
  width: 1rem;
  height: 1rem;
}

.share-dialog__qr {
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  padding: 1rem;
  aspect-ratio: 1 / 1;
}

.share-dialog__qr svg {
  width: 100%;
  height: 100%;
  display: block;
}

.share-dialog__url {
  display: flex;
  gap: 0.5rem;
}

.share-dialog__url input {
  flex: 1;
  min-width: 0;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-family: inherit;
  background: var(--bg);
  color: var(--fg);
}

.share-dialog__copy-done {
  display: none;
}

[data-share-copy][data-state='copied'] .share-dialog__copy-default {
  display: none;
}

[data-share-copy][data-state='copied'] .share-dialog__copy-done {
  display: inline;
}

@media (min-width: 721px) and (max-width: 1023.98px) {
  .topbar {
    flex-wrap: wrap;
    row-gap: 0;
  }

  .topbar__brand {
    order: 1;
  }

  .toolbar {
    order: 2;
  }

  .tabs {
    order: 3;
    flex-basis: 100%;
    border-top: 1px solid var(--border);
    margin: 0 -1.25rem;
    padding: 0 1.25rem;
  }

  .tabs__link {
    padding: 0.6rem 0.85rem;
  }
}

@media (max-width: 720px) {
  body {
    padding-bottom: calc(3rem + env(safe-area-inset-bottom, 0px));
  }

  .topbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
  }

  .topbar__brand {
    padding: 0.625rem 1rem;
    gap: 0.875rem;
  }

  .topbar__logo {
    height: 1.5rem;
  }

  .topbar__title {
    padding-left: 0.875rem;
  }

  .topbar__model {
    font-size: 1.0625rem;
  }

  .topbar__eyebrow {
    font-size: 0.625rem;
    margin-bottom: 0.125rem;
  }

  .tabs {
    border-top: 1px solid var(--border);
    padding: 0 0.5rem;
  }

  .tabs__link {
    padding: 0.55rem 0.75rem;
  }

  .toolbar {
    position: fixed;
    inset: auto 0 0 0;
    margin: 0;
    padding: 0.4rem 0.5rem;
    padding-bottom: max(0.4rem, env(safe-area-inset-bottom, 0px));
    background: white;
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.04);
    justify-content: space-between;
    gap: 0.4rem;
    z-index: 5;
  }

  .toolbar__btn {
    width: 2.25rem;
    height: 2.25rem;
  }

  .toolbar__zoom {
    min-width: 3rem;
    height: 2.25rem;
  }

  /* Doc page mobile: lang trigger sits in the bottom-pinned toolbar with icon buttons,
     so we keep it compact (code only) and flip the panel upward. */
  body:not(.page-home) .lang-combobox__trigger {
    min-width: 0;
    padding: 0 0.55rem;
    height: 2.25rem;
  }

  body:not(.page-home) .lang-combobox__current-native {
    display: none;
  }

  body:not(.page-home) .lang-combobox__panel {
    top: auto;
    bottom: calc(100% + 0.375rem);
    max-height: min(22rem, calc(100vh - 4rem - env(safe-area-inset-bottom, 0px)));
  }

  /* Home page mobile: 2-row grid topbar — [logo | combobox] / [title spans full width].
     `display: contents` flattens .topbar__brand and .toolbar so their children become direct grid items. */
  body.page-home {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .page-home .topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "logo lang"
      "title title";
    align-items: center;
    column-gap: 0.875rem;
    row-gap: 0;
    padding: 0;
    background: transparent;
  }

  /* Row 1 navbar background spans the full width via a pseudo grid item. */
  .page-home .topbar::before {
    content: '';
    grid-column: 1 / -1;
    grid-row: 1;
    background: white;
    border-bottom: 1px solid var(--border);
    z-index: 0;
  }

  .page-home .topbar__brand,
  .page-home .toolbar {
    display: contents;
  }

  .page-home .topbar__logo {
    grid-area: logo;
    position: relative;
    z-index: 1;
    margin: 0.625rem 0 0.625rem 1rem;
  }

  .page-home .lang-combobox {
    grid-area: lang;
    position: relative;
    z-index: 1;
    width: 100%;
    margin: 0.625rem 1rem 0.625rem 0;
    justify-self: stretch;
  }

  .page-home .lang-combobox__trigger {
    width: 100%;
    min-width: 0;
    height: 2.5rem;
  }

  .page-home .lang-combobox__panel {
    width: 100%;
    max-width: none;
  }

  /* Title is its own block on the page background, taller and disconnected. */
  .page-home .topbar__title {
    grid-area: title;
    padding: 1.5rem 1rem 0.75rem;
    margin: 0;
  }

  .page-home .topbar__eyebrow {
    font-size: 0.6875rem;
    margin-bottom: 0.375rem;
  }

  .page-home .topbar__model {
    font-size: 1.25rem;
    line-height: 1.3;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
  }

  .footer {
    font-size: 0.6875rem;
    padding: 0.4rem 1rem;
  }
}

@media print {
  .topbar,
  .tabs,
  .toolbar,
  .banner,
  .progress,
  .footer,
  .share-dialog {
    display: none !important;
  }
  .viewer {
    padding: 0;
    overflow: visible;
  }
  .viewer__pdf {
    max-width: none;
  }
  .pdf-page {
    box-shadow: none;
    border-radius: 0;
    page-break-after: always;
    break-after: page;
  }
}
