* { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --card: #f2f2f2;
  --white: #ffffff;
  --yellow: #f5ba00;
  --title-yellow: #f5ba00;
  --title-green: #00823b;
  --green: #009e3a;
  --blue: #2f5c9e;
  --dot-blue: #2f5c9e;
  --dot-gray: #8ea3be;
  --active-blue: #2563eb;
  --text-gray: #9b9b9b;
  --icon-gray: #a2a2a2;
  --shadow: 0 4px 14px rgba(0, 0, 0, 0.08);
  --top-height: 44px;
  --nav-height: 64px;
}

html, body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: #eef1f5;
  color: #444;
}

body {
  display: flex;
  width: 100%;
  min-height: 100vh;
  min-height: 100svh;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  justify-content: center;
  align-items: stretch;
}

@media (max-width: 480px) {
  html, body {
    background: #ffffff;
  }
}

.app {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100vh;
  min-height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  background: #ffffff;
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  margin: 0 auto;
  box-shadow: 0 0 30px rgba(0, 0, 0, 0.08);
}

.top-space {
  position: relative;
  min-height: var(--top-height);
  height: var(--top-height);
  flex: 0 0 var(--top-height);
}
.top-logo {
  position: absolute;
  left: 14px;
  top: 8px;
  max-width: 92px;
  max-height: 34px;
  width: auto;
  height: auto;
  object-fit: contain;
  object-position: left top;
}

/* Palco Central Contendo Tag + Documento + Controles como Grupo Unificado */
.main-stage {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4px 10px 8px;
  overflow: hidden;
}

.header-wrap {
  display: flex;
  justify-content: center;
  margin-top: 0;
  margin-bottom: 9px;
  padding: 0;
  flex: 0 0 auto;
}

.header-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--title-yellow);
  color: var(--title-green);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
  line-height: 1;
  text-transform: uppercase;
  padding: 5px 12px;
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  border-radius: 2px;
}

.doc-area {
  position: relative;
  aspect-ratio: var(--doc-ratio, 0.72);
  height: auto;
  max-height: calc(100vh - 212px);
  max-height: calc(100dvh - 212px);
  max-width: calc((100vh - 212px) * var(--doc-ratio, 0.72));
  max-width: calc((100dvh - 212px) * var(--doc-ratio, 0.72));
  width: min(calc(100% - 14px), 396px);
  margin: 0 auto;
  background: transparent;
  flex: 0 1 auto;
  overflow: hidden;
  border-radius: 4px;
}

.doc-slider {
  position: absolute;
  inset: 0;
  display: flex;
  background: transparent;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  touch-action: pan-x pan-y;
}
.doc-slider::-webkit-scrollbar { display: none; }
.doc-slide {
  flex: 0 0 100%;
  min-width: 0;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 0;
  background: transparent;
  scroll-snap-align: start;
  scroll-snap-stop: always;
}
.doc-slide img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.controls {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  max-width: 396px;
  padding: 0 4px;
  margin-top: 9px;
  margin-bottom: 0;
  flex: 0 0 auto;
}

.control-btn {
  width: 50px;
  height: 50px;
  border: 0;
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  cursor: pointer;
  flex: 0 0 50px;
  transition: transform 0.1s ease, filter 0.1s ease;
}
.control-btn:active {
  transform: scale(0.96);
}

.control-btn svg {
  width: 22px;
  height: 22px;
}

.more-btn {
  background: var(--green);
  box-shadow: 0 3px 10px rgba(0, 158, 58, 0.25);
}

.more-btn svg {
  width: 18px;
  height: 18px;
}

.pager-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  gap: 16px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pager-dot {
  position: relative;
  appearance: none;
  padding: 0;
  border: 0;
  flex: 0 0 6.5px;
  width: 6.5px;
  height: 6.5px;
  border-radius: 50%;
  background: var(--dot-gray);
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.15s ease;
}
.pager-dot::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 26px;
  height: 26px;
}

.pager-dot.active {
  background: var(--dot-blue);
  width: 7.2px;
  height: 7.2px;
  flex: 0 0 7.2px;
}

