/* One stylesheet for both apps. No framework.
   Layout: the map fills the page; a search box and one card float over it. Every section says how things look,
   except the last, "layouts", which alone says where they stand: on a wide screen the card is at the side, on a
   phone held upright it is a sheet at the bottom of the screen, on a phone held sideways it is at the side again.
   Arabic is right-to-left, so sides are written as "inline-start / inline-end"
   and the same rules work in either direction.
   Each page says which app it is: <body class="staff"> or <body class="public">.

   Contents, in order (search for a heading to jump to it):
     ---------- settings: change the look here ----------   colours, text sizes, corners, widths
     ---------- the font ----------                          the one font, shipped with the app
     ---------- the page ----------                          body text, titles, links
     ---------- the map page ----------                      the search box, the card, the buttons over the map, the legend
     ---------- inside the card ----------                   rows, pills, buttons, lists, parts, the steps strip
     ---------- forms ----------                             fields, chips to choose from, stars
     ---------- plain pages (log-in) ----------              the staff log-in pages
     ---------- map furniture ----------                     dots, names and drawing corners over the map
     ---------- public app: category chips, the near list, reviews ----------
     ---------- the map key, for both apps ----------         «مفتاح الخريطة»: what each thing on the map is
     ---------- public app: the near list's ×, the vendor's call ----------
     ---------- layouts: where things stand on the screen ----------   a wide screen, a phone upright, a phone sideways */

/* ---------- settings: change the look here ----------
   Every colour of both apps is here, the map's too: layers.js and public/map.js read theirs from these lines
   (cssColour), so write a colour the map can read: #rrggbb. */

:root {
    --ink: #1d1d1f;          /* text */
    --ink-2: #6e6e73;        /* labels, secondary text */
    --line: #e3e3e6;         /* hairlines */
    --paper: #ffffff;        /* the card */
    --wash: #f2f2f4;         /* fields, quiet buttons */
    --blue: #0a66d8;         /* the selected thing and the main action, on the page and on the map */
    --blue-wash: #e3eefc;    /* behind a chosen chip: a light --blue, to change with it */
    --blue-halo: color-mix(in srgb, var(--blue) 20%, transparent);   /* --blue, faint: the ring around the "موقعي" dot */
    --gold: #f5a623;         /* rating stars */
    --green: #1a7f37;        /* status only: a valid permit, «سارية», on the page and on the map */
    --amber: #9a6700;        /* status only: ending soon, «تنتهي قريباً» */
    --red: #c62828;          /* status and errors only: expired, cancelled, unpaid */
    --grey: #86868b;         /* a paid violation and a zone's outline, on the staff map */
    --green-wash: #e6f4ea;   /* behind green words (a pill, «صدرت الإجازة.»): a light --green */
    --amber-wash: #fff4d6;   /* behind amber words: a light --amber */
    --red-wash: #fdeaea;     /* behind red words (a pill, an error): a light --red */
    --map-edge: #ffffff;     /* the white edge around the shapes and dots on the map, so they show on both base maps */
    --zone-name: rgba(255, 255, 255, 0.85);   /* behind a zone's name on the staff map */
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.14);

    --text: 16px;            /* body text: buttons, fields, list rows (16px also stops phones zooming into a field) */
    --text-title: 22px;      /* a card's title (h1) */
    --text-heading: 17px;    /* a part's heading in a card (h2) */
    --text-row: 15px;        /* a card's rows and facts, its notes, «تعديل» buttons, the category chips */
    --text-small: 14px;      /* labels, a card's subtitle, pills, the buttons over the map, errors */
    --text-tiny: 13px;       /* the line over a card's title, the legend, hints, a review's date, a zone's name */

    --radius-card: 16px;     /* the card, and the log-in page's panel */
    --radius: 12px;          /* everything else with corners: fields, buttons, photos */
    --gap: 12px;             /* between the edge of the screen and what floats over the map */
    --card-width: 380px;     /* the card on a wide screen, and the search box and the category chips above it */
    --card-width-sideways: min(var(--card-width), 50vw);   /* the same, held sideways: half the screen at most */
    --search-height: 48px;   /* the search box over the map */
    --tap: 44px;             /* smallest height of anything tappable */
    --sheet-height: 72dvh;   /* the card on a phone held upright, a sheet at the bottom: at most this tall */
    --sheet-short: 50dvh;    /* a short sheet, which leaves half the map in view */
    /* Which screen is a phone, held which way: the two numbers are in the last section, "layouts". */
}

