/* PDF Scanner - Modern Dark Theme */
:root {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #252542;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --accent-glow: rgba(99, 102, 241, 0.3);
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.3);
  --text-primary: #ffffff;
  --text-secondary: #a1a1aa;
  --text-muted: #6b7280;
  --border: rgba(255, 255, 255, 0.1);
  --glass: rgba(255, 255, 255, 0.05);
  --glass-border: rgba(255, 255, 255, 0.1);
  --shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 20px;
  --radius-full: 9999px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 100%;
  overflow: hidden;
}

/* Header */
.header {
  position: relative;
  z-index: 100;
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top));
  background: linear-gradient(180deg, var(--bg-primary) 0%, transparent 100%);
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 18px;
}

.logo-icon {
  width: 28px;
  height: 28px;
  color: var(--accent);
}

.page-counter {
  background: var(--glass);
  border: 1px solid var(--glass-border);
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  backdrop-filter: blur(10px);
}

/* Main Content */
.main-content {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Camera Container */
.camera-container {
  position: absolute;
  inset: 0;
  background: #000;
}

.camera-container video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.scan-frame {
  position: relative;
  width: 85%;
  aspect-ratio: 210/297; /* A4 aspect ratio */
  max-height: 70%;
}

.corner {
  position: absolute;
  width: 30px;
  height: 30px;
  border-color: var(--accent);
  border-style: solid;
  border-width: 0;
}

.corner.top-left {
  top: 0;
  left: 0;
  border-top-width: 3px;
  border-left-width: 3px;
  border-top-left-radius: 8px;
}

.corner.top-right {
  top: 0;
  right: 0;
  border-top-width: 3px;
  border-right-width: 3px;
  border-top-right-radius: 8px;
}

.corner.bottom-left {
  bottom: 0;
  left: 0;
  border-bottom-width: 3px;
  border-left-width: 3px;
  border-bottom-left-radius: 8px;
}

.corner.bottom-right {
  bottom: 0;
  right: 0;
  border-bottom-width: 3px;
  border-right-width: 3px;
  border-bottom-right-radius: 8px;
}

/* Preview Container */
.preview-container {
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.preview-wrapper {
  position: relative;
  max-width: 100%;
  max-height: 100%;
}

.preview-wrapper img {
  max-width: 100%;
  max-height: calc(100vh - 250px);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}

.preview-actions {
  position: absolute;
  top: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
}

/* Pages Gallery */
.pages-gallery {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  background: linear-gradient(0deg, var(--bg-primary) 0%, transparent 100%);
}

.pages-scroll {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 8px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.pages-scroll::-webkit-scrollbar {
  display: none;
}

.page-thumb {
  flex-shrink: 0;
  width: 50px;
  height: 70px;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: all 0.2s ease;
}

.page-thumb:hover,
.page-thumb.active {
  border-color: var(--accent);
  box-shadow: 0 0 20px var(--accent-glow);
}

.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.page-thumb .remove-page {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 20px;
  height: 20px;
  background: #ef4444;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.page-thumb:hover .remove-page {
  opacity: 1;
}

.remove-page svg {
  width: 12px;
  height: 12px;
  color: white;
}

/* Controls */
.controls {
  position: relative;
  z-index: 100;
  padding: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(0deg, var(--bg-secondary) 80%, transparent 100%);
}

.controls-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Buttons */
.btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 10px;
  border-radius: var(--radius-md);
  transition: all 0.2s ease;
  min-width: 70px;
}

.btn svg {
  width: 24px;
  height: 24px;
}

.btn span {
  font-size: 11px;
  font-weight: 500;
}

.btn-secondary {
  color: var(--text-secondary);
}

.btn-secondary:hover {
  color: var(--text-primary);
  background: var(--glass);
}

.btn-primary {
  color: var(--accent-light);
}

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

.btn-primary:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* Capture Button */
.btn-capture {
  position: relative;
  width: 72px;
  height: 72px;
  min-width: 72px;
  padding: 0;
  background: transparent;
}

.capture-ring {
  width: 100%;
  height: 100%;
  border: 4px solid var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.capture-inner {
  width: 56px;
  height: 56px;
  background: var(--accent);
  border-radius: 50%;
  transition: all 0.15s ease;
}

.btn-capture:hover .capture-ring {
  border-color: var(--accent-light);
  box-shadow: 0 0 30px var(--accent-glow);
}

.btn-capture:hover .capture-inner {
  background: var(--accent-light);
}

.btn-capture:active .capture-inner {
  transform: scale(0.9);
}

/* Icon Button */
.btn-icon {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(10px);
  border: 1px solid var(--glass-border);
  border-radius: 50%;
  cursor: pointer;
  color: var(--text-primary);
  transition: all 0.2s ease;
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.btn-icon:hover {
  background: var(--glass);
  border-color: var(--accent);
  color: var(--accent);
}

/* Loading Overlay */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 26, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(10px);
}

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

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 3px solid var(--bg-tertiary);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 20px;
}

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

.loading-content p {
  color: var(--text-secondary);
  font-size: 15px;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 15, 26, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(10px);
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 40px 30px;
  max-width: 320px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
  animation: modalIn 0.3s ease;
}

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

.success-icon {
  width: 70px;
  height: 70px;
  background: var(--success-glow);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  animation: successPulse 0.5s ease;
}

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

.success-icon svg {
  width: 35px;
  height: 35px;
  color: var(--success);
}

.modal-content h2 {
  font-size: 24px;
  margin-bottom: 10px;
  font-weight: 600;
}

.modal-content p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 25px;
}

.btn-full {
  width: 100%;
  flex-direction: row;
  justify-content: center;
  padding: 14px 20px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-md);
}

.btn-full:hover {
  background: var(--accent-light) !important;
}

/* Utility */
.hidden {
  display: none !important;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
  .app-container {
    height: -webkit-fill-available;
  }
}
