/* Al Fajr SG - Cert lookup page styles
   Brand colours kept in sync with Settings/email_template.html:
     navy   #0C1E40 (primary)
     bg     #f5f5f5 (page)
     card   #ffffff
     text   #333
     muted  #888
*/

:root {
  --navy: #0C1E40;
  --navy-hover: #0a1832;
  --bg: #f5f5f5;
  --card: #ffffff;
  --text: #333333;
  --muted: #888888;
  --border: #e6e6e6;
  --error: #b3261e;
  --success: #1a7f37;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, Helvetica, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100%;
}

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 24px 16px 48px 16px;
}

/* ---------- Header ---------- */

.brand {
  background-color: var(--navy);
  border-radius: var(--radius);
  padding: 32px 24px;
  text-align: center;
  color: #ffffff;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.brand-logo {
  display: block;
  margin: 0 auto 16px auto;
  max-width: 110px;
  width: 100%;
  height: auto;
}

.brand-title {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand-sub {
  margin: 6px 0 0 0;
  font-size: 13px;
  opacity: 0.8;
}

/* ---------- Card ---------- */

.card {
  background-color: var(--card);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: var(--shadow-md);
}

.lead {
  margin: 0 0 24px 0;
  color: var(--text);
}

/* ---------- Form ---------- */

.lookup-form { margin: 0; }

.lookup-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.lookup-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--navy);
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.help-link {
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 13px;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s ease;
}

.help-link:hover,
.help-link:focus-visible {
  opacity: 1;
  outline: none;
}

.help-link:focus-visible {
  text-decoration-thickness: 2px;
}

.lookup-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.lookup-input {
  flex: 1 1 180px;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  background: #fff;
  color: var(--text);
}

.lookup-input:focus {
  border-color: var(--navy);
  box-shadow: 0 0 0 3px rgba(12, 30, 64, 0.12);
}

.lookup-button {
  flex: 0 0 auto;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  color: #ffffff;
  background-color: var(--navy);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
}

.lookup-button:hover { background-color: var(--navy-hover); }
.lookup-button:active { transform: translateY(1px); }
.lookup-button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.lookup-error {
  margin: 12px 0 0 0;
  min-height: 1.4em;
  color: var(--error);
  font-size: 14px;
}

/* ---------- Results ---------- */

.results {
  margin-top: 24px;
  border-top: 1px solid var(--border);
  padding-top: 20px;
}

.results-heading {
  margin: 0 0 14px 0;
  font-size: 14px;
  color: var(--muted);
}

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.results-toolbar .results-heading {
  margin: 0;
  flex: 1 1 auto;
}

.download-all-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  min-width: 78px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--navy);
  background-color: var(--navy);
  color: #ffffff;
  cursor: pointer;
  transition: background-color 0.15s ease, opacity 0.15s ease, transform 0.05s ease;
}

.download-all-btn:hover { background-color: var(--navy-hover); border-color: var(--navy-hover); }
.download-all-btn:active { transform: translateY(1px); }
.download-all-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.cert-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

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

.cert-name {
  font-weight: 600;
  color: var(--navy);
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cert-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.cert-link {
  display: inline-block;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border-radius: 6px;
  border: 1px solid var(--navy);
  color: var(--navy);
  background: #ffffff;
  transition: background-color 0.15s ease, color 0.15s ease;
  min-width: 78px;
}

.cert-link:hover {
  background-color: var(--navy);
  color: #ffffff;
}

.cert-link.primary {
  background-color: var(--navy);
  color: #ffffff;
}

.cert-link.primary:hover {
  background-color: var(--navy-hover);
  border-color: var(--navy-hover);
}

/* ---------- Full report card (top of every result) ---------- */

.report-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  margin-bottom: 18px;
  background: linear-gradient(135deg, #0C1E40 0%, #14315f 100%);
  border-radius: 8px;
  color: #ffffff;
}

.report-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.report-title {
  font-weight: 600;
  font-size: 15px;
  color: #ffffff;
}

.report-sub {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.82);
}