/* ---------- the font ----------
   One font, shipped with the app, so every phone and computer shows the same letters.
   IBM Plex Sans Arabic (open licence, SIL OFL). Two weights only: 400 and 700. */
@font-face {
    font-family: "Plex Arabic";
    src: url("fonts/IBMPlexSansArabic-Regular.ttf") format("truetype");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "Plex Arabic";
    src: url("fonts/IBMPlexSansArabic-Bold.ttf") format("truetype");
    font-weight: 700;
    font-display: swap;
}

/* ---------- the page ---------- */

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    font-family: "Plex Arabic", Tahoma, sans-serif;
    font-size: var(--text);
    line-height: 1.5;
    color: var(--ink);
    background: var(--wash);
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: var(--text-title); font-weight: 700; line-height: 1.3; }
h2 { font-size: var(--text-heading); font-weight: 700; }
a { color: var(--blue); text-decoration: none; }
[hidden] { display: none !important; }

/* ---------- the map page ----------
   How the map, the search box, the card, the buttons over the map and the legend look. Where each of them stands
   on the screen (its top, sides, width, height) is written in the last section, "layouts". */

/* font-family: the map library's own CSS sets Helvetica on the map; inherit gives the zone names, the "+"
   markers and the map's credits inside it the page's font */
#map { position: fixed; font-family: inherit; }

.search { position: fixed; z-index: 3; }
.search input {
    width: 100%;
    height: var(--search-height);
    padding: 0 16px;
    border: 0;
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
    font: inherit;
}
.search-results {              /* the list under the search box */
    margin-top: 6px;
    background: var(--paper);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-height: 50vh;
    overflow-y: auto;
}

.card {
    position: fixed;
    z-index: 2;
    display: flex;
    flex-direction: column;
    background: var(--paper);
    border-radius: var(--radius-card);
    box-shadow: var(--shadow);
    overflow: hidden;
}
.card-head {                   /* a photo (if any), title and subtitle, the close or back button */
    display: flex;
    flex-wrap: wrap;           /* a step card's strip of steps (.steps) takes a row of its own, above the rest */
    align-items: flex-start;
    gap: 8px;
    padding: 16px 16px 8px;
}
.card-head .titles { flex: 1; min-width: 0; }
.card-head .sub { color: var(--ink-2); font-size: var(--text-small); }
/* over the title, what the card is about: «بائع», «منطقة بيع», or what its form works on (html.php, kind).
   Plain grey words, so that it is never taken for a state (those are pills) */
.kind { font-size: var(--text-tiny); color: var(--ink-2); }
.card-body { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }   /* what scrolls (held sideways: the whole card) */
.card-foot {                   /* the actions: always visible, never scrolled away */
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 12px 16px 16px;
    border-top: 1px solid var(--line);
}
/* a footer whose buttons are all hidden for now (a drawing card before anything is drawn) takes no room */
.card-foot:not(:has(.btn:not([hidden]))) { display: none; }

.close, .back {
    min-width: var(--tap);
    height: var(--tap);
    padding: 0 14px;
    border: 0;
    border-radius: 999px;
    background: var(--wash);
    color: var(--ink-2);
    font: inherit;
    cursor: pointer;
}

