/* =========================================================
   Wefaq — base styles (mobile-first, RTL)
   ======================================================= */
:root {
  --brand-navy: #14243a;
  --brand-teal: #077a78;
  --brand-teal-hover: #05605f;

  --bg: #f3f6f8;
  --bg-accent: #e3eeee;
  --surface: #ffffff;
  --text: #14243a;
  --text-muted: #5b6878;
  --border: #d5dde5;
  --input-bg: #ffffff;
  --focus: rgba(7, 122, 120, .35);
  --error-bg: #fdecec;
  --error-text: #a32020;
  --error-border: #f3c2c2;
  --info-bg: #e8f2fb;
  --info-text: #1d4e7a;
  --success-bg: #e6f5ef;
  --success-text: #136b47;
  --shadow: 0 10px 30px rgba(20, 36, 58, .08), 0 2px 6px rgba(20, 36, 58, .05);

  --radius: 14px;
  --radius-sm: 10px;
  --font: "Almarai", "Segoe UI", Tahoma, "Geeza Pro", "Arial", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1826;
    --bg-accent: #10283a;
    --surface: #15233a;
    --text: #e8eef5;
    --text-muted: #9fb0c3;
    --border: #2b3d55;
    --input-bg: #0f1c2e;
    --brand-teal: #14a3a0;
    --brand-teal-hover: #18b8b5;
    --focus: rgba(20, 163, 160, .4);
    --error-bg: #3a1a1f;
    --error-text: #ffb4b4;
    --error-border: #5c2a30;
    --info-bg: #142c45;
    --info-text: #b5d6f5;
    --success-bg: #12332a;
    --success-text: #9be3c3;
    --shadow: 0 10px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

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

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }
[hidden] { display: none !important; }

/* =========================================================
   Login page
   ======================================================= */
.auth-page {
  min-height: 100vh;
  min-height: 100dvh;
  background:
    radial-gradient(1200px 600px at 100% -10%, var(--bg-accent), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, var(--bg-accent), transparent 60%),
    var(--bg);
}

.auth-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding:
    max(24px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 20px;
}

.brand {
  display: flex;
  justify-content: center;
  margin-bottom: 20px;
}
.brand-logo { width: 180px; height: auto; display: block; }

@media (prefers-color-scheme: dark) {
  /* the logo has a light background — give it a soft plate in dark mode */
  .brand-logo, .topbar-logo { background: #fff; border-radius: 10px; padding: 6px 10px; }
}

.brand-text {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--brand-navy);
  letter-spacing: 0;
}
@media (prefers-color-scheme: dark) { .brand-text { color: var(--text); } }
.brand-text-sm { font-size: 1.5rem; }

.auth-title {
  margin: 0 0 4px;
  font-size: 1.35rem;
  font-weight: 700;
  text-align: center;
}
.auth-subtitle {
  margin: 0 0 22px;
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
}

.auth-form { display: grid; gap: 18px; }

.field { display: grid; gap: 6px; }
.field label { font-weight: 600; font-size: .95rem; }

