/* e-Daftar Sinode 41 PCS */

:root {
  --navy: #0b2a4a;
  --navy-deep: #061a30;
  --gold: #c9a227;
  --gold-light: #e8c547;
  --gold-soft: #f5e6b8;
  --cream: #faf8f3;
  --white: #ffffff;
  --text: #1a2332;
  --muted: #5a6a7a;
  --border: #d8dfe8;
  --success: #1a7a4c;
  --success-bg: #e8f6ef;
  --error: #b42318;
  --error-bg: #fef3f2;
  --shadow: 0 12px 40px rgba(11, 42, 74, 0.12);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font);
  background: var(--cream);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

/* Header */
.site-header {
  background: linear-gradient(135deg, var(--navy-deep) 0%, var(--navy) 55%, #123a63 100%);
  color: var(--white);
  padding: 1.25rem 1.5rem 1.5rem;
  position: relative;
  overflow: hidden;
}

.site-header::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 4px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light), var(--gold));
}

.header-inner {
  max-width: 920px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-badge {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--gold-light), var(--gold));
  display: grid;
  place-items: center;
  flex-shrink: 0;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  border: 3px solid rgba(255, 255, 255, 0.25);
}

.logo-badge span {
  font-weight: 800;
  font-size: 0.85rem;
  color: var(--navy-deep);
  letter-spacing: 0.02em;
  text-align: center;
  line-height: 1.1;
}

.logo-img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 12px;
  padding: 4px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
}

input.readonly,
input[readonly] {
  background: #f0f3f7;
  color: var(--muted);
}

textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  resize: vertical;
  min-height: 64px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(11, 42, 74, 0.12);
}

/* ========== Simple profile dashboard ========== */
.profile-simple {
  max-width: 440px;
  margin: 0 auto;
}

.profile-body {
  padding: 1.5rem 1.35rem 1.4rem;
}

.profile-simple-head {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  align-items: center;
  column-gap: 1rem;
  row-gap: 0.35rem;
  margin: 0;
  padding-bottom: 1.15rem;
  border-bottom: 1px solid var(--border);
}

.profile-simple-photo {
  width: 76px;
  height: 90px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #eef2f6;
  display: block;
}

.profile-simple-title {
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.2rem;
}

.profile-serial {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: #a8871a;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  line-height: 1.2;
}

.profile-name {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.3;
  letter-spacing: -0.01em;
  word-break: break-word;
}

.profile-sub {
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #f4f7fa;
  color: var(--navy);
  display: grid;
  place-items: center;
  cursor: pointer;
  flex-shrink: 0;
  align-self: start;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.icon-btn:hover {
  background: var(--gold-soft);
  border-color: var(--gold);
}

.icon-btn:active {
  transform: scale(0.96);
}

.profile-section {
  margin-top: 1.15rem;
}

.profile-section-title {
  margin: 0 0 0.55rem;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  line-height: 1.2;
}

.profile-details {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #fbfcfe;
}

.profile-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  align-items: baseline;
  gap: 0.75rem;
  margin: 0;
  padding: 0.72rem 0.95rem;
  border-bottom: 1px solid #e8eef4;
  font-size: 0.9rem;
  line-height: 1.4;
}

.profile-row:last-child {
  border-bottom: none;
}

.profile-row dt {
  margin: 0;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}

.profile-row dd {
  margin: 0;
  color: var(--navy);
  font-weight: 600;
  font-size: 0.92rem;
  text-align: right;
  word-break: break-word;
}

.profile-actions {
  margin-top: 1.15rem;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.6rem;
}

/* Dashboard QR — fully centered */
.profile-qr-block {
  margin-top: 1.15rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--border);
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.profile-qr-block .profile-section-title {
  margin: 0 0 0.2rem;
  width: 100%;
  text-align: center;
}

.profile-qr-label {
  margin: 0 0 0.75rem;
  width: 100%;
  text-align: center;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.35;
}

