/*
 * Chat module — PedalPro house style.
 *
 * Loaded before pedalpro.css, which defines the --pp-* tokens this file uses.
 * See docs/24-layout.md §6 for the design spec and §1–§5 for the token values.
 *
 * Scope: .crm-chat (added to the root element in chat.blade.php).
 */

/* ── Tokens (follow the same pattern as .crm-board in pedalpro.css) ─────── */

.crm-chat {
    --surface:         #ffffff;
    --surface-2:       #f7f9fd;
    --border:          #e1e8f5;
    --text:            #0a1230;
    --text-dim:        #66738f;
    --text-muted:      #9dafc8;
    --accent:          #2563eb;
    --accent-soft:     #eaf0fe;
    --accent-ink:      #1d3fb0;
    --out-bg:          #eaf0fe;   /* blauw-zacht: own messages — right */
    --out-text:        #0a1230;
    --in-bg:           #ffffff;   /* white: incoming — left */
    --in-text:         #0a1230;
    --badge:           #ef4444;
    --radius:          12px;
    --shadow:          0 0 0 2px var(--border);
}

.dark .crm-chat {
    --surface:         #0f1a3d;
    --surface-2:       #16224a;
    --border:          #24305a;
    --text:            #e8ecf7;
    --text-dim:        #a3adc7;
    --text-muted:      #5b6a8c;
    --accent:          #3b82f6;
    --accent-soft:     rgba(37, 99, 235, 0.22);
    --accent-ink:      #60a5fa;
    --out-bg:          rgba(37, 99, 235, 0.22);
    --out-text:        #e8ecf7;
    --in-bg:           #16224a;
    --in-text:         #e8ecf7;
    --shadow:          0 0 0 1px rgba(255, 255, 255, 0.1);
}

/* ── Root layout ─────────────────────────────────────────────────────────── */

.chat-root {
    display: flex;
    height: calc(100vh - 10rem);
    min-height: 400px;
    border-radius: 22px;
    overflow: hidden;
    box-shadow: var(--shadow);
    background: var(--surface-2);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */

.chat-sidebar {
    width: 15rem;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    overflow: hidden;
}

.chat-sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-sidebar-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-dim);
}

.chat-new-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 8px;
    color: var(--accent);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}

.chat-new-btn:hover {
    background: var(--accent-soft);
}

/* ── New-conversation form ───────────────────────────────────────────────── */

.chat-new-form {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-shrink: 0;
    background: var(--surface-2);
}

.chat-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.chat-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
}

.chat-input,
.chat-select {
    font-size: 12px;
    font-weight: 500;
    padding: 0.375rem 0.625rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input:focus,
.chat-select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.chat-hint {
    font-size: 10px;
    color: var(--text-muted);
}

.chat-new-form-actions {
    display: flex;
    gap: 0.375rem;
}

.chat-btn-primary {
    flex: 1;
    padding: 0.375rem 0.625rem;
    font-size: 12px;
    font-weight: 700;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
    transition: opacity 0.15s;
}

.chat-btn-primary:hover {
    opacity: 0.88;
}

.chat-btn-ghost {
    flex: 1;
    padding: 0.375rem 0.625rem;
    font-size: 12px;
    font-weight: 600;
    border-radius: 999px;
    background: transparent;
    color: var(--text-dim);
    border: 2px solid var(--border);
    cursor: pointer;
    transition: background 0.15s;
}

.chat-btn-ghost:hover {
    background: var(--accent-soft);
}

/* ── Conversation list ───────────────────────────────────────────────────── */

.chat-conv-list {
    list-style: none;
    margin: 0;
    padding: 0.375rem;
    overflow-y: auto;
    flex: 1;
}

.chat-conv-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.5rem 0.625rem;
    border-radius: 8px;
    cursor: pointer;
    background: transparent;
    border: none;
    transition: background 0.1s;
}

.chat-conv-item:hover {
    background: var(--surface-2);
}

.chat-conv-item--active {
    background: var(--accent-soft);
}

.dark .chat-conv-item--active {
    background: var(--accent-soft);
}

.chat-conv-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.25rem;
}

