/* Ain Ghazal Water — mobile-first stylesheet. No framework, no build step. */

:root {
  /* Blue and red from the logo. Blue carries every action; red is kept to
     brand touches, so it is never mistaken for a destructive button. */
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-alt: #edf1f6;
  --border: #d7dee7;
  --text: #121a24;
  --text-dim: #586474;
  --accent: #0b5fb0;
  --accent-text: #ffffff;
  --accent-soft: #e2eefa;
  --brand-red: #d7262e;
  --danger: #b4231f;
  --danger-soft: #fdecec;
  --ok: #156b47;
  --ok-soft: #e4f3ea;
  --radius: 12px;
  --radius-sm: 9px;
  --gutter: 16px;
  --tap: 46px;
  --shadow: 0 1px 2px rgba(15, 25, 35, .06), 0 1px 10px rgba(15, 25, 35, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11161d;
    --surface: #19202a;
    --surface-alt: #222b37;
    --border: #313c4a;
    --text: #e8ecf1;
    --text-dim: #98a4b3;
    --accent: #5cb4f2;
    --accent-text: #061a30;
    --accent-soft: #15304a;
    --brand-red: #ff5c61;
    --danger: #f98b86;
    --danger-soft: #3a2020;
    --ok: #7ddba4;
    --ok-soft: #1c3127;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  /* Stops the rubber-band scroll from showing a different colour behind the page. */
  overscroll-behavior-y: none;
}

h1 { font-size: 1.4rem; line-height: 1.25; margin: 0 0 .5rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 1.75rem 0 .6rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent); }
code { font-size: .85em; background: var(--surface-alt); padding: .1em .35em; border-radius: 4px; }
hr.rule { border: 0; border-top: 1px solid var(--border); margin: 2rem 0 0; }

/* --- app bar --- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  /* A red rule along the top, like the band under the drops in the logo. */
  border-top: 3px solid var(--brand-red);
  padding-top: env(safe-area-inset-top);
}

.appbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 var(--gutter);
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 1.02rem;
  color: var(--text);
  text-decoration: none;
}

.brand-mark { width: 30px; height: 30px; flex: none; }

.brand { min-width: 0; }
.brand-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* The language switcher and sign-out share one row, however narrow the screen. */
.appbar-tools { display: flex; flex: none; flex-wrap: nowrap; align-items: center; gap: 10px; }
.appbar-tools form { margin: 0; }
.appbar-tools .btn-quiet { white-space: nowrap; }

/* A two-way segmented control: a flag and short name per language. */
.lang-switch {
  display: inline-flex;
  align-items: center;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-alt);
}

.lang-opt {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: .82rem;
  font-weight: 600;
  line-height: 1;
  color: var(--text-dim);
  text-decoration: none;
  white-space: nowrap;
}

.lang-opt.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgb(0 0 0 / .12);
}

a.lang-opt:hover { color: var(--text); }

/* On narrow phones the flags alone carry it; the name stays for screen readers. */
.signout { display: inline-flex; align-items: center; gap: 6px; }
.signout svg { width: 20px; height: 20px; flex: none; }
/* The arrow points out of the door in reading order. */
[dir="rtl"] .signout svg { transform: scaleX(-1); }

/* The app bar shares its row with the name, so there the switcher shows flags
   alone, and sign-out is an icon until the screen has room for its label.
   Hidden labels stay readable to screen readers. */
