/* ── Variables ── */
:root {
  --bg: #0a0a14;
  --surface: #13132a;
  --surface2: #1a1a35;
  --surface3: #22223f;
  --accent: #7c3aed;
  --accent-dim: rgba(124, 58, 237, 0.15);
  --accent-border: rgba(124, 58, 237, 0.42);
  --text: #ededf8;
  --text-muted: #7070a0;
  --text-dim: #3d3d60;
  --border: #21213e;
  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.11);
  --success-border: rgba(34, 197, 94, 0.38);
  --warn: #f59e0b;
  --warn-bg: rgba(245, 158, 11, 0.11);
  --warn-border: rgba(245, 158, 11, 0.38);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --ease: 0.18s ease;
  --header-h: 64px;
  --tabs-h: 46px;
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  min-height: 100dvh;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

/* ── Header ── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 14px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.logo {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--accent), #5b21b6);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 900;
  color: white;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.35);
}

.header-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.header-text p {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 1px;
}

/* ── Tabs ── */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: var(--header-h);
  z-index: 99;
  padding: 0 4px;
}

.tab {
  flex: 1;
  padding: 13px 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all var(--ease);
  user-select: none;
  letter-spacing: 0.01em;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ── Pages ── */
.page {
  display: none;
  padding: 20px 16px 120px;
  max-width: 720px;
  margin: 0 auto;
}

.page.active { display: block; }

/* ── Scan page ── */
.scan-area {
  background: var(--surface);
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--ease), background var(--ease), transform var(--ease);
  position: relative;
  overflow: hidden;
}

.scan-area:hover {
  border-color: var(--accent-border);
  background: var(--surface2);
}

.scan-area:active { transform: scale(0.995); }

.scan-area.drag-over {
  border-color: var(--success);
  background: var(--success-bg);
}

.scan-icon { font-size: 50px; margin-bottom: 14px; line-height: 1; }
.scan-area h2 { font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.scan-area p { font-size: 13.5px; color: var(--text-muted); line-height: 1.55; }

.btn-gallery {
  width: 100%;
  margin-top: 10px;
  padding: 10px 14px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  text-align: center;
  transition: border-color var(--ease), color var(--ease);
}
.btn-gallery:hover { border-color: var(--accent-border); color: var(--text); }

/* ── Camera modal ── */
.camera-modal {
  position: fixed;
  inset: 0;
  z-index: 500;
  background: #000;
  display: flex;
  flex-direction: column;
}
.camera-video {
  flex: 1;
  width: 100%;
  object-fit: contain;
  min-height: 0;
}
.camera-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 32px max(28px, env(safe-area-inset-bottom));
  background: rgba(0, 0, 0, 0.72);
  flex-shrink: 0;
}
.btn-shutter {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: #fff;
  border: 5px solid rgba(255, 255, 255, 0.45);
  box-shadow: 0 0 0 6px rgba(255, 255, 255, 0.18);
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.1s ease, background 0.1s ease;
}
.btn-shutter:active { transform: scale(0.90); background: #ccc; }
.btn-camera-side {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  font-family: var(--font);
}
.btn-camera-side:hover { background: rgba(255, 255, 255, 0.26); }

.camera-badge {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(-80px);
  background: rgba(22, 196, 101, 0.93);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 9px 22px;
  border-radius: 999px;
  pointer-events: none;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s;
  opacity: 0;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  z-index: 510;
}
.camera-badge.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

input[type="file"] {
  position: fixed;
  top: -9999px;
  left: -9999px;
  opacity: 0;
  pointer-events: none;
  width: 0;
  height: 0;
}

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 15px 20px;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  transition: opacity var(--ease), transform var(--ease), box-shadow var(--ease);
  letter-spacing: 0.01em;
  font-family: var(--font);
}

.btn:active { opacity: 0.8; transform: scale(0.983); }
.btn:disabled { opacity: 0.35; pointer-events: none; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent) 0%, #5b21b6 100%);
  color: white;
  box-shadow: 0 4px 18px rgba(124, 58, 237, 0.32);
}

.btn-primary:hover { box-shadow: 0 6px 22px rgba(124, 58, 237, 0.44); }

