/* One stylesheet for both apps. No framework.
   Layout: the map fills the page; a search box and one card float over it.
   On a phone the card becomes a sheet at the bottom of the screen.
   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">. */

/* 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;
}

: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 */
    --blue-wash: #e3eefc;    /* behind a chosen chip */
    --blue-halo: rgba(10, 102, 216, 0.2);   /* --blue, faint: the ring around the "موقعي" dot */
    --gold: #f5a623;         /* rating stars */
    --green: #1a7f37;        /* status only */
    --amber: #9a6700;        /* status only */
    --red: #c62828;          /* status and errors only */
    --green-wash: #e6f4ea;
    --amber-wash: #fff4d6;
    --red-wash: #fdeaea;
    --radius-card: 16px;     /* the card, and the log-in page's panel */
    --radius: 12px;          /* everything else with corners: fields, buttons, photos */
    --gap: 12px;
    --card-width: 380px;
    --search-height: 48px;   /* the search box over the map */
    --tap: 44px;             /* smallest height of anything tappable */
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.14);
}

* { box-sizing: border-box; }

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

body {
    font-family: "Plex Arabic", Tahoma, sans-serif;
    font-size: 16px;         /* 16px also stops phones zooming into a field */
    line-height: 1.5;
    color: var(--ink);
    background: var(--wash);
}

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

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

/* 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; inset: 0; font-family: inherit; }

.search {
    position: fixed;
    top: var(--gap);
    inset-inline-start: var(--gap);
    width: var(--card-width);
    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;
    top: calc(var(--search-height) + 2 * var(--gap));
    bottom: calc(var(--gap) + 20px);   /* under it, the map's credits: one line, 20px high (the map library's CSS) */
    inset-inline-start: var(--gap);
    width: var(--card-width);
    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;
    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: 14px; }
.card-body { flex: 1; overflow-y: auto; padding: 8px 16px 16px; }
.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);
}

.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;
    top: var(--gap);
    inset-inline-end: var(--gap);
    z-index: 1;
    display: flex;
    flex-direction: column;
    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: 14px;
    text-align: center;
    line-height: var(--tap);
    cursor: pointer;
}
.mapbar .is-on { color: var(--blue); font-weight: 700; }

/* ---------- 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: 15px;
}
.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: 14px;
    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; }

.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: 14px; }
.list a:hover, .list button:hover, .list .is-active { background: var(--wash); }

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

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

.review { padding: 12px 0; border-top: 1px solid var(--line); }
.review .sub { color: var(--ink-2); font-size: 13px; }
.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: 14px; 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: 14px; 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: 13px; 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(--paper); 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: rgba(255, 255, 255, 0.85);
    color: var(--ink-2); font-size: 13px; white-space: nowrap; pointer-events: none;
}
.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(--paper); 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 */
    position: fixed; z-index: 3; top: var(--gap); left: 50%; transform: translateX(-50%);
    width: max-content;         /* one line where it fits: with left: 50% alone it would wrap at half the screen */
    max-width: calc(100vw - 2 * var(--gap));
    padding: 8px 16px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 14px;
}

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

.chips {                        /* categories under the search box, one row that scrolls sideways */
    position: fixed;
    top: calc(var(--search-height) + var(--gap));
    inset-inline-start: var(--gap);
    width: var(--card-width);
    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: 15px;
    cursor: pointer;
}
.chips .is-on { background: var(--blue-wash); color: var(--blue); font-weight: 700; }   /* the chosen filter */

.list .side { float: inline-end; margin-inline-start: 12px; color: var(--ink-2); font-size: 14px; }   /* a row's distance */
.reviews h2 { margin: 20px 0 4px; }

/* the public page on a desktop: the card starts under the chips (16px: the chips row's padding) */
@media (min-width: 721px) {
    .public .card { top: calc(var(--search-height) + var(--tap) + 16px + 2 * var(--gap)); }
}

/* ---------- phones ---------- */

@media (max-width: 720px) {
    .search { inset-inline: var(--gap); width: auto; }
    .chips { inset-inline: 0; width: auto; padding-inline: var(--gap); }

    /* the card becomes a sheet at the bottom, under the thumb */
    .card {
        top: auto;
        bottom: 0;
        inset-inline: 0;
        width: auto;
        max-height: 72dvh;
        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 cards of places, and drawing */
    .card.is-short { max-height: 50dvh; }
    .card-foot { padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

    /* the buttons over the map in one row. 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 { flex-direction: row; }
    .staff .mapbar { top: calc(var(--search-height) + 2 * var(--gap)); flex-wrap: wrap; }
    .public .mapbar { top: auto; bottom: calc(var(--sheet, 0px) + var(--gap)); }
    .public .maplibregl-ctrl-bottom-right { bottom: calc(var(--sheet, 0px) + var(--tap) + 2 * var(--gap)); }
    .staff .maplibregl-ctrl-bottom-right { bottom: var(--sheet, 0px); }   /* the staff's credits just above the sheet */
}
