:root {
  --green-950: #052e24;
  --green-900: #064e3b;
  --green-800: #0b5d46;
  --green-700: #0f7454;
  --lime: #8bc64a;
  --lime-2: #70b33d;
  --panel: #132b30;
  --panel-2: #17363c;
  --surface: #0b1c20;
  --text: #edf7f1;
  --muted: #a8c0b8;
  --border: rgba(255, 255, 255, 0.12);
  --danger: #f87171;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.28);
  --app-height: 100vh;
}

* {
  box-sizing: border-box;
}

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

body {
  height: var(--app-height);
  min-height: 0;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 10%, rgba(139, 198, 74, 0.08), transparent 28%),
    linear-gradient(135deg, #08191d, #0b2428 60%, #0a1b1f);
  overflow: hidden;
}


body.is-viewer-fullscreen {
  overflow: hidden;
}

body.is-viewer-fullscreen .viewer-frame.is-app-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

body.is-viewer-fullscreen .viewer-frame.is-app-fullscreen .viewer-controls,
body.is-viewer-fullscreen .viewer-frame.is-app-fullscreen .viewer-help {
  visibility: visible;
  opacity: 1;
}

button,
input {
  font: inherit;
}

button,
label {
  -webkit-tap-highlight-color: transparent;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  width: 100%;
  height: var(--app-height);
  min-height: 0;
  max-height: var(--app-height);
  display: grid;
  grid-template-rows: 72px minmax(0, 1fr);
}

.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 20px;
  min-width: 0;
  padding: 0 20px;
  background: linear-gradient(90deg, #073b2f, #0b5360);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 7px 24px rgba(0, 0, 0, 0.24);
}

.brand {
  display: flex;
  align-items: center;
  min-width: 290px;
}

.brand img {
  display: block;
  width: 245px;
  max-height: 52px;
  object-fit: contain;
  object-position: left center;
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, 0.28));
}

.title-block {
  min-width: 0;
  padding-left: 20px;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
}

.title-block strong,
.title-block span {
  display: block;
}

.title-block strong {
  font-size: 18px;
  letter-spacing: 0.2px;
}

.title-block span {
  margin-top: 3px;
  color: #c8ded7;
  font-size: 12px;
}

.session-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  padding: 8px 12px;
  color: #dbf5bf;
  font-size: 12px;
  border: 1px solid rgba(139, 198, 74, 0.48);
  border-radius: 999px;
  background: rgba(139, 198, 74, 0.12);
}

.session-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--lime);
  box-shadow: 0 0 0 4px rgba(139, 198, 74, 0.15);
}

.workspace {
  min-height: 0;
  height: 100%;
  display: grid;
  overflow: hidden;
  grid-template-columns: minmax(0, 1fr) 340px;
}

.viewer-column {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  overflow: hidden;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(4, 17, 20, 0.54);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(11, 28, 32, 0.92);
  backdrop-filter: blur(10px);
}

#fileInput {
  display: none;
}

.btn {
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 10px 13px;
  color: var(--text);
  font-weight: 750;
  border: 1px solid transparent;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  transition: transform 0.14s ease, filter 0.14s ease, border-color 0.14s ease, background 0.14s ease;
  user-select: none;
}

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

.btn:active {
  transform: translateY(1px);
}

.btn:focus-visible,
.viewer-frame:focus-visible {
  outline: 3px solid rgba(139, 198, 74, 0.45);
  outline-offset: 2px;
}

.btn-primary {
  color: #14301d;
  background: linear-gradient(135deg, var(--lime), var(--lime-2));
  box-shadow: 0 8px 22px rgba(112, 179, 61, 0.17);
}

.upload-button {
  flex: 0 0 auto;
}

.btn-secondary {
  margin-left: auto;
  color: #e8f6f1;
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.08);
}

.format-switch {
  min-width: 0;
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
}

.btn-format {
  min-height: 34px;
  padding: 7px 10px;
  color: #c5d8d2;
  font-size: 12px;
  border-radius: 7px;
}

.btn-format svg {
  width: 17px;
  height: 17px;
}

