/* ═══════════════════════════════════════════
   PMFME Document Scanner — Modern Minimal CSS
   ═══════════════════════════════════════════ */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-alt: #f0f2f5;
  --text-primary: #1a1d23;
  --text-secondary: #5f6570;
  --text-muted: #9da3ae;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-dark: #1e40af;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --border: #e5e7eb;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.2s ease;
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ═══════════ HEADER ═══════════ */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.header-left h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-dark);
  letter-spacing: -0.3px;
}

.header-subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  display: block;
  margin-top: 1px;
}

.header-right { display: flex; gap: 8px; align-items: center; }

/* ═══════════ BUTTONS ═══════════ */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  border: none; cursor: pointer;
  font-family: inherit; font-weight: 600;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  outline: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-sm {
  padding: 6px 14px; font-size: 13px;
  background: var(--accent); color: #fff;
}
.btn-sm:hover:not(:disabled) { background: var(--accent-dark); }

.btn-icon {
  width: 40px; height: 40px; padding: 0;
  background: var(--surface-alt); color: var(--text-primary);
  border-radius: 50%; font-size: 18px;
}
.btn-icon:hover:not(:disabled) { background: var(--border); }

.btn-capture {
  padding: 14px 40px; font-size: 16px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  min-width: 180px;
}
.btn-capture:hover:not(:disabled) {
  background: var(--accent-dark);
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}
.btn-capture:active { transform: translateY(0) scale(0.98); }

.btn-voice {
  padding: 12px 24px; font-size: 15px;
  background: var(--success);
  color: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
}
.btn-voice:hover:not(:disabled) { background: #047857; }

.btn-voice.listening {
  background: var(--danger);
  animation: pulse-voice 1.2s ease-in-out infinite;
}

@keyframes pulse-voice {
  0%, 100% { box-shadow: 0 0 0 0 rgba(220,38,38,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(220,38,38,0); }
}

/* ═══════════ PROGRESS ═══════════ */
.progress-container {
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.progress-steps {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.chip {
  display: inline-flex; align-items: center;
  gap: 4px; padding: 5px 10px;
  border-radius: var(--radius-xl);
  background: var(--surface-alt);
  font-size: 12px; font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: all 0.3s ease;
  flex-shrink: 0;
}

.chip-icon { font-size: 12px; }

.chip.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 0 2px var(--accent-light);
  transform: scale(1.02);
}

.chip.done {
  background: var(--success-light);
  color: var(--success);
  font-weight: 600;
}

.chip.error { background: var(--danger-light); color: var(--danger); }
.chip.skipped { opacity: 0.4; text-decoration: line-through; }

/* ═══════════ MAIN LAYOUT ═══════════ */
main {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  padding: 16px;
  height: calc(100vh - 100px);
  overflow: hidden;
}

/* ═══════════ CAMERA PANEL ═══════════ */
.panel {
  display: flex; flex-direction: column;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.video-wrap {
  flex: 1 1 auto;
  position: relative;
  background: #0a0a0a;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
  overflow: hidden;
  min-height: 0;
  display: flex; align-items: center; justify-content: center;
}

video#video {
  width: 100%; height: 100%;
  object-fit: cover;
}

.overlay-box {
  position: absolute; inset: 10%;
  border: 2px dashed rgba(255,255,255,0.35);
  border-radius: var(--radius-md);
  pointer-events: none;
  transition: border-color 0.3s ease;
}

.step-instruction-overlay {
  position: absolute; bottom: 12px; left: 12px; right: 12px;
  padding: 10px 16px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  border-radius: var(--radius-sm);
  color: #fff; font-size: 14px; font-weight: 500;
  text-align: center;
}

.controls {
  display: flex; align-items: center;
  padding: 10px 16px;
  gap: 8px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.controls-left, .controls-right { flex: 0 0 auto; }
.controls-center { flex: 1; display: flex; justify-content: center; }

.pill {
  padding: 4px 10px;
  border-radius: var(--radius-xl);
  font-size: 11px; font-weight: 600;
  background: var(--surface-alt);
  color: var(--text-muted);
}

/* ═══════════ RIGHT COLUMN ═══════════ */
.right-col {
  display: flex; flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  padding-right: 4px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.card h3 {
  font-size: 14px; font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex; align-items: center; gap: 6px;
}

/* ═══════════ Q&A CHAT ═══════════ */
/* Q&A card uses .card base styles */

.qa-chat {
  max-height: 280px;
  overflow-y: auto;
  display: flex; flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px;
}

.qa-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.5;
  animation: fadeSlideUp 0.3s ease;
}

.qa-bubble.system {
  align-self: flex-start;
  background: var(--accent-light);
  color: var(--accent-dark);
  border-bottom-left-radius: 4px;
}

.qa-bubble.user {
  align-self: flex-end;
  background: var(--surface-alt);
  color: var(--text-primary);
  border-bottom-right-radius: 4px;
}

.qa-bubble.success {
  align-self: flex-start;
  background: var(--success-light);
  color: var(--success);
  border-bottom-left-radius: 4px;
}

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

/* ═══════════ LISTENING INDICATOR ═══════════ */
.qa-listen-indicator {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0 4px;
  border-top: 1px solid var(--border);
  justify-content: center;
  flex-direction: column;
}

.listen-ring {
  width: 48px; height: 48px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(37, 99, 235, 0.1);
  animation: listen-pulse 1.5s ease-in-out infinite;
}

.listen-ring.large {
  width: 64px; height: 64px;
}

.listen-ring-inner {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  animation: listen-glow 1.5s ease-in-out infinite;
}

.listen-ring.large .listen-ring-inner {
  width: 32px; height: 32px;
}

.listen-ring.processing {
  animation: none;
  background: rgba(217, 119, 6, 0.15);
}

.listen-ring.processing .listen-ring-inner {
  background: var(--warning);
  animation: spin 1s linear infinite;
}

@keyframes listen-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.3); }
  50% { box-shadow: 0 0 0 16px rgba(37,99,235,0); }
}

@keyframes listen-glow {
  0%, 100% { transform: scale(1); opacity: 0.8; }
  50% { transform: scale(1.15); opacity: 1; }
}

.qa-status {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
  text-align: center;
}

/* ═══════════ VOICE YES/NO OVERLAY ═══════════ */
.voice-yesno-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(8px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.3s ease;
}

.voice-yesno-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 32px 40px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 400px;
  width: 90%;
  animation: scaleIn 0.3s ease;
}