/* buttons over the map: always a word, never only a symbol */
.mapbar {
    position: fixed;
    z-index: 1;
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.mapbar button, .mapbar a {
    min-height: var(--tap);
    padding: 0 14px;
    border: 0;
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
    color: var(--ink);
    font: inherit;
    font-size: var(--text-small);
    text-align: center;
    line-height: var(--tap);
    cursor: pointer;
}
.mapbar .is-on { color: var(--blue); font-weight: 700; }
.mapbar .main { background: var(--blue); color: var(--paper); font-weight: 700; }   /* the staff's "بائع جديد" */
/* blue only while the map is alone: an open card's own main button is then the one blue button */
body:has(#card:not([hidden])) .mapbar .main { background: var(--paper); color: var(--blue); }

/* what the colours of the vendors' places mean (staff map). Where it stands is in the layouts: on a wide screen
   always in sight, at the bottom of the map's free side; on a phone only while "التفاصيل" shows the layer buttons. */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 14px;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
    font-size: var(--text-tiny);
    color: var(--ink-2);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 12px; height: 12px; border-radius: 50%; }
.legend .ok { background: var(--green); }
.legend .soon { background: var(--amber); }
.legend .bad { background: var(--red); }
.legend .open { background: var(--blue); }

/* ---------- inside the card ---------- */

.rows { margin: 12px 0; }
.row {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    font-size: var(--text-row);
}
.row:last-child { border-bottom: 1px solid var(--line); }
.row .label { color: var(--ink-2); flex-shrink: 0; }
.row .value { text-align: end; overflow-wrap: anywhere; }

.pill {
    display: inline-block;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: var(--text-small);
    font-weight: 700;
    background: var(--wash);
    color: var(--ink-2);
}
.pill.ok { background: var(--green-wash); color: var(--green); }
.pill.warn { background: var(--amber-wash); color: var(--amber); }
.pill.bad { background: var(--red-wash); color: var(--red); }
.pill.big { font-size: 18px; padding: 8px 18px; }   /* the card's answer at a glance, readable in sunlight */
.pills { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }   /* a big pill and a small one beside it */

/* a person's or a review's photo, small: tapping it opens the file */
.avatar { display: block; flex: none; width: 96px; height: 96px; object-fit: cover; border-radius: var(--radius); background: var(--wash); }
/* a photo the width of the card */
.photo { display: block; width: 100%; height: 200px; object-fit: cover; border-radius: var(--radius); background: var(--wash); }

.btn {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: 0 16px;
    border: 0;
    border-radius: var(--radius);
    background: var(--wash);
    color: var(--ink);
    font: inherit;
    font-weight: 700;
    text-align: center;
    line-height: 48px;
    cursor: pointer;
}
.btn.main { background: var(--blue); color: var(--paper); }   /* one per card */
.btn.danger { color: var(--red); }
.btn[disabled] { opacity: 0.6; cursor: wait; }        /* only while saving */
.btn-row { display: flex; gap: 8px; }
.btn-row .btn { flex: 1; }
/* a button inside a part of the card, for that part: «تعديل», «إضافة مركبة». Blue words that recede behind the
   facts, still a finger's height; the padding sticks out past the part's edge, so the words line up with the text */
.btn.small {
    display: inline-block;
    width: auto;
    flex: none;
    min-height: var(--tap);
    margin-inline-start: -12px;
    padding: 0 12px;
    background: none;
    color: var(--blue);
    font-size: var(--text-row);
    font-weight: 400;
    line-height: var(--tap);
}
.fact .btn.small { margin-inline: 0 -12px; }   /* at the end of its row */
.btn.small.danger { color: var(--red); }   /* a small «حذف» (the governorates' list) */

/* The steps of registering a new vendor, a strip across the top of a step card (html.php, steps_line): one equal
   column per step (NEW_VENDOR_STEPS), each a thin bar with the step's name under it. Done: a green bar and ✓;
   this step: blue. */
.steps { flex-basis: 100%; }
.steps ol {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: 1fr;
    gap: 6px;
    margin: 8px 0 4px;
    padding: 0;
    list-style: none;
    font-size: 12px;
    color: var(--ink-2);
    text-align: center;
}
.steps li::before { content: ""; display: block; height: 4px; margin-bottom: 4px; border-radius: 2px; background: var(--line); }
.steps .done::before { background: var(--green); }
.steps .now::before { background: var(--blue); }
.steps .now { color: var(--blue); font-weight: 700; }

.list a, .list button {        /* search results, reports, pick-one lists */
    display: block;
    width: 100%;
    min-height: var(--tap);
    padding: 10px 16px;
    border: 0;
    border-top: 1px solid var(--line);
    background: none;
    color: var(--ink);
    font: inherit;
    text-align: start;
    cursor: pointer;
}
.list a:first-child, .list button:first-child { border-top: 0; }
.list .sub { display: block; color: var(--ink-2); font-size: var(--text-small); }
.list .side { float: inline-end; margin-inline-start: 12px; color: var(--ink-2); font-size: var(--text-small); }   /* at a row's end: a distance, a state */
.list a:hover, .list button:hover, .list .is-active { background: var(--wash); }

.empty { padding: 24px 0; color: var(--ink-2); text-align: center; }

/* A card in titled parts: <section class="part"><h2>الإجازة</h2> … </section> */
.part { margin-top: 32px; }
.part:first-child { margin-top: 8px; }
.part > h2 { margin-bottom: 8px; font-size: var(--text-heading); }
.part .rows { margin: 8px 0; }
.part .pills { margin: 8px 0; }
.note { margin: 8px 0; color: var(--ink-2); font-size: var(--text-row); }   /* a sentence in a card: what to do next, or to know */
.done-note {                   /* what the step before has just saved: «صدرت الإجازة.» */
    margin: 8px 0 12px;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--green-wash);
    color: var(--green);
    font-size: var(--text-row);
}

