/* ===========================================================================
   Cabinet — theme layer (Graphite & Soft Gold)
   ---------------------------------------------------------------------------
   Overrides Bootstrap 5 through its CSS variables. No markup depends on this
   file: remove the two <link> tags in base.html and the app looks like stock
   Bootstrap again.

   Designed for the people who actually use this all day (lawyers and
   associates reading dense bilingual case data on a laptop):
     - 17px base text, 1.6 line-height, generous row height;
     - real contrast (body text 13.6:1) — gold is NEVER used for text on light
       backgrounds (2.3:1). Gold buttons carry graphite text (5.9:1);
     - large click targets and visible focus rings;
     - muted status colours so gold stays the only bright accent;
     - works identically in LTR (fr) and RTL (ar).
   =========================================================================== */

:root {
    /* ── Palette ────────────────────────────────────────────────────────── */
    --c-graphite:      #2B2E34;   /* base: top bar, headings */
    --c-graphite-deep: #231F20;   /* hover on dark surfaces */
    --c-graphite-soft: #3A3E46;   /* dark surface, raised */
    --c-gold:          #C6A75E;   /* accent: buttons, active state, rules */
    --c-gold-dark:     #8E793E;   /* accent on light: icons, hover */
    --c-gold-deep:     #6F5C2E;   /* gold-toned text on white (6.5:1) */
    --c-gold-tint:     #F3ECDC;   /* selected rows, soft highlights */
    --c-surface:       #F7F5F1;   /* page background (warm off-white) */
    --c-card:          #FFFFFF;
    --c-hairline:      #E6E2D9;
    --c-text:          #2B2E34;
    --c-text-muted:    #5C6068;
    --c-sage:          #3F6B4A;   /* success */
    --c-sage-tint:     #E8F0EA;
    --c-brick:         #8E2F2F;   /* danger */
    --c-brick-tint:    #F6E9E9;
    --c-info-tint:     #EAEEF2;

    --radius:    10px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(35, 31, 32, .06);
    --shadow:    0 6px 24px rgba(35, 31, 32, .08);

    /* ── Bootstrap variable overrides ───────────────────────────────────── */
    --bs-body-bg: var(--c-surface);
    --bs-body-color: var(--c-text);
    --bs-body-font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
    --bs-body-font-size: 1.0625rem;      /* 17px */
    --bs-body-line-height: 1.6;
    --bs-border-color: var(--c-hairline);
    --bs-border-radius: var(--radius);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-link-color: var(--c-gold-deep);
    --bs-link-hover-color: var(--c-graphite);
    --bs-emphasis-color: var(--c-graphite);
    --bs-secondary-color: var(--c-text-muted);
    --bs-primary: #2B2E34;
    --bs-primary-rgb: 43, 46, 52;
    --bs-focus-ring-color: rgba(198, 167, 94, .45);
    --bs-focus-ring-width: 3px;
}

/* Arabic pages: Noto Kufi Arabic, slightly looser lines for diacritics */
html[lang="ar"], html[dir="rtl"] {
    --bs-body-font-family: 'Noto Kufi Arabic', 'Inter', system-ui, sans-serif;
    --bs-body-line-height: 1.85;
}

body { background-color: var(--c-surface); }

/* ── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, .h1, .h2, .h3, .navbar-brand {
    font-family: 'Playfair Display', Georgia, 'Times New Roman', serif;
    font-weight: 700;
    letter-spacing: -.01em;
    color: var(--c-graphite);
}
html[lang="ar"] h1, html[lang="ar"] h2, html[lang="ar"] h3,
html[lang="ar"] .navbar-brand, html[dir="rtl"] .navbar-brand {
    font-family: 'Noto Kufi Arabic', 'Playfair Display', serif;
    font-weight: 700;
    letter-spacing: 0;
}
h4, h5, h6, .h4, .h5, .h6 { font-weight: 600; color: var(--c-graphite); }
h2, .h2 { font-size: 1.75rem; }
h3, .h3 { font-size: 1.4rem; }
small, .small { font-size: .9375rem; }      /* 15px — no microscopic text */
code { color: var(--c-gold-deep); background: var(--c-gold-tint); padding: .1em .4em; border-radius: 4px; }

/* ── Top bar ────────────────────────────────────────────────────────────── */
.navbar {
    background-color: var(--c-graphite) !important;
    border-bottom: 3px solid var(--c-gold);
    padding-block: .85rem;
    box-shadow: var(--shadow-sm);
}
.navbar .navbar-brand {
    color: #fff;
    font-size: 1.35rem;
    display: inline-flex;
    align-items: center;
    gap: .55rem;
}
.navbar .navbar-brand::before {          /* small gold rule, the "seal" */
    content: "";
    width: 22px; height: 3px;
    background: var(--c-gold);
    display: inline-block;
}
.navbar .nav-link {
    color: rgba(255, 255, 255, .82) !important;
    font-weight: 500;
    padding: .5rem .9rem !important;
    border-radius: var(--radius-sm);
    white-space: nowrap;
}
.navbar .nav-link:hover, .navbar .nav-link:focus-visible {
    color: #fff !important;
    background: rgba(255, 255, 255, .08);
}
.navbar .nav-link.active { color: var(--c-gold) !important; }
.navbar-toggler { border-color: rgba(255, 255, 255, .3); }

