/* Drivyn recruitment dashboard.
   One style for every page. Logical properties (inline-start/end) so Arabic mirrors cleanly.
   Status colours: waiting = amber, approved = blue, sent/ok = green, blocked/failed = red, closed = grey. */

:root {
  --ink: #1b1530;
  --ink-2: #3d3654;
  --muted: #6b6480;
  --line: #e8e4ef;
  --line-2: #d6d0e2;
  --bg: #f6f4f9;
  --card: #ffffff;
  --brand: #5f2997;
  --brand-dark: #4a1f78;
  --brand-soft: #f2eafb;
  --accent: #cd82ff;

  --ok: #13744a;      --ok-soft: #e4f5ec;      /* sent, complete, meets */
  --info: #1d5fa6;    --info-soft: #e6f0fb;    /* approved, in progress */
  --warn: #8f5300;    --warn-soft: #fff2d9;    /* waiting, needs review */
  --bad: #b3261e;     --bad-soft: #fde8e6;     /* blocked, failed */
  --grey: #5b5568;    --grey-soft: #efedf3;    /* closed, cancelled */

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(27, 21, 48, .05), 0 2px 8px rgba(27, 21, 48, .04);
  --gap: 1.25rem;

  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic", "Noto Naskh Arabic", "Geeza Pro", Tahoma, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--ink);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); }
a { color: var(--brand); text-underline-offset: 2px; }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 0 0 .85rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .5rem; }
p { margin: .4rem 0; }
small, .muted { color: var(--muted); }
small { font-size: .85rem; }
code { font-size: .88em; background: var(--brand-soft); padding: .05em .35em; border-radius: 5px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
[dir="rtl"] h1, [dir="rtl"] h2, [dir="rtl"] h3 { letter-spacing: 0; }
[dir="rtl"] { line-height: 1.7; }

/* ── Icons ── */
.ico { width: 1.25em; height: 1.25em; flex: none; vertical-align: -.25em; }
.ico-lg { width: 2.6rem; height: 2.6rem; }

/* ── Header ── */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem;
  padding: .6rem 1.5rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.top a { text-decoration: none; }
.brand { font-weight: 800; font-size: 1.15rem; color: var(--brand); white-space: nowrap; }
.brand span { font-weight: 500; color: var(--muted); margin-inline-start: .4rem; font-size: .88rem; }
nav.main { display: flex; gap: .35rem; flex: 1; }
nav.main a, nav.bottom a {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .55rem .95rem; border-radius: 999px; color: var(--ink-2); font-weight: 600;
}
nav.main a:hover { background: var(--bg); }
nav.main a.active { background: var(--brand-soft); color: var(--brand); }
.me { display: flex; gap: .5rem; align-items: center; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem; cursor: pointer; list-style: none;
  padding: .45rem .8rem; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--card); color: var(--ink-2); font: inherit; font-size: .92rem; min-height: 40px;
}
.chip:hover { background: var(--bg); }
summary.chip::-webkit-details-marker { display: none; }
.menu { position: relative; }
.menu-panel {
  position: absolute; inset-inline-end: 0; top: calc(100% + .4rem); min-width: 220px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(27, 21, 48, .12); padding: .75rem 1rem; z-index: 30;
}
.menu-panel a, .menu-panel button { display: block; padding: .4rem 0; }
.pill {
  display: inline-block; min-width: 1.5em; padding: 0 .45em; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: .75rem; font-weight: 700; text-align: center; line-height: 1.5;
}

/* Section tabs (under the header) */
nav.tabs {
  display: flex; gap: .25rem; padding: 0 1.5rem; background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none;
}
nav.tabs a {
  display: inline-flex; align-items: center; gap: .4rem; white-space: nowrap;
  padding: .8rem .9rem; color: var(--muted); font-weight: 600; text-decoration: none;
  border-bottom: 3px solid transparent;
}
nav.tabs a.active { color: var(--brand); border-bottom-color: var(--brand); }
nav.tabs a:hover { color: var(--ink); }

/* Phone: bottom navigation */
nav.bottom { display: none; }

.banner {
  display: flex; align-items: center; gap: .5rem; justify-content: center;
  background: var(--warn-soft); color: var(--warn); padding: .45rem 1rem; font-size: .88rem; text-align: center;
}

