/*
 * SangDZ - single stylesheet for the public site and the admin area.
 * Plain CSS, no framework, no build step. Works right-to-left (Arabic) and left-to-right.
 */

/* ---------- Fonts ---------- */
@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-Regular.woff') format('woff'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-Medium.woff') format('woff'); font-weight: 500 600; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-Bold.woff') format('woff'); font-weight: 700; font-display: swap; }
@font-face { font-family: 'Tajawal'; src: url('../fonts/Tajawal-ExtraBold.woff') format('woff'); font-weight: 800 900; font-display: swap; }

/* ---------- Colours (light / dark) ---------- */
:root {
  color-scheme: light;
  --bg: #ffffff;
  --fg: #171717;
  --muted: #525252;
  --card: rgba(255, 255, 255, .55);
  --panel: #ffffff;
  --border: rgba(23, 23, 23, .12);
  --input-bg: rgba(255, 255, 255, .7);
  --footer-bg: rgba(229, 229, 229, .35);
  --primary: #f43f5e;
  --primary-strong: #e11d48;
  --primary-soft: rgba(244, 63, 94, .1);
  --ok: #15803d;
  --ok-soft: rgba(22, 163, 74, .12);
  --gradient-opacity: .5;
  --show-light: inline-block;
  --show-dark: none;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #171717; --fg: #fafafa; --muted: #d4d4d4;
    --card: rgba(38, 38, 38, .45); --panel: #262626; --border: rgba(255, 255, 255, .14);
    --input-bg: rgba(23, 23, 23, .6); --footer-bg: rgba(38, 38, 38, .35);
    --primary: #fb7185; --primary-strong: #f43f5e; --primary-soft: rgba(251, 113, 133, .14);
    --ok: #4ade80; --ok-soft: rgba(74, 222, 128, .12);
    --gradient-opacity: .2; --show-light: none; --show-dark: inline-block;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #171717; --fg: #fafafa; --muted: #d4d4d4;
  --card: rgba(38, 38, 38, .45); --panel: #262626; --border: rgba(255, 255, 255, .14);
  --input-bg: rgba(23, 23, 23, .6); --footer-bg: rgba(38, 38, 38, .35);
  --primary: #fb7185; --primary-strong: #f43f5e; --primary-soft: rgba(251, 113, 133, .14);
  --ok: #4ade80; --ok-soft: rgba(74, 222, 128, .12);
  --gradient-opacity: .2; --show-light: none; --show-dark: inline-block;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  font-family: 'Tajawal', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 1.0625rem; line-height: 1.6; overflow-x: hidden; position: relative;
}
img { max-width: 100%; height: auto; }
a { color: var(--primary-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5rem; }
p { margin: 0 0 1rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: .5rem 0; width: 100%; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.icon { flex: none; vertical-align: -0.2em; }
.container { width: 100%; max-width: 1180px; margin-inline: auto; padding-inline: 1.5rem; }
.muted { color: var(--muted); }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.hp { position: absolute; inset-inline-start: -9999px; width: 1px; height: 1px; overflow: hidden; }
.only-light { display: var(--show-light); }
.only-dark { display: var(--show-dark); }
.gradient-text { background: linear-gradient(135deg, #ef4444, #db2777); -webkit-background-clip: text; background-clip: text; color: transparent; }
.bg-gradient { position: absolute; top: 0; left: 0; width: 100%; max-width: none; height: auto; z-index: -1; opacity: var(--gradient-opacity); filter: hue-rotate(180deg); pointer-events: none; user-select: none; }

/* ---------- Header ---------- */
.site-header { position: fixed; top: 0; inset-inline: 0; z-index: 50; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.header-inner { display: flex; align-items: center; gap: 1.25rem; padding-block: 1.25rem; }
.logo { display: flex; align-items: center; }
.logo img { height: 28px; width: auto; }
.nav-toggle { position: absolute; opacity: 0; width: 1px; height: 1px; }
.burger { display: none; cursor: pointer; padding: .35rem; border-radius: .5rem; }
.nav-toggle:focus-visible + .burger { outline: 2px solid var(--primary); }
.nav-panel { flex: 1; display: flex; align-items: center; gap: 1.25rem; }
.nav-links { flex: 1; display: flex; justify-content: center; gap: .5rem; }
.nav-links a { color: var(--fg); font-weight: 600; padding: .4rem .8rem; border-radius: .5rem; }
.nav-links a:hover { background: var(--primary-soft); text-decoration: none; }
.nav-links a.active { color: var(--primary-strong); }
.nav-tools { display: flex; align-items: center; gap: .75rem; }
.lang-menu { position: relative; }
.lang-menu summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: .3rem; padding: .3rem .6rem; border-radius: 999px; color: var(--muted); font-size: .9rem; font-weight: 600; user-select: none; }
.lang-menu summary::-webkit-details-marker { display: none; }
.lang-menu summary:hover, .lang-menu[open] summary { background: var(--primary-soft); }
.lang-menu .menu { min-width: 9.5rem; }
.lang-menu .menu a { justify-content: space-between; }
.lang-menu .menu a.active { color: var(--primary-strong); font-weight: 700; }
.icon-btn { display: inline-flex; padding: .4rem; border-radius: 999px; color: var(--muted); }
.icon-btn:hover { background: var(--primary-soft); }
.theme-to-dark { display: var(--show-light); }
.theme-to-light { display: var(--show-dark); }
.header-user { display: flex; align-items: center; }
.login-link { display: flex; align-items: center; gap: .3rem; font-weight: 600; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 2.5rem; height: 2.5rem; border-radius: 999px; background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
.menu { position: absolute; inset-inline-end: 0; top: calc(100% + .5rem); min-width: 13rem; background: var(--panel); border: 1px solid var(--border); border-radius: .75rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .15); padding: .4rem; z-index: 60; }
.menu-head { margin: 0; padding: .5rem .75rem; font-size: .9rem; border-bottom: 1px solid var(--border); }
.menu a, .menu button { display: flex; align-items: center; gap: .5rem; width: 100%; padding: .55rem .75rem; border: 0; background: none; color: var(--fg); font: inherit; font-size: .95rem; text-align: start; border-radius: .5rem; cursor: pointer; }
.menu a:hover, .menu button:hover { background: var(--primary-soft); text-decoration: none; }
.menu form { margin: 0; }

/* ---------- Main ---------- */
.site-main { flex: 1; padding-top: 6.5rem; padding-bottom: 3rem; display: grid; gap: 1rem; align-content: start; }
.page-title { font-size: 1.35rem; margin: 0; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: .85rem; padding: 1.5rem; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); box-shadow: 0 1px 2px rgba(0, 0, 0, .04); }
.card-title { font-size: 1.4rem; margin-bottom: .75rem; }
.narrow { max-width: 420px; width: 100%; margin-inline: auto; }
.narrow-lg { max-width: 640px; width: 100%; margin-inline: auto; }
.big-code { font-size: 4rem; color: var(--primary-strong); }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; margin: 0; }

/* ---------- Home ---------- */
.hero { display: flex; align-items: center; gap: 4rem; min-height: 512px; margin-top: 1.5rem; }
.hero-text { flex: 1; display: grid; gap: 1.25rem; min-width: 0; }
.hero-image { flex: 1; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.75rem); font-weight: 700; margin: 0; }
.hero-lead { font-size: 1.2rem; line-height: 1.75; margin: 0; }
.hero-cta { font-size: 1.25rem; margin: 0; display: inline-block; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: .3rem; min-width: 0; border: 0; padding: 0; margin: 0; }
.field label, .field legend { font-size: .92rem; font-weight: 600; padding: 0; }
.req { color: var(--primary-strong); }
input[type="text"], input[type="tel"], input[type="email"], input[type="password"], input[type="date"], input[type="search"], input[type="number"], select, textarea {
  width: 100%; padding: .6rem .8rem; font: inherit; font-size: 1rem; color: var(--fg);
  background: var(--input-bg); border: 1px solid var(--border); border-radius: .5rem; min-height: 2.75rem;
}
textarea { resize: vertical; min-height: 7rem; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 0; border-color: transparent; }
select:disabled { opacity: .55; cursor: not-allowed; }
input[dir="ltr"] { text-align: start; }
[dir="rtl"] input[dir="ltr"] { text-align: end; }
.field-error { color: var(--primary-strong); font-size: .85rem; margin: 0; }
.field-help { color: var(--muted); font-size: .8rem; margin: 0; }
.form-stack { display: grid; gap: 1rem; }
.form-narrow { max-width: 420px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.span-2 { grid-column: 1 / -1; }
.geo { display: contents; }
.geo-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.field-refresh { justify-content: flex-end; }
.search-form { display: grid; grid-template-columns: repeat(4, 1fr); gap: .6rem; }
.search-form .form-actions { grid-column: 1 / -1; margin-top: .6rem; }
.search-form-inline { grid-template-columns: repeat(4, 1fr) auto; align-items: end; margin-bottom: 1.25rem; }
.search-form-inline .form-actions { grid-column: auto; margin: 0; }
.search-option { grid-column: 1 / -1; font-size: .92rem; color: var(--muted); }
.reveal-form { margin: 0; }
.reveal-form .btn { white-space: nowrap; }
.contact-links { align-items: center; }
.donated-today { margin: 0 0 1rem; }
.small { font-size: .88rem; }
.table-compact th, .table-compact td { padding: .4rem .6rem; font-size: .9rem; }
.table-compact td:first-child { white-space: nowrap; }
.form-actions { display: flex; flex-wrap: wrap; gap: .75rem; }
.radio, .switch { display: flex; align-items: center; gap: .6rem; font-weight: 500; cursor: pointer; padding: .2rem 0; }
.radio input, .switch input { width: 1.15rem; height: 1.15rem; accent-color: var(--primary-strong); flex: none; }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .45rem; padding: .55rem 1.1rem; border-radius: .5rem; border: 1px solid transparent; font: inherit; font-weight: 600; font-size: 1rem; cursor: pointer; text-decoration: none; line-height: 1.3; }
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary-strong); color: #fff; }
.btn-primary:hover { background: #be123c; }
.btn-white { background: var(--panel); color: var(--fg); border-color: var(--border); }
.btn-white:hover, .btn-ghost:hover { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--fg); border-color: var(--border); }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-lg { padding: .75rem 1.4rem; }
.btn-sm { padding: .3rem .7rem; font-size: .88rem; }
.btn-block { width: 100%; }
.is-disabled { opacity: .45; pointer-events: none; }

