/* ──────────────────────────────────────────────────────────────────────
   PI2C Messenger — beta · thème dark dérivé du mockup
   ──────────────────────────────────────────────────────────────────── */

:root {
    --bg: #0f172a;
    --bg-elev: #1e293b;
    --bg-elev-2: #334155;
    --text: #f1f5f9;
    --text-mute: #94a3b8;
    --text-dim: #64748b;
    --text-faint: #475569;
    --border: rgba(255, 255, 255, 0.06);
    --border-strong: rgba(255, 255, 255, 0.10);
    --primary: #6366f1;
    --primary-2: #818cf8;
    --primary-soft: rgba(99, 102, 241, 0.12);
    --accent-green: #22c55e;
    --danger: #ef4444;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior-y: none;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }

/* ──── Auth / Login ──── */
.auth-shell {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background:
        radial-gradient(800px 400px at 20% 0%, rgba(99,102,241,0.18), transparent 60%),
        radial-gradient(700px 400px at 100% 100%, rgba(34,211,238,0.10), transparent 60%),
        var(--bg);
}
.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 28px 24px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-logo {
    width: 56px; height: 56px;
    margin: 0 auto 12px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), #4f46e5);
    display: flex; align-items: center; justify-content: center;
    font-size: 28px; color: #fff;
}
.auth-brand h1 { margin: 0 0 4px; font-size: 22px; }
.auth-brand p { margin: 0; color: var(--text-dim); font-size: 13px; }

.auth-form { display: grid; gap: 14px; }
.auth-field { display: grid; gap: 6px; }
.auth-field span { font-size: 12px; color: var(--text-mute); }
.auth-field input {
    background: #0b1220;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    padding: 11px 14px;
    color: var(--text);
    font-size: 14px;
    outline: none;
    transition: border-color .15s;
}
.auth-field input:focus { border-color: var(--primary); }
.auth-submit {
    margin-top: 6px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-md);
    padding: 12px 16px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background .15s;
}
.auth-submit:hover { background: #4f46e5; }
.auth-footer { margin-top: 18px; font-size: 12px; color: var(--text-dim); text-align: center; }
.auth-footer a { color: var(--primary-2); }
.auth-alert {
    background: rgba(239,68,68,0.12);
    border: 1px solid rgba(239,68,68,0.35);
    color: #fecaca;
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 13px;
    margin-bottom: 14px;
    display: flex; gap: 8px; align-items: center;
}

/* ──── Layout shell ──── */
.app-shell {
    height: 100dvh;
    display: flex;
    background: var(--bg);
}
@media (max-width: 900px) {
    .app-shell { flex-direction: column; }
}

.sidebar {
    width: 100%;
    max-width: 360px;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border-right: 1px solid var(--border);
    height: 100dvh;
}
.sidebar--full { max-width: none; flex: 1; }
@media (min-width: 901px) {
    .sidebar--list { display: flex; }
}
@media (max-width: 900px) {
    .app-shell--chat .sidebar--list { display: none; }
}

.sidebar-header {
    padding: 16px 18px 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.sidebar-title h1 { margin: 0; font-size: 22px; font-weight: 700; }
.sidebar-subtitle { font-size: 12px; color: var(--text-dim); }
.sidebar-actions { display: flex; gap: 8px; }

.btn-icon {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--bg-elev);
    color: var(--text-mute);
    cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    transition: background .15s;
}
.btn-icon:hover { background: var(--bg-elev-2); }
.btn-icon i { font-size: 18px; }

.search-box {
    margin: 0 18px 12px;
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-elev);
    border-radius: var(--radius-md);
    padding: 0 12px;
}
.search-box i { color: var(--text-dim); }
.search-box input {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    padding: 10px 0;
    font-size: 14px;
    outline: none;
}
.search-box input::placeholder { color: var(--text-faint); }
.search-box input:disabled { opacity: .6; }