.pager-next {
  border: 0;
  background: transparent;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.pager-next svg {
  width: 9px;
  height: 15px;
  stroke: var(--blue);
  stroke-width: 2.6;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav-bar {
  width: 100%;
  height: var(--nav-height);
  flex: 0 0 var(--nav-height);
  display: flex;
  justify-content: space-around;
  align-items: center;
  border-top: 1px solid #ebebeb;
  background: #ffffff;
  margin-top: 0;
  padding: 0;
  position: relative;
  z-index: 31;
}

.nav-item {
  width: 20%;
  min-width: 0;
  padding: 3px 0;
  appearance: none;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: #666;
  font-family: inherit;
  font-size: 10px;
  font-weight: 400;
  line-height: normal;
  cursor: pointer;
  text-decoration: none;
}
.nav-item > span:last-child { white-space: nowrap; }
.nav-item.active { color: var(--active-blue); font-weight: 600; }
.nav-item.active .nav-icon { color: var(--active-blue); }
.nav-icon {
  display: block;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  fill: currentColor;
}
.qr-circle {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  border-radius: 50%;
  background: var(--green);
  display: grid;
  place-items: center;
  margin-bottom: 3px;
  box-shadow: 0 2px 8px rgba(0, 158, 58, 0.28);
}
.qr-circle svg { width: 19px; height: 19px; fill: #fff; }
.nav-item.active .qr-circle { background: var(--green); }

.clipboard {
  position: relative;
  display: block;
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  margin: 0;
  background: transparent;
}
.clipboard::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 1px;
  width: 20px;
  height: 19px;
  border-radius: 3px;
  background: #999;
}
.clipboard::after {
  content: "";
  position: absolute;
  top: 0;
  left: 6px;
  width: 10px;
  height: 5px;
  border-radius: 2px 2px 0 0;
  background: #999;
}
.nav-item.active .clipboard::before,
.nav-item.active .clipboard::after { background: var(--active-blue); }
.clip-line {
  position: absolute;
  left: 5px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
  z-index: 1;
}
.clip-line-top { top: 8px; width: 12px; }
.clip-line-mid { top: 13px; left: 9px; width: 8px; }
.clip-line-bot { top: 18px; left: 9px; width: 8px; }
.clip-dot {
  position: absolute;
  left: 5px;
  width: 2px;
  height: 2px;
  border-radius: 50%;
  background: #fff;
  z-index: 1;
}
.clip-dot-mid { top: 13px; }
.clip-dot-bot { top: 18px; }

.app-dialog {
  border: 0;
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.25);
  max-width: 90vw;
  max-height: 90vh;
}
.app-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.dialog-close {
  appearance: none;
  border: 0;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 12px;
}
.dialog-image {
  max-width: 100%;
  max-height: 75vh;
  object-fit: contain;
  display: block;
  border-radius: 8px;
}

@media (max-width: 390px) {
  .doc-area {
    width: min(calc(100% - 10px), 380px);
  }
  .controls {
    padding: 0 4px;
    gap: 8px;
  }
  .control-btn {
    width: 48px;
    height: 48px;
    border-radius: 15px;
    flex-basis: 48px;
  }
}

@media (max-width: 340px) {
  :root {
    --top-height: 38px;
    --nav-height: 56px;
  }
  .main-stage {
    padding: 2px 6px 6px;
  }
  .header-wrap {
    margin-bottom: 6px;
  }
  .header-tag {
    font-size: 9px;
    padding: 4px 8px;
  }
  .doc-area {
    width: calc(100% - 6px);
    max-height: calc(100dvh - 176px);
    max-width: calc((100dvh - 176px) * var(--doc-ratio, 0.72));
  }
  .controls {
    margin-top: 6px;
    padding: 0 2px;
    gap: 6px;
  }
  .control-btn {
    width: 44px;
    height: 44px;
    flex-basis: 44px;
    border-radius: 14px;
  }
}

@media (max-height: 660px) {
  :root {
    --top-height: 38px;
    --nav-height: 58px;
  }
  .main-stage {
    padding: 2px 8px 6px;
  }
  .header-wrap {
    margin-bottom: 7px;
  }
  .controls {
    margin-top: 7px;
  }
  .control-btn {
    width: 46px;
    height: 46px;
    flex-basis: 46px;
  }
  .doc-area {
    max-height: calc(100dvh - 190px);
    max-width: calc((100dvh - 190px) * var(--doc-ratio, 0.72));
  }
}

@supports not (aspect-ratio: 1) {
  .doc-area {
    height: calc(100vh - 212px);
  }
}