/* ── Cards / panels ─────────────────────────────────────────────────────── */
.card {
    background: var(--c-card);
    border: 1px solid var(--c-hairline);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}
.card-header {
    background: var(--c-card);
    border-bottom: 1px solid var(--c-hairline);
    padding: 1.15rem 1.35rem;
}
.card-header h2, .card-header h3, .card-header h4, .card-header h5 { margin-bottom: 0; }
.card-body { padding: 1.35rem; }
.card.shadow, .card.shadow-sm { box-shadow: var(--shadow) !important; }

/* Page-title rule under the main heading of a card header */
.card-header > h2::after, .card-header > .h2::after {
    content: "";
    display: block;
    width: 52px; height: 3px;
    background: var(--c-gold);
    margin-top: .5rem;
}

/* ── Buttons ────────────────────────────────────────────────────────────── */
.btn {
    --bs-btn-padding-y: .55rem;
    --bs-btn-padding-x: 1.1rem;
    --bs-btn-font-weight: 600;
    --bs-btn-border-radius: var(--radius-sm);
    letter-spacing: .01em;
}
.btn-sm { --bs-btn-padding-y: .4rem; --bs-btn-padding-x: .75rem; --bs-btn-font-size: .9375rem; }
.btn-lg { --bs-btn-padding-y: .75rem; --bs-btn-padding-x: 1.5rem; }

/* Primary = gold with graphite text (5.9:1). White on gold would be 2.3:1. */
.btn-primary {
    --bs-btn-bg: var(--c-gold);
    --bs-btn-border-color: var(--c-gold);
    --bs-btn-color: var(--c-graphite);
    --bs-btn-hover-bg: #B8974A;
    --bs-btn-hover-border-color: #B8974A;
    --bs-btn-hover-color: var(--c-graphite-deep);
    --bs-btn-active-bg: var(--c-gold-dark);
    --bs-btn-active-border-color: var(--c-gold-dark);
    --bs-btn-active-color: #fff;
    --bs-btn-disabled-bg: #E2D6B8;
    --bs-btn-disabled-border-color: #E2D6B8;
    --bs-btn-disabled-color: #7A736A;
}
.btn-secondary {
    --bs-btn-bg: transparent;
    --bs-btn-border-color: var(--c-hairline);
    --bs-btn-color: var(--c-text);
    --bs-btn-hover-bg: #EFEBE3;
    --bs-btn-hover-border-color: #D9D3C6;
    --bs-btn-hover-color: var(--c-graphite);
    --bs-btn-active-bg: #E7E2D8;
    --bs-btn-active-border-color: #D9D3C6;
    --bs-btn-active-color: var(--c-graphite);
}
.btn-dark {
    --bs-btn-bg: var(--c-graphite);
    --bs-btn-border-color: var(--c-graphite);
    --bs-btn-hover-bg: var(--c-graphite-deep);
    --bs-btn-hover-border-color: var(--c-graphite-deep);
    --bs-btn-active-bg: #000;
}
.btn-success {
    --bs-btn-bg: var(--c-sage); --bs-btn-border-color: var(--c-sage);
    --bs-btn-hover-bg: #35573D; --bs-btn-hover-border-color: #35573D;
    --bs-btn-active-bg: #2C4A34;
}
/* AI actions: graphite with a gold sheen, so they read apart from plain buttons */
.btn-ai {
    --bs-btn-color: #E3CC8F;
    --bs-btn-bg: var(--c-graphite);
    --bs-btn-border-color: var(--c-gold-dark);
    --bs-btn-hover-color: var(--c-graphite-deep);
    --bs-btn-hover-bg: var(--c-gold);
    --bs-btn-hover-border-color: var(--c-gold);
    --bs-btn-active-color: var(--c-graphite-deep);
    --bs-btn-active-bg: #B8974A;
    --bs-btn-active-border-color: #B8974A;
    background-image: linear-gradient(135deg, var(--c-graphite-deep), var(--c-graphite-soft));
    box-shadow: 0 0 0 1px rgba(198, 167, 94, .25) inset, 0 4px 14px rgba(198, 167, 94, .18);
}
.btn-ai:hover, .btn-ai:active, .btn-ai.show { background-image: none; }
.btn-ai .fa-wand-magic-sparkles { color: var(--c-gold); }
.btn-ai:hover .fa-wand-magic-sparkles, .btn-ai.show .fa-wand-magic-sparkles { color: inherit; }

