/* Amulait Intake PWA — Mobile-first styles */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #1AB4FF;
  --primary-light: #e0f6ff;
  --text: #111827;
  --text-muted: #6b7280;
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); -webkit-tap-highlight-color: transparent; }

#app { max-width: 480px; margin: 0 auto; padding: 0 16px 40px; min-height: 100dvh; display: flex; flex-direction: column; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.header { display: flex; align-items: center; justify-content: space-between; padding: 16px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.header-logo { font-size: 18px; font-weight: 700; color: var(--primary); letter-spacing: -0.5px; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-status { font-size: 12px; color: var(--text-muted); display: flex; align-items: center; gap: 4px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.status-dot.offline { background: var(--warning); }
.btn-logout { background: none; border: none; font-size: 12px; font-weight: 600; color: var(--text-muted); cursor: pointer; padding: 4px 0; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
.btn-logout:active { color: var(--danger); }

/* ── Offline Banner ───────────────────────────────────────────────────────── */
.offline-banner { background: #fef3c7; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 14px; color: #92400e; display: flex; align-items: center; gap: 8px; }
.offline-banner.hidden { display: none; }

/* ── Validation Error Banner ─────────────────────────────────────────────── */
.validation-error { background: #fee2e2; border: 1px solid #fca5a5; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 14px; color: #b91c1c; display: flex; align-items: flex-start; gap: 8px; }
.validation-error::before { content: '⚠'; flex-shrink: 0; }
.validation-error.hidden { display: none; }

/* ── Document type select ─────────────────────────────────────────────────── */
.select-group { margin-bottom: 16px; }
.select-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.required-star { color: var(--danger); margin-left: 2px; }
.select-wrapper { position: relative; }
.select-wrapper::after { content: '▾'; position: absolute; right: 12px; top: 50%; transform: translateY(-50%); pointer-events: none; font-size: 14px; color: var(--text-muted); }
.select-wrapper select { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 11px 36px 11px 12px; font-size: 15px; font-family: inherit; background: var(--surface); color: var(--text); appearance: none; -webkit-appearance: none; cursor: pointer; }
.select-wrapper select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,180,255,.15); }
.select-wrapper select:invalid, .select-wrapper select option[value=""] { color: var(--text-muted); }

/* ── Upload Area (empty state) ────────────────────────────────────────────── */
.upload-area {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 22px 16px;
  text-align: center;
  margin-bottom: 16px;
  transition: border-color .15s, background .15s;
  cursor: pointer;
  /* iOS: ensures div registers touch as clickable */
  -webkit-tap-highlight-color: rgba(26,180,255,.12);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.upload-area:active { border-color: var(--primary); background: var(--primary-light); }
.upload-area svg { color: var(--primary); margin-bottom: 8px; display: block; margin-left: auto; margin-right: auto; }
.upload-label { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.upload-sub { font-size: 12px; color: var(--text-muted); }

/* ── Hidden file input (inline style="display:none" on element is the primary guard) ── */
#file-input { display: none; }

/* ── Pages Section ────────────────────────────────────────────────────────── */
.pages-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.pages-label { font-size: 13px; font-weight: 600; color: var(--text); }
.pages-hint { font-size: 11px; color: var(--text-muted); }

/* Horizontally scrollable strip of page thumbnails */
.pages-strip {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none; /* Firefox */
}
.pages-strip::-webkit-scrollbar { display: none; }

/* Individual page thumbnail */
.page-thumb {
  position: relative;
  flex-shrink: 0;
  width: 90px;
  height: 120px;
  border-radius: 8px;
  overflow: hidden;
  border: 2px solid var(--border);
  background: var(--bg);
  box-shadow: var(--shadow);
}
.page-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
/* Delete button — top-right corner */
.page-thumb-del {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0,0,0,.55);
  color: #fff;
  border: none;
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}
.page-thumb-del:active { background: var(--danger); }
/* Page number badge — bottom-left */
.page-thumb-num {
  position: absolute;
  bottom: 4px;
  left: 4px;
  background: rgba(0,0,0,.55);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 4px;
  padding: 1px 5px;
  line-height: 1.4;
}

/* "Add Another Page" ghost button (below strip) */
.btn-add-page { margin-top: 10px; margin-bottom: 16px; font-size: 14px; touch-action: manipulation; }

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 14px 20px; border-radius: var(--radius); font-size: 15px; font-weight: 600; border: none; cursor: pointer; transition: opacity .15s, transform .1s; -webkit-user-select: none; width: 100%; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }
.btn-danger  { background: var(--danger);  color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }

/* Submit Document button — bottom of form, margin above progress */
#btn-submit-doc { margin-bottom: 16px; }

/* ── Note field ───────────────────────────────────────────────────────────── */
.note-group { margin-bottom: 16px; }
.note-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 6px; }
.note-group textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 14px; font-family: inherit; resize: none; background: var(--surface); color: var(--text); }
.note-group textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,180,255,.15); }

