:root {
  color-scheme: light dark;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #101828;
  --muted: #667085;
  --line: #e4e7ec;
  --primary: #1f6feb;
  --danger: #b42318;
  --ok: #027a48;
  --warn: #b54708;
  --warn-bg: #fffaeb;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --card: #171a21;
    --ink: #e6e8ec;
    --muted: #98a2b3;
    --line: #262b36;
    --primary: #4c8dff;
    --warn-bg: #2a220f;
  }
}

* { box-sizing: border-box; }

/* The `hidden` attribute is a UA rule of the lowest priority: any class here
   that sets `display` beats it, and the signed-out page showed its tabs. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand .mark {
  display: grid;
  place-items: center;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  letter-spacing: .5px;
}
.brand div { display: flex; flex-direction: column; line-height: 1.25; }
.brand .sub { color: var(--muted); font-size: 12px; }

.tabs { display: flex; gap: 4px; margin-inline-start: auto; }
.tab {
  border: 0; background: transparent; color: var(--muted);
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font: inherit;
}
.tab:hover { background: var(--bg); color: var(--ink); }
.tab.active { background: var(--bg); color: var(--ink); font-weight: 600; }
.badge {
  display: inline-grid; place-items: center; min-width: 20px; height: 20px;
  margin-inline-start: 6px; padding: 0 6px; border-radius: 999px;
  background: var(--danger); color: #fff; font-size: 12px; font-weight: 700;
}

.account { margin-inline-start: 8px; display: flex; align-items: center; gap: 8px; }

main { max-width: 900px; margin: 0 auto; padding: 24px 16px 64px; }

.panel, .card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
}
.panel h1 { margin-top: 0; font-size: 22px; }

.view-head { margin-bottom: 16px; }
.view-head h2 { margin: 0 0 4px; font-size: 19px; }

.list { display: flex; flex-direction: column; gap: 12px; }

.card header { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; }
.card h3 { margin: 0 0 2px; font-size: 16px; }
.card.compact { padding: 14px 20px; }
.card footer { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 16px; }
/* « Rien n'a été envoyé… » after a question answered no. Empty, it takes no
   room but stays in the page, so a screen reader hears it when it fills. */
.note { margin: 0; color: var(--muted); font-size: 13px; }

.muted { color: var(--muted); margin: 0; font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 32px; }

dl {
  display: grid;
  grid-template-columns: minmax(140px, auto) 1fr;
  gap: 6px 16px;
  margin: 14px 0 0;
  font-size: 14px;
}
dt { color: var(--muted); }
dd { margin: 0; font-variant-numeric: tabular-nums; }

.warning {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 13px;
}

button, .primary {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 9px 16px;
  border: 1px solid transparent;
}
.primary { background: var(--primary); color: #fff; text-decoration: none; display: inline-block; }
.primary:hover { filter: brightness(1.05); }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { background: var(--bg); }
.danger { background: var(--danger); color: #fff; }
/* « Approuver et exécuter » stays disabled until its preview has loaded: it
   must LOOK unavailable, not merely ignore the click. */
button:disabled { opacity: .5; cursor: not-allowed; filter: none; }

/* A queue that could not be read must not look like an empty one. */
.failure {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px; border-radius: var(--radius);
  background: var(--warn-bg); color: var(--warn); border: 1px solid currentColor;
}
.failure p { margin: 0; }

.chip {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--bg); color: var(--muted); border: 1px solid var(--line);
  white-space: nowrap;
}
.chip.active, .chip.executed { color: var(--ok); border-color: currentColor; }
.chip.revoked, .chip.rejected, .chip.failed { color: var(--danger); border-color: currentColor; }
.chip.expired { color: var(--warn); border-color: currentColor; }

code { font-size: 12px; background: var(--bg); padding: 1px 6px; border-radius: 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--ink); color: var(--bg);
  padding: 10px 18px; border-radius: 10px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
}
.toast.ok { background: var(--ok); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }

/* The page's own question before a decision or a revocation (confirm.js) —
   never `window.confirm`, which a browser may silence (2026-10-16). Centred
   and fixed in both modes: modal (`showModal`), and shown by its `open`
   attribute in a browser without <dialog>, where nothing else styles it. */
.confirm {
  width: min(480px, calc(100vw - 32px));
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .28);
}
.confirm:not([open]) { display: none; }
.confirm[open] {
  display: block;
  position: fixed; inset: 0; margin: auto; height: fit-content; z-index: 20;
}
/* No custom property here: `::backdrop` did not inherit them before 2024. */
.confirm::backdrop { background: rgba(16, 24, 40, .55); }
.confirm h2 { margin: 0 0 8px; font-size: 17px; }
.confirm p { margin: 0; }
.confirm-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 20px; }

