:root {
    --sidebar-width: 300px;
    --bubble-sent-bg: #0b93f6;
    --bubble-sent-text: #ffffff;
    --bubble-recv-bg: #e9ecef;
    --bubble-recv-text: #212529;
    --bubble-radius: 14px;
    --bubble-tail-size: 6px;
    --msg-anim-duration: 600ms;
    --msg-group-gap: 3px;
    --msg-block-gap: 16px;
    --date-divider-color: #dee2e6;
    --date-divider-pill-bg: #f0f0f0;
    --date-divider-text: #6c757d;
    --convo-border: #f0f0f0;
    --convo-hover-bg: #f8f9fa;
    --convo-active-bg: #e8f0fe;
    --convo-presence-border: #fff;
    --convo-active-presence-border: #e8f0fe;
    --msg-meta-color: #6c757d;
    --msg-meta-strong-color: #333;
    --msg-time-color: #adb5bd;
    --typing-color: #6c757d;
}

[data-bs-theme="dark"] {
    --bubble-recv-bg: #3d3d3d;
    --bubble-recv-text: #f0f0f0;
    --date-divider-color: #444;
    --date-divider-pill-bg: #2d2d2d;
    --date-divider-text: #adb5bd;
    --convo-border: #2d2d2d;
    --convo-hover-bg: #2a2a2a;
    --convo-active-bg: #1a3a5c;
    --convo-presence-border: #212529;
    --convo-active-presence-border: #1a3a5c;
    --msg-meta-color: #adb5bd;
    --msg-meta-strong-color: #e0e0e0;
    --msg-time-color: #6c757d;
    --typing-color: #adb5bd;
}

body {
    height: 100vh;
    overflow: hidden;
}

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    font-size: 14px;
    flex-shrink: 0;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.online {
    background-color: #28a745;
}

.status-dot.idle {
    background-color: #ffc107;
}

.status-dot.offline {
    background-color: #6c757d;
}

.login-container {
    max-width: 400px;
    margin: 100px auto;
}

.nav-brand-icon {
    font-size: 1.25rem;
    color: #0b93f6;
}

.nav-user-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(255,255,255,0.1);
    border-radius: 20px;
    padding: 3px 12px 3px 3px;
    transition: background 150ms;
    border: none;
    color: #fff;
    cursor: pointer;
}

.nav-user-pill:hover {
    background: rgba(255,255,255,0.18);
}

.nav-avatar-wrap {
    position: relative;
    display: inline-flex;
}

.nav-avatar-wrap .status-dot {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border: 2px solid #212529;
    border-radius: 50%;
}

.navbar-shadow {
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    z-index: 1050;
}

.avatar-sm {
    width: 28px;
    height: 28px;
    font-size: 11px;
}

.avatar-spacer {
    width: 36px;
    flex-shrink: 0;
}

.convo-item {
    cursor: pointer;
    border-bottom: 1px solid var(--convo-border);
    transition: background 100ms;
}

.convo-item:hover {
    background: var(--convo-hover-bg);
}

.convo-item.active {
    background: var(--convo-active-bg);
}

.convo-avatar {
    position: relative;
    flex-shrink: 0;
}

.convo-presence {
    position: absolute;
    bottom: -1px;
    right: -1px;
    width: 10px;
    height: 10px;
    border: 2px solid var(--convo-presence-border);
    border-radius: 50%;
}

.convo-item.active .convo-presence {
    border-color: var(--convo-active-presence-border);
}

.convo-text {
    flex: 1;
    min-width: 0;
}

