:root {
  --ink: #10241a;
  --muted: #4a6356;
  --paper: #f3f6f1;
  --panel: rgba(255, 255, 255, 0.88);
  --line: #c5d4cb;
  --green: #1f5138;
  --green-deep: #143c24;
  --gold: #c9a227;
  --focus: #2d6a4f;
  --shadow: 0 18px 50px rgba(16, 36, 26, 0.12);
  --radius: 18px;
  --font: "DM Sans", system-ui, sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(201, 162, 39, 0.18), transparent 60%),
    radial-gradient(800px 480px at 100% 0%, rgba(45, 106, 79, 0.2), transparent 55%),
    linear-gradient(165deg, #eef4ef 0%, #f7faf6 45%, #e7eee8 100%);
}

.top {
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 24px 8px;
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.mark {
  width: 56px;
  height: 56px;
  object-fit: contain;
  flex-shrink: 0;
  display: block;
}

.brand-logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
  display: block;
  margin-bottom: 4px;
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}

h1 {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: clamp(28px, 4vw, 40px);
  font-weight: 400;
  letter-spacing: -0.02em;
  color: var(--green-deep);
}

.tagline {
  margin: 0;
  max-width: 280px;
  text-align: right;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.shell {
  max-width: 1200px;
  margin: 16px auto 24px;
  padding: 0 24px;
  display: grid;
  grid-template-columns: minmax(300px, 420px) 1fr;
  gap: 18px;
  min-height: calc(100vh - 160px);
}

.search-panel,
.viewer-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.search-panel {
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.search-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.search-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

#q {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

#q:focus {
  outline: 2px solid var(--focus);
  border-color: var(--focus);
}

.ghost,
.button {
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 0 14px;
  cursor: pointer;
}

.button {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  background: var(--green);
  color: #fff;
  border-color: var(--green);
  padding: 10px 14px;
}

.button:hover {
  background: var(--green-deep);
}

.filters {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.filters-unit {
  grid-template-columns: 1fr;
}

.filters label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.filters select {
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: #fff;
}

.status {
  margin: 14px 0 8px;
  font-size: 13px;
  color: var(--muted);
}

.results {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow: auto;
  flex: 1;
}

.results li button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  padding: 12px;
  cursor: pointer;
  font: inherit;
  color: inherit;
}

.results li button:hover,
.results li button.active {
  background: rgba(31, 81, 56, 0.06);
  border-color: var(--line);
}

.results .id {
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  letter-spacing: 0.04em;
}

.results .title {
  margin: 4px 0;
  font-weight: 600;
  line-height: 1.35;
}

.results .meta {
  font-size: 12px;
  color: var(--muted);
}

.results mark {
  background: rgba(201, 162, 39, 0.35);
  color: inherit;
  padding: 0 2px;
  border-radius: 3px;
}

.viewer-panel {
  min-height: 560px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.empty {
  margin: auto;
  padding: 40px;
  max-width: 420px;
  text-align: center;
}

.empty h2 {
  font-family: var(--display);
  font-weight: 400;
  font-size: 32px;
  margin: 0 0 10px;
  color: var(--green-deep);
}

.empty p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.viewer {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 560px;
}

.viewer.hidden,
.empty.hidden {
  display: none;
}

.viewer-meta {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.poc-id {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--gold);
}

#v-title {
  margin: 4px 0;
  font-size: 20px;
  line-height: 1.25;
}

.title-edit-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.title-edit {
  margin: 0;
  border: 1.5px solid transparent;
  border-radius: 10px;
  padding: 6px 8px;
  font: inherit;
  font-size: 20px;
  font-weight: 600;
  line-height: 1.25;
  color: var(--ink);
  background: transparent;
}

.title-edit:hover {
  border-color: var(--line);
  background: #fff;
}

.title-edit:focus {
  outline: none;
  border-color: var(--focus);
  background: #fff;
}

.title-status {
  margin: 4px 0 0;
  font-size: 12px;
}

.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

#frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #dfe8e2;
  min-height: 480px;
}