/* ── Progress ─────────────────────────────────────────────────────────────── */
.upload-progress { display: none; background: var(--surface); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); }
.upload-progress.visible { display: block; }
.progress-label { font-size: 14px; font-weight: 500; margin-bottom: 10px; }
.progress-bar-track { background: var(--border); border-radius: 99px; height: 6px; overflow: hidden; }
.progress-bar-fill { height: 100%; background: var(--primary); border-radius: 99px; transition: width .3s; }
.progress-sub { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Queue Section ────────────────────────────────────────────────────────── */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); }
.section-actions { display: flex; align-items: center; gap: 12px; }
.btn-text { background: none; border: none; font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; color: var(--primary); }
.btn-text-danger { color: var(--danger); }
.queue-list { display: flex; flex-direction: column; gap: 8px; }

/* ── Queue Item ───────────────────────────────────────────────────────────── */
.queue-item { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.queue-item-tappable { cursor: pointer; }
.queue-item-tappable:active { opacity: 0.75; }
.queue-item-left { flex-shrink: 0; display: flex; align-items: center; }
.queue-item-icon { font-size: 22px; }
.queue-item-body { flex: 1; min-width: 0; }
.queue-item-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.queue-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Checkbox (select mode) ───────────────────────────────────────────────── */
.item-checkbox { display: inline-block; width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--border); background: var(--surface); transition: background .15s, border-color .15s; position: relative; }
.item-checkbox.checked { background: var(--primary); border-color: var(--primary); }
.item-checkbox.checked::after { content: ''; display: block; width: 6px; height: 10px; border: 2px solid #fff; border-top: none; border-left: none; transform: rotate(45deg); position: absolute; top: 3px; left: 6px; }

/* ── Badges ───────────────────────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 600; flex-shrink: 0; }
.badge-success    { background: #dcfce7; color: #15803d; }
.badge-processing { background: #dbeafe; color: #1d4ed8; }
.badge-queued     { background: #f3f4f6; color: #6b7280; }
.badge-failed     { background: #fee2e2; color: #b91c1c; }
.badge-manual     { background: #fef3c7; color: #b45309; }

/* ── Modal backdrop ───────────────────────────────────────────────────────── */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 100; display: flex; align-items: flex-end; }
.modal-backdrop.hidden { display: none; }

/* ── Modal sheet ──────────────────────────────────────────────────────────── */
.modal-sheet { background: var(--surface); border-radius: var(--radius) var(--radius) 0 0; padding: 12px 20px 32px; width: 100%; max-height: 85vh; overflow-y: auto; }
.modal-handle { width: 36px; height: 4px; background: var(--border); border-radius: 99px; margin: 0 auto 20px; }
.modal-preview { text-align: center; margin-bottom: 16px; min-height: 64px; display: flex; align-items: center; justify-content: center; }
.modal-preview img { max-width: 100%; max-height: 260px; border-radius: 8px; object-fit: contain; }
.modal-file-icon { font-size: 64px; line-height: 1; }
.modal-filename { font-size: 16px; font-weight: 600; word-break: break-all; margin-bottom: 4px; }
.modal-meta { font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
.modal-error { font-size: 12px; color: var(--danger); background: #fee2e2; border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.modal-actions { display: flex; flex-direction: column; gap: 8px; }

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-card { background: var(--surface); border-radius: var(--radius); padding: 32px 24px; box-shadow: var(--shadow); margin-top: 40px; }
.login-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.login-card p { font-size: 14px; color: var(--text-muted); margin-bottom: 24px; }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; }
.form-group input { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 11px 12px; font-size: 15px; font-family: inherit; background: var(--surface); color: var(--text); }
.form-group input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,180,255,.15); }
.error-msg { background: #fee2e2; color: #b91c1c; border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; display: none; }
.error-msg.visible { display: block; }

/* ── OTP input (TOTP step) ────────────────────────────────────────────────── */
.otp-input { text-align: center; font-size: 28px; font-weight: 700; letter-spacing: 0.25em; }

/* ── Back link (MFA step) ─────────────────────────────────────────────────── */
.btn-back { display: block; width: 100%; background: none; border: none; margin-top: 16px; font-size: 13px; color: var(--text-muted); cursor: pointer; padding: 4px 0; text-align: center; }
.btn-back:active { color: var(--primary); }

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

/* ── Dark mode ────────────────────────────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
  :root {
    --text: #f9fafb; --text-muted: #9ca3af; --bg: #111827; --surface: #1f2937;
    --border: #374151; --primary-light: #003d5c;
  }
  .offline-banner  { background: #422006; border-color: #78350f; color: #fef3c7; }
  .validation-error { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }
  .page-thumb { border-color: var(--border); }
}
