:root {
    --bg: #07111a;
    --bg-soft: #0c1722;
    --panel: #0f1b27;
    --panel-2: #132334;
    --panel-3: #182c41;
    --line: rgba(148, 163, 184, 0.14);
    --line-strong: rgba(96, 165, 250, 0.25);
    --text: #e7eef7;
    --muted: #8ca0b5;
    --blue: #1d9bf0;
    --blue-2: #3b82f6;
    --green: #0f766e;
    --green-2: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: Inter, system-ui, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(29, 155, 240, 0.18), transparent 26%),
        radial-gradient(circle at top right, rgba(59, 130, 246, 0.12), transparent 22%),
        linear-gradient(180deg, #050b12 0%, #07111a 100%);
    color: var(--text);
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    display: block;
    max-width: 100%;
}

.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card,
.card,
.modal-card {
    background: linear-gradient(180deg, rgba(19, 35, 52, 0.98), rgba(10, 21, 31, 0.98));
    border: 1px solid var(--line);
    box-shadow: var(--shadow);
    border-radius: 28px;
}

.login-card {
    width: min(520px, 100%);
    padding: 32px;
}

.brand-lockup {
    display: flex;
    gap: 18px;
    align-items: center;
    margin-bottom: 24px;
}

.brand-lockup.compact {
    margin-bottom: 0;
}

.brand-logo {
    width: 72px;
    height: 72px;
    border-radius: 24px;
    padding: 4px;
    background: linear-gradient(135deg, rgba(29, 155, 240, 0.9), rgba(37, 99, 235, 0.18));
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.24);
}

.brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 20px;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.18em;
    color: #7dd3fc;
}

h1,
h2,
h3 {
    margin: 0;
    font-family: Manrope, Inter, sans-serif;
}

.brand-copy,
.helper-text,
.conversation-preview,
.timeline-item p,
.empty-panel p {
    color: var(--muted);
}

.login-form,
.stack-form {
    display: grid;
    gap: 14px;
}

.login-form label,
.stack-form label {
    display: grid;
    gap: 8px;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--line);
    background: rgba(7, 17, 26, 0.88);
    color: var(--text);
    border-radius: 16px;
    padding: 13px 14px;
    outline: none;
}

textarea {
    resize: vertical;
    min-height: 96px;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

.primary-btn,
.ghost-btn,
.switch-chip,
.stage-chip,
.template-pill,
.bubble-action,
.reaction-btn {
    border: 0;
    cursor: pointer;
    transition: transform 160ms ease, opacity 160ms ease, background 160ms ease;
}

.primary-btn:hover,
.ghost-btn:hover,
.switch-chip:hover,
.stage-chip:hover,
.template-pill:hover,
.bubble-action:hover,
.reaction-btn:hover {
    transform: translateY(-1px);
}

.primary-btn {
    background: linear-gradient(135deg, var(--blue), var(--blue-2));
    color: #fff;
    padding: 12px 18px;
    border-radius: 16px;
    font-weight: 700;
}

.ghost-btn {
    background: rgba(13, 23, 33, 0.75);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 11px 14px;
    border-radius: 14px;
}

.ghost-btn.small {
    padding: 8px 10px;
    font-size: 13px;
}

.ghost-btn.danger {
    color: #fecaca;
}

.full-width {
    width: 100%;
}

.flash {
    padding: 14px 16px;
    border-radius: 18px;
    margin-bottom: 18px;
    border: 1px solid transparent;
}

.flash.banner {
    margin: 14px 18px 0;
}

.flash-success {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.28);
}

.flash-error {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.26);
}

.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
    background: rgba(5, 12, 18, 0.72);
    backdrop-filter: blur(18px);
    position: sticky;
    top: 0;
    z-index: 4;
}

