:root {
  --royal-blue: #0b1f4b;
  --royal-blue-light: #163a7a;
  --royal-blue-dark: #071428;
  --gold: #d4af37;
  --gold-light: #f4e4a6;
  --gold-dark: #a67c00;
  --white: #ffffff;
  --page-bg: #f4f6fa;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --row-alt: #f8fafc;
  --shadow: 0 4px 24px rgba(11, 31, 75, 0.1);
  --shadow-lg: 0 12px 40px rgba(11, 31, 75, 0.14);
  --radius: 18px;
  --radius-sm: 12px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Tajawal", "Segoe UI", Tahoma, sans-serif;
  background: var(--page-bg);
  color: var(--text);
  line-height: 1.65;
  overflow-x: hidden;
}

.skip-link {
  position: absolute;
  top: -100px;
  right: 1rem;
  background: var(--gold);
  color: var(--royal-blue-dark);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  z-index: 9999;
  font-weight: 700;
  text-decoration: none;
}

.skip-link:focus { top: 1rem; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ========== HERO ========== */
.hero {
  position: relative;
  background: linear-gradient(165deg, #071428 0%, var(--royal-blue) 55%, #1a3d6e 100%);
  color: var(--white);
  padding: calc(2rem + var(--safe-top)) 1.25rem 0;
  text-align: center;
  overflow: hidden;
}

.hero__pattern {
  position: absolute;
  inset: 0;
  opacity: 0.35;
  background-image: radial-gradient(circle, rgba(255,255,255,0.12) 1px, transparent 1px);
  background-size: 22px 22px;
  pointer-events: none;
}

.hero__inner {
  position: relative;
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: 2.5rem;
  z-index: 1;
}

.hero__logo-wrap {
  width: 100px;
  height: 100px;
  margin: 0 auto 1rem;
  background: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
  border: 3px solid var(--gold-light);
}

.hero__logo {
  width: 72px;
  height: 72px;
  object-fit: contain;
}

.hero__title {
  margin: 0 0 1.1rem;
  font-family: "Tajawal", sans-serif;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 800;
  line-height: 1.45;
}

.hero__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: linear-gradient(135deg, #c9a227, var(--gold), var(--gold-light));
  color: var(--royal-blue-dark);
  padding: 0.55rem 1.15rem;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.92rem;
  box-shadow: 0 4px 18px rgba(212, 175, 55, 0.45);
}

.hero__badge-count { font-size: 1.15rem; }

.hero__badge-icon { flex-shrink: 0; opacity: 0.85; }

.hero__wave {
  position: relative;
  width: 100%;
  line-height: 0;
  margin-top: -1px;
}

.hero__wave svg {
  display: block;
  width: 100%;
  height: 48px;
}

/* ========== PAGE ========== */
.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.5rem 1rem calc(2rem + var(--safe-bottom));
}

.section { margin-bottom: 1.25rem; }

/* ========== DOCUMENT CARD ========== */
.document-card {
  position: relative;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  border: 2px solid var(--gold);
  padding: 1.5rem 1.15rem;
  margin-top: -0.5rem;
}

.corner {
  position: absolute;
  width: 28px;
  height: 28px;
  border: 3px solid var(--gold);
  pointer-events: none;
}

.corner--tl { top: 10px; right: 10px; border-left: none; border-bottom: none; }
.corner--tr { top: 10px; left: 10px; border-right: none; border-bottom: none; }
.corner--bl { bottom: 10px; right: 10px; border-left: none; border-top: none; }
.corner--br { bottom: 10px; left: 10px; border-right: none; border-top: none; }

.document-card__grid {
  display: grid;
  gap: 1.25rem;
  align-items: center;
}

.document-card__content { text-align: center; }

.document-card__visual {
  display: flex;
  justify-content: center;
  align-items: center;
}

.document-card__logo {
  width: min(160px, 42vw);
  height: auto;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(11, 31, 75, 0.12));
}

.document-card__title {
  margin: 0 0 0.4rem;
  font-family: "Amiri", serif;
  font-size: clamp(1.75rem, 6vw, 2.1rem);
  color: var(--royal-blue);
  font-weight: 700;
}

.document-card__subtitle {
  margin: 0 0 0.75rem;
  color: var(--gold-dark);
  font-size: 0.95rem;
  font-weight: 700;
}

.document-card__separator {
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold-light), var(--gold), var(--gold-light), transparent);
  margin: 1rem auto;
  max-width: 280px;
}

.document-card__body {
  margin: 0;
  font-family: "Amiri", serif;
  font-size: clamp(1.05rem, 3.5vw, 1.25rem);
  line-height: 2;
  color: var(--text);
}