.btn-danger {
    --bs-btn-bg: var(--c-brick); --bs-btn-border-color: var(--c-brick);
    --bs-btn-hover-bg: #772626; --bs-btn-hover-border-color: #772626;
    --bs-btn-active-bg: #661F1F;
}
/* Info / warning exist in the markup: keep them quiet so gold stays the accent */
.btn-info {
    --bs-btn-bg: var(--c-graphite-soft); --bs-btn-border-color: var(--c-graphite-soft);
    --bs-btn-color: #fff;
    --bs-btn-hover-bg: var(--c-graphite); --bs-btn-hover-border-color: var(--c-graphite);
    --bs-btn-hover-color: #fff; --bs-btn-active-color: #fff;
}
.btn-warning {
    --bs-btn-bg: var(--c-gold-tint); --bs-btn-border-color: #E3D6B6;
    --bs-btn-color: var(--c-gold-deep);
    --bs-btn-hover-bg: #EBE0C6; --bs-btn-hover-border-color: #D9C9A6;
    --bs-btn-hover-color: var(--c-gold-deep);
}
.btn-outline-primary {
    --bs-btn-color: var(--c-gold-deep);
    --bs-btn-border-color: var(--c-gold-dark);
    --bs-btn-hover-bg: var(--c-gold);
    --bs-btn-hover-border-color: var(--c-gold);
    --bs-btn-hover-color: var(--c-graphite);
    --bs-btn-active-bg: var(--c-gold-dark);
    --bs-btn-active-border-color: var(--c-gold-dark);
    --bs-btn-active-color: #fff;
}
.btn-outline-secondary {
    --bs-btn-color: var(--c-text);
    --bs-btn-border-color: var(--c-hairline);
    --bs-btn-hover-bg: #EFEBE3;
    --bs-btn-hover-border-color: #D9D3C6;
    --bs-btn-hover-color: var(--c-graphite);
}
.btn-outline-danger { --bs-btn-color: var(--c-brick); --bs-btn-border-color: #D8B4B4;
    --bs-btn-hover-bg: var(--c-brick); --bs-btn-hover-border-color: var(--c-brick); }
