/* ═══════════════════════════════════════════════════════════════════════
   ELTS Dispatch — the board.

   Built for someone who looks at it for a whole shift: dense but calm, colour
   that MEANS something (amber = waiting, blue = heading to pickup, violet =
   carrying goods, green / red / grey = finished), and nothing that moves unless
   it needs attention. Logical properties throughout (inline-start/end), so the
   Arabic layout mirrors correctly with no separate stylesheet.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --border: #e3e6ea;
    --text: #1b1f24;
    --muted: #5d6673;
    --faint: #8a93a0;
    --accent: #2f5bea;
    --accent-ink: #ffffff;

    --waiting: #b7791f;
    --waiting-bg: #fff6e5;
    --heading: #2b6cb0;
    --heading-bg: #e8f1fb;
    --carrying: #6b46c1;
    --carrying-bg: #f1ebfd;
    --done: #2f855a;
    --done-bg: #e8f6ee;
    --failed: #c53030;
    --failed-bg: #fdecec;
    --cancelled: #718096;
    --cancelled-bg: #eef1f4;
    --breach: #d62828;

    --radius: 8px;
    --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
    --shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
    --font: system-ui, -apple-system, "Segoe UI", "Noto Sans", "Noto Naskh Arabic", Tahoma, sans-serif;
    --mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --surface: #171b21;
        --surface-2: #1d222a;
        --border: #2a313b;
        --text: #e7eaee;
        --muted: #a2abb7;
        --faint: #6f7886;
        --accent: #6b8cff;
        --accent-ink: #0f1216;

        --waiting: #f0b429;
        --waiting-bg: #2b2413;
        --heading: #63b3ed;
        --heading-bg: #13253a;
        --carrying: #b794f4;
        --carrying-bg: #251c3a;
        --done: #68d391;
        --done-bg: #14271d;
        --failed: #fc8181;
        --failed-bg: #331818;
        --cancelled: #a0aec0;
        --cancelled-bg: #22272e;
        --breach: #ff6b6b;

        --shadow: 0 1px 2px rgb(0 0 0 / 40%);
        --shadow-lg: 0 12px 32px rgb(0 0 0 / 55%);
    }
}

* { box-sizing: border-box; }

html { height: 100%; }

/* At least the window's height, and taller when the page is: the sticky top
   bar sticks only within its container, and a body fixed at 100% let it scroll
   away with the rest of a long page (the admin screens). The board itself is
   sized by 100vh, so nothing there moves. */
body {
    min-height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 var(--font);
    -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; color: inherit; }

button {
    cursor: pointer;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 6px;
    padding: 6px 12px;
}

button:hover { border-color: var(--faint); }
button:disabled { opacity: .55; cursor: default; }

button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
    font-weight: 600;
}

button.danger {
    color: var(--failed);
    border-color: color-mix(in srgb, var(--failed) 40%, var(--border));
}

.link-button {
    background: none;
    border: 0;
    padding: 0;
    color: var(--muted);
    text-decoration: underline;
    text-underline-offset: 2px;
}

input:not([type="radio"], [type="checkbox"]), select, textarea {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 7px 10px;
    width: 100%;
}

input:focus, select:focus, textarea:focus, button:focus-visible {
    outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent);
    outline-offset: 1px;
}

[hidden] { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────────────────── */

.topbar {
    height: 52px;
    display: flex;
    align-items: center;
    gap: 24px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 900;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    letter-spacing: .2px;
}

.brand-mark {
    color: var(--accent);
    font-size: 13px;
}

.nav { display: flex; gap: 4px; }

.nav a {
    color: var(--muted);
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 6px;
}

.nav a.active,
.nav a:hover {
    color: var(--text);
    background: var(--surface-2);
}

.topbar-right {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: 16px;
}

.live-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
}

.live-indicator .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--faint);
}

.live-indicator[data-state="live"] .dot { background: var(--done); }
.live-indicator[data-state="down"] .dot,
.live-indicator[data-state="stale"] .dot { background: var(--failed); }
.live-indicator[data-state="down"],
.live-indicator[data-state="stale"] { color: var(--failed); }

