:root {
    --bg: #f3f5f9;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #101828;
    --muted: #667085;
    --border: #e4e7ec;
    --primary: #1d4ed8;
    --primary-hover: #1e40af;
    --sidebar-bg: #111827;
    --sidebar-border: #1f2937;
    --sidebar-text: #d0d7e2;
    --sidebar-active: #243145;
    --success: #067647;
    --danger: #b42318;
    --radius-lg: 12px;
    --radius-md: 10px;
    --radius-sm: 8px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.04);
    --shadow-md: 0 8px 28px rgba(16, 24, 40, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
}

body {
    font-family: "Sora", "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
    background: var(--bg);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1,
h2,
h3,
h4 {
    margin-top: 0;
    color: var(--text);
}

.small {
    font-size: 0.84rem;
    color: var(--muted);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
}

.app-sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    border-right: 1px solid var(--sidebar-border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.app-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #f5f8fd;
    text-decoration: none;
    margin-bottom: 6px;
}

.app-brand:hover {
    text-decoration: none;
}

.app-brand-mark {
    width: 30px;
    height: 30px;
    border-radius: var(--radius-sm);
    display: grid;
    place-items: center;
    background: #1f2937;
    border: 1px solid #344054;
    font-size: 0.9rem;
    font-weight: 700;
    color: #ffffff;
}

.app-brand-text {
    font-size: 0.95rem;
    font-weight: 700;
    letter-spacing: 0.01em;
}

.app-nav {
    display: grid;
    gap: 4px;
    min-height: 0;
    overflow: auto;
}

.app-nav-link {
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    padding: 9px 10px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background-color 120ms ease, color 120ms ease;
}

.app-nav-link:hover {
    text-decoration: none;
    color: #ffffff;
    background: #1f2937;
}

.app-nav-link.is-active {
    color: #ffffff;
    background: var(--sidebar-active);
}

.app-sidebar-footer {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #243042;
    background: var(--sidebar-bg);
}

.app-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.app-topbar {
    position: sticky;
    top: 0;
    z-index: 5;
    background: rgba(243, 245, 249, 0.98);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
}

.topbar-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}

.topbar-user {
    margin-top: 2px;
    font-weight: 600;
    font-size: 0.92rem;
}

.app-content {
    padding: 18px;
}

.inbox-page .app-main {
    height: 100vh;
    overflow: hidden;
}

.inbox-page .app-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding: 12px;
}

.public-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.auth-layout {
    width: min(940px, 100%);
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(360px, 420px);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

.auth-hero {
    padding: 34px;
    background: var(--surface-muted);
    border-right: 1px solid var(--border);
    color: var(--text);
}

.auth-hero h1 {
    font-size: 1.6rem;
    line-height: 1.3;
    margin-bottom: 12px;
}

.auth-panel {
    padding: 30px;
}

.auth-panel h2 {
    margin-bottom: 4px;
}

.flash-list {
    list-style: none;
    padding: 0;
    margin: 0 0 14px;
    display: grid;
    gap: 8px;
}

.flash-list li {
    border-radius: var(--radius-sm);
    padding: 9px 11px;
    font-size: 0.88rem;
    border: 1px solid transparent;
}

.flash-success {
    background: #ecfdf3;
    color: #05603a;
    border-color: #abefc6;
}

.flash-error {
    background: #fef3f2;
    color: #912018;
    border-color: #fecdca;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.page-header h1 {
    margin: 0;
    font-size: 1.35rem;
    line-height: 1.25;
}

.page-header p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.88rem;
}

.page-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.page-actions form {
    margin: 0;
}

.panel,
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 14px;
    margin-bottom: 12px;
}

.panel-title {
    margin: 0 0 10px;
    font-size: 1rem;
}

.grid {
    display: grid;
    gap: 12px;
}

.grid-2 {
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 10px;
}

.kpi {
    padding: 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: #ffffff;
}

.kpi-label {
    font-size: 0.74rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    font-weight: 600;
}

