:root {
    --bg: #f0f2f5;
    --card: #ffffff;
    --primary: #128c7e;
    --primary-dark: #075e54;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success: #059669;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}
a { color: var(--primary-dark); text-decoration: none; }
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 14px 24px; background: var(--primary-dark); color: #fff;
    flex-shrink: 0;
}
.topbar a, .topbar .btn-link { color: #fff; margin-left: 16px; background: none; border: 0; cursor: pointer; }
.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 18px;
}
.brand-logo {
    width: 28px; height: 28px; object-fit: contain; flex-shrink: 0;
}
.nav-links { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.main-content {
    flex: 1;
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
}
.main-content--chat {
    max-width: none;
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.main-content--chat .chat-app {
    flex: 1;
    min-height: 0;
}
.site-footer {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 16px;
    background: #fff;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 13px;
    text-align: center;
}
.footer-logo {
    width: 20px; height: 20px; object-fit: contain; flex-shrink: 0;
}
.card, .auth-card {
    background: var(--card); border-radius: 12px; padding: 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,.06); margin-bottom: 20px;
}
.auth-card { max-width: 420px; width: 100%; margin: 0 auto; }
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 120px);
    padding: 24px 0;
}
.auth-logo-wrap { text-align: center; margin-bottom: 16px; }
.auth-logo {
    width: 72px; height: 72px; object-fit: contain;
}
.auth-card h1 { margin-top: 0; text-align: center; }
.auth-card .muted { text-align: center; }
.form-grid { display: grid; gap: 10px; }
.form-grid.two-col { grid-template-columns: 1fr 1fr; }
.form-grid label { font-size: 14px; font-weight: 600; }
.form-grid input, .form-grid textarea, .search-input {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
}
.form-actions, .actions-row, .card-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.span-2 { grid-column: span 2; }
.btn, .btn-primary, .btn-success, .btn-info {
    display: inline-block; padding: 10px 16px; border-radius: 8px; border: 0; cursor: pointer;
    background: #e5e7eb; color: var(--text); font-weight: 600;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-info { background: #0284c7; color: #fff; }
.btn-link { background: none; border: 0; color: var(--primary-dark); cursor: pointer; padding: 0; }
.btn-link.danger { color: var(--danger); }
.inline-form { display: inline; }
.alert { padding: 12px 14px; border-radius: 8px; margin-bottom: 16px; }
.alert-success { background: #d1fae5; color: #065f46; }
.alert-error { background: #fee2e2; color: #991b1b; }
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: 12px; padding: 18px; box-shadow: 0 8px 24px rgba(0,0,0,.05); }
.stat-card span { display: block; color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: 28px; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 10px; border-bottom: 1px solid var(--border); text-align: left; }
.muted { color: var(--muted); font-size: 13px; }
.code-block, .log-box {
    display: block; background: #111; color: #9fef9f; padding: 12px; border-radius: 8px;
    overflow: auto; word-break: break-all; font-size: 12px;
}
.checkbox-line { display: flex; align-items: center; gap: 8px; }

.chat-app {
    display: grid; grid-template-columns: 340px 1fr; gap: 0;
    height: calc(100vh - 130px);
    min-height: 480px;
    max-height: calc(100vh - 130px);
    background: var(--card); border-radius: 16px;
    box-shadow: 0 12px 32px rgba(0,0,0,.08);
    overflow: hidden;
}
.chat-sidebar {
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    background: #fff;
    min-height: 0;
    overflow: hidden;
}
.chat-sidebar-head { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.search-input { margin: 12px; width: calc(100% - 24px); flex-shrink: 0; }
.conversation-list {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.conversation-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 8px;
}
.conversation-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.conversation-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: #c5c9ce;
    border-radius: 8px;
}
.conversation-list::-webkit-scrollbar-thumb:hover,
.chat-messages::-webkit-scrollbar-thumb:hover {
    background: #a8adb3;
}
.conv-item {
    padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.conv-item:hover, .conv-item.active { background: #f0faf6; }
.conv-item.active {
    border-left: 3px solid var(--primary);
    padding-left: 13px;
}
.conv-item .title { font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.conv-item .preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge-unread {
    background: var(--primary); color: #fff; border-radius: 999px; font-size: 11px;
    padding: 2px 7px; min-width: 20px; text-align: center;
}
.chat-main {
    display: flex;
    flex-direction: column;
    position: relative;
    background: #0f1412;
    min-height: 0;
    overflow: hidden;
}
.chat-bg {
    position: absolute;
    inset: 0;
    z-index: 0;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    transform: scale(1.02);
}
.chat-bg-overlay {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(180deg, rgba(8, 10, 9, 0.55) 0%, rgba(8, 10, 9, 0.72) 45%, rgba(8, 10, 9, 0.82) 100%);
}
.chat-header,
.chat-messages,
.chat-notice,
.chat-form,
.recording-panel,
.audio-preview {
    position: relative;
    z-index: 2;
}
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(17, 21, 18, 0.88);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    color: #fff;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #fff; }
.chat-header .muted { color: rgba(255, 255, 255, 0.62); }
.btn-back { display: none; color: #fff; }
.chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 16px 22px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.msg {
    max-width: min(78%, 520px);
    padding: 9px 12px 8px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.22);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    word-break: break-word;
}
.msg.in {
    align-self: flex-start;
    background: rgba(32, 34, 38, 0.94);
    color: #f3f4f6;
    border-bottom-left-radius: 6px;
}
.msg.out {
    align-self: flex-end;
    background: rgba(122, 36, 58, 0.95);
    color: #fff;
    border-bottom-right-radius: 6px;
}
.msg-text {
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.msg-meta {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.55);
    margin-top: 5px;
}
.msg.failed { border: 1px solid rgba(248, 113, 113, 0.85); }
.chat-notice {
    padding: 10px 16px;
    background: rgba(154, 52, 18, 0.88);
    color: #ffedd5;
    border-top: 1px solid rgba(251, 146, 60, 0.35);
    flex-shrink: 0;
}
.chat-form {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    padding: 14px;
    background: rgba(17, 21, 18, 0.92);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
    align-items: end;
    width: 100%;
    max-width: 100%;
    overflow: hidden;
    box-sizing: border-box;
}
.chat-form-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}
.chat-form-actions .btn,
.chat-form-actions .btn-primary,
.chat-form-actions .btn-mic {
    flex-shrink: 0;
    white-space: nowrap;
}
.chat-compose {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    min-width: 0;
    overflow: hidden;
}
.compose-input-wrap {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
}
.chat-compose textarea {
    width: 100%;
    resize: vertical;
    min-height: 44px;
    max-height: 120px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 22px;
    padding: 11px 14px;
}
.chat-compose textarea::placeholder { color: rgba(255, 255, 255, 0.45); }
.chat-form textarea {
    resize: vertical;
    min-height: 44px;
    max-height: 120px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 22px;
}
.chat-form textarea::placeholder { color: rgba(255, 255, 255, 0.45); }
/* ── File chip ──────────────────────────────────────────────────────── */
.file-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 6px 4px 10px;
    background: rgba(46, 125, 50, 0.22);
    border: 1px solid rgba(129, 199, 132, 0.45);
    border-radius: 16px;
    font-size: 12px;
    color: #c8e6c9;
    max-width: 100%;
    min-width: 0;
    overflow: hidden;
}
.file-chip svg { flex-shrink: 0; color: #81c784; }
.file-chip-name {
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
    color: #e8f5e9;
}
.file-chip-clear {
    flex-shrink: 0;
    color: #c5e1a5;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: rgba(0,0,0,.06);
}
.file-chip-clear:hover { background: rgba(0,0,0,.14); }
.btn-attach {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 42px;
    height: 42px;
    padding: 0;
    cursor: pointer;
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.72);
    transition: color .15s;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 50%;
}
.btn-attach:hover { color: #fff; background: rgba(255, 255, 255, 0.14); }
.msg-media { margin-bottom: 6px; }
.msg-media--missing {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, .06);
    color: var(--text-muted, #8696a0);
    font-size: .9rem;
}
.msg-media img {
    display: block;
    max-width: min(280px, 100%);
    border-radius: 10px;
    cursor: zoom-in;
    transition: opacity .15s;
}
.msg-media img:hover { opacity: .92; }

/* ── WhatsApp-style audio messages ── */
.msg-audio {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: min(100%, 260px);
    max-width: 320px;
    margin-bottom: 2px;
}
.msg-audio-native { display: none; }
.msg-audio-play {
    position: relative;
    width: 36px;
    height: 36px;
    margin-top: 2px;
    border: 0;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #fff;
    transition: transform .12s ease, background .12s ease;
}
.msg.in .msg-audio-play {
    background: rgba(255, 255, 255, 0.14);
    color: #f3f4f6;
}
.msg.out .msg-audio-play {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.msg-audio-play:hover { transform: scale(1.04); }
.msg.in .msg-audio:not(.msg-audio--played):not(.msg-audio--playing) .msg-audio-play::after {
    content: '';
    position: absolute;
    top: 1px;
    right: 1px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #53bdeb;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.msg-audio-icon { display: block; }
.msg-audio-content {
    flex: 1;
    min-width: 0;
    padding-top: 2px;
}
.msg-audio-wave {
    position: relative;
    height: 30px;
    display: flex;
    align-items: center;
    cursor: pointer;
    touch-action: none;
}
.msg-audio-bars {
    --progress: 0%;
    position: relative;
    display: flex;
    align-items: center;
    gap: 2px;
    width: 100%;
    height: 100%;
    overflow: hidden;
}
.msg-audio-bars::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: calc(100% - var(--progress));
    background: rgba(0, 0, 0, 0.28);
    pointer-events: none;
    transition: width .05s linear;
}
.msg.in .msg-audio-bars::after { background: rgba(0, 0, 0, 0.32); }
.msg-audio-bar {
    width: 3px;
    min-height: 4px;
    border-radius: 2px;
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.88);
}
.msg.in .msg-audio-bar { background: rgba(255, 255, 255, 0.78); }
.msg-audio-dot {
    position: absolute;
    top: 50%;
    left: 0;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    background: #53bdeb;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
    pointer-events: none;
    transition: left .05s linear;
    z-index: 2;
}
.msg.out .msg-audio-dot {
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
}
.msg-audio-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 2px;
    min-height: 16px;
}
.msg-audio-time {
    font-size: 11px;
    line-height: 1;
    color: rgba(255, 255, 255, 0.62);
    font-variant-numeric: tabular-nums;
}
.msg-audio-mic {
    flex-shrink: 0;
    color: rgba(255, 255, 255, 0.55);
    opacity: 0.9;
}
.msg.out .msg-audio-mic { color: rgba(255, 255, 255, 0.72); }
.msg:has(.msg-audio) {
    padding-top: 8px;
    padding-bottom: 7px;
}
.msg:has(.msg-audio) .msg-meta {
    margin-top: 4px;
}

.hidden { display: none !important; }
.btn-icon {
    background: none;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    transition: color .15s;
}
.btn-icon:hover { color: var(--text); }

/* SVG icons — block display so they don't get extra line-height space */
.btn-icon svg, .btn-mic svg, .btn-send-rec svg,
.btn-attach svg, .btn-cancel-rec svg { display: block; }

/* ── Microphone / recording buttons ── */
.btn-mic, .btn-send-rec {
    width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, opacity .15s;
}
.btn-mic { background: rgba(122, 36, 58, 0.95); color: #fff; }
.btn-mic:hover { background: rgba(98, 28, 46, 0.98); }
.chat-form-actions .btn-primary {
    background: rgba(122, 36, 58, 0.95);
    border-radius: 22px;
    padding: 10px 16px;
}
.chat-form-actions .btn-primary:hover {
    background: rgba(98, 28, 46, 0.98);
}
.btn-send-rec { background: var(--success); color: #fff; }
.btn-send-rec:hover { opacity: .88; }

/* ── Recording panel (replaces compose area while recording) ── */
.recording-panel {
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 48px;
    padding: 0 10px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    overflow: hidden;
}
.rec-time {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 4px;
}
.rec-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--danger);
    flex-shrink: 0;
    animation: recPulse 1.2s ease-in-out infinite;
}
.rec-dot--paused {
    animation: none;
    opacity: .45;
    background: var(--muted);
}
@keyframes recPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: .3; transform: scale(.65); }
}
#recordTimer {
    font-size: 15px;
    font-weight: 600;
    color: var(--danger);
    min-width: 36px;
    font-variant-numeric: tabular-nums;
    letter-spacing: .5px;
}
.rec-dot--paused ~ #recordTimer { color: var(--muted); }
.btn-cancel-rec {
    color: var(--muted);
    padding: 0;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border-radius: 50%;
    transition: color .12s, background .12s;
}
.btn-cancel-rec:hover { color: var(--danger); background: #fee2e2; }
.btn-rec-ctrl {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    color: var(--primary);
    transition: background .15s;
}
.btn-rec-ctrl:hover { background: #e6f4f1; }
.btn-rec-stop {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    color: var(--danger);
    transition: background .15s;
}
.btn-rec-stop:hover { background: #fee2e2; }

/* ── Audio preview (after stopping, before sending) ── */
.audio-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 48px;
    padding: 4px 12px 4px 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 24px;
    border: 1px solid rgba(255, 255, 255, 0.14);
}
.audio-preview-player {
    flex: 1;
    min-width: 0;
    height: 36px;
    accent-color: var(--primary);
}
.btn-delete-audio {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: var(--danger);
    transition: background .15s;
}
.btn-delete-audio:hover { background: #fee2e2; }

/* ── Lightbox ── */
.lightbox {
    position: fixed;
    inset: 0;
    z-index: 50000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, .9);
    cursor: zoom-out;
}
.lightbox-content {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: min(92vw, 1100px);
    max-height: 92vh;
    gap: 10px;
}
.lightbox-toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    width: 100%;
}
.lightbox-btn {
    background: rgba(255, 255, 255, .15);
    backdrop-filter: blur(6px);
    color: #fff;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 0;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
    text-decoration: none;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, .28); color: #fff; }
.lightbox-btn svg { display: block; }
.lightbox-img {
    display: block;
    max-width: 100%;
    max-height: calc(92vh - 70px);
    object-fit: contain;
    border-radius: 8px;
    box-shadow: 0 8px 40px rgba(0,0,0,.6);
}
body.lightbox-open { overflow: hidden; }

/* ── Message context menu ── */
.msg-menu {
    position: fixed;
    z-index: 9999;
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 6px 24px rgba(0,0,0,.18);
    padding: 4px 0;
    min-width: 190px;
    border: 1px solid var(--border);
    overflow: hidden;
    animation: menuFadeIn .13s ease;
}
@keyframes menuFadeIn {
    from { opacity: 0; transform: scale(.93) translateY(-4px); }
    to   { opacity: 1; transform: scale(1)  translateY(0); }
}
.msg-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 11px 16px;
    background: none;
    border: 0;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    text-align: left;
    white-space: nowrap;
    font-family: inherit;
}
.msg-menu-item:hover, .msg-menu-item:focus-visible {
    background: #f3f4f6;
    outline: none;
}
.msg-menu-icon {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.msg-menu-sep {
    height: 1px;
    background: var(--border);
    margin: 4px 0;
}
.msg-menu-item--danger { color: var(--danger); }
.msg-menu-item--danger:hover, .msg-menu-item--danger:focus-visible {
    background: #fee2e2;
    color: var(--danger);
}

/* ── Messages: cursor hint that they are clickable ── */
.msg { cursor: pointer; }
.msg:hover { filter: brightness(1.05); }

/* ── Toast notification ── */
.copy-toast {
    position: fixed;
    bottom: 90px;
    left: 50%;
    transform: translateX(-50%) translateY(12px);
    background: #1f2937;
    color: #fff;
    padding: 10px 22px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity .22s ease, transform .22s ease;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0,0,0,.22);
}
.copy-toast--in {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 900px) {
    /* ── Topbar compact ── */
    .topbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 10px 14px;
        gap: 4px;
    }
    .brand { font-size: 15px; }
    .brand-logo { width: 22px; height: 22px; }
    .nav-links { gap: 0; }
    .topbar a, .topbar .btn-link { margin-left: 0; margin-right: 10px; font-size: 13px; }

    /* ── Masquer le footer pour maximiser l'espace ── */
    .site-footer { display: none; }

    /* ── Bouton retour : visible uniquement sur mobile ── */
    .btn-back { display: inline-flex; }

    /*
     * Chaîne de hauteur fixe : sans hauteur bornée, .chat-messages
     * s'étire avec son contenu et overflow-y:auto ne crée pas de scroll.
     */
    .app-shell:has(.main-content--chat) {
        height: 100dvh;
        max-height: 100dvh;
        overflow: hidden;
    }

    body.mobile-chat-active {
        overflow: hidden;
        overscroll-behavior: none;
    }

    /* Plein écran : masquer la barre du site quand une conversation est ouverte */
    body.mobile-chat-active .topbar {
        display: none;
    }

    .main-content--chat {
        position: relative;
        padding: 0;
        margin: 0;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    .chat-app {
        display: flex;
        flex-direction: column;
        flex: 1;
        height: 100%;
        max-height: none;
        min-height: 0;
        border-radius: 0;
        box-shadow: none;
        overflow: hidden;
    }

    .chat-app.mobile-chat-open {
        position: absolute;
        inset: 0;
    }

    .chat-sidebar {
        position: static;
        inset: auto;
        z-index: auto;
        flex: 1;
        min-height: 0;
        max-height: none;
        border-right: 0;
        border-bottom: 0;
        display: flex;
        overflow: hidden;
    }

    .chat-main {
        position: static;
        inset: auto;
        z-index: auto;
        flex: 1;
        min-height: 0;
        display: none;
        flex-direction: column;
        overflow: hidden;
        margin: 0;
        padding: 0;
    }

    /* ── Quand une conversation est ouverte ── */
    .chat-app.mobile-chat-open .chat-sidebar { display: none; }
    .chat-app.mobile-chat-open .chat-main {
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
        overflow: hidden;
        justify-content: flex-start;
    }

    /* ── En-tête collé en haut, sans espace ── */
    .chat-app.mobile-chat-open .chat-header {
        flex-shrink: 0;
        margin: 0;
        padding-top: max(12px, env(safe-area-inset-top, 0px));
        padding-bottom: 12px;
    }

    .chat-app.mobile-chat-open .chat-bg,
    .chat-app.mobile-chat-open .chat-bg-overlay {
        top: 0;
        bottom: 0;
    }

    /* ── Zone messages : seul conteneur scrollable de la discussion ── */
    .chat-app.mobile-chat-open .chat-messages {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        padding-bottom: calc(110px + env(safe-area-inset-bottom, 0px));
    }

    /* ── Notice ── */
    .chat-app.mobile-chat-open .chat-notice {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 101;
    }

    /* ── Formulaire : fixé en bas du viewport ── */
    .chat-app.mobile-chat-open .chat-form {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        padding: 10px 10px max(10px, env(safe-area-inset-bottom, 0px));
        gap: 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.08);
        box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.35);
    }

    .chat-app.mobile-chat-open .chat-form-actions .btn-primary {
        padding: 10px 12px;
        font-size: 14px;
    }

    .chat-app.mobile-chat-open .file-chip-name {
        max-width: 28ch;
    }

    /* ── Autres ajustements ── */
    .form-grid.two-col { grid-template-columns: 1fr; }
    .span-2 { grid-column: span 1; }
}