.btn-format span {
  color: #88aaa0;
  font-size: 10px;
}

.btn-format.is-active {
  color: #eaffd9;
  border-color: rgba(139, 198, 74, 0.35);
  background: rgba(139, 198, 74, 0.16);
}

.btn-format.is-active span {
  color: #c9efa5;
}

.viewer-area {
  position: relative;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  overflow: hidden;
  background:
    linear-gradient(45deg, rgba(255, 255, 255, 0.018) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.018) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, 0.018) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, 0.018) 75%),
    #08181c;
  background-position: 0 0, 18px 18px;
  background-size: 36px 36px;
}

.viewer-frame {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 14px;
  background: #061216;
  box-shadow: var(--shadow);
  flex: 0 0 auto;
  transition: border-radius 0.18s ease;
  touch-action: none;
}

.viewer-frame.is-vertical {
  width: auto;
  height: 100%;
  aspect-ratio: 9 / 16;
}

.viewer-frame.is-horizontal {
  width: 100%;
  height: 100%;
}

.viewer-frame:fullscreen,
.viewer-frame:-webkit-full-screen {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
}

.viewer-frame.is-layout-resetting {
  visibility: hidden;
}

.viewer-frame:fullscreen .viewer-controls,
.viewer-frame:-webkit-full-screen .viewer-controls,
.viewer-frame:fullscreen .viewer-help,
.viewer-frame:-webkit-full-screen .viewer-help {
  visibility: visible;
  opacity: 1;
}

.viewer-frame:fullscreen .viewer-controls,
.viewer-frame:-webkit-full-screen .viewer-controls {
  z-index: 20;
}

#panoramaCanvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: grab;
  background: #071519;
}

#panoramaCanvas.is-dragging {
  cursor: grabbing;
}

.empty-state,
.loading-state {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 26px;
  text-align: center;
  color: #dceee8;
  background:
    radial-gradient(circle at center, rgba(15, 116, 84, 0.22), transparent 42%),
    linear-gradient(145deg, rgba(6, 32, 35, 0.96), rgba(8, 19, 23, 0.98));
}

.empty-state[hidden],
.loading-state[hidden] {
  display: none;
}

.empty-state strong,
.loading-state strong {
  font-size: 18px;
}

.empty-state > span {
  max-width: 430px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.empty-state .btn {
  margin-top: 6px;
}

.empty-icon {
  width: 66px;
  height: 66px;
  display: grid;
  place-items: center;
  color: var(--lime);
  border: 1px solid rgba(139, 198, 74, 0.28);
  border-radius: 50%;
  background: rgba(139, 198, 74, 0.08);
}

.empty-icon svg {
  width: 35px;
  height: 35px;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--lime);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.ai-progress-state {
  position: absolute;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px;
  color: #f4f0ff;
  text-align: center;
  background: rgba(5, 16, 20, 0.88);
  backdrop-filter: blur(8px);
}

.ai-progress-state[hidden] {
  display: none;
}

.ai-progress-state strong {
  font-size: 16px;
}

.ai-progress-state small {
  max-width: 430px;
  color: #c9c0e7;
  font-size: 11px;
  line-height: 1.45;
}

.ai-progress-track {
  width: min(320px, 72%);
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
}

.ai-progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #8b5cf6, #c4b5fd);
  transition: width 0.18s ease;
}

.viewer-controls {
  position: absolute;
  z-index: 8;
  left: 14px;
  bottom: 14px;
  display: flex;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 10px;
  background: rgba(4, 18, 21, 0.72);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(9px);
}

.viewer-controls button {
  width: 42px;
  height: 40px;
  display: grid;
  place-items: center;
  color: #f2fbf7;
  font-size: 22px;
  border: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  background: transparent;
  cursor: pointer;
}

.viewer-controls button:last-child {
  border-right: 0;
}

.viewer-controls button:hover,
.viewer-controls button.is-active {
  color: #dfffbf;
  background: rgba(139, 198, 74, 0.18);
}

.viewer-controls svg {
  width: 19px;
  height: 19px;
}

.viewer-controls #autoRotateBtn svg {
  transform: scaleX(-1);
}