.appbar .lang-opt { padding: 0 8px; }
.appbar .lang-label,
.signout-label {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

@media (min-width: 480px) {
  .signout-label { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
}

.flag {
  width: 21px;
  height: 14px;
  flex: none;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgb(0 0 0 / .12);
}

/* Signed out there is no app bar, so the switcher sits in the top corner. */
.lang-corner {
  display: flex;
  justify-content: flex-end;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 0;
}

/* --- page shell --- */

.page {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px var(--gutter) 32px;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

body.has-tabbar .page { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }

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

.page-head h1 { margin: 0; }
.section-title { font-size: 1rem; color: var(--text-dim); }

/* --- bottom tab bar (admins) --- */

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 58px;
  font-size: .72rem;
  font-weight: 500;
  color: var(--text-dim);
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.tab svg { width: 23px; height: 23px; }
.tab.is-active { color: var(--accent); }

/* --- flash --- */

.flash {
  border-radius: var(--radius-sm);
  padding: 11px 13px;
  margin-bottom: 16px;
  font-size: .92rem;
  border: 1px solid transparent;
}

.flash-ok { background: var(--ok-soft); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }

/* --- buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: .95rem;
  text-decoration: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.btn svg { width: 19px; height: 19px; flex: none; }
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-quiet { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }
.btn-block { width: 100%; }
.btn-sm { min-height: 38px; padding: 0 14px; font-size: .88rem; }
.btn:active { filter: brightness(.94); }

/* Text-only buttons: the sign-out control and the picker tools. */
button.btn-quiet:not(.btn), .btn-xs {
  background: none;
  border: 0;
  padding: 6px 2px;
  font: inherit;
  font-size: .88rem;
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
}

.btn-xs { font-size: .82rem; }
.appbar button.btn-quiet { min-height: var(--tap); }

/* --- forms --- */

.stack { display: flex; flex-direction: column; gap: 16px; }

/* The address parts, grouped under one heading. */
.address-group { display: flex; flex-direction: column; gap: 12px; margin: 0; padding: 14px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); min-width: 0; }
.group-label { padding: 0 6px; margin-inline-start: -6px; font-size: .9rem; font-weight: 600; color: var(--text); }
.field-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field-label { font-size: .82rem; font-weight: 600; color: var(--text-dim); letter-spacing: .01em; padding: 0; }
.field-hint { font-size: .8rem; color: var(--text-dim); line-height: 1.45; }
.field-error { font-size: .82rem; color: var(--danger); font-weight: 500; }

input[type="text"], input[type="email"], input[type="password"],
input[type="tel"], input[type="search"], textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  /* 16px keeps iOS Safari from zooming in when a field is focused. */
  font: inherit;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

textarea { resize: vertical; line-height: 1.45; }

input:focus-visible, textarea:focus-visible, .btn:focus-visible,
button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Radio and checkbox rows, sized for thumbs. */
.choice, .check {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
}

.choice { margin-bottom: 8px; }
.choice input, .check input { width: 20px; height: 20px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
.choice span, .check span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.choice small, .check small { color: var(--text-dim); font-size: .82rem; line-height: 1.4; }
.choice:has(input:checked), .check:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
}

/* The checkbox list is irrelevant while "all contacts" is selected. */
.picker[hidden] { display: none; }

.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; min-width: 0; }
.search .btn { flex: none; }

/* --- lists --- */

.card-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.card-list > li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.contact-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 13px;
  min-height: 62px;
  color: inherit;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}

.contact-row:active { background: var(--surface-alt); }
.contact-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1; }
.contact-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.contact-meta {
  font-size: .84rem;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chevron { width: 18px; height: 18px; flex: none; color: var(--text-dim); opacity: .7; }

.row-action {
  display: block;
  border-top: 1px solid var(--border);
  padding: 11px 13px;
  font-size: .88rem;
  font-weight: 500;
  text-decoration: none;
  background: var(--surface-alt);
}

.avatar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: .85rem;
  font-weight: 700;
  letter-spacing: .02em;
}

.avatar-lg { width: 60px; height: 60px; font-size: 1.25rem; }

.list-count { margin: 12px 0 0; font-size: .8rem; color: var(--text-dim); text-align: center; }

.check-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.picker-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.picker-tools { display: flex; gap: 12px; }

.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 99px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-dim);
  vertical-align: 1px;
}

.tag-admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.tag-you { background: var(--accent); color: var(--accent-text); border-color: transparent; }

/* --- detail --- */

.backlink {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 14px;
  min-height: 38px;
  font-size: .92rem;
  font-weight: 500;
  text-decoration: none;
}

.backlink svg { width: 17px; height: 17px; }

.detail-head { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 10px; margin-bottom: 22px; }
.detail-head h1 { margin: 0; }
.detail-sub { margin: 0; color: var(--text-dim); font-size: .95rem; }