.convo-name {
    font-weight: 600;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.convo-time {
    font-size: 0.7rem;
    color: var(--msg-time-color);
    white-space: nowrap;
    flex-shrink: 0;
}

.convo-preview {
    font-size: 0.8rem;
    color: var(--msg-meta-color);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.msg-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: var(--msg-group-gap);
    padding: 0 1rem;
}

.msg-row.msg-block-end {
    margin-bottom: var(--msg-block-gap);
}

.msg-sent {
    justify-content: flex-end;
}

.msg-bubble {
    display: inline-block;
    padding: 8px 12px;
    max-width: 75%;
    word-break: break-word;
    position: relative;
}

.msg-content {
    min-width: 0;
    flex: 1;
}

.msg-sent .msg-content {
    text-align: right;
}

.msg-received .msg-bubble {
    background: var(--bubble-recv-bg);
    color: var(--bubble-recv-text);
}

.msg-sent .msg-bubble {
    background: var(--bubble-sent-bg);
    color: var(--bubble-sent-text);
}

.msg-received.msg-standalone .msg-bubble { border-radius: 4px var(--bubble-radius) var(--bubble-radius) var(--bubble-radius); }
.msg-received.msg-start .msg-bubble { border-radius: 4px var(--bubble-radius) var(--bubble-radius) 8px; }
.msg-received.msg-middle .msg-bubble { border-radius: 8px var(--bubble-radius) var(--bubble-radius) 8px; }
.msg-received.msg-end .msg-bubble { border-radius: 8px var(--bubble-radius) var(--bubble-radius) var(--bubble-radius); }

.msg-sent.msg-standalone .msg-bubble { border-radius: var(--bubble-radius) 4px var(--bubble-radius) var(--bubble-radius); }
.msg-sent.msg-start .msg-bubble { border-radius: var(--bubble-radius) 4px 8px var(--bubble-radius); }
.msg-sent.msg-middle .msg-bubble { border-radius: var(--bubble-radius) 8px 8px var(--bubble-radius); }
.msg-sent.msg-end .msg-bubble { border-radius: var(--bubble-radius) 8px var(--bubble-radius) var(--bubble-radius); }

.msg-received .bubble-tail {
    position: absolute;
    left: -5px;
    top: 8px;
    width: 0;
    height: 0;
    border: 5px solid transparent;
    border-right-color: var(--bubble-recv-bg);
    border-left: 0;
}

.msg-sent .bubble-tail {
    display: none;
}

.msg-meta {
    font-size: 0.75rem;
    color: var(--msg-meta-color);
    margin-bottom: 2px;
}

.msg-meta strong {
    color: var(--msg-meta-strong-color);
}

.msg-sent .msg-meta {
    text-align: right;
}

.msg-text {
    word-break: break-word;
}

.msg-sent .msg-text a {
    color: #cce5ff;
}

.msg-deleted {
    font-size: 0.8rem;
    color: var(--msg-meta-color);
    font-style: italic;
}

.msg-sent .msg-deleted {
    color: rgba(255, 255, 255, 0.7);
}

.msg-edited {
    font-size: 0.7rem;
    color: var(--msg-meta-color);
    display: block;
    margin-top: 2px;
}

.msg-sent .msg-edited {
    color: rgba(255, 255, 255, 0.6);
}

.msg-time-hover {
    font-size: 10px;
    color: var(--msg-time-color);
    opacity: 0;
    transition: opacity 150ms;
    margin-top: 2px;
}

.msg-sent .msg-time-hover {
    text-align: right;
}

.msg-row:hover .msg-time-hover {
    opacity: 1;
}

.msg-time-hover.msg-time-visible {
    opacity: 1;
}

.msg-actions {
    display: none;
    font-size: 0.75rem;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(0,0,0,0.6);
    border-radius: 8px;
    padding: 2px 8px;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 150ms;
}

.msg-sent .msg-actions {
    right: 100%;
    margin-right: 6px;
}

.msg-received .msg-actions {
    left: 100%;
    margin-left: 6px;
}

.msg-row:hover .msg-actions {
    display: block;
    opacity: 1;
}

.msg-actions a {
    color: #fff;
    text-decoration: none;
    margin: 0 4px;
}

.msg-actions a:hover {
    text-decoration: underline;
}

.msg-bubble {
    position: relative;
}

.date-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 16px 1rem;
}

.date-divider-line {
    flex: 1;
    height: 1px;
    background: var(--date-divider-color);
}

.date-divider-pill {
    font-size: 11px;
    color: var(--date-divider-text);
    background: var(--date-divider-pill-bg);
    padding: 2px 12px;
    border-radius: 12px;
    white-space: nowrap;
}

.typing-indicator {
    font-size: 0.8rem;
    color: var(--typing-color);
    padding: 0.25rem 1rem;
    min-height: 1.5rem;
}

.new-messages-bar {
    text-align: center;
    cursor: pointer;
    background: #0d6efd;
    color: #fff;
    padding: 0.25rem;
    font-size: 0.8rem;
    display: none;
}