.kpi-value {
    margin-top: 6px;
    font-size: 1.2rem;
    font-weight: 700;
}

.table-wrap {
    overflow: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.error-summary-cell {
    display: grid;
    gap: 4px;
}

.error-summary-line {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 10px 11px;
    border-bottom: 1px solid #eef2f6;
    text-align: left;
    vertical-align: top;
    font-size: 0.88rem;
}

th {
    background: #f9fafb;
    color: #475467;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-weight: 600;
}

tr:last-child td {
    border-bottom: 0;
}

form p {
    margin: 0 0 11px;
}

label {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
    margin-bottom: 5px;
}

input,
select,
textarea,
button {
    width: 100%;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: 9px 11px;
    font-size: 0.9rem;
    font-family: inherit;
}

textarea {
    min-height: 92px;
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    outline: 2px solid rgba(29, 78, 216, 0.15);
    border-color: #93b4ff;
}

button,
.button-link {
    border: 1px solid transparent;
    cursor: pointer;
    font-weight: 600;
    background: var(--primary);
    color: #fff;
}

button:hover,
.button-link:hover {
    background: var(--primary-hover);
    text-decoration: none;
}

.button-link {
    display: inline-flex;
    width: auto;
    align-items: center;
    justify-content: center;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
}

.button-secondary {
    background: #344054;
}

.button-secondary:hover {
    background: #1d2939;
}

.ghost-button {
    border: 1px solid #344054;
    background: transparent;
    color: #d0d7e2;
    border-radius: var(--radius-sm);
    padding: 8px 11px;
    font-weight: 600;
}

.ghost-button:hover {
    background: #1f2937;
}

.inline-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.inline-form {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
}

.inline-form button {
    width: auto;
    min-width: 100px;
}

.status-pill,
.chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 0.76rem;
    font-weight: 600;
    background: #eef4ff;
    color: #1e3a8a;
}

.empty-state {
    border: 1px dashed #d0d5dd;
    border-radius: var(--radius-md);
    background: var(--surface-muted);
    color: var(--muted);
    text-align: center;
    padding: 22px;
}

.pre-block {
    margin: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #f8fafc;
    padding: 11px;
    white-space: pre-wrap;
    font-size: 0.84rem;
    overflow: auto;
}

.messenger {
    display: grid;
    grid-template-columns: minmax(280px, 320px) minmax(0, 1fr) minmax(280px, 320px);
    gap: 12px;
    min-height: 0;
    height: 100%;
}

.inbox-page .messenger {
    flex: 1;
    min-height: 0;
    height: auto;
}

.messenger-list,
.thread-panel,
.details-panel {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.messenger-list {
    padding: 12px;
    gap: 10px;
}

.messenger-list-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.messenger-list-header h2 {
    margin: 0;
    font-size: 1.08rem;
}

.messenger-filter {
    display: grid;
    gap: 8px;
}

.conversation-list {
    margin-top: 2px;
    display: grid;
    gap: 8px;
    overflow: auto;
    padding-right: 2px;
}

.conversation-card {
    border: 1px solid var(--border);
    background: #fff;
    border-radius: var(--radius-md);
    padding: 9px;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
    transition: border-color 120ms ease;
}

.conversation-card:hover {
    text-decoration: none;
    border-color: #b8c3d3;
}

.conversation-card.is-active {
    border-color: #94a3b8;
    background: #f8fafc;
}

.conversation-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #e5e7eb;
    color: #344054;
    font-weight: 700;
    font-size: 0.82rem;
}

.conversation-main {
    min-width: 0;
}

