:root {
    --bg: #f5f7f9;
    --panel: #ffffff;
    --ink: #111827;
    --muted: #667085;
    --line: #dfe5ea;
    --green: #0a8f45;
    --green-2: #e8f7ef;
    --red: #d92d20;
    --red-2: #fff1f0;
    --blue: #2176d2;
    --dark: #0d1b2a;
    font-family: Inter, Segoe UI, Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--bg); color: var(--ink); }
body.chat-route {
    height: var(--app-height, 100dvh);
    overflow: hidden;
}
body.chat-route.ios-viewport {
    position: fixed;
    inset: 0;
    width: 100%;
}
a { color: inherit; text-decoration: none; }
button, input, textarea { font: inherit; }

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: linear-gradient(90deg, #f5fffa 0%, #f8fafc 48%, #ffffff 100%);
}
.login-wrap {
    width: min(1100px, calc(100vw - 32px));
    display: grid;
    grid-template-columns: minmax(320px, 430px) 1fr;
    gap: 34px;
    align-items: center;
}
.login-card, .login-preview, .panel, .stat-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .07);
}
.login-card { padding: 34px; }
.logo-bubble, .brand-mark {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 8px;
    background: var(--green);
    color: white;
    font-weight: 800;
}
.login-card h1 { margin: 16px 0 6px; font-size: 32px; }
.login-card p, .login-preview p, .page-title p, .panel p { color: var(--muted); }
.login-form { display: grid; gap: 12px; margin-top: 22px; }
label { display: grid; gap: 8px; font-weight: 650; }
input, textarea, select {
    width: 100%;
    border: 1px solid #cfd8e3;
    border-radius: 6px;
    min-height: 46px;
    padding: 11px 13px;
    background: white;
    color: var(--ink);
}
textarea { resize: vertical; }
.login-form button, .primary, .send-btn {
    min-height: 46px;
    border: 0;
    border-radius: 6px;
    background: var(--green);
    color: white;
    font-weight: 750;
    cursor: pointer;
}
.primary:disabled, .send-btn:disabled {
    background: #98a2b3;
    cursor: not-allowed;
}
.signup-link {
    display: block;
    margin-top: 18px;
    text-align: center;
    color: var(--green);
    font-weight: 750;
}
.login-preview { padding: 34px; min-height: 390px; }
.login-preview h2 { font-size: 42px; max-width: 500px; margin: 24px 0 10px; }
.mini-chat { margin-top: 26px; display: grid; gap: 12px; }
.mini-chat div {
    width: fit-content;
    max-width: 78%;
    padding: 12px 14px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
}
.mini-chat .sent { justify-self: end; background: var(--green-2); border-color: #b7e4c7; }

.shell { min-height: 100vh; display: grid; grid-template-columns: 270px 1fr; }
.sidebar {
    background: var(--dark);
    color: #e8eef5;
    padding: 22px 16px;
    display: grid;
    grid-template-rows: auto 1fr auto;
    gap: 28px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand span { display: block; color: #aab6c3; font-size: 13px; margin-top: 2px; }
.sidebar nav { display: grid; gap: 8px; align-content: start; }
.sidebar nav a {
    padding: 13px 14px;
    border-radius: 7px;
    color: #d7dee7;
    font-weight: 650;
}
.sidebar nav a.active, .sidebar nav a:hover { background: rgba(255,255,255,.10); color: #ffffff; box-shadow: inset 4px 0 0 var(--green); }
.sidebar-user { border-top: 1px solid rgba(255,255,255,.12); padding-top: 16px; }
.sidebar-user span, .sidebar-user small { display: block; }
.sidebar-user small { color: #73e49a; margin-top: 4px; }
.main { padding: 28px; overflow-x: hidden; }
.chat-route {
    overflow: hidden;
}
.chat-route .shell {
    height: var(--app-height, 100dvh);
    min-height: 0;
}
.chat-route .main {
    height: var(--app-height, 100dvh);
    min-height: 0;
    padding: 0;
    overflow: hidden;
}
.chat-route .inbox-app {
    width: 100%;
    height: var(--app-height, 100dvh);
    min-height: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}
.page-title {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}
.page-title h1 { font-size: 34px; margin: 0 0 5px; }
.status-pill, .cloud-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 7px 12px;
    border-radius: 999px;
    font-weight: 750;
    font-size: 13px;
    white-space: nowrap;
}
.status-pill.ok, .cloud-pill { color: var(--green); background: var(--green-2); border: 1px solid #b7e4c7; }
.status-pill.danger { color: var(--red); background: var(--red-2); border: 1px solid #ffc5bf; }
.status-pill.muted { color: #475467; background: #eef2f6; border: 1px solid #d7dee7; }
.notice {
    padding: 12px 14px;
    border-radius: 7px;
    margin-bottom: 16px;
    background: var(--green-2);
    color: #05603a;
    border: 1px solid #b7e4c7;
}
.notice.danger { background: var(--red-2); color: var(--red); border-color: #ffc5bf; }
.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 18px; }
.stat-card { padding: 20px; display: grid; gap: 8px; }
.stat-card small { color: var(--muted); font-weight: 700; }
.stat-card strong { font-size: 28px; }
.stat-card span { color: var(--muted); }
.panel { padding: 22px; margin-bottom: 18px; }
.panel h2 { margin: 0 0 12px; }
.account-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 220px));
    gap: 14px;
}
.account-grid div {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 14px;
    background: #fbfcfe;
}
.account-grid small {
    display: block;
    color: var(--muted);
    font-weight: 750;
    margin-bottom: 6px;
}
.account-grid strong {
    font-size: 18px;
}
.setup-top { display: grid; grid-template-columns: 1fr 170px; gap: 22px; align-items: end; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.form-grid.wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.setup-progress {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 18px 0 0;
}
.setup-progress span {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid #ffd4cf;
    background: #fff7f6;
    color: var(--red);
    font-size: 12px;
    font-weight: 800;
}
.setup-progress span.done {
    border-color: #b7e4c7;
    background: var(--green-2);
    color: var(--green);
}
.auto-note {
    margin: 18px 0 12px;
    padding: 12px 14px;
    color: #155eef;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 7px;
}
.status-row { display: flex; flex-wrap: wrap; gap: 10px; }
.divider { height: 1px; background: var(--line); margin: 22px 0; }
.action-panel { display: flex; justify-content: space-between; gap: 20px; align-items: center; }
.inline-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.outline, .outline-ok, .outline-danger, .copy-row button, .icon-btn {
    min-height: 42px;
    padding: 9px 13px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 6px;
    cursor: pointer;
    font-weight: 700;
}
.outline-ok { color: var(--green); border-color: #8ed9aa; }
.outline-danger { color: var(--red); border-color: #ffa9a1; }
.copy-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin: 8px 0 16px; }
.toggle-line { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.toggle-line input { width: 18px; min-height: 18px; }

.setup-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}
.setup-main {
    display: grid;
    gap: 18px;
}
.setup-card {
    display: grid;
    gap: 16px;
}
.setup-card-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 18px;
}
.setup-card-head small {
    color: var(--green);
    font-weight: 850;
    text-transform: uppercase;
}
.setup-card-head h2 {
    margin: 4px 0 6px;
}
.status-stack {
    display: grid;
    gap: 8px;
    justify-items: end;
}
.meta-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    width: fit-content;
    padding: 8px 12px;
    border: 1px solid #b7d7f8;
    border-radius: 6px;
    color: var(--blue);
    background: #f3f8ff;
    font-weight: 750;
}
.link-row, .setup-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.setup-step-form {
    display: grid;
    gap: 14px;
}
.webhook-help {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 8px 12px;
    padding: 14px;
    border: 1px solid #ffd4cf;
    border-radius: 7px;
    background: #fff7f6;
}
.webhook-help span {
    overflow-wrap: anywhere;
    color: #475467;
}
.webhook-help .inline-actions {
    grid-column: 1 / -1;
}
.token-info {
    display: grid;
    gap: 12px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: #fbfcfe;
}
.token-info h3 {
    margin: 0;
}
.info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
}
.info-grid div {
    min-width: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: white;
}
.info-grid small, .phone-card small, .health-panel dt {
    display: block;
    color: var(--muted);
    font-weight: 750;
    font-size: 12px;
}
.info-grid strong, .phone-card strong {
    display: block;
    margin-top: 4px;
    overflow-wrap: anywhere;
}
.scope-list {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.scope-list span, .scope-list em {
    padding: 6px 9px;
    border-radius: 999px;
    background: #eef2f6;
    color: #344054;
    font-size: 12px;
    font-style: normal;
    font-weight: 750;
}
.mini-alert {
    padding: 10px 12px;
    border-radius: 7px;
    border: 1px solid #ffc5bf;
    background: var(--red-2);
    color: var(--red);
    font-weight: 750;
}
.phone-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.phone-card {
    display: grid;
    gap: 5px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: white;
}
.phone-card.selected {
    border-color: #8ed9aa;
    background: #f1fbf5;
}
.phone-card span {
    color: #344054;
}
.health-panel {
    position: sticky;
    top: 18px;
    display: grid;
    gap: 14px;
}
.health-status {
    min-height: 46px;
    display: grid;
    place-items: center;
    border-radius: 7px;
    font-weight: 900;
}
.health-status.good {
    color: var(--green);
    background: var(--green-2);
    border: 1px solid #b7e4c7;
}
.health-status.limited {
    color: #b54708;
    background: #fffaeb;
    border: 1px solid #fedf89;
}
.health-panel dl {
    display: grid;
    grid-template-columns: minmax(120px, auto) minmax(0, 1fr);
    gap: 8px 12px;
    margin: 0;
}
.health-panel dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.health-issues {
    display: grid;
    gap: 10px;
}
.issue-card {
    display: grid;
    gap: 5px;
    padding: 12px;
    border-radius: 7px;
    border: 1px solid #fedf89;
    background: #fffaeb;
}
.issue-card.ok {
    border-color: #b7e4c7;
    background: var(--green-2);
}
.issue-card span, .issue-card small {
    overflow-wrap: anywhere;
    color: #475467;
}

.chat-app {
    height: calc(100vh - 56px);
    min-height: 620px;
    display: grid;
    grid-template-columns: 410px 1fr;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.contact-pane { border-right: 1px solid var(--line); padding: 20px; overflow: auto; }
.chat-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; }
.chat-heading h1 { margin: 0; font-size: 28px; }
.chat-heading span { color: var(--green); font-size: 13px; font-weight: 750; }
.search { margin: 18px 0 12px; }
.tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.tabs button {
    border: 0;
    background: transparent;
    border-bottom: 2px solid transparent;
    padding: 10px 4px;
    cursor: pointer;
    font-weight: 750;
}
.tabs button span {
    display: inline-grid;
    min-width: 20px;
    min-height: 20px;
    margin-left: 4px;
    padding: 2px 6px;
    place-items: center;
    border-radius: 999px;
    background: #eef2f6;
    color: #475467;
    font-size: 11px;
    line-height: 1;
}
.tabs button span:empty {
    display: none;
}
.tabs button.active { color: var(--green); border-color: var(--green); }
.contacts { display: grid; gap: 8px; }
.contact-item {
    width: 100%;
    display: grid;
    grid-template-columns: 44px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    text-align: left;
    cursor: pointer;
}
.contact-item.active, .contact-item:hover { background: #f1fbf5; border-color: #ccefd8; }
.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #0f9f6e;
    color: white;
    display: grid;
    place-items: center;
    font-weight: 800;
}
.contact-item strong, .contact-item span { display: block; }
.contact-item span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 230px; }
.badge { background: var(--green); color: white; border-radius: 999px; min-width: 22px; min-height: 22px; display: grid; place-items: center; font-size: 12px; font-weight: 800; }
.conversation { display: grid; grid-template-rows: auto 1fr auto; min-width: 0; }
.conversation-head {
    height: 74px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 0 22px;
    border-bottom: 1px solid var(--line);
}
.conversation-head strong, .conversation-head span { display: block; }
.conversation-head span { color: var(--green); margin-top: 3px; }
.messages {
    padding: 24px;
    overflow: auto;
    background: #fbfaf6;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.message {
    max-width: min(640px, 82%);
    padding: 12px 14px;
    border-radius: 8px;
    background: white;
    border: 1px solid var(--line);
    box-shadow: 0 2px 8px rgba(15,23,42,.04);
}
.message.out { align-self: flex-end; background: #dcf8c6; border-color: #bceaa5; }
.message small { display: block; margin-top: 7px; color: var(--muted); font-size: 12px; }
.empty-state { margin: auto; color: var(--muted); }
.composer {
    position: relative;
    display: grid;
    grid-template-columns: auto auto 1fr auto auto;
    gap: 10px;
    padding: 14px;
    border-top: 1px solid var(--line);
    background: white;
}
.composer textarea { min-height: 46px; max-height: 120px; }
.voice-btn {
    border: 0;
    background: var(--green);
    color: white;
    border-radius: 999px;
    padding: 0 18px;
    font-weight: 800;
    cursor: pointer;
}
.voice-btn.recording { background: var(--red); }
.attach-menu {
    position: absolute;
    left: 58px;
    bottom: 70px;
    background: white;
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 16px 36px rgba(15,23,42,.14);
    padding: 8px;
    display: grid;
    min-width: 170px;
}
.attach-menu button {
    background: transparent;
    border: 0;
    text-align: left;
    padding: 10px 12px;
    border-radius: 6px;
    cursor: pointer;
}
.attach-menu button:hover { background: #f2f4f7; }
dialog { border: 0; border-radius: 8px; padding: 0; width: min(480px, calc(100vw - 28px)); }
dialog::backdrop { background: rgba(15, 23, 42, .42); }
.modal { padding: 22px; display: grid; gap: 14px; }
.modal h2 { margin: 0; }
.modal menu { display: flex; justify-content: end; gap: 10px; padding: 0; margin: 0; }
.quick-list { display: grid; gap: 8px; max-height: 200px; overflow: auto; }
.quick-list button { text-align: left; padding: 10px; border: 1px solid var(--line); border-radius: 6px; background: white; cursor: pointer; }

.tool-btn {
    min-height: 40px;
    padding: 9px 13px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    color: var(--ink);
    font-weight: 750;
    cursor: pointer;
}
.tool-btn:hover, .icon-btn:hover { background: #f2f6f9; }
.inbox-app {
    height: calc(var(--app-height, 100dvh) - 56px);
    min-height: 640px;
    display: grid;
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr);
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .06);
}
.chat-list-panel {
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    border-right: 1px solid var(--line);
    display: grid;
    grid-template-rows: auto auto auto minmax(0, 1fr);
    background: #ffffff;
}
.chat-list-head {
    min-height: 76px;
    padding: 18px 18px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.chat-list-head h1 {
    margin: 0;
    font-size: 25px;
    line-height: 1.15;
}
.chat-list-head span {
    display: block;
    margin-top: 4px;
    color: var(--green);
    font-size: 13px;
    font-weight: 750;
}
.chat-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.icon-only {
    min-width: 42px;
    padding: 8px 10px;
    display: inline-grid;
    place-items: center;
}
.inbox-app .search {
    width: calc(100% - 32px);
    margin: 8px 16px 12px;
}
.inbox-app .tabs {
    padding: 0 16px;
    margin-bottom: 8px;
}
.inbox-app .contacts {
    overflow: auto;
    padding: 0 10px 14px;
    align-content: start;
}
.inbox-app .contact-swipe {
    position: relative;
    overflow: hidden;
    border-radius: 6px;
    touch-action: pan-y;
}
.inbox-app .contact-swipe .contact-item {
    position: relative;
    z-index: 1;
    background: #ffffff;
    transition: transform .18s ease;
    will-change: transform;
}
.inbox-app .contact-swipe.swiped .contact-item {
    transform: translateX(-96px);
}
.contact-archive-action {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 0;
    width: 96px;
    border: 0;
    background: #16a34a;
    color: #ffffff;
    cursor: pointer;
    font-weight: 850;
}
.contact-load-more {
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    color: var(--green);
    cursor: pointer;
    font-weight: 800;
}
.contact-load-more[disabled] {
    cursor: default;
    opacity: .65;
}
.inbox-app .contact-item {
    grid-template-columns: 46px minmax(0, 1fr) auto;
    min-height: 74px;
    border-radius: 6px;
    border-color: transparent;
}
.contact-item.unread {
    background: #f5fbf7;
}
.contact-item.unread strong {
    color: #064e3b;
}
.avatar img, .thread-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}
.contact-main {
    min-width: 0;
    display: grid;
    gap: 2px;
}
.contact-main strong, .contact-main small, .contact-main span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.contact-main small {
    color: #475467;
    font-size: 12px;
}
.contact-main span {
    color: var(--muted);
    max-width: none;
}
.contact-meta {
    min-width: 58px;
    display: grid;
    justify-items: end;
    gap: 5px;
    color: var(--muted);
    font-size: 12px;
}
.contact-meta time {
    max-width: 86px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.contact-meta small {
    color: var(--green);
    font-weight: 750;
}
.thread-panel {
    position: relative;
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    background: #eef2f1;
}
.thread-empty {
    grid-row: 1 / -1;
    grid-column: 1;
    height: 100%;
    display: grid;
    place-items: center;
    align-content: center;
    gap: 8px;
    padding: 24px;
    color: var(--muted);
    text-align: center;
    background: #f8fafc;
}
.thread-empty strong {
    color: var(--ink);
    font-size: 20px;
}
.inbox-app:not(.conversation-selected) .thread-head,
.inbox-app:not(.conversation-selected) .thread-search,
.inbox-app:not(.conversation-selected) .messages,
.inbox-app:not(.conversation-selected) .recorder,
.inbox-app:not(.conversation-selected) .composer,
.inbox-app:not(.conversation-selected) .message-scrollbar,
.inbox-app:not(.conversation-selected) .new-message-indicator {
    display: none !important;
}
.inbox-app.conversation-selected .thread-empty {
    display: none;
}
.thread-head {
    grid-row: 1;
    grid-column: 1;
    min-height: 74px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--line);
    background: #ffffff;
}
.back-btn {
    display: none;
    min-height: 38px;
    padding: 8px 11px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    font-weight: 750;
    cursor: pointer;
}
.thread-avatar {
    width: 46px;
    height: 46px;
    flex: 0 0 46px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #0f9f6e;
    color: white;
    font-weight: 850;
}
.thread-title {
    min-width: 0;
    flex: 1;
    display: grid;
    gap: 3px;
}
.thread-title strong, .thread-title span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.thread-title span {
    color: var(--muted);
    font-size: 13px;
}
.thread-search {
    grid-row: 2;
    grid-column: 1;
    padding: 10px 16px;
    background: #ffffff;
    border-bottom: 1px solid var(--line);
}
.inbox-app .messages {
    grid-row: 3;
    grid-column: 1;
    min-height: 0;
    overflow-y: scroll;
    overflow-x: hidden;
    background: linear-gradient(180deg, #f7f4ed 0%, #eef5ef 100%);
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    scrollbar-gutter: stable;
    scrollbar-width: thin;
    scrollbar-color: rgba(77, 91, 103, .56) rgba(255, 255, 255, .18);
}
.inbox-app .messages::-webkit-scrollbar {
    width: 10px;
}
.inbox-app .messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, .18);
    border-radius: 999px;
}
.inbox-app .messages::-webkit-scrollbar-thumb {
    background: rgba(77, 91, 103, .56);
    border: 2px solid rgba(255, 255, 255, .22);
    border-radius: 999px;
}
.message-scrollbar {
    position: absolute;
    right: 5px;
    z-index: 3;
    width: 7px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .34);
    opacity: .62;
    pointer-events: none;
    transition: opacity .16s ease;
}
.message-scrollbar.active {
    opacity: .95;
}
.message-scrollbar span {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    min-height: 34px;
    border-radius: 999px;
    background: rgba(46, 59, 73, .58);
    box-shadow: 0 1px 6px rgba(15, 23, 42, .18);
}
.new-message-indicator {
    position: absolute;
    right: 22px;
    bottom: 88px;
    z-index: 4;
    width: 44px;
    height: 44px;
    min-height: 44px;
    padding: 0;
    display: grid;
    place-items: center;
    border: 0;
    border-radius: 50%;
    background: #ffffff;
    color: #ffffff;
    color: #0f9f6e;
    font-size: 24px;
    line-height: 1;
    font-weight: 900;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .22);
    cursor: pointer;
}
.date-separator {
    align-self: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .82);
    color: #475467;
    font-size: 12px;
    font-weight: 800;
    box-shadow: 0 2px 8px rgba(15,23,42,.05);
}
.message-text {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.message.failed {
    border-color: #ffc5bf;
    background: #fff7f6;
}
.error-line {
    margin-top: 8px;
    color: var(--red);
    font-size: 12px;
    overflow-wrap: anywhere;
}
.retry-btn {
    margin-top: 8px;
    border: 1px solid #ffa9a1;
    color: var(--red);
    background: white;
    border-radius: 6px;
    padding: 7px 10px;
    font-weight: 750;
    cursor: pointer;
}
.image-preview {
    display: block;
    width: min(320px, 100%);
    border: 0;
    padding: 0;
    margin: 0 0 8px;
    background: transparent;
    cursor: zoom-in;
}
.image-preview img {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: cover;
    border-radius: 7px;
}
.video-preview {
    display: block;
    width: min(360px, 100%);
    max-height: 320px;
    border-radius: 7px;
    margin-bottom: 8px;
    background: #111827;
}
.audio-card {
    min-width: min(320px, 72vw);
    display: grid;
    gap: 7px;
}
.audio-card audio {
    width: 100%;
}
.document-card {
    display: grid;
    gap: 4px;
    min-width: min(300px, 72vw);
    padding: 12px;
    margin-bottom: 8px;
    border-radius: 7px;
    border: 1px solid #cfd8e3;
    background: #ffffff;
}
.document-card strong, .document-card span {
    overflow-wrap: anywhere;
}
.document-card span {
    color: var(--muted);
    font-size: 12px;
}
.document-card em {
    color: var(--blue);
    font-style: normal;
    font-weight: 750;
}
.recorder {
    grid-row: 1;
    grid-column: 1 / -1;
    margin: 0;
    padding: 0;
    width: 100%;
    min-width: 0;
    min-height: 46px;
    display: grid;
    grid-template-columns: auto minmax(72px, 1fr) minmax(150px, 300px) auto auto auto auto;
    gap: 6px;
    align-items: center;
    border: 0;
    background: transparent;
}
.recorder.sending {
    opacity: .76;
    pointer-events: none;
}
.recorder.preview {
    grid-template-columns: auto minmax(150px, 1fr) auto auto auto;
}
.recorder audio {
    width: 100%;
    min-width: 0;
    height: 38px;
}
.inbox-app.voice-active .composer {
    display: grid;
}
.inbox-app.voice-active .composer > :not(.recorder) {
    display: none !important;
}
.recorder .voice-status {
    display: flex;
    align-items: center;
    gap: 7px;
    white-space: nowrap;
}
.recorder span {
    color: var(--red);
    font-weight: 800;
}
.recorder button {
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    cursor: pointer;
    font-weight: 750;
    white-space: nowrap;
}
.recorder [data-record-send] {
    background: var(--green);
    color: white;
    border-color: var(--green);
}
.record-wave {
    min-height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    min-width: 0;
    border-radius: 999px;
    background: white;
    border: 1px solid #ffd4cf;
}
.record-wave i {
    width: 4px;
    height: 12px;
    border-radius: 999px;
    background: var(--red);
    opacity: .45;
}
.record-wave.active i {
    animation: record-bars .7s ease-in-out infinite alternate;
}
.record-wave.active i:nth-child(2n) { animation-delay: .12s; }
.record-wave.active i:nth-child(3n) { animation-delay: .22s; }
@keyframes record-bars {
    from { height: 10px; opacity: .45; }
    to { height: 28px; opacity: 1; }
}
.inbox-app .composer {
    grid-row: 5;
    grid-column: 1;
    grid-template-columns: 52px 52px minmax(180px, 1fr) 54px 58px;
    align-items: end;
}
.inbox-app .composer textarea {
    min-width: 0;
    overflow-wrap: anywhere;
}
.inbox-app .attach-menu {
    left: 58px;
    bottom: 66px;
    z-index: 5;
}
.send-btn {
    padding: 0 14px;
}
.status-mark {
    color: var(--green);
    font-weight: 750;
}
.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 100;
    max-width: min(420px, calc(100vw - 32px));
    padding: 12px 14px;
    border-radius: 7px;
    background: #101828;
    color: #ffffff;
    box-shadow: 0 16px 42px rgba(15, 23, 42, .24);
    transform: translateY(20px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease, transform .18s ease;
}
.toast.show {
    opacity: 1;
    transform: translateY(0);
}
.emoji-panel {
    position: absolute;
    left: 14px;
    bottom: 66px;
    z-index: 6;
    width: min(360px, calc(100vw - 28px));
    display: none;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: white;
    box-shadow: 0 16px 36px rgba(15,23,42,.14);
}
.emoji-panel.open {
    display: grid;
}
.emoji-panel input {
    min-height: 38px;
}
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 4px;
    max-height: 220px;
    overflow: auto;
}
.emoji-grid button {
    min-height: 36px;
    border: 0;
    border-radius: 6px;
    background: #f8fafc;
    cursor: pointer;
    font-size: 19px;
}
.emoji-grid button:hover {
    background: #e8f7ef;
}
.emoji-tabs {
    display: flex;
    gap: 4px;
    overflow-x: auto;
}
.emoji-tabs button {
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: white;
    padding: 5px 9px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 750;
    white-space: nowrap;
}
.emoji-tabs button.active {
    color: var(--green);
    background: var(--green-2);
    border-color: #b7e4c7;
}
.preview-modal {
    padding: 12px;
    display: grid;
    gap: 12px;
    background: white;
}
.preview-modal button {
    justify-self: end;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: white;
    min-height: 36px;
    padding: 6px 10px;
    font-weight: 750;
    cursor: pointer;
}
.preview-modal img, .preview-modal video {
    max-width: min(92vw, 920px);
    max-height: 82vh;
    border-radius: 7px;
    object-fit: contain;
}

