:root {
  --bg: #edf2ed;
  --surface: rgba(255,255,255,0.93);
  --surface-strong: #ffffff;
  --line: #d5ded2;
  --ink: #223229;
  --muted: #6c7d73;
  --brand: #9faf9d;
  --brand-deep: #6f8474;
  --brand-dark: #51675a;
  --brand-soft: #e7eee5;
  --accent: #c5d1c3;
  --ok: #3f7853;
  --danger: #b65f5f;
  --shadow: 0 14px 40px rgba(64, 84, 67, 0.12);
  --radius: 26px;
  --radius-sm: 18px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: Inter, system-ui, sans-serif;
  background:
    radial-gradient(circle at top, rgba(159,175,157,0.18), transparent 24%),
    linear-gradient(180deg, #eff4ef 0%, #e7eee6 45%, #edf2ed 100%);
  color: var(--ink);
}
body { min-height: 100vh; }
a { color: inherit; }
button, input, select, textarea {
  font: inherit;
}
button {
  cursor: pointer;
  border: 0;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px 14px;
  background: #fff;
  color: var(--ink);
  outline: none;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--brand-dark);
  box-shadow: 0 0 0 4px rgba(111,132,116,0.12);
}
textarea { resize: vertical; min-height: 96px; }
label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
label > span, .field-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
}

.shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 14px max(20px, env(safe-area-inset-bottom));
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-logo {
  width: 54px;
  height: 54px;
  object-fit: contain;
  border-radius: 20px;
  background: rgba(255,255,255,0.6);
  box-shadow: var(--shadow);
}
.brand-ar {
  font-family: 'Noto Kufi Arabic', sans-serif;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.25;
}
.brand-en {
  font-size: 0.88rem;
  color: var(--muted);
  text-transform: lowercase;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.user-chip {
  border-radius: 999px;
  padding: 10px 12px;
  background: rgba(255,255,255,0.86);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.layout { min-height: calc(100vh - 110px); }
.card {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.75);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.auth-wrap {
  min-height: calc(100vh - 120px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.auth-card {
  width: 100%;
  max-width: 430px;
  padding: 28px 22px 22px;
  text-align: center;
}
.auth-logo {
  width: 88px;
  height: 88px;
  object-fit: contain;
  display: block;
  margin: 0 auto 14px;
}
.auth-title {
  margin-bottom: 20px;
}
.form-stack { text-align: left; }
.stack, .stack-lg {
  display: flex;
  flex-direction: column;
}
.stack { gap: 14px; }
.stack-lg { gap: 18px; }
.hidden { display: none !important; }

.home-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.home-brand {
  padding: 22px;
  background: linear-gradient(180deg, rgba(255,255,255,0.9), rgba(249,251,248,0.94));
}
.home-title {
  font-size: 1.3rem;
}
.home-subtitle {
  margin-top: 8px;
  font-size: 0.95rem;
  color: var(--muted);
}
.home-actions {
  display: grid;
  gap: 14px;
}
.home-action {
  width: 100%;
  border-radius: 28px;
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
  box-shadow: var(--shadow);
}
.home-action:hover, .home-action:active {
  transform: translateY(-1px);
}
.home-action.add {
  background: linear-gradient(160deg, #6f8474, #8ea08d 58%, #a5b6a4);
  color: #fff;
}
.home-action.search {
  background: linear-gradient(180deg, #ffffff, #f3f7f2);
  color: var(--ink);
  border: 1px solid var(--line);
}
.home-action-icon {
  width: 54px;
  height: 54px;
  border-radius: 18px;
  display: grid;
  place-items: center;
  font-size: 1.65rem;
  font-weight: 800;
  background: rgba(255,255,255,0.18);
  flex: 0 0 auto;
}
.home-action.search .home-action-icon {
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.home-action-text {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.home-action-text strong {
  font-size: 1.08rem;
}
.home-action-text small {
  font-size: 0.86rem;
  opacity: 0.92;
}

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.section-kicker {
  font-size: 12px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 800;
  margin-bottom: 4px;
}
.view-head h2, .dialog-head h3 {
  margin: 0;
  font-size: 1.35rem;
}
.form-card, .search-card {
  padding: 18px;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.dob-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.dob-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.form-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.primary, .secondary, .ghost {
  border-radius: 18px;
  padding: 13px 16px;
  font-weight: 700;
  transition: transform .18s ease, opacity .18s ease, background .18s ease;
}
.primary:hover, .secondary:hover, .ghost:hover,
.primary:active, .secondary:active, .ghost:active {
  transform: translateY(-1px);
}
.primary {
  background: linear-gradient(180deg, var(--brand-deep), var(--brand-dark));
  color: #fff;
  box-shadow: 0 12px 26px rgba(81,103,90,0.24);
}
.secondary {
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.ghost {
  background: rgba(255,255,255,0.6);
  color: var(--ink);
  border: 1px solid var(--line);
}
.small {
  padding: 10px 12px;
  font-size: 12px;
}
.auth-btn { width: 100%; }
.password-wrap {
  display: flex;
  gap: 8px;
}
.password-wrap input { flex: 1 1 auto; }
.password-wrap button { flex: 0 0 auto; }

.search-main {
  padding: 16px 16px;
  font-size: 15px;
}
.filter-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.toggle-field {
  justify-content: space-between;
  align-items: center;
  flex-direction: row;
  background: var(--brand-soft);
  border-radius: 18px;
  padding: 14px;
  min-height: 56px;
}
.toggle-field input {
  width: 22px;
  height: 22px;
  accent-color: var(--brand-dark);
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-chip {
  padding: 10px 14px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 700;
}
.filter-chip.active {
  background: var(--brand-dark);
  color: #fff;
  border-color: transparent;
}
.toolbar-end {
  display: flex;
  justify-content: flex-end;
}
.pill-row {
  min-width: 88px;
  text-align: center;
  padding: 10px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.88);
  border: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
}

.donor-card {
  padding: 16px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255,255,255,0.96), rgba(247,250,246,0.98));
  border: 1px solid rgba(255,255,255,0.85);
  box-shadow: var(--shadow);
}
.donor-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.donor-name {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: 4px;
}
.muted {
  color: var(--muted);
}
.compact {
  margin: 0;
  font-size: 0.9rem;
}
.meta, .stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.meta span, .stats span {
  padding: 8px 10px;
  border-radius: 999px;
  background: var(--brand-soft);
  font-size: 12px;
  color: var(--brand-dark);
}
.stats {
  margin-top: 12px;
}
.status-chip.ok {
  background: rgba(63,120,83,0.12);
  color: var(--ok);
}
.status-chip.wait {
  background: rgba(182,95,95,0.12);
  color: var(--danger);
}
.donor-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}
.edit-btn, .history-btn, .delete-btn {
  padding: 11px 14px;
  border-radius: 16px;
  font-weight: 700;
}
.edit-btn {
  background: var(--brand-dark);
  color: #fff;
}
.history-btn {
  background: var(--brand-soft);
  color: var(--brand-dark);
}
.delete-btn {
  background: rgba(182,95,95,0.14);
  color: var(--danger);
}

.history-dialog {
  width: min(92vw, 560px);
  border: 0;
  padding: 0;
  border-radius: 28px;
  background: #fff;
  box-shadow: 0 24px 60px rgba(0,0,0,0.24);
}
.history-dialog::backdrop {
  background: rgba(20,31,25,0.38);
}
.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 20px 20px 12px;
  border-bottom: 1px solid var(--line);
}
.history-body {
  padding: 18px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 70vh;
  overflow: auto;
}
.history-item {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 14px;
  background: #fbfcfb;
}
.empty-state {
  text-align: center;
  padding: 32px 16px;
  border-radius: 24px;
  color: var(--muted);
  background: rgba(255,255,255,0.82);
  border: 1px dashed var(--line);
}
.message {
  padding: 13px 14px;
  border-radius: 16px;
  font-size: 14px;
  font-weight: 700;
}
.message.ok {
  background: rgba(63,120,83,0.12);
  color: var(--ok);
}
.message.err {
  background: rgba(182,95,95,0.12);
  color: var(--danger);
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }
  .user-chip {
    max-width: calc(100vw - 130px);
  }
  .form-grid, .filter-grid {
    grid-template-columns: 1fr;
  }
  .dob-grid {
    grid-template-columns: 1fr;
  }
  .view-head {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .form-actions {
    flex-direction: column;
  }
  .form-actions > * {
    width: 100%;
  }
  .donor-top {
    flex-direction: column;
  }
  .home-action {
    padding: 20px 18px;
  }
}
