:root {
    --bg: #f7f7f5;
    --panel: #ffffff;
    --line: #dededb;
    --text: #1f1f1f;
    --muted: #757575;
    --soft: #f0f0ed;
    --accent: #111111;
    --green: #207245;
    --amber: #9a5b00;
    --blue: #2557a7;
    --red: #b42318;
    --shadow: 0 18px 50px rgba(0,0,0,.07);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

.app-shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 292px minmax(0, 1fr);
}

.sidebar {
    border-right: 1px solid var(--line);
    background: #f2f2ef;
    padding: 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 4px 8px 10px;
}
.brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #111;
    color: white;
    display: grid;
    place-items: center;
    font-weight: 800;
}
.brand-name { font-weight: 750; font-size: 15px; }
.brand-subtitle { color: var(--muted); font-size: 12px; margin-top: 1px; }

.sidebar-action {
    width: 100%;
    border: 0;
    background: transparent;
    border-radius: 12px;
    padding: 10px 12px;
    text-align: left;
    font-size: 15px;
    cursor: pointer;
}
.sidebar-action:hover, .nav-item:hover, .recent-item:hover { background: #e8e8e4; }

.nav-list { display: grid; gap: 4px; }
.nav-item {
    color: var(--text);
    text-decoration: none;
    border-radius: 10px;
    padding: 9px 10px;
    display: block;
    font-size: 14px;
}
.nav-item.active { background: #e5e5e0; font-weight: 650; }
.nav-item[aria-disabled="true"] { opacity: .58; }

.recent-block { margin-top: auto; min-height: 220px; overflow: visible; }
.section-label {
    color: var(--muted);
    font-size: 12px;
    padding: 0 9px 8px;
}
.recent-list { display: grid; gap: 3px; overflow: visible; }
.recent-item {
    display: block;
    color: var(--text);
    text-decoration: none;
    border-radius: 9px;
    padding: 9px 10px;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.main-panel {
    display: grid;
    grid-template-rows: 58px minmax(0, 1fr) auto;
    min-width: 0;
    height: 100vh;
    background: var(--panel);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #eeeeec;
    padding: 0 22px;
}
.topbar-title { font-weight: 700; font-size: 15px; }
.topbar-subline { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }
.ghost-btn {
    border: 1px solid var(--line);
    background: white;
    border-radius: 10px;
    padding: 7px 11px;
    cursor: pointer;
}

.start-panel, .chat-panel {
    min-height: 0;
    overflow-y: auto;
    position: relative;
}
.start-panel {
    display: grid;
    place-items: start center;
    padding: 76px 24px 120px;
}
.start-card {
    width: min(780px, 100%);
    border: 1px solid var(--line);
    border-radius: 22px;
    padding: 30px;
    box-shadow: var(--shadow);
    background: white;
}
.eyebrow {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
}
.start-card h1 {
    margin: 9px 0 8px;
    font-size: clamp(28px, 4vw, 46px);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.start-card p {
    color: #595959;
    font-size: 16px;
    line-height: 1.55;
    margin-bottom: 24px;
}

.create-form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; }
label span, .field-title {
    color: #333;
    font-size: 13px;
    font-weight: 700;
}
input, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px 14px;
    font: inherit;
    background: #fff;
    outline: none;
}
input:focus, textarea:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(0,0,0,.05); }
textarea { resize: vertical; }
.agent-picker { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 9px; margin-top: 8px; }
.agent-choice {
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 11px;
    display: flex;
    gap: 9px;
    align-items: flex-start;
    cursor: pointer;
}
.agent-choice input { width: auto; margin-top: 3px; }
.agent-choice strong { display: block; font-size: 14px; }
.agent-choice small { color: var(--muted); display: block; margin-top: 2px; }
.primary-btn, .send-btn, .continue-btn {
    border: 0;
    background: var(--accent);
    color: white;
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 750;
    cursor: pointer;
}
.primary-btn:hover, .send-btn:hover, .continue-btn:hover { opacity: .92; }

.presence-bar {
    position: sticky;
    top: 0;
    z-index: 4;
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(10px);
    padding: 12px 24px;
    border-bottom: 1px solid #eeeeec;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.presence-pill {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: 13px;
    display: flex;
    gap: 7px;
    align-items: center;
    cursor: default;
    user-select: none;
}
.presence-pill[data-wake-agent] {
    cursor: pointer;
}
.presence-pill[data-wake-agent]:hover {
    background: #f0f0ed;
    border-color: #c0c0bc;
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #a0a0a0;
}
.status-thinking .status-dot, .status-responding .status-dot { background: var(--green); animation: pulse 1s ease-in-out infinite; }
.status-queued .status-dot { background: var(--amber); }
.status-idle .status-dot { background: var(--blue); }
.status-offline .status-dot { background: #888; }
.status-blocked .status-dot { background: var(--red); }
@keyframes pulse { 0%, 100% { transform: scale(.82); opacity: .75; } 50% { transform: scale(1.25); opacity: 1; } }

.messages {
    width: min(820px, calc(100% - 36px));
    margin: 0 auto;
    padding: 34px 0 120px;
    display: grid;
    gap: 20px;
}
.message-row { display: grid; gap: 7px; }
.message-row.human { justify-items: end; }
.message-card {
    max-width: 720px;
    border-radius: 18px;
    padding: 14px 16px;
    background: #f2f2ef;
    line-height: 1.55;
    white-space: pre-wrap;
    word-break: break-word;
}
.message-row.agent .message-card { background: #fff; border: 1px solid #ecece9; box-shadow: 0 8px 24px rgba(0,0,0,.04); }
.message-row.human .message-card { background: #111; color: white; }
.message-row.system .message-card { background: #fff8df; border: 1px solid #f3de9a; color: #5d4600; max-width: 100%; }
.message-meta {
    color: var(--muted);
    font-size: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
}
.message-row.human .message-meta { justify-content: flex-end; }

.continue-box {
    position: sticky;
    bottom: 0;
    width: min(820px, calc(100% - 36px));
    margin: -94px auto 14px;
    border: 1px solid var(--line);
    background: rgba(255,255,255,.95);
    backdrop-filter: blur(14px);
    border-radius: 18px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow);
}
.continue-box.hidden { display: none; }
#continueText { color: var(--muted); font-size: 14px; }

.composer {
    width: min(820px, calc(100% - 36px));
    margin: 0 auto 18px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: white;
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
}
.composer textarea {
    border: 0;
    box-shadow: none;
    resize: none;
    padding: 12px 4px;
    max-height: 160px;
}
.composer textarea:focus { box-shadow: none; }
.plus-btn {
    height: 38px;
    border: 0;
    background: transparent;
    font-size: 25px;
    color: var(--muted);
    cursor: pointer;
}
.send-btn { padding: 10px 14px; }
.hidden { display: none !important; }
.toast {
    position: fixed;
    right: 18px;
    bottom: 18px;
    background: #111;
    color: white;
    padding: 10px 12px;
    border-radius: 12px;
    box-shadow: var(--shadow);
    z-index: 20;
}

@media (max-width: 820px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .topbar { padding: 0 14px; }
    .start-panel { padding: 28px 14px 100px; }
    .start-card { padding: 22px; border-radius: 18px; }
    .messages, .composer, .continue-box { width: calc(100% - 24px); }
}

select {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 13px 14px;
    font: inherit;
    background: #fff;
    outline: none;
}
select:focus { border-color: #111; box-shadow: 0 0 0 3px rgba(0,0,0,.05); }

.sidebar-user {
    border-top: 1px solid var(--line);
    padding: 12px 8px 0;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr) auto;
    gap: 9px;
    align-items: center;
    position: relative;
}
.user-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #111;
    color: white;
    display: grid;
    place-items: center;
    font-weight: 800;
}
.user-copy { min-width: 0; }
.user-copy strong, .user-copy span {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-copy strong { font-size: 13px; }
.user-copy span { color: var(--muted); font-size: 11px; margin-top: 1px; }
.logout-link {
    color: var(--muted);
    text-decoration: none;
    font-size: 12px;
}
.logout-link:hover { color: var(--text); text-decoration: underline; }
.logout-top { text-decoration: none; color: var(--text); font-size: 13px; }
.user-actions {
    position: relative;
    display: grid;
    justify-items: end;
}
.settings-menu-btn {
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 10px;
    display: grid;
    place-items: center;
    background: #fff;
    color: var(--muted);
    cursor: pointer;
    transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.settings-menu-btn:hover,
.settings-menu-btn:focus-visible {
    background: #f7f7f4;
    color: var(--text);
    border-color: #d2d2cc;
    outline: none;
}
.settings-menu-btn svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}
.settings-menu {
    position: absolute;
    right: 0;
    bottom: 42px;
    min-width: 156px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 16px 40px rgba(0,0,0,.12);
    padding: 6px;
    display: grid;
    gap: 2px;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(6px);
    transition: opacity .14s ease, transform .14s ease, visibility .14s ease;
    z-index: 40;
}
.sidebar-user.settings-open .settings-menu {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0);
}
.settings-menu-item {
    display: flex;
    align-items: center;
    gap: 9px;
    border-radius: 9px;
    padding: 9px 10px;
    color: var(--text);
    text-decoration: none;
    font-size: 13px;
    font-weight: 650;
}
.settings-menu-item:hover,
.settings-menu-item:focus-visible {
    background: #f2f2ef;
    outline: none;
}
.settings-menu-item svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
    color: var(--muted);
    flex: 0 0 auto;
}
.human-online-pill {
    border: 1px solid #cfe8d8;
    background: #effaf3;
    color: var(--green);
    border-radius: 999px;
    padding: 7px 10px;
    font-size: 12px;
    font-weight: 750;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background: var(--bg);
}
.auth-card {
    width: min(460px, 100%);
    border: 1px solid var(--line);
    border-radius: 24px;
    background: white;
    box-shadow: var(--shadow);
    padding: 28px;
}
.auth-brand { padding: 0 0 18px; }
.auth-card h1 {
    margin: 0 0 8px;
    font-size: 32px;
    letter-spacing: -0.04em;
    line-height: 1.05;
}
.auth-card p {
    margin: 0 0 22px;
    color: var(--muted);
    line-height: 1.5;
}
.auth-note, .auth-error {
    border-radius: 14px;
    padding: 11px 12px;
    margin-bottom: 14px;
    font-size: 14px;
}
.auth-note { background: #eef7ff; border: 1px solid #cbe4ff; color: #183b65; }
.auth-error { background: #fff0ee; border: 1px solid #ffd2cc; color: var(--red); }
.auth-form { margin-top: 6px; }

@media (max-width: 820px) {
    .logout-top, .human-online-pill { display: none; }
}

.auth-success {
    border-radius: 14px;
    padding: 11px 12px;
    margin-bottom: 14px;
    font-size: 14px;
    background: #effaf3;
    border: 1px solid #cfe8d8;
    color: var(--green);
}
.account-card {
    width: min(560px, 100%);
}
.auth-links {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    margin-top: 18px;
    font-size: 14px;
}
.auth-links a {
    color: var(--text);
    text-decoration: none;
}
.auth-links a:hover { text-decoration: underline; }

.link-action { color: var(--text); text-decoration: none; display: block; }
.page-panel { grid-template-rows: 58px minmax(0, 1fr); }
.page-scroll { display: block; padding: 34px 24px 80px; }
.wide-card { width: min(980px, 100%); margin: 0 auto 18px; }
.two-col-form { grid-template-columns: 1fr 160px; }
.two-col-form .span-2 { grid-column: 1 / -1; }
.invite-result { margin-top: 22px; border: 1px solid var(--line); background: #fafafa; border-radius: 16px; padding: 18px; }
.invite-result h3 { margin: 0 0 12px; }
.info-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.info-grid.single-col { grid-template-columns: 1fr; }
.info-tile { border: 1px solid var(--line); border-radius: 16px; padding: 14px; background: #fafafa; display: grid; gap: 6px; }
.info-tile strong { font-size: 14px; }
.info-tile span { color: var(--muted); font-size: 13px; line-height: 1.45; }
.invite-list { display: grid; gap: 10px; }
.invite-row { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 14px; padding: 12px; background: #fafafa; }
.invite-row span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.invite-status { border-radius: 999px; padding: 5px 9px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.invite-status.open { background: #eef7f1; color: var(--green); }
.invite-status.used { background: #eeeef8; color: var(--blue); }
.invite-date { color: var(--muted); font-size: 12px; text-align: right; line-height: 1.45; }
.code-textarea { width: 100%; border: 1px solid var(--line); border-radius: 14px; padding: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.45; background: #fafafa; color: var(--text); resize: vertical; }
.onboarding-card { width: min(920px, calc(100% - 28px)); }
.onboarding-body { align-items: flex-start; padding: 32px 0; }
.hidden { display: none !important; }

@media (max-width: 760px) {
    .two-col-form { grid-template-columns: 1fr; }
    .info-grid { grid-template-columns: 1fr; }
    .invite-row { grid-template-columns: 1fr; }
    .invite-date { text-align: left; }
}

.copy-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}
.copy-line input {
    min-width: 0;
}
.copy-line button, .secondary-btn {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    color: var(--text);
    font-weight: 750;
    padding: 10px 12px;
    cursor: pointer;
}
.copy-line button:hover, .secondary-btn:hover { background: #f5f5f5; }
.secondary-btn { margin-top: 8px; }
.full-width { width: 100%; }
.primary-link {
    color: var(--text);
    font-weight: 800;
    text-decoration: none;
}
.primary-link:hover { text-decoration: underline; }

.exact-link-card {
    margin: 18px 0;
    padding: 18px;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    background: #fafafa;
}
.exact-link-title {
    margin: 12px 0 8px;
    font-weight: 800;
    color: #111827;
}
.exact-link-title:first-child {
    margin-top: 0;
}
.exact-link-url {
    margin: 0 0 10px;
    padding: 12px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #ffffff;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    font-size: 13px;
    color: #111827;
}
.hidden-copy-textarea {
    position: absolute;
    left: -9999px;
    top: auto;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.emoji-select-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
}
.emoji-select-line input {
    font-size: 24px;
    text-align: center;
    padding: 9px 12px;
    cursor: default;
}
.no-margin { margin-top: 0; }
.emoji-picker-panel {
    display: none;
    margin-top: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #fafafa;
    padding: 16px;
}
.emoji-picker-panel.open { display: block; }
.emoji-picker-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 320px);
    gap: 12px;
    align-items: end;
    margin-bottom: 12px;
}
.emoji-picker-header strong { display: block; font-size: 15px; }
.emoji-picker-header span { display: block; color: var(--muted); font-size: 13px; margin-top: 3px; }
.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
    gap: 8px;
    max-height: 360px;
    overflow: auto;
    padding-right: 4px;
}
.emoji-option {
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
    padding: 10px 8px;
    display: grid;
    gap: 5px;
    place-items: center;
    cursor: pointer;
    min-height: 78px;
}
.emoji-option:hover { background: #f2f2ef; }
.emoji-option.selected { border-color: #111; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.emoji-option span { font-size: 27px; line-height: 1; }
.emoji-option small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.15;
    text-align: center;
}
.emoji-empty {
    grid-column: 1 / -1;
    color: var(--muted);
    padding: 14px;
    text-align: center;
}

@media (max-width: 760px) {
    .emoji-picker-header { grid-template-columns: 1fr; }
    .emoji-select-line { grid-template-columns: 1fr; }
}

/* v9: emoji picker as click-to-open dropdown from Emoji signature field */
.emoji-field-wrap {
    position: relative;
}
.emoji-field-wrap #inviteEmoji {
    font-size: 26px;
    text-align: center;
    padding: 10px 12px;
    cursor: pointer;
    background: #fff;
}
.emoji-dropdown-panel {
    position: absolute;
    z-index: 40;
    left: 0;
    right: 0;
    top: calc(100% + 8px);
    margin-top: 0;
    box-shadow: 0 22px 60px rgba(0,0,0,.14);
    max-width: min(720px, calc(100vw - 48px));
}
.emoji-dropdown-panel .emoji-grid {
    max-height: 290px;
    overscroll-behavior: contain;
}
.emoji-dropdown-panel .emoji-option {
    min-height: 68px;
}
.emoji-dropdown-panel .emoji-picker-header {
    grid-template-columns: 1fr;
}

/* v9: account page inside the same HQ layout */
.account-settings-card {
    max-width: 860px;
}
.account-form-grid {
    margin-top: 18px;
}
.account-form-grid .primary-btn.span-2 {
    grid-column: 1 / -1;
}

/* v9: live agent profiles */
.agents-profile-shell {
    min-height: 0;
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    background: var(--panel);
}
.agent-directory-panel {
    border-right: 1px solid var(--line);
    background: #fafaf8;
    padding: 18px 12px;
    overflow-y: auto;
}
.agent-directory-list {
    display: grid;
    gap: 8px;
}
.agent-list-button {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fff;
    padding: 11px;
    display: grid;
    grid-template-columns: 34px minmax(0, 1fr);
    gap: 10px;
    text-align: left;
    cursor: pointer;
}
.agent-list-button:hover { background: #f2f2ef; }
.agent-list-button.active { border-color: #111; box-shadow: 0 0 0 3px rgba(0,0,0,.06); }
.agent-list-emoji {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    background: #f0f0ed;
    display: grid;
    place-items: center;
    font-size: 20px;
}
.agent-list-copy { min-width: 0; }
.agent-list-copy strong,
.agent-list-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-list-copy strong { font-size: 14px; }
.agent-list-copy small { color: var(--muted); margin-top: 2px; font-size: 12px; }
.agent-list-button .presence-pill.mini {
    grid-column: 1 / -1;
    justify-self: start;
    font-size: 12px;
    padding: 5px 8px;
}
.agent-empty {
    color: var(--muted);
    border: 1px dashed var(--line);
    border-radius: 16px;
    padding: 16px;
    background: #fff;
    font-size: 14px;
}
.agent-profile-panel {
    min-width: 0;
    overflow-y: auto;
    padding: 26px;
}
.agent-profile-content {
    width: min(1180px, 100%);
    margin: 0 auto;
}
.agent-profile-header {
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 22px;
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    margin-bottom: 18px;
}
.agent-profile-avatar {
    width: 64px;
    height: 64px;
    border-radius: 22px;
    background: #f0f0ed;
    display: grid;
    place-items: center;
    font-size: 34px;
}
.agent-profile-header h1 {
    margin: 5px 0 3px;
    font-size: clamp(28px, 4vw, 44px);
    letter-spacing: -0.04em;
    line-height: 1.05;
}
.agent-profile-header p {
    margin: 0;
    color: var(--muted);
}
.agent-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 18px;
}
.agent-md-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}
.agent-md-card {
    width: 100%;
    margin: 0;
    padding: 18px;
    box-shadow: none;
}
.agent-md-card .code-textarea {
    min-height: 520px;
}

@media (max-width: 1050px) {
    .agents-profile-shell { grid-template-columns: 1fr; }
    .agent-directory-panel { border-right: 0; border-bottom: 1px solid var(--line); max-height: 260px; }
    .agent-stats-grid { grid-template-columns: 1fr 1fr; }
    .agent-md-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .agent-profile-header { grid-template-columns: 1fr; }
    .agent-stats-grid { grid-template-columns: 1fr; }
    .agent-profile-panel { padding: 16px; }
    .emoji-dropdown-panel { max-width: calc(100vw - 28px); }
}

/* v10: unified sidebar behavior */
.app-shell, .sidebar, .main-panel {
    transition: grid-template-columns .18s ease, width .18s ease, opacity .18s ease, transform .18s ease;
}
.sidebar-toggle-btn {
    position: fixed;
    top: 12px;
    left: 302px;
    z-index: 1000;
    width: 30px;
    height: 30px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: rgba(255,255,255,.9);
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.06);
    backdrop-filter: blur(8px);
}
.sidebar-toggle-btn:hover { background: #f6f6f3; }
.sidebar-toggle-btn span { font-size: 16px; line-height: 1; }
body.sidebar-collapsed .app-shell { grid-template-columns: 0 minmax(0, 1fr); }
body.sidebar-collapsed .sidebar {
    width: 0;
    min-width: 0;
    padding-left: 0;
    padding-right: 0;
    border-right: 0;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}
body.sidebar-collapsed .sidebar-toggle-btn { left: 12px; }
body.sidebar-collapsed .topbar { padding-left: 54px; }

.agents-memory-page {
    min-height: 0;
    overflow: auto;
    background: var(--panel);
    padding: 24px;
}
.agents-memory-layout {
    width: min(1320px, 100%);
    margin: 0 auto;
    display: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}
.agents-card {
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #fff;
    box-shadow: var(--shadow);
}
.agent-directory-card {
    position: sticky;
    top: 0;
    padding: 16px;
    max-height: calc(100vh - 110px);
    overflow: auto;
}
.directory-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}
.directory-header h2 {
    margin: 5px 0 0;
    font-size: 26px;
    line-height: 1.1;
    letter-spacing: -0.04em;
}
.small-link-btn {
    border: 1px solid var(--line);
    background: #fafafa;
    color: var(--text);
    text-decoration: none;
    border-radius: 12px;
    padding: 8px 10px;
    font-size: 13px;
    font-weight: 750;
    white-space: nowrap;
}
.small-link-btn:hover { background: #f1f1ee; }
.unified-agent-panel {
    padding: 0;
    overflow: visible;
}
.agent-profile-content {
    width: 100%;
    margin: 0;
}
.unified-profile-header {
    margin: 0 0 16px;
    box-shadow: var(--shadow);
}
.profile-title-block { min-width: 0; }
.unified-stats-grid {
    margin-bottom: 16px;
}
.unified-stats-grid .info-tile {
    min-width: 0;
    box-shadow: none;
}
.unified-stats-grid .info-tile strong,
.unified-stats-grid .info-tile span {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}
.memory-rule-card {
    padding: 18px;
    margin-bottom: 16px;
    box-shadow: none;
    background: #fbfbfa;
}
.memory-rule-card p {
    color: #595959;
    line-height: 1.55;
    margin: 8px 0 0;
}
.unified-md-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}
.unified-md-grid .agent-md-card {
    padding: 18px;
    min-width: 0;
}
.md-card-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}
.md-card-head span {
    color: var(--muted);
    font-size: 12px;
    overflow-wrap: anywhere;
    text-align: right;
}
.agent-md-card .code-textarea {
    min-height: 560px;
    resize: vertical;
    white-space: pre;
    overflow: auto;
}
.empty-profile-card {
    padding: 30px;
}
.empty-profile-card h1 {
    margin: 8px 0;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.empty-profile-card p {
    color: var(--muted);
    line-height: 1.55;
}

@media (max-width: 1050px) {
    .agents-memory-layout { grid-template-columns: 1fr; }
    .agent-directory-card {
        position: static;
        max-height: none;
    }
    .agent-directory-list {
        grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    }
    .unified-md-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
    .sidebar-toggle-btn { left: 12px; }
    body:not(.sidebar-collapsed) .sidebar-toggle-btn { left: 12px; }
    body.sidebar-collapsed .topbar,
    .topbar { padding-left: 54px; }
    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: 292px;
        z-index: 900;
        box-shadow: 12px 0 40px rgba(0,0,0,.12);
    }
    body.sidebar-collapsed .sidebar { transform: translateX(-100%); width: 292px; opacity: 0; }
    body:not(.sidebar-collapsed) .sidebar { display: flex; }
    .agents-memory-page { padding: 16px; }
}
@media (max-width: 640px) {
    .agent-profile-header.unified-profile-header { grid-template-columns: 1fr; }
    .agent-profile-avatar { width: 58px; height: 58px; border-radius: 18px; }
    .md-card-head { display: block; }
    .md-card-head span { display: block; margin-top: 4px; text-align: left; }
}

/* v11: fixed Agents page — one consistent two-pane layout */
.no-pad { padding: 0; }
.agents-workspace {
    min-height: 0;
    height: calc(100vh - 58px);
    display: grid;
    grid-template-columns: 318px minmax(0, 1fr);
    background: var(--panel);
    overflow: hidden;
}
.agent-rail {
    min-width: 0;
    border-right: 1px solid var(--line);
    background: #fafaf8;
    padding: 18px 12px;
    overflow-y: auto;
}
.agent-rail-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 0 2px 14px;
}
.agent-rail-head h2 {
    margin: 4px 0 0;
    font-size: 24px;
    letter-spacing: -0.035em;
    line-height: 1.1;
}
.agent-rail-list {
    display: grid;
    gap: 7px;
}
.agent-row-button {
    width: 100%;
    border: 1px solid transparent;
    border-radius: 14px;
    background: transparent;
    color: var(--text);
    padding: 10px;
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    text-align: left;
    cursor: pointer;
}
.agent-row-button:hover { background: #eeeeeb; }
.agent-row-button.active {
    border-color: var(--line);
    background: #fff;
    box-shadow: 0 8px 24px rgba(0,0,0,.06);
}
.agent-row-avatar {
    width: 38px;
    height: 38px;
    border-radius: 13px;
    background: #f0f0ed;
    display: grid;
    place-items: center;
    font-size: 22px;
}
.agent-row-copy { min-width: 0; }
.agent-row-copy strong,
.agent-row-copy small {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.agent-row-copy strong { font-size: 14px; line-height: 1.2; }
.agent-row-copy small { margin-top: 2px; color: var(--muted); font-size: 12px; }
.agent-row-status {
    justify-self: end;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}
.agent-detail-pane {
    min-width: 0;
    overflow-y: auto;
    background: #fff;
}
.agent-detail-inner {
    width: min(1120px, calc(100% - 48px));
    margin: 0 auto;
    padding: 28px 0 42px;
}
.agent-profile-masthead {
    display: grid;
    grid-template-columns: 72px minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 20px;
}
.agent-profile-avatar-big {
    width: 72px;
    height: 72px;
    border-radius: 22px;
    background: #f0f0ed;
    display: grid;
    place-items: center;
    font-size: 38px;
}
.agent-profile-title { min-width: 0; }
.agent-profile-title h1 {
    margin: 5px 0 3px;
    font-size: clamp(30px, 4vw, 46px);
    line-height: 1.03;
    letter-spacing: -0.045em;
}
.agent-profile-title p {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
}
.profile-tabs {
    display: flex;
    gap: 6px;
    margin: 16px 0;
    border-bottom: 1px solid var(--line);
}
.profile-tab {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 12px 14px;
    font: inherit;
    font-size: 14px;
    cursor: pointer;
    border-bottom: 2px solid transparent;
}
.profile-tab:hover { color: var(--text); background: #fafaf8; }
.profile-tab.active {
    color: var(--text);
    border-bottom-color: var(--accent);
    font-weight: 750;
}
.profile-tab-body { min-width: 0; }
.agent-doc-card,
.agent-rule-card,
.agent-empty-state {
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #fff;
    box-shadow: var(--shadow);
    padding: 20px;
}
.doc-card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 14px;
    margin-bottom: 12px;
}
.doc-card-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 13px;
}
.doc-card-head code {
    background: #f2f2ef;
    padding: 2px 5px;
    border-radius: 6px;
}
.doc-badge {
    border: 1px solid var(--line);
    border-radius: 999px;
    color: var(--muted);
    background: #fafaf8;
    padding: 6px 9px;
    font-size: 12px;
    white-space: nowrap;
}
.agent-md-view {
    width: 100%;
    min-height: 560px;
    max-height: calc(100vh - 275px);
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: #fbfbfa;
    padding: 16px;
    font: 13px/1.55 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}
.profile-info-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.profile-info-grid .info-tile {
    min-width: 0;
    box-shadow: none;
}
.profile-info-grid .info-tile strong,
.profile-info-grid .info-tile span {
    display: block;
    min-width: 0;
    overflow-wrap: anywhere;
}
.agent-rule-card {
    box-shadow: none;
    background: #fbfbfa;
}
.agent-rule-card p {
    color: #595959;
    line-height: 1.55;
    margin: 8px 0 0;
}
.agent-empty-state {
    margin-top: 28px;
    width: min(760px, 100%);
}
.agent-empty-state h1 {
    margin: 8px 0;
    font-size: clamp(30px, 4vw, 48px);
    line-height: 1.05;
    letter-spacing: -0.04em;
}
.agent-empty-state p {
    color: var(--muted);
    line-height: 1.55;
}
@media (max-width: 1050px) {
    .agents-workspace { grid-template-columns: 270px minmax(0, 1fr); }
    .profile-info-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
    .agents-workspace {
        grid-template-columns: 1fr;
        height: auto;
        min-height: calc(100vh - 58px);
        overflow: visible;
    }
    .agent-rail {
        border-right: 0;
        border-bottom: 1px solid var(--line);
        max-height: 260px;
    }
    .agent-detail-inner { width: calc(100% - 28px); padding: 18px 0 34px; }
    .agent-md-view { min-height: 420px; max-height: none; }
}
@media (max-width: 640px) {
    .agent-profile-masthead { grid-template-columns: 1fr; }
    .agent-profile-avatar-big { width: 62px; height: 62px; border-radius: 18px; }
    .profile-info-grid { grid-template-columns: 1fr; }
    .doc-card-head { display: block; }
    .doc-badge { display: inline-flex; margin-top: 10px; }
}

/* v13: fix sidebar toggle alignment and ChatGPT-like message styling */
.sidebar-toggle-btn {
    top: 12px !important;
    left: 258px !important;
    width: 28px !important;
    height: 28px !important;
    border-radius: 8px !important;
    box-shadow: 0 3px 12px rgba(0,0,0,.05) !important;
}
body.sidebar-collapsed .sidebar-toggle-btn { left: 12px !important; }
body.sidebar-collapsed .topbar { padding-left: 58px !important; }

.messages {
    width: min(880px, calc(100% - 40px));
    gap: 28px;
}
.message-row.agent {
    justify-items: start;
}
.message-row.agent .message-card {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
    max-width: 760px;
    color: var(--text);
}
.message-row.human .message-card {
    background: #f3f3f1 !important;
    color: var(--text) !important;
    border: 0 !important;
    box-shadow: none !important;
    border-radius: 14px !important;
    padding: 12px 15px !important;
    max-width: 520px;
}
.message-row.human .message-meta {
    justify-content: flex-end;
}
.message-row.agent .message-meta {
    color: #6f6f6f;
    padding-left: 0;
}
.presence-pill.status-offline {
    opacity: .72;
}
.presence-pill.status-idle,
.presence-pill.status-queued,
.presence-pill.status-thinking,
.presence-pill.status-responding {
    opacity: 1;
}

@media (max-width: 820px) {
    .sidebar-toggle-btn { left: 12px !important; }
}

/* v14: Recents room actions */
.recent-row {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 30px;
    align-items: center;
    gap: 2px;
}
.recent-row .recent-link {
    min-width: 0;
    padding-right: 6px;
}
.recent-row .recent-menu-btn {
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    font-weight: 800;
    line-height: 1;
    display: grid;
    place-items: center;
    padding: 0;
}
.recent-row .recent-menu-btn svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}
.recent-row:hover .recent-menu-btn,
.recent-row.menu-open .recent-menu-btn {
    background: #e8e8e4;
    color: var(--text);
}
.recent-menu {
    display: none;
    position: absolute;
    right: 0;
    bottom: calc(100% + 4px);
    z-index: 1200;
    min-width: 146px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 12px 32px rgba(0,0,0,.12);
    padding: 5px;
}
.recent-row.menu-open .recent-menu {
    display: block;
}
.recent-menu-item {
    width: 100%;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    padding: 8px 9px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 8px;
}
.recent-menu-item svg {
    width: 15px;
    height: 15px;
    fill: currentColor;
    flex: 0 0 auto;
}
.recent-menu-item:hover {
    background: #f2f2ef;
}
.recent-menu-item.danger {
    color: var(--red);
}

/* ── v19: Live thinking indicator in messages area ─────── */
.thinking-row {
    display: grid;
    justify-items: start;
    padding: 10px 0;
}
.thinking-bubble {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #fafafa;
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 12px 16px;
    font-size: 13px;
    color: var(--muted);
    animation: fadeInSlide .25s ease-out;
}
.thinking-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}
.thinking-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--muted);
    animation: thinkBounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(1) { animation-delay: 0s; }
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes thinkBounce {
    0%, 80%, 100% { transform: scale(.6); opacity: .4; }
    40% { transform: scale(1.15); opacity: 1; }
}
@keyframes fadeInSlide {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ── v19: status-online pill ────────────────────────────── */
.status-online .status-dot { background: var(--green); }
.human-online-pill .status-dot { display: none; }

/* v20: BusyLight-style live presence colors */
.presence-pill,
.agent-row-status {
    --presence-color: #8b8b8b;
    --presence-bg: #f4f4f2;
    --presence-border: #deded9;
    border-color: var(--presence-border) !important;
    background: var(--presence-bg) !important;
    color: #202020 !important;
}
.presence-pill .status-dot,
.agent-row-status .status-dot {
    width: 14px;
    height: 14px;
    background: var(--presence-color) !important;
    box-shadow: 0 0 0 3px rgba(255,255,255,.85), 0 1px 5px rgba(0,0,0,.15);
    flex: 0 0 auto;
}
.presence-pill strong {
    color: #202020;
    font-weight: 800;
}
.status-available {
    --presence-color: #5caf4f;
    --presence-bg: #eef7ed;
    --presence-border: #cfe9ca;
}
.status-incoming-call,
.status-on-call,
.status-queued,
.status-thinking,
.status-responding {
    --presence-color: #28a6d1;
    --presence-bg: #eaf6fb;
    --presence-border: #c4e7f3;
}
.status-away,
.status-offline {
    --presence-color: #f4c63d;
    --presence-bg: #fff8df;
    --presence-border: #f1df9a;
}
.status-busy {
    --presence-color: #e53142;
    --presence-bg: #fff0f1;
    --presence-border: #f4c4ca;
}
.status-do-not-disturb,
.status-blocked {
    --presence-color: #e53142;
    --presence-bg: #fff0f1;
    --presence-border: #f4c4ca;
}
.status-thinking .status-dot,
.status-responding .status-dot,
.status-on-call .status-dot,
.status-incoming-call .status-dot {
    animation: pulse 1s ease-in-out infinite;
}