.voice-yesno-question {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 24px;
  line-height: 1.5;
}

.voice-yesno-indicator {
  display: flex; flex-direction: column;
  align-items: center; gap: 12px;
  margin-bottom: 20px;
}

.voice-yesno-status {
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
}

.voice-yesno-hint {
  font-size: 13px;
  color: var(--text-muted);
}

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}

/* ═══════════ REVIEW PAGE ═══════════ */
.review-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 300;
  overflow-y: auto;
  animation: fadeIn 0.4s ease;
}

.review-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

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

.review-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--accent-dark);
}

.review-subtitle {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

.review-section {
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.review-section h3 {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.review-field {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--surface-alt);
}

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

.review-field label {
  flex: 0 0 160px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.review-field input {
  flex: 1;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text-primary);
  transition: border-color var(--transition);
  min-width: 0;
}

.review-field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.review-doc-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.review-doc-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
}

.review-doc-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.review-doc-status {
  margin-left: auto;
  font-size: 12px;
  font-weight: 600;
  color: var(--success);
}

.review-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 20px;
  display: flex;
  justify-content: center;
  z-index: 310;
}

.btn-save {
  padding: 14px 48px;
  font-size: 16px;
  background: var(--success);
  color: #fff;
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  font-weight: 700;
}

.btn-save:hover:not(:disabled) {
  background: #047857;
  box-shadow: var(--shadow-lg);
  transform: translateY(-1px);
}

.btn-save:disabled {
  background: var(--text-muted);
}

@media (max-width: 600px) {
  .review-field label { flex: 0 0 120px; font-size: 12px; }
  .review-field input { font-size: 12px; }
  .review-doc-list { grid-template-columns: 1fr; }
  .review-container { padding: 16px 14px 80px; }
}

/* ═══════════ EXTRACTION FIELDS ═══════════ */
.extraction-fields {
  max-height: 400px;
  overflow-y: auto;
}

.kv {
  display: flex; gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--surface-alt);
  font-size: 13px;
}

.kv:last-child { border-bottom: none; }

.kv .label {
  flex: 0 0 auto;
  font-weight: 600;
  color: var(--text-secondary);
  min-width: 130px;
}

.kv .value {
  color: var(--text-primary);
  word-break: break-word;
}

.muted-text {
  color: var(--text-muted);
  font-size: 13px;
  font-style: italic;
}

/* ═══════════ BUFFERING OVERLAY ═══════════ */
.buffering-overlay {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  z-index: 50;
  display: none;
  flex-direction: column;
  align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 15px;
}

.spinner {
  width: 36px; height: 36px;
  border: 3px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 10px;
}

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

/* ═══════════ TOAST ═══════════ */
#toast {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%);
  background: var(--danger);
  color: #fff;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-lg);
  z-index: 9999;
  display: none; opacity: 0;
  transition: opacity 0.3s ease;
}

/* ═══════════ SCROLLBAR ═══════════ */
.right-col::-webkit-scrollbar,
.qa-chat::-webkit-scrollbar,
.extraction-fields::-webkit-scrollbar {
  width: 4px;
}

.right-col::-webkit-scrollbar-thumb,
.qa-chat::-webkit-scrollbar-thumb,
.extraction-fields::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ═══════════ HIDE INTERNALS ═══════════ */
#startBtn { display: none; }
#flipBtn { display: none; }
#log, #error { display: none; }

/* ═══════════ MOBILE RESPONSIVE ═══════════ */
@media (max-width: 900px) {
  html, body { height: auto; overflow-y: auto; }

  main {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto;
    height: auto; min-height: 100vh;
    padding: 10px;
    overflow: visible;
  }

  .panel { order: 1; }
  .right-col { order: 2; max-width: 100%; }

  .video-wrap { min-height: 55vh; max-height: 65vh; }

  header {
    flex-wrap: wrap; padding: 8px 14px;
  }
  .header-left h1 { font-size: 16px; }
  .header-subtitle { font-size: 10px; }

  .progress-container { padding: 6px 14px; }
  .chip { font-size: 11px; padding: 4px 8px; }

  .card { padding: 12px; }
  .controls { padding: 8px 12px; }

  .btn-capture { padding: 12px 28px; font-size: 15px; min-width: 160px; }
}

@media (max-width: 480px) {
  .video-wrap { min-height: 60vh; }
  main { padding: 8px; gap: 10px; }
  .kv .label { min-width: 100px; font-size: 12px; }
  .kv .value { font-size: 12px; }
}

/* ═══════════ DESKTOP ENHANCEMENTS ═══════════ */
@media (min-width: 1024px) {
  main { height: calc(100vh - 100px); }
  .video-wrap { height: auto; }
}