/* ── Admin: upload arriere-plan client ── */
.admin-bg-section {
    margin-top: 8px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
    display: grid;
    gap: 10px;
}
.admin-bg-preview {
    height: 160px;
    border-radius: 12px;
    background-size: cover;
    background-position: center;
    background-color: #111;
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.admin-bg-preview::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(0,0,0,.25), rgba(0,0,0,.55));
}
.admin-bg-preview-label {
    position: absolute;
    left: 12px;
    bottom: 10px;
    z-index: 1;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .02em;
}
.admin-bg-remove { margin-top: 4px; }

/* ── Admin: logo application ── */
.admin-logo-section {
    margin-top: 8px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #fafafa;
    display: grid;
    gap: 10px;
}
.admin-logo-preview-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    border-radius: 12px;
    background: #fff;
    border: 1px dashed var(--border);
}
.admin-logo-preview {
    max-width: 220px;
    max-height: 120px;
    object-fit: contain;
}
.admin-logo-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 16px 24px;
}
.admin-logo-placeholder-text {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary-dark);
}
.admin-logo-preview-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .02em;
}
.admin-logo-remove { margin-top: 4px; }

.auth-brand-title {
    text-align: center;
    font-size: 32px;
    font-weight: 700;
    color: var(--primary-dark);
    margin-bottom: 16px;
    letter-spacing: .02em;
}