.viewer-help {
  position: absolute;
  z-index: 8;
  right: 14px;
  bottom: 14px;
  max-width: calc(100% - 220px);
  padding: 9px 11px;
  color: rgba(244, 253, 249, 0.82);
  font-size: 11px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(4, 18, 21, 0.68);
  backdrop-filter: blur(8px);
}

.export-bar {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  background: rgba(11, 28, 32, 0.94);
}

.export-info {
  min-width: 0;
  flex: 1;
}

.export-info span,
.export-info small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.export-info span {
  color: #e8f6f1;
  font-size: 13px;
  font-weight: 750;
}

.export-info small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.export-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-ai {
  min-width: 190px;
  color: #f4efff;
  border-color: rgba(196, 181, 253, 0.25);
  background: linear-gradient(135deg, #6d4cc4, #4a35a1);
  box-shadow: 0 9px 24px rgba(109, 76, 196, 0.18);
}

.btn-ai:disabled,
.btn-capture:disabled {
  opacity: 0.46;
  cursor: not-allowed;
  filter: none;
}

.btn-capture {
  flex: 0 0 auto;
  min-width: 210px;
  color: white;
  background: linear-gradient(135deg, #0ea5a7, #0b7d83);
  box-shadow: 0 9px 24px rgba(14, 165, 167, 0.16);
}

.gallery-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-left: 1px solid var(--border);
  background: linear-gradient(180deg, var(--panel), #0e2428);
}

.gallery-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}

.gallery-head > div {
  min-width: 0;
  flex: 1;
}

.eyebrow {
  display: block;
  margin-bottom: 5px;
  color: #b9e78a;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

.gallery-head h1 {
  margin: 0;
  font-size: 20px;
}

.gallery-head p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.photo-count {
  min-width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  color: #18331f;
  font-size: 12px;
  font-weight: 900;
  border-radius: 50%;
  background: var(--lime);
}

.gallery-list {
  min-height: 0;
  padding: 12px;
  overflow-y: auto;
  scrollbar-color: rgba(139, 198, 74, 0.4) rgba(255, 255, 255, 0.03);
  scrollbar-width: thin;
}

.gallery-item {
  position: relative;
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-bottom: 9px;
  padding: 7px;
  color: var(--text);
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.045);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.gallery-item:hover {
  transform: translateY(-1px);
  border-color: rgba(139, 198, 74, 0.34);
  background: rgba(255, 255, 255, 0.07);
}

.gallery-item.is-active {
  border-color: rgba(139, 198, 74, 0.66);
  background: rgba(139, 198, 74, 0.11);
  box-shadow: inset 3px 0 0 var(--lime);
}

.gallery-thumb {
  width: 88px;
  aspect-ratio: 2 / 1;
  display: block;
  object-fit: cover;
  border-radius: 7px;
  background: #071519;
}

.gallery-meta {
  min-width: 0;
}

.gallery-meta strong,
.gallery-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.gallery-meta strong {
  font-size: 12px;
}

.gallery-meta span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.delete-photo {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  color: #fecaca;
  border: 1px solid rgba(248, 113, 113, 0.18);
  border-radius: 7px;
  background: rgba(248, 113, 113, 0.08);
  cursor: pointer;
}

.delete-photo:hover {
  background: rgba(248, 113, 113, 0.16);
}

.delete-photo svg {
  width: 15px;
  height: 15px;
}

.gallery-empty {
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
}

.gallery-empty[hidden] {
  display: none;
}

.gallery-empty svg {
  width: 40px;
  height: 40px;
  color: #6f978a;
}

.gallery-empty strong {
  color: #dcebe6;
  font-size: 13px;
}

.gallery-empty span {
  max-width: 230px;
  font-size: 11px;
  line-height: 1.45;
}

.gallery-footer {
  padding: 14px 16px 16px;
  border-top: 1px solid var(--border);
}

.gallery-footer .btn {
  width: 100%;
}

.gallery-upload-button {
  margin-bottom: 10px;
}

.gallery-footer p {
  margin: 10px 0 0;
  color: #8fa9a1;
  font-size: 10px;
  line-height: 1.4;
}

.btn-danger {
  color: #fecaca;
  border-color: rgba(248, 113, 113, 0.25);
  background: rgba(248, 113, 113, 0.09);
}

.btn-danger:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.toast {
  position: fixed;
  z-index: 9999;
  left: 50%;
  bottom: 24px;
  max-width: min(90vw, 520px);
  padding: 11px 15px;
  color: white;
  font-size: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: rgba(5, 46, 36, 0.94);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translate(-50%, 18px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.is-error {
  background: rgba(127, 29, 29, 0.96);
}

@media (max-width: 1120px) {
  .workspace {
    grid-template-columns: minmax(0, 1fr) 300px;
  }

  .btn-format span {
    display: none;
  }
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  body {
    height: auto;
    min-height: 100dvh;
  }

  .app-shell {
    height: auto;
    min-height: 100dvh;
    max-height: none;
    grid-template-rows: auto auto;
  }

  .topbar {
    min-height: 66px;
    padding: 8px 12px;
  }

  .brand {
    min-width: 0;
  }

  .brand img {
    width: 190px;
  }

  .title-block {
    display: none;
  }

  .session-badge {
    padding: 7px 10px;
    font-size: 10px;
  }

  .workspace {
    height: auto;
    display: block;
    overflow: visible;
  }

  .viewer-column {
    height: auto;
    min-height: 720px;
    overflow: visible;
    grid-template-rows: auto minmax(520px, 66vh) auto;
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
    padding: 10px;
  }

  .format-switch {
    flex: 1 1 100%;
    order: 3;
  }

  .btn-format {
    flex: 1;
  }

  .btn-format span {
    display: inline;
  }

  .btn-secondary {
    flex: 1 1 140px;
    margin-left: 0;
  }

  .viewer-area {
    padding: 10px;
  }

  .viewer-frame.is-vertical {
    height: 100%;
    max-width: 100%;
  }

  .gallery-panel {
    min-height: 350px;
    grid-template-rows: auto auto auto;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  .gallery-list {
    display: flex;
    gap: 10px;
    padding: 12px;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .gallery-item {
    flex: 0 0 260px;
    margin: 0;
    grid-template-columns: 88px minmax(0, 1fr) 28px;
  }
}

@media (max-width: 560px) {
  .session-badge {
    width: 10px;
    height: 10px;
    padding: 0;
    border: 0;
    background: transparent;
    overflow: hidden;
    font-size: 0;
  }

  .session-dot {
    flex: 0 0 8px;
  }

  .viewer-column {
    min-height: 680px;
    grid-template-rows: auto minmax(480px, 68vh) auto;
  }

  .toolbar .btn {
    font-size: 12px;
  }

  .btn-format span {
    display: block;
    font-size: 9px;
  }

  .viewer-help {
    display: none;
  }

  .viewer-controls {
    left: 10px;
    bottom: 10px;
  }

  .viewer-controls button {
    width: 39px;
    height: 38px;
  }

  .export-bar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }

  .export-actions {
    width: 100%;
    flex-direction: column;
  }

  .btn-ai,
  .btn-capture {
    width: 100%;
    min-width: 0;
  }

  .gallery-head {
    padding: 16px 14px 13px;
  }

  .gallery-head h1 {
    font-size: 18px;
  }
}


.viewer-frame.is-app-fullscreen .viewer-controls {
  left: max(16px, env(safe-area-inset-left));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 40;
}

.viewer-frame.is-app-fullscreen .viewer-help {
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 40;
}


.fullscreen-exit-btn {
  position: absolute;
  z-index: 45;
  top: max(16px, env(safe-area-inset-top));
  right: max(16px, env(safe-area-inset-right));
  min-height: 42px;
  display: none;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  color: #f2fbf7;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 9px;
  background: rgba(4, 18, 21, 0.78);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(9px);
  cursor: pointer;
}

.fullscreen-exit-btn svg {
  width: 19px;
  height: 19px;
}

.viewer-frame.is-app-fullscreen .fullscreen-exit-btn {
  display: inline-flex;
}