@keyframes msgSlideIn {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.msg-row.msg-new {
    animation: msgSlideIn var(--msg-anim-duration) ease;
}

@media (prefers-reduced-motion: reduce) {
    .msg-row.msg-new { animation: none; }
}

.inline-code {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.85em;
    background: #f0f0f0;
    border: 1px solid #e0e0e0;
    padding: 1px 4px;
    border-radius: 4px;
}

.code-block {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 0.82em;
    background: #f8f8f8;
    color: #333;
    border: 1px solid #e0e0e0;
    border-left: 3px solid #ddd;
    padding: 6px 10px;
    border-radius: 4px;
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
    margin: 4px 0;
    white-space: pre;
    line-height: 1.4;
}

.code-block code {
    background: none;
    padding: 0;
    color: inherit;
}

.msg-sent .inline-code {
    background: #e8e8e8;
    border-color: #d0d0d0;
    color: #c7254e;
}

.msg-sent .code-block {
    background: #f0f0f0;
    color: #333;
    border-color: #d0d0d0;
    border-left-color: #bbb;
}

[data-bs-theme="dark"] .color-opt-dark {
    color: #e8e8e8 !important;
}

[data-bs-theme="dark"] .card {
    background: #2a2a3a;
    border-color: #3a3a4a;
}

[data-bs-theme="dark"] .btn-outline-secondary {
    color: #adb5bd;
    border-color: #4a4a5a;
}

[data-bs-theme="dark"] .btn-outline-secondary:hover {
    background: #3a3a4a;
    color: #e8e8e8;
    border-color: #5a5a6a;
}

[data-bs-theme="dark"] .table {
    color: #e8e8e8;
    border-color: #3a3a4a;
}

[data-bs-theme="dark"] .table-striped > tbody > tr:nth-of-type(odd) {
    color: #e8e8e8;
    --bs-table-striped-bg: #252535;
}

[data-bs-theme="dark"] .table-hover > tbody > tr:hover {
    color: #e8e8e8;
    --bs-table-hover-bg: #2a2a3a;
}

[data-bs-theme="dark"] .border {
    border-color: #3a3a4a !important;
}

[data-bs-theme="dark"] .nav-pills .nav-link:not(.active) {
    color: #adb5bd;
}

[data-bs-theme="dark"] .list-group-item-action:not(.active) {
    color: #e8e8e8;
    background: transparent;
}

[data-bs-theme="dark"] .list-group-item-action:not(.active):hover {
    background: #2a2a3a;
}

.save-indicator {
    font-size: 0.75rem;
    color: #198754;
    position: absolute;
    right: 0;
    top: -0.25rem;
    opacity: 1;
    transition: opacity 0.5s;
}

.save-indicator.fade-out {
    opacity: 0;
}

[data-bs-theme="dark"] .save-indicator {
    color: #75b798;
}

[data-bs-theme="dark"] .inline-code {
    background: #3a3a4a;
    border-color: #4a4a5a;
}

[data-bs-theme="dark"] .code-block {
    background: #1e1e2e;
    color: #e0e0e0;
    border-color: #3a3a4a;
    border-left-color: #555;
}

[data-bs-theme="dark"] .msg-sent .inline-code {
    background: rgba(0,0,0,0.3);
    color: #ff8fab;
    border-color: rgba(255,255,255,0.2);
}

[data-bs-theme="dark"] .msg-sent .code-block {
    background: rgba(0,0,0,0.3);
    color: #f0f0f0;
    border-color: rgba(255,255,255,0.2);
    border-left-color: rgba(255,255,255,0.4);
}

.msg-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 12px;
    cursor: pointer;
    display: block;
    margin: 0;
}

.msg-bubble:has(.msg-image) {
    background: none !important;
    padding: 0;
    border: none;
}

.msg-bubble:has(.msg-image) .bubble-tail {
    display: none;
}

.msg-image:hover {
    opacity: 0.9;
}

.msg-image-expired {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 120px;
    background: #f0f0f0;
    border: 1px dashed #ccc;
    border-radius: 12px;
    color: #999;
    font-size: 0.8rem;
    font-style: italic;
    text-align: center;
    gap: 4px;
}

[data-bs-theme="dark"] .msg-image-expired {
    background: #2a2a3a;
    border-color: #444;
    color: #777;
}

[data-bs-theme="dark"] .msg-image {
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}