.profile-qr-box {
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto;
  padding: 0.5rem;
  width: fit-content;
  max-width: 100%;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  line-height: 0;
}

.profile-qr-box canvas,
.profile-qr-img {
  display: block;
  width: 148px;
  height: 148px;
  margin: 0 auto;
}

/* hidden must win over display:block (common QR dual-element bug) */
.profile-qr-box canvas[hidden],
.profile-qr-box img[hidden],
.nametag-qr-wrap canvas[hidden],
.nametag-qr-wrap img[hidden] {
  display: none !important;
}

.profile-qr-sn {
  margin: 0.55rem auto 0;
  width: 100%;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  color: var(--navy);
  letter-spacing: 0.1em;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.photo-preview-sm {
  width: 72px;
  height: 86px;
}

.photo-upload-sm {
  grid-template-columns: 72px 1fr;
}

/* Name tag — compact vertical stack */
.nametag {
  background: linear-gradient(180deg, #fff 0%, #f7f9fc 100%);
  border: 2px solid var(--navy);
  border-radius: 14px;
  padding: 0.9rem 0.9rem 0.85rem;
  text-align: center;
  box-shadow: 0 8px 24px rgba(11, 42, 74, 0.1);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.nametag-lg {
  width: 100%;
  max-width: 280px;
  padding: 1rem 0.95rem 0.9rem;
  gap: 0; /* control spacing per child */
}

.nametag-top {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-align: left;
  width: 100%;
  margin: 0 0 0.55rem;
  padding: 0 0 0.55rem;
  border-bottom: 2px solid var(--gold);
}

.nametag-logo {
  width: 40px;
  height: 40px;
  object-fit: contain;
  flex-shrink: 0;
}

.nametag-event {
  font-weight: 800;
  color: var(--navy);
  font-size: 0.84rem;
  letter-spacing: 0.08em;
  line-height: 1.2;
}

.nametag-serial {
  font-size: 0.78rem;
  color: #a8871a;
  font-weight: 700;
  margin-top: 0.15rem;
  letter-spacing: 0.06em;
  font-variant-numeric: tabular-nums;
}

.nametag-photo {
  width: 88px;
  height: 102px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 0 auto 0.4rem;
  display: block;
  background: #eee;
}

.nametag-lg .nametag-photo {
  width: 96px;
  height: 112px;
  margin-bottom: 0.4rem;
}

.nametag-name {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--navy);
  line-height: 1.25;
  letter-spacing: -0.01em;
  margin: 0;
}

.nametag-meta {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0.25rem 0 0;
  line-height: 1.4;
  font-weight: 500;
  max-width: 100%;
}

.nametag-qr-wrap {
  margin: 0.45rem 0 0; /* close to meta above */
  padding: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}

.nametag-qr-wrap canvas,
.nametag-qr-wrap img {
  display: block;
  border-radius: 6px;
  width: 120px;
  height: 120px;
  margin: 0 auto;
}

/* Desktop / tablet: normal centered modal */
.modal.tag-modal {
  max-width: 360px;
}

.tag-modal .modal-body,
#tagModal .modal-body {
  display: flex;
  justify-content: center;
  padding: 1rem 1rem 1.15rem;
}

/* Explicit: tablet+ keep normal Show Tag (not fullscreen) */
@media (min-width: 721px) {
  #tagModal.modal-overlay {
    padding: 1rem;
    align-items: center;
    justify-content: center;
  }

  #tagModal .modal.tag-modal {
    width: 100%;
    max-width: 360px;
    height: auto;
    max-height: 90vh;
    min-height: 0;
    border-radius: var(--radius);
  }

  #tagModal .modal-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 1rem 1.25rem;
  }

  #tagModal .modal-header h3 {
    color: var(--navy);
  }

  #tagModal .modal-close {
    color: var(--muted);
  }

  #tagModal .modal-body {
    flex: none;
    background: transparent;
    padding: 1rem 1rem 1.15rem;
  }
}