.foot {
  max-width: 1200px;
  margin: 0 auto 28px;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

@media (max-width: 900px) {
  .top {
    flex-direction: column;
    align-items: start;
  }

  .tagline {
    text-align: left;
  }

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

  .viewer-panel {
    min-height: 70vh;
  }
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

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

.nav a {
  color: var(--green-deep);
  font-weight: 600;
  text-decoration: none;
  font-size: 14px;
}

.nav.center {
  justify-content: center;
  margin-top: 18px;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: lowercase;
}

.pill.hot {
  border-color: var(--gold);
  color: var(--green-deep);
  background: rgba(201, 162, 39, 0.2);
}

.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--gold);
  color: #143c24;
  font-size: 10px;
  letter-spacing: 0.06em;
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-card h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 400;
  font-size: 34px;
  color: var(--green-deep);
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.auth-card input[type="password"],
.auth-card input[type="text"],
.auth-card input[type="file"] {
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;
  background: #fff;
  color: var(--ink);
}

.auth-card .button {
  margin-top: 6px;
  justify-content: center;
  min-height: 46px;
  border: 0;
  cursor: pointer;
}

.auth-card .error {
  margin: 0;
  color: #8a1c1c;
  font-weight: 600;
}

.upload-card {
  width: min(480px, 100%);
}

.file-label input {
  padding: 10px;
}

.detail {
  margin: 0;
  padding: 12px;
  border-radius: 12px;
  background: #143c2410;
  overflow: auto;
  font-size: 11px;
  max-height: 180px;
}

@media (max-width: 900px) {
  .top-actions {
    align-items: flex-start;
  }
}

.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;
}