.facts {
  margin: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.facts { display: flex; flex-wrap: wrap; }
.fact { flex: 1 0 100%; min-width: 0; padding: 13px; }
.fact + .fact { border-top: 1px solid var(--border); }
/* Building, floor and apartment sit side by side. */
.fact-short { flex: 1 1 0; }
.fact-short + .fact-short { border-inline-start: 1px solid var(--border); }
.fact dt { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-dim); }
.fact dd { margin: 4px 0 0; }
.pre-line { white-space: pre-line; }
.breakable { overflow-wrap: anywhere; font-size: .9rem; color: var(--text-dim); }

.actions { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.timestamps { margin-top: 18px; font-size: .78rem; color: var(--text-dim); text-align: center; }

/* --- empty states & auth --- */

.empty {
  text-align: center;
  padding: 36px 18px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
}

.empty .btn { margin-top: 10px; }
.empty-hint { font-size: .88rem; color: var(--text-dim); }
.empty-page { border-style: solid; }
.empty-page h1 { color: var(--text); }
.error-code { font-size: 2.2rem; font-weight: 700; color: var(--accent); margin: 0; line-height: 1; }

.auth { max-width: 380px; margin: 6vh auto 0; text-align: center; }
.auth h1 { margin-bottom: .25rem; color: var(--brand-red); }
.auth-sub { color: var(--text-dim); margin-bottom: 1.5rem; }
.auth .stack { text-align: start; }
.auth .field-label { font-size: .85rem; }
.auth-mark { color: var(--accent); margin-bottom: 6px; }
.auth-mark img { display: block; width: 96px; height: 96px; margin: 0 auto; }

/* Call and Map sit side by side: both are one-thumb actions on a phone. */
.quick-actions { display: flex; gap: 10px; margin-bottom: 20px; }
.quick-actions .btn { flex: 1; min-width: 0; }

/* Tabular figures keep a column of numbers from looking ragged. */
.contact-phone { font-variant-numeric: tabular-nums; }

.fact dd a { text-decoration: none; font-weight: 500; }

/* --- import / export --- */

.toolbar { display: flex; gap: 8px; margin-bottom: 16px; }
.toolbar .btn { flex: 1; }

/* The file input is the one control browsers style themselves, so it gets the
   field border and a comfortable height rather than a full restyle. */
input[type="file"] {
  width: 100%;
  min-height: var(--tap);
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: .92rem;
}

input[type="file"]::file-selector-button {
  margin-inline-end: 10px;
  padding: 7px 12px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: var(--accent-text);
  font: inherit;
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
}

.problems {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  margin-bottom: 18px;
  font-size: .9rem;
}

.problems-head { margin: 0 0 8px; font-weight: 600; color: var(--danger); }
.problems ul { margin: 0; padding-inline-start: 20px; display: flex; flex-direction: column; gap: 4px; }
.problems li { color: var(--text); }

/* Narrow screens scroll the format table sideways rather than squeezing it. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin-bottom: 14px; }

.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.grid th, .grid td { padding: 9px 11px; text-align: start; border-bottom: 1px solid var(--border); }
.grid th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid td:first-child { white-space: nowrap; }

/* --- right-to-left (Arabic) ---
   Layout uses logical properties, so mostly only the arrows need flipping.
   Letter-spacing pulls apart Arabic's joined letters and uppercase means
   nothing to it, so both are dropped. */

/* Phone numbers, emails, links and names in Latin script are marked dir=ltr
   or dir=auto so they read correctly, but they still line up with the page. */
[dir="rtl"] [dir="ltr"],
[dir="rtl"] [dir="auto"] { text-align: right; }

[dir="rtl"] .chevron,
[dir="rtl"] .backlink svg { transform: scaleX(-1); }

[dir="rtl"] h1,
[dir="rtl"] .field-label,
[dir="rtl"] .fact dt,
[dir="rtl"] .grid th { letter-spacing: normal; text-transform: none; }

/* Column names and examples are code and read left to right inside Arabic text. */
code { direction: ltr; unicode-bidi: isolate; }

@media (min-width: 560px) {
  .page { padding-top: 26px; }
  h1 { font-size: 1.6rem; }
  .actions { flex-direction: row; }
  .actions > * { flex: 1; }
}
