:root {
  --bg-color: #0b0f19;
  --surface-color: #161f30;
  --surface-border: #23314a;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --accent-color: #3b82f6;
  --accent-hover: #2563eb;
  --success-color: #10b981;
  --cvm-active-bg: #2563eb;
  --cvm-active-border: #60a5fa;
  --radius-lg: 18px;
  --radius-md: 12px;
  --radius-sm: 8px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-color);
  color: var(--text-primary);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header */
.app-header {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: rgba(22, 31, 48, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--surface-border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-link-btn {
  background: #1e293b;
  color: #f1f5f9;
  border: 1px solid var(--surface-border);
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 6px;
}

.nav-link-btn:active {
  background: #334155;
}

.user-badge {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* Main Container */
.main-viewport {
  flex: 1;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  height: calc(100dvh - 56px);
}

/* Top Progress bar & Meta */
.status-bar {
  padding: 8px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  background: #111827;
  border-bottom: 1px solid #1f2937;
}

.task-id-badge {
  font-family: monospace;
  background: #1e293b;
  color: #38bdf8;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  font-size: 13px;
}

.counter-badge {
  color: #94a3b8;
  font-weight: 600;
}

/* Viewer Container */
.image-viewport-wrapper {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: none;
  width: 100%;
  height: 100%;
}

.panzoom-scene {
  display: flex;
  align-items: center;
  justify-content: center;
  transform-origin: center center;
}

#mainImage {
  max-width: 96vw;
  max-height: 60vh;
  width: auto;
  height: auto;
  object-fit: contain;
  display: block;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: auto;
  border-radius: 4px;
}

/* Floating Controls (Reset Zoom & hint) */
.zoom-controls-floating {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
  z-index: 20;
}

.btn-floating {
  background: rgba(15, 23, 42, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 8px 14px;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

.btn-floating:active {
  background: rgba(30, 41, 59, 0.95);
  transform: scale(0.96);
}

/* Progress loader bar on top */
.progress-loader {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background: rgba(255, 255, 255, 0.1);
  overflow: hidden;
  z-index: 60;
  display: none;
}

.progress-loader .progress-bar-fill {
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, #38bdf8, #2563eb);
  transform: translateX(-100%);
  animation: indeterminate 1.1s infinite linear;
  transform-origin: left;
}

@keyframes indeterminate {
  0% { transform: translateX(-100%) scaleX(0.2); }
  50% { transform: translateX(0%) scaleX(0.6); }
  100% { transform: translateX(100%) scaleX(0.2); }
}

/* Image loading spinner */
.img-loading-spinner {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: #94a3b8;
  font-size: 14px;
  font-weight: 500;
  z-index: 10;
  pointer-events: none;
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3.5px solid rgba(255, 255, 255, 0.15);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.75s infinite linear;
}

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

/* Bottom Controls Section */
.bottom-dock {
  background: var(--surface-color);
  border-top: 1px solid var(--surface-border);
  padding: 12px 14px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 30;
  min-height: 128px;
}

/* 6 CVM Stage Buttons Grid */
.cvm-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.cvm-grid.loading-hidden {
  opacity: 0.15;
  pointer-events: none;
  filter: blur(1px);
}

.cvm-btn {
  background: #1e293b;
  border: 1.5px solid #334155;
  color: #e2e8f0;
  height: 52px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 700;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease-out;
}

.cvm-btn span.stage-num {
  font-size: 18px;
  line-height: 1.1;
}

.cvm-btn span.stage-lbl {
  font-size: 10px;
  letter-spacing: 0.5px;
  opacity: 0.8;
}

.cvm-btn:active {
  transform: scale(0.93);
}

.cvm-btn.selected {
  background: #2563eb !important;
  border-color: #60a5fa !important;
  color: #ffffff !important;
  box-shadow: 0 0 16px rgba(37, 99, 235, 0.6);
}

/* Navigation prev / next */
.nav-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.nav-action-btn {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fff;
  height: 46px;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
}

.nav-action-btn:active {
  background: #334155;
  transform: scale(0.97);
}

.nav-action-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
}

.nav-action-btn.primary {
  background: #0284c7;
  border-color: #38bdf8;
}

.nav-action-btn.primary:active {
  background: #0369a1;
}

/* Login Card Screen */
.login-screen {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #1e293b 0%, #0b0f19 70%);
}

.login-card {
  background: #161f30;
  border: 1px solid var(--surface-border);
  padding: 32px 24px;
  border-radius: 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
}

.login-card h1 {
  font-size: 22px;
  margin-bottom: 8px;
  color: #fff;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

.code-input {
  width: 100%;
  padding: 16px;
  font-size: 24px;
  text-align: center;
  letter-spacing: 6px;
  font-weight: 700;
  border-radius: var(--radius-md);
  border: 2px solid #334155;
  background: #0f172a;
  color: #38bdf8;
  outline: none;
  margin-bottom: 18px;
}

.code-input:focus {
  border-color: #38bdf8;
  box-shadow: 0 0 12px rgba(56, 189, 248, 0.25);
}

.login-btn {
  width: 100%;
  height: 52px;
  background: #2563eb;
  border: none;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.login-btn:active {
  background: #1d4ed8;
}

/* Overview / Index page */
.overview-container {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.stats-card {
  background: #161f30;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
  gap: 10px;
}

.card-item {
  background: #161f30;
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease;
}

.card-item:active {
  transform: scale(0.96);
}

.card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  background: #000;
  object-fit: cover;
  display: block;
}

.card-info {
  padding: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
}

.badge-stage {
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 700;
  background: #2563eb;
  color: #fff;
}

.badge-pending {
  padding: 2px 5px;
  border-radius: 4px;
  font-weight: 600;
  background: #334155;
  color: #94a3b8;
}
