/* ===== DocScan — Document Scanner ===== */
:root {
  --bg: #0f0f1a;
  --surface: #1a1a2e;
  --surface2: #252540;
  --text: #e8e8f0;
  --text-dim: #8888a0;
  --accent: #6c5ce7;
  --accent-glow: rgba(108, 92, 231, 0.4);
  --danger: #e74c3c;
  --success: #2ecc71;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 14px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  position: relative;
}

/* ===== Top bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 10;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.topbar-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.icon-btn:active { transform: scale(0.92); }
.icon-btn.active { background: var(--accent); border-color: var(--accent); }

/* ===== Viewport ===== */
.viewport {
  flex: 1;
  position: relative;
  background: #000;
  overflow: hidden;
  min-height: 0;
}
#video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
}

.scan-hint {
  position: absolute;
  bottom: 120px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: var(--text-dim);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 0.85rem;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  transition: opacity 0.3s;
}
.scan-hint.hidden { opacity: 0; }

.scan-region-guide {
  position: absolute;
  border: 2px dashed rgba(108, 92, 231, 0.6);
  border-radius: 4px;
  pointer-events: none;
  transition: all 0.2s;
}

/* ===== Controls ===== */
.controls {
  padding: 16px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-shrink: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.capture-btn {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 4px solid var(--accent);
  background: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  box-shadow: 0 0 24px var(--accent-glow);
}
.capture-btn:active {
  transform: scale(0.95);
  box-shadow: 0 0 12px var(--accent-glow);
}
.capture-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: white;
  transition: all 0.15s;
}
.capture-btn:active .capture-circle {
  width: 36px;
  height: 36px;
}
.capture-label {
  position: absolute;
  bottom: -22px;
  white-space: nowrap;
  font-size: 0.75rem;
  color: var(--text-dim);
  letter-spacing: 1px;
}

/* ===== Preview panel ===== */
.preview-panel {
  position: absolute;
  inset: 0;
  background: var(--bg);
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 16px;
}
.preview-panel.hidden { display: none; }

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  flex-shrink: 0;
}
.preview-title {
  font-size: 1rem;
  font-weight: 600;
}
.preview-actions { display: flex; gap: 8px; }

.preview-canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0a14;
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 0;
  border: 1px solid var(--border);
}
#preview-canvas {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.preview-actions-row {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: center;
}
.preview-size {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
  padding-top: 6px;
  flex-shrink: 0;
}

.btn-primary {
  padding: 12px 22px;
  border: none;
  border-radius: 10px;
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-primary:active { transform: scale(0.96); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-outline {
  padding: 12px 22px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}
.btn-outline:active { transform: scale(0.96); }

/* ===== Gallery overlay ===== */
.gallery-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 30;
  flex-direction: column;
}
.gallery-overlay.hidden { display: none; }
.gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  color: var(--text);
  flex-shrink: 0;
}
.gallery-header h2 { font-size: 1.1rem; }
.gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
  align-content: start;
}
.gallery-item {
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.gallery-item.selected {
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.gallery-item:active { transform: scale(0.97); }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.85rem;
  z-index: 50;
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  transition: all 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(8px); }

/* ===== Hidden states ===== */
.hidden { display: none !important; }

/* ===== iPad / large screen ===== */
@media (min-width: 768px) {
  .viewport { border-radius: var(--radius); }
  .capture-btn { width: 80px; height: 80px; }
  .capture-circle { width: 54px; height: 54px; }
}
