/**
 * QuickScope Shared Styles
 * ========================
 * Common CSS styles shared across all QuickScope PWA modules.
 * 
 * Usage:
 *   <link rel="stylesheet" href="qs-styles.css">
 * 
 * @version 1.1.0
 * @date 2026-02-04
 */

/* ============================================
   CSS RESET & BOX SIZING
   ============================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* ============================================
   CSS CUSTOM PROPERTIES (Design Tokens)
   ============================================ */
:root {
  /* Primary Colors - Purple Theme */
  --primary-500: #7c3aed;
  --primary-600: #6d28d9;
  --primary-700: #5b21b6;
  --primary-light: #ede9fe;
  --gradient-primary: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%);
  --gradient-header: linear-gradient(135deg, #7c3aed 0%, #818cf8 100%);
  
  /* Semantic Colors */
  --success: #10b981;
  --success-light: #d1fae5;
  --success-glow: rgba(16, 185, 129, 0.2);
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --error: #ef4444;
  --error-light: #fee2e2;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  
  /* Gray Scale */
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  
  /* Typography */
  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --shadow-xl: 0 20px 40px rgba(0, 0, 0, 0.2);
}

/* ============================================
   BASE STYLES
   ============================================ */
body {
  font-family: var(--font-sans);
  background: var(--gray-100);
  color: var(--gray-800);
  min-height: 100vh;
  line-height: 1.5;
}

.container {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
}

/* ============================================
   HEADER STYLES
   ============================================ */
.header {
  background: var(--gradient-header);
  color: white;
  padding: 20px 16px 56px;
  position: relative;
  z-index: 100;
}

.header-content {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.header-title {
  font-size: 1.5rem;
  font-weight: 800;
}

.header-subtitle {
  font-size: 0.8125rem;
  opacity: 0.9;
  margin-top: 2px;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border-radius: 12px;
  font-weight: 600;
  font-size: 0.9375rem;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
}

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

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.4);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-secondary {
  background: var(--gray-100);
  color: var(--gray-700);
}

.btn-secondary:hover {
  background: var(--gray-200);
}

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

.btn-success:hover {
  background: #059669;
}

.btn-danger {
  background: var(--error);
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-back {
  background: none;
  color: var(--gray-500);
  padding: 8px 0;
  margin-bottom: 12px;
  width: auto;
  font-size: 0.875rem;
}

.btn-back:hover {
  color: var(--gray-700);
}

.logout-btn {
  background: rgba(255, 255, 255, 0.18);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.25);
  color: white;
  padding: 10px 16px;
  border-radius: 12px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.logout-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

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

.back-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

/* ============================================
   FORM ELEMENTS
   ============================================ */
.input-group {
  margin-bottom: 16px;
}

.input-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--gray-600);
  margin-bottom: 6px;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
}

.select,
.input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--gray-200);
  border-radius: 12px;
  font-size: 0.9375rem;
  font-family: inherit;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  appearance: none;
}

.select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 40px;
  cursor: pointer;
}

.select:focus,
.input:focus {
  outline: none;
  border-color: var(--primary-500);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.select:disabled,
.input:disabled {
  background: var(--gray-100);
  cursor: not-allowed;
}

.error-msg {
  color: var(--error);
  font-size: 0.8125rem;
  margin-top: 8px;
  display: none;
}

.error-msg.show {
  display: block;
}

/* ============================================
   CARDS
   ============================================ */
.card {
  background: white;
  border-radius: 16px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-100);
}

.card-icon {
  font-size: 1.5rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

/* ============================================
   LOADING OVERLAY
   ============================================ */
.loading-overlay {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
}

.loading-overlay.active {
  display: flex;
}

.loading-overlay .spinner {
  width: 32px;
  height: 32px;
  border-width: 3px;
}

.loading-overlay p,
.loading-text {
  color: var(--gray-600);
  font-size: 0.875rem;
}

/* ============================================
   SPINNER
   ============================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.spinner-dark {
  border-color: var(--gray-200);
  border-top-color: var(--primary-500);
}

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

/* ============================================
   OFFLINE & SYNC BADGES
   ============================================ */
.offline-badge {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  z-index: 9999;
  display: none;
  animation: pulse 2s infinite;
}

.offline-badge.show {
  display: block;
}

.sync-badge {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--primary-500);
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 700;
  z-index: 9999;
  display: none;
}