.btn-secondary {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-success {
  background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
  color: white;
  box-shadow: 0 4px 16px rgba(22, 163, 74, 0.28);
}

.btn-danger {
  background: var(--surface2);
  color: #fc8080;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.btn-danger:hover { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.6); }

.btn-sm {
  padding: 9px 14px;
  font-size: 13px;
  width: auto;
  font-weight: 600;
  border-radius: var(--radius-sm);
}

.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mt-5 { margin-top: 20px; }

/* ── Loading overlay ── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 20, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  text-align: center;
  padding: 24px;
}

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

.spinner {
  width: 50px;
  height: 50px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}

.loading-overlay p { font-size: 16px; font-weight: 600; }
.loading-overlay small { color: var(--text-muted); font-size: 13px; }

/* ── Section title ── */
.section-title {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 24px 0 10px;
}

/* ── Review form ── */
.field-group { display: flex; flex-direction: column; gap: 10px; }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.field label {
  display: block;
  font-size: 10px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field input {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color var(--ease), background var(--ease);
  appearance: none;
  -webkit-appearance: none;
}

.field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface3);
}

.field input[readonly] {
  opacity: 0.45;
  background: var(--surface);
  cursor: default;
}

/* ── Status badges ── */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  margin-bottom: 10px;
  border: 1px solid transparent;
  line-height: 1.35;
}

.status-badge.ok {
  color: var(--success);
  border-color: var(--success-border);
  background: var(--success-bg);
}

.status-badge.warn {
  color: var(--warn);
  border-color: var(--warn-border);
  background: var(--warn-bg);
}

/* ── Radio group / selectors ── */
.radio-group { display: flex; gap: 8px; }

.radio-group.scrollable {
  overflow-x: auto;
  overflow-y: hidden;
  flex-wrap: nowrap;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  -webkit-overflow-scrolling: touch;
}

.radio-group.scrollable::-webkit-scrollbar { height: 4px; }
.radio-group.scrollable::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }

.radio-opt {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all var(--ease);
  user-select: none;
}

.radio-group.scrollable .radio-opt { flex: 0 0 auto; white-space: nowrap; }
#squadraSelector .radio-opt { flex: 1 1 0; }
.radio-opt.selected { background: var(--accent-dim); border-color: var(--accent); color: var(--text); }
.radio-opt input { display: none; }

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 20px;
  left: 16px;
  right: 16px;
  transform: translateY(140px);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 14px 14px 16px;
  font-size: 13.5px;
  font-weight: 600;
  transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  z-index: 300;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-height: min(40vh, 280px);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
}

.toast.show { transform: translateY(0); }
.toast.success { border-color: var(--success-border); }
.toast.error { border-color: var(--accent-border); }

.toast-body {
  min-width: 0;
  flex: 1;
  color: var(--text);
  line-height: 1.5;
  word-break: break-word;
  overflow-y: auto;
  padding-right: 4px;
}

.toast-close {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--ease);
}

.toast-close:hover { background: var(--surface3); }

/* ── Records list ── */
.record-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 10px;
  transition: border-color var(--ease);
}

.record-card:hover { border-color: var(--text-dim); }
.record-card h3 { font-size: 15.5px; font-weight: 700; margin-bottom: 4px; }
.record-card .meta { font-size: 12px; color: var(--text-muted); margin-bottom: 8px; line-height: 1.7; }
.record-card .fields { display: flex; flex-wrap: wrap; gap: 6px; }

.chip {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text-muted);
}

.chip span { color: var(--text); font-weight: 600; }

.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}

.empty-state .icon { font-size: 48px; margin-bottom: 14px; line-height: 1; }
.empty-state p { font-size: 15px; }

