:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2127;
  --muted: #6b7280;
  --primary: #2f5df5;
  --primary-dark: #1f45c9;
  --danger: #e0473f;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.hidden { display: none !important; }
.muted { color: var(--muted); }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}
.container.narrow { max-width: 680px; }

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}
.brand {
  font-weight: 700;
  font-size: 18px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }
.brand-mark { color: var(--primary); }

.search-form {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 200px;
}
.search-form input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.search-form button {
  padding: 9px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}

.nav-actions { display: flex; align-items: center; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; }
.link-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  text-decoration: underline;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn:hover { text-decoration: none; background: #f0f1f4; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdecec; }
.btn-lg { padding: 12px 20px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-google { justify-content: center; width: 100%; }
.btn-whatsapp { background: #25d366; border-color: #25d366; color: #fff; }
.btn-whatsapp:hover { background: #1ebe5a; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Landing page (shown to signed-out visitors) */
.landing-body { margin: 0; }

.landing-nav {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.landing-nav-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hero {
  text-align: center;
  padding: 72px 20px 56px;
  background: linear-gradient(180deg, #eef2ff 0%, var(--bg) 100%);
}
.hero-inner { max-width: 640px; margin: 0 auto; }
.hero h1 { font-size: 34px; line-height: 1.2; margin: 0 0 16px; }
.hero-subtitle { color: var(--muted); font-size: 16px; line-height: 1.6; margin: 0 0 28px; }
.hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: center;
  align-items: center;
}
.hero .error-banner { text-align: left; }

.landing-section-inner { max-width: 1100px; margin: 0 auto; padding: 56px 20px; }
.landing-features h2,
.landing-steps h2 { text-align: center; font-size: 26px; margin: 0 0 36px; }
.landing-steps { background: var(--surface); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }

.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px;
}
.feature-icon { font-size: 28px; margin-bottom: 10px; }
.feature-card h3 { font-size: 16px; margin: 0 0 8px; }
.feature-card p { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0; }

.steps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 28px;
  text-align: center;
}
.step-number {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  margin: 0 auto 12px;
}
.step h3 { font-size: 16px; margin: 0 0 6px; }
.step p { color: var(--muted); font-size: 14px; line-height: 1.55; margin: 0; }

.landing-footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 28px 20px 40px;
}

.small-note { font-size: 13px; }

@media (max-width: 640px) {
  .hero { padding: 52px 20px 40px; }
  .hero h1 { font-size: 27px; }
}

.error-banner {
  background: #fdecec;
  color: var(--danger);
  border: 1px solid #f5c6c3;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 16px;
}

/* Card grid */
.results-meta { color: var(--muted); font-size: 14px; margin-bottom: 16px; }
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 18px;
  margin-top: 12px;
}
.card-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  color: var(--text);
  display: flex;
  flex-direction: column;
}
.card-tile:hover { text-decoration: none; border-color: var(--primary); }
.card-tile-image { aspect-ratio: 16 / 10; background: #eee; overflow: hidden; }
.card-tile-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card-tile-image-placeholder,
.detail-image-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eef0f4;
  color: var(--muted);
  font-size: 28px;
}
.card-tile-image-placeholder { width: 100%; height: 100%; }
.detail-image-placeholder {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 40px;
}
.card-tile-body { padding: 12px 14px; }
.card-tile-name { font-weight: 600; margin-bottom: 2px; }
.card-tile-sub { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.card-tile-meta { font-size: 12px; color: var(--muted); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state .btn { margin-top: 12px; }

/* Add card page */
.capture-tabs { display: flex; gap: 8px; margin: 16px 0; }
.tab-btn {
  padding: 8px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
}
.tab-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.camera-wrap {
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  display: flex;
  align-items: center;
  justify-content: center;
}
#video { width: 100%; height: 100%; object-fit: cover; }

.capture-actions { display: flex; gap: 10px; margin-top: 14px; flex-wrap: wrap; }

.file-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 40px 20px;
  cursor: pointer;
  color: var(--muted);
  text-align: center;
}
.file-drop input { display: none; }

#preview-section img {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-top: 10px;
}