.conv-list {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 90px;
}
.conv-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
}
.conv-item:hover, .conv-item.active { background: var(--primary-soft); }
.conv-info { flex: 1; min-width: 0; }
.conv-name { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 2px; }
.conv-preview {
    font-size: 13px;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.conv-preview.unread { color: var(--text-mute); }
.conv-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; min-width: 50px; }
.conv-time { font-size: 11px; color: var(--text-faint); }
.badge {
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* ──── Avatars ──── */
.avatar {
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
    position: relative;
}
.avatar.group { border-radius: 14px; }
.avatar.online::after {
    content: '';
    position: absolute;
    bottom: 1px; right: 1px;
    width: 11px; height: 11px;
    border-radius: 50%;
    background: var(--accent-green);
    border: 2px solid var(--bg);
}

/* ──── Contacts ──── */
.company-section { padding-bottom: 6px; }
.company-header {
    padding: 14px 18px 6px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.company-dot { width: 8px; height: 8px; border-radius: 50%; }
.company-name { font-size: 12px; font-weight: 700; color: var(--text-mute); text-transform: uppercase; letter-spacing: .5px; }
.company-count { font-size: 11px; color: var(--text-faint); }
.contact-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 18px;
    cursor: pointer;
    transition: background .1s;
}
.contact-item:hover { background: var(--primary-soft); }
.contact-info { flex: 1; }
.contact-name { font-size: 14px; font-weight: 500; color: var(--text); }
.contact-role { font-size: 12px; color: var(--text-dim); }
.contact-action {
    color: var(--text-faint);
    transition: color .15s;
}
.contact-item:hover .contact-action { color: var(--primary); }

/* ──── Bottom nav ──── */
.bottom-nav {
    position: sticky;
    bottom: 0;
    height: 70px;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    z-index: 5;
}
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
    color: var(--text-faint);
    font-size: 10px;
    text-decoration: none;
    padding: 8px 14px;
    transition: color .15s;
}
.nav-item i { font-size: 22px; }
.nav-item.active { color: var(--primary); }
.nav-item.is-disabled { opacity: .4; pointer-events: none; }

/* ──── Chat ──── */
.chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100dvh;
    background: var(--bg);
}
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.chat-back {
    color: var(--primary);
    font-size: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
}
@media (min-width: 901px) {
    .chat-back { display: none; }
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h2 { margin: 0; font-size: 16px; font-weight: 600; }
.chat-header-info span { font-size: 12px; color: var(--text-dim); }
.chat-header-actions { display: flex; gap: 6px; }

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.date-separator {
    text-align: center;
    font-size: 11px;
    color: var(--text-faint);
    margin: 6px 0;
    position: relative;
}
.date-separator::before,
.date-separator::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: var(--border);
}
.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

.msg-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.msg-row.mine { flex-direction: row-reverse; }
.msg-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
}
.msg-content { max-width: 72%; }
.msg-sender-name {
    font-size: 11px;
    color: var(--text-dim);
    margin-bottom: 3px;
    margin-left: 4px;
    font-weight: 600;
}
.msg-bubble {
    padding: 9px 13px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.msg-bubble.them {
    background: var(--bg-elev);
    color: #e2e8f0;
    border-bottom-left-radius: 4px;
}
.msg-bubble.mine {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.msg-meta {
    font-size: 10px;
    color: var(--text-faint);
    margin-top: 3px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.msg-row.mine .msg-meta { justify-content: flex-end; }
.read-icon { color: var(--primary-2); font-size: 12px; }

/* ──── Composer ──── */
.composer {
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px));
    background: var(--bg);
    border-top: 1px solid var(--border);
}
.composer-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.composer-input-wrap {
    flex: 1;
    background: var(--bg-elev);
    border-radius: 22px;
    padding: 8px 12px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.composer-input-wrap textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 14px;
    resize: none;
    outline: none;
    line-height: 1.4;
    max-height: 120px;
    font-family: inherit;
    padding: 4px 0;
}
.composer-input-wrap textarea::placeholder { color: var(--text-faint); }
.composer-action {
    background: none;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
}
.composer-action:disabled { opacity: .35; cursor: not-allowed; }
.composer-send {
    width: 42px; height: 42px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background .15s, transform .1s;
}
.composer-send:hover { background: #4f46e5; }
.composer-send:active { transform: scale(0.96); }
.composer-send i { font-size: 18px; }

/* ──── Empty state ──── */
.empty-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-dim);
}
.empty-state i { font-size: 42px; color: var(--text-faint); margin-bottom: 12px; }
.empty-state p { margin: 0 0 18px; font-size: 14px; }