@media print {
  body * {
    visibility: hidden;
  }
  #tagModal,
  #tagModal * {
    visibility: visible;
  }
  #tagModal {
    position: fixed;
    inset: 0;
    background: white;
    display: grid !important;
  }
  .modal-header,
  .modal-close {
    display: none !important;
  }
}

.header-text h1 {
  font-size: clamp(1.25rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-text p {
  opacity: 0.85;
  font-size: 0.95rem;
  margin-top: 0.15rem;
}

.nav-links {
  margin-left: auto;
  display: flex;
  gap: 0.5rem;
}

.nav-links a {
  color: var(--white);
  text-decoration: none;
  font-size: 0.9rem;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  transition: background 0.2s, border-color 0.2s;
}

.nav-links a:hover,
.nav-links a.active {
  background: rgba(201, 162, 39, 0.25);
  border-color: var(--gold);
}

/* Main */
main {
  max-width: 920px;
  margin: 0 auto;
  padding: 2rem 1.25rem 3rem;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid rgba(11, 42, 74, 0.06);
  overflow: hidden;
}

.card-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #fff 0%, #f9fafb 100%);
}

.card-header h2 {
  font-size: 1.2rem;
  color: var(--navy);
}

.card-header p {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.25rem;
}

.card-body {
  padding: 1.5rem;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.15rem 1.25rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.form-group.full {
  grid-column: 1 / -1;
}

label {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--navy);
}

label .req {
  color: var(--error);
  margin-left: 2px;
}

input[type="text"],
input[type="search"],
input[type="tel"],
input[type="password"],
select,
textarea {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1.5px solid var(--border);
  border-radius: 10px;
  font: inherit;
  font-size: 0.95rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  max-width: 100%;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(11, 42, 74, 0.12);
}

input::placeholder {
  color: #9aa8b5;
}

.hint {
  font-size: 0.78rem;
  color: var(--muted);
}

/* Photo upload */
.photo-upload {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1.25rem;
  align-items: start;
}

.photo-preview {
  width: 140px;
  height: 160px;
  border-radius: 12px;
  border: 2px dashed var(--border);
  background: #f4f7fa;
  display: grid;
  place-items: center;
  overflow: hidden;
  position: relative;
}

.photo-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.photo-preview .placeholder {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.5rem;
}

.photo-preview .placeholder svg {
  display: block;
  margin: 0 auto 0.4rem;
  opacity: 0.5;
}

.file-input-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.65rem 1rem;
  background: var(--navy);
  color: white;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  width: fit-content;
  transition: background 0.15s;
}

.file-btn:hover {
  background: var(--navy-deep);
}

input[type="file"] {
  display: none;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.8rem 1.5rem;
  border: none;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(135deg, var(--gold) 0%, #b8921f 100%);
  color: var(--navy-deep);
  box-shadow: 0 4px 14px rgba(201, 162, 39, 0.35);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, var(--gold-light) 0%, var(--gold) 100%);
}

.btn-secondary {
  background: #eef2f6;
  color: var(--navy);
}

.btn-secondary:hover:not(:disabled) {
  background: #e2e8ef;
}

.btn-danger {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #fecdca;
  padding: 0.4rem 0.75rem;
  font-size: 0.82rem;
}

.btn-danger:hover:not(:disabled) {
  background: #fee4e2;
}

.form-actions {
  margin-top: 1.5rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Alerts */
.alert {
  padding: 0.9rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
  display: none;
}

.alert.show {
  display: block;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success);
  border: 1px solid #abefc6;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid #fecdca;
}

/* Success screen */
.success-panel {
  display: none;
  text-align: center;
  padding: 2rem 1rem;
}

.success-panel.show {
  display: block;
}

.success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--success-bg);
  color: var(--success);
  display: grid;
  place-items: center;
  margin: 0 auto 1rem;
  font-size: 2rem;
}

.success-panel h3 {
  color: var(--navy);
  margin-bottom: 0.4rem;
}

