:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-border: rgba(16, 28, 39, 0.12);
  --ink: #101c27;
  --muted: #636466;
  --accent: #c4161c;
  --accent-strong: #9d0b0f;
  --accent-soft: #f7d7d8;
  --warning: #9d0b0f;
  --shadow: 0 22px 50px rgba(16, 28, 39, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Space Grotesk", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at top left, rgba(196, 22, 28, 0.16), transparent 30%),
    radial-gradient(circle at right, rgba(16, 28, 39, 0.12), transparent 25%),
    linear-gradient(180deg, #f8f4ef 0%, var(--bg) 55%, #ece7e1 100%);
}

.app-shell {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 36px 0 48px;
}

.hero {
  margin-bottom: 24px;
}

.eyebrow,
.section-title {
  margin: 0 0 8px;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent);
}

h1 {
  margin: 0;
  font-size: clamp(2.2rem, 4vw, 4.4rem);
  line-height: 0.95;
  max-width: 10ch;
}

.intro {
  max-width: 58ch;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
  line-height: 1.5;
}

.panel {
  backdrop-filter: blur(14px);
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.tab-row {
  display: inline-flex;
  gap: 10px;
  padding: 8px;
  margin-bottom: 16px;
  border-radius: 18px;
  background: rgba(16, 28, 39, 0.08);
}

.tab-button {
  padding: 10px 16px;
  background: transparent;
  color: var(--muted);
}

.tab-button.active {
  background: var(--accent);
  color: #fff;
}

.local-card {
  padding: 2px 0 0;
}

.local-grid {
  display: grid;
  grid-template-columns: minmax(260px, 420px) 140px;
  gap: 16px;
  margin-bottom: 16px;
  align-items: end;
  justify-content: start;
}

.auth-grid {
  grid-template-columns: minmax(260px, 420px) minmax(220px, 320px);
}

.auth-password-wrap {
  min-width: 0;
}

.local-select {
  min-height: 58px;
  resize: none;
}

.controls-panel {
  padding: 24px;
  margin-bottom: 20px;
}

.snapshot-form {
  margin-bottom: 16px;
}

.job-result {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
  padding: 18px;
  border-radius: 22px;
  background: rgba(16, 28, 39, 0.04);
  border: 1px solid rgba(16, 28, 39, 0.08);
}

.job-summary {
  display: grid;
  gap: 6px;
}

.job-note-panel {
  display: grid;
  gap: 10px;
  padding-top: 4px;
}

.job-note-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.note-input {
  width: 100%;
  min-height: 120px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(23, 33, 43, 0.12);
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

.note-input:focus {
  outline: 2px solid rgba(196, 22, 28, 0.22);
  border-color: rgba(196, 22, 28, 0.4);
}

.file-picker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.worksheet-link {
  color: #0b57d0;
  font-weight: 500;
  text-decoration: none;
}

.worksheet-link:hover {
  text-decoration: underline;
}

.job-result.project-emphasis {
  background:
    linear-gradient(135deg, rgba(196, 22, 28, 0.1), rgba(16, 28, 39, 0.06)),
    rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(196, 22, 28, 0.22);
  box-shadow: 0 18px 36px rgba(196, 22, 28, 0.08);
}

.label {
  display: block;
  margin-bottom: 10px;
  font-weight: 700;
}

.token-label {
  margin-top: 16px;
}

.remember-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 4px;
  color: var(--muted);
}

.remember-wrap input {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  padding: 0;
}

.form-row,
.viewer-header,
.helper-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.viewer-actions {
  display: flex;
  gap: 12px;
  align-items: center;
}

.nav-button {
  display: none;
  min-width: 112px;
}

.lookup-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.lookup-suggestions {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  right: 0;
  z-index: 20;
  display: grid;
  gap: 6px;
  padding: 10px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(23, 33, 43, 0.1);
  box-shadow: 0 18px 36px rgba(16, 28, 39, 0.14);
}

.lookup-suggestion {
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  border-radius: 12px;
  background: rgba(16, 28, 39, 0.05);
  color: var(--ink);
}

.lookup-suggestion:hover {
  background: rgba(196, 22, 28, 0.12);
}

input {
  flex: 1;
  min-width: 0;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(23, 33, 43, 0.12);
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  font: inherit;
}

.token-input {
  width: 100%;
  resize: vertical;
  min-height: 92px;
  padding: 16px 18px;
  border-radius: 16px;
  border: 1px solid rgba(23, 33, 43, 0.12);
  background: rgba(255, 255, 255, 0.84);
  color: var(--ink);
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(196, 22, 28, 0.22);
  border-color: rgba(196, 22, 28, 0.4);
}

.token-input:focus {
  outline: 2px solid rgba(196, 22, 28, 0.22);
  border-color: rgba(196, 22, 28, 0.4);
}

button {
  border: 0;
  border-radius: 16px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, background 120ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.primary-button {
  padding: 16px 20px;
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.snapshot-job-button {
  width: 100%;
  margin-top: 12px;
  padding: 16px 20px;
  border: 0;
  border-radius: 14px;
  color: #fff;
  background: #0b57d0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.snapshot-job-button:hover,
.snapshot-job-button:focus {
  background: #0842a0;
}

.snapshot-job-button:disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.ghost-button {
  padding: 12px 14px;
  color: var(--accent-strong);
  background: var(--accent-soft);
}

.button-stack {
  display: flex;
  gap: 12px;
}

.helper-row {
  margin-bottom: 18px;
  align-items: flex-start;
}

.helper-text,
.current-camera,
.status {
  margin: 0;
  color: var(--muted);
}

.lookup-emphasis {
  color: var(--warning);
  font-weight: 700;
}

.saved-cameras {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.saved-camera {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  border-radius: 999px;
  background: rgba(16, 28, 39, 0.08);
}

.job-result.project-emphasis .saved-camera {
  background: rgba(196, 22, 28, 0.12);
}

.saved-camera button {
  border-radius: 999px;
}

.saved-camera-load {
  padding: 8px 0;
  background: transparent;
  color: var(--ink);
}

.saved-camera-remove {
  width: 30px;
  height: 30px;
  background: rgba(23, 33, 43, 0.08);
  color: var(--ink);
}

.viewer-panel {
  padding: 24px;
}

.admin-tools {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 20px;
  background: rgba(16, 28, 39, 0.04);
  border: 1px solid rgba(16, 28, 39, 0.08);
}

.admin-tools summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--ink);
}

.admin-tools-body {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.admin-url {
  word-break: break-all;
}

.view-panel {
  display: block;
}

.viewer-header {
  margin-bottom: 12px;
}

.status {
  min-height: 24px;
  margin-bottom: 16px;
}

.status.error {
  color: var(--warning);
}

.status.success {
  color: var(--accent-strong);
}

.snapshot-frame {
  position: relative;
  min-height: 360px;
  overflow: hidden;
  border-radius: 22px;
  background:
    linear-gradient(135deg, rgba(196, 22, 28, 0.12), rgba(16, 28, 39, 0.1)),
    #dde3e1;
  border: 1px solid rgba(23, 33, 43, 0.08);
}

.image-nav-button {
  position: absolute;
  top: 50%;
  transform: translateY(-50%) !important;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  padding: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transition: none;
  color: transparent;
  font-size: 0;
  line-height: 0;
  text-indent: -9999px;
  overflow: hidden;
}

.image-nav-left {
  left: 24px;
}

.image-nav-right {
  right: 24px;
}

.image-nav-button::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  border-top: 4px solid rgba(255, 255, 255, 0.96);
  border-right: 4px solid rgba(255, 255, 255, 0.96);
  filter: drop-shadow(0 2px 8px rgba(16, 28, 39, 0.42));
}

.image-nav-left::before {
  transform: rotate(-135deg);
}

.image-nav-right::before {
  transform: rotate(45deg);
}

.image-nav-button:hover,
.image-nav-button:focus,
.image-nav-button:active {
  transform: translateY(-50%) !important;
  background: transparent;
  box-shadow: none;
}

#snapshot-image {
  display: block;
  width: 100%;
  height: auto;
  cursor: zoom-in;
}

.live-video {
  display: block;
  width: 100%;
  min-height: 360px;
  background: #10191d;
}

.placeholder {
  display: grid;
  place-items: center;
  min-height: 360px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.rotate-hint {
  display: none;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
  text-align: center;
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1100px);
    padding-top: 22px;
  }

  .form-row,
  .viewer-header,
  .helper-row {
    flex-direction: column;
    align-items: stretch;
  }

  .viewer-actions {
    flex-direction: column;
    align-items: stretch;
  }

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

  .primary-button,
  .ghost-button {
    width: 100%;
  }

  .button-stack {
    flex-direction: column;
  }

  .tab-row {
    width: 100%;
  }

  .tab-button {
    flex: 1;
  }

  .viewer-panel {
    padding: 14px;
  }

  .snapshot-frame {
    min-height: 56vh;
    border-radius: 16px;
  }

  #snapshot-image {
    width: 100%;
    min-height: 56vh;
    height: 56vh;
    object-fit: cover;
  }

  .placeholder,
  .live-video {
    min-height: 56vh;
  }
}

@media (max-width: 720px) and (orientation: portrait) {
  .snapshot-frame {
    min-height: auto;
  }

  #snapshot-image {
    height: auto;
    min-height: 0;
    object-fit: contain;
  }

  .rotate-hint {
    display: block;
  }
}
