/* =========================
   Messaging (Shared)
   ========================= */
.messages {
    background:
        radial-gradient(640px 220px at 0% 0%, rgba(23, 103, 211, 0.07), transparent 60%),
        linear-gradient(180deg, #f8fbfe 0%, #eef4f9 100%);
    overflow-y: auto;
    padding: var(--space-3) var(--space-4) var(--space-5);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-height: 0;
}
.messages::after {
    content: "";
    position: absolute;
    inset: 0;
    background: radial-gradient(520px 180px at 76% -20%, rgba(23, 103, 211, 0.08), transparent 60%);
    pointer-events: none;
}
.bubble {
    max-width: min(92%, 760px);
    border: 1px solid #d9e2ec;
    border-radius: 18px;
    padding: var(--space-3) var(--space-4);
    background: #ffffff;
    line-height: 1.5;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
    position: relative;
    animation: rise .18s ease-out;
}
.bubble.latest {
    box-shadow: 0 0 0 2px rgba(23, 103, 211, 0.12);
}
.bubble.customer {
    margin-left: auto;
    background: linear-gradient(135deg, #1767d3 0%, #0e4fa8 100%);
    color: #fff;
    border-color: #1767d3;
}
.bubble.admin {
    margin-right: auto;
    max-width: 100%;
    background: #ffffff;
    border-color: #dde6f0;
}
.main-chat .bubble-from-customer {
    margin-right: auto;
    margin-left: 0;
    max-width: min(100%, 860px);
    background: linear-gradient(180deg, #ffffff 0%, #f9fbff 100%);
    border-left: 4px solid rgba(23, 103, 211, 0.48);
    color: #12243b;
}
.main-chat .bubble-from-admin {
    margin-left: auto;
    max-width: min(88%, 720px);
    background: linear-gradient(180deg, #eef5ff 0%, #e5efff 100%);
    border-right: 4px solid rgba(33, 79, 149, 0.18);
    color: #143051;
}
.main-chat .bubble-from-bot {
    border-style: dashed;
    background: linear-gradient(180deg, #f8fafc 0%, #eef3f7 100%);
    border-color: #d7e0eb;
    color: #4a5d76;
}
.bubble-grouped {
    margin-top: -4px;
}
.bubble-grouped .meta {
    opacity: 0.72;
    margin-bottom: 6px;
}
.meta {
    display: flex;
    justify-content: space-between;
    gap: var(--space-2);
    font-size: var(--font-xs);
    opacity: .85;
    margin-bottom: var(--space-2);
    align-items: center;
}
.meta-sender {
    font-weight: 600;
}
.meta-time {
    color: var(--muted);
    white-space: nowrap;
}
.meta-right {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.bubble.customer .meta { color: rgba(255, 255, 255, 0.85); }
.bubble.admin .meta { color: #3b4259; }
.main-chat .bubble-from-customer .meta { color: #4f6279; }
.main-chat .bubble-from-admin .meta { color: #4a5d76; }
.main-chat .bubble-from-bot .meta { color: #66798f; }
.channel-pill {
    margin-left: var(--space-2);
    padding: 2px var(--space-2);
    border-radius: 999px;
    font-size: var(--font-xs);
    font-weight: 600;
    background: rgba(23, 103, 211, 0.08);
    color: #214f95;
}
.channel-pill.email {
    background: rgba(23, 103, 211, 0.1);
    color: #1767d3;
}
.source-pill {
    margin-left: 0;
    background: rgba(15, 23, 42, 0.08);
    color: #334155;
}
.source-pill-marker {
    background: rgba(245, 158, 11, 0.2);
    color: #92400e;
}
.source-pill-file {
    background: rgba(14, 165, 233, 0.16);
    color: #0369a1;
}
.source-pill-customer_email {
    background: rgba(255, 46, 139, 0.14);
    color: #b71560;
}
.bubble.customer .channel-pill {
    background: rgba(255, 255, 255, 0.16);
    color: rgba(255, 255, 255, 0.92);
}
.bubble-source-marker {
    border-left: 4px solid rgba(245, 158, 11, 0.62);
    background: linear-gradient(180deg, #fffbf4 0%, #fff8ea 100%);
}
.bubble-source-marker .text {
    color: #78350f;
}
.bubble-day-separator {
    align-self: center;
    border: 1px solid #dbe4ee;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.86);
    color: #607289;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.01em;
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.04);
}
.text {
    white-space: pre-wrap;
    word-break: break-word;
}
.text details {
    margin-top: 10px;
}
.text summary {
    cursor: pointer;
    color: #1767d3;
    font-size: 12px;
    font-weight: 700;
}
.text summary::-webkit-details-marker {
    color: #1767d3;
}
.bubble-raw-detail {
    margin-top: 8px;
    padding: 10px 12px;
    border: 1px solid #dce5ef;
    border-radius: 12px;
    background: #f8fbfe;
    color: #52657b;
    font-size: 12px;
    line-height: 1.55;
    white-space: pre-wrap;
}
.bubble-preview {
    display: none;
    margin-top: 2px;
    font-size: 12px;
    opacity: 0.82;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bubble.collapsed {
    cursor: pointer;
}
.bubble.collapsed .text {
    display: none;
}
.bubble.collapsed .bubble-preview {
    display: block;
}
.template-row {
    margin-bottom: 8px;
}
.template-row select {
    width: 100%;
}
.composer {
    border-top: 1px solid var(--border);
    background: var(--panel);
    padding: var(--space-3) var(--space-4) var(--space-4);
}
.composer-shell {
    padding-bottom: calc(var(--space-4) + var(--safe-area-bottom));
}
.composer-tools {
    display: grid;
    gap: 10px;
    margin-bottom: 6px;
}
.composer:focus-within {
    border-top-color: rgba(46, 108, 255, 0.5);
}
.customer-composer__input-row,
.admin-composer__template-row,
.admin-composer__input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: var(--space-2);
    align-items: center;
    min-width: 0;
}
.composer-actions {
    display: flex;
    gap: var(--space-2);
    align-items: center;
}
.composer-actions button {
    white-space: nowrap;
}
.customer-composer__attachments {
    display: grid;
    grid-template-columns: 1fr;
    margin-top: var(--space-2);
}
.file-hint {
    font-size: var(--font-sm);
    color: var(--muted);
}
.file-input {
    width: 100%;
}
.file-size {
    margin-top: var(--space-1);
    font-size: var(--font-sm);
    color: var(--muted);
}
.file-selected {
    font-size: var(--font-sm);
    color: #1f2a44;
    margin-top: var(--space-1);
}
.file-preview {
    display: block;
    margin-top: 8px;
    max-width: 100%;
    max-height: 260px;
    border-radius: 10px;
    border: 1px solid var(--border);
    cursor: zoom-in;
}
.composer-hint {
    font-size: var(--font-sm);
    color: var(--muted);
    margin: var(--space-2) 0 0;
}
.file-preview-hint {
    margin-top: var(--space-2);
    font-size: var(--font-sm);
    color: var(--warning);
}
.file-list {
    display: grid;
    gap: var(--space-3);
}
.file-item {
    display: grid;
    gap: var(--space-1);
}
.file-badge {
    align-self: start;
    font-size: var(--font-xs);
    padding: 3px var(--space-2);
    border-radius: 999px;
    background: #eef2ff;
    color: #1f2a44;
    display: inline-flex;
    width: fit-content;
}
.file-count {
    align-self: start;
    font-size: var(--font-xs);
    padding: 4px var(--space-2);
    border-radius: 999px;
    background: #eef2ff;
    color: #1f2a44;
    display: inline-flex;
    margin-bottom: var(--space-1);
}
.file-exif {
    font-size: var(--font-sm);
    color: #4b5563;
    margin-top: var(--space-1);
    display: none;
}
.file-exif.open {
    display: block;
}
.sidebar-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-3);
    padding: var(--space-2);
    border: 1px solid #e2e6f4;
    border-radius: var(--radius-md);
    background: #f8fafc;
}
.filter-btn {
    border: 1px solid #d3ddee;
    background: #ffffff;
    color: #24314c;
    font-size: var(--font-sm);
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}
.filter-btn.active {
    background: #1767d3;
    color: #fff;
    border-color: #1767d3;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}
.chat-snippet {
    font-size: var(--font-sm);
    color: #4b5563;
    margin-top: var(--space-2);
}
.toast {
    position: fixed;
    right: 20px;
    bottom: calc(24px + var(--safe-area-bottom));
    background: #12243b;
    color: #fff;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: 13px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .2s ease, transform .2s ease;
    z-index: 1000;
    pointer-events: none;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.file-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-1);
}
.file-action-btn {
    border: 1px solid #d3ddee;
    background: #fff;
    color: #1f2a44;
    font-size: var(--font-sm);
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 999px;
    text-decoration: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 46px;
}
.file-action-btn:hover {
    border-color: #c9d2ea;
}
.media-count {
    border: 1px solid #d3ddee;
    background: #fff;
    color: #1f2a44;
    font-size: var(--font-sm);
    font-weight: 600;
    padding: 8px 12px;
    border-radius: 999px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
}
.subject-line {
    font-size: var(--font-sm);
    color: #4b5563;
    margin: 2px 0 6px;
    font-weight: 600;
}
.toolbar-shell {
    width: 100%;
}
.chat-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    border-bottom: 1px solid var(--border);
    background: #f6f7fb;
}
.chat-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.link-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: #1f2a44;
    font-size: var(--font-sm);
    padding: 8px var(--space-3);
    border-radius: 999px;
    text-decoration: none;
    min-height: 46px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.message-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

input[type="email"],
input[type="password"],
input[type="search"],
textarea,
button,
select {
    border: 1px solid #c8d2e4;
    border-radius: var(--radius-md);
    font: inherit;
    padding: var(--space-3) var(--space-4);
    background: #fff;
    transition: border-color .15s ease, box-shadow .15s ease, transform .1s ease, background-color .15s ease, color .15s ease;
}
textarea {
    width: 100%;
    min-height: 58px;
    max-height: 170px;
    resize: vertical;
}
#adminMessage {
    min-height: 180px;
    max-height: 520px;
}
button {
    border: 1px solid transparent;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
    padding: 10px var(--space-5);
    box-shadow: 0 4px 10px rgba(199, 31, 106, 0.18);
    min-height: 44px;
    touch-action: manipulation;
}
.cta-button,
#sendBtn {
    letter-spacing: 0.01em;
}
#sendBtn:disabled {
    background: linear-gradient(135deg, #b6bac9 0%, #9aa0b3 100%);
    border-color: #b6bac9;
    box-shadow: none;
}
button:hover { transform: translateY(-1px); }
button:active { transform: translateY(0); }
button:disabled {
    opacity: 1;
    color: #e5e7eb;
    background: linear-gradient(135deg, #9ca3af 0%, #7f8795 100%);
    cursor: not-allowed;
    box-shadow: none;
}
.link-btn,
.file-action-btn,
.settings-action-btn,
.settings-page__logout,
.admin-back-btn {
    border: 1px solid #d3ddee;
    background: #ffffff;
    color: #1f2a44;
    font-weight: 600;
    box-shadow: none;
}
.link-btn:hover,
.file-action-btn:hover,
.settings-action-btn:hover,
.settings-page__logout:hover,
.admin-back-btn:hover {
    transform: none;
    background: #f7f9fe;
    border-color: #becbe6;
}
.link-btn:active,
.file-action-btn:active,
.settings-action-btn:active,
.settings-page__logout:active,
.admin-back-btn:active {
    transform: none;
    background: #f1f5fd;
}
.filter-btn:hover {
    border-color: #bac8e4;
    background: #f7f9fe;
}
.filter-btn.active:hover {
    background: #1f244c;
    border-color: #1f244c;
}
input:focus,
textarea:focus {
    outline: none;
    border-color: rgba(46, 108, 255, 0.65);
    box-shadow: 0 0 0 4px rgba(46, 108, 255, 0.12);
}
.status {
    min-height: 22px;
    margin-top: var(--space-2);
    color: var(--danger);
    font-size: 13px;
    line-height: 1.4;
}
.status:empty {
    min-height: 0;
    margin-top: 0;
}
.status:not(:empty) {
    border: 1px solid #f1c5c5;
    border-radius: 11px;
    background: #fff4f4;
    padding: 8px 10px;
}
.status.ok {
    color: #166534;
    border-color: #bbf7d0;
    background: #f0fdf4;
}
.status.info {
    color: #1f2a44;
    border-color: #d6deef;
    background: #f8faff;
}
.status.warn {
    color: #9f1239;
    border-color: #fecdd3;
    background: #fff1f2;
}
.status.loading {
    color: #1f2a44;
    border-color: #bfdbfe;
    background: #eff6ff;
}