.success-panel p {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

.success-details {
  text-align: left;
  background: #f4f7fa;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin: 0 auto 1.5rem;
  max-width: 400px;
  font-size: 0.9rem;
}

.success-details dt {
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.5rem;
}

.success-details dd {
  font-weight: 600;
  color: var(--navy);
}

/* Admin */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.toolbar .search-box {
  flex: 1;
  min-width: 200px;
}

.stat-pill {
  background: var(--navy);
  color: white;
  padding: 0.45rem 0.9rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  white-space: nowrap;
}

.stat-pill span {
  color: var(--gold-light);
}

.table-wrap {
  overflow-x: auto;
  border-radius: 12px;
  border: 1px solid var(--border);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

thead {
  background: var(--navy);
  color: white;
}

th {
  text-align: left;
  padding: 0.75rem 0.9rem;
  font-weight: 600;
  white-space: nowrap;
}

td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody tr:last-child td {
  border-bottom: none;
}

.avatar {
  width: 44px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: #eee;
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
}

.empty-state strong {
  display: block;
  color: var(--navy);
  margin-bottom: 0.35rem;
  font-size: 1.05rem;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(6, 26, 48, 0.55);
  display: none;
  place-items: center;
  z-index: 100;
  padding: 1rem;
}

.modal-overlay.show {
  display: grid;
}

.modal {
  background: white;
  border-radius: var(--radius);
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  color: var(--navy);
  font-size: 1.05rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--muted);
  line-height: 1;
  padding: 0.2rem;
}

.modal-body {
  padding: 1.25rem;
}

.detail-photo {
  width: 120px;
  height: 140px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  display: block;
  margin: 0 auto 1rem;
  background: #eef2f6;
}

/* Admin Lihat: photo + QR side by side */
.admin-detail-top {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 1.25rem;
  flex-wrap: wrap;
  margin-bottom: 1.15rem;
}

.admin-detail .detail-photo {
  margin: 0;
  flex-shrink: 0;
}

.admin-detail-qr {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.35rem;
  min-width: 140px;
}

.admin-qr-img {
  display: block;
  width: 140px;
  height: 140px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 0.35rem;
  box-sizing: border-box;
}

.admin-qr-missing {
  width: 140px;
  height: 140px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
  color: var(--muted);
  font-size: 0.82rem;
  background: #f4f7fa;
}

.admin-qr-sn {
  font-weight: 800;
  font-size: 0.95rem;
  color: var(--navy);
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.admin-qr-caption {
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 500;
}

.admin-serial-value {
  letter-spacing: 0.04em;
  color: #a8871a !important;
}

.detail-grid {
  display: grid;
  gap: 0.65rem;
}

.detail-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 0.5rem;
  font-size: 0.9rem;
}

.detail-row .label {
  color: var(--muted);
  font-weight: 500;
}

.detail-row .value {
  font-weight: 600;
  color: var(--navy);
  word-break: break-word;
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 1.5rem;
  color: var(--muted);
  font-size: 0.82rem;
  border-top: 1px solid var(--border);
  background: white;
}

/* ========== Responsive / Mobile ========== */
@media (max-width: 720px) {
  .site-header {
    padding: 0.85rem 0.9rem 1rem;
  }

  .header-inner {
    flex-wrap: wrap;
    gap: 0.65rem 0.75rem;
    align-items: center;
  }

  .logo-img {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    padding: 3px;
  }

  .header-text {
    flex: 1;
    min-width: 0;
  }

  .header-text h1 {
    font-size: 1.05rem;
    line-height: 1.25;
  }

  .header-text p {
    font-size: 0.78rem;
    margin-top: 0.1rem;
  }

  .nav-links {
    margin-left: 0;
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    justify-content: flex-start;
  }

  .nav-links a {
    font-size: 0.8rem;
    padding: 0.4rem 0.7rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
  }

  main {
    padding: 1rem 0.75rem 2rem;
    max-width: 100%;
  }

  .card {
    border-radius: 14px;
  }

  .card-header {
    padding: 1rem 1rem 0.9rem;
  }

  .card-header h2 {
    font-size: 1.05rem;
  }

  .card-header p {
    font-size: 0.82rem;
  }

  .card-body {
    padding: 1rem;
  }

  /* Forms: single column, no iOS zoom */
  .form-grid {
    grid-template-columns: 1fr;
    gap: 0.9rem;
  }

  input[type="text"],
  input[type="search"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    font-size: 16px; /* prevents iOS zoom on focus */
    padding: 0.75rem 0.85rem;
  }

  .photo-upload {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 0.85rem;
  }

  .photo-preview {
    width: 88px;
    height: 100px;
  }

  .photo-preview-sm {
    width: 56px;
    height: 66px;
  }

  .photo-upload-sm {
    grid-template-columns: 56px 1fr;
    gap: 0.75rem;
  }

  .file-input-wrap {
    align-items: center;
    width: 100%;
  }

  .file-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }

  .form-actions {
    flex-direction: column;
    gap: 0.55rem;
    margin-top: 1.15rem;
  }

  .form-actions .btn,
  .form-actions a.btn {
    width: 100%;
    min-height: 46px;
  }

  /* Dashboard profile */
  .profile-simple {
    max-width: 100%;
  }

  .profile-body {
    padding: 1rem 0.85rem 1.05rem;
  }

  .profile-simple-head {
    grid-template-columns: 48px minmax(0, 1fr) 34px;
    column-gap: 0.65rem;
    align-items: start;
    padding-bottom: 0.85rem;
  }

  .profile-simple-photo {
    width: 48px;
    height: 56px;
    border-radius: 8px;
  }

  .profile-serial {
    font-size: 0.7rem;
    letter-spacing: 0.06em;
  }

  .profile-name {
    font-size: 1rem;
    line-height: 1.3;
  }

  .profile-sub {
    font-size: 0.8rem;
    -webkit-line-clamp: 3;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }

  .profile-section {
    margin-top: 1rem;
  }

  .profile-section-title {
    font-size: 0.68rem;
    margin-bottom: 0.45rem;
  }

  .profile-row {
    grid-template-columns: 1fr;
    gap: 0.12rem;
    padding: 0.65rem 0.8rem;
  }

  .profile-row dt {
    font-size: 0.75rem;
  }

  .profile-row dd {
    text-align: left;
    font-size: 0.92rem;
  }

  .profile-qr-block {
    margin-top: 1rem;
    padding-top: 0.95rem;
  }

  .profile-qr-label {
    font-size: 0.75rem;
    margin-bottom: 0.65rem;
    padding: 0 0.5rem;
  }

  .profile-qr-box {
    margin-left: auto;
    margin-right: auto;
  }

  .profile-qr-box canvas,
  .profile-qr-img {
    width: 112px;
    height: 112px;
  }

  .profile-qr-sn {
    font-size: 0.9rem;
    letter-spacing: 0.08em;
  }

  .profile-actions {
    flex-direction: column;
    width: 100%;
  }

  .profile-actions .btn {
    width: 100%;
  }

  /* Edit / general modals: sheet style */
  .modal-overlay:not(#tagModal) {
    padding: 0.65rem;
    align-items: flex-end;
  }

  @supports (padding: max(0px)) {
    .modal-overlay:not(#tagModal) {
      padding-bottom: max(0.65rem, env(safe-area-inset-bottom));
    }
  }

  .modal-overlay:not(#tagModal) .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 12px 12px;
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-header h3 {
    font-size: 1rem;
  }

  .modal-body {
    padding: 0.9rem 0.9rem 1.1rem;
  }

  /* Show Tag = FULL SCREEN on mobile only */
  #tagModal.modal-overlay {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    background: rgba(6, 26, 48, 0.72);
  }

  #tagModal .modal.tag-modal {
    max-width: none;
    width: 100%;
    height: 100%;
    max-height: 100%;
    min-height: 100%;
    border-radius: 0;
    display: flex;
    flex-direction: column;
    box-shadow: none;
  }

  #tagModal .modal-header {
    flex-shrink: 0;
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
    background: var(--navy);
    border-bottom: none;
  }

  #tagModal .modal-header h3 {
    color: #fff;
    font-size: 1rem;
  }

  #tagModal .modal-close {
    color: #fff;
    opacity: 0.9;
    font-size: 1.6rem;
  }

  #tagModal .modal-body {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    overflow: auto;
    background: linear-gradient(180deg, #f4f7fa 0%, #e8eef5 100%);
  }

  #tagModal .nametag-lg {
    max-width: min(320px, 92vw);
    width: 100%;
    margin: 0 auto;
    padding: 1.1rem 1rem 1rem;
  }

  #tagModal .nametag-photo,
  #tagModal .nametag-lg .nametag-photo {
    width: 100px;
    height: 118px;
    margin-bottom: 0.45rem;
  }

  #tagModal .nametag-name {
    font-size: 1.15rem;
  }

  #tagModal .nametag-meta {
    font-size: 0.8rem;
  }

  #tagModal .nametag-qr-wrap {
    margin-top: 0.5rem;
  }

  #tagModal .nametag-qr-wrap canvas,
  #tagModal .nametag-qr-wrap img {
    width: 128px;
    height: 128px;
  }

  .detail-photo {
    width: 72px;
    height: 86px;
  }

  .admin-detail-top {
    gap: 0.85rem;
  }

  .admin-detail .detail-photo {
    width: 96px;
    height: 112px;
  }

  .admin-qr-img,
  .admin-qr-missing {
    width: 120px;
    height: 120px;
  }

  .avatar {
    width: 36px;
    height: 42px;
  }

  .detail-row {
    grid-template-columns: 1fr;
    gap: 0.1rem;
  }

  /* Admin table: keep scroll, hide less critical cols */
  .table-wrap {
    margin: 0 -0.15rem;
    border-radius: 10px;
  }

  table {
    font-size: 0.8rem;
  }

  th, td {
    padding: 0.55rem 0.5rem;
  }

  th:nth-child(5),
  td:nth-child(5),
  th:nth-child(6),
  td:nth-child(6) {
    display: none;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .toolbar .search-box {
    min-width: 0;
    width: 100%;
  }

  .toolbar .btn {
    width: 100%;
  }

  .stat-pill {
    text-align: center;
  }

  .site-footer {
    padding: 1.1rem 0.75rem;
    font-size: 0.75rem;
  }
}

