:root {
    --bg: #050814;
    --panel: rgba(9, 18, 34, .94);
    --panel-solid: #091222;
    --panel-soft: rgba(16, 31, 52, .88);
    --panel-hover: rgba(27, 52, 82, .72);
    --chat-bg: rgba(5, 11, 22, .9);
    --bubble-in: #101827;
    --bubble-out: #07384f;
    --line: rgba(113, 199, 255, .18);
    --line-strong: rgba(54, 211, 255, .42);
    --text: #eaf6ff;
    --text-soft: #c7d9e8;
    --text-muted: #8aa6bd;
    --accent: #00b7ff;
    --accent-strong: #22d3ee;
    --accent-violet: #8b5cf6;
    --danger-bg: rgba(127, 29, 29, .34);
    --danger-line: rgba(248, 113, 113, .34);
}

html {
    color-scheme: dark;
}

body {
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 12% 0%, rgba(0, 183, 255, .20), transparent 30%),
        radial-gradient(circle at 88% 4%, rgba(139, 92, 246, .18), transparent 32%),
        radial-gradient(circle at 52% 100%, rgba(34, 211, 238, .10), transparent 34%),
        linear-gradient(135deg, #050814, #071827 48%, #0a1020);
    background-attachment: fixed;
}

a {
    color: var(--accent-strong);
}

a:hover {
    color: #7de8ff;
}

.app-navbar {
    background: rgba(5, 10, 22, .84);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 10px 28px rgba(0, 0, 0, .28);
    backdrop-filter: blur(14px);
}

.navbar-brand {
    color: var(--text) !important;
}

.app-navbar .nav-link {
    color: var(--text-muted);
    border-radius: 6px;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
    color: var(--text);
    background: rgba(34, 211, 238, .10);
}

.app-navbar .text-secondary {
    color: var(--text-muted) !important;
}

.btn-success,
.btn-neon {
    --bs-btn-color: #00131d;
    --bs-btn-bg: var(--accent-strong);
    --bs-btn-border-color: rgba(125, 232, 255, .55);
    --bs-btn-hover-color: #00131d;
    --bs-btn-hover-bg: #67e8f9;
    --bs-btn-hover-border-color: #a5f3fc;
    --bs-btn-active-color: #00131d;
    --bs-btn-active-bg: var(--accent);
    --bs-btn-active-border-color: var(--accent);
    background-image: linear-gradient(135deg, var(--accent), var(--accent-strong) 54%, #a78bfa);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, .08) inset, 0 10px 22px rgba(0, 183, 255, .18);
    font-weight: 700;
}

.btn-outline-secondary {
    --bs-btn-color: var(--text-soft);
    --bs-btn-border-color: rgba(138, 166, 189, .42);
    --bs-btn-hover-color: var(--text);
    --bs-btn-hover-bg: rgba(138, 92, 246, .18);
    --bs-btn-hover-border-color: rgba(34, 211, 238, .42);
    --bs-btn-active-bg: rgba(0, 183, 255, .22);
    --bs-btn-active-border-color: var(--accent);
}

.btn-outline-danger {
    --bs-btn-color: #fecaca;
    --bs-btn-border-color: rgba(248, 113, 113, .45);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: rgba(185, 28, 28, .48);
    --bs-btn-hover-border-color: rgba(248, 113, 113, .7);
    --bs-btn-active-bg: rgba(153, 27, 27, .6);
    --bs-btn-active-border-color: rgba(248, 113, 113, .7);
}

.form-control,
.form-select {
    color: var(--text);
    background-color: rgba(3, 9, 20, .72);
    border-color: rgba(113, 199, 255, .22);
}

.form-control::placeholder {
    color: #6f8aa1;
}

.form-control:focus,
.form-select:focus {
    color: var(--text);
    background-color: rgba(5, 13, 28, .92);
    border-color: var(--accent-strong);
    box-shadow: 0 0 0 .2rem rgba(34, 211, 238, .16);
}

.form-text,
.form-label {
    color: var(--text-muted);
}

.alert-danger {
    color: #fecaca;
    background: var(--danger-bg);
    border-color: var(--danger-line);
}

.alert-success {
    color: #bbf7d0;
    background: rgba(20, 83, 45, .28);
    border-color: rgba(74, 222, 128, .32);
}

.alert-warning {
    color: #fde68a;
    background: rgba(113, 63, 18, .32);
    border-color: rgba(251, 191, 36, .3);
}

.modal-content {
    color: var(--text);
    background: rgba(8, 18, 34, .98);
    border: 1px solid var(--line);
    box-shadow: 0 24px 70px rgba(0, 0, 0, .52);
}

.modal-header,
.modal-footer {
    border-color: var(--line);
}

.btn-close {
    filter: invert(1) grayscale(1);
    opacity: .8;
}

.auth-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at 20% 10%, rgba(0, 183, 255, .30), transparent 35%),
        radial-gradient(circle at 80% 30%, rgba(139, 92, 246, .22), transparent 34%),
        linear-gradient(135deg, #050814, #071827 48%, #0a1020);
}

