:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --line: #d7dce2;
  --line-strong: #aeb6c1;
  --text: #1f2328;
  --muted: #66717f;
  --accent: #d9002b;
  --accent-dark: #9f001f;
  --focus: #1663d8;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--text);
  background: var(--bg);
}

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

.skip-link {
  position: fixed;
  top: -48px;
  left: 12px;
  z-index: 20;
  padding: 9px 12px;
  color: #ffffff;
  background: var(--focus);
  border-radius: 4px;
}

.skip-link:focus { top: 8px; }

.apu-reader-shell {
  display: grid;
  grid-template-rows: 64px 32px minmax(0, 1fr);
  width: 100%;
  height: 100dvh;
}

.apu-reader-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 1px 2px rgb(15 23 42 / 8%);
}

.apu-reader-brand {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 10px;
}

.brand-mark {
  width: 6px;
  height: 38px;
  flex: 0 0 auto;
  background: var(--accent);
}

h1 {
  margin: 0;
  font-size: 17px;
  line-height: 22px;
}

.apu-reader-brand p {
  margin: 1px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.apu-reader-actions,
.apu-page-controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.apu-mobile-aircraft-switch {
  display: none;
}

.apu-button,
.apu-control-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--text);
  background: var(--panel);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  line-height: 18px;
  text-decoration: none;
  cursor: pointer;
}

.apu-button svg,
.apu-control-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2;
}

.apu-button:hover:not(:disabled),
.apu-control-button:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent-dark);
}

.apu-button-primary {
  color: #ffffff;
  background: var(--accent);
  border-color: var(--accent);
}

.apu-button-primary:hover:not(:disabled) {
  color: #ffffff;
  background: var(--accent-dark);
  border-color: var(--accent-dark);
}

.apu-button:disabled,
.apu-control-button:disabled {
  opacity: .5;
  cursor: not-allowed;
}

.apu-button:focus-visible,
.apu-control-button:focus-visible,
.apu-page-field input:focus-visible,
.skip-link:focus-visible,
.apu-document:focus-visible,
.apu-mobile-document:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.apu-reader-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 0 14px;
  color: var(--muted);
  background: #f8fafb;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.apu-reader-status {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.apu-page-controls {
  display: none;
}

.apu-control-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

.apu-page-field {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

.apu-page-field input {
  width: 58px;
  height: 32px;
  padding: 0 5px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  color: var(--text);
  text-align: center;
  background: var(--panel);
  font: inherit;
}

.apu-reader-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #60666d;
}

.apu-document {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
  background: #60666d;
}

.apu-mobile-document {
  display: none;
}

body.apu-page-reader-mode .apu-page-controls {
  display: flex;
}

body.apu-page-reader-mode .apu-document {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

body.apu-page-reader-mode .apu-mobile-document {
  position: absolute;
  inset: 0;
  display: block;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 1024px), (max-width: 1366px) and (hover: none), (max-width: 1366px) and (pointer: coarse) {
  .skip-link {
    min-height: 44px;
  }

  .apu-reader-shell {
    grid-template-rows: calc(64px + env(safe-area-inset-top, 0px)) 48px minmax(0, 1fr);
  }

  .apu-reader-toolbar {
    position: relative;
    min-width: 0;
    min-height: 64px;
    padding: env(safe-area-inset-top, 0px) 216px 0 8px;
    gap: 8px;
  }

  .apu-reader-brand {
    flex: 1 1 auto;
    gap: 7px;
    overflow: hidden;
  }

  .brand-mark {
    width: 5px;
    height: 32px;
  }

  h1 {
    overflow: hidden;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .apu-reader-brand p {
    display: none;
  }

  .apu-reader-actions {
    position: absolute;
    top: calc(env(safe-area-inset-top, 0px) + 10px);
    right: 8px;
    width: 200px;
    flex: 0 0 auto;
    gap: 8px;
  }

  .apu-mobile-aircraft-switch {
    display: inline-flex;
  }

  .apu-button,
  .apu-control-button {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border-radius: 7px;
  }

  .apu-button span {
    display: none;
  }

  .apu-reader-controls {
    min-height: 48px;
    padding: 2px 8px;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: none;
  }

  .apu-reader-controls::-webkit-scrollbar { display: none; }

  .apu-reader-status {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  .apu-page-controls {
    display: flex;
    width: max-content;
    min-width: 100%;
    justify-content: center;
    gap: 8px;
  }

  .apu-page-field input {
    width: 56px;
    height: 44px;
    font-size: 16px;
  }

  .apu-document {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
  }

  .apu-mobile-document {
    position: absolute;
    inset: 0;
    display: block;
    overflow: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: #596068;
    scrollbar-gutter: stable;
  }

  .apu-mobile-document .apu-pdf-viewer {
    padding: 12px 8px max(20px, env(safe-area-inset-bottom, 0px));
  }

  .apu-mobile-document .apu-pdf-viewer .page {
    margin: 0 auto 12px;
    border: 0;
    box-shadow: 0 5px 20px rgb(15 23 42 / 32%);
  }

  .apu-page-loading {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: grid;
    place-items: center;
    padding: 20px;
    color: var(--muted);
    text-align: center;
    background: #f5f7f9;
    font-size: 13px;
  }

  .apu-loading-error {
    display: grid;
    width: min(100%, 360px);
    justify-items: center;
    gap: 10px;
    line-height: 1.5;
  }

  .apu-loading-error strong {
    color: var(--text);
    font-size: 15px;
  }

  .apu-loading-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    margin-top: 2px;
  }

  .apu-loading-action {
    display: inline-flex;
    min-height: 44px;
    align-items: center;
    justify-content: center;
    padding: 0 14px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    color: var(--text);
    background: #ffffff;
    font: inherit;
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
  }

  .apu-loading-retry {
    color: #ffffff;
    border-color: var(--accent-dark);
    background: var(--accent);
  }

  .apu-loading-action:active {
    filter: brightness(.92);
  }

  .apu-loading-action:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
  }

  .apu-page-loading[hidden] { display: none; }
}

@media (max-width: 360px) {
  .apu-reader-brand h1 { max-width: 118px; }
  .apu-reader-actions { gap: 5px; }
}

@media (min-width: 601px) and (max-width: 1024px), (min-width: 601px) and (max-width: 1366px) and (hover: none), (min-width: 601px) and (max-width: 1366px) and (pointer: coarse) {
  .apu-reader-toolbar {
    padding-right: 244px;
  }

  .apu-reader-actions {
    width: 228px;
  }

  .apu-mobile-aircraft-switch {
    width: 72px;
    gap: 5px;
  }

  .apu-mobile-aircraft-switch span {
    display: inline;
  }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}

@media print {
  .apu-reader-toolbar,
  .apu-reader-controls { display: none !important; }
}
