:root {
  --purple: #7C3AED;
  --purple-dark: #6D28D9;
  --purple-light: #EDE9FE;
  --green: #22C55E;
  --green-dark: #16A34A;
  --red: #EF4444;
  --yellow: #F59E0B;
  --blue: #3B82F6;
  --gray-50: #F9FAFB;
  --gray-100: #F3F4F6;
  --gray-300: #D1D5DB;
  --gray-500: #6B7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 14px;
  --radius-sm: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Screen layout (NOT display — JS handles that) ── */
.screen {
  flex-direction: column;
  min-height: 100dvh;
}

/* ── Top bar ── */
.topbar {
  background: var(--purple);
  color: #fff;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar h1 { font-size: 18px; font-weight: 700; flex: 1; }
.topbar .subtitle { font-size: 11px; opacity: 0.8; font-weight: 400; }
.topbar-btn {
  background: none; border: none; color: #fff; cursor: pointer;
  font-size: 20px; padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.topbar-btn:active { background: rgba(255,255,255,0.15); }

/* ── Content area ── */
.content { flex: 1; padding: 16px; overflow-y: auto; }

/* ── Cards ── */
.card {
  background: #fff;
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  padding: 16px;
}
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}
.stat-card .icon { font-size: 22px; margin-bottom: 8px; }
.stat-card .value { font-size: 28px; font-weight: 700; }
.stat-card .label { font-size: 12px; color: var(--gray-500); }

/* ── Buttons ── */
.btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--purple); color: #fff; }
.btn-green { background: var(--green); color: #fff; }
.btn-outline {
  background: transparent;
  border: 1.5px solid var(--gray-300);
  color: var(--gray-700);
  padding: 14px;
  font-size: 15px;
}
.btn-text {
  background: none; border: none;
  color: var(--gray-500); font-size: 13px;
  padding: 10px; cursor: pointer;
}
.btn-sm { padding: 10px 16px; font-size: 14px; border-radius: var(--radius-sm); }
.btn-icon {
  background: none; border: none; cursor: pointer;
  font-size: 24px; padding: 8px; color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ── Login ── */
.login-wrap {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  flex: 1; padding: 32px;
  background: linear-gradient(135deg, var(--purple) 0%, var(--purple-dark) 100%);
}
.login-box {
  background: #fff; border-radius: 20px;
  padding: 32px 24px; width: 100%; max-width: 360px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-box h1 { text-align: center; margin-bottom: 4px; color: var(--purple); font-size: 22px; }
.login-box .sub { text-align: center; color: var(--gray-500); font-size: 13px; margin-bottom: 24px; }
.input-group { margin-bottom: 16px; }
.input-group label { display: block; font-size: 13px; font-weight: 600; color: var(--gray-700); margin-bottom: 6px; }
.input-group input {
  width: 100%; padding: 12px 14px; border: 1.5px solid var(--gray-300);
  border-radius: 12px; font-size: 15px; outline: none; transition: border 0.2s;
}
.input-group input:focus { border-color: var(--purple); }
.login-error { color: var(--red); font-size: 13px; text-align: center; margin-bottom: 12px; }

/* ── Store list ── */
.search-box {
  width: 100%; padding: 12px 14px 12px 40px;
  border: 1.5px solid var(--gray-300);
  border-radius: 12px; font-size: 15px; outline: none;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' fill='%236B7280' viewBox='0 0 24 24'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.47 6.47 0 0016 9.5 6.5 6.5 0 109.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E") 12px center no-repeat;
}
.search-box:focus { border-color: var(--purple); }
.store-count { font-size: 12px; color: var(--gray-500); padding: 8px 0; }
.store-list { display: flex; flex-direction: column; gap: 8px; }
.store-item {
  background: #fff; border-radius: var(--radius);
  padding: 14px; cursor: pointer;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  display: flex; align-items: center; gap: 12px;
  transition: background 0.15s;
}
.store-item:active { background: var(--gray-100); }
.store-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--purple-light); color: var(--purple);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; flex-shrink: 0;
}
.store-info { flex: 1; min-width: 0; }
.store-info .name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.store-info .network { font-size: 12px; color: var(--purple); font-weight: 500; }
.store-info .address { font-size: 11px; color: var(--gray-500); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; color: var(--gray-500);
  text-align: center; gap: 8px;
}
.empty-state .icon { font-size: 48px; opacity: 0.4; }

/* ── Camera screen ── */
#screen-camera { background: #000; position: relative; }
.camera-topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 10;
  background: rgba(0,0,0,0.6);
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex; align-items: center; gap: 12px;
}
.camera-topbar .store-label { flex: 1; color: #fff; }
.camera-topbar .store-label .net { font-size: 14px; font-weight: 700; }
.camera-topbar .store-label .nm { font-size: 12px; opacity: 0.8; }
.camera-counter {
  background: var(--purple); color: #fff;
  padding: 6px 16px; border-radius: 20px;
  font-size: 14px; font-weight: 700;
}
.camera-video-wrap {
  flex: 1; position: relative; display: flex;
  align-items: center; justify-content: center;
  overflow: hidden;
}
.camera-video-wrap video {
  width: 100%; height: 100%; object-fit: cover;
}
.camera-frame {
  position: absolute; pointer-events: none;
  border: 2px solid rgba(255,255,255,0.8);
  border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.45);
}
.camera-frame-label {
  position: absolute; right: 12px; top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,0.6); color: #fff;
  padding: 4px 8px; border-radius: 8px;
  font-size: 12px; font-weight: 700; z-index: 5;
}
.camera-bottom {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.7); z-index: 10;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
}
.thumb-strip {
  display: flex; gap: 8px; padding: 8px 12px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.thumb-strip::-webkit-scrollbar { display: none; }
.thumb-item {
  position: relative; flex-shrink: 0;
  border: 2px solid var(--purple);
  border-radius: 8px; overflow: hidden; cursor: pointer;
}
.thumb-item.landscape { width: 80px; height: 45px; }
.thumb-item.portrait { width: 45px; height: 80px; }
.thumb-item img { width: 100%; height: 100%; object-fit: cover; }
.thumb-num {
  position: absolute; top: 2px; left: 2px;
  background: var(--purple); color: #fff;
  font-size: 10px; font-weight: 700;
  width: 18px; height: 18px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
}
.thumb-del {
  position: absolute; top: 2px; right: 2px;
  background: rgba(0,0,0,0.5); color: #fff;
  font-size: 12px; border: none; cursor: pointer;
  width: 16px; height: 16px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
.camera-controls {
  display: flex; align-items: center; justify-content: space-evenly;
  padding: 20px 0;
}
.capture-btn {
  width: 72px; height: 72px; border-radius: 50%;
  background: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; color: var(--purple);
  transition: transform 0.1s;
}
.capture-btn:active { transform: scale(0.92); }
.capture-btn:disabled { opacity: 0.5; }
.done-btn { font-size: 36px; color: #ccc; background: none; border: none; cursor: pointer; padding: 8px; }
.done-btn.ready { color: var(--green); }

/* ── Collage preview ── */
.collage-img {
  width: 100%; border-radius: 12px;
  max-height: 50vh; object-fit: contain;
}
.collage-info {
  background: var(--purple-light); border-radius: var(--radius);
  padding: 16px; display: flex; align-items: center; gap: 16px;
}
.collage-info .icon { font-size: 28px; color: var(--purple); }
.collage-info .text .title { font-size: 16px; font-weight: 700; }
.collage-info .text .sub { font-size: 13px; color: var(--gray-500); }

/* ── Photo list ── */
.photo-item {
  background: #fff; border-radius: 12px; padding: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  display: flex; align-items: center; gap: 12px;
}
.photo-thumb {
  width: 70px; height: 70px; border-radius: 8px;
  object-fit: cover; flex-shrink: 0; background: var(--gray-100);
}
.photo-info { flex: 1; min-width: 0; }
.photo-info .network { font-size: 13px; font-weight: 700; color: var(--purple); }
.photo-info .store { font-size: 12px; }
.photo-status { display: flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 500; }
.photo-date { font-size: 11px; color: var(--gray-500); }
.photo-error { font-size: 10px; color: var(--red); }
.photo-actions { display: flex; flex-direction: column; gap: 4px; }
.photo-actions button {
  background: none; border: none; cursor: pointer;
  font-size: 20px; padding: 4px;
}

/* ── Snackbar ── */
.snackbar {
  position: fixed; bottom: 24px; left: 16px; right: 16px;
  background: var(--gray-900); color: #fff;
  padding: 14px 20px; border-radius: 12px;
  font-size: 14px; z-index: 9999;
  transform: translateY(120%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  text-align: center;
}
.snackbar.show { transform: translateY(0); }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