/* ── Bottom safe area ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .page { padding-bottom: calc(120px + env(safe-area-inset-bottom)); }
}

/* ── OCR Queue panel ── */
.queue-panel {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.queue-item {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  transition: border-color var(--ease), opacity var(--ease);
}

.queue-item.qi-done       { border-color: var(--accent-border); }
.queue-item.qi-processing { border-color: var(--accent); animation: pulseBorder 1.4s ease-in-out infinite; }
.queue-item.qi-error      { border-color: rgba(239, 68, 68, 0.42); }
.queue-item.qi-reviewed   { opacity: 0.35; }

@keyframes pulseBorder {
  0%, 100% { border-color: var(--accent); }
  50%       { border-color: rgba(124, 58, 237, 0.22); }
}

.qi-icon { flex-shrink: 0; font-size: 14px; }
.qi-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text); }
.qi-status { flex-shrink: 0; font-size: 12px; color: var(--text-muted); }
.queue-item.qi-done .qi-status       { color: var(--accent); font-weight: 600; }
.queue-item.qi-processing .qi-status { color: var(--accent); }
.queue-item.qi-error .qi-status      { color: #fc8080; font-weight: 600; }
.qi-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  opacity: 0.55;
  transition: opacity var(--ease), color var(--ease);
}
.qi-remove:hover { opacity: 1; color: #fc8080; }

/* ── Review image ── */
.review-image-wrap {
  position: relative;
  cursor: zoom-in;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  border: 1.5px solid var(--border);
  margin-bottom: 16px;
  transition: border-color var(--ease);
}

.review-image-wrap:hover { border-color: var(--accent-border); }

.review-image {
  width: 100%;
  max-height: 55vh;
  object-fit: contain;
  display: block;
}

.review-image-hint {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0, 0, 0, 0.6);
  color: rgba(255, 255, 255, 0.65);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  pointer-events: none;
  letter-spacing: 0.04em;
}

.review-nav-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.review-counter {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  flex: 1;
}

/* ── Review nav bar (fixed bottom) ── */
.review-nav-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  display: flex;
  gap: 10px;
  padding: 12px 16px max(16px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 60%, transparent);
  pointer-events: none;
}
.review-nav-bar .btn-nav {
  pointer-events: all;
}
.btn-nav {
  flex: 1;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  border-radius: 999px;
  height: 48px;
  font-size: 14px;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background var(--ease), color var(--ease), border-color var(--ease);
  -webkit-tap-highlight-color: transparent;
}
.btn-nav:not(:disabled) {
  color: var(--text);
  border-color: var(--accent-border);
}
.btn-nav:not(:disabled):active {
  background: var(--surface3);
}
.btn-nav:disabled { opacity: 0.22; cursor: default; }

/* ── Lightbox ── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.96);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 16px;
  cursor: zoom-out;
}

.lightbox.open {
  display: flex;
  animation: lbFadeIn 0.18s ease;
}

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

.lightbox-img {
  max-width: 100%;
  max-height: calc(100dvh - 60px);
  object-fit: contain;
  border-radius: 6px;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: white;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }

/* ── Desktop ── */
@media (min-width: 700px) {
  #page-review.active {
    display: grid;
    grid-template-columns: 42% 1fr;
    gap: 32px;
    align-items: start;
  }

  #reviewEmpty {
    grid-column: 1 / -1;
  }

  #reviewImageWrap {
    position: sticky;
    top: calc(var(--header-h) + var(--tabs-h) + 16px);
    grid-row: 1 / 20;
  }

  .review-image { max-height: 82vh; }
}

@media (min-width: 900px) {
  .page { padding-left: 24px; padding-right: 24px; }

  #page-review.active {
    grid-template-columns: 52% 1fr;
  }

  .review-image { max-height: 90vh; }
}

/* ── Logout button ── */
.btn-logout {
  margin-left: auto;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease);
}

.btn-logout:hover { background: var(--surface2); color: var(--text); }

/* ── Select dropdown ── */
.field-select {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 36px 11px 13px;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font);
  transition: border-color var(--ease);
  appearance: none;
  -webkit-appearance: none;
  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='%237070a0' stroke-width='2.5' 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;
  cursor: pointer;
}

.field-select:focus {
  outline: none;
  border-color: var(--accent);
  background-color: var(--surface3);
}

.field-select option {
  background: #1a1a35;
  color: var(--text);
}

/* ── Login overlay ── */
.login-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 400;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-overlay.visible { display: flex; }

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 32px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 28px 72px rgba(0, 0, 0, 0.55);
  text-align: center;
}

.login-logo {
  width: 56px !important;
  height: 56px !important;
  font-size: 26px !important;
  margin: 0 auto 22px !important;
}

.login-card h2 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 6px;
}

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

.login-card .field { text-align: left; }

.login-error {
  font-size: 12.5px;
  color: #fc8080;
  min-height: 18px;
  margin-top: 10px;
  text-align: center;
}