@media (max-width: 960px) {
    .login-wrap, .shell, .chat-app, .setup-top, .setup-layout, .form-grid, .form-grid.wide, .stats-grid, .account-grid, .info-grid, .phone-grid { grid-template-columns: 1fr; }
    .sidebar { min-height: auto; }
    .chat-app { height: auto; }
    .conversation { min-height: 560px; }
    .action-panel { display: grid; }
    .health-panel { position: static; }
}

@media (max-width: 620px) {
    .main { padding: 16px; }
    .page-title { display: grid; }
    .composer { grid-template-columns: auto auto 1fr; }
    .voice-btn, .send-btn { grid-column: span 1; min-height: 42px; }
    .message { max-width: 94%; }
}

@media (max-width: 960px) {
    .chat-route {
        overflow: hidden;
    }
    .chat-route .shell {
        height: var(--app-height, 100dvh);
        min-height: 0;
        display: block;
        overflow: hidden;
    }
    .chat-route .sidebar {
        display: none;
    }
    .chat-route .main {
        height: var(--app-height, 100dvh);
        min-height: 0;
        overflow: hidden;
        padding: 0;
    }
    .inbox-app {
        width: 100%;
        height: var(--app-height, 100dvh);
        min-height: 0;
        display: grid;
        grid-template-columns: 1fr;
        position: relative;
        border: 0;
        border-radius: 0;
    }
    .chat-list-panel, .thread-panel {
        height: 100%;
        min-height: 0;
        border-right: 0;
    }
    .chat-list-panel {
        display: grid;
    }
    .thread-panel {
        display: none;
        grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    }
    .inbox-app.conversation-open .chat-list-panel {
        display: none;
    }
    .inbox-app.conversation-open .thread-panel {
        display: grid;
    }
    .inbox-app:not(.conversation-open) .thread-panel {
        display: none !important;
    }
    .back-btn {
        display: inline-flex;
        align-items: center;
    }
}