.lang-toggle {
    padding: 4px 10px;
    font-size: 12px;
}

.lang-toggle.quiet {
    border: 0;
    background: none;
    color: var(--muted);
    margin-top: 4px;
}

.user { display: inline-flex; align-items: center; gap: 6px; }
.user-name { font-weight: 600; }

.role-badge {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--muted);
}

.logout { margin: 0; }

/* ── Board layout ────────────────────────────────────────────────────── */

.board {
    display: grid;
    grid-template-columns: minmax(380px, 44%) 1fr;
    height: calc(100vh - 52px);
}

.columns {
    overflow-y: auto;
    border-inline-end: 1px solid var(--border);
    padding: 12px 12px 40px;
}

.toolbar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
    position: sticky;
    top: -12px;
    padding: 12px 0 8px;
    margin-top: -12px;
    background: var(--bg);
    z-index: 2;
}

.filter { flex: 1; }

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    color: var(--muted);
    font-size: 13px;
}

.toggle input { width: auto; }

/* Said once, at the top of the columns, for as long as it is true. */
.board-alert {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-radius: 6px;
    border-inline-start: 4px solid var(--waiting);
    background: var(--waiting-bg);
    font-size: 13px;
}

.board-alert.error {
    border-inline-start-color: var(--failed);
    background: var(--failed-bg);
}

.column { margin-bottom: 18px; }

.column h2 {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
    margin: 0 0 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.count {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0 7px;
    font-size: 11px;
    color: var(--text);
}

.cards { display: grid; gap: 8px; }

.empty {
    color: var(--faint);
    font-size: 13px;
    padding: 10px 2px;
}

.section .empty { margin: 0; padding: 2px 0; }

.map-panel { position: relative; }
.map { position: absolute; inset: 0; }

/* ── Order card ──────────────────────────────────────────────────────── */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-inline-start: 4px solid var(--status, var(--faint));
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 10px 12px;
    cursor: pointer;
    display: grid;
    gap: 4px;
    transition: border-color .15s, transform .15s;
}

.card:hover { border-color: var(--faint); border-inline-start-color: var(--status); }
.card.selected { outline: 2px solid var(--accent); outline-offset: 1px; }

.card.flash { animation: flash 1.2s ease-out 1; }

@keyframes flash {
    from { background: color-mix(in srgb, var(--accent) 16%, var(--surface)); }
    to { background: var(--surface); }
}

.card.test { background-image: repeating-linear-gradient(135deg, transparent 0 10px, color-mix(in srgb, var(--faint) 8%, transparent) 10px 20px); }

.card.breach { border-inline-start-color: var(--breach); }

.card-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Phone numbers, e-mails and codes read left to right even on an Arabic page;
   without this "+962790000102" renders as "962790000102+". */
.ltr, .card-ref { direction: ltr; unicode-bidi: isolate; }

.card-ref {
    font-family: var(--mono);
    font-size: 12px;
    color: var(--muted);
}

.card-age {
    margin-inline-start: auto;
    font-variant-numeric: tabular-nums;
    font-size: 12px;
    color: var(--muted);
}

.card.breach .card-age {
    color: var(--breach);
    font-weight: 700;
}