@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; gap: 12px; padding: 12px 16px; }
  .tabs { margin-left: 0; width: 100%; overflow-x: auto; }
  .card header { flex-direction: column; }
  dl { grid-template-columns: 1fr; gap: 2px 0; }
  dt { margin-top: 8px; }
}

/* ------------------------------------------------------------------ RTL --
 * Arabic reads right to left, so the layout mirrors itself. Nearly all of it
 * comes free from logical properties above; what remains is the handful of
 * places where a value is directional by nature.
 *
 * ⚠️ Numbers stay Latin and dates stay dd/mm/yyyy in every language: an
 * invoice number or an amount that changed shape with the interface language
 * would stop matching the document it names.
 *
 * ⚠️ No RTL rule for `.toast`: it is centred by `left: 50%` and
 * `translateX(-50%)`, physical values that hold in both directions. An
 * `[dir='rtl'] .toast { transform: translateX(50%) }` pushed it right by its
 * own width, half off a phone's screen (analysis of 2026-10-21, P3-53). */
[dir='rtl'] dl { direction: rtl; }
[dir='rtl'] code,
[dir='rtl'] .chip,
[dir='rtl'] dd { direction: ltr; text-align: start; unicode-bidi: isolate; }
/* A date and its time, an amount being typed: read left to right, sat on the right. */
[dir='rtl'] .reads td:first-child,
[dir='rtl'] .auto-ceiling input { direction: ltr; text-align: end; unicode-bidi: isolate; }

.lang {
  font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}

/* Visible to a screen reader, not to the eye: the language picker needs a
   name, and a floating "Langue" label would be noise next to a select whose
   options already say what it is. */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* « Actions sans validation » of a connection: what runs with nobody approving
   it. The chip says so from the list; the box sits between the facts and the
   « Révoquer » footer. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; align-items: center; flex: none; }
.chip.auto { color: var(--warn); border-color: currentColor; background: var(--warn-bg); }
.auto-box {
  margin-top: 16px; padding: 14px 16px;
  border: 1px dashed var(--line); border-radius: 10px;
}
.auto-box h4 { margin: 0 0 4px; font-size: 14px; }
.auto-tools { border: 0; margin: 12px 0 0; padding: 0; display: grid; gap: 8px; }
.auto-tool { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; cursor: pointer; }
.auto-tool input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--warn); flex: none; }
.auto-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 12px; }

/* A link that reads as a button: « Se reconnecter ». */
a.ghost {
  display: inline-block; padding: 9px 16px; border: 1px solid var(--line); border-radius: 8px;
  text-decoration: none;
}
.auto-box > .muted { margin-top: 12px; }
.auto-box .muted + .muted { margin-top: 4px; }
.card > [data-auto-forbidden] { margin-top: 14px; }
.auto-ceiling { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin-top: 12px; font-size: 14px; }
.auto-ceiling span { flex: 1 1 260px; }
.auto-ceiling input {
  flex: 0 1 180px; min-width: 0; font: inherit; font-variant-numeric: tabular-nums;
  color: var(--ink); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px;
}

/* « Règles du cabinet »: one row per company. */
.cabinet-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 12px; }
.cabinet-row > span:first-child { flex: 1 1 140px; min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
[data-cabinet] > a.ghost { margin-top: 12px; }
[data-cabinet-note]:not(:empty) { margin-top: 8px; }

/* The second title of « Activité ». */
.list + .view-head { margin-top: 28px; }

/* « Lectures des agents ». */
.reads { width: 100%; border-collapse: collapse; font-size: 14px; }
.reads th, .reads td { padding: 8px 12px; text-align: start; border-bottom: 1px solid var(--line); }
.reads th { color: var(--muted); font-weight: 500; font-size: 12px; }
.reads td:first-child { font-variant-numeric: tabular-nums; white-space: nowrap; }
/* A read per line on a phone: five columns do not fit, and a table wider than
   the phone moves the whole page. After the rules above, which it overrides. */
@media (max-width: 640px) {
  .reads thead { display: none; }
  .reads tr { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .reads td { display: block; padding: 2px 0; border: 0; overflow-wrap: anywhere; }
  .reads td:empty { display: none; }
}

/* The card an agent's link names (/approvals/<id>). */
.card.linked {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