.conversation-top,
.conversation-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.conversation-title {
    margin: 0;
    font-size: 0.89rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-preview {
    margin: 4px 0;
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    min-width: 20px;
    height: 20px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    padding: 0 6px;
}

.thread-panel {
    padding: 0;
    overflow: hidden;
}

.thread-header {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 10px;
    background: #ffffff;
}

.thread-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.thread-header-actions form {
    margin: 0;
}

.thread-title {
    margin: 0;
    font-size: 0.98rem;
}

.thread-subtitle {
    margin-top: 3px;
}

.thread-messages {
    flex: 1;
    overflow: auto;
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: #f9fafb;
}

.message-row {
    display: flex;
}

.message-row.inbound {
    justify-content: flex-start;
}

.message-row.outbound {
    justify-content: flex-end;
}

.message-row.system {
    justify-content: center;
}

.message-bubble {
    max-width: min(64%, 540px);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 7px 9px;
    background: #fff;
}

.message-row.outbound .message-bubble {
    background: #eef4ff;
    border-color: #c7d7fe;
}

.message-row.system .message-bubble {
    background: #f2f4f7;
    border-color: #e4e7ec;
}

.message-text {
    white-space: pre-line;
    word-break: break-word;
    font-size: 0.87rem;
    line-height: 1.35;
}

.message-meta {
    margin-top: 6px;
    font-size: 0.74rem;
    color: var(--muted);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.message-error {
    margin-top: 4px;
    color: var(--danger);
    font-size: 0.78rem;
}

.message-error-card {
    margin-top: 8px;
    border: 1px solid #fecdca;
    border-radius: 10px;
    background: #fef3f2;
    padding: 8px 9px;
}

.message-error-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 4px;
}

.message-error-title {
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: #912018;
}

.error-code-chip {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 3px 8px;
    font-size: 0.72rem;
    font-weight: 700;
    background: #fff;
    color: #912018;
    border: 1px solid #fda29b;
    white-space: nowrap;
}

.error-help-text {
    margin-top: 4px;
    color: #7a271a;
    font-size: 0.76rem;
    line-height: 1.35;
}

.message-error-link {
    display: inline-flex;
    margin-top: 6px;
    font-size: 0.78rem;
    font-weight: 600;
}

.message-error-details {
    margin-top: 6px;
}

.message-error-details-list {
    margin-top: 6px;
    display: grid;
    gap: 8px;
}

.message-error-detail-item {
    border-top: 1px solid #fecdca;
    padding-top: 6px;
}

.message-template-header {
    font-size: 0.82rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.message-template-footer {
    margin-top: 6px;
    font-size: 0.76rem;
    color: var(--muted);
    line-height: 1.3;
}

.message-actions-list {
    margin-top: 8px;
    display: grid;
    gap: 6px;
}

.message-action-chip {
    border: 1px solid #d0d5dd;
    border-radius: 8px;
    padding: 6px 8px;
    font-size: 0.82rem;
    line-height: 1.3;
    background: #ffffff;
}

.message-list-title {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--muted);
    margin-top: 2px;
}

.message-media-card {
    border: 1px solid #d0d5dd;
    border-radius: 10px;
    padding: 8px 10px;
    background: #ffffff;
}

.message-row.outbound .message-media-card {
    background: #f8fbff;
    border-color: #bfd2ff;
}

.message-media-title {
    font-size: 0.76rem;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: #475467;
}

.message-media-file {
    margin-top: 5px;
    font-size: 0.84rem;
    line-height: 1.35;
    word-break: break-word;
}

.message-media-preview-link {
    display: block;
    margin-top: 8px;
}

.message-media-preview-link:hover {
    text-decoration: none;
}

.message-media-preview,
.message-video-player {
    display: block;
    width: min(100%, 280px);
    max-height: 280px;
    border-radius: 8px;
    background: #0f172a;
    object-fit: cover;
}

.message-audio-player {
    display: block;
    width: min(100%, 280px);
    margin-top: 8px;
}

.message-media-actions {
    margin-top: 8px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.message-media-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: auto;
    min-width: 74px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid #d0d5dd;
    background: #fff;
    color: #344054;
    font-size: 0.8rem;
    font-weight: 600;
}

.message-media-link:hover {
    text-decoration: none;
    background: #f8fafc;
}

.thread-composer {
    border-top: 1px solid var(--border);
    padding: 8px 10px;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
    align-items: end;
    background: #fff;
}

.thread-composer textarea {
    min-height: 36px;
    max-height: 180px;
    overflow-y: hidden;
    resize: none;
}

.thread-composer button {
    width: auto;
    min-width: 96px;
}

.composer-actions {
    display: flex;
    gap: 8px;
    align-items: end;
    justify-content: flex-end;
}

.composer-actions button {
    width: auto;
    min-width: 74px;
}

.composer-actions .icon-button {
    min-width: 40px;
    width: 40px;
    height: 40px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.composer-actions .icon-button svg {
    width: 18px;
    height: 18px;
}

.composer-actions .is-recording {
    background: #b42318;
}

.composer-actions .is-recording:hover {
    background: #912018;
}

.details-panel {
    padding: 12px;
    gap: 12px;
    overflow: auto;
}

.details-panel h3,
.details-panel h4 {
    margin: 0 0 7px;
}

.details-list {
    display: grid;
    gap: 6px;
    font-size: 0.84rem;
}

.details-list div {
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.note-list {
    display: grid;
    gap: 8px;
}

.note-item {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px;
    background: #fff;
}

.note-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.note-delete-form {
    margin: 0;
}

.note-delete-btn {
    width: auto;
    min-width: 68px;
    padding: 6px 10px;
    font-size: 0.78rem;
}

.advanced-stack {
    display: grid;
    gap: 10px;
}

.advanced-tool-buttons {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 8px;
}

.interactive-item-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    margin-bottom: 8px;
    align-items: start;
}

#rowsContainer .interactive-item-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
}

.interactive-item-row button {
    width: auto;
}

.app-modal {
    width: min(760px, 92vw);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0;
    background: #fff;
    color: var(--text);
}

.app-modal::backdrop {
    background: rgba(16, 24, 40, 0.45);
}

.app-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}