/* The place step's answer (staff place.js): the zone, its monthly fee and how full it is; red when the database
   would not take a permit on the place */
.answer {
    margin: 12px 0;
    padding: 10px 12px;
    border-radius: var(--radius);
    background: var(--wash);
    font-size: var(--text-row);
}
.answer.is-bad { background: var(--red-wash); color: var(--red); }

/* A group of facts with its own «تعديل» beside it (the vendor card) */
.fact {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
    border-top: 1px solid var(--line);
    font-size: var(--text-row);
}
.fact:last-child { border-bottom: 1px solid var(--line); }
.fact .text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.fact .label { display: block; color: var(--ink-2); font-size: var(--text-small); }
.fact .sub { display: block; color: var(--ink-2); font-size: var(--text-small); }   /* a grey line under it: a governorate's zones */

/* A permit's own buttons, under it (the vendor card): «تسجيل الدفع», «إلغاء الإجازة» */
.part .btn-row { margin: 8px 0; }

/* A permit in «الإجازات الأخرى» (the vendor card): its place, then its dates and state in grey, then its buttons */
.permit {
    padding: 10px 0;
    border-top: 1px solid var(--line);
    font-size: var(--text-row);
}
.permit:last-child { border-bottom: 1px solid var(--line); }
.permit .sub { display: block; color: var(--ink-2); font-size: var(--text-small); }

.history summary { padding: 12px 0; color: var(--ink-2); cursor: pointer; }   /* a folded list: a category's subcategories */

.review { padding: 12px 0; border-top: 1px solid var(--line); }
.review .sub { color: var(--ink-2); font-size: var(--text-tiny); }
.review .photo, .review .avatar { margin-top: 8px; }
.rating { color: var(--gold); letter-spacing: 1px; }   /* a review's stars, read-only, filled from the right */

/* ---------- forms ---------- */

.field { display: block; margin: 14px 0; }
.field > span { display: block; margin-bottom: 4px; font-size: var(--text-small); color: var(--ink-2); }
.field input, .field select, .field textarea {
    width: 100%;
    min-height: 48px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: var(--wash);
    color: var(--ink);
    font: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus,
.search input:focus, .btn:focus-visible, .list a:focus-visible, .list button:focus-visible {
    outline: 2px solid var(--blue);
    outline-offset: 1px;
}
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--red); }
.field .error, .form-error { color: var(--red); font-size: var(--text-small); margin-top: 4px; }
.form-error { padding: 10px 12px; border-radius: var(--radius); background: var(--red-wash); margin: 12px 0; }
.field .hint { color: var(--ink-2); font-size: var(--text-tiny); margin-top: 4px; }
.field .avatar { margin-bottom: 8px; }
/* A phone number: a fixed +964, then the rest of the number, typed left to right (7701234567):
   <span class="phone"><b>+964</b><input name="phone" …></span> */
.field > .phone { display: flex; gap: 8px; direction: ltr; margin-bottom: 0; font-size: inherit; color: inherit; }
.phone b {
    display: flex;
    align-items: center;
    padding: 0 12px;
    border-radius: var(--radius);
    background: var(--wash);
    color: var(--ink-2);
    font-weight: 400;
}
.phone input { flex: 1; min-width: 0; }
.field-pair { display: flex; gap: 8px; }
.field-pair .field { flex: 1; }

.choices { display: flex; flex-wrap: wrap; gap: 8px; }   /* pick one or several: big tappable chips */
.choices label {
    position: relative;        /* keeps the hidden input inside its chip: in a scrolled card it would otherwise
                                  sit, unseen, over the buttons below */
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 0 14px;
    border-radius: 999px;
    background: var(--wash);
    cursor: pointer;
}
.choices input { position: absolute; opacity: 0; }
.choices input:checked + span { color: var(--blue); font-weight: 700; }
.choices label:has(input:checked) { background: var(--blue-wash); }
.choices label:has(input:focus-visible) { outline: 2px solid var(--blue); }

.stars { display: flex; gap: 4px; }   /* right to left like the page: the first star is at the right */
.stars button {
    width: var(--tap); height: var(--tap);
    border: 0; background: none; font: inherit; font-size: 30px; line-height: 1;
    color: var(--line); cursor: pointer;
}
.stars button.is-on { color: var(--gold); }

