/* Chat del webmail — estilo afín al tema Elastic de Roundcube. */
:root {
    --c-bg: #ffffff;
    --c-side: #f4f4f4;
    --c-border: #dddddd;
    --c-text: #2c363a;
    --c-muted: #6c757d;
    --c-accent: #37beff;
    --c-accent-dark: #0a97db;
    --c-mine: #dff3ff;
    --c-theirs: #f1f3f4;
    --c-hover: #eaf6fd;
    --c-active: #d5efff;
    --c-online: #3cb371;
    --c-danger: #d9534f;
    --c-system: #8a9399;
    --radius: 10px;
}

/* Modo oscuro: el que tenga el webmail (data-theme lo pone la pantalla con
   lo que manda el plugin); si no viene, el del sistema. */
:root[data-theme="dark"] {
    --c-bg: #21292c;
    --c-side: #2c363a;
    --c-border: #3c464a;
    --c-text: #e8ecee;
    --c-muted: #a3acb0;
    --c-mine: #10465f;
    --c-theirs: #333d41;
    --c-hover: #33424a;
    --c-active: #1d4f68;
    --c-system: #8f9a9f;
}
@media (prefers-color-scheme: dark) {
    :root:not([data-theme]) {
        --c-bg: #21292c;
        --c-side: #2c363a;
        --c-border: #3c464a;
        --c-text: #e8ecee;
        --c-muted: #a3acb0;
        --c-mine: #10465f;
        --c-theirs: #333d41;
        --c-hover: #33424a;
        --c-active: #1d4f68;
        --c-system: #8f9a9f;
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--c-bg);
    color: var(--c-text);
    font: 14px/1.45 Roboto, "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
}

button { font: inherit; color: inherit; }
.hidden { display: none !important; }

svg { width: 20px; height: 20px; fill: currentColor; flex: none; }

.chat-app { display: flex; height: 100vh; overflow: hidden; }

/* ---------- Lista lateral ---------- */
.chat-side {
    width: 320px;
    flex: none;
    display: flex;
    flex-direction: column;
    background: var(--c-side);
    border-right: 1px solid var(--c-border);
    min-height: 0;
}

.side-header, .conv-header, .modal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 58px;
    padding: 0 12px 0 16px;
    border-bottom: 1px solid var(--c-border);
    flex: none;
}

.side-title { font-size: 18px; font-weight: 500; flex: 1; }
.side-actions { display: flex; gap: 4px; }

.side-search { padding: 10px 12px; flex: none; }

input[type="search"], input[type="text"], textarea {
    width: 100%;
    border: 1px solid var(--c-border);
    border-radius: 6px;
    background: var(--c-bg);
    color: var(--c-text);
    padding: 8px 10px;
    font: inherit;
    outline: none;
}
input:focus, textarea:focus { border-color: var(--c-accent); box-shadow: 0 0 0 2px rgba(55, 190, 255, .25); }

.side-list { flex: 1; overflow-y: auto; min-height: 0; padding-bottom: 8px; }

.list-section {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--c-muted);
    padding: 12px 16px 6px;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 14px;
    border: 0;
    background: none;
    text-align: left;
    cursor: pointer;
    border-left: 3px solid transparent;
}
.list-item:hover { background: var(--c-hover); }
.list-item.active { background: var(--c-active); border-left-color: var(--c-accent); }

.item-body { flex: 1; min-width: 0; }
.item-top { display: flex; align-items: baseline; gap: 6px; }
.item-name { flex: 1; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 11px; color: var(--c-muted); flex: none; }
.item-bottom { display: flex; align-items: center; gap: 6px; }
.item-preview { flex: 1; font-size: 13px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item.unread .item-name, .list-item.unread .item-preview { font-weight: 600; color: var(--c-text); }

.badge {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 10px;
    background: var(--c-accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
}

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

/* ---------- Avatares ---------- */
.avatar {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    flex: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    background: #8a9399;
    user-select: none;
}
.avatar.small { width: 30px; height: 30px; font-size: 12px; }
.avatar.group { border-radius: 10px; }
.avatar .dot {
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--c-online);
    border: 2px solid var(--c-side);
}

/* ---------- Conversación ---------- */
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--c-muted);
    text-align: center;
    padding: 24px;
}
.empty-state h2 { margin: 12px 0 4px; font-weight: 500; color: var(--c-text); font-size: 18px; }
.empty-state p { margin: 0; }
.empty-icon { width: 56px; height: 56px; color: var(--c-accent); fill: none; }

