/* public/css/dashboard.css */

* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --tmis-green: #075E54;
    --tmis-green-light: #25D366;
    --bg-app: #f0f2f5;
    --bg-panel: #ffffff;
    --bg-thread: #e5ddd5;
    --text-main: #111b21;
    --text-muted: #667781;
    --border-color: #e9edef;
    --bubble-inbound: #ffffff;
    --bubble-outbound: #d9fdd3;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    background: var(--bg-app);
    height: 100vh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
}

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

#sidebar {
    width: 360px;
    min-width: 280px;
    max-width: 40vw;
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

#sidebar-header {
    padding: 16px;
    background: var(--tmis-green);
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
#sidebar-header h1 { font-size: 18px; font-weight: 600; }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.15);
    width: fit-content;
}
.status-pill .dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: #aaa;
}
.status-pill.status-ready .dot { background: #4ade80; }
.status-pill.status-qr .dot,
.status-pill.status-authenticated .dot { background: #fbbf24; }
.status-pill.status-disconnected .dot,
.status-pill.status-uninitialized .dot { background: #f87171; }

#conversation-list {
    flex: 1;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.1s;
}
.conversation-item:hover { background: #f5f6f6; }
.conversation-item.active { background: #e9edef; }

.conversation-item .name-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.conversation-item .name { font-weight: 600; font-size: 14.5px; }
.conversation-item .time { font-size: 11px; color: var(--text-muted); }
.conversation-item .preview {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.empty-list-hint {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ── Main panel ──────────────────────────────────────────────────────────── */

#main-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-thread);
}

.hidden { display: none !important; }

.centered-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    padding: 24px;
    background: var(--bg-panel);
}
.centered-screen h2 { font-size: 20px; color: var(--text-main); }
.centered-screen p { color: var(--text-muted); font-size: 14px; max-width: 360px; }
.centered-screen .hint { font-size: 12px; }
#qr-image {
    margin-top: 16px;
    width: 260px;
    height: 260px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background: #fff;
}

.rejection-notice {
    margin-top: 8px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    border-radius: 8px;
    font-size: 13px;
    max-width: 360px;
}

#thread-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
}

#thread-header {
    background: var(--bg-panel);
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-color);
}
#thread-contact-name { font-weight: 600; font-size: 15px; }
.muted { color: var(--text-muted); font-size: 12.5px; }

#message-list {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.45;
    box-shadow: 0 1px 1px rgba(0,0,0,0.08);
    position: relative;
}
.msg-bubble.inbound {
    background: var(--bubble-inbound);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}
.msg-bubble.outbound {
    background: var(--bubble-outbound);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}
.msg-bubble .msg-meta {
    font-size: 10.5px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}
.msg-bubble .msg-type-tag {
    font-size: 11px;
    font-style: italic;
    color: var(--text-muted);
}

/* ── Reply footer ────────────────────────────────────────────────────────── */

#thread-footer {
    padding: 10px 20px;
    background: #f7f7f8;
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.reply-error {
    font-size: 12.5px;
    color: #991b1b;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 6px;
    padding: 6px 10px;
}

#reply-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

#attachment-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: transparent;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-muted);
    transition: background 0.15s;
    flex-shrink: 0;
}
#attachment-btn:hover:not(:disabled) { background: #e9edef; }
#attachment-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── Staged attachment preview (before send) ────────────────────────────── */

.attachment-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 10px;
}
.attachment-preview img#attachment-preview-thumb {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 6px;
}
.attachment-file-icon { font-size: 24px; line-height: 1; }
.attachment-preview-info { flex: 1; min-width: 0; }
.attachment-preview-name {
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.attachment-preview-size { font-size: 11.5px; color: var(--text-muted); }
.attachment-remove-btn {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    padding: 4px 6px;
    line-height: 1;
    flex-shrink: 0;
}
.attachment-remove-btn:hover { color: #991b1b; }

.attachment-upload-progress {
    width: 80px;
    height: 6px;
    background: var(--border-color);
    border-radius: 3px;
    overflow: hidden;
    flex-shrink: 0;
}
.attachment-upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--tmis-green-light);
    transition: width 0.15s;
}

/* Drag-and-drop: highlight the whole footer while a file is dragged over it. */
#thread-footer.drag-over {
    outline: 2px dashed var(--tmis-green-light);
    outline-offset: -4px;
    background: #eefaf0;
}

.reply-error {
    display: flex;
    align-items: center;
    gap: 10px;
}
.reply-error .retry-btn {
    border: 1px solid #991b1b;
    background: transparent;
    color: #991b1b;
    border-radius: 6px;
    padding: 2px 10px;
    font-size: 12px;
    cursor: pointer;
    flex-shrink: 0;
}
.reply-error .retry-btn:hover { background: #991b1b; color: #fff; }

/* ── Inline media within message bubbles ─────────────────────────────────── */

.msg-media-image {
    max-width: 100%;
    max-height: 260px;
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
    cursor: pointer;
}
.msg-media-video, .msg-media-audio {
    max-width: 100%;
    border-radius: 6px;
    display: block;
    margin-bottom: 4px;
}
.msg-media-video { max-height: 260px; }
.msg-media-audio { width: 260px; }

.msg-media-doc {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.04);
    border-radius: 8px;
    margin-bottom: 4px;
    text-decoration: none;
    color: inherit;
    max-width: 220px;
}
.msg-media-doc .doc-icon { font-size: 22px; flex-shrink: 0; }
.msg-media-doc .doc-name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-media-unavailable {
    font-size: 12px;
    font-style: italic;
    color: var(--text-muted);
    margin-bottom: 4px;
}

#reply-input {
    flex: 1;
    resize: none;
    max-height: 120px;
    min-height: 38px;
    padding: 9px 14px;
    border: 1px solid var(--border-color);
    border-radius: 18px;
    background: #fff;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s;
}
#reply-input:focus { border-color: var(--tmis-green-light); }
#reply-input:disabled {
    background: #eceff1;
    color: var(--text-muted);
    cursor: not-allowed;
}

#reply-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 68px;
    height: 38px;
    padding: 0 16px;
    border: none;
    border-radius: 18px;
    background: var(--tmis-green);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
}
#reply-send-btn:hover:not(:disabled) { background: #064840; }
#reply-send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: reply-spin 0.7s linear infinite;
}
@keyframes reply-spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 760px) {
    #sidebar { width: 100%; max-width: 100%; }
    #main-panel.has-thread-open #sidebar { display: none; }
    #app.thread-open #sidebar { display: none; }
}