/* ---------- Alerts ---------- */
.alert { padding: .8rem 1rem; border-radius: .6rem; border: 1px solid var(--border); margin: 0 0 1rem; font-size: .95rem; }
.site-main > .alert { margin: 0; }
.alert-success { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
/* Confirmation messages of the public site ("... updated successfully!") leave by themselves after 5 seconds.
   Errors stay. Hovering the message keeps it. */
.site-main:not(.admin-main) > .alert-success[role="status"] { overflow: hidden; max-height: 12rem; animation: flash-out .6s ease 5s forwards; }
.site-main:not(.admin-main) > .alert-success[role="status"]:hover { animation-play-state: paused; }
@keyframes flash-out { to { opacity: 0; max-height: 0; padding-block: 0; border-width: 0; visibility: hidden; } }
.alert-error, .alert-info { background: var(--primary-soft); color: var(--primary-strong); border-color: transparent; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; margin-inline: -1.5rem; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .7rem 1rem; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-weight: 600; white-space: nowrap; color: var(--muted); font-size: .88rem; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .center { text-align: center; }
.donor-blood { font-weight: 700; }
.contact-links { display: flex; gap: .4rem; justify-content: flex-end; flex-wrap: wrap; }
.contact { display: inline-flex; align-items: center; justify-content: center; width: 2.15rem; height: 2.15rem; border-radius: 999px; border: 1px solid var(--border); color: var(--fg); }
.contact:hover { text-decoration: none; background: var(--primary-soft); }
.contact-telegram { background: #0ea5e9; color: #fff; border-color: transparent; }
.contact-whatsapp { background: #16a34a; color: #fff; border-color: transparent; }
.contact-viber { background: #8b5cf6; color: #fff; border-color: transparent; }
.contact-telegram:hover, .contact-whatsapp:hover, .contact-viber:hover { filter: brightness(1.1); }
.contact-telegram .icon, .contact-whatsapp .icon, .contact-viber .icon { width: 1.15rem; height: 1.15rem; }
.contact-report { color: #f87171; }
.list-footer { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding-top: 1rem; font-size: .9rem; }
.pagination { display: flex; align-items: center; gap: .6rem; }
.pagination-info { color: var(--muted); font-size: .88rem; }

/* ---------- Statistics ---------- */
.stats { display: grid; grid-template-columns: repeat(9, 1fr); gap: .5rem; text-align: center; }
.stat { display: grid; gap: .25rem; padding: .5rem; }
.stat-label { color: var(--muted); font-weight: 600; font-size: .92rem; }
.stat-value { font-size: 1.35rem; font-weight: 700; }
.stat-total .stat-value { color: var(--primary-strong); }

/* ---------- Account ---------- */
.account { display: flex; padding: 0; }
.account-nav { display: flex; flex-direction: column; gap: .2rem; padding: 1rem; min-width: 15rem; border-inline-end: 1px solid var(--border); }
.account-nav a { display: flex; align-items: center; gap: .6rem; padding: .55rem .8rem; border-radius: .5rem; color: var(--fg); font-weight: 500; }
.account-nav a:hover { background: var(--primary-soft); text-decoration: none; }
.account-nav a.active { background: var(--primary-soft); color: var(--primary-strong); font-weight: 700; }
.account-body { flex: 1; padding: 1.5rem; min-width: 0; }
.danger-box { border: 1px solid var(--border); border-radius: .75rem; padding: 1.1rem; margin-top: 1rem; display: grid; gap: .6rem; justify-items: start; }
.danger-box h2 { font-size: 1.05rem; margin: 0; }
.danger-box p { margin: 0; }

/* ---------- Content pages ---------- */
.page-content { padding-inline: .5rem; overflow-wrap: anywhere; }
.page-content h1 { font-size: 1.5rem; margin-bottom: 1rem; }
.page-content ul, .page-content ol { margin: 1rem 0; padding-inline-start: 2.5rem; }
.page-content img { max-width: 100%; height: auto; }

/* ---------- Footer ---------- */
.site-footer { background: var(--footer-bg); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); padding-block: 3rem; }
.footer-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2rem; }
.site-footer img { height: 40px; width: auto; }
.site-footer h2 { font-size: 1rem; font-weight: 600; margin-bottom: .9rem; }
.footer-mail { display: flex; align-items: center; gap: .5rem; font-size: .9rem; margin-top: 1rem; }
.footer-mail a, .footer-links a { color: var(--muted); }
.footer-links { list-style: none; margin: 0; padding: 0; display: grid; gap: .3rem; font-size: .92rem; }
.footer-about { color: var(--muted); font-size: .92rem; }
.social { display: flex; gap: 1rem; margin: 1rem 0 0; }
.social a { color: var(--muted); }
.social a:hover { color: var(--primary-strong); }

/* ---------- Announcement banner (admin setting) ---------- */
.notice-bar { display: flex; align-items: flex-start; gap: .75rem; padding: .55rem .9rem; border-radius: .6rem; background: var(--primary-soft); border: 1px solid var(--border); font-size: .95rem; }
.notice-text { flex: 1; min-width: 0; }
.notice-close { display: inline-flex; padding: .2rem; border-radius: 999px; color: var(--muted); flex: none; }
.notice-close:hover { background: var(--primary-soft); }

/* ---------- Admin area ---------- */
.admin-bar { background: #171717; color: #fafafa; }
.admin-bar .container { display: flex; align-items: center; gap: 1.25rem; padding-block: .7rem; flex-wrap: wrap; }
.admin-bar a, .admin-bar button { color: #e5e5e5; font-weight: 600; font-size: .95rem; background: none; border: 0; cursor: pointer; font-family: inherit; padding: .25rem .5rem; border-radius: .4rem; }
.admin-bar a:hover, .admin-bar button:hover { background: rgba(255, 255, 255, .12); text-decoration: none; }
.admin-bar a.active { color: #fda4af; }
.admin-bar .brand { font-weight: 800; color: #fff; margin-inline-end: .5rem; }
.admin-bar .spacer { flex: 1; }
.admin-bar form { margin: 0; }
.admin-main { padding-top: 1.5rem; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr)); gap: 1rem; }
.tile { display: grid; gap: .2rem; padding: 1.1rem; border: 1px solid var(--border); border-radius: .75rem; background: var(--card); color: var(--fg); }
.tile:hover { text-decoration: none; border-color: var(--primary); }
.tile strong { font-size: 1.7rem; }
.tile span { color: var(--muted); font-size: .9rem; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: end; margin-bottom: 1rem; }
.filters .field { flex: 1 1 10rem; }
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 700; background: var(--primary-soft); color: var(--primary-strong); white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-off { background: rgba(115, 115, 115, .18); color: var(--muted); }
.row-actions { display: flex; gap: .35rem; flex-wrap: wrap; }
.row-actions form { margin: 0; }
.admin-main .table-wrap { margin-inline: 0; }
.prewrap { white-space: pre-wrap; overflow-wrap: anywhere; }
textarea.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88rem; min-height: 14rem; direction: ltr; text-align: left; }

/* ---------- Small screens ---------- */
@media (max-width: 860px) {
  .container { padding-inline: 1rem; }
  .header-inner { justify-content: space-between; padding-block: .9rem; }
  .burger { display: inline-flex; }
  .nav-panel { display: none; position: absolute; top: 100%; inset-inline: 0; flex-direction: column; align-items: stretch; gap: 1rem; padding: 1rem; background: var(--panel); border-block: 1px solid var(--border); box-shadow: 0 20px 30px rgba(0, 0, 0, .12); }
  .nav-toggle:checked ~ .nav-panel { display: flex; }
  .nav-links { flex-direction: column; }
  .nav-links a { padding: .7rem .9rem; background: var(--primary-soft); }
  .nav-tools { justify-content: space-between; }
  .lang-menu .menu { inset-inline: 0 auto; }
  .login-link span { display: none; }
  .site-main { padding-top: 5.25rem; }
  .hero { min-height: 0; margin-top: .5rem; text-align: center; }
  .hero-image, .hero-lead { display: none; }
  .search-form, .search-form-inline, .form-grid, .geo-row { grid-template-columns: 1fr; }
  .search-form .btn, .search-form-inline .btn { width: 100%; }
  .card { padding: 1.1rem; }
  .stats { grid-template-columns: 1fr; text-align: start; }
  .stat { grid-template-columns: 1fr auto; border-bottom: 1px solid var(--border); padding: .6rem .25rem; }
  .stat:last-child { border-bottom: 0; }
  .account { flex-direction: column; }
  .account-nav { border-inline-end: 0; border-bottom: 1px solid var(--border); min-width: 0; }
  .account-body { padding: 1.1rem; }
  .footer-grid { grid-template-columns: 1fr; }

  /* donor table becomes a list of cards */
  .table-wrap { margin-inline: 0; overflow: visible; }
  .donors thead { display: none; }
  .donors, .donors tbody { display: block; }
  .donors tr { display: grid; grid-template-columns: 1fr auto; gap: .15rem .75rem; padding: .9rem; margin-bottom: .75rem; border: 1px solid var(--border); border-radius: .75rem; background: var(--card); }
  .donors td { display: block; padding: 0; border: 0; text-align: start !important; font-size: .9rem; color: var(--muted); grid-column: 1 / -1; }
  .donors td[data-label]:not(.donor-name):not(.donor-blood)::before { content: attr(data-label) ": "; font-weight: 600; }
  .donors .donor-name { grid-column: 1; font-weight: 700; font-size: 1.05rem; color: var(--fg); }
  .donors .donor-blood { grid-column: 2; grid-row: 1; font-size: 1.15rem; color: var(--fg); }
  .donors .contact-cell { padding-top: .6rem; }
  .contact { width: 2.5rem; height: 2.5rem; }
}
