:root {
    --bg: #e7e3dc;
    --panel: #fff;
    --ink: #17212b;
    --muted: #667781;
    --line: #e9edef;
    --green: #00a884;
    --green-deep: #008069;
    --bubble-out: #d9fdd3;
    --bubble-in: #fff;
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--ink);
}

* { box-sizing: border-box; }
html, body {
    width: 100%;
    height: 100%;
    min-height: 100%;
    overflow: hidden;
}
body {
    margin: 0;
    background:
        linear-gradient(var(--green-deep) 0 128px, var(--bg) 128px 100%);
    font-size: 14px;
}
button, input { font: inherit; }
a { color: inherit; }
.shell {
    width: min(1500px, calc(100% - 38px));
    height: calc(100vh - 38px);
    min-height: 620px;
    margin: 19px auto;
    position: relative;
}
.app {
    position: relative;
    display: grid;
    grid-template-columns: 390px minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: var(--panel);
    border-radius: 4px;
    box-shadow: 0 8px 32px rgba(11, 20, 26, .18);
}
.flash {
    position: absolute;
    z-index: 10;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    max-width: min(680px, 90%);
    padding: 12px 18px;
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .16);
}
.flash-success { background: #e7f8f3; color: #056450; }
.flash-error { background: #fff0f0; color: #9f2020; }
.sidebar {
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-right: 1px solid var(--line);
    background: #fff;
}
.sidebar-header, .chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 70px;
    padding: 12px 18px;
    background: #f0f2f5;
}
.sidebar-header h1, .chat-header h2 {
    margin: 1px 0 0;
    font-size: 19px;
    line-height: 1.2;
}
.eyebrow {
    color: var(--green-deep);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
}
.icon-button {
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #54656f;
    font-size: 23px;
    cursor: pointer;
}
.icon-button:hover { background: #e3e6e8; }
.icon-link { display: grid; place-items: center; text-decoration: none; }
.sidebar-actions { display: flex; align-items: center; gap: 3px; }
.sidebar-actions form { margin: 0; }
.search {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 8px 12px;
    padding: 0 14px;
    height: 38px;
    border-radius: 9px;
    background: #f0f2f5;
    color: var(--muted);
}
.search input {
    width: 100%;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--ink);
}
.conversation-list {
    flex: 1 1 0;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: scroll;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
}
.conversation-list-sentinel {
    display: block;
    height: 1px;
}
.conversation-list.loading-more .conversation-list-sentinel {
    height: 42px;
    background: linear-gradient(90deg, transparent, #f0f2f5, transparent);
    animation: conversation-loading 1s ease-in-out infinite alternate;
}
.conversation-list-sentinel.load-error { height: 8px; background: #f15c6d; }
@keyframes conversation-loading { to { opacity: .35; } }
.conversation-item {
    display: flex;
    gap: 12px;
    min-width: 0;
    padding: 11px 13px;
    text-decoration: none;
}
.conversation-item:hover, .conversation-item.active { background: #f0f2f5; }
.avatar {
    position: relative;
    overflow: hidden;
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    font-weight: 700;
    background: linear-gradient(145deg, #83c4b8, #3b887d);
}
.avatar-fallback { line-height: 1; }
.avatar img {
    position: absolute;
    z-index: 1;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    border-radius: inherit;
    object-fit: cover;
}
.avatar.group { background: linear-gradient(145deg, #8da6c8, #526d94); }
.conversation-copy { min-width: 0; flex: 1; padding-top: 3px; }
.conversation-line {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    min-width: 0;
}
.conversation-line strong, .conversation-line span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.conversation-line strong { font-size: 16px; font-weight: 500; }
.conversation-line time { flex: 0 0 auto; color: var(--muted); font-size: 11px; }
.conversation-line.preview { margin-top: 6px; color: var(--muted); }
.conversation-line.preview small {
    flex: 0 0 auto;
    min-width: 20px;
    padding: 2px 6px;
    border-radius: 10px;
    background: #e9edef;
    text-align: center;
}
.sidebar-empty, .chat-empty {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: var(--muted);
    text-align: center;
    padding: 42px 28px;
}
.sidebar-empty strong, .chat-empty strong { color: var(--ink); }
.pager { margin-top: auto; padding: 8px; text-align: center; }
.pager ul { display: flex; justify-content: center; gap: 4px; padding: 0; margin: 0; list-style: none; }
.pager a { display: block; padding: 5px 8px; border-radius: 4px; text-decoration: none; }
.pager .active a { color: #fff; background: var(--green-deep); }
.welcome-panel {
    display: grid;
    place-content: center;
    justify-items: center;
    padding: 44px;
    border-bottom: 6px solid var(--green);
    background: #f8fafb;
    text-align: center;
}
.welcome-mark {
    width: 116px;
    height: 116px;
    display: grid;
    place-items: center;
    margin-bottom: 20px;
    border-radius: 50%;
    color: var(--green-deep);
    background: #e2f4ef;
    font-size: 74px;
}
.welcome-panel h2 { margin: 0 0 9px; font-size: 30px; font-weight: 400; }
.welcome-panel p { margin: 0; color: var(--muted); font-size: 15px; }
.sync-note {
    max-width: 520px;
    margin-top: 34px;
    padding: 16px 18px;
    border: 1px solid #d9e5e2;
    border-radius: 10px;
    color: var(--muted);
    background: #fff;
    line-height: 1.5;
}
.sync-note strong { display: block; margin-bottom: 3px; color: var(--ink); }
.chat {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #efeae2;
}
.conversation-stage {
    position: relative;
    isolation: isolate;
}
.conversation-stage > :not(.external-loading-overlay) {
    transition: filter .2s ease, opacity .2s ease, transform .2s ease;
}
.conversation-stage.is-external-loading > :not(.external-loading-overlay) {
    filter: blur(5px);
    opacity: .62;
    transform: scale(.995);
    pointer-events: none;
    user-select: none;
}
.external-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 20;
    display: grid;
    place-items: center;
    padding: 24px;
    background: rgba(239, 234, 226, .58);
    animation: external-loading-fade .2s ease both;
}
.external-loading-card {
    width: min(390px, 100%);
    display: grid;
    justify-items: center;
    gap: 8px;
    padding: 26px 28px;
    border: 1px solid rgba(7, 94, 84, .14);
    border-radius: 16px;
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 18px 50px rgba(11, 20, 26, .16);
    color: var(--ink);
    text-align: center;
}
.external-loading-card strong { margin-top: 4px; font-size: 18px; }
.external-loading-card > span:not(.external-loading-spinner) {
    color: var(--muted);
    line-height: 1.45;
}
.external-loading-card small {
    max-width: 100%;
    margin-top: 4px;
    overflow: hidden;
    color: var(--green-deep);
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.external-loading-spinner {
    width: 38px;
    height: 38px;
    border: 3px solid #d7e8e4;
    border-top-color: var(--green);
    border-radius: 50%;
    animation: external-loading-spin .8s linear infinite;
}
@keyframes external-loading-spin { to { transform: rotate(360deg); } }
@keyframes external-loading-fade { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
    .conversation-stage > :not(.external-loading-overlay) { transition: none; }
    .external-loading-overlay { animation: none; }
    .external-loading-spinner { animation-duration: 1.6s; }
}
.chat-header { flex: 0 0 auto; border-bottom: 1px solid #e0e3e5; }
.chat-header > .chat-header-copy { flex: 1; min-width: 0; }
.chat-header-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}
.chat-header-actions form { margin: 0; }
.chat-header .header-avatar {
    display: grid;
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    margin: 0;
    color: #fff;
    font-size: 14px;
}
.chat-header h2 { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chat-header span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }
.chat-header .header-avatar .avatar-fallback {
    margin: 0;
    color: #fff;
    font-size: 14px;
}
.secondary-button {
    padding: 9px 13px;
    border: 1px solid #b9c6c3;
    border-radius: 8px;
    color: #075e54;
    background: #fff;
    cursor: pointer;
}
.secondary-button:hover { background: #f5fbf9; }
.history-sync-status {
    flex: 0 0 auto;
    padding: 7px 10px;
    border-radius: 999px;
    color: var(--muted);
    background: rgba(255, 255, 255, .72);
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.history-sync-status.working { color: #8a6200; background: #fff5d6; }
.history-sync-status.complete { color: #056450; background: #e7f8f3; }
.mobile-back { display: none; text-decoration: none; font-size: 32px; }
.messages {
    flex: 1 1 0;
    min-height: 0;
    height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-gutter: stable;
    padding: 20px max(30px, 8%);
    background-color: #efeae2;
    background-image:
        radial-gradient(rgba(75, 85, 82, .055) 1px, transparent 1px),
        radial-gradient(rgba(75, 85, 82, .035) 1px, transparent 1px);
    background-position: 0 0, 11px 11px;
    background-size: 22px 22px;
}
.conversation-list,
.messages,
.webhook-page,
.pairing-page {
    scrollbar-color: #b8c0c4 transparent;
    scrollbar-width: thin;
}
.conversation-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.webhook-page::-webkit-scrollbar,
.pairing-page::-webkit-scrollbar {
    width: 10px;
}
.conversation-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.webhook-page::-webkit-scrollbar-thumb,
.pairing-page::-webkit-scrollbar-thumb {
    border: 2px solid transparent;
    border-radius: 8px;
    background: #b8c0c4;
    background-clip: padding-box;
}
.conversation-list::-webkit-scrollbar-track,
.messages::-webkit-scrollbar-track,
.webhook-page::-webkit-scrollbar-track,
.pairing-page::-webkit-scrollbar-track {
    background: transparent;
}
.bubble {
    position: relative;
    width: fit-content;
    max-width: min(650px, 78%);
    margin: 4px 0 12px;
    padding: 8px 10px 7px;
    border-radius: 8px;
    box-shadow: 0 1px 1px rgba(11, 20, 26, .12);
    line-height: 1.38;
}
.bubble.in { margin-right: auto; background: var(--bubble-in); border-top-left-radius: 2px; }
.bubble.out { margin-left: auto; background: var(--bubble-out); border-top-right-radius: 2px; }
.bubble.edited {
    min-width: min(340px, 76vw);
    border: 1px solid rgba(0, 128, 105, .34);
    box-shadow: 0 2px 8px rgba(0, 92, 75, .13);
}
.bubble time {
    display: block;
    clear: both;
    margin: 8px 0 0;
    color: var(--muted);
    font-size: 10px;
    line-height: 1.2;
    text-align: right;
}
.sender { display: block; margin-bottom: 4px; color: #7b5ea7; font-size: 12px; }
.sender-phone { font-weight: 500; white-space: nowrap; }
.message-type { display: block; color: var(--green-deep); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.message-body { overflow-wrap: anywhere; }
.message-body.muted { color: var(--muted); font-style: italic; }
.message-edit-history {
    margin-top: 4px;
    overflow: hidden;
    border: 1px solid rgba(0, 92, 75, .14);
    border-radius: 7px;
}
.message-edit-version { padding: 9px 10px; }
.message-edit-version.original {
    border-bottom: 1px solid rgba(0, 92, 75, .13);
    background: rgba(255, 255, 255, .58);
}
.message-edit-version.intermediate {
    border-bottom: 1px solid rgba(0, 92, 75, .13);
    background: rgba(255, 255, 255, .32);
}
.message-edit-version.current { background: rgba(0, 168, 132, .09); }
.message-edit-header {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 5px;
}
.message-edit-header strong {
    color: var(--green-deep);
    font-size: 11px;
    letter-spacing: .02em;
    text-transform: uppercase;
}
.bubble .message-edit-time {
    display: inline;
    flex: 0 0 auto;
    margin: 0;
    font-size: 10px;
    white-space: nowrap;
}
.message-edit-body { overflow-wrap: anywhere; }
.message-edit-body.muted { color: var(--muted); font-style: italic; }
.bubble.reaction { min-width: min(360px, 82%); }
.reaction-summary {
    display: flex;
    align-items: center;
    gap: 10px;
}
.reaction-symbol { font-size: 28px; line-height: 1; }
.reaction-meta { display: flex; flex-direction: column; gap: 2px; }
.reaction-meta strong { font-size: 13px; }
.bubble .reaction-meta time { display: block; margin: 0; font-size: 10px; }
.reaction-target {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-top: 9px;
    padding: 8px 10px;
    border-left: 3px solid var(--green);
    border-radius: 4px;
    background: rgba(255, 255, 255, .58);
    color: inherit;
    text-decoration: none;
}
.reaction-target[href]:hover { background: rgba(255, 255, 255, .82); }
.reaction-target strong { color: var(--green-deep); font-size: 11px; text-transform: uppercase; }
.reaction-target small { color: var(--muted); font-size: 10px; }
.reaction-target span { overflow-wrap: anywhere; }
.reaction-target.unavailable { border-left-color: var(--muted); }
.message-sticker {
    display: block;
    width: min(180px, 100%);
    max-height: 180px;
    margin: 4px 0;
    object-fit: contain;
}
.attachment {
    margin: 5px 0;
    padding: 9px;
    border-radius: 6px;
    background: rgba(255, 255, 255, .55);
}
.media-image-link {
    display: block;
    max-width: 420px;
    margin: 6px 0 3px;
    overflow: hidden;
    border-radius: 7px;
    line-height: 0;
}
.message-image {
    display: block;
    width: 100%;
    max-height: 520px;
    object-fit: contain;
    background: rgba(0, 0, 0, .06);
}
.message-audio {
    display: block;
    width: min(340px, 72vw);
    margin: 7px 0 3px;
}
.media-download-link {
    display: inline-flex;
    margin-top: 5px;
    color: var(--green-deep);
    font-size: 11px;
    font-weight: 700;
    text-decoration: none;
}
.media-download-link:hover { text-decoration: underline; }
.document-download {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: min(280px, 68vw);
    max-width: 420px;
    margin-top: 7px;
    padding: 10px;
    border: 1px solid rgba(0, 92, 75, .12);
    border-radius: 7px;
    color: var(--text);
    background: rgba(255, 255, 255, .58);
    text-decoration: none;
}
.document-download:hover { background: rgba(255, 255, 255, .82); }
.document-download-icon {
    display: grid;
    flex: 0 0 34px;
    width: 34px;
    height: 34px;
    place-items: center;
    border-radius: 50%;
    color: #fff;
    background: var(--green-deep);
    font-size: 19px;
    font-weight: 700;
}
.document-download span:last-child { min-width: 0; }
.document-download strong {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.document-download small {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 10px;
}
.media-unavailable {
    max-width: 360px;
    margin-top: 6px;
    color: var(--muted);
    font-size: 11px;
    font-style: italic;
}
.day-divider { display: flex; justify-content: center; margin: 16px 0 10px; }
.day-divider span, .history-link {
    padding: 7px 12px;
    border-radius: 7px;
    color: #54656f;
    background: #fff;
    box-shadow: 0 1px 1px rgba(11, 20, 26, .12);
    font-size: 11px;
}
.history-link { display: table; margin: 10px auto; text-decoration: none; }
.history-link.loading { cursor: wait; opacity: .72; pointer-events: none; }
.primary-button {
    display: inline-block;
    padding: 10px 14px;
    border-radius: 8px;
    color: #fff;
    background: var(--green-deep);
    text-decoration: none;
}
.webhook-page {
    height: 100%;
    overflow-y: auto;
    padding: 28px;
    border-radius: 4px;
    background: #f4f6f7;
}
.webhook-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 22px 24px;
    border-radius: 12px;
    background: #fff;
}
.webhook-header h1 { margin: 3px 0 6px; font-size: 28px; }
.webhook-header p { margin: 0; color: var(--muted); }
.webhook-actions { display: flex; gap: 8px; }
.webhook-actions .secondary-button { display: inline-block; text-decoration: none; }
.log-location {
    display: flex;
    gap: 10px;
    margin: 16px 0;
    padding: 12px 16px;
    border: 1px solid #dce3e5;
    border-radius: 9px;
    background: #fff;
}
.log-location code { color: var(--muted); overflow-wrap: anywhere; }
.event-list { display: grid; gap: 10px; }
.event-card {
    overflow: hidden;
    border: 1px solid #dce3e5;
    border-left: 4px solid #cc4545;
    border-radius: 9px;
    background: #fff;
}
.event-card.success { border-left-color: var(--green); }
.event-card summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 16px;
    cursor: pointer;
    list-style: none;
}
.event-card summary::-webkit-details-marker { display: none; }
.event-status { width: 8px; height: 8px; border-radius: 50%; background: #cc4545; }
.event-card.success .event-status { background: var(--green); }
.event-name { min-width: 110px; font-weight: 700; }
.event-outcome, .event-stats { color: var(--muted); font-size: 12px; }
.event-card summary time { margin-left: auto; color: var(--muted); font-size: 12px; }
.event-meta {
    display: flex;
    gap: 22px;
    padding: 10px 16px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 12px;
}
.event-card pre {
    max-height: 520px;
    overflow: auto;
    margin: 0;
    padding: 16px;
    border-top: 1px solid var(--line);
    color: #d8dee9;
    background: #202a33;
    font: 12px/1.55 Consolas, "Courier New", monospace;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.truncate-warning { margin: 0; padding: 10px 16px; color: #965c00; background: #fff4d8; }
.event-empty { display: grid; gap: 6px; padding: 60px; color: var(--muted); text-align: center; }
.event-empty strong { color: var(--ink); }
.pairing-page {
    min-height: 100%;
    display: grid;
    place-items: center;
    overflow-y: auto;
    padding: 28px;
    border-radius: 4px;
    background: #f0f2f5;
}
.pairing-card {
    width: min(560px, 100%);
    padding: 32px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 8px 30px rgba(11, 20, 26, .12);
    text-align: center;
}
.pairing-card h1 { margin: 5px 0 22px; font-size: 28px; }
.pairing-card > p { color: var(--muted); line-height: 1.55; }
.pairing-state {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 18px 0;
    padding: 14px 16px;
    border-radius: 9px;
    background: #fff6de;
    text-align: left;
}
.pairing-state.connected { background: #e5f7f1; }
.pairing-state strong, .pairing-state span { display: block; }
.pairing-state span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.pairing-dot { flex: 0 0 11px; width: 11px; height: 11px; border-radius: 50%; background: #e5a100; }
.pairing-state.connected .pairing-dot { background: var(--green); }
.qr-code {
    display: block;
    width: min(330px, 100%);
    margin: 18px auto;
    border: 10px solid #fff;
    border-radius: 8px;
    box-shadow: 0 2px 14px rgba(11, 20, 26, .14);
}
.pairing-steps {
    display: inline-block;
    margin: 10px auto;
    padding-left: 24px;
    color: var(--muted);
    text-align: left;
    line-height: 1.8;
}
.pairing-refresh { font-size: 12px; }
.pairing-alert { margin: 16px 0; padding: 12px; border-radius: 8px; }
.pairing-alert.error { color: #912929; background: #ffe8e8; }
.pairing-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 28px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}
.pairing-footer a { color: var(--green-deep); }
.danger-button {
    padding: 9px 12px;
    border: 1px solid #dd7777;
    border-radius: 8px;
    color: #a32626;
    background: #fff;
    cursor: pointer;
}
.instances-page, .form-page {
    height: 100%;
    overflow-y: auto;
    padding: 38px;
    border-radius: 4px;
    background: #f7f9fa;
}
.page-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    max-width: 1180px;
    margin: 0 auto 28px;
}
.page-heading.compact { max-width: 760px; }
.page-heading h1 { margin: 5px 0 7px; font-size: 31px; }
.page-heading p { margin: 0; color: var(--muted); }
.page-actions { display: flex; gap: 9px; }
.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
    border: 1px solid #cbd3d7;
    border-radius: 8px;
    color: var(--ink);
    background: #fff;
    text-decoration: none;
    cursor: pointer;
}
.button.primary { border-color: var(--green-deep); color: #fff; background: var(--green-deep); }
.button.full { width: 100%; }
.instance-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
    max-width: 1180px;
    margin: 0 auto;
}
.instance-grid > .empty-card { grid-column: 1 / -1; }
.instance-card, .empty-card, .settings-form {
    padding: 24px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #fff;
    box-shadow: 0 5px 20px rgba(11, 20, 26, .06);
}
.instance-card.selected { border-color: var(--green); box-shadow: 0 5px 22px rgba(0, 128, 105, .13); }
.instance-card-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.instance-card h2 { margin: 8px 0 0; font-size: 20px; }
.status, .current-badge {
    display: inline-block;
    padding: 3px 8px;
    border-radius: 999px;
    color: #49606d;
    background: #edf1f3;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}
.status-active, .current-badge { color: #056450; background: #dff5ee; }
.status-error { color: #972929; background: #ffe8e8; }
.instance-node-stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin: 24px 0 18px;
}
.instance-node-stats.single-node { grid-template-columns: 1fr; }
.instance-node-panel { padding: 12px; border-radius: 11px; background: #f3f6f7; }
.instance-node-panel.desktop-node { background: #e7f5f0; }
.instance-node-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.instance-node-heading span { color: #16313d; font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.instance-node-heading small { color: var(--muted); font-size: 10px; }
.instance-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 10px 0 0; }
.instance-stats div { min-width: 0; padding: 10px; border-radius: 8px; background: rgba(255, 255, 255, .78); }
.instance-stats dt { color: var(--muted); font-size: 11px; }
.instance-stats dd { margin: 4px 0 0; font-size: 21px; font-weight: 700; }
.desktop-stats-status { margin: 9px 2px 0; color: #056450; font-size: 10px; }
.desktop-stats-status.stale { color: #8a5a00; }
.instance-id { color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.instance-error { padding: 9px; border-radius: 7px; color: #8d2929; background: #fff0f0; font-size: 12px; }
.instance-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
    gap: 8px;
    margin-top: 16px;
}
.instance-actions form { margin: 0; }
.instance-actions .button, .instance-actions .danger-button { min-height: 40px; }
.instance-action-wide { grid-column: 1 / -1; }
.instance-actions > .replication-progress { grid-column: 2; }
.replication-button:disabled {
    cursor: wait;
    color: #65757d;
    border-color: #d4dadd;
    background: #edf1f3;
    opacity: 1;
}
.replication-progress { margin: -2px 2px 4px; color: var(--muted); font-size: 11px; }
.replication-progress.complete { color: #056450; }
.replication-progress.error { color: #972929; }
.danger-button.full { width: 100%; min-height: 40px; }
.settings-form { display: grid; gap: 18px; max-width: 760px; margin: 0 auto; }
.settings-section {
    display: grid;
    gap: 16px;
    padding: 20px;
    border: 1px solid #dfe5e7;
    border-radius: 12px;
    background: #fff;
}
.settings-section h2 { margin: 5px 0 4px; }
.settings-section p { margin: 0; color: var(--muted); }
.settings-form label { display: grid; gap: 7px; font-weight: 600; }
.settings-form input {
    width: 100%;
    padding: 11px 12px;
    border: 1px solid #c8d0d4;
    border-radius: 8px;
    outline: none;
}
.settings-form select {
    width: 100%; padding: 11px 12px; border: 1px solid #c8d0d4;
    border-radius: 8px; background: #fff;
}
.settings-form input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(0, 168, 132, .12); }
.settings-form small { color: var(--muted); font-weight: 400; }
.auth-page { display: grid; align-content: center; min-height: 100vh; }
.auth-form, .auth-flash { width: min(100%, 480px); margin-right: auto; margin-left: auto; }
.auth-form { padding: 28px; }
.auth-link { color: var(--green-deep); text-align: center; }
.auth-checkbox { display: flex !important; grid-template-columns: auto 1fr; align-items: center; justify-content: flex-start; }
.auth-checkbox input { width: auto; }
.auth-message p { margin: 0; color: var(--muted); line-height: 1.65; }
.desktop-health-check { display: grid; gap: 9px; }
.desktop-health-check .button { width: 100%; }
.desktop-health-check .button:disabled { cursor: wait; opacity: .65; }
.desktop-health-result {
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--muted);
    background: #f1f4f5;
    font-size: 12px;
}
.desktop-health-result.testing { color: #725600; background: #fff5d6; }
.desktop-health-result.connected { color: #056450; background: #dff5ee; }
.desktop-health-result.disconnected { color: #972929; background: #ffe8e8; }
.integration-summary {
    margin: 0 0 18px;
    padding: 12px 14px;
    border-radius: 9px;
    color: #056450;
    background: #e9f7f2;
    overflow-wrap: anywhere;
}
.instance-onboarding-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.instance-onboarding-card, .configuration-required-card {
    padding: 22px;
    border: 1px solid #dfe5e7;
    border-radius: 12px;
    background: #fff;
}
.instance-onboarding-card h2, .configuration-required-card h2 { margin: 7px 0 8px; }
.instance-onboarding-card > p, .configuration-required-card p {
    margin: 0 0 18px;
    color: var(--muted);
}
.compact-form { gap: 14px; max-width: none; margin: 0; }
.empty-inline-state {
    padding: 14px;
    border-radius: 9px;
    color: var(--muted);
    background: #f2f5f6;
}
.import-history-note { display: block; margin-top: 14px; color: var(--muted); line-height: 1.5; }

@media (max-width: 800px) {
    body { background: #fff; }
    .shell { width: 100%; height: 100vh; height: 100dvh; min-height: 0; margin: 0; }
    .app { grid-template-columns: 1fr; border-radius: 0; box-shadow: none; }
    .welcome-panel { display: none; }
    .welcome-panel.conversation-stage.is-external-loading {
        position: absolute;
        inset: 0;
        z-index: 3;
        display: block;
        padding: 0;
        border: 0;
    }
    .chat { position: absolute; inset: 0; z-index: 2; height: 100vh; height: 100dvh; }
    .chat .chat-header { min-height: 62px; padding: 9px 12px; gap: 9px; }
    .chat-header h2 { font-size: 16px; }
    .mobile-back { display: block; }
    .secondary-button { padding: 8px; font-size: 12px; }
    .chat-header-actions { gap: 5px; }
    .chat-header-actions > :not(:first-child) { display: none; }
    .export-conversation-button { max-width: 92px; line-height: 1.15; }
    .messages { padding: 14px 12px; }
    .bubble { max-width: 88%; }
    .webhook-page { padding: 12px; }
    .webhook-header { align-items: flex-start; flex-direction: column; }
    .event-card summary { flex-wrap: wrap; }
    .event-card summary time { width: 100%; margin-left: 18px; }
    .event-meta { flex-direction: column; gap: 4px; }
    .pairing-page { padding: 12px; }
    .pairing-card { padding: 22px 16px; }
    .pairing-footer { align-items: stretch; flex-direction: column; }
    .instances-page, .form-page { padding: 20px 14px; border-radius: 0; }
    .instance-grid { grid-template-columns: 1fr; }
    .instance-stats { grid-template-columns: 1fr 1fr; }
    .page-heading { flex-direction: column; }
    .page-actions { width: 100%; flex-wrap: wrap; }
    .instance-onboarding-grid { grid-template-columns: 1fr; }
}

@media (max-width: 520px) {
    .instance-node-stats { grid-template-columns: 1fr; }
    .instance-actions { grid-template-columns: 1fr; }
    .instance-action-wide, .instance-actions > .replication-progress { grid-column: auto; }
}