.btn-outline-info { --bs-btn-color: var(--c-graphite); --bs-btn-border-color: var(--c-hairline);
    --bs-btn-hover-bg: var(--c-graphite); --bs-btn-hover-border-color: var(--c-graphite); --bs-btn-hover-color: #fff; }

.btn:focus-visible, .form-control:focus, .form-select:focus, .form-check-input:focus, a:focus-visible {
    box-shadow: 0 0 0 3px var(--bs-focus-ring-color) !important;
    outline: none;
}

/* ── Tables ─────────────────────────────────────────────────────────────── */
.table {
    --bs-table-bg: var(--c-card);
    --bs-table-color: var(--c-text);
    --bs-table-border-color: var(--c-hairline);
    --bs-table-hover-bg: var(--c-gold-tint);
    --bs-table-hover-color: var(--c-graphite);
    margin-bottom: 0;
}
.table > :not(caption) > * > * { padding: .95rem 1rem; }   /* taller rows */
.table thead th, .table > thead > tr > th {
    background: var(--c-graphite);
    color: #fff;
    font-weight: 600;
    font-size: .9375rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    border-bottom: 0;
    white-space: nowrap;
}
.table thead.table-dark th { background: var(--c-graphite); }
.table-hover > tbody > tr:hover > * { background-color: var(--c-gold-tint); }
.table > tbody > tr.table-warning > * {       /* "needs attention" rows */
    background-color: var(--c-gold-tint);
    box-shadow: inset 4px 0 0 var(--c-gold);
}
html[dir="rtl"] .table > tbody > tr.table-warning > * { box-shadow: inset -4px 0 0 var(--c-gold); }

/* ── Badges: tinted, not saturated ──────────────────────────────────────── */
.badge {
    font-weight: 600;
    font-size: .8125rem;
    padding: .4em .7em;
    border-radius: 999px;
    letter-spacing: .01em;
}
.badge.bg-primary  { background: var(--c-gold-tint) !important; color: var(--c-gold-deep) !important; }
.badge.bg-secondary{ background: #EDEAE3 !important;           color: var(--c-text-muted) !important; }
.badge.bg-success  { background: var(--c-sage-tint) !important; color: var(--c-sage) !important; }
.badge.bg-danger   { background: var(--c-brick-tint) !important; color: var(--c-brick) !important; }
.badge.bg-warning  { background: var(--c-gold-tint) !important; color: var(--c-gold-deep) !important; }
.badge.bg-info     { background: var(--c-info-tint) !important;  color: var(--c-graphite) !important; }
.badge.bg-white    { background: #fff !important; }

/* ── Forms ──────────────────────────────────────────────────────────────── */
.form-label, label.form-label, .col-form-label {
    font-weight: 600;
    color: var(--c-graphite);
    margin-bottom: .4rem;
}
.form-control, .form-select {
    border-color: #D9D3C6;
    border-radius: var(--radius-sm);
    padding: .6rem .85rem;
    background-color: #fff;
    color: var(--c-text);
}
.form-control:focus, .form-select:focus { border-color: var(--c-gold-dark); }
.form-control::placeholder { color: #9A9690; }
.form-text { color: var(--c-text-muted); }
.input-group-text { background: var(--c-gold-tint); border-color: #D9D3C6; color: var(--c-gold-deep); }
.form-check-input:checked { background-color: var(--c-gold-dark); border-color: var(--c-gold-dark); }

/* Grouped bilingual field blocks (client forms) */
.card .card-header.bg-light, .bg-light { background: #F1EEE7 !important; }

/* ── Alerts ─────────────────────────────────────────────────────────────── */
.alert {
    border: 1px solid var(--c-hairline);
    border-radius: var(--radius-sm);
    padding: 1rem 1.15rem;
}
.alert-success { background: var(--c-sage-tint);  border-color: #CFE0D4; color: #2C4A34; }
.alert-danger  { background: var(--c-brick-tint); border-color: #E6CACA; color: #6E2323; }
.alert-warning { background: var(--c-gold-tint);  border-color: #E3D6B6; color: var(--c-gold-deep); }
.alert-info    { background: var(--c-info-tint);  border-color: #D6DEE6; color: var(--c-graphite); }
.alert-secondary { background: #EFEBE3; border-color: var(--c-hairline); color: var(--c-text); }

/* ── Dropdowns, modals, tabs ────────────────────────────────────────────── */
.dropdown-menu {
    border: 1px solid var(--c-hairline);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .4rem;
}
.dropdown-item { border-radius: var(--radius-sm); padding: .55rem .85rem; font-weight: 500; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--c-gold-tint); color: var(--c-graphite); }
.dropdown-item.disabled { color: var(--c-text-muted); font-size: .875rem; text-transform: uppercase; letter-spacing: .05em; }
.dropdown-divider { border-color: var(--c-hairline); }

.modal-content { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); }
.modal-header { background: var(--c-graphite); color: #fff; border-bottom: 3px solid var(--c-gold);
    border-radius: var(--radius) var(--radius) 0 0; padding: 1.1rem 1.35rem; }
.modal-header .modal-title, .modal-header h5 { color: #fff; font-family: 'Playfair Display', Georgia, serif; }
.modal-header .btn-close { filter: invert(1) grayscale(1) brightness(2); }
.modal-footer { border-top: 1px solid var(--c-hairline); padding: 1rem 1.35rem; }

.nav-tabs .nav-link { color: var(--c-text-muted); font-weight: 600; border: 0; border-bottom: 3px solid transparent; }
.nav-tabs .nav-link.active { color: var(--c-graphite); background: transparent; border-bottom-color: var(--c-gold); }

/* ── Buttons grouped in toolbars: allow wrapping, keep targets big ──────── */
.btn-group { flex-wrap: wrap; gap: .5rem; }
/* Row actions stay on one line; the table scrolls instead of stacking buttons */
.table .btn-group { flex-wrap: nowrap; gap: .35rem; }
.table td:last-child { white-space: nowrap; }
.btn-group > .btn, .btn-group > .dropdown > .btn { border-radius: var(--radius-sm) !important; }
.card-header .btn-group { justify-content: flex-end; }

/* ── Empty states ───────────────────────────────────────────────────────── */
.text-muted { color: var(--c-text-muted) !important; }
tbody .text-muted i.fas, tbody .text-muted i.fa { color: var(--c-gold-dark); opacity: .55; }

/* ── Chat widget frame (the iframe lives on every page) ─────────────────── */
#juristai-iframe { box-shadow: 0 8px 28px rgba(35, 31, 32, .28) !important; }

/* ── Print: keep screens colourful, printouts plain ─────────────────────── */
@media print {
    .navbar, #juristai-container, .btn, .dropdown { display: none !important; }
    .card { box-shadow: none; border: 0; }
    body { background: #fff; }
}

/* ── Dossier header: the case identity, readable at a glance ────────────── */
.dossier-title__ref {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-bottom: .15rem;
}
.dossier-title__number {
    font-family: 'Inter', system-ui, sans-serif;
    font-weight: 700;
    font-size: .95rem;
    letter-spacing: .12em;
    color: var(--c-gold-deep);
}
.dossier-title h2 { font-size: 1.85rem; line-height: 1.2; }
.dossier-title h2::after { content: none; }      /* the gold rule belongs to list pages */
.dossier-title__meta {
    display: flex;
    flex-wrap: wrap;
    gap: .35rem 1.5rem;
    margin-top: .55rem;
    color: var(--c-text-muted);
    font-size: .95rem;
}
.dossier-title__meta i { color: var(--c-gold-dark); margin-inline-end: .3rem; }
.dossier-title__meta strong { color: var(--c-text); font-weight: 600; }

/* ── Narrow screens (smaller laptops, split-screen work) ────────────────── */
.card-header.d-flex { flex-wrap: wrap; gap: .85rem; }
/* Case numbers must never break mid-value (first column), nor dates/refs */
.table > tbody > tr > td:first-child, .table > thead > tr > th:first-child,
.table td code, .dossier-title__number { white-space: nowrap; }
@media (max-width: 991.98px) {
    .table > :not(caption) > * > * { padding: .8rem .7rem; }
    h2, .h2 { font-size: 1.5rem; }
    .dossier-title h2 { font-size: 1.45rem; }
    .card-body { padding: 1.1rem; }
    /* Toolbars in headers go full width; row actions stay on one line */
    .card-header .btn-group { width: 100%; }
    .table .btn-group { flex-wrap: nowrap; gap: .25rem; }
}

/* ── Empty states: say what to do next, not just "nothing here" ─────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--c-text);
}
.empty-state > i {
    font-size: 2.25rem;
    color: var(--c-gold-dark);
    opacity: .5;
    margin-bottom: 1rem;
    display: block;
}
.empty-state p { margin-inline: auto; max-width: 42ch; }

/* ── Login ──────────────────────────────────────────────────────────────── */
.login-page { margin-top: 4.5rem; }
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand__rule { display: inline-block; width: 46px; height: 3px; background: var(--c-gold); margin-bottom: 1rem; }
.login-brand h1 { font-size: 2.1rem; margin-bottom: .35rem; }
.login-brand p { color: var(--c-text-muted); margin-bottom: 0; }
.login-page .card-header { text-align: center; }
.login-page .btn[type="submit"], .login-page button[type="submit"] { width: 100%; }

/* ══════════════════════════════════════════════════════════════════════════
   First-run guided tour (static/js/onboarding.js)

   The spotlight is a box-shadow trick rather than an SVG mask or four
   positioned panels: one element, one repaint, and the hole follows the target
   exactly. The shadow spread is large enough to cover any viewport.
   ══════════════════════════════════════════════════════════════════════════ */
.tour-overlay {
    position: absolute;
    inset: 0;
    /* The assistant's launcher sits at the maximum z-index. The overlay is added
       to the page later, so at the same value it stacks above it; at 2000 the
       launcher covered the card on a phone. */
    z-index: 2147483647;
    pointer-events: auto;
}

.tour-spot {
    position: absolute;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 0 9999px rgba(35, 31, 32, .68);
    border: 2px solid var(--c-gold);
    transition: top .2s ease, left .2s ease, width .2s ease, height .2s ease;
    pointer-events: none;
}

.tour-pop {
    position: absolute;
    width: min(360px, calc(100vw - 32px));
    background: var(--c-card);
    border: 1px solid var(--c-hairline);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(35, 31, 32, .28);
    padding: 20px 22px;
}

.tour-pop__step {
    font-size: .75rem;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--c-gold-deep);
    font-weight: 600;
    margin: 0 0 6px;
}

.tour-pop__title {
    font-family: 'Playfair Display', Georgia, serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--c-graphite);
    margin: 0 0 8px;
}

.tour-pop__body {
    font-size: .9375rem;
    color: var(--c-text-muted);
    margin: 0 0 18px;
    line-height: 1.55;
}
.tour-pop__body code {
    background: var(--c-gold-tint);
    color: var(--c-gold-deep);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: .875em;
}

.tour-pop__actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;              /* three buttons do not fit a 316px card on one line */
    gap: 8px 12px;
}
.tour-pop__nav { display: flex; gap: 8px; margin-left: auto; }

.tour-pop button {
    font: inherit;
    font-size: .875rem;
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    cursor: pointer;
    border: 1px solid transparent;
}
.tour-skip {
    background: transparent;
    color: var(--c-text-muted);
    border: 0;
    padding-left: 0;
    padding-right: 4px;
    white-space: nowrap;
}
.tour-skip:hover { color: var(--c-text); text-decoration: underline; }
.tour-prev {
    background: transparent;
    color: var(--c-graphite);
    border-color: var(--c-hairline);
}
.tour-prev:hover { border-color: var(--c-graphite); }
.tour-next {
    background: var(--c-gold);
    color: var(--c-graphite);     /* 8.2:1 */
    font-weight: 600;
}
.tour-next:hover { background: var(--c-gold-dark); color: #fff; }

@media (prefers-reduced-motion: reduce) {
    .tour-spot { transition: none; }
}

/* On a phone the card is a sheet along the bottom edge rather than a tooltip
   hung off its target. Placed against the target it landed wherever there was
   room — under the assistant's launcher, or past the screen edge. */
@media (max-width: 575.98px) {
    .tour-pop {
        position: fixed;
        left: 12px; right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        top: auto;
        width: auto;
        max-height: 70vh;
        overflow-y: auto;
        padding: 18px;
    }
    [id^="tour-"] { scroll-margin-top: 84px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   Phones

   The application was built for a desk: a wide table of dossiers, toolbars with
   four buttons on a line, and forms in two columns. Bootstrap's grid already
   stacks the columns, so what was left was everything the grid does not touch —
   toolbars, tap targets, the dossier table, and the assistant's panel, which at
   450px wide simply hung off the side of the screen.

   Two breakpoints: 767.98px for anything narrower than a tablet in landscape,
   575.98px for phones proper, where the dossier table stops being a table.
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 767.98px) {
    /* A 16px gutter, matching the landing page. Bootstrap's 12px reads as an
       accident on a phone; less than that and text touches the bezel. */
    .container, .container-fluid { padding-inline: 16px; }
    .container.mt-4 { margin-top: 1rem !important; }

    h2, .h2 { font-size: 1.35rem; }
    h3, .h3 { font-size: 1.15rem; }
    .dossier-title h2 { font-size: 1.3rem; }

    .card { border-radius: var(--radius-sm); }
    .card-header, .card-body { padding: 1rem; }
    .card.mb-4 { margin-bottom: 1rem !important; }

    /* Toolbars: one action per line reads better than four squeezed onto one.
       The header's own flex row wraps, and each group fills the width. */
    .card-header { flex-wrap: wrap; }
    .card-header > .d-flex { width: 100%; flex-wrap: wrap; }
    .card-header > .d-flex > .btn,
    .card-header > .d-flex > form > .btn { flex: 1 1 auto; }
    .card-header .dropdown { flex: 1 1 100%; }
    .card-header .dropdown > .btn { width: 100%; white-space: normal; }
    .card-header .dropdown { min-width: 0; }
    .card-header .dropdown-menu { width: 100%; }

    /* Segmented filters share the width instead of overflowing it. */
    .btn-group { width: 100%; }
    .btn-group > .btn { flex: 1 1 0; }
    /* …except inside a table row, where they are icon-sized already. */
    .table .btn-group { width: auto; }
    .table .btn-group > .btn { flex: 0 0 auto; }

    /* 44px is the tap target both Apple and Google document as the minimum.
       Below that, a mis-tap on "Supprimer" is a real possibility. */
    .btn { min-height: 44px; }
    .btn-sm { min-height: 38px; }
    .navbar-toggler { min-height: 44px; min-width: 44px; }

    /* Safari zooms the whole page when a focused field's text is under 16px,
       and never zooms back out. */
    .form-control, .form-select, textarea, input[type="text"],
    input[type="number"], input[type="date"], input[type="password"] { font-size: 16px; }
    .form-label { margin-bottom: .25rem; }
    .mb-3 { margin-bottom: .85rem !important; }

    /* Tables that stay tables scroll sideways, with momentum and a hint that
       there is more to the right. */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
        background:
            linear-gradient(to right, var(--c-card) 30%, rgba(255, 255, 255, 0)),
            linear-gradient(to left,  var(--c-card) 30%, rgba(255, 255, 255, 0)) 100% 0,
            radial-gradient(farthest-side at 0 50%, rgba(35, 31, 32, .12), transparent),
            radial-gradient(farthest-side at 100% 50%, rgba(35, 31, 32, .12), transparent) 100% 0;
        background-repeat: no-repeat;
        background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
        background-attachment: local, local, scroll, scroll;
    }
    .table > :not(caption) > * > * { padding: .65rem .55rem; }

    /* Modals use the screen rather than sitting in a letterbox. */
    .modal-dialog { margin: .5rem; }
    .modal-header, .modal-body, .modal-footer { padding: 1rem; }
    .modal-footer .btn { flex: 1 1 auto; }

    /* The dossier's summary panels: label and value on one line each. */
    .dossier-title__meta { gap: .35rem .9rem; }

    .empty-state { padding: 2rem 1rem; }

    /* Nothing may push the page wider than the screen. A court reference, a
       file name or a pasted URL with no spaces in it otherwise does exactly
       that, and then every page scrolls sideways, not just the one element. */
    img, pre, code, table { max-width: 100%; }
    pre { overflow-x: auto; white-space: pre-wrap; }
    .alert, .card-body p, .dossier-title h2 { overflow-wrap: anywhere; }
}

@media (max-width: 575.98px) {
    /* ── A table of dossiers is not a table on a phone ──────────────────────
       Five columns in 360px means either a 9px font or sideways scrolling on
       the screen people check between hearings. Each row becomes a card and
       each cell carries its own label, taken from `data-label` in the markup
       so the header row can be dropped. Opt in with `.table-stack`; every
       other table keeps scrolling, which is right for figures that need to
       line up. */
    .table-stack thead { display: none; }
    .table-stack, .table-stack > tbody, .table-stack > tbody > tr,
    .table-stack > tbody > tr > td { display: block; width: 100%; }
    .table-stack { border-collapse: separate; }

    .table-stack > tbody > tr {
        border: 1px solid var(--c-hairline);
        border-radius: var(--radius-sm);
        background: var(--c-card);
        padding: .85rem 1rem;
        margin-bottom: .75rem;
    }
    /* Bootstrap's striping and hover colour cells, which now fill the card. */
    .table-stack.table-striped > tbody > tr > td,
    .table-stack.table-hover > tbody > tr:hover > td { background: transparent; }
    .table-stack > tbody > tr.table-warning {
        border-color: var(--c-gold);
        box-shadow: inset 0 0 0 1px var(--c-gold);
    }
    .table-stack > tbody > tr.table-warning > * { box-shadow: none; }

    /* The value wraps; only the reference in the title cell stays on one line,
       which the rule above the breakpoints already takes care of. */
    .table-stack > tbody > tr > td:not(:first-child) { white-space: normal; }
    .table-stack > tbody > tr > td {
        border: 0;
        padding: .3rem 0;
        display: flex;
        gap: 1rem;
        align-items: baseline;
        justify-content: space-between;
        text-align: end;
        white-space: normal;
    }
    .table-stack > tbody > tr > td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-size: .8125rem;
        font-weight: 600;
        letter-spacing: .03em;
        text-transform: uppercase;
        color: var(--c-text-muted);
        text-align: start;
    }
    /* A cell with no label — the reference line, the actions — spans the card. */
    .table-stack > tbody > tr > td:not([data-label])::before { content: none; }
    .table-stack > tbody > tr > td:not([data-label]) { justify-content: flex-start; text-align: start; }

    /* The reference reads as the card's title. */
    .table-stack > tbody > tr > td.stack-title {
        font-size: 1.0625rem;
        padding-bottom: .5rem;
        margin-bottom: .35rem;
        border-bottom: 1px solid var(--c-hairline);
        flex-wrap: wrap;
        gap: .5rem;
    }
    /* Actions sit at the foot of the card, filling the width. */
    .table-stack > tbody > tr > td.stack-actions {
        padding-top: .75rem;
        margin-top: .35rem;
        border-top: 1px solid var(--c-hairline);
    }
    .table-stack > tbody > tr > td.stack-actions .btn-group { width: 100%; }
    .table-stack > tbody > tr > td.stack-actions .btn-group > .btn { flex: 1 1 0; }
    /* Icon-only buttons need their label back once there is room for it. */
    .table-stack > tbody > tr > td.stack-actions .btn > span { display: inline !important; }

    /* An empty state inside a stacked table has no card frame around it. */
    .table-stack > tbody > tr:has(.empty-state) { border: 0; background: transparent; padding: 0; }

    /* The dossier's own key/value tables read the same way. */
    .table-responsive { background-image: none; }
}

/* ── Dossier status: one colour per stage, same on the list, the page and the dashboard ── */
.status-badge, .status-select { font-weight: 600; border: 1px solid transparent; }
.status-switch { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.status-select { width: auto; display: inline-block; padding-block: .15rem; font-size: .85rem; }
.status-en_cours   { background-color: var(--c-info-tint);  color: #2E4A66; }
.status-en_attente { background-color: var(--c-gold-tint);  color: var(--c-gold-deep); }
.status-juge       { background-color: #ECE7F3;             color: #4B3A6B; }
.status-cloture    { background-color: var(--c-sage-tint);  color: var(--c-sage); }

/* ── Dashboard ──────────────────────────────────────────────────────────── */
.kpi {
    display: flex; flex-direction: column; height: 100%;
    padding: .9rem 1rem; border: 1px solid var(--c-hairline); border-radius: 10px;
    background: var(--c-card); border-inline-start: 4px solid var(--c-graphite);
}
.kpi--good  { border-inline-start-color: var(--c-sage); }
.kpi--warn  { border-inline-start-color: var(--c-gold); }
.kpi--alert { border-inline-start-color: var(--c-brick); }
.kpi__value { font-size: 1.7rem; font-weight: 700; color: var(--c-graphite); line-height: 1.1; }
.kpi__label { font-weight: 600; color: var(--c-text); margin-top: .25rem; }
.kpi__sub   { font-size: .82rem; color: var(--c-text-muted); }
.chart-box { position: relative; height: 280px; }
.chart-box--small { height: 200px; }
.status-legend li { display: flex; justify-content: space-between; align-items: center; padding: .2rem 0; }
.bar-list li { display: flex; justify-content: space-between; gap: 1rem; padding: .3rem 0;
               border-bottom: 1px solid var(--c-hairline); }
.bar-list li:last-child { border-bottom: 0; }
.activity-table td, .activity-table th { white-space: nowrap; }
@media (max-width: 575.98px) {
    .kpi__value { font-size: 1.35rem; }
    .chart-box { height: 220px; }
    #dashboard-period { width: 100%; }
    #dashboard-period .btn-group { width: 100%; }
    #dashboard-period .btn-group .btn { flex: 1 1 0; padding-inline: .3rem; }
    #dashboard-period select { width: 100% !important; }
}

/* ── Drafting workspace (Travailler avec JuristAI) ──────────────────────── */
.draft-text {
    font-family: 'Amiri', 'Traditional Arabic', 'Times New Roman', serif;
    font-size: 1.1rem;
    line-height: 1.9;
    min-height: 6rem;
    resize: vertical;
    overflow: hidden;
}
.draft-heading { color: var(--c-gold-deep); font-weight: 600; text-decoration: underline; margin-bottom: .35rem; }
.draft-flash { box-shadow: 0 0 0 .2rem var(--c-gold); transition: box-shadow .3s; }
.draft-proposal {
    border: 1px solid var(--c-hairline);
    border-inline-start: 3px solid var(--c-gold);
    border-radius: .375rem;
    padding: .75rem;
    margin-bottom: .75rem;
    background: var(--c-card);
}
.draft-proposal-text, .draft-similar-text, .draft-version-text {
    white-space: pre-wrap;
    font-family: 'Amiri', 'Traditional Arabic', 'Times New Roman', serif;
    line-height: 1.8;
}
.draft-proposal-text { font-size: 1.05rem; }
.draft-similar-text { max-height: 14rem; overflow-y: auto; background: var(--c-surface); padding: .5rem; border-radius: .25rem; }
.draft-similar + .draft-similar { border-top: 1px solid var(--c-hairline); margin-top: .75rem; padding-top: .75rem; }
.draft-answer { white-space: pre-wrap; }
.draft-facts dd { margin-bottom: .25rem; word-break: break-word; }
.draft-version-body { max-height: 60vh; overflow-y: auto; }
@media (min-width: 992px) {
    .draft-panel { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow-y: auto; }
}
.draft-text:lang(fr), .draft-proposal-text:lang(fr), .draft-similar-text:lang(fr), .draft-version-body:lang(fr) .draft-version-text {
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.6;
}

/* ── AI credits bar (navbar, "Consommation IA", "Mon utilisation de l'IA") ── */
.ai-bar { height: .5rem; background: var(--c-hairline); border-radius: 1rem; overflow: hidden; min-width: 6rem; }
.ai-bar__fill { height: 100%; background: var(--c-sage); border-radius: 1rem; }
.ai-bar--warn .ai-bar__fill { background: var(--c-gold); }
.ai-bar--empty .ai-bar__fill { background: var(--c-brick); }
.ai-grant input { max-width: 7rem; }
.navbar .ai-nav { display: flex; flex-direction: column; justify-content: center; gap: .15rem; min-width: 7rem;
                  color: rgba(255,255,255,.75); font-size: .75rem; text-decoration: none; padding: .25rem .5rem; }
.navbar .ai-nav:hover { color: #fff; }
.navbar .ai-nav .ai-bar { background: rgba(255,255,255,.2); height: .35rem; }

/* ── AI traces (Consommation IA → sessions, requête) ── */
.ai-latency { position: relative; height: 1.4rem; background: var(--c-hairline); border-radius: var(--radius-sm); overflow: hidden; }
.ai-latency__bar { position: absolute; inset: 0 auto 0 0; background: var(--c-gold); opacity: .55; }
.ai-latency__value { position: relative; display: block; padding: 0 .4rem; font-size: .75rem; line-height: 1.4rem; white-space: nowrap; }
.ai-tabs { flex-wrap: wrap; }
.ai-pack dl { row-gap: .15rem; }
.ai-pack__lines li { display: grid; grid-template-columns: 1fr auto 5.5rem; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid var(--c-hairline); }

/* ── JuristAI preferences (playbooks, memory, skills) ── */
.juristai-pref > summary { cursor: pointer; list-style: none; }
.juristai-pref > summary::-webkit-details-marker { display: none; }
.juristai-preview { white-space: pre-wrap; background: var(--c-surface, #fff); border: 1px solid var(--c-hairline); border-radius: var(--radius-sm); padding: .75rem; font-size: .85rem; max-height: 22rem; overflow: auto; }