.field input {
  width: 100%;
  min-height: 50px;
  padding: 12px 14px;
  font: inherit;
  font-size: 16px;            /* >=16px prevents iOS auto-zoom */
  color: var(--text);
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  -webkit-appearance: none;
  appearance: none;
}
.field input[dir="ltr"] { text-align: left; }
.field input:focus {
  border-color: var(--brand-teal);
  box-shadow: 0 0 0 4px var(--focus);
}
.field input[aria-invalid="true"] { border-color: var(--error-text); }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 52px; } /* room for the eye button (input is LTR) */
.toggle-password {
  position: absolute;
  top: 50%;
  right: 4px;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.toggle-password:hover { color: var(--text); }
.toggle-password:focus-visible { outline: 3px solid var(--focus); }
.toggle-password .icon-eye-off { display: none; }
.toggle-password[aria-pressed="true"] .icon-eye { display: none; }
.toggle-password[aria-pressed="true"] .icon-eye-off { display: block; }

.caps-warning { margin: 0; font-size: .85rem; color: var(--error-text); }

/* =========================================================
   Buttons
   ======================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 18px;
  font: inherit;
  font-weight: 700;
  border-radius: var(--radius-sm);
  border: 1.5px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s, border-color .15s, transform .05s;
  touch-action: manipulation;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus); }
.btn-block { width: 100%; min-height: 52px; font-size: 1.05rem; }

.btn-primary { background: var(--brand-teal); color: #fff; }
.btn-primary:hover { background: var(--brand-teal-hover); }
.btn-primary:disabled { opacity: .75; cursor: progress; }

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-ghost:hover { border-color: var(--brand-teal); color: var(--brand-teal); }

.spinner {
  display: none;
  width: 18px; height: 18px;
  flex: 0 0 auto;
  border: 2.5px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  opacity: .9;
  animation: spin .7s linear infinite;
}
.btn-sm .spinner { width: 14px; height: 14px; border-width: 2px; }
.is-loading .spinner { display: inline-block; }
.btn.is-loading { pointer-events: none; opacity: .85; cursor: progress; }
@keyframes spin { to { transform: rotate(360deg); } }

.btn-danger-solid { background: #c62828; color: #fff; }
.btn-danger-solid:hover { background: #a91f1f; }

/* ---------- Confirmation dialog ---------- */
.modal {
  border: 0;
  padding: 0;
  width: min(420px, calc(100vw - 32px));
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(13, 24, 38, .55); backdrop-filter: blur(2px); }
.modal[open] { animation: modal-in .16s ease-out; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-box { margin: 0; padding: 24px 22px 20px; text-align: center; }
.modal-icon {
  width: 52px; height: 52px; margin: 0 auto 12px;
  display: grid; place-items: center;
  border-radius: 50%;
  font-size: 1.6rem; font-weight: 800;
  background: var(--info-bg); color: var(--info-text);
}
.modal-danger .modal-icon { background: var(--error-bg); color: var(--error-text); }
.modal-title { margin: 0 0 8px; font-size: 1.2rem; }
.modal-msg { margin: 0 0 20px; color: var(--text-muted); line-height: 1.8; }
.modal-actions { display: flex; gap: 10px; }
.modal-actions .btn { flex: 1; min-height: 48px; }

/* ---------- Full-page loading overlay ---------- */
.page-loading {
  position: fixed; inset: 0; z-index: 1000;
  display: grid; place-items: center;
  background: rgba(13, 24, 38, .35);
  opacity: 0; visibility: hidden;
  transition: opacity .2s, visibility .2s;
}
.page-loading.is-visible { opacity: 1; visibility: visible; }
.page-loading-box {
  display: flex; flex-direction: column; align-items: center; gap: 14px;
  padding: 24px 32px;
  border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow);
  font-weight: 700;
}
.loader {
  width: 46px; height: 46px;
  border: 4px solid var(--border);
  border-top-color: var(--brand-teal);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* =========================================================
   Alerts
   ======================================================= */
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: .95rem;
  border: 1px solid transparent;
}
.alert-error   { background: var(--error-bg);   color: var(--error-text);   border-color: var(--error-border); }
.alert-info    { background: var(--info-bg);    color: var(--info-text); }
.alert-success { background: var(--success-bg); color: var(--success-text); }

.auth-note {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 20px 0 0;
  color: var(--text-muted);
  font-size: .82rem;
  text-align: center;
}
.auth-note svg { color: var(--brand-teal); flex-shrink: 0; }

.auth-footer { color: var(--text-muted); font-size: .8rem; }

/* =========================================================
   App shell (dashboard)
   ======================================================= */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar-logo { width: 110px; height: auto; display: block; }
.topbar-user { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-user form { margin: 0; }
.user-name { font-weight: 600; }
.badge {
  font-size: .75rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg-accent);
  color: var(--brand-teal);
  font-weight: 700;
}

.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 20px 16px max(24px, env(safe-area-inset-bottom));
}
.page-title { font-size: 1.4rem; margin: 4px 0 16px; }
.muted { color: var(--text-muted); }

.stats {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  border-inline-start: 5px solid var(--brand-navy);
  display: grid;
  gap: 4px;
}
.stat-card-accent { border-inline-start-color: var(--brand-teal); }
.stat-label { color: var(--text-muted); font-size: .9rem; }
.stat-value { font-size: 2rem; line-height: 1.1; font-variant-numeric: tabular-nums; }