.topbar-actions,
.header-actions,
.modal-actions,
.composer-actions,
.conversation-tags,
.detail-grid,
.form-row,
.sidebar-switches,
.composer-toolbar,
.reactions-row,
.reaction-picker {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.workspace {
    display: grid;
    grid-template-columns: 340px minmax(0, 1fr) 320px;
    gap: 18px;
    padding: 18px;
    flex: 1;
    min-height: 0;
}

.sidebar,
.chat-panel,
.detail-rail {
    min-height: 0;
}

.sidebar,
.detail-rail,
.chat-panel {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.sidebar-toolbar,
.sidebar-switches,
.chat-header,
.overview-grid,
.composer,
.card {
    min-width: 0;
}

.sidebar-toolbar,
.sidebar {
    background: rgba(10, 20, 30, 0.75);
}

.sidebar {
    border: 1px solid var(--line);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.sidebar-toolbar {
    display: grid;
    gap: 10px;
    padding: 16px;
    border-bottom: 1px solid var(--line);
}

.sidebar-switches {
    padding: 14px 16px 0;
}

.switch-chip {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(12, 23, 34, 0.84);
    border: 1px solid var(--line);
    font-size: 14px;
}

.switch-chip.active {
    background: rgba(29, 155, 240, 0.18);
    border-color: rgba(59, 130, 246, 0.42);
}

.conversation-list {
    overflow: auto;
    padding: 10px;
    display: grid;
    gap: 10px;
}

.conversation-card {
    display: grid;
    grid-template-columns: 50px minmax(0, 1fr);
    gap: 12px;
    padding: 14px;
    border-radius: 22px;
    background: rgba(15, 27, 39, 0.86);
    border: 1px solid transparent;
}

.conversation-card.active {
    border-color: rgba(59, 130, 246, 0.34);
    box-shadow: inset 0 0 0 1px rgba(29, 155, 240, 0.22);
    background: linear-gradient(180deg, rgba(17, 33, 49, 0.96), rgba(11, 21, 31, 0.96));
}

.avatar {
    width: 50px;
    height: 50px;
    border-radius: 18px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(29, 155, 240, 0.8), rgba(15, 118, 110, 0.62));
    font-weight: 800;
}

.conversation-line {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 14px;
}

.conversation-line.muted {
    color: var(--muted);
    font-size: 12px;
}

.conversation-copy {
    min-width: 0;
}

.conversation-preview {
    margin: 8px 0 10px;
    font-size: 13px;
    line-height: 1.45;
}

.status-pill,
.meta-pill,
.unread-pill,
.reaction-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 700;
}

.status-pill {
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid var(--pill-color);
    color: #fff;
}

.meta-pill {
    background: rgba(140, 160, 181, 0.12);
    color: var(--muted);
}

.unread-pill {
    background: var(--blue);
    color: #fff;
    min-width: 22px;
}

.chat-panel {
    min-width: 0;
}

.chat-header,
.card,
.composer {
    border: 1px solid var(--line);
    border-radius: 28px;
    background: rgba(10, 20, 30, 0.76);
    padding: 18px;
    box-shadow: var(--shadow);
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header p {
    margin: 6px 0 0;
    color: var(--muted);
}

.overview-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 18px;
}

.card-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.stage-strip {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.stage-chip {
    padding: 10px 14px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.9);
    border: 1px solid rgba(148, 163, 184, 0.16);
    color: #dbeafe;
}

.stage-chip.active {
    border-color: var(--stage-color);
    box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08);
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.detail-grid div {
    background: rgba(11, 22, 32, 0.72);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px;
}

.detail-grid dt {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.messages-scroll {
    flex: 1;
    min-height: 260px;
    overflow: auto;
    display: grid;
    gap: 12px;
    padding: 24px 12px 8px;
    border-radius: 28px;
    border: 1px solid var(--line);
    background:
        radial-gradient(circle at top, rgba(29, 155, 240, 0.1), transparent 30%),
        linear-gradient(180deg, rgba(12, 24, 35, 0.92), rgba(8, 16, 25, 0.94));
    box-shadow: var(--shadow);
}

.message-row {
    display: flex;
}

.message-row.inbound {
    justify-content: flex-start;
}

.message-row.outbound {
    justify-content: flex-end;
}

.message-bubble {
    max-width: min(76%, 680px);
    background: linear-gradient(180deg, rgba(21, 38, 55, 0.98), rgba(14, 29, 43, 0.98));
    border: 1px solid rgba(96, 165, 250, 0.12);
    padding: 14px 16px 12px;
    border-radius: 24px 24px 24px 10px;
    position: relative;
}

.message-row.outbound .message-bubble {
    background: linear-gradient(180deg, rgba(15, 118, 110, 0.72), rgba(14, 80, 110, 0.82));
    border-radius: 24px 24px 10px 24px;
}

.message-bubble.deleted {
    opacity: 0.75;
    font-style: italic;
}

.message-bubble p {
    margin: 0;
    line-height: 1.55;
    white-space: normal;
    word-break: break-word;
}

.message-tools {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.bubble-action {
    background: rgba(7, 17, 26, 0.28);
    color: #dbeafe;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 11px;
}

.reply-pill,
.media-link {
    display: inline-flex;
    margin-bottom: 10px;
}

.reply-pill {
    padding: 7px 10px;
    border-radius: 14px;
    background: rgba(7, 17, 26, 0.22);
    color: #cbd5e1;
    font-size: 12px;
}

.media-link {
    margin-top: 10px;
    color: #bae6fd;
}

.reactions-row,
.reaction-picker {
    margin-top: 10px;
}

.reaction-pill {
    background: rgba(255, 255, 255, 0.14);
}

.reaction-btn {
    background: rgba(7, 17, 26, 0.22);
    color: #fff;
    border-radius: 12px;
    padding: 6px 8px;
}

.message-bubble footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
    font-size: 11px;
    color: rgba(231, 238, 247, 0.78);
}

.composer {
    display: grid;
    gap: 14px;
}

.template-pill {
    padding: 9px 13px;
    border-radius: 999px;
    background: rgba(29, 155, 240, 0.14);
    color: #dbeafe;
}

.composer-form {
    display: grid;
    gap: 14px;
}

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

.optional-fields {
    align-items: stretch;
}

.detail-rail .card {
    overflow: hidden;
}

.timeline {
    display: grid;
    gap: 12px;
}

.timeline-item {
    background: rgba(9, 18, 27, 0.75);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px;
}

.timeline-item span {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.timeline-item p {
    margin: 10px 0 0;
    line-height: 1.5;
    font-size: 13px;
}

.empty-panel {
    min-height: 320px;
    display: grid;
    place-items: center;
    text-align: center;
    border: 1px dashed var(--line-strong);
    border-radius: 28px;
    padding: 24px;
    background: rgba(10, 20, 30, 0.56);
}

.empty-panel.compact {
    min-height: 180px;
}

.modal {
    border: 0;
    padding: 0;
    background: rgba(0, 0, 0, 0.58);
}

.modal::backdrop {
    background: rgba(0, 0, 0, 0.58);
}

.modal-card {
    width: min(900px, calc(100vw - 32px));
    padding: 22px;
    margin: auto;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.template-card {
    background: rgba(9, 18, 27, 0.75);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 14px;
    display: grid;
    gap: 8px;
}

.template-card span,
.template-card p {
    color: var(--muted);
    font-size: 13px;
}

.template-actions {
    display: flex;
    gap: 8px;
}

.template-editor {
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

@media (max-width: 1240px) {
    .workspace {
        grid-template-columns: 320px minmax(0, 1fr);
    }

    .detail-rail {
        grid-column: 1 / -1;
        flex-direction: row;
    }

    .detail-rail .card {
        flex: 1;
    }
}

@media (max-width: 920px) {
    .workspace,
    .overview-grid,
    .detail-grid,
    .form-row,
    .detail-rail {
        grid-template-columns: 1fr;
        display: grid;
    }

    .workspace {
        padding: 14px;
    }

    .sidebar,
    .chat-panel,
    .detail-rail {
        width: 100%;
    }

    .topbar,
    .chat-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .message-bubble {
        max-width: 100%;
    }
}

/* Overlay fix: keep dashboard columns and controls inside their grid cells. */
.workspace > .sidebar,
.workspace > .chat-panel,
.workspace > .detail-rail,
.overview-grid > .card,
.chat-header > *,
.detail-rail > .card {
    min-width: 0;
    max-width: 100%;
}

.header-actions,
.topbar-actions {
    min-width: 0;
    justify-content: flex-end;
}

.header-actions .ghost-btn,
.topbar-actions .ghost-btn {
    flex: 0 1 auto;
    white-space: nowrap;
}

.card-heading > * {
    min-width: 0;
}

.detail-grid > div {
    min-width: 0;
    overflow-wrap: anywhere;
}

@media (max-width: 1320px) and (min-width: 921px) {
    .workspace {
        grid-template-columns: 300px minmax(0, 1fr) 280px;
    }

    .overview-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }

    .chat-header {
        align-items: flex-start;
        gap: 12px;
    }

    .header-actions {
        flex-shrink: 1;
    }
}

/* Detail-card text fix: preserve normal words and remove the browser's
   default <dd> indentation, which was squeezing values into narrow columns. */
.detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.detail-grid > div {
    min-width: 0;
}

.detail-grid dt,
.detail-grid dd {
    min-width: 0;
    max-width: 100%;
}

.detail-grid dd {
    margin: 0;
    white-space: normal;
    overflow-wrap: normal;
    word-break: normal;
}

@media (max-width: 1050px) and (min-width: 921px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
}