.review-form { margin-top: 24px; }
.review-form-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 16px 0;
}
.form-grid label { display: flex; flex-direction: column; font-size: 13px; color: var(--muted); gap: 5px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.form-grid input, .form-grid textarea {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
}

.back-image-section {
  margin: 20px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.back-image-group-label { font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.file-drop-sm { padding: 18px 16px; font-size: 13px; margin-top: 8px; }
.back-image-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 8px;
}
.back-image-preview img {
  width: 96px;
  height: 64px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.extra-fields-section {
  margin: 20px 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.extra-fields-section h3 { font-size: 15px; margin: 0 0 2px; }
.extra-field-group { margin: 14px 0; }
.extra-field-group-label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.extra-fields { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.extra-field-row {
  display: grid;
  grid-template-columns: 1fr 2fr auto;
  gap: 8px;
  align-items: center;
}
.extra-field-row input {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  width: 100%;
}
.btn-remove-extra {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  width: 32px;
  height: 32px;
}
.btn-remove-extra:hover { background: #fdecec; color: var(--danger); border-color: #f5c6c3; }
@media (max-width: 480px) {
  .extra-field-row { grid-template-columns: 1fr; }
}

.raw-text-details { margin-top: 16px; }
.raw-text-details pre {
  background: #f0f1f4;
  padding: 12px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  font-size: 12px;
  max-height: 200px;
  overflow-y: auto;
}

/* Card detail */
.back-link { display: inline-block; margin-bottom: 16px; }
.detail-layout { display: flex; flex-direction: column; gap: 20px; }
.detail-image img {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.detail-actions { margin-top: 4px; }
.delete-form { margin-top: -8px; }
.share-actions { margin: -8px 0 4px; }

@media (min-width: 640px) {
  .form-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .form-grid { grid-template-columns: 1fr; }
}

/* ===================================================================
   Shared building blocks for the Phase 1/2 + admin pages
   =================================================================== */

.section-title {
  font-size: 15px;
  font-weight: 600;
  margin: 28px 0 12px;
  color: var(--text);
}

/* Badges (status / role pills) */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.6;
  text-transform: capitalize;
  border: 1px solid transparent;
}
.badge-pending  { background: #fff4e0; color: #9a6400; border-color: #f5dcae; }
.badge-approved { background: #e6f6ec; color: #1b7a3d; border-color: #bfe6cd; }
.badge-disabled { background: #f0f1f4; color: #6b7280; border-color: var(--border); }
.badge-admin    { background: #e8edff; color: var(--primary-dark); border-color: #c9d5fb; }
.badge-super    { background: #efe7fb; color: #6b39c9; border-color: #d8c7f3; }

/* ---- Admin: stats + user table ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  margin-top: 8px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}
.stat-num { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 4px; }

.admin-table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.admin-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.admin-table th,
.admin-table td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  background: #fafbfc;
}
.admin-table tr:last-child td { border-bottom: none; }
.admin-user { font-weight: 600; }
.admin-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.admin-actions form { margin: 0; }

/* ---- Folders (library + shared) ---- */
.library-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 12px 0 4px;
}
.breadcrumbs { font-size: 14px; margin-bottom: 8px; }
.breadcrumbs .crumb-sep { color: var(--muted); margin: 0 6px; }

.folder-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
}
.folder-tile {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  color: var(--text);
}
.folder-tile:hover { text-decoration: none; border-color: var(--primary); }
.folder-icon { font-size: 22px; }
.folder-name { font-weight: 600; }
.folder-meta { color: var(--muted); }

/* Card tile + inline "move to folder" control on the dashboard */
.card-tile-wrap { display: flex; flex-direction: column; gap: 6px; }
.card-move-form { display: flex; gap: 6px; }
.card-move-form select {
  flex: 1;
  min-width: 0;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12px;
  background: var(--surface);
}

/* Collapsible inline forms (new folder, manage folder) */
.inline-form { position: relative; }
.inline-form > summary { list-style: none; cursor: pointer; display: inline-flex; }
.inline-form > summary::-webkit-details-marker { display: none; }
.inline-form-body {
  margin-top: 10px;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
}
.inline-form-body input[type="text"],
.inline-form-body input[type="email"],
.inline-form-body select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.stacked-form { display: flex; flex-direction: column; gap: 6px; }
.stacked-form label { font-size: 12px; color: var(--muted); }
.share-subsection {
  width: 100%;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* ---- Sharing ---- */
.share-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.share-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.share-form input[type="email"] {
  flex: 1;
  min-width: 200px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}
.share-form select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
}
.share-list { list-style: none; padding: 0; margin: 12px 0 0; }
.share-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
}
.share-list form { margin: 0; }
.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.link-btn:hover { text-decoration: underline; }
.shared-banner {
  display: inline-block;
  background: #eef1f6;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}

/* Read-only card view (view-only share) */
.readonly-card {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin: 0;
}
.readonly-card dt { color: var(--muted); font-size: 13px; }
.readonly-card dd { margin: 0; }

/* ---- My Card editor ---- */
.avatar-logo-row { display: flex; flex-wrap: wrap; gap: 20px; margin-bottom: 16px; }
.image-widget { flex: 1; min-width: 220px; }
.image-preview { margin-bottom: 8px; }
.image-preview img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  margin-bottom: 6px;
}
.file-drop-sm { padding: 14px; font-size: 13px; }
.handle-section { margin: 16px 0; }
.handle-input { display: flex; align-items: center; gap: 0; margin-top: 4px; }
.handle-prefix {
  background: #f0f1f4;
  border: 1px solid var(--border);
  border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 14px;
}
.handle-input input {
  border-radius: 0 var(--radius) var(--radius) 0 !important;
  flex: 1;
}
.publish-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 16px 0;
  font-size: 14px;
  font-weight: 600;
}
.share-panel-row { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; }
.share-qr img { display: block; border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; background: #fff; }
.share-links p { margin: 6px 0; }
.copy-field { display: block; font-size: 12px; color: var(--muted); margin-top: 8px; }
.copy-field input {
  width: 100%;
  margin-top: 4px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
}

/* ===================================================================
   Public card page (unauthenticated /c/:slug)
   =================================================================== */
.public-card-body {
  background: var(--bg);
  min-height: 100vh;
  display: flex;
  justify-content: center;
  padding: 40px 16px;
}
.public-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px 28px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.06);
}
.public-card-header { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.public-card-avatar {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
}
.public-card-avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 44px;
  background: #f0f1f4;
}
.public-card-name { font-size: 22px; margin: 8px 0 0; }
.public-card-pronouns { font-size: 14px; font-weight: 400; color: var(--muted); }
.public-card-role { color: var(--muted); margin: 2px 0 0; }
.public-card-logo { max-height: 40px; margin-top: 10px; }
.public-card-bio { margin: 16px 0; color: var(--text); }
.public-card-save { display: block; margin: 20px 0; }
.public-card-contacts { list-style: none; padding: 0; margin: 0; text-align: left; }
.public-card-contacts li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}
.public-card-contacts .pc-icon { width: 20px; text-align: center; }
.public-card-footer { margin-top: 20px; text-align: center; }

/* ---- Manual crop tool (scan preview) ---- */
.crop-wrap {
  position: relative;
  display: inline-block;
  max-width: 100%;
  line-height: 0;
  overflow: hidden;
  border-radius: var(--radius);
}
.crop-wrap #preview-image {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.crop-box {
  position: absolute;
  border: 2px solid var(--primary);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
  cursor: move;
  touch-action: none;
  box-sizing: border-box;
}
.crop-handle {
  position: absolute;
  width: 18px;
  height: 18px;
  background: #fff;
  border: 2px solid var(--primary);
  border-radius: 50%;
  touch-action: none;
}
.crop-handle[data-h="nw"] { left: -10px; top: -10px; cursor: nwse-resize; }
.crop-handle[data-h="ne"] { right: -10px; top: -10px; cursor: nesw-resize; }
.crop-handle[data-h="sw"] { left: -10px; bottom: -10px; cursor: nesw-resize; }
.crop-handle[data-h="se"] { right: -10px; bottom: -10px; cursor: nwse-resize; }
.crop-hint { margin: 8px 0 0; }
.crop-hint .link-btn { font-weight: 600; }
.recrop-controls { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.recrop-form { display: inline-flex; gap: 8px; }
.recrop-form.hidden { display: none; }