@media (max-width: 700px) {
    .chat-list-head {
        padding: 14px 14px 8px;
    }
    .chat-list-head h1 {
        font-size: 22px;
    }
    .inbox-app .tabs {
        padding: 0 10px;
        gap: 4px;
    }
    .inbox-app .tabs button {
        font-size: 12px;
        padding-inline: 2px;
    }
    .inbox-app .tabs button span {
        min-width: 18px;
        min-height: 18px;
        margin-left: 2px;
        padding: 2px 5px;
        font-size: 10px;
    }
    .thread-head {
        padding: 10px;
        gap: 8px;
    }
    .thread-head .tool-btn {
        min-height: 36px;
        padding: 7px 9px;
        font-size: 13px;
    }
    .thread-avatar {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
    }
    .inbox-app .messages {
        padding: 14px 10px;
    }
    .inbox-app .message {
        max-width: 92%;
    }
    .inbox-app .composer {
        grid-template-columns: 40px 40px minmax(0, 1fr) 42px 46px;
        gap: 6px;
        padding: 8px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
        align-items: center;
    }
    .inbox-app .composer textarea {
        grid-column: auto;
        grid-row: auto;
        min-height: 42px;
        max-height: 92px;
        border-radius: 22px;
    }
    .inbox-app .composer [data-emoji],
    .inbox-app .composer [data-attach-toggle],
    .inbox-app .composer [data-voice],
    .inbox-app .composer [data-send] {
        grid-row: auto;
        min-height: 40px;
        min-width: 40px;
        padding: 0;
    }
    .inbox-app .attach-menu {
        left: 10px;
        right: 10px;
        bottom: 66px;
    }
    .emoji-panel {
        left: 10px;
        right: 10px;
        bottom: 66px;
        width: auto;
    }
    .recorder {
        grid-template-columns: auto minmax(42px, 1fr) auto auto auto auto;
        gap: 4px;
        min-height: 42px;
        max-height: none;
        overflow: visible;
        padding-bottom: 0;
    }
    .recorder.preview {
        grid-template-columns: auto minmax(80px, 1fr) auto auto auto;
    }
    .recorder.preview audio {
        min-width: 0;
        height: 34px;
    }
    .recorder .voice-status {
        gap: 4px;
        font-size: 11px;
    }
    .recorder .record-wave {
        min-height: 34px;
        gap: 2px;
        padding: 0 4px;
    }
    .recorder button {
        min-height: 34px;
        padding: 4px 6px;
        font-size: 11px;
    }
    .new-message-indicator {
        right: 12px;
        bottom: 72px;
    }
}

