:root {
    --navy: #0b1628;
    --navy-mid: #12233f;
    --blue: #1e5bb8;
    --blue-dark: #15448c;
    --yellow: #f5c518;
    --yellow-soft: #fff6d6;
    --white: #ffffff;
    --surface: #ffffff;
    --surface-2: #f4f7fc;
    --surface-3: #eef3fa;
    --text: #121826;
    --muted: #5b677a;
    --border: #d5deec;
    --border-strong: #b8c6dc;
    --ok: #1f6b2d;
    --ok-bg: #e7f6ea;
    --err: #8a1f1f;
    --err-bg: #ffe8e8;
    --topbar-h: 60px;
    --radius: 12px;
    --radius-sm: 9px;
    --shadow: 0 12px 30px rgba(11, 22, 40, 0.08);
    --shadow-sm: 0 4px 14px rgba(11, 22, 40, 0.06);
    --font: "Source Sans 3", "Segoe UI", sans-serif;
    --display: "Barlow Condensed", "Arial Narrow", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html, body { margin: 0; }

body {
    font-family: var(--font);
    color: var(--text);
    min-height: 100vh;
    background:
        radial-gradient(ellipse 55% 40% at 100% 0%, rgba(245, 197, 24, 0.16), transparent 55%),
        radial-gradient(ellipse 45% 35% at 0% 100%, rgba(30, 91, 184, 0.12), transparent 50%),
        linear-gradient(180deg, #e6edf7 0%, #eef2f8 40%, #f5f7fb 100%);
}

[hidden],
.is-hidden { display: none !important; }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ===== Topbar ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 120;
    min-height: var(--topbar-h);
    background:
        linear-gradient(105deg, rgba(245, 197, 24, 0.12), transparent 35%),
        linear-gradient(180deg, var(--navy-mid), var(--navy));
    color: var(--white);
    padding: 0.55rem clamp(0.9rem, 2.5vw, 1.4rem);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    border-bottom: 3px solid var(--yellow);
    box-shadow: 0 8px 24px rgba(11, 22, 40, 0.28);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    justify-content: flex-end;
}

.topbar a {
    color: var(--white);
    text-decoration: none;
    font-weight: 600;
    font-size: 0.95rem;
    opacity: 0.95;
}

.topbar a:hover { opacity: 1; color: var(--yellow); }

.topbar-user {
    opacity: 0.88;
    font-size: 0.92rem;
    padding: 0.28rem 0.65rem;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
}

.brand {
    font-family: var(--display);
    font-size: 1.55rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: #fff;
    text-decoration: none;
}

.brand span { color: var(--yellow); }

/* ===== Layout ===== */
.container {
    width: min(1280px, calc(100% - 1.5rem));
    margin: 1.15rem auto 2.25rem;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1.45fr) minmax(300px, 0.9fr);
    gap: 1rem;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.15rem 1.2rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.volet-commandes,
.volet-messages {
    margin-bottom: 0;
    min-width: 0;
}

.volet-messages {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    min-height: 620px;
    max-height: calc(100vh - 110px);
    position: sticky;
    top: calc(var(--topbar-h) + 12px);
}

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    margin-bottom: 0.95rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.page-head p { margin: 0.3rem 0 0; }

h1, h2, h3 {
    margin-top: 0;
    color: var(--blue-dark);
    font-family: var(--display);
    letter-spacing: 0.01em;
}

h1 {
    font-size: clamp(1.55rem, 3vw, 1.95rem);
    font-weight: 700;
    margin-bottom: 0.15rem;
    line-height: 1.05;
}

h2 {
    font-size: 1.25rem;
    font-weight: 700;
}

h3 {
    font-size: 1.05rem;
    font-weight: 700;
}

/* ===== Login ===== */
body.page-login {
    background:
        radial-gradient(ellipse 70% 55% at 85% 10%, rgba(245, 197, 24, 0.22), transparent 55%),
        radial-gradient(ellipse 50% 45% at 10% 90%, rgba(37, 99, 186, 0.35), transparent 58%),
        repeating-linear-gradient(90deg, transparent 0 71px, rgba(255, 255, 255, 0.03) 71px 72px),
        repeating-linear-gradient(0deg, transparent 0 71px, rgba(255, 255, 255, 0.025) 71px 72px),
        linear-gradient(165deg, #153156 0%, #0b1628 45%, #0a2038 100%);
    color: #fff;
    min-height: 100vh;
}

body.page-login .topbar {
    background: transparent;
    box-shadow: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.login-wrap {
    max-width: 440px;
    margin: 3.5rem auto 2rem;
}

body.page-login .login-wrap .card {
    background: rgba(255, 255, 255, 0.97);
    color: var(--text);
    border: none;
    box-shadow: 0 24px 50px rgba(0, 0, 0, 0.35);
    padding: 1.5rem 1.45rem 1.6rem;
}

body.page-login .login-wrap h1 {
    font-size: 2rem;
}

body.page-login .login-wrap .btn-primary {
    width: 100%;
    min-height: 48px;
    margin-top: 0.25rem;
}

.login-kicker {
    margin: 0 0 0.35rem;
    font-size: 0.78rem;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #b8860b;
}

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.badge-attente { background: var(--yellow-soft); color: #7a5b00; }
.badge-planifiee { background: #dce9ff; color: var(--blue-dark); }
.badge-livree,
.badge-acceptee { background: var(--ok-bg); color: var(--ok); }
.badge-refusee { background: var(--err-bg); color: var(--err); }
.badge-cloturee { background: #eceff3; color: #445; }

/* ===== Forms ===== */
label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 650;
    font-size: 0.88rem;
    color: #2a3548;
}

input[type="text"],
input[type="password"],
input[type="date"],
input[type="search"],
input[type="file"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--white);
    margin-bottom: 0.75rem;
    font: inherit;
    color: var(--text);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus,
textarea:focus,
select:focus {
    outline: none;
    border-color: #7aa3e0;
    box-shadow: 0 0 0 3px rgba(30, 91, 184, 0.15);
}

textarea { min-height: 72px; resize: vertical; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.58rem 1rem;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    font: inherit;
    line-height: 1.2;
    transition: filter 0.12s ease, background 0.12s ease, transform 0.12s ease;
}

.btn:active { transform: translateY(1px); }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.88rem; }
.btn-primary { background: var(--blue); color: var(--white); }
.btn-primary:hover { background: var(--blue-dark); }
.btn-yellow { background: var(--yellow); color: #1a1a1a; }
.btn-yellow:hover { filter: brightness(0.96); }
.btn-danger { background: #c62828; color: #fff; }
.btn-danger:hover { filter: brightness(0.95); }
.btn-ghost {
    background: transparent;
    color: var(--blue-dark);
    border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.alert {
    padding: 0.75rem 0.95rem;
    border-radius: var(--radius-sm);
    margin: 0 0 0.9rem;
    font-weight: 600;
}
.alert-error { background: var(--err-bg); color: var(--err); border: 1px solid #f2b4b4; }
.alert-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #b7e0b7; }
.muted { color: var(--muted); font-size: 0.9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.mb-0 { margin-bottom: 0; }
.pad { padding: 1rem; }

/* ===== Volet discussions ===== */
.msg-volet {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    flex: 1;
}

.msg-volet-head {
    padding: 1rem 1rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, #f5f8fd, #fff);
}

.msg-volet-head h2 { margin: 0; }

.msg-toolbar {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 0.5rem;
    background: var(--surface-2);
}

.msg-toolbar input,
.msg-toolbar select { margin: 0; }

.discussions-list {
    flex: 1;
    overflow: auto;
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    min-height: 0;
}

.discussion-item {
    text-align: left;
    border: 1px solid var(--border);
    background: #fbfcff;
    border-radius: 12px;
    padding: 0.7rem 0.8rem;
    cursor: pointer;
    display: grid;
    gap: 0.18rem;
    font: inherit;
    color: inherit;
    width: 100%;
    transition: border-color 0.12s ease, background 0.12s ease, box-shadow 0.12s ease;
}

.discussion-item:hover {
    border-color: #9bb8e8;
    background: #f3f7ff;
    box-shadow: var(--shadow-sm);
}

.discussion-item.has-msg {
    border-color: #e6c34a;
    background: var(--yellow-soft);
}

.discussion-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.discussion-top strong {
    color: var(--blue-dark);
    font-family: var(--display);
    font-size: 1.05rem;
}

.discussion-count {
    background: var(--blue);
    color: #fff;
    border-radius: 999px;
    min-width: 1.3rem;
    height: 1.3rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
    padding: 0 0.35rem;
}

.discussion-client { font-weight: 600; font-size: 0.92rem; }
.discussion-preview {
    color: var(--muted);
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.discussion-meta {
    color: #7a8699;
    font-size: 0.75rem;
    font-style: normal;
}

.discussion-detail {
    flex: 1;
    min-height: 0;
    overflow: auto;
    padding: 0.85rem 1rem 1rem;
    display: flex;
    flex-direction: column;
}

.discussion-detail h3 { margin: 0.55rem 0 0.1rem; }
.discussion-detail #discussion-ref { margin: 0 0 0.5rem; }

.thread {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.65rem;
    background: var(--surface-2);
    flex: 1;
    overflow: auto;
    margin: 0.5rem 0 0.75rem;
    min-height: 160px;
}

.thread-empty {
    color: var(--muted);
    text-align: center;
    padding: 1.5rem 0.75rem;
    font-size: 0.92rem;
}

.thread-msg {
    padding: 0.55rem 0.65rem;
    margin-bottom: 0.45rem;
    border-radius: 10px;
}

.thread-msg.thread-admin { background: #e8f0ff; border-left: 3px solid var(--blue); }
.thread-msg.thread-transporteur { background: #fff3c2; border-left: 3px solid var(--yellow); }

.thread-msg-head {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
    font-size: 0.82rem;
}

.thread-msg-head time { color: var(--muted); }

.chat-compose {
    border-top: 1px solid var(--border);
    padding-top: 0.65rem;
}

.chat-compose textarea { margin-bottom: 0.55rem; }

.chat-store {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ===== Filtres + pagination ===== */
.filters {
    display: grid;
    grid-template-columns: 1fr 160px auto;
    gap: 0.55rem;
    align-items: end;
    margin: 0.35rem 0 0.95rem;
    padding: 0.8rem;
    background: linear-gradient(180deg, #f7faff, #f2f6fc);
    border: 1px solid var(--border);
    border-radius: 12px;
}

.filters label { margin-bottom: 0.25rem; }
.filters input,
.filters select { margin-bottom: 0; }

.filtre-count {
    align-self: center;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
}

.pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
    margin-top: 0.85rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

.pager-btn {
    min-width: 2rem;
    height: 2rem;
    border: 1px solid var(--border);
    background: #fff;
    border-radius: 8px;
    font: inherit;
    font-weight: 700;
    color: var(--blue-dark);
    cursor: pointer;
}

.pager-btn:hover:not(:disabled) { background: #eef4ff; }
.pager-btn.is-active {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
}
.pager-btn:disabled { opacity: 0.4; cursor: default; }
.pager-gap { color: var(--muted); padding: 0 0.15rem; }
.pager-info {
    margin-left: auto;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
}

/* ===== Liste commandes ===== */
.commande-list {
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

.commande-item {
    border-bottom: 1px solid var(--border);
    background: var(--white);
}
.commande-item:last-child { border-bottom: none; }

.commande-toggle {
    width: 100%;
    display: grid;
    grid-template-columns: 110px minmax(0, 1fr) auto;
    gap: 0.45rem 0.65rem;
    align-items: center;
    padding: 0.8rem 0.9rem;
    border: none;
    background: transparent;
    text-align: left;
    cursor: pointer;
    font: inherit;
    color: inherit;
    transition: background 0.12s ease;
}

.commande-toggle:hover { background: #f5f8fd; }

.commande-ref {
    font-family: var(--display);
    font-weight: 700;
    color: var(--blue-dark);
    font-size: 1.05rem;
    letter-spacing: 0.02em;
}

.commande-main { min-width: 0; }
.commande-main strong {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.commande-main span {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.commande-meta {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.commande-chevron {
    width: 1.25rem;
    text-align: center;
    color: var(--blue);
    font-weight: 800;
    transition: transform 0.15s ease;
}
.commande-item.is-open .commande-chevron { transform: rotate(90deg); }
.commande-item.is-open .commande-toggle {
    background: #eef4ff;
    border-left: 3px solid var(--yellow);
    padding-left: calc(0.9rem - 3px);
}

.commande-panel {
    display: none;
    padding: 0 0.9rem 1rem;
    border-top: 1px dashed var(--border);
    background: linear-gradient(180deg, #f8faff, #f4f7fc);
}
.commande-item.is-open .commande-panel { display: block; }

.panel-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.7rem 0.95rem;
    padding-top: 0.85rem;
}

.meta-block {
    padding: 0.45rem 0.55rem;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(213, 222, 236, 0.7);
}

.meta-block .muted {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.15rem;
    font-weight: 700;
}

.panel-full { grid-column: 1 / -1; }

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.45rem;
}

.create-box {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 0.9rem;
    margin-top: 0.7rem;
    background: linear-gradient(180deg, #fbfcff, #f5f8fd);
}

.create-box summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--blue-dark);
    list-style: none;
    font-family: var(--display);
    font-size: 1.1rem;
}

.create-box summary::-webkit-details-marker { display: none; }
.create-box summary::before {
    content: "+ ";
    color: var(--yellow);
    font-weight: 800;
}
.create-box[open] summary::before { content: "− "; }
.create-box .create-body { margin-top: 0.85rem; }

/* ===== Manuel ===== */
.manuel {
    width: min(860px, calc(100% - 1.5rem));
    margin: 1.25rem auto 2.5rem;
}

.manuel .card { margin-bottom: 1rem; }
.manuel h1 { margin-bottom: 0.35rem; }
.manuel h2 {
    margin: 0 0 0.65rem;
    padding-bottom: 0.4rem;
    border-bottom: 2px solid var(--yellow);
}

.manuel ol, .manuel ul {
    margin: 0.4rem 0 0.8rem;
    padding-left: 1.2rem;
}

.manuel li { margin-bottom: 0.35rem; }

.manuel-shot {
    display: block;
    width: 100%;
    margin: 0.85rem 0 0.35rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    background: #fff;
}

.manuel figcaption {
    color: var(--muted);
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 980px) {
    .workspace { grid-template-columns: 1fr; }
    .volet-messages {
        position: static;
        max-height: none;
        min-height: 520px;
        order: 2;
    }
    .volet-commandes { order: 1; }
    .filters { grid-template-columns: 1fr; }
    .commande-toggle {
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "ref meta"
            "main main";
    }
    .commande-ref { grid-area: ref; }
    .commande-main { grid-area: main; }
    .commande-meta { grid-area: meta; }
    .panel-grid,
    .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
    .container { width: calc(100% - 1rem); }
    .card { padding: 0.95rem; }
    .topbar-user { display: none; }
}