/* =========================================================
   App: navigation, page head, cards
   ======================================================= */
.skip-link {
  position: absolute; inset-inline-start: 8px; top: -60px;
  background: var(--brand-teal); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 100;
}
.skip-link:focus { top: 8px; }
.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;
}
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

.topbar-brand { display: inline-flex; align-items: center; text-decoration: none; }

.mainnav {
  order: 3;
  flex-basis: 100%;
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  margin: 0 -4px;
}
.mainnav::-webkit-scrollbar { display: none; }
.mainnav a {
  flex: 0 0 auto;
  padding: 8px 14px;
  border-radius: 999px;
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 700;
  min-height: 40px;
  display: inline-flex;
  align-items: center;
}
.mainnav a:hover { color: var(--text); background: var(--bg); }
.mainnav a.active { background: var(--bg-accent); color: var(--brand-teal); }

/* ---------- Mobile side menu (drawer); becomes the normal top bar from 900px ---------- */
.topbar { flex-wrap: nowrap; }
.topbar-brand { margin-inline-start: auto; }  /* menu button on the right, logo on the left */
.nav-toggle, .nav-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: 0 0 auto;
  padding: 0;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.nav-toggle:focus-visible, .nav-close:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--focus); }
.nav-close { width: 40px; height: 40px; border-color: transparent; font-size: 1.1rem; }
.nav-toggle-bars { display: grid; gap: 4px; width: 20px; }
.nav-toggle-bars span { display: block; height: 2px; border-radius: 2px; background: currentColor; }

.drawer {
  position: fixed;
  top: 0; bottom: 0;
  inset-inline-start: 0;            /* right side in RTL */
  z-index: 30;
  width: min(300px, 84vw);
  display: flex; flex-direction: column; gap: 12px;
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: var(--surface);
  box-shadow: -12px 0 40px rgba(0, 0, 0, .18);
  overflow-y: auto;
  transform: translateX(100%);
  visibility: hidden;
  transition: transform .25s ease, visibility .25s;
}
[dir="ltr"] .drawer { transform: translateX(-100%); }
.nav-open .drawer { transform: none; visibility: visible; }
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 25;
  background: rgba(13, 24, 38, .5);
  opacity: 0; visibility: hidden;
  transition: opacity .25s, visibility .25s;
}
.nav-open .drawer-backdrop { opacity: 1; visibility: visible; }
body.nav-open { overflow: hidden; }

.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.drawer-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.drawer-user > span:last-child { display: grid; gap: 4px; justify-items: start; min-width: 0; }
.drawer-avatar {
  width: 42px; height: 42px; flex: 0 0 auto;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--brand-teal); color: #fff;
  font-weight: 800; font-size: 1.1rem;
}
.drawer .mainnav { order: 0; flex-basis: auto; flex-direction: column; gap: 4px; margin: 0; overflow: visible; }
.drawer .mainnav a {
  min-height: 50px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 1.05rem;
  color: var(--text);
}
.drawer .mainnav a.active { background: var(--bg-accent); color: var(--brand-teal); box-shadow: inset -4px 0 0 var(--brand-teal); }
.drawer .topbar-user { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); }
.drawer .topbar-user .user-name, .drawer .topbar-user .badge { display: none; }
.drawer .topbar-user form, .drawer .topbar-user .btn { width: 100%; }
.drawer .topbar-user .btn { min-height: 46px; }

.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .9rem; }
.btn-danger { background: transparent; color: var(--error-text); border-color: var(--error-border); }
.btn-danger:hover { background: var(--error-bg); }
.badge-danger { background: var(--error-bg); color: var(--error-text); }

.page-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.page-head .page-title { margin-bottom: 0; }
.page-sub { margin: 2px 0 0; }
.page-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.page-actions form { margin: 0; }
.page-actions .btn { flex: 1 1 auto; }

.breadcrumb {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  font-size: .9rem; color: var(--text-muted); margin-bottom: 8px;
}
.breadcrumb a { color: var(--brand-teal); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }

