/* ── Reset & base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0c0e12;
  --surface:   #161b22;
  --surface2:  #1e2530;
  --border:    #2a3140;
  --text:      #e6eaf0;
  --text-sub:  #8892a0;
  --blue:      #3b82f6;
  --blue-dark: #2563eb;
  --green:     #25d366;
  --green-dark:#128c4a;
  --red:       #f87171;
  --amber:     #fbbf24;
  --radius:    14px;
  --radius-sm: 8px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

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

/* ── Header ── */
header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(22, 27, 34, 0.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}

/* ── Avatar button (header) ── */
.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  cursor: pointer;
  padding: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  transition: border-color 0.15s;
}
.avatar-btn:active { border-color: var(--blue); }

.avatar-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-initials {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  text-transform: uppercase;
  line-height: 1;
}

/* ── Profile sheet ── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0,0,0,0.5);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.profile-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  border-top: 1px solid var(--border);
  padding: 12px 20px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
}
.profile-sheet.open { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

/* identity row */
.profile-identity {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.profile-avatar-lg {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface2);
  border: 2px solid var(--border);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.profile-avatar-lg .avatar-initials { font-size: 22px; }
.profile-avatar-lg .avatar-img { width: 100%; height: 100%; object-fit: cover; }

.profile-name { font-size: 17px; font-weight: 600; margin-bottom: 5px; }

.profile-providers { display: flex; gap: 6px; flex-wrap: wrap; }

.provider-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 9px;
  font-size: 12px;
  color: var(--text-sub);
}

.sheet-divider {
  height: 1px;
  background: var(--border);
  margin: 16px 0;
}

/* link email */
.sheet-section-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.sheet-section-sub {
  font-size: 13px;
  color: var(--text-sub);
  margin-bottom: 12px;
  line-height: 1.5;
}

.btn-google-full {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

/* sheet action buttons */
.sheet-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 13px 16px;
  font-size: 15px;
  cursor: pointer;
  text-align: left;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.sheet-action-btn:active { background: var(--border); }
.sheet-action-danger { color: var(--red); }

/* ── Buttons ── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-primary:active { background: var(--blue-dark); }

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 17px;
  border-radius: var(--radius);
}

.btn-whatsapp {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--green);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-whatsapp:active { background: var(--green-dark); }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn-ghost:active { background: var(--surface2); }

.btn-icon { display: flex; align-items: center; }

/* ── Permission banner ── */
.perm-banner {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: #3d2000;
  border-bottom: 1px solid #7c4a00;
  padding: 14px 16px;
  font-size: 14px;
  line-height: 1.5;
}

.perm-banner-icon { font-size: 22px; flex-shrink: 0; margin-top: 2px; }

.perm-banner-body { flex: 1; }
.perm-banner-body strong { display: block; color: var(--amber); margin-bottom: 4px; }
.perm-banner-body p { color: #e8c97a; margin: 0; }

.perm-close {
  flex-shrink: 0;
  border: none;
  color: #e8c97a;
  font-size: 16px;
  padding: 4px 8px;
  line-height: 1;
}

/* ── Main container ── */
main {
  min-height: calc(100dvh - 49px);
  display: flex;
  flex-direction: column;
}

.view { display: flex; flex-direction: column; flex: 1; }

/* ── Login view ── */
.view-login {
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

.login-card {
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.app-logo { font-size: 56px; margin-bottom: 12px; }
.app-name { font-size: 26px; font-weight: 700; margin-bottom: 6px; }
.app-tagline { font-size: 14px; color: var(--text-sub); text-align: center; margin-bottom: 32px; }

.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 14px;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-google:active { background: var(--surface2); }

.or-divider {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
  color: var(--text-sub);
  font-size: 13px;
}
.or-divider::before,
.or-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.phone-group {
  width: 100%;
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

input[type=tel], input[type=text] {
  flex: 1;
  padding: 13px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 16px; /* 16px prevents iOS zoom */
  outline: none;
  min-width: 0;
}
input[type=tel]:focus,
input[type=text]:focus { border-color: var(--blue); }

/* ── Login mode toggle ── */
.login-mode-toggle {
  display: flex;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
  margin-bottom: 10px;
}

.mode-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-sub);
  border-radius: 6px;
  padding: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.mode-btn-active {
  background: var(--surface2);
  color: var(--text);
  font-weight: 600;
}

.form-error {
  color: var(--red);
  font-size: 13px;
  min-height: 18px;
  margin-top: 8px;
  text-align: center;
}

/* ── Status views (pending/denied) ── */
.view-status {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 24px;
  gap: 12px;
}
.status-icon { font-size: 52px; }
.view-status h2 { font-size: 22px; }
.view-status p { color: var(--text-sub); line-height: 1.6; }
.status-sub { font-size: 13px; margin-top: 8px; }
.status-sub strong { color: var(--text); }

/* ── App view ── */
.view-app {
  padding: 0;
  gap: 0;
}

/* Photo preview */
#preview-wrap {
  width: 100%;
  background: var(--surface);
  position: relative;
}

#preview-placeholder {
  aspect-ratio: 4/3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-sub);
}
.placeholder-icon { font-size: 44px; opacity: 0.4; }
.placeholder-text { font-size: 14px; opacity: 0.5; }

#canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* Processing status row */
.status-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 14px;
  color: var(--text-sub);
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Install hint (inside profile sheet, iOS) ── */
.install-hint {
  font-size: 13px;
  color: var(--text-sub);
  line-height: 1.5;
  margin-top: 8px;
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

/* ── Install banner ── */
.install-banner {
  position: fixed;
  bottom: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  z-index: 150;
  background: #0d1f44;
  border: 1px solid rgba(59, 130, 246, 0.45);
  border-radius: var(--radius);
  padding: 12px 10px 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  transform: translateY(calc(100% + 40px));
  transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}
.install-banner.show { transform: translateY(0); }

.install-banner-icon { font-size: 26px; flex-shrink: 0; }

.install-banner-body { flex: 1; min-width: 0; }
.install-banner-body strong {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.install-banner-sub {
  font-size: 12px;
  color: var(--text-sub);
  line-height: 1.4;
}

.install-banner-btn {
  flex-shrink: 0;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.install-banner-btn:active { background: var(--blue-dark); }

.install-banner-close {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
  -webkit-tap-highlight-color: transparent;
}

/* ── Update toast ── */
.update-toast {
  position: fixed;
  bottom: 24px;
  bottom: max(24px, env(safe-area-inset-bottom));
  left: 16px;
  right: 16px;
  z-index: 200;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.update-toast-actions { display: flex; gap: 8px; flex-shrink: 0; }

.update-btn-close {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-sub);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
}

.update-btn-now {
  background: var(--blue);
  border: none;
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.update-btn-now:active { background: var(--blue-dark); }

/* Save toast */
.save-toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30, 37, 48, 0.95);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 100;
  white-space: nowrap;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

/* Post-stamp action buttons */
.post-stamp-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.btn-save {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s;
}
.btn-save:active { background: var(--border); }

/* Action buttons */
.app-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--bg);
}

/* ── Admin view ── */
.view-admin {
  padding: 0 16px 32px;
}

.admin-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 0 8px;
}
.admin-header h2 { font-size: 20px; }

.admin-section { margin-top: 24px; }

.admin-section-title {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-sub);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  background: var(--amber);
  color: #000;
  font-size: 11px;
  font-weight: 700;
  border-radius: 20px;
  padding: 1px 7px;
}
.badge:empty { display: none; }