.camera-fab {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 40;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: #fff;
  background: var(--green);
  box-shadow: 0 12px 28px rgba(16, 36, 26, 0.28);
  transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.camera-fab:hover {
  background: var(--green-deep);
  transform: translateY(-1px);
}

.camera-fab:active {
  transform: scale(0.96);
}

.camera-fab:disabled,
.camera-fab.busy {
  opacity: 0.72;
  cursor: wait;
}

.camera-fab[hidden] {
  display: none;
}

/* Scan dock: camera FAB morphs into this glass capsule once a page exists,
   anchored at the same corner so it reads as one control, not a new one. */
.scan-dock {
  position: fixed;
  right: max(20px, env(safe-area-inset-right));
  bottom: max(22px, env(safe-area-inset-bottom));
  z-index: 40;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}

.scan-dock[hidden] {
  display: none;
}

.capsule {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: 60px;
  padding: 0 18px 0 10px;
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: 999px;
  background: rgba(18, 52, 32, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 12px 28px rgba(16, 36, 26, 0.32);
  color: #f4f1e6;
  font: inherit;
  cursor: pointer;
  animation: capsule-in 0.22s cubic-bezier(0.2, 0.8, 0.3, 1.2);
}

.capsule[hidden] {
  display: none;
}

@keyframes capsule-in {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  .capsule {
    animation: none;
  }
}

.capsule .stack {
  position: relative;
  width: 34px;
  height: 30px;
  flex: none;
}

.capsule .stack .mini {
  position: absolute;
  width: 21px;
  height: 27px;
  border-radius: 4px;
  background: linear-gradient(160deg, #fbf8ef, #efe9d8);
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}

.capsule .stack .mini:nth-child(1) {
  left: 0;
  top: 2px;
  transform: rotate(-8deg);
}

.capsule .stack .mini:nth-child(2) {
  left: 6px;
  top: 0;
  transform: rotate(-1deg);
}

.capsule .stack .mini:nth-child(3) {
  left: 11px;
  top: 1px;
  transform: rotate(6deg);
}

.capsule .label {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
  text-align: left;
}

.capsule .label b {
  font-size: 13px;
  font-weight: 700;
}

.capsule .label small {
  font-size: 10.5px;
  font-weight: 500;
  color: rgba(244, 241, 230, 0.75);
}

.scan-panel {
  width: min(320px, calc(100vw - 24px));
  padding: 16px;
  border: 1px solid rgba(201, 162, 39, 0.45);
  border-radius: 20px;
  background: rgba(18, 52, 32, 0.94);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow: 0 16px 40px rgba(16, 36, 26, 0.4);
  color: #f4f1e6;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transform-origin: bottom right;
  animation: panel-in 0.2s ease;
}

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

@keyframes panel-in {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .scan-panel {
    animation: none;
  }
}

.scan-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
}

.scan-panel-head strong {
  display: block;
  font-size: 14px;
}

.scan-panel-head span {
  display: block;
  font-size: 11.5px;
  color: rgba(244, 241, 230, 0.7);
}

.scan-collapse {
  border: 0;
  background: transparent;
  color: rgba(244, 241, 230, 0.8);
  font-size: 15px;
  line-height: 1;
  padding: 4px;
  cursor: pointer;
  flex: none;
}

.scan-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 0;
}

.page-chip {
  position: relative;
  width: 46px;
  height: 60px;
  flex: none;
  border-radius: 6px;
  background: linear-gradient(160deg, #fbf8ef, #efe9d8);
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
}

.page-chip::before {
  content: "";
  position: absolute;
  left: 7px;
  right: 7px;
  top: 10px;
  height: 2px;
  background: rgba(16, 36, 26, 0.12);
  box-shadow:
    0 6px 0 rgba(16, 36, 26, 0.1),
    0 12px 0 rgba(16, 36, 26, 0.1),
    0 18px 0 rgba(16, 36, 26, 0.08);
}

.page-chip .num {
  position: absolute;
  bottom: -5px;
  left: -5px;
  width: 15px;
  height: 15px;
  border-radius: 50%;
  background: var(--gold);
  color: var(--green-deep);
  font-size: 8.5px;
  font-weight: 700;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 2px rgba(18, 52, 32, 0.94);
}

.page-chip .rm {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 16px;
  height: 16px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 10px;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 0 0 2px rgba(18, 52, 32, 0.94);
}

.add-tile {
  width: 46px;
  height: 60px;
  flex: none;
  border: 1.5px dashed rgba(244, 241, 230, 0.4);
  border-radius: 6px;
  background: transparent;
  color: rgba(244, 241, 230, 0.75);
  font-size: 20px;
  display: grid;
  place-items: center;
  cursor: pointer;
}

.add-tile:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.scan-panel-unit {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 600;
  color: rgba(244, 241, 230, 0.75);
}

.scan-panel-unit select {
  border: 1.5px solid rgba(244, 241, 230, 0.3);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  min-height: 44px;
  background: rgba(255, 255, 255, 0.06);
  color: #f4f1e6;
}

.scan-panel-unit select:disabled {
  opacity: 0.5;
}

.scan-panel-unit select option {
  color: var(--ink);
}

.scan-panel-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.ghost-glass,
.upload-glass {
  min-height: 40px;
  padding: 10px 14px;
  border-radius: 12px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

.ghost-glass {
  border: 1px solid rgba(244, 241, 230, 0.3);
  background: transparent;
  color: rgba(244, 241, 230, 0.9);
}

.upload-glass {
  border: 1px solid var(--gold);
  background: var(--gold);
  color: var(--green-deep);
}

.ghost-glass:disabled,
.upload-glass:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.scan-toast {
  position: fixed;
  left: 50%;
  bottom: max(96px, calc(env(safe-area-inset-bottom) + 88px));
  transform: translateX(-50%);
  z-index: 42;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 14px;
  background: rgba(20, 60, 36, 0.94);
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 10px 30px rgba(16, 36, 26, 0.25);
}

body:has(.scan-panel:not([hidden])) .scan-toast:not([hidden]) {
  bottom: max(300px, calc(env(safe-area-inset-bottom) + 292px));
}