.ref {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  letter-spacing: .04em;
  direction: ltr;
  unicode-bidi: isolate;
}
a.ref { color: var(--brand-teal); font-weight: 700; text-decoration: none; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  margin: 0 0 16px;
  min-width: 0;
}
.card-title { font-size: 1.05rem; font-weight: 800; margin: 0 0 14px; padding: 0; }
fieldset.card { margin-inline: 0; }
fieldset.card > legend.card-title { float: inline-start; width: 100%; }
fieldset.card > legend.card-title + * { clear: both; }

a.stat-card { text-decoration: none; color: inherit; transition: border-color .15s, transform .15s; }
a.stat-card:hover { border-color: var(--brand-teal); }
.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.quick-actions .btn { flex: 1 1 220px; }

/* =========================================================
   Filters
   ======================================================= */
.filters {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 16px;
}
.filters > summary {
  cursor: pointer;
  padding: 14px 16px;
  font-weight: 700;
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
}
.filters > summary::-webkit-details-marker { display: none; }
.filters > summary::before {
  content: "";
  width: 8px; height: 8px;
  border-inline-end: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform .15s;
  margin-inline-end: 4px;
}
.filters[open] > summary::before { transform: rotate(-135deg); }

.filters-form, .phone-search {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  padding: 0 16px 16px;
}
.phone-search { border-top: 1px dashed var(--border); padding-top: 14px; }
.filters-actions { display: flex; gap: 8px; align-items: flex-end; }
.filters-actions .btn { flex: 1; }
.pair { display: flex; gap: 8px; }
.pair > * { flex: 1; min-width: 0; }
.pair > .btn { flex: 0 0 auto; }