.auth-card {
    width: min(100%, 420px);
    color: var(--text);
    background: rgba(9, 18, 34, .92);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 28px;
    box-shadow: 0 18px 50px rgba(0, 0, 0, .46), 0 0 70px rgba(0, 183, 255, .12);
    backdrop-filter: blur(16px);
}

.auth-card h1 {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.auth-card p,
.reader-empty p,
.text-secondary {
    color: var(--text-muted) !important;
}

.page-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 28px 18px;
}

.page-shell.narrow {
    max-width: 680px;
}

.upload-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 22px;
}

.table-panel {
    overflow: hidden;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 44px rgba(0, 0, 0, .24);
}

.table-dark-custom {
    --bs-table-color: var(--text);
    --bs-table-bg: transparent;
    --bs-table-border-color: rgba(113, 199, 255, .12);
    --bs-table-hover-bg: rgba(0, 183, 255, .08);
}

.table-dark-custom th {
    color: var(--text-soft);
    background: rgba(3, 9, 20, .48);
    font-size: .82rem;
    font-weight: 700;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: .78rem;
    font-weight: 700;
}

.status-pill.success {
    color: #bbf7d0;
    background: rgba(34, 197, 94, .16);
    border: 1px solid rgba(74, 222, 128, .28);
}

.status-pill.failed {
    color: #fecaca;
    background: rgba(220, 38, 38, .16);
    border: 1px solid rgba(248, 113, 113, .28);
}

.app-shell {
    max-width: 1480px;
    margin: 0 auto;
    padding: 18px;
}

.reader-frame {
    height: calc(100vh - 94px);
    min-height: 620px;
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    overflow: hidden;
    background: rgba(9, 18, 34, .68);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .34), 0 0 90px rgba(0, 183, 255, .10);
    backdrop-filter: blur(18px);
}

.conversation-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: rgba(7, 15, 30, .86);
}

.conversation-actions {
    padding: 12px 14px 0;
}

.btn-xs {
    --bs-btn-padding-y: .16rem;
    --bs-btn-padding-x: .45rem;
    --bs-btn-font-size: .76rem;
    --bs-btn-border-radius: .25rem;
}

.conversation-search {
    padding: 10px 14px 14px;
    border-bottom: 1px solid var(--line);
}

.conversation-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.conversation-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid rgba(113, 199, 255, .10);
}

.conversation-item:hover,
.conversation-item.active {
    background: linear-gradient(90deg, rgba(0, 183, 255, .16), rgba(139, 92, 246, .10));
}

.conversation-item.active {
    box-shadow: inset 3px 0 0 var(--accent-strong);
}

.avatar {
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(0, 183, 255, .28), rgba(139, 92, 246, .24));
    border: 1px solid rgba(34, 211, 238, .32);
    color: var(--text);
    font-weight: 700;
    box-shadow: 0 0 22px rgba(0, 183, 255, .12);
}