.app-modal-header h4 {
    margin: 0;
}

.app-modal-close {
    width: auto;
    min-width: 34px;
    padding: 6px 9px;
    line-height: 1;
    font-size: 1rem;
}

.app-modal-body {
    padding: 12px;
}

.app-modal-body-bottom-space {
    padding-bottom: 20px;
}

.app-modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.interactive-modal-actions {
    margin-top: 14px;
}

.app-modal-actions button {
    width: auto;
}

details summary {
    cursor: pointer;
    color: #344054;
}

.panel-tight {
    margin-bottom: 0;
}

.panel-heading-tight {
    margin: 0 0 8px;
}

.empty-state-spaced {
    margin: 14px;
}

.mt-8 {
    margin-top: 8px;
}

.mt-10 {
    margin-top: 10px;
}

@media (max-width: 1240px) {
    .messenger {
        grid-template-columns: minmax(270px, 310px) minmax(0, 1fr);
    }

    .details-panel {
        grid-column: 1 / -1;
        min-height: auto;
    }
}

@media (max-width: 960px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .app-sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--sidebar-border);
    }

    .app-content {
        padding: 14px;
    }

    .inbox-page .app-main,
    .inbox-page .app-content {
        height: auto;
        overflow: visible;
    }

    .auth-layout {
        grid-template-columns: 1fr;
    }

    .auth-hero {
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding: 24px;
    }

    .auth-panel {
        padding: 22px;
    }

    .messenger {
        grid-template-columns: 1fr;
        min-height: auto;
        height: auto;
    }

    .messenger-list {
        max-height: 50vh;
    }

    .thread-panel {
        min-height: 62vh;
    }

    .thread-composer {
        grid-template-columns: 1fr;
    }

    .composer-actions {
        justify-content: stretch;
    }

    .composer-actions button {
        flex: 1;
    }

    .advanced-tool-buttons {
        grid-template-columns: 1fr;
    }

    .inline-form {
        grid-template-columns: 1fr;
    }

    .inline-form button {
        width: 100%;
    }

    .page-header {
        flex-direction: column;
        align-items: stretch;
    }
}