/* shared form controls */
.field select, .field textarea,
.field input[type="search"], .field input[type="number"], .field input[type="tel"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  background: var(--input-bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.field select:focus, .field textarea:focus { border-color: var(--brand-teal); box-shadow: 0 0 0 4px var(--focus); }
.field textarea { resize: vertical; min-height: 110px; line-height: 1.7; }
.field select {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235b6878' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: left 14px center; /* RTL: arrow on the left */
  background-size: 12px 8px;
  padding-inline-start: 12px;
  padding-inline-end: 40px;
}
.field select:focus {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23077a78' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  .field select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%239fb0c3' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
  .field select:focus {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2314a3a0' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}
.field [aria-invalid="true"] { border-color: var(--error-text) !important; }
.field-error { margin: 2px 0 0; color: var(--error-text); font-size: .875rem; }
.hint { margin: 2px 0 0; color: var(--text-muted); font-size: .85rem; }
.counter { display: block; text-align: end; font-size: .8rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.req { color: var(--error-text); }
.optional { color: var(--text-muted); font-weight: 400; font-size: .85rem; }
.label { font-weight: 600; font-size: .95rem; }
.field input::placeholder, .field textarea::placeholder { color: var(--text-muted); opacity: .75; }

/* =========================================================
   Record form
   ======================================================= */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 16px; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; }
.choice {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  padding: 8px 14px;
  border: 1.5px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  background: var(--input-bg);
  user-select: none;
}
/* undo the text-input styles (.field input) for radios / checkboxes */
.field .choice input {
  all: revert;
  width: 20px;
  height: 20px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--brand-teal);
  cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--brand-teal); background: var(--bg-accent); color: var(--brand-teal); font-weight: 700; }
.choice:has(input:focus-visible) { box-shadow: 0 0 0 4px var(--focus); }

.form-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 10px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.form-actions .btn { flex: 1; min-height: 50px; }
.form-actions .btn-primary { flex: 2; }

/* =========================================================
   Data table -> cards on mobile
   ======================================================= */
.table-wrap { margin-bottom: 16px; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead { display: none; }
.data-table tr {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 10px;
}
.data-table td {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px dashed var(--border);
  text-align: start;
}
.data-table td:last-child { border-bottom: 0; }
.data-table td::before {
  content: attr(data-label);
  color: var(--text-muted);
  font-size: .875rem;
  flex-shrink: 0;
}
.data-table td.cell-action { padding-top: 10px; }
.data-table td.cell-action::before { content: none; }
.data-table td.cell-action .btn { width: 100%; }
.data-table td > * { text-align: end; }

.empty {
  text-align: center;
  padding: 40px 16px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-muted);
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 24px;
}

/* =========================================================
   Record details
   ======================================================= */
.detail-grid { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.details { margin: 0; display: grid; gap: 0; }
.details > div {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.details > div:last-child { border-bottom: 0; }
.details dt { color: var(--text-muted); font-size: .875rem; }
.details dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.details-text dd { font-weight: 400; line-height: 1.8; }

.card-contact { display: flex; flex-direction: column; gap: 10px; }
.card-contact .card-title { margin-bottom: 4px; }
.phone { font-size: 1.5rem; font-weight: 800; margin: 0; letter-spacing: .04em; text-align: start; unicode-bidi: isolate; }
.phone-masked { color: var(--text-muted); letter-spacing: .15em; }
.contact-actions { display: flex; gap: 8px; }
.contact-actions .btn { flex: 1; }
.card-contact form { margin: 0; }
.card-contact form .btn { width: 100%; }
.meta { margin: 0 0 24px; }

/* =========================================================
   Registration links (invites) + public page
   ======================================================= */
.section-title { font-size: 1.1rem; margin: 8px 0 12px; }
.card-highlight { border: 2px solid var(--brand-teal); }
.copy-row { margin-bottom: 12px; }
.copy-input {
  width: 100%;
  min-height: 50px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color: var(--text);
  background: var(--bg);
  border: 1.5px dashed var(--brand-teal);
  border-radius: var(--radius-sm);
  text-align: left;
}
.contact-actions { flex-wrap: wrap; }

.status {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-active  { background: var(--success-bg); color: var(--success-text); }
.status-used    { background: var(--info-bg);    color: var(--info-text); }
.status-expired { background: var(--bg);         color: var(--text-muted); border: 1px solid var(--border); }
.status-revoked { background: var(--error-bg);   color: var(--error-text); }

.public-header {
  display: flex;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px 4px;
}
.public-header .brand-logo { width: 150px; }
.public-page .page-title { margin-top: 8px; }

.gender-choice {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  max-width: 520px;
  margin: 24px auto;
}
.gender-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 170px;
  padding: 20px 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--brand-navy);
  text-decoration: none;
  transition: border-color .15s, transform .1s, background-color .15s;
  touch-action: manipulation;
}
.gender-card:hover, .gender-card:focus-visible {
  border-color: var(--brand-teal);
  background: var(--bg-accent);
  outline: none;
}
.gender-card:active { transform: scale(.98); }
.gender-icon {
  width: 72px; height: 72px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 2.4rem; line-height: 1;
  background: var(--bg-accent);
  color: var(--brand-navy);
}
.gender-card-f .gender-icon { color: var(--brand-teal); }
.gender-label { font-size: 1.35rem; font-weight: 800; }
@media (prefers-color-scheme: dark) {
  .gender-card, .gender-icon { color: var(--text); }
}

.result-card { text-align: center; max-width: 480px; margin: 24px auto; padding: 32px 22px; }
.result-icon {
  width: 64px; height: 64px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 2rem; font-weight: 800;
}
.result-success .result-icon { background: var(--success-bg); color: var(--success-text); }
.result-error .result-icon   { background: var(--error-bg);   color: var(--error-text); }

/* =========================================================
   Users page
   ======================================================= */
.user-form { display: grid; gap: 18px; max-width: 560px; }
.user-form .field input[type="text"] { width: 100%; }
.user-form .field .choice { justify-self: start; }
.user-form .form-actions { margin-top: 4px; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
.row-actions > a, .row-actions form { margin: 0; flex: 1 1 auto; }
.row-actions .btn { white-space: nowrap; }

/* =========================================================
   Breakpoints
   ======================================================= */
@media (min-width: 640px) {
  .user-add .btn { width: auto; min-width: 170px; justify-self: start; }
  .filters-form { grid-template-columns: repeat(2, 1fr); }
  .filters-form .field-wide { grid-column: 1 / -1; }
  .phone-search { grid-template-columns: 1fr 1fr; }
  .form-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid .field-wide { grid-column: 1 / -1; }
  .details > div { grid-template-columns: 160px 1fr; align-items: baseline; }
  .card { padding: 22px; }
  .page-actions .btn { flex: 0 0 auto; }
  .form-actions { justify-content: flex-start; position: static; background: none; }
  .form-actions .btn, .form-actions .btn-primary { flex: 0 0 auto; min-width: 160px; }
}

@media (min-width: 900px) {
  .mainnav { order: 0; flex-basis: auto; margin: 0; }
  .topbar { flex-wrap: nowrap; }

  /* desktop: the drawer's content sits inline in the top bar */
  .nav-toggle, .drawer-head, .drawer-backdrop { display: none; }
  .topbar-brand { margin-inline-start: 0; }
  .drawer, [dir="ltr"] .drawer {
    display: contents;
    position: static; transform: none; visibility: visible;
  }
  .drawer .mainnav { flex-direction: row; }
  .drawer .mainnav a {
    min-height: 40px; padding: 8px 14px; border-radius: 999px; font-size: inherit; color: var(--text-muted);
  }
  .drawer .mainnav a:hover { color: var(--text); }
  .drawer .mainnav a.active { color: var(--brand-teal); box-shadow: none; }
  .drawer .topbar-user { margin: 0; padding: 0; border: 0; }
  .drawer .topbar-user .user-name, .drawer .topbar-user .badge { display: inline; }
  .drawer .topbar-user form, .drawer .topbar-user .btn { width: auto; }
  .drawer .topbar-user .btn { min-height: 36px; }
  body.nav-open { overflow: visible; }
  .filters-form { grid-template-columns: repeat(4, 1fr); }
  .filters-form .field-wide { grid-column: span 2; }
  .phone-search { grid-template-columns: repeat(4, 1fr); }
  .detail-grid { grid-template-columns: 2fr 1fr; align-items: start; }

  /* real table on wide screens */
  .table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow-x: auto;
  }
  .data-table thead { display: table-header-group; }
  .data-table tr { display: table-row; border: 0; border-radius: 0; padding: 0; margin: 0; background: none; }
  .data-table th, .data-table td {
    display: table-cell;
    padding: 12px 14px;
    text-align: start;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
  }
  .data-table th { font-size: .85rem; color: var(--text-muted); font-weight: 700; background: var(--bg); white-space: nowrap; }
  .data-table td:last-child { border-bottom: 1px solid var(--border); }
  .data-table tbody tr:last-child td { border-bottom: 0; }
  .data-table tbody tr:hover { background: var(--bg); }
  .data-table td::before { content: none; }
  .data-table td > * { text-align: start; }
  .data-table td.cell-action { padding-top: 12px; width: 1%; }
  .data-table td.cell-action .btn { width: auto; }
  .row-actions { flex-wrap: nowrap; justify-content: flex-end; }
  .row-actions > a, .row-actions form { flex: 0 0 auto; }
  .data-table td.cell-clip { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* =========================================================
   Breakpoints (auth + dashboard)
   ======================================================= */
@media (min-width: 480px) {
  .auth-card { padding: 36px 32px; }
  .brand-logo { width: 220px; }
  .auth-title { font-size: 1.5rem; }
  .stats { grid-template-columns: repeat(2, 1fr); }
}

@media (min-width: 768px) {
  .container { padding-top: 32px; }
  .page-title { font-size: 1.7rem; }
  .topbar-logo { width: 130px; }
}

/* Very small phones (e.g. iPhone SE 1st gen, 320px) */
@media (max-width: 340px) {
  .auth-card { padding: 22px 14px; border-radius: 12px; }
  .brand-logo { width: 150px; }
  .auth-title { font-size: 1.2rem; }
}

/* Short landscape screens (phones turned sideways) */
@media (max-height: 520px) and (orientation: landscape) {
  .auth-wrap { justify-content: flex-start; }
  .brand { margin-bottom: 10px; }
  .brand-logo { width: 140px; }
  .auth-subtitle { margin-bottom: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation-duration: .01ms !important; }
  .spinner, .loader { animation-duration: 1.6s !important; } /* keep progress visible */
}

@media (forced-colors: active) {
  .btn-primary { border: 2px solid ButtonText; }
}