.document-card__footer {
  margin: 0;
  font-weight: 800;
  color: var(--royal-blue);
  font-size: 0.95rem;
}

/* ========== DUAL GRID (form + values) ========== */
.dual-grid {
  display: grid;
  gap: 1rem;
}

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.35rem 1.15rem;
}

.card__title {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  color: var(--royal-blue);
  font-weight: 800;
}

.card__title--icon {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.card__title-icon { font-size: 1.1rem; }

/* Values grid */
.values-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}

.value-item {
  text-align: center;
  padding: 0.85rem 0.5rem;
  border-radius: var(--radius-sm);
  background: linear-gradient(180deg, #f8fafc 0%, #fff 100%);
  border: 1px solid #eef2f7;
}

.value-item__icon {
  font-size: 1.75rem;
  margin-bottom: 0.35rem;
  line-height: 1;
}

.value-item__title {
  margin: 0 0 0.2rem;
  font-size: 0.82rem;
  font-weight: 800;
  color: var(--royal-blue);
}

.value-item__desc {
  margin: 0;
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Form fields with icons */
.field { margin-bottom: 0.85rem; position: relative; }

.field--icon .field__icon {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1rem;
  opacity: 0.55;
  pointer-events: none;
  z-index: 1;
}

.field--icon input {
  width: 100%;
  padding: 0.85rem 2.5rem 0.85rem 1rem;
  border: 1.5px solid #e5e9f0;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.95rem;
  background: #fafbfc;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field--icon input:focus {
  outline: none;
  border-color: var(--royal-blue-light);
  box-shadow: 0 0 0 3px rgba(11, 31, 75, 0.1);
  background: var(--white);
}

.field--icon input.is-invalid { border-color: #e74c3c; }

.field-error {
  margin: 0.3rem 0 0;
  color: #c0392b;
  font-size: 0.8rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.8rem 1.1rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--full { width: 100%; }

.btn--primary {
  background: linear-gradient(135deg, var(--royal-blue), var(--royal-blue-light));
  color: var(--white);
  box-shadow: 0 4px 14px rgba(11, 31, 75, 0.28);
}

.btn--gold {
  background: linear-gradient(135deg, var(--gold-dark), var(--gold));
  color: var(--royal-blue-dark);
  box-shadow: 0 3px 12px rgba(212, 175, 55, 0.35);
}

.btn--outline {
  background: var(--white);
  color: var(--royal-blue);
  border: 2px solid var(--royal-blue);
}

.btn--sm { padding: 0.5rem 0.85rem; font-size: 0.8rem; }

.btn--ig {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  background: linear-gradient(135deg, #833ab4, #fd1d1d, #fcb045);
  color: var(--white);
  box-shadow: 0 2px 8px rgba(131, 58, 180, 0.35);
}

.btn-ig-icon {
  display: block;
  flex-shrink: 0;
}

.btn__spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,0.35);
  border-top-color: var(--white);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Alerts */
.alert {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.88rem;
}

.alert--success { background: #e8f8f0; color: #1e7e46; border: 1px solid #a8e6c1; }
.alert--error { background: #fdecea; color: #c0392b; border: 1px solid #f5c6cb; }

/* ========== BOARD ========== */
.card--board { padding: 1.25rem 1rem; }

.board-toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.board-toolbar__search {
  position: relative;
}

.search-icon {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.5;
  pointer-events: none;
}

.board-toolbar__search input {
  width: 100%;
  padding: 0.7rem 2.4rem 0.7rem 1rem;
  border: 1.5px solid #e5e9f0;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.92rem;
  background: #fafbfc;
}

.board-toolbar__search input:focus {
  outline: none;
  border-color: var(--royal-blue-light);
}

.board-toolbar__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
  border: 1px solid #e8ecf4;
}

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

.signatures-table th,
.signatures-table td {
  padding: 0.7rem 0.65rem;
  text-align: right;
}

.signatures-table thead th {
  background: var(--royal-blue);
  color: var(--white);
  font-weight: 700;
  font-size: 0.82rem;
  white-space: nowrap;
}

.signatures-table tbody tr:nth-child(even) { background: var(--row-alt); }
.signatures-table tbody tr:hover { background: #eef3fa; }

.signatures-table td:first-child {
  color: var(--text-muted);
  font-weight: 600;
  width: 40px;
}

.date-cell {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.date-cell__icon { font-size: 0.85rem; opacity: 0.7; }

.signatures-table .empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
}

/* Pagination */
.pagination-bar {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #eef1f6;
}

.pagination-bar[hidden] { display: none !important; }

.pagination-bar__nav {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.page-btn {
  width: 34px;
  height: 34px;
  border: 1.5px solid #dde3ec;
  background: var(--white);
  border-radius: 8px;
  font-size: 1.1rem;
  color: var(--royal-blue);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

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

.page-numbers {
  display: flex;
  gap: 0.3rem;
}

.page-num {
  min-width: 34px;
  height: 34px;
  border: 1.5px solid #dde3ec;
  background: var(--white);
  border-radius: 8px;
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--royal-blue);
  cursor: pointer;
}

.page-num.is-active {
  background: var(--royal-blue);
  color: var(--white);
  border-color: var(--royal-blue);
}

.pagination-bar__info {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ========== FOOTER ========== */
.site-footer {
  background: linear-gradient(180deg, var(--royal-blue) 0%, var(--royal-blue-dark) 100%);
  color: rgba(255,255,255,0.9);
  padding: 2rem 1.25rem calc(1.25rem + var(--safe-bottom));
  text-align: center;
}

.site-footer__inner {
  max-width: 600px;
  margin: 0 auto;
}

.site-footer__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin-bottom: 0.75rem;
}

.site-footer__logo {
  border-radius: 50%;
  background: var(--white);
  padding: 4px;
  object-fit: contain;
}

.site-footer__name {
  font-weight: 800;
  font-size: 1rem;
}

.site-footer__ornament {
  color: var(--gold);
  font-size: 1rem;
  margin-bottom: 0.5rem;
}

.site-footer__copy {
  margin: 0;
  font-size: 0.75rem;
  opacity: 0.65;
}

/* ========== MODAL ========== */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal[hidden] { display: none !important; }

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(7, 20, 40, 0.7);
  backdrop-filter: blur(4px);
}

.modal__dialog {
  position: relative;
  background: var(--white);
  width: 100%;
  max-width: 400px;
  max-height: 92vh;
  overflow-y: auto;
  border-radius: var(--radius) var(--radius) 0 0;
  padding: 1.5rem 1.15rem calc(1.25rem + var(--safe-bottom));
  box-shadow: var(--shadow-lg);
  animation: slide-up 0.3s ease;
}

@keyframes slide-up {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

.modal__close {
  position: absolute;
  top: 0.65rem;
  left: 0.65rem;
  background: none;
  border: none;
  font-size: 1.6rem;
  color: var(--text-muted);
  cursor: pointer;
}

.modal__title {
  margin: 0 0 0.3rem;
  font-size: 1.1rem;
  color: var(--royal-blue);
  text-align: center;
  padding-top: 0.25rem;
}

.modal__subtitle {
  margin: 0 0 0.85rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.modal__subtitle strong { color: var(--royal-blue); }

.story-preview {
  display: flex;
  justify-content: center;
  margin-bottom: 0.85rem;
  background: #111;
  border-radius: var(--radius-sm);
  padding: 0.65rem;
}

#story-canvas {
  width: 100%;
  max-width: 240px;
  height: auto;
  border-radius: 8px;
}

.modal__actions {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

/* PRINT */
.print-only { display: none; }

@media print {
  body > *:not(.print-only) { display: none !important; }
  .print-only { display: block !important; padding: 1rem; color: #000; }
  .print-only h1 { text-align: center; font-size: 1.4rem; }
  .print-only table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
  .print-only th, .print-only td { border: 1px solid #333; padding: 0.45rem; text-align: right; }
  .print-only th { background: #eee; }
}

/* ========== RESPONSIVE ========== */
@media (min-width: 640px) {
  .document-card__grid {
    grid-template-columns: 1fr auto;
    text-align: right;
  }

  .document-card__content { text-align: right; }

  .dual-grid {
    grid-template-columns: 1fr 1fr;
  }

  .board-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
  }

  .board-toolbar__start { flex: 0 0 auto; }

  .board-toolbar__search {
    flex: 1 1 200px;
    min-width: 180px;
  }

  .board-toolbar__actions {
    flex: 0 0 auto;
    margin-right: auto;
  }

  .pagination-bar {
    flex-direction: row;
    justify-content: space-between;
  }

  .modal {
    align-items: center;
    padding: 1rem;
  }

  .modal__dialog {
    border-radius: var(--radius);
    max-height: 90vh;
  }
}

@media (min-width: 900px) {
  .page { padding: 1rem 1.5rem 3rem; }

  .card { padding: 1.5rem 1.35rem; }

  .document-card { padding: 2rem 1.75rem; }

  .value-item__title { font-size: 0.88rem; }
  .value-item__desc { font-size: 0.78rem; }
}