ul { list-style: none; }

.user-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.user-item .who { font-size: 14px; line-height: 1.5; min-width: 0; }
.user-item .who strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-item .who small { color: var(--text-sub); font-size: 12px; }
.user-item .actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn-approve {
  background: #14532d;
  color: #4ade80;
  border: 1px solid #166534;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-approve:active { background: #166534; }

.btn-deny {
  background: #3f0d0d;
  color: #f87171;
  border: 1px solid #7f1d1d;
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn-deny:active { background: #7f1d1d; }

.empty-state {
  color: var(--text-sub);
  font-size: 14px;
  padding: 12px 0;
  text-align: center;
}

/* ── Location gate ── */
.location-gate {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px 24px;
  gap: 14px;
}

.location-gate-icon { font-size: 52px; }

.location-gate h2 { font-size: 22px; font-weight: 700; }

.location-gate p {
  color: var(--text-sub);
  font-size: 15px;
  line-height: 1.6;
  max-width: 340px;
}

.location-gate-steps {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  text-align: left;
  width: 100%;
  max-width: 360px;
}

.location-gate-steps p {
  color: var(--text-sub);
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 10px;
}

.location-gate-steps ol {
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.location-gate-steps li {
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.location-gate-steps li strong { color: #fff; }

/* make app view position:relative so the gate can be absolute inside it */
.view-app { position: relative; }

/* ── My Photos button (camera view) ── */
.btn-my-photos {
  width: 100%;
  background: none;
  border: 1px dashed var(--border);
  color: var(--text-sub);
  border-radius: var(--radius);
  padding: 13px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s, color 0.15s;
}
.btn-my-photos:active { background: var(--surface2); color: var(--text); }

/* ── Discard button (after stamping) ── */
.btn-discard {
  width: 100%;
  background: none;
  border: none;
  color: var(--text-sub);
  font-size: 14px;
  padding: 10px;
  cursor: pointer;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn-discard:active { color: var(--text); }

/* ── Gallery view ── */
.view-gallery {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
}

.gallery-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gallery-header h2 { font-size: 18px; flex: 1; }
.gallery-header-sub {
  font-size: 12px;
  color: var(--text-sub);
  flex-shrink: 0;
}

.gallery-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
}

.gallery-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 20px;
  color: var(--text-sub);
  font-size: 14px;
}

.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 60px 24px;
  text-align: center;
  color: var(--text-sub);
}
.gallery-empty span { font-size: 48px; opacity: 0.4; }
.gallery-empty p { font-size: 15px; margin: 0; }
.gallery-empty-sub { font-size: 13px; opacity: 0.7; }

.gallery-group { padding: 0 0 8px; }

.gallery-date-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-sub);
  padding: 14px 14px 8px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 0 2px;
}

.gallery-thumb {
  position: relative;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--surface2);
  cursor: pointer;
}
.gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s;
}
.gallery-thumb:active img { transform: scale(0.96); }

.thumb-place {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff;
  font-size: 10px;
  padding: 12px 5px 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Photo modal ── */
.photo-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 300;
  background: rgba(0,0,0,0.92);
}

.photo-modal {
  position: fixed;
  inset: 0;
  z-index: 310;
  display: flex;
  flex-direction: column;
}

.modal-close {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: 16px;
  z-index: 320;
  background: rgba(0,0,0,0.5);
  border: none;
  color: #fff;
  font-size: 20px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.modal-img-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 48px 0 0;
}

.modal-img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.modal-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ── Tablet+ ── */
@media (min-width: 600px) {
  #preview-placeholder { aspect-ratio: 16/9; }
  .app-actions { flex-direction: row; }
  .btn-large { width: auto; flex: 1; }
  .view-login { padding: 48px 24px; }
  .login-card { max-width: 420px; }
}
