/* ===========================
   Bulk Scanner - Ocean Bottle
   Mobile-first NFC scanning app
   =========================== */

:root {
  --primary: #146FF8;
  --primary-dark: #1059CC;
  --dark: #0E1311;
  --white: #FFFFFF;
  --teal: #0A8F8F;
  --success: #10B981;
  --success-bg: #D1FAE5;
  --duplicate: #F59E0B;
  --duplicate-bg: #FEF3C7;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-200: #E5E7EB;
  --gray-300: #D1D5DB;
  --gray-400: #9CA3AF;
  --gray-500: #6B7280;
  --gray-600: #4B5563;
  --gray-700: #374151;
  --gray-800: #1F2937;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

/* -- Reset & Base -- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--gray-50);
  color: var(--dark);
  line-height: 1.5;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
}

/* -- App Container -- */

.app-container {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--white);
  position: relative;
}

/* -- Screen Base -- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 24px 20px;
  padding-bottom: env(safe-area-inset-bottom, 24px);
}

/* =======================
   START SCREEN
   ======================= */

.start-screen {
  justify-content: center;
  align-items: center;
  gap: 48px;
}

.logo-section {
  text-align: center;
}

.logo-mark {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}

.logo-icon {
  width: 64px;
  height: 64px;
  color: var(--teal);
}

.app-title {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--dark);
  margin-bottom: 4px;
}

.app-subtitle {
  font-size: 1rem;
  color: var(--gray-500);
  font-weight: 400;
}

.instructions {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.instruction-step {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px;
  background: var(--gray-50);
  border-radius: var(--radius);
}

.step-number {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: var(--teal);
  color: var(--white);
  border-radius: 50%;
  font-size: 0.875rem;
  font-weight: 600;
}

.step-text {
  font-size: 0.9375rem;
  color: var(--gray-700);
}

.nfc-warning {
  width: 100%;
  padding: 16px;
  background: var(--duplicate-bg);
  border: 1px solid var(--duplicate);
  border-radius: var(--radius);
  text-align: center;
}

.nfc-warning-title {
  font-weight: 600;
  font-size: 0.9375rem;
  color: var(--gray-800);
  margin-bottom: 4px;
}

.nfc-warning-text {
  font-size: 0.875rem;
  color: var(--gray-600);
}

/* =======================
   SCANNING SCREEN
   ======================= */

.scanning-screen {
  gap: 0;
  padding-bottom: 0;
}

.scan-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 0 24px;
  gap: 16px;
}

/* NFC Pulse Indicator */

.scan-indicator {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 96px;
  height: 96px;
}

.scan-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--teal);
  opacity: 0;
}

.pulsing .scan-ring {
  animation: pulse-ring 2s cubic-bezier(0.4, 0, 0.6, 1) infinite;
}

.pulsing .scan-ring-2 {
  animation-delay: 0.6s;
}

@keyframes pulse-ring {
  0% {
    transform: scale(0.8);
    opacity: 0.6;
  }
  100% {
    transform: scale(1.6);
    opacity: 0;
  }
}

.scan-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--teal);
  color: var(--white);
  border-radius: 50%;
  font-size: 0.8125rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  z-index: 1;
}

.pulsing .scan-icon {
  animation: pulse-icon 2s ease-in-out infinite;
}

@keyframes pulse-icon {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

.error-banner {
  width: 100%;
  padding: 12px 16px;
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  text-align: center;
}

/* Stats Bar */

.stats-bar {
  display: flex;
  gap: 1px;
  background: var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 8px;
  background: var(--white);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
}

/* Last Scan Flash */

.last-scan {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--success-bg);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  animation: flash-in 0.3s ease-out;
}

.last-scan-label {
  font-size: 0.8125rem;
  color: var(--gray-600);
  font-weight: 500;
}

.last-scan-id {
  font-size: 0.875rem;
  font-family: var(--font-mono);
  color: var(--success);
  font-weight: 600;
}

@keyframes flash-in {
  0% {
    background-color: var(--success);
    color: var(--white);
  }
  100% {
    background-color: var(--success-bg);
  }
}

/* Scan List */

.scan-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -20px;
  padding: 0 20px;
  min-height: 0;
}

.scan-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
  transition: background-color 0.15s ease;
}

.scan-item.duplicate {
  background: var(--duplicate-bg);
}

.scan-item-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.scan-id {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--dark);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-url {
  font-size: 0.75rem;
  color: var(--gray-400);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Scan item enter animation */

.scan-item-enter {
  opacity: 0;
  transform: translateX(20px);
}

.scan-item {
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Badges */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.badge-duplicate {
  background: var(--duplicate);
  color: var(--white);
}

/* Scan Actions Bar */

.scan-actions {
  display: flex;
  gap: 12px;
  padding: 16px 20px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  background: var(--white);
  border-top: 1px solid var(--gray-200);
  position: sticky;
  bottom: 0;
  margin: 0 -20px;
  margin-top: auto;
  z-index: 10;
}

.scan-actions .btn {
  flex: 1;
}

/* =======================
   REVIEW SCREEN
   ======================= */

.review-screen {
  gap: 24px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom, 0px));
}

.review-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--dark);
}

/* Stats Summary Cards */

.stats-summary {
  display: flex;
  gap: 12px;
}

.stat-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 8px;
  background: var(--gray-50);
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
}

.stat-card-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--dark);
  line-height: 1.2;
}

.stat-card-label {
  font-size: 0.75rem;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 500;
  margin-top: 2px;
}

/* Export Actions */

.export-actions {
  display: flex;
  gap: 12px;
}

.export-actions .btn {
  flex: 1;
}

/* Diff Section */

.diff-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--dark);
}