.card-title {
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-sub {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
    font-size: 12px;
    color: var(--muted);
}

.money { font-variant-numeric: tabular-nums; color: var(--text); font-weight: 600; }

/* ── Status badges ───────────────────────────────────────────────────── */

.badge {
    font-size: 11px;
    font-weight: 600;
    padding: 1px 7px;
    border-radius: 10px;
    background: var(--status-bg, var(--surface-2));
    color: var(--status, var(--muted));
    white-space: nowrap;
}

.badge.test-badge {
    background: transparent;
    border: 1px dashed var(--faint);
    color: var(--muted);
}

.badge.breach-badge {
    background: var(--breach);
    color: #fff;
    animation: pulse 1.6s ease-in-out infinite;
}

@keyframes pulse { 50% { opacity: .55; } }

@media (prefers-reduced-motion: reduce) {
    .badge.breach-badge, .card.flash { animation: none; }
}

.s-new, .s-searching, .s-offered { --status: var(--waiting); --status-bg: var(--waiting-bg); }
.s-assigned, .s-at_pickup { --status: var(--heading); --status-bg: var(--heading-bg); }
.s-picked_up, .s-at_dropoff { --status: var(--carrying); --status-bg: var(--carrying-bg); }
.s-delivered { --status: var(--done); --status-bg: var(--done-bg); }
.s-failed { --status: var(--failed); --status-bg: var(--failed-bg); }
.s-cancelled { --status: var(--cancelled); --status-bg: var(--cancelled-bg); }

/* ── Drawer ──────────────────────────────────────────────────────────── */

.drawer {
    position: fixed;
    top: 52px;
    inset-inline-end: 0;
    bottom: 0;
    width: min(460px, 100%); /* not 100vw: that includes the page scrollbar and pushes the drawer off-screen */
    background: var(--surface);
    border-inline-start: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    overflow-y: auto;
}

.drawer-inner { padding: 16px 18px 40px; display: grid; gap: 18px; transition: opacity .15s; }

/* Another card was clicked and its detail is on the way: the buttons still
   here belong to the previous order, so they are dimmed and out of reach. */
.drawer.loading .drawer-inner > :not(.drawer-head),
.drawer.loading .drawer-head > :not(.drawer-close) { opacity: .45; }

.drawer-head {
    display: flex;
    align-items: flex-start;
    gap: 10px;
}

.drawer-head h3 { margin: 0; font-size: 17px; }

/* Focus lands on the heading when the drawer opens, so a keyboard user starts
   there; a mouse user should not see a ring they did not ask for. */
.drawer-title:focus { outline: none; }
.drawer-title:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }

.drawer-close {
    margin-inline-start: auto;
    border: 0;
    background: none;
    font-size: 22px;
    line-height: 1;
    color: var(--muted);
    padding: 0 4px;
}

.section h4 {
    margin: 0 0 8px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .6px;
    color: var(--muted);
}

.facts {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 6px 14px;
    margin: 0;
}

.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
/* The merchant's note keeps the lines it was written in ("الدفع بالبطاقة" above "No onions"). */
.facts .note { white-space: pre-line; }

.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions .hint { width: 100%; color: var(--faint); font-size: 12px; margin: 0; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }

.timeline li {
    display: grid;
    grid-template-columns: 12px 1fr;
    gap: 10px;
}

.timeline .tick {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 5px;
    background: var(--status, var(--faint));
}

.timeline .what { font-weight: 600; }
.timeline .who, .timeline .when { color: var(--muted); font-size: 12px; }
.timeline .why { font-size: 13px; margin-top: 2px; }

.hooks { width: 100%; border-collapse: collapse; font-size: 12px; }
.hooks td { padding: 4px 6px; border-top: 1px solid var(--border); vertical-align: top; }
.hooks .url { font-family: var(--mono); overflow-wrap: anywhere; color: var(--muted); }
.hook-delivered { color: var(--done); font-weight: 600; }
.hook-pending { color: var(--waiting); font-weight: 600; }
.hook-dead { color: var(--failed); font-weight: 600; }

/* ── Dialog ──────────────────────────────────────────────────────────── */

.dialog-backdrop {
    position: fixed;
    inset: 0;
    background: rgb(10 12 16 / 45%);
    display: grid;
    place-items: center;
    z-index: 2000;
    padding: 16px;
}

.dialog {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    width: min(440px, 100%);
    padding: 18px;
    display: grid;
    gap: 12px;
}

.dialog h3 { margin: 0; font-size: 16px; }
.dialog label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }

.driver-list { display: grid; gap: 6px; max-height: 320px; overflow-y: auto; }