.btn .file { position: absolute; width: 1px; height: 1px; opacity: 0; }   /* a file input inside a button that says, in Arabic, what it does */
.btn:has(.file:focus-visible) { outline: 2px solid var(--blue); }

/* ---------- plain pages (log-in) ---------- */

.page { max-width: 420px; margin: 0 auto; padding: 48px 16px; }
.page .card-like { background: var(--paper); border-radius: var(--radius-card); padding: 24px; box-shadow: var(--shadow); }
.page .btn + .btn { margin-top: 8px; }   /* buttons one under the other: the staff log-in code's "دخول", "إرسال رمز جديد" */

/* ---------- map furniture ---------- */

.me {                           /* the person's own GPS position: the citizen's, or the staff member's "موقعي" */
    width: 18px; height: 18px; border-radius: 50%;
    background: var(--blue); border: 3px solid var(--map-edge); box-shadow: 0 0 0 6px var(--blue-halo);
}
.zone-label {                   /* a zone's name on the staff map; clicks pass through to the map */
    padding: 2px 10px; border-radius: 999px; background: var(--zone-name);
    color: var(--ink-2); font-size: var(--text-tiny); white-space: nowrap; pointer-events: none;
}
.shape-label {                  /* the name of the open card's place, over its blue shape (staff map) */
    padding: 4px 12px; border-radius: 999px; background: var(--blue); box-shadow: var(--shadow);
    color: var(--paper); font-size: var(--text-small); font-weight: 700; white-space: nowrap; pointer-events: none;
    overflow: hidden; text-overflow: ellipsis;   /* "…" when longer than the free part of the map (map.js, keepLabelInSight) */
}
.dot {                          /* where a violation is recorded; the inspector can drag it */
    width: 24px; height: 24px; border-radius: 50%;
    background: var(--red); border: 3px solid var(--map-edge); box-shadow: var(--shadow); cursor: grab;
}
.corner {                       /* a draggable corner while drawing */
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--paper); border: 3px solid var(--blue); cursor: grab;
}
.corner.is-on { background: var(--blue); }   /* the corner just tapped, which "حذف الزاوية" removes */
.plus {                         /* "add a corner here", in the middle of an edge */
    width: 20px; height: 20px; border-radius: 50%;
    background: var(--blue); color: var(--paper); font-size: 16px; line-height: 20px;
    text-align: center; opacity: 0.75; cursor: pointer;
}
@media (pointer: coarse) {
    .corner, .plus { width: 32px; height: 32px; line-height: 32px; }   /* big enough for a finger to grab */
}
.draw-hint {                    /* one line telling the user what the next click does; where: the layouts */
    position: fixed; z-index: 3;
    width: max-content;         /* one line where it fits: with left: 50% alone it would wrap at half the screen */
    padding: 8px 16px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: var(--text-small);
}

/* ---------- public app: category chips, the near list, reviews ---------- */

.chips {                        /* categories under the search box, one row that scrolls sideways; where: the layouts */
    position: fixed;
    z-index: 2;
    display: flex;
    gap: 8px;
    padding: 6px 2px 10px;      /* room for the chips' shadow, which the scrolling row would cut off */
    overflow-x: auto;
    scrollbar-width: none;      /* scrolled by finger, trackpad or mouse wheel (search.js), with no scrollbar */
}
.chips::-webkit-scrollbar { display: none; }   /* the same for browsers that don't know scrollbar-width */
.chips button {
    flex: none;
    min-height: var(--tap);
    padding: 0 16px;
    border: 0;
    border-radius: 999px;
    background: var(--paper);
    box-shadow: var(--shadow);
    color: var(--ink);
    font: inherit;
    font-size: var(--text-row);
    cursor: pointer;
}
.chips .is-on { background: var(--blue-wash); color: var(--blue); font-weight: 700; }   /* the chosen filter */

/* the near list closed (its ×; public/card.js, closeNear): gone at every screen size, the whole map free, until
   «القريبون» over the map brings it back */
.near-closed .is-near { display: none; }

.reviews h2 { margin: 20px 0 4px; }

/* ---------- the map key, for both apps ----------
   «مفتاح الخريطة»: a button over the map opens and shuts a small list of what each thing on the map is, one row
   each, its shape then its words: <ul id="map-key" class="map-key"><li><i class="stall"></i>…</li></ul>, inside the
   buttons over the map (.mapbar). Its script is the part "the map key" of map.js. The shapes take the colours the
   map reads from :root (--ink, --blue, --map-edge), so a colour changed there changes here too. --key-line and
   --key-fill are how see-through a route and a region are drawn: keep them as the map's own at rest (public/map.js,
   AT_REST: line 0.45, fill 0.15). Where the key stands: the layouts. */