.expected-input {
  width: 100%;
  min-height: 100px;
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  line-height: 1.6;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
  transition: border-color 0.15s ease;
  background: var(--white);
  color: var(--dark);
}

.expected-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(20, 111, 248, 0.1);
}

.expected-input::placeholder {
  color: var(--gray-400);
}

/* Diff Results */

.diff-results {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.diff-group {
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.diff-group h4 {
  padding: 10px 16px;
  font-size: 0.8125rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.diff-matches h4 {
  background: var(--success-bg);
  color: var(--success);
}

.diff-missing h4 {
  background: var(--danger-bg);
  color: var(--danger);
}

.diff-extra h4 {
  background: var(--duplicate-bg);
  color: var(--duplicate);
}

.diff-id {
  padding: 8px 16px;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  border-bottom: 1px solid var(--gray-100);
}

.diff-id.match {
  background: #F0FDF4;
  color: var(--gray-700);
}

.diff-id.missing {
  background: #FEF2F2;
  color: var(--danger);
}

.diff-id.extra {
  background: #FFFBEB;
  color: var(--gray-700);
}

/* Full Scan List (Review) */

.full-scan-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.full-scan-list .section-title {
  margin-bottom: 8px;
}

.scan-item-review {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-100);
}

.scan-item-review.duplicate {
  background: var(--duplicate-bg);
}

.scan-item-review .scan-id {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scan-time {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--gray-400);
  white-space: nowrap;
}

/* Review Actions */

.review-actions {
  display: flex;
  gap: 12px;
  position: sticky;
  bottom: 0;
  background: var(--white);
  padding: 16px 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  margin-top: auto;
  border-top: 1px solid var(--gray-200);
  z-index: 10;
}

.review-actions .btn {
  flex: 1;
}

/* =======================
   BUTTONS
   ======================= */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 12px 20px;
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border-radius: var(--radius);
  border: 2px solid transparent;
  cursor: pointer;
  transition: all 0.15s ease;
  outline: none;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: var(--white);
  border-color: var(--primary);
}

.btn-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.btn-primary:active:not(:disabled) {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--white);
  color: var(--dark);
  border-color: var(--gray-300);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-400);
}

.btn-outline {
  background: transparent;
  color: var(--gray-600);
  border-color: var(--gray-200);
}

.btn-outline:hover:not(:disabled) {
  background: var(--gray-50);
  border-color: var(--gray-300);
}

.btn-large {
  width: 100%;
  padding: 16px 24px;
  font-size: 1.0625rem;
}

.btn-block {
  width: 100%;
}

/* =======================
   UTILITIES
   ======================= */

/* Smooth scroll for scan list */
.scan-list::-webkit-scrollbar {
  width: 4px;
}

.scan-list::-webkit-scrollbar-track {
  background: transparent;
}

.scan-list::-webkit-scrollbar-thumb {
  background: var(--gray-300);
  border-radius: 2px;
}

/* Safe area padding for bottom fixed elements */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .scan-actions,
  .review-screen {
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
  }
}

/* Focus visible for keyboard navigation */
.btn:focus-visible {
  box-shadow: 0 0 0 3px rgba(20, 111, 248, 0.3);
}

/* Selection color */
::selection {
  background: rgba(20, 111, 248, 0.15);
}

/* Prevent text selection on interactive elements */
.btn,
.scan-indicator,
.stat,
.stat-card,
.step-number {
  user-select: none;
  -webkit-user-select: none;
}

/* =======================
   TUTORIAL OVERLAY
   ======================= */

.tutorial-demo-btn {
  margin-top: 8px;
}

.tutorial-overlay {
  position: absolute;
  inset: 0;
  z-index: 50;
  pointer-events: none;
  display: flex;
  flex-direction: column;
}

.tutorial-skip {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 51;
  pointer-events: auto;
  padding: 8px 16px;
  font-size: 0.8125rem;
  font-weight: 600;
  font-family: var(--font-sans);
  color: var(--white);
  background: rgba(0, 0, 0, 0.45);
  border: none;
  border-radius: 100px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.tutorial-skip:active {
  background: rgba(0, 0, 0, 0.6);
}

/* Annotation bubble */

.tutorial-annotation {
  position: absolute;
  left: 20px;
  right: 20px;
  pointer-events: auto;
  cursor: pointer;
  padding: 16px 20px;
  background: rgba(14, 19, 17, 0.82);
  color: var(--white);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s ease, transform 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}

.tutorial-annotation--top {
  top: 140px;
}

.tutorial-annotation--center {
  top: 50%;
  transform: translateY(-50%);
}

.tutorial-annotation--bottom {
  bottom: 120px;
}

.tutorial-annotation--enter {
  opacity: 0;
  transform: translateY(8px);
}

.tutorial-annotation--enter.tutorial-annotation--center {
  transform: translateY(calc(-50% + 8px));
}

.tutorial-annotation-text {
  font-size: 0.9375rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
}

/* End panel */

.tutorial-end-panel {
  position: absolute;
  bottom: 80px;
  left: 20px;
  right: 20px;
  pointer-events: auto;
  padding: 24px 20px;
  background: rgba(14, 19, 17, 0.88);
  color: var(--white);
  border-radius: var(--radius);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-lg);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.tutorial-end-text {
  font-size: 1.0625rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 20px;
}

.tutorial-end-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tutorial-end-actions .btn {
  width: 100%;
}

/* Progress dots */

.tutorial-progress {
  position: absolute;
  bottom: 40px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 8px;
  pointer-events: none;
}

.tutorial-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transition: background 0.2s ease, transform 0.2s ease;
}

.tutorial-dot--active {
  background: var(--white);
  transform: scale(1.4);
}

.tutorial-dot--done {
  background: rgba(255, 255, 255, 0.6);
}
