/* Portal styles, after the wireframes in docs/wireframes. */

:root {
    --bg: #F2F2F0;
    --surface: #FFFFFF;
    --subtle: #F7F7F5;
    --border: #D6D6D2;
    --border-strong: #B8B8B4;
    --divider: #EDEDEA;
    --text: #1F1F1F;
    --text-soft: #3A3A3A;
    --text-muted: #5C5C58;
    --text-inverse: #FFFFFF;
    --selected: #E9E9E6;
    --link-hover: #111111;
    --primary-hover: #000000;
    --danger: #8A1C1C;
    --danger-bg: #FBF1F1;
    --danger-border: #E2B4B4;
    --success: #1F5A2E;
    --success-bg: #EFF8F1;
    --success-border: #A9D3B5;
    --warning: #6B4E00;
    --warning-bg: #FCF6E6;
    --warning-border: #E5CF94;
    /* Outline of the logo's dark tile, which only needs one on a dark background. */
    --logo-ring: transparent;
    --radius: 8px;
    color-scheme: light;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

/*
 * Dark theme, chosen in the settings (data-theme="dark" on <html>, set by the
 * server from a cookie), or following the device when nothing is chosen.
 * Text contrasts are AA (4.5:1 at least) on every background they sit on.
 * Both blocks hold the same values.
 */
:root[data-theme="dark"] {
    --bg: #161615;
    --surface: #1F1F1E;
    --subtle: #262624;
    --border: #3A3A37;
    --border-strong: #6A6A64;
    --divider: #2E2E2C;
    --text: #EDEDEA;
    --text-soft: #D3D3CE;
    --text-muted: #A8A8A1;
    --text-inverse: #161615;
    --selected: #2E2E2C;
    --link-hover: #FFFFFF;
    --primary-hover: #FFFFFF;
    --danger: #F3B0AC;
    --danger-bg: #2E1A19;
    --danger-border: #7A3A36;
    --success: #9DD6AB;
    --success-bg: #15281B;
    --success-border: #2F6340;
    --warning: #E8C872;
    --warning-bg: #2B2410;
    --warning-border: #6B5520;
    --logo-ring: #4A4A46;
    color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #161615;
        --surface: #1F1F1E;
        --subtle: #262624;
        --border: #3A3A37;
        --border-strong: #6A6A64;
        --divider: #2E2E2C;
        --text: #EDEDEA;
        --text-soft: #D3D3CE;
        --text-muted: #A8A8A1;
        --text-inverse: #161615;
        --selected: #2E2E2C;
        --link-hover: #FFFFFF;
        --primary-hover: #FFFFFF;
        --danger: #F3B0AC;
        --danger-bg: #2E1A19;
        --danger-border: #7A3A36;
        --success: #9DD6AB;
        --success-bg: #15281B;
        --success-border: #2F6340;
        --warning: #E8C872;
        --warning-bg: #2B2410;
        --warning-border: #6B5520;
        --logo-ring: #4A4A46;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--text-soft); }
a:hover { color: var(--link-hover); }
.icon { flex-shrink: 0; }
.visually-hidden {
    position: absolute; width: 1px; height: 1px; overflow: hidden;
    clip-path: inset(50%); white-space: nowrap;
}

/* Layout */
.portal { min-height: 100vh; display: flex; flex-wrap: wrap; }
.portal-nav {
    flex: 1 1 240px; max-width: 100%; background: var(--surface); border-right: 1px solid var(--border);
    padding: 20px 14px; display: flex; flex-direction: column; gap: 20px;
}
.portal-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; }
.portal-content { flex: 1; min-height: 0; display: flex; flex-direction: column; }

/* Menu */
.brand { display: flex; align-items: center; gap: 10px; padding: 0 6px; font-weight: 700; font-size: 16px; }
.brand img { border-radius: 7px; box-shadow: 0 0 0 1px var(--logo-ring); }
.new-conversation {
    display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px;
    border-radius: var(--radius); background: var(--text); color: var(--text-inverse); text-decoration: none;
    font-size: 14px; font-weight: 600;
}
.new-conversation:hover { color: var(--text-inverse); background: var(--primary-hover); }
.nav-scroll { flex: 1; display: flex; flex-direction: column; gap: 20px; }
.nav-group { display: flex; flex-direction: column; gap: 2px; }
.nav-heading {
    padding: 0 12px 6px; font-size: 12px; font-weight: 600; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .04em;
}
.nav-item {
    display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 0 12px;
    border-radius: var(--radius); font-size: 14px; text-decoration: none; color: var(--text-soft);
}
.nav-item:hover { background: var(--bg); }
.nav-item[aria-current="page"] { background: var(--selected); font-weight: 600; color: var(--text); }
.nav-recent { flex: 1; }
.nav-empty { padding: 0 12px; font-size: 13px; color: var(--text-muted); }
.nav-user { display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; border-top: 1px solid var(--border); }
.avatar {
    width: 36px; height: 36px; border-radius: 50%; background: var(--selected); flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 600;
}
.nav-user-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.nav-user-name { font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-user-role { font-size: 12px; color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-button {
    width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
    border-radius: var(--radius); color: var(--text-soft);
}
.icon-button:hover { background: var(--bg); }

/* Page */
.page-header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
    padding: 16px 32px; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.page-header h1 { margin: 0; font-size: 16px; font-weight: 600; }
.company-name { font-size: 13px; color: var(--text-muted); }

/* Chat */
.chat { flex: 1; min-height: 0; display: flex; flex-direction: column; }
/* The conversation scrolls across the whole width, its content in a centred 820px column. */
.chat-messages {
    flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; justify-content: center; gap: 16px;
    padding: 32px max(24px, calc((100% - 772px) / 2));
}
.chat-empty { text-align: center; color: var(--text-soft); line-height: 1.5; }
.chat-welcome { font-size: 22px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.chat-composer { flex-shrink: 0; width: 100%; max-width: 820px; margin: 0 auto; padding: 0 24px 20px; }
.composer-box {
    display: flex; flex-direction: column; gap: 8px; padding: 12px 14px;
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
}
.composer-box textarea {
    border: none; resize: none; font: inherit; font-size: 15px; line-height: 1.5;
    color: var(--text); background: transparent; outline: none;
}
.composer-actions { display: flex; justify-content: flex-end; }
.send-button {
    width: 44px; height: 44px; border-radius: 10px; border: none; background: var(--text); color: var(--text-inverse);
    display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.send-button:disabled { background: var(--border-strong); cursor: not-allowed; }
.composer-note {
    display: flex; align-items: center; justify-content: center; gap: 6px;
    margin: 8px 0 0; font-size: 12px; color: var(--text-muted);
}

.chat-message { max-width: 85%; padding: 12px 16px; border-radius: 14px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-message--user { align-self: flex-end; background: var(--text); color: var(--text-inverse); }
.chat-message--assistant { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.chat-message.is-writing:empty::after { content: "…"; color: var(--text-muted); }
/* Answers rendered from Markdown: normal spacing instead of preserved line breaks. */
.chat-message.is-markdown { white-space: normal; }
.chat-message.is-markdown > :first-child { margin-top: 0; }
.chat-message.is-markdown > :last-child { margin-bottom: 0; }
.chat-message.is-markdown p, .chat-message.is-markdown ul, .chat-message.is-markdown ol { margin: 0 0 10px; }
.chat-message.is-markdown ul, .chat-message.is-markdown ol { padding-left: 22px; }
.chat-message.is-markdown h1, .chat-message.is-markdown h2, .chat-message.is-markdown h3 { font-size: 15px; margin: 14px 0 6px; }
.chat-message.is-markdown code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }
.chat-message.is-markdown pre { background: var(--bg); padding: 10px 12px; border-radius: 8px; overflow-x: auto; white-space: pre; }
.chat-message.is-markdown pre code { padding: 0; background: none; }
.chat-message.is-markdown table { border-collapse: collapse; margin: 0 0 10px; }
.chat-message.is-markdown th, .chat-message.is-markdown td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.chat-message.is-error { color: var(--danger); border-color: var(--danger-border); background: var(--danger-bg); }
.chat-messages:has(.chat-message) { justify-content: flex-start; }

/* Content pages (Mes connecteurs…) */
.page { width: 100%; max-width: 820px; padding: 24px 32px 40px; display: flex; flex-direction: column; gap: 16px; }
.page-intro, .page-note { margin: 0; color: var(--text-soft); line-height: 1.5; }
.page-note { font-size: 13px; color: var(--text-muted); }
.notice { margin: 0; padding: 10px 14px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); }
.notice--success { border-color: var(--success-border); background: var(--success-bg); }
.notice--error { border-color: var(--danger-border); background: var(--danger-bg); color: var(--danger); }
.connector-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.connector-head { display: flex; align-items: center; gap: 12px; }
.connector-head h2 { margin: 0; font-size: 16px; flex: 1; }
.connector-card h3 { margin: 0; font-size: 13px; color: var(--text-muted); font-weight: 600; }
.connector-pill { width: 36px; height: 36px; border-radius: 8px; background: var(--selected); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; }
.connector-account { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; color: var(--text-soft); }
.connector-account form { margin: 0; }
.connector-form { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.connector-form p { margin: 0; color: var(--text-soft); line-height: 1.5; }
.connector-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.connector-form input { height: 44px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; font-weight: 400; }
.connector-form .button { align-self: flex-start; border: none; cursor: pointer; font: inherit; font-weight: 600; }
.button--secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); cursor: pointer; font: inherit; }
.button--secondary:hover { background: var(--bg); color: var(--text); }
.badge { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border-strong); font-size: 12px; color: var(--text-soft); background: var(--surface); }
.badge--ok { border-color: var(--success-border); background: var(--success-bg); color: var(--success); }
.action-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }

/* Placeholder pages */
.placeholder { margin: auto; padding: 48px 24px; text-align: center; color: var(--text-soft); }
.placeholder-title { font-size: 20px; font-weight: 600; color: var(--text); margin: 0 0 6px; }

/* Standalone pages (login failure) */
.standalone { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.card {
    width: 100%; max-width: 420px; padding: 32px; background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px; text-align: center;
}
.card h1 { font-size: 20px; margin: 16px 0 8px; }
.card p { color: var(--text-soft); line-height: 1.5; }
.button {
    display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
    border-radius: var(--radius); background: var(--text); color: var(--text-inverse); text-decoration: none; font-weight: 600;
}
.button:hover { color: var(--text-inverse); background: var(--primary-hover); }

/* Wide screens: the menu, the page header and the composer stay in place; only the content scrolls. */
@media (min-width: 821px) {
    .portal { height: 100vh; height: 100dvh; flex-wrap: nowrap; overflow: hidden; }
    .nav-scroll { min-height: 0; overflow-y: auto; }
    .portal-content { overflow-y: auto; }
}

/* Narrow screens: the menu sits above the page, which scrolls as a whole; the composer sticks to the bottom. */
@media (max-width: 820px) {
    .portal-nav { border-right: none; border-bottom: 1px solid var(--border); }
    .page-header { padding: 16px; }
    .chat-messages { overflow-y: visible; padding: 24px 16px; }
    .chat-composer { position: sticky; bottom: 0; padding: 12px 16px 16px; background: var(--bg); }
}

/* Validations (screens 2h, 3a, 3b, 3d) */
.page--wide { max-width: 880px; }
.counter {
    margin-left: auto; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 999px;
    background: var(--text); color: var(--text-inverse); font-size: 12px; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
}
.tabs { display: flex; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.tab {
    min-height: 44px; padding: 0 16px; display: flex; align-items: center; gap: 8px; font-size: 14px;
    text-decoration: none; color: var(--text-muted); border-bottom: 3px solid transparent;
}
.tab[aria-current="page"] { color: var(--text); font-weight: 700; border-bottom-color: var(--text); }
.tab .counter { margin-left: 0; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    min-height: 44px; padding: 0 16px; border-radius: 999px; display: flex; align-items: center;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); text-decoration: none; font-size: 14px;
}
.chip[aria-current="true"] { background: var(--text); border-color: var(--text); color: var(--text-inverse); font-weight: 600; }
.request-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.request-card--active { border: 2px solid var(--text); }
.request-card:target { box-shadow: 0 0 0 3px var(--border-strong); }
.request-head { padding: 16px 24px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.request-title { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.request-title h2 { margin: 0; font-size: 16px; }
.request-number { font-weight: 500; color: var(--text-muted); font-size: 14px; }
.request-meta { margin: 0; font-size: 14px; color: var(--text-soft); }
.request-body { padding: 16px 24px; display: flex; flex-direction: column; gap: 14px; }
.request-why { margin: 0; padding: 12px 14px; border: 1px dashed var(--border-strong); border-radius: 10px; font-size: 14px; line-height: 1.5; }
.request-details h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.request-rows { margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.request-rows div { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.request-rows dt { color: var(--text-muted); }
.request-rows dd { margin: 0; }
.request-lines { width: 100%; border-collapse: collapse; font-size: 14px; margin-top: 8px; }
.request-lines th, .request-lines td { padding: 6px 4px; text-align: right; border-bottom: 1px solid var(--border); }
.request-lines th:first-child, .request-lines td:first-child { text-align: left; }
.request-lines thead th { font-weight: 600; color: var(--text-muted); font-size: 13px; }
.request-lines tfoot th, .request-lines tfoot td { font-weight: 700; border-bottom: none; }
.request-note, .request-progress { margin: 0; font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.request-decision { margin: 0; padding: 10px 14px; border-left: 3px solid var(--border-strong); background: var(--subtle); border-radius: 0 8px 8px 0; font-size: 14px; }
.request-decision p { margin: 0; }
.request-decision-who { color: var(--text-muted); font-size: 13px; margin-bottom: 4px !important; }
.request-decision--refused { border-left-color: var(--danger-border); }
.request-decision--approved, .request-decision--confirmed { border-left-color: var(--success-border); }
.request-status { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.request-status--wait { border: 1px dashed var(--border-strong); }
.request-status--ok { border: 1px solid var(--success-border); background: var(--success-bg); color: var(--success); }
.request-status--no { border: 1px solid var(--danger-border); background: var(--danger-bg); color: var(--danger); }
.request-decide { display: flex; flex-direction: column; gap: 8px; }
.request-decide label { font-size: 14px; font-weight: 600; }
.request-decide .hint { font-weight: 400; color: var(--text-muted); }
.request-decide textarea { border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 14px; font: inherit; font-size: 14px; resize: vertical; }
.request-actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.request-actions .button, .request-cancel .button { border: none; cursor: pointer; font: inherit; font-weight: 600; }
.request-actions .button--secondary, .request-cancel .button--secondary { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.request-actions .button--secondary:hover, .request-cancel .button--secondary:hover { background: var(--bg); color: var(--text); }
.button--key { gap: 8px; }
.button--key:disabled { opacity: .6; cursor: progress; }
.request-error { margin: 0; color: var(--danger); font-size: 14px; }
.request-cancel { margin: 0; display: flex; justify-content: flex-end; }

/* Conversations (2a to 2c, 2g) */
/* A long title in "Récentes" is cut, never widens the menu. */
.portal-nav { min-width: 0; }
.nav-recent-item {
    display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: var(--radius);
    font-size: 14px; color: var(--text-soft); text-decoration: none;
}
.nav-recent-item:hover { background: var(--bg); }
.nav-recent-item[aria-current="page"] { background: var(--bg); color: var(--text); }
.nav-recent-item.is-unseen { font-weight: 600; color: var(--text); }
.nav-recent-title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-recent-mark { display: flex; color: var(--text-muted); }
.nav-recent-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text); flex-shrink: 0; }
.nav-recent-archives { padding: 8px 12px 0; font-size: 13px; color: var(--text-muted); }
.conversation-bar { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; padding: 0 32px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.conversation-tabs { border-bottom: none; }
.conversation-menu { position: relative; align-self: center; font-size: 14px; }
.conversation-menu summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; padding: 0 8px; color: var(--text-muted); list-style: none; }
.conversation-menu summary::-webkit-details-marker { display: none; }
.conversation-menu-panel {
    position: absolute; right: 0; top: 100%; z-index: 10; min-width: 260px; padding: 14px; display: flex; flex-direction: column; gap: 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
}
.conversation-menu-panel form { margin: 0; display: flex; flex-direction: column; gap: 8px; }
.conversation-menu-panel label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.conversation-menu-panel input { height: 40px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--radius); font: inherit; background: var(--surface); color: var(--text); }
.conversation-menu-panel .button { border: 1px solid var(--border-strong); cursor: pointer; font: inherit; font-weight: 600; }
.conversation-menu-panel .button--secondary { background: var(--surface); color: var(--text); }
.button--danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border) !important; }
.chat-card {
    align-self: stretch; max-width: 85%; padding: 12px 16px; border-radius: 12px; font-size: 14px; line-height: 1.5;
    display: flex; flex-direction: column; gap: 6px; background: var(--surface);
}
.chat-card p { margin: 0; }
.chat-card--wait { border: 1px dashed var(--border-strong); }
.chat-card--ok { border: 1px solid var(--success-border); }
.chat-card--no { border: 1px solid var(--danger-border); }
.chat-card-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.chat-card--ok .chat-card-title { color: var(--success); }
.chat-card--no .chat-card-title { color: var(--danger); }
.chat-card-who { color: var(--text-muted); font-size: 13px; }
.chat-card-comment { margin: 0; padding-left: 10px; border-left: 3px solid var(--border-strong); }
.chat-card-link { font-weight: 600; color: var(--text); }
.chat-card:target { box-shadow: 0 0 0 3px var(--border-strong); }
.archive-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 820px) {
    .conversation-bar { padding: 0 16px; }
}

/* Live notices (live_controller.js) */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast {
    position: relative; padding: 12px 40px 12px 16px; border-radius: 12px; background: var(--surface); color: var(--text);
    border: 1px solid var(--border-strong); box-shadow: 0 8px 24px rgba(0, 0, 0, .14); font-size: 14px; line-height: 1.5;
}
.toast p { margin: 0 0 4px; }
.toast a { font-weight: 600; color: var(--text); }
.toast-close { position: absolute; top: 6px; right: 6px; width: 32px; height: 32px; border: none; background: transparent; color: var(--text-muted); font-size: 20px; cursor: pointer; border-radius: var(--radius); }
.toast-close:hover { background: var(--bg); }
