/* Siasat Donation Portal — styles */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #0d9488;
  --primary-dark: #0f766e;
  --accent: #1e40af;
  --border: #e2e8f0;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --fab-size: 56px;
  --brand-gold: #b8974d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: hidden;
  min-height: 100%;
  min-height: -webkit-fill-available;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: -webkit-fill-available;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
  overflow-x: hidden;
  -webkit-tap-highlight-color: rgba(13, 148, 136, 0.15);
  padding-bottom: calc(
    var(--fab-size) + max(1.25rem, var(--safe-bottom)) + 0.75rem
  );
}

button,
[role="button"],
.fab,
.recipient-card {
  touch-action: manipulation;
}

img,
video {
  max-width: 100%;
  height: auto;
}

.app-header {
  background: linear-gradient(135deg, #0f766e 0%, #1e3a5f 100%);
  color: #fff;
  padding-top: calc(1rem + var(--safe-top));
  padding-left: max(1rem, var(--safe-left));
  padding-right: max(1rem, var(--safe-right));
  padding-bottom: 1rem;
}

.header-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 960px;
  margin: 0 auto;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-logo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.4);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}

.header-brand-text {
  min-width: 0;
}

.header-brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.header-brand-text p {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  opacity: 0.9;
}

.header-auth {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.4rem;
  flex-shrink: 0;
}

.session-label {
  font-size: 0.75rem;
  opacity: 0.92;
  max-width: 200px;
  text-align: right;
  line-height: 1.3;
}

.btn-header {
  padding: 0.45rem 0.85rem;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}

.btn-header:hover {
  background: rgba(255, 255, 255, 0.22);
}

.login-intro {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0 0 1rem;
  line-height: 1.45;
}

.login-intro code,
.hint code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
}

main {
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
  padding: 1rem max(1rem, var(--safe-left)) 0 max(1rem, var(--safe-right));
}

/* Summary card */
.summary-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 1.5rem;
}

.summary-allocated {
  text-align: center;
  padding: 1.25rem 1rem;
}

.summary-allocated .label {
  font-size: 0.8rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.35rem;
}

.summary-allocated .amount {
  font-size: clamp(1.35rem, 5.5vw, 1.75rem);
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.03em;
}

.summary-allocated .sub {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

.summary-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}

.summary-split > div {
  padding: 1rem;
  text-align: center;
}

.summary-split > div:first-child {
  border-right: 1px solid var(--border);
}

.summary-split .label {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.summary-split .amount {
  font-size: clamp(1rem, 4vw, 1.15rem);
  font-weight: 700;
  color: var(--text);
}

@media (max-width: 380px) {
  .summary-split {
    grid-template-columns: 1fr;
  }
  .summary-split > div:first-child {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin: 0 0 0.75rem;
  color: var(--text);
}

/* Gallery — fluid columns; min 2 across on phones */
.recipient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 148px), 1fr));
  gap: clamp(0.5rem, 2vw, 0.75rem);
  width: 100%;
}

@media (max-width: 360px) {
  .recipient-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }
}

.recipient-card {
  background: var(--surface);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.06);
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
  padding: 0;
  font: inherit;
  text-align: left;
  width: 100%;
}

.recipient-card:hover,
.recipient-card:focus-visible {
  border-color: var(--primary);
  outline: none;
  transform: translateY(-2px);
}

.recipient-card .thumb {
  aspect-ratio: 1;
  position: relative;
  overflow: hidden;
  background: #e2e8f0;
}

.recipient-card .thumb--photo {
  padding: 0;
}