/* ── Page ── */
main { padding: var(--gap) 1.5rem 3rem; max-width: 1180px; margin: 0 auto; }
main.narrow { max-width: 440px; padding-top: 10vh; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin: .25rem 0 var(--gap); }
.help { color: var(--muted); margin: .35rem 0 0; max-width: 62ch; }
.flash { display: flex; gap: .5rem; align-items: center; background: var(--ok-soft); color: var(--ok); padding: .8rem 1rem; border-radius: var(--radius-sm); margin-bottom: var(--gap); font-weight: 600; }
.flash-err { background: var(--bad-soft); color: var(--bad); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.4rem; margin-bottom: var(--gap); box-shadow: var(--shadow); }
.card > h2:first-child, .card > .spread:first-child h2 { margin-top: 0; }
.card-title { display: flex; align-items: center; gap: .5rem; }
.grid { display: grid; gap: var(--gap); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: var(--gap); align-items: start; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spread { display: flex; justify-content: space-between; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.stack > * + * { margin-top: .6rem; }
.narrow-card { max-width: 560px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 1.25rem 0; }

/* ── Buttons ── */
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  min-height: 44px; padding: .55rem 1.1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--brand); background: var(--brand); color: #fff; font-size: .95rem;
}
button:hover, .btn:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-primary { min-height: 52px; padding: .75rem 1.6rem; font-size: 1.05rem; border-radius: 12px; }
.btn-ok { background: var(--ok); border-color: var(--ok); }
.btn-ok:hover { background: #0e5c3a; border-color: #0e5c3a; }
button.secondary, .btn.secondary { background: var(--card); color: var(--brand); border-color: var(--line-2); }
button.secondary:hover, .btn.secondary:hover { background: var(--brand-soft); border-color: var(--brand-soft); }
button.danger, .btn.danger { background: var(--card); color: var(--bad); border-color: #f0c4c0; }
button.danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
button.link { background: none; border: 0; padding: 0; min-height: 0; color: var(--brand); text-decoration: underline; font-weight: 500; }
button.link:hover { background: none; color: var(--brand-dark); }
button:disabled, button:disabled:hover { opacity: .45; cursor: not-allowed; background: var(--grey-soft); color: var(--grey); border-color: var(--line-2); }
.actions { display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; margin-top: 1rem; }

/* ── Status badges ── */
.badge {
  display: inline-flex; align-items: center; gap: .3rem; padding: .15rem .65rem; border-radius: 999px;
  font-size: .8rem; font-weight: 700; white-space: nowrap; background: var(--grey-soft); color: var(--grey); line-height: 1.6;
}
.badge::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: currentColor; opacity: .8; }
.b-ok, .b-priority, .st-sent { background: var(--ok-soft); color: var(--ok); }
.b-info, .b-other_areas, .st-approved { background: var(--info-soft); color: var(--info); }
.b-warn, .b-needs_review, .st-waiting { background: var(--warn-soft); color: var(--warn); }
.b-bad, .st-blocked { background: var(--bad-soft); color: var(--bad); }
.b-below_minimums, .st-closed { background: var(--grey-soft); color: var(--grey); }
.b-brand { background: var(--brand-soft); color: var(--brand); }

/* ── Forms ── */
form.inline { display: inline; }
label { display: block; font-size: .9rem; font-weight: 600; margin: .75rem 0 .3rem; color: var(--ink-2); }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], select, textarea {
  font: inherit; font-size: 1rem; min-height: 44px; padding: .55rem .75rem; border: 1px solid var(--line-2);
  border-radius: var(--radius-sm); background: #fff; color: var(--ink); width: 100%; max-width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); outline: 3px solid var(--brand-soft); }
textarea { min-height: 7rem; resize: vertical; }
label.check { display: flex; gap: .6rem; align-items: center; font-weight: 500; }
label.check input { width: 1.2rem; height: 1.2rem; min-height: 0; }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .25rem 1rem; align-items: end; }
.filters label { margin-top: 0; }
.search-row { display: flex; gap: .75rem; align-items: center; }
.search-row input { flex: 1; }
.search-row button, .search-row .btn { white-space: nowrap; }
/* Arrows follow the reading direction: "back" points right in Arabic. */
[dir="rtl"] .dir-arrow { display: inline-block; transform: scaleX(-1); }
.nowrap { white-space: nowrap; }
code.bad-code { color: var(--bad, #b42318); font-weight: 600; overflow-wrap: anywhere; }
.tight label { margin-top: .4rem; }

/* ── "More" disclosure ── */
details > summary { cursor: pointer; color: var(--brand); font-weight: 600; margin: .5rem 0; list-style-position: inside; }
details.more { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: .5rem; }
details.more > summary { color: var(--muted); font-weight: 600; }
details.more[open] > summary { color: var(--ink-2); }
details.box { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .25rem 1rem; margin: .75rem 0; background: var(--card); }

/* ── Tables (cards on phones) ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: start; padding: .75rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfaff; }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; }
.row-link { font-weight: 700; text-decoration: none; }
.row-link:hover { text-decoration: underline; }

/* ── Key-value lists ── */
.kv { display: grid; grid-template-columns: minmax(150px, max-content) 1fr; gap: .55rem 1.25rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* ── Boxes ── */
.warn-box, .bad-box, .ok-box, .info-box { border-radius: var(--radius-sm); padding: .7rem .9rem; margin: .6rem 0; }
.warn-box { background: var(--warn-soft); color: var(--warn); }
.bad-box { background: var(--bad-soft); color: var(--bad); }
.ok-box { background: var(--ok-soft); color: var(--ok); }
.info-box { background: var(--info-soft); color: var(--info); }
.issues { margin: .5rem 0; padding-inline-start: 1.2rem; }
.issues li { margin: .3rem 0; }
.issues .issue { color: var(--warn); }
.notes-list li { color: var(--muted); }

details.card > summary { color: var(--ink-2); font-weight: 700; display: flex; align-items: center; gap: .5rem; margin: 0; list-style: none; }
details.card > summary::-webkit-details-marker { display: none; }
details.card[open] > summary { margin-bottom: .5rem; }
h1.brand { font-size: 1.6rem; }

/* ── Empty states ── */
.empty { text-align: center; padding: 2.25rem 1rem; color: var(--muted); }
.empty .ico-lg { color: var(--accent); background: var(--brand-soft); border-radius: 50%; padding: .55rem; width: 3.6rem; height: 3.6rem; }
.empty-title { font-size: 1.1rem; font-weight: 700; color: var(--ink); margin-top: .75rem; }

/* ── Approval cards ── */
.approve-card .to { font-size: 1.05rem; }
.approve-card .meta { color: var(--muted); font-size: .9rem; }
.draft-label { font-size: .85rem; font-weight: 700; color: var(--muted); margin: 1rem 0 .4rem; }
.draft-text {
  white-space: pre-wrap; background: var(--bg); border: 1px solid var(--line); border-inline-start: 4px solid var(--brand);
  border-radius: var(--radius-sm); padding: .9rem 1rem; font-size: 1.02rem; line-height: 1.6;
}

/* ── Chat ── */
.chat { display: flex; flex-direction: column; gap: .5rem; max-height: 420px; overflow-y: auto; padding: .5rem; background: var(--bg); border-radius: var(--radius-sm); }
.msg { max-width: 82%; padding: .55rem .85rem; border-radius: 16px; font-size: .95rem; white-space: pre-wrap; background: #fff; border: 1px solid var(--line); }
.msg.in { align-self: flex-start; border-end-start-radius: 4px; }
.msg.out { align-self: flex-end; background: var(--brand-soft); border-color: transparent; border-end-end-radius: 4px; }
.msg small { display: block; margin-top: .25rem; font-size: .75rem; }

/* ── Lead page ── */
.lead-head { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; align-items: flex-start; }
.lead-head .sub { color: var(--muted); margin: .3rem 0 .6rem; }
.key-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .75rem; margin-top: 1rem; }
.fact { background: var(--bg); border-radius: var(--radius-sm); padding: .7rem .9rem; }
.fact .k { color: var(--muted); font-size: .82rem; }
.fact .v { font-weight: 700; font-size: 1.05rem; }
.shots { display: grid; gap: var(--gap); grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.shot { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .9rem; background: #fff; }
.shot img { width: 100%; max-height: 440px; object-fit: contain; background: var(--bg); border-radius: 8px; display: block; margin: .6rem 0 .3rem; }
.fig { border-top: 1px dashed var(--line); padding-top: .6rem; margin-top: .6rem; font-size: .92rem; }
.fig .val { font-size: 1.3rem; font-weight: 800; font-variant-numeric: tabular-nums; }

.pager { display: flex; gap: .75rem; justify-content: center; margin-top: 1rem; align-items: center; }
.stat { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }

/* ── Admin bits ── */
.subcard { border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem; }
.envlist { list-style: none; padding: 0; columns: 2; }
.envlist li { margin: .3rem 0; }
code.secret { display: inline-block; font-size: 1.15rem; padding: .3rem .6rem; margin: .4rem 0; background: #fff; border: 1px dashed var(--warn); user-select: all; }
.details { word-break: break-all; }

/* ── Public pages ── */
body.bare main.narrow .card { padding: 1.75rem; }
.policy h2 { margin-top: 1.75rem; }
main.policy-main { max-width: 760px; padding-top: 2rem; }
.policy-links { display: flex; gap: 1rem; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1.5rem; }
.policy-links a[aria-current] { color: var(--ink); font-weight: 700; text-decoration: none; }
.needs-approval { background: #fef3c7; border: 1px dashed #b45309; padding: 0 .25rem; border-radius: .2rem; }
.stack .btn { width: 100%; }

/* ── Phones and small tablets ── */
@media (max-width: 760px) {
  :root { --gap: 1rem; }
  .top { padding: .55rem 1rem; gap: .75rem; }
  .brand span, .hide-sm { display: none; }
  nav.main { display: none; }
  nav.tabs { padding: 0 .5rem; }
  main { padding: 1rem 1rem 6.5rem; }
  h1 { font-size: 1.35rem; }
  .card { padding: 1.05rem; border-radius: 12px; }
  /* minmax(0, …): a plain 1fr track grows to its widest content (the trips table), which made the
     whole lead page wider than the phone screen. */
  .cols { grid-template-columns: minmax(0, 1fr); }
  .search-row { flex-wrap: wrap; }
  .kv { grid-template-columns: 1fr; gap: .1rem; }
  .kv dd { margin-bottom: .6rem; }
  .btn-primary, .actions-main button, .actions-main .btn { width: 100%; }
  .filters { grid-template-columns: 1fr 1fr; }
  .envlist { columns: 1; }
  .msg { max-width: 92%; }
  th, td { overflow-wrap: anywhere; }
  .badge { white-space: normal; }
  /* A table that scrolls sideways in its wrapper keeps whole words and badges. */
  .table-wrap > table:not(.rtable) th, .table-wrap > table:not(.rtable) td { overflow-wrap: normal; }
  .table-wrap > table:not(.rtable) .badge { white-space: nowrap; }
  table.kvtable th { width: 40%; white-space: normal; }

  nav.bottom {
    display: flex; position: fixed; inset-inline: 0; bottom: 0; z-index: 25;
    background: var(--card); border-top: 1px solid var(--line);
    padding: .35rem .5rem calc(.35rem + env(safe-area-inset-bottom));
  }
  nav.bottom a { flex: 1; flex-direction: column; gap: .15rem; padding: .35rem .25rem; border-radius: 12px; font-size: .78rem; position: relative; text-decoration: none; }
  nav.bottom a .ico { width: 1.5rem; height: 1.5rem; }
  nav.bottom a.active { color: var(--brand); background: var(--brand-soft); }
  nav.bottom .pill { position: absolute; top: .1rem; inset-inline-start: calc(50% + .35rem); }

  /* Tables become stacked cards */
  table.rtable thead { display: none; }
  table.rtable, table.rtable tbody, table.rtable tr, table.rtable td { display: block; width: 100%; }
  table.rtable tr {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 1rem;
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: .5rem .85rem; margin-bottom: .75rem; background: #fff;
  }
  table.rtable td { border: 0; padding: .3rem 0; min-width: 0; overflow-wrap: anywhere; }
  /* The first cell (name) and cells without a label (buttons, long text) use the full width. */
  table.rtable td:first-child, table.rtable td:not([data-label]), table.rtable td.wide { grid-column: 1 / -1; }
  table.rtable td[data-label]::before { content: attr(data-label); display: block; font-size: .78rem; color: var(--muted); font-weight: 600; }
  table.rtable td.num { text-align: start; }
  table.rtable tbody tr:hover td { background: none; }
  .card.table-wrap { padding: .75rem; background: transparent; border: 0; box-shadow: none; }
}

@media (min-width: 761px) and (max-width: 1000px) {
  .cols { grid-template-columns: minmax(0, 1fr); }
}