/* Older / very small phones */
@media (max-width: 400px) {
  .header-text h1 {
    font-size: 0.95rem;
  }

  .logo-img {
    width: 40px;
    height: 40px;
  }

  .profile-simple-head {
    grid-template-columns: 42px minmax(0, 1fr) 32px;
    column-gap: 0.55rem;
  }

  .profile-simple-photo {
    width: 42px;
    height: 50px;
    border-radius: 6px;
  }

  .profile-name {
    font-size: 0.95rem;
  }

  .profile-sub {
    font-size: 0.75rem;
  }

  .icon-btn {
    width: 32px;
    height: 32px;
  }

  .icon-btn svg {
    width: 15px;
    height: 15px;
  }

  .photo-preview {
    width: 72px;
    height: 84px;
  }

  .profile-qr-box canvas,
  .profile-qr-img {
    width: 100px;
    height: 100px;
  }

  .profile-qr-sn {
    font-size: 0.85rem;
  }

  /* Don't shrink Show Tag in fullscreen on tiny phones */
  #tagModal .nametag-photo,
  #tagModal .nametag-lg .nametag-photo {
    width: 96px;
    height: 112px;
  }

  #tagModal .nametag-qr-wrap canvas,
  #tagModal .nametag-qr-wrap img {
    width: 120px;
    height: 120px;
  }
}