.recipient-card .thumb--photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.recipient-card .thumb--fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.recipient-card .meta {
  padding: 0.5rem 0.6rem 0.65rem;
  font-size: 0.8rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* FAB — min 48×48dp touch target + safe areas */
.fab {
  position: fixed;
  right: max(1rem, var(--safe-right));
  bottom: max(1rem, var(--safe-bottom));
  min-height: max(var(--fab-size), 48px);
  min-width: max(var(--fab-size), 48px);
  padding: 0 max(1rem, 0.75rem);
  border-radius: 999px;
  border: none;
  background: var(--primary);
  color: #fff;
  font-size: clamp(0.85rem, 2.8vw, 0.95rem);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(13, 148, 136, 0.45);
  z-index: 50;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  max-width: calc(100vw - 2rem - var(--safe-left) - var(--safe-right));
}

.fab:hover {
  background: var(--primary-dark);
}

.fab:focus-visible {
  outline: 3px solid rgba(13, 148, 136, 0.5);
  outline-offset: 2px;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  background: rgba(15, 23, 42, 0.55);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s, visibility 0.2s;
  overscroll-behavior: contain;
}

.modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.modal-sheet {
  background: var(--surface);
  width: 100%;
  max-width: 560px;
  max-height: min(92vh, 900px);
  max-height: min(92dvh, 900px);
  border-radius: 16px 16px 0 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}

.modal-overlay.is-open .modal-sheet {
  transform: translateY(0);
}

@media (min-width: 600px) {
  .modal-overlay {
    align-items: center;
    padding: 1rem;
    padding-top: max(1rem, var(--safe-top));
    padding-bottom: max(1rem, var(--safe-bottom));
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
  }
  .modal-sheet {
    border-radius: var(--radius);
    max-height: min(90vh, 900px);
    max-height: min(90dvh, 900px);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.1rem;
}

.modal-body {
  padding: 1rem;
  padding-bottom: max(1rem, var(--safe-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.btn-icon {
  background: var(--bg);
  border: none;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.25rem;
  line-height: 1;
  color: var(--text);
  flex-shrink: 0;
}

.btn-icon:hover {
  background: var(--border);
}

/* Detail */
.detail-photo {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 800;
  color: #fff;
}

.detail-photo--photo {
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
}

.detail-photo--photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.detail-rows dt {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-top: 0.75rem;
}

.detail-rows dd {
  margin: 0.15rem 0 0;
  font-size: 0.95rem;
}

.detail-rows a {
  color: var(--accent);
}

.reason-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  background: var(--bg);
  border-radius: 8px;
  font-size: 0.9rem;
}

/* Form */
.form-group {
  margin-bottom: 0.85rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  font-size: 0.95rem;
}

.form-group textarea {
  min-height: 72px;
  resize: vertical;
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

@media (max-width: 480px) {
  .form-row-2 {
    grid-template-columns: 1fr;
  }
}

.hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin-top: 0.2rem;
}

.image-previews {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.image-preview {
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-preview button.remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}

.btn {
  padding: 0.65rem 1.1rem;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: none;
  font-size: 0.95rem;
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-danger {
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
}

.btn-danger:hover {
  background: #fee2e2;
}

.status-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* Confirm dialog (smaller) */
.modal-overlay.confirm-z {
  z-index: 200;
  align-items: center;
}

.modal-overlay.confirm-z .modal-sheet {
  max-width: 400px;
  border-radius: var(--radius);
  transform: none;
  margin: 1rem;
}

.modal-overlay.confirm-z.is-open .modal-sheet {
  transform: none;
}

.confirm-body {
  padding: 0 1rem 1rem;
  font-size: 0.95rem;
}

.confirm-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: 0 1rem max(1rem, var(--safe-bottom));
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.hidden {
  display: none !important;
}

.status-edit-form .form-group {
  margin-bottom: 0.85rem;
}

/* ——— Mobile WebView / Safari / Chrome: fit & usability ——— */

/* iOS: avoid auto zoom on focus when font-size < 16px */
@media (max-width: 599px) {
  .form-group input,
  .form-group textarea,
  .form-group select,
  #login-mobile,
  #login-pin,
  .status-edit-form input,
  .status-edit-form textarea {
    font-size: 16px;
  }
}

@media (max-width: 400px) {
  .brand-logo {
    width: 48px;
    height: 48px;
  }

  .header-brand-text h1 {
    font-size: 1.2rem;
  }

  .header-brand-text p {
    font-size: 0.8125rem;
  }

  .header-auth {
    width: 100%;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
  }

  .session-label {
    max-width: none;
    width: 100%;
    text-align: right;
    margin-bottom: 0.15rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