/* Scoped pages added without changing the existing inbox or setup layout. */
.details-gate {
    min-height: calc(100vh - 64px);
    display: grid;
    place-items: center;
    padding: 24px;
}
.details-gate-card {
    width: min(100%, 430px);
    padding: 28px;
    border: 1px solid #dce3e8;
    border-radius: 8px;
    background: #fff;
    box-shadow: 0 12px 34px rgba(16, 30, 38, .1);
}
.details-gate-card h1 {
    margin: 0 0 8px;
    font-size: 24px;
}
.details-gate-card p {
    margin: 0 0 20px;
    color: #60717a;
}
.details-gate-card label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}
.details-gate-card input {
    width: 100%;
    min-height: 44px;
    margin-bottom: 16px;
}
.details-gate-card .primary-btn {
    width: 100%;
}

.support-page {
    max-width: 860px;
    margin: 0 auto;
}
.support-page > header {
    margin-bottom: 24px;
}
.support-page h1 {
    margin: 0 0 8px;
}
.support-page p {
    margin: 0;
    color: #60717a;
}
.support-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
}
.support-button {
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    border-radius: 8px;
    color: #fff;
    font-weight: 800;
    text-decoration: none;
    text-align: center;
}
.support-button:hover {
    filter: brightness(.94);
}
.support-green { background: #128c5a; }
.support-blue { background: #1667b1; }
.support-black { background: #20272b; }
.support-red { background: #bd3f46; }
.support-gray { background: #657078; }

.ai-page {
    max-width: 1180px;
    margin: 0 auto;
}
.ai-page-header,
.ai-auto-bar,
.section-heading,
.ai-key-card-head,
.ai-key-actions,
.ai-key-tags {
    display: flex;
    align-items: center;
}
.ai-page-header,
.ai-auto-bar {
    justify-content: space-between;
    gap: 20px;
}
.ai-page-header {
    margin-bottom: 18px;
}
.ai-page-header h1,
.ai-auto-bar h2,
.section-heading h2,
.ai-key-card h3 {
    margin: 0;
}
.ai-page-header p,
.ai-auto-bar p,
.ai-key-card p {
    margin: 5px 0 0;
    color: #64747c;
}
.ai-cloud-state,
.verify-state,
.ai-key-tags span {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}
.ai-cloud-state.on,
.verify-state.ok,
.ai-key-tags .active-tag {
    color: #07633d;
    background: #dff5e9;
}
.ai-cloud-state.off,
.verify-state.bad {
    color: #98404a;
    background: #fae7e9;
}
.ai-auto-bar,
.ai-editor,
.ai-key-list {
    border: 1px solid #dce3e8;
    border-radius: 8px;
    background: #fff;
}
.ai-auto-bar {
    padding: 18px 20px;
    margin-bottom: 18px;
}
.ai-auto-form {
    display: flex;
    align-items: center;
    gap: 12px;
}
.ai-auto-form select {
    min-width: 260px;
}
.toggle-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}
.toggle-control input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}
.toggle-control span {
    width: 44px;
    height: 24px;
    position: relative;
    border-radius: 999px;
    background: #aeb9bf;
}
.toggle-control span::after {
    content: "";
    width: 18px;
    height: 18px;
    position: absolute;
    top: 3px;
    left: 3px;
    border-radius: 50%;
    background: #fff;
    transition: transform .16s ease;
}
.toggle-control input:checked + span {
    background: #128c5a;
}
.toggle-control input:checked + span::after {
    transform: translateX(20px);
}
.ai-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr);
    gap: 18px;
    align-items: start;
}
.ai-editor,
.ai-key-list {
    padding: 20px;
}
.section-heading {
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
}
.ai-key-form {
    display: grid;
    gap: 15px;
}
.ai-key-form > label,
.ai-key-form .form-grid label {
    display: grid;
    gap: 7px;
    font-weight: 700;
}
.ai-key-form textarea {
    width: 100%;
    resize: vertical;
}
.ai-capabilities {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}
.check-row {
    display: flex;
    gap: 10px;
    padding: 12px;
    border: 1px solid #dce3e8;
    border-radius: 7px;
}
.check-row span {
    display: grid;
    gap: 4px;
}
.check-row small {
    color: #687981;
    font-weight: 500;
}
.provider-note {
    min-height: 20px;
    margin: 0;
    color: #52656e;
    font-size: 13px;
}
.ai-key-list {
    display: grid;
    gap: 12px;
}
.ai-key-list .section-heading {
    margin-bottom: 4px;
}
.ai-key-card {
    padding: 15px;
    border: 1px solid #dce3e8;
    border-left: 4px solid #87959c;
    border-radius: 7px;
}
.ai-key-card.active {
    border-left-color: #128c5a;
}
.ai-key-card-head {
    justify-content: space-between;
    gap: 10px;
}
.ai-key-tags {
    flex-wrap: wrap;
    gap: 6px;
    margin: 12px 0;
}
.ai-key-tags span {
    color: #3d4e56;
    background: #edf1f3;
}
.ai-key-error {
    margin: 10px 0;
    padding: 10px;
    border-radius: 6px;
    color: #8b2932;
    background: #fff0f1;
    overflow-wrap: anywhere;
}
.ai-key-actions {
    flex-wrap: wrap;
    gap: 8px;
}
.ai-key-actions form {
    margin: 0;
}

@media (max-width: 900px) {
    .ai-layout,
    .support-actions {
        grid-template-columns: 1fr;
    }
    .ai-page-header,
    .ai-auto-bar,
    .ai-auto-form {
        align-items: stretch;
        flex-direction: column;
    }
    .ai-auto-form select {
        min-width: 0;
        width: 100%;
    }
}
@media (max-width: 560px) {
    .details-gate {
        padding: 12px;
    }
    .details-gate-card,
    .ai-editor,
    .ai-key-list {
        padding: 16px;
    }
    .ai-capabilities {
        grid-template-columns: 1fr;
    }
}

.auto-connect-shell {
    display: block;
}
.auto-connect-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 320px;
    gap: 18px;
}
.auto-connect-main,
.auto-connect-side {
    display: grid;
    align-content: start;
    gap: 14px;
}
.auto-card {
    padding: 18px;
    border: 1px solid #dce3e8;
    border-radius: 8px;
    background: #fff;
}
.auto-card small {
    display: block;
    margin-bottom: 6px;
    color: #6a7b83;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
}
.auto-card h2 {
    margin: 0 0 8px;
}
.auto-card p {
    margin: 0 0 12px;
    color: #52656e;
}
.auto-card-head,
.auto-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
}
.auto-actions {
    justify-content: flex-start;
    margin-top: 14px;
}
.auto-alert,
.auto-status-message {
    margin-top: 12px;
    padding: 11px 12px;
    border-radius: 7px;
    color: #7a3d00;
    background: #fff5df;
}
.auto-status-message {
    display: none;
}
.auto-status-message.info,
.auto-status-message.success,
.auto-status-message.error {
    display: block;
}
.auto-status-message.info {
    color: #22506d;
    background: #eaf6ff;
}
.auto-status-message.success {
    color: #12633f;
    background: #e8f8ef;
}
.auto-status-message.error {
    color: #8b2932;
    background: #fff0f1;
}
.auto-info-list {
    display: grid;
    grid-template-columns: 190px minmax(0, 1fr);
    gap: 8px 12px;
    margin: 0;
}
.auto-info-list dt {
    color: #6a7b83;
    font-weight: 700;
}
.auto-info-list dd {
    margin: 0;
    overflow-wrap: anywhere;
}
.auto-info-list.compact {
    grid-template-columns: 100px minmax(0, 1fr);
}
.auto-method-state {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0;
}
.auto-method-state span {
    padding: 10px;
    border: 1px solid #dce3e8;
    border-radius: 7px;
    color: #52656e;
    text-align: center;
    background: #f6f8f9;
}
.auto-method-state span.is-active {
    color: #0f5132;
    border-color: #88d4aa;
    background: #e8f8ef;
}
.auto-connect-blocked {
    padding: 20px;
}
.auto-connect-blocked p {
    max-width: 720px;
    color: #52656e;
}
.is-loading {
    opacity: .72;
    cursor: wait;
}
@media (max-width: 900px) {
    .auto-connect-grid {
        grid-template-columns: 1fr;
    }
    .auto-info-list {
        grid-template-columns: 1fr;
    }
}