.map-key {
    --key-line: 45%;             /* a route, and a region's outline */
    --key-fill: 15%;             /* a region's inside */
    position: absolute;          /* placed against the buttons over the map (.mapbar), in the layouts */
    width: max-content;          /* each row on one line, where the screen allows */
    margin: 0;
    padding: 8px 12px;
    list-style: none;
    border-radius: var(--radius);
    background: var(--paper);
    box-shadow: var(--shadow);
    font-size: var(--text-small);
    overflow-y: auto;            /* on a very short screen it scrolls, rather than run past its room (the layouts) */
}
.map-key li {                    /* two columns: the shape, centred in 30px, then the words */
    display: grid;
    grid-template-columns: 30px auto;
    align-items: center;
    column-gap: 10px;
    min-height: 28px;
}
.map-key i { justify-self: center; }
.map-key .stall { width: 18px; height: 18px; border-radius: 50%; background: var(--ink); border: 2px solid var(--map-edge); }
.map-key .route { width: 28px; height: 4px; border-radius: 2px; background: color-mix(in srgb, var(--ink) var(--key-line), transparent); }
.map-key .region {
    width: 28px; height: 18px; border-radius: 4px;
    background: color-mix(in srgb, var(--ink) var(--key-fill), transparent);
    border: 2px solid color-mix(in srgb, var(--ink) var(--key-line), transparent);
}
.map-key .chosen { width: 28px; height: 5px; border-radius: 3px; background: var(--blue); }   /* the open card's place */
/* a row can also show one of the map's own dots: <i class="me"></i>, the person's position (---------- map furniture) */

/* ---------- public app: the near list's ×, the vendor's call ---------- */

/* the near list's ×: a round button the size of a fingertip */
.close.x { width: var(--tap); padding: 0; font-size: 24px; line-height: 1; }

/* «نداء البائع» on the vendor card: its words, then the browser's own play button, as wide as the card */
.call { margin: 12px 0; }
.call .label { display: block; margin-bottom: 4px; color: var(--ink-2); font-size: var(--text-small); }
.call audio { display: block; width: 100%; }

/* ---------- layouts: where things stand on the screen ----------
   Every section above says how things look. This one alone says where they stand, in three layouts, one block
   each. A block places every floating thing (the map, the search box, the citizens' category chips, the card, the
   buttons over the map, the staff legend, the map key, the map's credits, the drawing hint) for both
   apps, so a block is read
   on its own. Where a block changes a look from above (a sheet's corners, say), it wins: it comes later.
   Two numbers choose the layout, each written as a pair in the three @media lines (a variable can't go there):
     720px / 720.1px  a phone held upright is at most 720px wide; anything wider is a wide screen;
     500px / 500.1px  a phone held sideways is at most 500px tall, however wide; the two others are taller.
   The .1 means "just over" (browsers round .01 away): a zoomed browser can be 720.5px wide, and 721 would leave it no
   layout at all. The three conditions leave no screen out, and no screen meets two of them. Each block
   also sets --layout, which the scripts read (layout(), in staff/layers.js and public/map.js) to know where the
   card and the buttons are.

     a wide screen                    a phone held upright      a phone held sideways
     +------------------------------+ +--------------------+    +--------------------------------+
     | [button]          [ search ] | | [     search     ] |    | [button][button]   [ search  ] |
     | [button]          +--------+ | | [button][button]   |    | [button]           +---------+ |
     | [button]          |  card  | | |                    |    |                    |  card   | |
     |                   |        | | |        map         |    |        map         | scrolls | |
     |        map        |        | | |                    |    |                    | [b] [b] | |
     | [legend]          +--------+ | +--------------------+    |                    +---------+ |
     +------------------------------+ |  card: a sheet     |    +--------------------------------+
                                      +--------------------+
   (the staff app; the citizens' app has its category chips under the search box, and on a phone held upright its
   buttons just above the sheet) */