.sync-badge.show {
  display: block;
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ============================================
   TOAST NOTIFICATIONS
   ============================================ */
@keyframes toastSlide {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}

/* ============================================
   MODALS
   ============================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

@keyframes modalSlideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-overlay.hidden {
  display: none;
}

/* Confirmation Modal */
.confirm-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
  padding: 20px;
}

.confirm-modal.hidden {
  display: none;
}

.confirm-modal-content {
  background: white;
  border-radius: 20px;
  padding: 28px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  animation: modalSlideIn 0.25s ease-out;
}

.confirm-modal-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.confirm-modal-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--gray-800);
  margin-bottom: 8px;
}

.confirm-modal-message {
  font-size: 0.9rem;
  color: var(--gray-500);
  margin-bottom: 24px;
  line-height: 1.5;
}

.confirm-modal-buttons {
  display: flex;
  gap: 12px;
}

.confirm-modal-buttons button {
  flex: 1;
  padding: 14px 20px;
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  border: none;
  font-family: inherit;
}

.confirm-modal-buttons button:active {
  transform: scale(0.97);
}

.confirm-btn-cancel {
  background: var(--gray-100);
  color: var(--gray-700);
}

.confirm-btn-danger {
  background: var(--error);
  color: white;
}

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

/* ============================================
   CHIPS
   ============================================ */
.chip {
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 0.75rem;
}

.header-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ============================================
   BADGES
   ============================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 700;
}

.badge-success {
  background: var(--success-light);
  color: var(--success);
}

.badge-warning {
  background: var(--warning-light);
  color: var(--warning);
}

.badge-error {
  background: var(--error-light);
  color: var(--error);
}

.badge-info {
  background: var(--primary-light);
  color: var(--primary-600);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
  display: none !important;
}

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

.text-right {
  text-align: right;
}

.text-mono {
  font-family: var(--font-mono);
}

.text-success {
  color: var(--success);
}

.text-error {
  color: var(--error);
}

.text-warning {
  color: var(--warning);
}

.text-muted {
  color: var(--gray-500);
}

.mt-2 {
  margin-top: 8px;
}

.mt-4 {
  margin-top: 16px;
}

.mb-2 {
  margin-bottom: 8px;
}

.mb-4 {
  margin-bottom: 16px;
}

.bottom-padding {
  height: 40px;
}

/* ============================================
   ANIMATION KEYFRAMES
   ============================================ */
@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  20%, 60% {
    transform: translateX(-8px);
  }
  40%, 80% {
    transform: translateX(8px);
  }
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ============================================
   EXTRACTION OVERLAY (AI Processing)
   ============================================ */
.extract-overlay {
  position: fixed;
  inset: 0;
  background: white;
  z-index: 250;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.extract-overlay.hidden {
  display: none;
}

.extract-header {
  text-align: center;
  margin-bottom: 24px;
}

.extract-header-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

.extract-header-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--gray-800);
}

.extract-header-sub {
  font-size: 0.875rem;
  color: var(--gray-500);
  margin-top: 4px;
}

.extract-status {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}

.extract-status-dot {
  width: 10px;
  height: 10px;
  background: var(--primary-500);
  border-radius: 50%;
  animation: pulse 1s infinite;
}

.extract-status-text {
  font-size: 0.9rem;
  color: var(--gray-600);
}

.extract-card {
  background: var(--gray-50);
  border-radius: 16px;
  padding: 20px;
  width: 100%;
  max-width: 400px;
}

.extract-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--gray-200);
}

.extract-field:last-child {
  border-bottom: none;
}

.extract-field-label {
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--gray-700);
}

.extract-field-value {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--gray-400);
  margin-top: 2px;
}

.extract-field.filled .extract-field-value {
  color: var(--success);
}

.extract-field-bar {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 4px;
}