.dialog .driver-option { /* .dialog, to outrank the ".dialog label" grid */
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
}

.driver-option input { flex: none; accent-color: var(--accent); }
.driver-option .load { margin-inline-start: auto; color: var(--muted); font-size: 12px; }

/* ── Toasts ──────────────────────────────────────────────────────────── */

.toasts {
    position: fixed;
    bottom: 16px;
    inset-inline-start: 16px;
    display: grid;
    gap: 8px;
    z-index: 3000;
}

.toast {
    background: var(--text);
    color: var(--bg);
    padding: 10px 14px;
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    max-width: 420px;
}

.toast.error { background: var(--failed); color: #fff; }

/* ── Login ───────────────────────────────────────────────────────────── */

.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 16px;
}

.login-card {
    width: min(380px, 100%);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: var(--shadow-lg);
    padding: 28px 26px 20px;
    display: grid;
    gap: 14px;
}

.login-brand { font-size: 15px; }
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card label { display: grid; gap: 5px; color: var(--muted); font-size: 13px; }
.login-card .primary { padding: 9px; margin-top: 4px; }

.form-error {
    margin: 0;
    color: var(--failed);
    background: var(--failed-bg);
    border-radius: 6px;
    padding: 8px 10px;
    font-size: 13px;
}

/* ── Drivers page ────────────────────────────────────────────────────── */

.drivers {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 60px;
    display: grid;
    gap: 16px;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 18px;
}

.panel h2 { margin: 0 0 12px; font-size: 15px; }

.form-row {
    display: grid;
    grid-template-columns: 2fr 1.4fr 1.2fr 1fr auto;
    gap: 10px;
    align-items: end;
}

.form-row label { display: grid; gap: 4px; color: var(--muted); font-size: 13px; }

.table { width: 100%; border-collapse: collapse; }
.table th { text-align: start; color: var(--muted); font-size: 12px; font-weight: 600; padding: 6px 8px; }
.table td { padding: 8px; border-top: 1px solid var(--border); }
.table .row-actions { text-align: end; white-space: nowrap; }

.state-approved { color: var(--done); font-weight: 600; }
.state-suspended, .state-rejected { color: var(--failed); font-weight: 600; }
.state-pending_review, .state-incomplete { color: var(--waiting); font-weight: 600; }

/* ── Map markers ─────────────────────────────────────────────────────── */

.map-popup { display: grid; gap: 2px; font: 13px/1.4 var(--font); }
.map-popup strong { font-size: 13px; }

/* Physical, not logical, on purpose. Leaflet places a tooltip with a
   translate from the pane's LEFT edge, but leaflet.css gives tooltips no
   "left", so on the Arabic page each one started from the right-hand static
   position and sat a tooltip's width to the left of what it names (a zone's
   label, a branch's name). Popups are not affected: Leaflet sets their left. */
.leaflet-tooltip { left: 0; }

/* ── Narrow screens ──────────────────────────────────────────────────── */

@media (max-width: 900px) {
    .board { grid-template-columns: 1fr; grid-template-rows: auto 45vh; height: auto; }
    .columns { border-inline-end: 0; overflow: visible; }
    .map-panel { position: relative; height: 45vh; order: -1; }
    .topbar { gap: 12px; }
    .user-name, .live-label { display: none; }
    .form-row { grid-template-columns: 1fr 1fr; }
}

/* A phone: the brand keeps only its mark, and the bar packs tighter, so
   nothing scrolls sideways at 360-400 px. An admin's four links still do not
   fit beside the language and sign-out buttons: the links scroll within their
   own strip instead of pushing the page wider than the screen. */
@media (max-width: 480px) {
    .topbar { gap: 8px; padding: 0 10px; }
    .brand > :not(.brand-mark) { display: none; }
    .nav { min-width: 0; overflow-x: auto; scrollbar-width: none; }
    .nav a { padding: 6px 8px; flex: none; white-space: nowrap; }
    .topbar-right { gap: 8px; flex: none; }
    .role-badge { display: none; }
}