.conversation { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.conv-title { flex: 1; min-width: 0; }
.conv-name { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub { font-size: 12px; color: var(--c-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-sub.online { color: var(--c-online); }

.icon-btn.back-btn { display: none; }

.icon-btn {
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--c-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: none;
}
.icon-btn:hover { background: var(--c-hover); color: var(--c-accent-dark); }
.icon-btn svg { fill: currentColor; }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px 8px; min-height: 0; }

.load-more {
    display: block;
    margin: 0 auto 12px;
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    border-radius: 14px;
    padding: 4px 14px;
    font-size: 12px;
    color: var(--c-muted);
    cursor: pointer;
}

.day-sep {
    text-align: center;
    font-size: 12px;
    color: var(--c-muted);
    margin: 14px 0 10px;
}
.day-sep span { background: var(--c-bg); padding: 2px 10px; border-radius: 10px; border: 1px solid var(--c-border); }

.msg { display: flex; gap: 8px; margin: 2px 0; align-items: flex-end; }
.msg.mine { justify-content: flex-end; }
.msg .avatar { visibility: hidden; }
.msg.first .avatar { visibility: visible; }
.msg.mine .avatar { display: none; }

.bubble {
    max-width: min(560px, 75%);
    padding: 7px 11px 6px;
    border-radius: var(--radius);
    background: var(--c-theirs);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.msg.mine .bubble { background: var(--c-mine); }
.msg.first .bubble { margin-top: 6px; }

.bubble .author { display: block; font-size: 12px; font-weight: 600; color: var(--c-accent-dark); margin-bottom: 1px; white-space: normal; }
.bubble .time { display: block; text-align: right; font-size: 10.5px; color: var(--c-muted); margin-top: 2px; white-space: normal; }
.bubble a { color: var(--c-accent-dark); }
.bubble img.att-img { display: block; max-width: 100%; max-height: 280px; border-radius: 6px; margin: 2px 0 4px; cursor: zoom-in; }
.att-file {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 6px;
    background: rgba(0, 0, 0, .05);
    text-decoration: none;
    color: inherit !important;
    margin: 2px 0 4px;
    white-space: normal;
}
.att-file small { display: block; color: var(--c-muted); }

.msg-system { text-align: center; font-size: 12px; color: var(--c-system); margin: 10px 0; white-space: normal; }

.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 1px solid var(--c-danger); }

/* ---------- Escribir ---------- */
.composer { border-top: 1px solid var(--c-border); padding: 10px 14px 6px; flex: none; }
.composer-row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { resize: none; max-height: 160px; line-height: 1.4; }
.composer-hint { font-size: 11px; color: var(--c-muted); margin: 4px 0 0 46px; }
.attach-btn { cursor: pointer; }

.send-btn {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: var(--c-accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex: none;
}
.send-btn:disabled { background: var(--c-border); cursor: default; }
.send-btn:not(:disabled):hover { background: var(--c-accent-dark); }

.attach-preview {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    padding: 6px 10px;
    margin-bottom: 8px;
    border: 1px dashed var(--c-border);
    border-radius: 6px;
}
.attach-preview span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.link-btn { border: 0; background: none; color: var(--c-accent-dark); cursor: pointer; padding: 0; }

.drop-hint { outline: 2px dashed var(--c-accent); outline-offset: -8px; }

/* ---------- Ventanas ---------- */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .4);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 50;
}
.modal-box {
    width: 100%;
    max-width: 460px;
    max-height: calc(100vh - 32px);
    background: var(--c-bg);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
.modal-header h3 { flex: 1; margin: 0; font-size: 16px; font-weight: 500; }
.modal-body { padding: 14px 16px; overflow-y: auto; min-height: 0; }
.modal-footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--c-border);
    flex-wrap: wrap;
}
.modal-error { flex: 1; color: var(--c-danger); font-size: 13px; }
.spacer { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span, .field-label { display: block; font-size: 12px; color: var(--c-muted); margin-bottom: 4px; }
.inline-field { display: flex; gap: 8px; }

.btn {
    border: 1px solid var(--c-border);
    background: var(--c-bg);
    border-radius: 6px;
    padding: 7px 14px;
    cursor: pointer;
}
.btn:hover { background: var(--c-hover); }
.btn-primary { background: var(--c-accent); border-color: var(--c-accent); color: #fff; }
.btn-primary:hover { background: var(--c-accent-dark); }
.btn-danger { color: var(--c-danger); }
.btn:disabled { opacity: .6; cursor: default; }

.picked { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--c-active);
    border-radius: 14px;
    padding: 3px 4px 3px 10px;
    font-size: 12px;
}
.chip button { border: 0; background: none; cursor: pointer; padding: 0 4px; color: var(--c-muted); }

.pick-list, .member-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--c-border); border-radius: 6px; }
.pick-list .list-item, .member-list .list-item { padding: 7px 10px; }
.pick-list .list-item input { margin-right: 2px; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 7px 10px; }
.member-row small { display: block; color: var(--c-muted); font-size: 12px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background: #2c363a;
    color: #fff;
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 13px;
    z-index: 60;
    max-width: calc(100% - 32px);
}

.fatal {
    position: fixed;
    inset: 0;
    background: var(--c-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
    color: var(--c-muted);
    z-index: 70;
}

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 80;
    cursor: zoom-out;
}
.lightbox img { max-width: 94vw; max-height: 94vh; }

/* ---------- Celular ---------- */
@media (max-width: 760px) {
    .chat-side { width: 100%; border-right: 0; }
    .chat-main { display: none; }
    .chat-app.show-conv .chat-side { display: none; }
    .chat-app.show-conv .chat-main { display: flex; }
    .icon-btn.back-btn { display: inline-flex; }
    .messages { padding: 12px 10px 6px; }
    .bubble { max-width: 85%; }
    .composer-hint { display: none; }
}