/* ----- a wide screen: the card at the side ----- */
@media (min-width: 720.1px) and (min-height: 500.1px) {
    :root { --layout: wide; }   /* the scripts read it: layout() */
    /* the sides: the card, the search box and the category chips at the start of a line, the right in Arabic; the
       buttons over the map and the legend at its end, the left. To swap the two sides, swap "start" and "end" in
       these three rules: the map measures where the card and the buttons are (map.js, freePadding). The third:
       the map key hangs under the buttons, lined up with their outer edge */
    .search, .chips, .card { inset-inline-start: var(--gap); }
    .mapbar, .legend { inset-inline-end: var(--gap); }
    .map-key { inset-inline-end: 0; }

    #map { inset: 0; }
    .search { top: var(--gap); width: var(--card-width); }
    .chips { top: calc(var(--search-height) + var(--gap)); width: var(--card-width); }   /* under the search box */
    .card {
        top: calc(var(--search-height) + 2 * var(--gap));   /* under the search box */
        bottom: calc(var(--gap) + 20px);   /* under it, the map's credits: one line, 20px high (the map library's CSS) */
        width: var(--card-width);
    }
    /* the citizens' card starts under the chips (16px: the chips row's padding) */
    .public .card { top: calc(var(--search-height) + var(--tap) + 16px + 2 * var(--gap)); }
    /* a short card (.is-fit): as tall as what it holds, its buttons right under it */
    .card.is-fit { bottom: auto; max-height: calc(100dvh - var(--search-height) - 3 * var(--gap) - 20px); }
    .mapbar { top: var(--gap); flex-direction: column; }   /* the buttons over the map in a column */
    .map-key { top: calc(100% + 8px); }   /* the map key under that column (100%: the column's height) */
    /* the staff legend: always in sight, at the bottom of the map's free side, clear of the map's logo */
    .legend { position: fixed; bottom: calc(var(--gap) + 40px); flex-direction: column; }
    .maplibregl-ctrl-bottom-right { bottom: 0; }   /* the map's credits in their corner, under the card */
    .draw-hint { top: var(--gap); left: 50%; transform: translateX(-50%); max-width: calc(100vw - 2 * var(--gap)); }
}

/* ----- a phone held upright: the card is a sheet at the bottom ----- */
@media (max-width: 720px) and (min-height: 500.1px) {
    :root { --layout: upright; }   /* the scripts read it: layout() */
    #map { inset: 0; }
    .search { top: var(--gap); inset-inline: var(--gap); }   /* the whole width */
    /* the chips under the search box, across the whole width */
    .chips { top: calc(var(--search-height) + var(--gap)); inset-inline: 0; padding-inline: var(--gap); }
    /* the card: a sheet at the bottom, under the thumb */
    .card {
        bottom: 0;
        inset-inline: 0;
        max-height: var(--sheet-height);
        border-radius: var(--radius-card) var(--radius-card) 0 0;
    }
    /* a long form (.is-tall) takes the whole screen, over the search box and the buttons too */
    .card.is-tall { top: 0; max-height: none; border-radius: 0; z-index: 4; }
    /* a short sheet leaves half the map in view: the public's near list and vendor; the staff's list of vendors
       under a press, a zone, a violation, and drawing */
    .card.is-short { max-height: var(--sheet-short); }
    .card-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

    /* the buttons over the map in one row, at the end of a line (the left in Arabic). The staff app's sit under
       the search box. The public app's sit just above the sheet, where the thumb is, and the map's credits just
       above them, where the buttons can't cover them; card.js keeps --sheet at the sheet's height. */
    .mapbar { inset-inline-end: var(--gap); flex-direction: row; }
    .staff .mapbar { top: calc(var(--search-height) + 2 * var(--gap)); flex-wrap: wrap; gap: 6px; }
    .staff .mapbar button { padding: 0 10px; }   /* "بائع جديد" and the four others in one row on a 390px phone */
    /* The public's: what does not fit in one row (with «القريبون», while the near list is closed) goes in a second
       row above, at the same end */
    .public .mapbar {
        bottom: calc(var(--sheet, 0px) + var(--gap));
        flex-wrap: wrap-reverse;
        justify-content: flex-end;
        max-width: calc(100vw - 2 * var(--gap));
    }
    .public .maplibregl-ctrl-bottom-right { bottom: calc(var(--sheet, 0px) + var(--tap) + 2 * var(--gap)); }
    /* the public's map key above its buttons and the map's credits (20px), lined up with the buttons' outer edge;
       never up over the chips: at most the screen's height less the sheet, the buttons (100%: their rows), the
       credits, and the search box with the chips */
    .public .map-key {
        inset-inline-end: 0;
        bottom: calc(100% + var(--gap) + 26px);
        max-width: calc(100vw - 2 * var(--gap));
        max-height: calc(100dvh - var(--sheet, 0px) - 100% - 2 * var(--gap) - 26px
                         - (var(--search-height) + var(--tap) + 16px + 2 * var(--gap)));
    }
    .staff .maplibregl-ctrl-bottom-right { bottom: var(--sheet, 0px); }   /* the staff's credits just above the sheet */
    /* the colours' legend: a row of its own under the buttons, only while "التفاصيل" shows the layer buttons */
    .legend { flex-basis: 100%; }
    .mapbar:has([data-layer][hidden]) .legend { display: none; }
    .draw-hint { top: var(--gap); left: 50%; transform: translateX(-50%); max-width: calc(100vw - 2 * var(--gap)); }
}