.chat-conv-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conv-item--active .chat-conv-name {
    color: var(--accent-ink);
}

.dark .chat-conv-item--active .chat-conv-name {
    color: var(--accent-ink);
}

.chat-conv-preview {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-dim);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.125rem;
}

.chat-conv-time {
    display: block;
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 0.125rem;
}

.chat-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.125rem;
    height: 1.125rem;
    padding: 0 0.3rem;
    border-radius: 999px;
    background: var(--badge);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    flex-shrink: 0;
}

.chat-empty-hint {
    padding: 1rem 0.75rem;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    text-align: center;
}

/* ── Right pane ─────────────────────────────────────────────────────────── */

.chat-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow: hidden;
}

/* Navy header with gradient — matches the portal and the login screen */
.chat-pane-header {
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    background: var(--surface);
}

.chat-pane-title {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.025em;
    color: var(--text);
}

/* ── Messages ────────────────────────────────────────────────────────────── */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    scroll-behavior: smooth;
    background: var(--surface-2);
}

.chat-date-sep {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin: 0.5rem 0;
    position: relative;
}

.chat-date-sep::before,
.chat-date-sep::after {
    content: '';
    display: inline-block;
    width: 3rem;
    height: 1px;
    background: var(--border);
    vertical-align: middle;
    margin: 0 0.5rem;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    max-width: 68%;
}

.chat-msg--mine {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-msg--theirs {
    align-self: flex-start;
    align-items: flex-start;
}

.chat-msg-sender {
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.02em;
    color: var(--accent-ink);
    margin-bottom: 0.2rem;
}

.dark .chat-msg-sender {
    color: var(--accent-ink);
}

.chat-msg-bubble {
    padding: 0.5625rem 0.875rem;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
}

/* Own messages: blauw-zacht (§6: "eigen: blauw-zacht rechts") */
.chat-msg--mine .chat-msg-bubble {
    background: var(--out-bg);
    color: var(--out-text);
    border-bottom-right-radius: 4px;
    box-shadow: 0 0 0 1.5px var(--border);
}

/* Incoming messages: white card (§6: "PedalPro: wit links") */
.chat-msg--theirs .chat-msg-bubble {
    background: var(--in-bg);
    color: var(--in-text);
    border-bottom-left-radius: 4px;
    box-shadow: 0 0 0 1.5px var(--border);
}

.chat-msg-deleted {
    font-style: italic;
    opacity: 0.5;
}

.chat-msg-time {
    font-size: 10px;
    font-weight: 500;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

/* ── Compose ─────────────────────────────────────────────────────────────── */

.chat-compose {
    display: flex;
    align-items: flex-end;
    gap: 0.625rem;
    padding: 0.875rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}

.chat-compose-input {
    flex: 1;
    resize: none;
    padding: 0.5625rem 0.875rem;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.5;
    outline: none;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-compose-input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
    background: var(--surface);
}

.chat-compose-input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

/* Round send button — primary style (§3: knop = 999px + schaduw) */
.chat-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.375rem;
    height: 2.375rem;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.28);
    transition: opacity 0.15s, box-shadow 0.15s;
}

.chat-send-btn:hover {
    opacity: 0.88;
    box-shadow: 0 10px 24px rgba(37, 99, 235, 0.35);
}

/* ── Empty state ─────────────────────────────────────────────────────────── */

.chat-pane-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    background: var(--surface-2);
}

.chat-pane-empty-icon {
    width: 3rem;
    height: 3rem;
    opacity: 0.3;
}

/* ── Shared icon size ────────────────────────────────────────────────────── */

.chat-icon-sm {
    width: 1rem;
    height: 1rem;
}

/* ── Scrollbar (subtle, matches the board) ───────────────────────────────── */

.chat-conv-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-conv-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-conv-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 999px;
}

/* ── Responsive: stack on small screens ─────────────────────────────────── */

@media (max-width: 640px) {
    .chat-sidebar {
        width: 100%;
        max-height: 40vh;
        border-inline-end: none;
        border-bottom: 1px solid var(--border);
    }

    .chat-root {
        flex-direction: column;
        height: auto;
        min-height: 70vh;
    }
}