.conversation-summary {
    min-width: 0;
    flex: 1;
}

.conversation-title-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.conversation-title-row strong {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.conversation-title-row time,
.conversation-meta {
    color: var(--text-muted);
    font-size: .78rem;
}

.conversation-meta {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reader-pane {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background:
        linear-gradient(rgba(5, 11, 22, .82), rgba(5, 11, 22, .82)),
        radial-gradient(circle at 20% 0%, rgba(0, 183, 255, .14), transparent 28%),
        radial-gradient(circle at 90% 100%, rgba(139, 92, 246, .12), transparent 30%);
}

.reader-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 12px 14px;
    background: rgba(8, 18, 34, .92);
    border-bottom: 1px solid var(--line);
}

.reader-title {
    min-width: 180px;
}

.reader-title h2 {
    font-size: 1rem;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.reader-title span {
    color: var(--text-muted);
    font-size: .78rem;
}

.inline-filters {
    display: grid;
    grid-template-columns: minmax(150px, 1.1fr) minmax(140px, .9fr) minmax(120px, .7fr) auto auto auto auto;
    gap: 8px;
    align-items: center;
    flex: 1;
}

.message-stage {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 18px;
}

.message-column {
    width: min(100%, 880px);
    margin: 0 auto;
}

.reader-empty {
    min-height: 100%;
    display: grid;
    place-content: center;
    justify-items: center;
    text-align: center;
    padding: 32px;
}

.reader-empty h2 {
    font-size: 1.25rem;
    color: var(--text);
}

.date-pill,
.system-message {
    width: fit-content;
    max-width: min(680px, 92%);
    margin: 10px auto;
    padding: 7px 12px;
    border-radius: 8px;
    background: rgba(8, 18, 34, .72);
    border: 1px solid rgba(34, 211, 238, .16);
    color: var(--text-soft);
    font-size: .8rem;
    text-align: center;
    box-shadow: 0 6px 18px rgba(0, 0, 0, .16);
}

.system-message {
    font-size: .84rem;
}

.bubble {
    width: fit-content;
    max-width: min(640px, 84%);
    margin: 8px 0;
    padding: 8px 10px 6px;
    border-radius: 8px;
    overflow-wrap: anywhere;
    box-shadow: 0 10px 24px rgba(0, 0, 0, .18);
}

.bubble.theirs {
    background: rgba(16, 24, 39, .96);
    border: 1px solid rgba(148, 163, 184, .12);
}

.bubble.mine {
    background: linear-gradient(135deg, rgba(7, 56, 79, .96), rgba(9, 74, 96, .94));
    border: 1px solid rgba(34, 211, 238, .18);
    margin-left: auto;
}

.bubble-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 2px;
}

.bubble-author {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: #67e8f9;
    font-size: .82rem;
    font-weight: 700;
}

.media-badges {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 4px;
    max-width: 55%;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.media-badge {
    display: inline-flex;
    align-items: center;
    min-height: 18px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: .62rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: 0;
    color: #03101c;
}

.media-badge.audio {
    background: linear-gradient(135deg, #38bdf8, #22d3ee);
}

.media-badge.video {
    background: linear-gradient(135deg, #a78bfa, #c084fc);
}

.media-badge.image {
    background: linear-gradient(135deg, #2dd4bf, #86efac);
}

.media-badge.sticker {
    background: linear-gradient(135deg, #f0abfc, #f472b6);
}

.media-badge.pdf {
    background: linear-gradient(135deg, #fb7185, #fca5a5);
}

.media-badge.contact {
    background: linear-gradient(135deg, #fbbf24, #fde68a);
}

.media-badge.document {
    color: var(--text);
    background: linear-gradient(135deg, #475569, #64748b);
}

.bubble-body {
    color: var(--text);
    white-space: normal;
    font-size: .95rem;
}

.bubble-meta {
    margin-top: 4px;
    color: var(--text-muted);
    text-align: right;
    font-size: .72rem;
}

.media-box {
    margin-bottom: 7px;
}

.image-trigger {
    display: block;
    padding: 0;
    border: 0;
    background: transparent;
    cursor: zoom-in;
}

.media-box img,
.media-box video {
    max-width: min(330px, 100%);
    max-height: 390px;
    border-radius: 6px;
    display: block;
    background: #020617;
}

.media-box audio {
    width: min(320px, 100%);
}

.media-box video,
.media-box audio {
    outline: none;
}

.load-media-button {
    display: block;
    width: min(330px, 100%);
    min-height: 42px;
    padding: 10px 12px;
    color: #7de8ff;
    text-align: left;
    background: rgba(0, 183, 255, .10);
    border: 1px solid rgba(34, 211, 238, .22);
    border-radius: 6px;
    cursor: pointer;
}

.load-media-button:hover {
    color: var(--text);
    background: rgba(0, 183, 255, .16);
    border-color: rgba(34, 211, 238, .42);
}

.file-unavailable {
    width: min(330px, 100%);
    padding: 10px 12px;
    color: #fecaca;
    background: rgba(127, 29, 29, .22);
    border: 1px solid rgba(248, 113, 113, .28);
    border-radius: 6px;
    font-size: .88rem;
}

.file-link {
    display: block;
    color: #7de8ff;
    background: rgba(0, 183, 255, .10);
    border: 1px solid rgba(34, 211, 238, .18);
    border-radius: 6px;
    padding: 10px;
    text-decoration: none;
}

.image-modal-content .modal-body {
    display: grid;
    place-items: center;
    background: #020617;
    min-height: 60vh;
}

.image-modal-content img {
    max-width: 100%;
    max-height: 78vh;
    object-fit: contain;
}

.upload-progress-modal .modal-body {
    padding-top: 22px;
}

.upload-progress {
    height: 22px;
    background: rgba(3, 9, 20, .8);
    border: 1px solid rgba(113, 199, 255, .18);
}

.upload-progress .progress-bar {
    color: #00131d;
    background-color: var(--accent-strong);
    background-image: linear-gradient(135deg, var(--accent), var(--accent-strong) 54%, #a78bfa);
    font-weight: 800;
}

.upload-progress-message {
    margin: 14px 0 4px;
    color: var(--text);
}

.upload-progress-note {
    margin: 0;
    color: var(--text-muted);
    font-size: .88rem;
}

.participants-editor {
    display: grid;
    gap: 10px;
}

.participant-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, .9fr);
    gap: 12px;
    align-items: center;
    padding: 10px;
    border: 1px solid rgba(113, 199, 255, .12);
    border-radius: 8px;
    background: rgba(3, 9, 20, .32);
}

.participant-row strong,
.participant-row span {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.participant-row span {
    color: var(--text-muted);
    font-size: .8rem;
}

* {
    scrollbar-color: rgba(34, 211, 238, .42) rgba(5, 11, 22, .55);
    scrollbar-width: thin;
}

::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(5, 11, 22, .55);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(0, 183, 255, .46), rgba(139, 92, 246, .42));
    border: 2px solid rgba(5, 11, 22, .55);
    border-radius: 999px;
}

@media (max-width: 1120px) {
    .reader-header {
        align-items: stretch;
        flex-direction: column;
    }

    .inline-filters {
        width: 100%;
    }
}

@media (max-width: 860px) {
    .app-shell {
        padding: 10px;
    }

    .reader-frame {
        height: auto;
        min-height: calc(100vh - 118px);
        grid-template-columns: 1fr;
    }

    .conversation-pane {
        max-height: 280px;
        min-height: 220px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .inline-filters {
        grid-template-columns: 1fr 1fr;
    }

    .inline-filters .form-control {
        grid-column: 1 / -1;
    }

    .participant-row {
        grid-template-columns: 1fr;
    }

    .bubble {
        max-width: 94%;
    }
}