/* ----- a phone held sideways: the card at the side, compact ----- */
@media (max-height: 500px) {
    :root { --layout: sideways; }   /* the scripts read it: layout() */
    /* the sides, as on a wide screen: the card, the search box and the category chips at the start of a line, the
       right in Arabic; the buttons over the map and the drawing hint at its end, the left. To swap the two sides,
       swap "start" and "end" in these three rules (the third: the map key, under the buttons) */
    .search, .chips, .card { inset-inline-start: var(--gap); }
    .mapbar, .draw-hint { inset-inline-end: var(--gap); }
    .map-key { inset-inline-end: 0; }

    #map { inset: 0; }
    .search { top: var(--gap); width: var(--card-width-sideways); }
    .chips { top: calc(var(--search-height) + var(--gap)); width: var(--card-width-sideways); }   /* under the search */
    /* the card: every card, a long form too, at the side, at most half the screen; the map keeps the other half */
    .card {
        top: calc(var(--search-height) + 2 * var(--gap));   /* under the search box */
        bottom: calc(var(--gap) + 20px);   /* under it, the map's credits */
        width: var(--card-width-sideways);
        overflow-y: auto;   /* the whole card scrolls, its title too, so its body always has room */
        scroll-padding-bottom: 72px;   /* a field or a refusal scrolled into view stops above a row of buttons */
    }
    .public .card { top: calc(var(--search-height) + var(--tap) + 16px + 2 * var(--gap)); }   /* under the chips */
    /* a long form (.is-tall) takes the whole height of its side, over the search box and the chips too */
    .card.is-tall { top: var(--gap); z-index: 4; }
    /* the body as tall as what it holds (at least the room left in the card): the card scrolls, not the body */
    .card-body { flex: 1 0 auto; overflow-y: visible; }
    /* the card's buttons stay at its bottom, on its white so nothing shows through, side by side: each as wide as
       its words and the rest of the row shared out; a pair (.btn-row) stays together; what does not fit goes to a
       second row. A label too long for its button takes two lines in the button's usual height */
    .card-foot {
        position: sticky;
        bottom: 0;
        flex-direction: row;
        flex-wrap: wrap;
        padding: 8px 16px;
        background: var(--paper);
    }
    .card-foot > * { flex: 1 1 auto; }
    .card-foot .btn {
        flex: 1 1 auto;
        width: auto;
        display: flex;
        align-items: center;
        justify-content: center;
        padding-block: 4px;
        line-height: 1.25;
    }

    /* the buttons over the map in rows at the top of the map's half, never under the search box or the card */
    .mapbar {
        top: var(--gap);
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
        max-width: calc(100vw - var(--card-width-sideways) - 3 * var(--gap));
    }
    .staff .mapbar button { padding: 0 10px; }   /* narrower, as on a phone held upright, so more fit in a row */
    /* the map key under the buttons' rows, never past the bottom of the screen (100%: the rows' height) */
    .map-key {
        top: calc(100% + 6px);
        max-width: calc(100vw - var(--card-width-sideways) - 3 * var(--gap));
        max-height: calc(100dvh - 100% - 2 * var(--gap) - 6px);
    }
    /* the colours' legend: a row of its own under the buttons, only while "التفاصيل" shows the layer buttons */
    .legend { flex-basis: 100%; }
    .mapbar:has([data-layer][hidden]) .legend { display: none; }
    .maplibregl-ctrl-bottom-right { bottom: 0; }   /* the map's credits in their corner, under the card */
    /* the drawing hint at the bottom of the map's half, where it covers neither the buttons nor the card */
    .draw-hint { bottom: calc(var(--gap) + 20px); max-width: calc(100vw - var(--card-width-sideways) - 3 * var(--gap)); }
}