.report-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.report-link {
  display: inline-block;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  text-decoration: none;
  border-radius: 6px;
  min-width: 78px;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.report-link.ghost {
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: #ffffff;
  background: transparent;
}

.report-link.ghost:hover { background: rgba(255, 255, 255, 0.14); }

.report-link.solid {
  border: 1px solid #ffffff;
  background: #ffffff;
  color: var(--navy);
}

.report-link.solid:hover { background: #eef0f3; }

/* ---------- Footer ---------- */

.page-footer {
  margin-top: 24px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.page-footer a { color: var(--navy); }
.page-footer .muted { font-size: 12px; margin-top: 8px; }

/* ---------- Modal (instructions popup) ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(12, 30, 64, 0.55);
  z-index: 10000; /* sits above the WhatsApp FAB (z-index: 9999) */
  padding: 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: modalFade 0.15s ease-out;
}

.modal-overlay.is-open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}

@keyframes modalFade {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.modal {
  position: relative;
  background-color: var(--card);
  border-radius: var(--radius);
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
  padding: 28px 28px 24px 28px;
  width: 100%;
  max-width: 480px;
  margin: 5vh auto;
  animation: modalRise 0.18s ease-out;
}

@keyframes modalRise {
  from { transform: translateY(8px); opacity: 0; }
  to   { transform: translateY(0);   opacity: 1; }
}

.modal-close {
  position: absolute;
  top: 8px;
  right: 10px;
  width: 36px;
  height: 36px;
  background: transparent;
  border: 0;
  border-radius: 50%;
  font-size: 26px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.modal-close:hover,
.modal-close:focus-visible {
  background-color: #f0f1f3;
  color: var(--navy);
  outline: none;
}

.modal-title {
  margin: 0 32px 8px 0;
  font-size: 18px;
  font-weight: 600;
  color: var(--navy);
}

.modal-intro {
  margin: 0 0 16px 0;
  color: var(--text);
  font-size: 14px;
}

.modal-steps {
  margin: 0 0 16px 0;
  padding-left: 22px;
  color: var(--text);
  font-size: 14px;
}

.modal-steps li {
  margin-bottom: 10px;
  line-height: 1.55;
}

.modal-steps li:last-child { margin-bottom: 0; }

.modal-steps code {
  background-color: #f0f2f5;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--navy);
}

.modal-help {
  margin: 16px 0 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--muted);
}

.modal-help a { color: var(--navy); }

/* Lock background scroll while modal is open. */
body.modal-open { overflow: hidden; }

/* ---------- Floating WhatsApp button ---------- */

.wa-fab {
  position: fixed;
  /* Sits 16px to the right of the centered 640px card on wide screens.
     Falls back to 20px from the viewport edge on narrow screens. */
  right: max(20px, calc(50vw - 392px));
  bottom: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #25D366;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  cursor: grab;
  z-index: 9999;
  text-decoration: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.wa-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
  background: #1ebe57;
}

.wa-fab:active,
.wa-fab.is-dragging {
  cursor: grabbing;
  transform: scale(1.02);
  transition: none;
}

.wa-fab-icon {
  width: 30px;
  height: 30px;
  display: block;
  pointer-events: none;
}

/* ---------- Small screens (tablets / large phones) ---------- */

@media (max-width: 600px) {
  .page { padding: 16px 12px 32px 12px; }

  .brand { padding: 24px 16px; margin-bottom: 16px; }
  .brand-logo { max-width: 90px; margin-bottom: 12px; }
  .brand-title { font-size: 18px; }
  .brand-sub { font-size: 12px; }

  .card { padding: 20px 16px; }
  .lead { font-size: 14px; margin-bottom: 20px; }

  /* Stack label and help link cleanly on narrow screens. */
  .lookup-label-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .lookup-row { flex-direction: column; gap: 10px; }
  .lookup-input { width: 100%; flex: 0 0 auto; }
  .lookup-button { width: 100%; padding: 14px 20px; }

  /* Download All becomes full-width under the count text. */
  .results-toolbar { flex-direction: column; align-items: stretch; }
  .download-all-btn { width: 100%; padding: 12px 14px; }

  /* Modal hugs the viewport on phones. */
  .modal {
    margin: 0 auto;
    padding: 24px 20px 20px 20px;
  }
  .modal-overlay { padding: 12px; }
  .modal-title { font-size: 17px; }
  .modal-intro, .modal-steps { font-size: 13.5px; }

  .cert-item {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .cert-name {
    white-space: normal;
    word-break: break-word;
  }
  .cert-actions {
    width: 100%;
    gap: 8px;
  }
  .cert-link {
    flex: 1 1 0;
    padding: 12px 14px;
    min-width: 0;
  }

  .page-footer { font-size: 12px; }

  .wa-fab {
    width: 52px;
    height: 52px;
    right: 16px;
    bottom: 16px;
  }
  .wa-fab-icon { width: 28px; height: 28px; }
}

/* ---------- Very small phones ---------- */

@media (max-width: 360px) {
  .page { padding: 12px 10px 24px 10px; }
  .brand { padding: 20px 14px; }
  .brand-title { font-size: 17px; }
  .card { padding: 18px 14px; }
}