.extract-field-bar-fill {
  height: 100%;
  background: var(--primary-500);
  width: 0%;
  animation: barPulse 1.5s ease-in-out infinite;
}

@keyframes barPulse {
  0% { width: 0%; }
  50% { width: 70%; }
  100% { width: 30%; }
}

.extract-complete {
  text-align: center;
  padding: 16px;
  color: var(--success);
  font-weight: 700;
  opacity: 0;
  transition: opacity 0.3s;
}

.extract-complete.visible {
  opacity: 1;
}

/* ============================================
   UPLOAD ZONE
   ============================================ */
.upload-zone {
  border: 2px dashed var(--gray-300);
  border-radius: 12px;
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: var(--gray-50);
}

.upload-zone:hover {
  border-color: var(--primary-500);
  background: var(--primary-light);
}

.upload-zone.has-file {
  border-color: var(--success);
  background: var(--success-light);
  border-style: solid;
}

.upload-zone-icon {
  font-size: 3rem;
  margin-bottom: 12px;
}

.upload-zone-text {
  font-weight: 600;
  color: var(--gray-700);
}

.upload-zone-hint {
  font-size: 0.8125rem;
  color: var(--gray-500);
  margin-top: 6px;
}

.upload-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.upload-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  border: 2px dashed var(--gray-300);
  border-radius: 12px;
  background: var(--gray-50);
  cursor: pointer;
  transition: all 0.2s;
}

.upload-option:hover {
  border-color: var(--primary-500);
  background: var(--primary-light);
}

.upload-option:active {
  transform: scale(0.98);
}

.upload-option-icon {
  font-size: 2rem;
}

.upload-option-label {
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--gray-700);
}

.upload-option-hint {
  font-size: 0.7rem;
  color: var(--gray-500);
}

/* ============================================
   ENHANCED PULL-TO-REFRESH
   ============================================ */

/* Pull-to-Refresh Indicator */
.ptr-indicator {
  position: fixed;
  top: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: top 0.25s ease, transform 0.25s ease, opacity 0.25s ease;
  z-index: 1000;
  opacity: 0;
}

.ptr-indicator.pulling {
  opacity: 1;
}

.ptr-indicator.refreshing {
  top: 16px;
  opacity: 1;
}

/* Animated arrow that rotates based on pull progress */
.ptr-arrow {
  font-size: 1.5rem;
  color: var(--primary-500);
  transition: transform 0.2s ease;
  display: block;
}

.ptr-indicator.ready .ptr-arrow {
  transform: rotate(180deg);
  color: var(--success);
}

/* Spinner - hidden until refreshing */
.ptr-spinner {
  display: none;
  width: 24px;
  height: 24px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary-500);
  border-radius: 50%;
  animation: ptrSpin 0.7s linear infinite;
}

.ptr-indicator.refreshing .ptr-arrow {
  display: none;
}

.ptr-indicator.refreshing .ptr-spinner {
  display: block;
}

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

/* Pull hint text */
.ptr-hint {
  position: fixed;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.75rem;
  color: var(--gray-500);
  background: white;
  padding: 6px 14px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  opacity: 0;
  transition: opacity 0.2s ease, top 0.25s ease;
  z-index: 999;
  white-space: nowrap;
  font-weight: 500;
}

.ptr-hint.show {
  opacity: 1;
}

.ptr-hint.refreshing-text {
  top: 75px;
}

/* Pulse animation when ready to release */
.ptr-indicator.ready {
  animation: ptrPulse 0.6s ease infinite;
}

@keyframes ptrPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.1); }
}

/* Success animation */
.ptr-indicator.success {
  background: var(--success);
  animation: ptrSuccess 0.4s ease forwards;
}

.ptr-indicator.success .ptr-spinner {
  display: none;
}

.ptr-indicator.success::after {
  content: '✓';
  color: white;
  font-size: 1.5rem;
  font-weight: bold;
}

@keyframes ptrSuccess {
  0% { transform: translateX(-50%) scale(1); }
  50% { transform: translateX(-50%) scale(1.2); }
  100% { transform: translateX(-50%) scale(1); }
}
