:root {
    --bg: #ffffff;
    --bg-muted: #f7f7f8;
    --bg-user-row: #f7f7f8;
    --bg-user-bubble: #f4f4f4;
    --border: #ececf1;
    --border-input: #d9d9e3;
    --text: #0d0d0d;
    --text-muted: #6e6e80;
    --accent: #10a37f;
    --accent-hover: #0d8f6f;
    --content-width: 48rem;
    --header-h: 3.25rem;
    --shadow-input: 0 0 0 1px rgba(0, 0, 0, 0.04), 0 4px 24px rgba(0, 0, 0, 0.08);
    --sidebar-w: 17rem;
    --whatsapp: #25d366;
    --touch-min: 2.75rem;
    --keyboard-offset: 0px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

[data-theme="dark"] {
    --bg: #212121;
    --bg-muted: #2f2f2f;
    --bg-user-row: #2a2a2a;
    --bg-user-bubble: #303030;
    --border: #3d3d3d;
    --border-input: #4a4a4a;
    --text: #ececec;
    --text-muted: #a0a0a0;
    --shadow-input: 0 0 0 1px rgba(255, 255, 255, 0.06), 0 4px 24px rgba(0, 0, 0, 0.35);
    color-scheme: dark;
}

[data-theme="dark"] .session-banner {
    background: #422006;
    color: #fde68a;
    border-bottom-color: #78350f;
}

[data-theme="dark"] .send-btn {
    background: #ececec;
    color: #212121;
}

[data-theme="dark"] .send-btn:hover:not(:disabled) {
    background: #ffffff;
}

[data-theme="dark"] .composer-area {
    background: linear-gradient(180deg, rgba(33, 33, 33, 0) 0%, var(--bg) 28%);
}

#theme-toggle-btn .icon-sun,
#theme-toggle-btn .icon-moon {
    display: block;
}

* {
    box-sizing: border-box;
}

.hidden {
    display: none !important;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

body {
    margin: 0;
    font-family: "Söhne", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, Cantarell, "Noto Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

.app-layout {
    display: flex;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.app-shell {
    flex: 1;
    min-width: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* —— Header (ChatGPT-style thin bar) —— */
.chat-header {
    flex-shrink: 0;
    min-height: calc(var(--header-h) + var(--safe-top));
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: var(--safe-top) calc(0.75rem + var(--safe-right)) 0 calc(0.75rem + var(--safe-left));
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    z-index: 20;
}

.header-side {
    display: flex;
    align-items: center;
    min-width: 0;
}

.header-side-right {
    justify-content: flex-end;
    gap: 0.35rem;
    position: relative;
}

.header-toolbar-desktop {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.header-toolbar-mobile {
    display: none;
}

.header-menu {
    position: absolute;
    top: calc(var(--header-h) + var(--safe-top) - 0.25rem);
    right: calc(0.75rem + var(--safe-right));
    z-index: 40;
    min-width: 11rem;
    padding: 0.65rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-input);
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
}

.header-menu-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
}

.header-menu-action {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: var(--touch-min);
    padding: 0.5rem 0.65rem;
    border: 1px solid var(--border);
    border-radius: 0.55rem;
    background: var(--bg-muted);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    text-align: left;
}

.header-menu-action:hover {
    background: var(--bg);
    border-color: var(--border-input);
}

.header-menu-link {
    text-decoration: none;
    box-sizing: border-box;
}

.toolbar-select--full {
    max-width: none;
    width: 100%;
}

.toast {
    position: fixed;
    bottom: calc(5.5rem + var(--safe-bottom) + var(--keyboard-offset));
    left: calc(50% + (var(--safe-left) - var(--safe-right)) / 2);
    transform: translateX(-50%);
    z-index: 60;
    background: var(--text);
    color: var(--bg);
    padding: 0.55rem 1rem;
    border-radius: 9999px;
    font-size: 0.82rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
    max-width: min(90vw, calc(22rem - var(--safe-left) - var(--safe-right)));
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.toast.visible {
    opacity: 1;
}

.composer-hint a {
    color: var(--text-muted);
    text-decoration: none;
}

.composer-hint a:hover {
    color: var(--accent);
    text-decoration: underline;
}

.chat-input-bar.dob-fallback .chat-input-shell {
    opacity: 0.72;
}

.chat-input-bar.dob-fallback .chat-input {
    font-size: 0.82rem;
}

.topic-browser-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 0.2rem;
}

body.modal-open {
    overflow: hidden;
}

body.sidebar-open-mobile {
    overflow: hidden;
}

.app-layout.sidebar-collapsed .client-sidebar {
    display: none;
}

.sidebar-close-mobile {
    display: none;
}

@media (max-width: 900px) {
    .sidebar-close-mobile {
        display: grid;
    }
}

.header-side-left {
    gap: 0.25rem;
}

.header-home-btn {
    text-decoration: none;
}

.icon-btn {
    width: 2rem;
    height: 2rem;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    background: transparent;
    color: var(--text);
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg-muted);
    border-color: var(--border);
}

/* —— Client sidebar —— */
.client-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-muted);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 30;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0.85rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.sidebar-title {
    margin: 0;
    font-size: 0.88rem;
    font-weight: 600;
}

.client-list {
    list-style: none;
    margin: 0;
    padding: 0.5rem;
    overflow-y: auto;
    flex: 1;
}

.client-item {
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--bg);
    margin-bottom: 0.45rem;
    overflow: hidden;
}

.client-item-row {
    display: flex;
    align-items: stretch;
    gap: 0;
}

.client-item-btn {
    flex: 1;
    min-width: 0;
    text-align: left;
    border: none;
    background: transparent;
    padding: 0.75rem 0.65rem;
    cursor: pointer;
    color: var(--text);
    min-height: var(--touch-min);
}

.client-item-btn:hover {
    background: var(--bg-muted);
}

.client-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    display: block;
}

.client-item-dob {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
    display: block;
}

.client-note-wrap {
    padding: 0 0.55rem 0.55rem;
    border-top: 1px solid var(--border);
}

.client-note-input {
    width: 100%;
    border: 1px solid var(--border-input);
    border-radius: 0.45rem;
    padding: 0.35rem 0.45rem;
    font-size: 0.72rem;
    background: var(--bg-muted);
    color: var(--text);
    resize: vertical;
    min-height: 2.25rem;
}

.client-note-save {
    margin-top: 0.3rem;
    font-size: 0.7rem;
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
}

.clients-empty {
    padding: 1rem 0.85rem;
    font-size: 0.8rem;
    color: var(--text-muted);
    line-height: 1.45;
    margin: 0;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 25;
}

.sidebar-overlay.visible {
    display: block;
}

body.sidebar-open-mobile .client-sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left);
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

/* —— Modal —— */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.modal-panel {
    position: relative;
    width: min(100%, 22rem);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
}

.modal-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-muted);
}

.form-input {
    border: 1px solid var(--border-input);
    border-radius: 0.55rem;
    padding: 0.5rem 0.6rem;
    font-size: 0.9rem;
    background: var(--bg-muted);
    color: var(--text);
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.header-center {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.brand-mark {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.35rem;
    background: var(--accent);
    color: #fff;
    display: grid;
    place-items: center;
    font-size: 0.8rem;
    font-weight: 700;
}

.brand-title {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.toolbar-item {
    display: block;
}

.toolbar-select {
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 0.35rem 0.5rem;
    background: var(--bg);
    color: var(--text);
    font-size: 0.78rem;
    cursor: pointer;
    max-width: 6.5rem;
}

.toolbar-select:hover {
    background: var(--bg-muted);
}

.session-banner {
    flex-shrink: 0;
    background: #fffbeb;
    color: #92400e;
    padding: 0.55rem calc(1rem + var(--safe-right)) 0.55rem calc(1rem + var(--safe-left));
    font-size: 0.82rem;
    border-bottom: 1px solid #fde68a;
    text-align: center;
    line-height: 1.45;
}

.session-banner.hidden {
    display: none;
}

.profile-snapshot {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.55rem calc(1rem + var(--safe-right)) 0.55rem calc(1rem + var(--safe-left));
    background: var(--bg-muted);
    border-bottom: 1px solid var(--border);
    cursor: pointer;
}

.profile-snapshot.hidden {
    display: none;
}

.profile-snapshot-main {
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.profile-snapshot-name {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-snapshot-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-snapshot-hint {
    flex-shrink: 0;
    font-size: 0.72rem;
    color: var(--accent);
    font-weight: 500;
}

.onboard-sheet-body {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.onboard-slide-title {
    margin: 0 0 0.5rem;
    font-size: 1rem;
    font-weight: 600;
}

.onboard-slide-body {
    margin: 0;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.onboard-dots {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
}

.onboard-dot {
    width: 0.45rem;
    height: 0.45rem;
    border-radius: 50%;
    background: var(--border);
}

.onboard-dot--active {
    background: var(--accent);
}

.onboard-skip-wrap {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.client-compare-btn {
    font-size: 0.72rem;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--accent);
    cursor: pointer;
}

.client-compare-btn--active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* —— Messages (full-width rows like ChatGPT) —— */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

.message-row {
    width: 100%;
    padding: 1.25rem 1rem;
    animation: fade-in 0.25s ease;
}

@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-row-bot {
    background: var(--bg);
    border-bottom: 1px solid transparent;
}

.message-row-user {
    background: var(--bg-user-row);
}

.message-row-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    display: flex;
    gap: 1rem;
    align-items: flex-start;
}

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

.avatar {
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 0.35rem;
    flex-shrink: 0;
    display: grid;
    place-items: center;
    font-size: 0.72rem;
    font-weight: 700;
    margin-top: 0.1rem;
}

.avatar-bot {
    background: var(--accent);
    color: #fff;
}

.message {
    flex: 1;
    min-width: 0;
    line-height: 1.65;
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 0.95rem;
    color: var(--text);
}

.message-bot {
    padding: 0;
    background: transparent;
}

.message-content-wrap {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-copy-btn {
    position: static;
    margin-top: 0.35rem;
    width: 1.65rem;
    height: 1.65rem;
    border: 1px solid var(--border);
    border-radius: 0.4rem;
    background: var(--bg);
    color: var(--text-muted);
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.15s;
    display: grid;
    place-items: center;
    padding: 0;
}

.message-row-bot:hover .message-copy-btn,
.message-row-bot:focus-within .message-copy-btn {
    opacity: 1;
}

@media (hover: none) {
    .message-copy-btn {
        opacity: 1;
    }
}

.message-copy-btn:hover {
    color: var(--text);
    background: var(--bg-muted);
}

.message-actions {
    display: flex;
    gap: 0.35rem;
    margin-top: 0.35rem;
    flex-wrap: wrap;
}

.message-action-btn {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 999px;
    padding: 0.2rem 0.55rem;
    font-size: 0.72rem;
    cursor: pointer;
}

.message-action-btn:hover {
    color: var(--text);
    background: var(--bg-muted);
}

.message-md h3 {
    margin: 0.85rem 0 0.35rem;
    font-size: 0.92rem;
    font-weight: 600;
}

.message-md h3:first-child {
    margin-top: 0;
}

.message-md ul {
    margin: 0.35rem 0;
    padding-left: 1.25rem;
}

.message-md li {
    margin: 0.2rem 0;
}

.message-md strong {
    font-weight: 600;
}

.message-md p {
    margin: 0.35rem 0;
}

.message-md p:first-child {
    margin-top: 0;
}

.message-md {
    white-space: normal;
}

.lo-shu-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(3.5rem, 1fr));
    gap: 0.35rem;
    max-width: 14rem;
    margin: 0.75rem 0 0.5rem;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--bg-muted);
}

.lo-shu-cell {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 3.25rem;
    border-radius: 0.45rem;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.lo-shu-num {
    font-size: 1.35rem;
    font-weight: 600;
    line-height: 1;
}

.lo-shu-dot {
    display: block;
    width: 0.4rem;
    height: 0.4rem;
    margin-top: 0.2rem;
    border-radius: 50%;
    background: var(--accent);
}

.lo-shu-count {
    margin-top: 0.15rem;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1;
    color: var(--accent);
}

.lo-shu-cell.lo-shu-present {
    color: var(--text);
    border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
    background: color-mix(in srgb, var(--accent) 10%, var(--bg));
}

.lo-shu-cell.lo-shu-strong {
    border-color: var(--accent);
    background: color-mix(in srgb, var(--accent) 18%, var(--bg));
    box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent);
}

.lo-shu-cell.lo-shu-missing .lo-shu-num {
    opacity: 0.45;
}

.lo-shu-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    margin-top: 0.45rem;
    font-size: 0.68rem;
    color: var(--text-muted);
}

.lo-shu-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
}

.lo-shu-legend-missing {
    opacity: 0.45;
    font-weight: 600;
}

.summary-card {
    margin: 0.5rem 0 0.75rem;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 0.65rem;
    background: var(--bg-muted);
}

.summary-card-title {
    font-size: 0.78rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.summary-card-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.summary-card-item {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.summary-card-item--wide {
    grid-column: 1 / -1;
}

.summary-card-label {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.summary-card-value {
    font-size: 0.95rem;
    font-weight: 600;
}

.family-lo-shu-member {
    margin: 0.5rem 0 0.75rem;
}

.family-lo-shu-name {
    font-size: 0.82rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.share-card-grid {
    margin: 0.75rem 0;
}

.share-card-grid .lo-shu-grid,
.share-card-grid .summary-card {
    max-width: 100%;
}

.session-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 0.75rem;
}

.session-banner-actions {
    display: flex;
    gap: 0.35rem;
}

.session-banner-btn {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    border-radius: 999px;
    padding: 0.25rem 0.65rem;
    font-size: 0.75rem;
    cursor: pointer;
}

.session-banner-btn--ghost {
    background: transparent;
}

.client-delete-btn {
    display: none;
}

.client-delete-icon-btn {
    flex-shrink: 0;
    align-self: center;
    margin-right: 0.35rem;
    color: var(--text-muted);
}

.client-delete-icon-btn:hover {
    color: #dc2626;
    background: rgba(220, 38, 38, 0.08);
    border-color: rgba(220, 38, 38, 0.25);
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    z-index: 1000;
    padding: 0.5rem 1rem;
    background: var(--accent);
    color: #fff;
    border-radius: 0.25rem;
}

.skip-link:focus {
    left: calc(0.5rem + var(--safe-left));
    top: calc(0.5rem + var(--safe-top));
}

.icon-btn:focus-visible,
.quick-reply-btn:focus-visible,
.share-action-btn:focus-visible,
.session-banner-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .typing-dots span,
    .message-row {
        animation: none !important;
    }
}

.message-user {
    flex: 0 1 auto;
    max-width: min(85%, 28rem);
    background: var(--bg-user-bubble);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 0.65rem 1rem;
}

.message-loading {
    padding: 0.25rem 0 !important;
    min-width: 2.5rem;
}

.message-skeleton {
    min-height: 0.75rem;
    border-radius: 0.4rem;
    background: linear-gradient(90deg, var(--bg-muted) 0%, color-mix(in srgb, var(--bg-muted) 45%, #fff) 50%, var(--bg-muted) 100%);
    background-size: 220% 100%;
    animation: skeleton-shimmer 1.15s linear infinite;
}

@keyframes skeleton-shimmer {
    0% { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

.typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    height: 1.25rem;
}

.typing-dots span {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-3px); opacity: 1; }
}

/* —— Composer (Gemini / ChatGPT bottom dock) —— */
.composer-area {
    flex-shrink: 0;
    padding: 0.75rem calc(1rem + var(--safe-right)) calc(0.85rem + var(--safe-bottom)) calc(1rem + var(--safe-left));
    background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, var(--bg) 28%);
    border-top: 1px solid var(--border);
}

.composer-inner {
    max-width: var(--content-width);
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.composer-hint {
    margin: 0.45rem 0 0;
    text-align: center;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.composer-disclaimer {
    margin: 0.35rem 0 0;
    padding: 0 0.5rem;
    text-align: center;
    font-size: 0.68rem;
    line-height: 1.45;
    color: var(--text-muted);
    opacity: 0.92;
}

.disclaimer-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
}

.composer-disclaimer--collapsed {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.composer-disclaimer--expanded {
    display: block;
    -webkit-line-clamp: unset;
    overflow: visible;
}

.disclaimer-toggle {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 0.68rem;
    text-decoration: underline;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    min-height: var(--touch-min);
}

.disclaimer-toggle:hover {
    color: var(--text);
}

.share-open-btn {
    display: none;
    width: 100%;
    min-height: var(--touch-min);
    border: 1px solid var(--accent);
    border-radius: 0.75rem;
    background: color-mix(in srgb, var(--accent) 10%, var(--bg));
    color: var(--accent);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    padding: 0.55rem 1rem;
}

.share-open-btn:hover:not(:disabled) {
    background: color-mix(in srgb, var(--accent) 18%, var(--bg));
}

.share-open-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.topic-browser-link--button {
    width: 100%;
    min-height: var(--touch-min);
    padding: 0.55rem 1rem;
    border: 1px solid var(--border-input);
    border-radius: 0.75rem;
    background: var(--bg-muted);
    color: var(--text);
    font-size: 0.84rem;
    font-weight: 500;
    text-decoration: none;
    text-align: center;
}

.topic-browser-link--button:hover {
    background: var(--bg);
    color: var(--text);
}

.quick-replies--stacked {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
    overflow-x: visible;
    overflow-y: visible;
    padding-bottom: 0;
}

.quick-replies--stacked::after {
    display: none;
}

.quick-replies--stacked .quick-reply-btn {
    flex-shrink: 1;
    width: 100%;
    max-width: none;
    white-space: normal;
    text-align: left;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
}

.quick-tools {
    display: flex;
    gap: 0.4rem;
    flex-wrap: wrap;
}

.quick-tool-btn {
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    border-radius: 999px;
    font-size: 0.72rem;
    padding: 0.2rem 0.65rem;
    cursor: pointer;
}

.quick-tool-btn:hover {
    color: var(--text);
    background: var(--bg-muted);
}

.recent-intents {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    scrollbar-width: none;
}

.recent-intents::-webkit-scrollbar {
    display: none;
}

.recent-intent-btn {
    flex-shrink: 0;
    border: 1px dashed var(--border-input);
    border-radius: 999px;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.72rem;
    padding: 0.2rem 0.6rem;
    cursor: pointer;
}

.pdf-export-status {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-align: center;
}

.pdf-export-status--error {
    color: #dc2626;
}

.retry-row {
    margin-top: 0.4rem;
}

.retry-btn {
    border: 1px solid var(--border-input);
    background: var(--bg);
    color: var(--text);
    border-radius: 0.45rem;
    font-size: 0.72rem;
    padding: 0.22rem 0.5rem;
    cursor: pointer;
}

.quick-replies--stacked .quick-reply-btn--conversation {
    max-width: none;
    border-radius: 0.75rem;
    padding: 0.65rem 1rem;
}

/* —— Bottom sheets —— */
.bottom-sheet {
    position: fixed;
    inset: 0;
    z-index: 55;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.bottom-sheet.hidden {
    display: none;
}

.bottom-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.bottom-sheet-panel {
    position: relative;
    width: 100%;
    max-height: min(85vh, 32rem);
    background: var(--bg);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 1rem 1rem 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    padding-bottom: var(--safe-bottom);
    animation: sheet-slide-up 0.25s ease;
}

.bottom-sheet-panel--compact {
    max-height: none;
}

@keyframes sheet-slide-up {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.bottom-sheet-handle {
    width: 2.5rem;
    height: 0.25rem;
    border-radius: 999px;
    background: var(--border-input);
    margin: 0.5rem auto 0;
    flex-shrink: 0;
}

.bottom-sheet-header {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.5rem 0.65rem 0.65rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.bottom-sheet-title {
    flex: 1;
    margin: 0;
    font-size: 0.95rem;
    font-weight: 600;
    text-align: center;
}

.bottom-sheet-back {
    margin-right: auto;
}

.bottom-sheet-close {
    margin-left: auto;
}

.bottom-sheet-body {
    overflow-y: auto;
    padding: 0.75rem;
    flex: 1;
    min-height: 0;
}

.bottom-sheet-body--actions {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    padding: 0.85rem 0.75rem 1rem;
}

.bottom-sheet-body--confirm {
    padding: 1rem 0.85rem 1.15rem;
}

.topic-sheet-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.topic-sheet-list {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.topic-sheet-item {
    width: 100%;
    min-height: var(--touch-min);
    border: 1px solid var(--border-input);
    border-radius: 0.75rem;
    background: var(--bg);
    color: var(--text);
    font-size: 0.86rem;
    font-weight: 500;
    padding: 0.65rem 0.85rem;
    text-align: left;
    cursor: pointer;
}

.topic-sheet-item--category {
    background: var(--bg-muted);
    font-weight: 600;
}

.topic-sheet-item:hover:not(:disabled) {
    background: var(--bg-muted);
    border-color: #c5c5d2;
}

.topic-sheet-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.sheet-action-btn {
    width: 100%;
    min-height: var(--touch-min);
    border: 1px solid var(--border-input);
    border-radius: 0.75rem;
    background: var(--bg);
    color: var(--text);
    font-size: 0.88rem;
    font-weight: 500;
    padding: 0.65rem 1rem;
    cursor: pointer;
    text-align: left;
}

.sheet-action-btn:hover:not(:disabled) {
    background: var(--bg-muted);
}

.sheet-action-btn--whatsapp {
    border-color: var(--whatsapp);
    color: #128c41;
}

[data-theme="dark"] .sheet-action-btn--whatsapp {
    color: #4ade80;
}

.confirm-sheet-message {
    margin: 0 0 1rem;
    font-size: 0.9rem;
    line-height: 1.5;
    text-align: center;
    color: var(--text);
}

.confirm-sheet-actions {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
}

.panel-btn--ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border-input);
}

.panel-btn--ghost:hover:not(:disabled) {
    background: var(--bg-muted);
}

body.sheet-open {
    overflow: hidden;
}

.quick-replies {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}

.quick-replies::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1.5rem;
    height: 100%;
    pointer-events: none;
    background: linear-gradient(90deg, transparent, var(--bg));
    opacity: 0;
}

.quick-replies.hidden {
    display: none;
}

.quick-reply-btn {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-input);
    border-radius: 9999px;
    padding: 0.42rem 0.95rem;
    font-size: 0.82rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s;
}

.quick-reply-btn:hover {
    background: var(--bg-muted);
    border-color: #c5c5d2;
}

.quick-reply-btn--category {
    font-weight: 600;
    background: var(--bg-muted);
}

.quick-reply-btn--submenu {
    font-size: 0.8rem;
}

.quick-reply-btn--conversation {
    border-radius: 1rem;
    padding: 0.5rem 1rem;
    font-size: 0.84rem;
    text-align: left;
    white-space: normal;
    max-width: 18rem;
    line-height: 1.35;
}

.topic-browser-link {
    display: block;
    width: fit-content;
    margin: 0.15rem 0 0.35rem;
    padding: 0;
    border: 0;
    background: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-decoration: underline;
    cursor: pointer;
}

.topic-browser-link:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.topic-browser-link:hover {
    color: var(--text);
}

.share-actions {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.45rem;
}

.share-actions.visible {
    display: flex;
    flex-wrap: nowrap;
    justify-content: flex-start;
    overflow-x: auto;
    padding-bottom: 0.15rem;
    scrollbar-width: none;
}

.share-actions.visible::-webkit-scrollbar {
    display: none;
}

.share-actions.visible .share-action-btn {
    flex-shrink: 0;
}

.share-action-btn {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border-input);
    border-radius: 9999px;
    padding: 0.38rem 0.85rem;
    font-size: 0.8rem;
    cursor: pointer;
}

.form-field-inline {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

body.density-compact .message-row {
    margin-bottom: 0.6rem;
}

body.density-compact .message {
    line-height: 1.5;
    font-size: 0.9rem;
}

.share-action-btn:hover {
    background: var(--bg-muted);
}

.share-action-btn--whatsapp {
    border-color: var(--whatsapp);
    color: #128c41;
}

[data-theme="dark"] .share-action-btn--whatsapp {
    color: #4ade80;
}

.share-action-btn--whatsapp:hover {
    background: rgba(37, 211, 102, 0.12);
}

.chat-input-bar {
    margin: 0;
}

.chat-input-shell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border-input);
    border-radius: 1.5rem;
    padding: 0.4rem 0.45rem 0.4rem 1.1rem;
    box-shadow: var(--shadow-input);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.chat-input-shell:focus-within {
    border-color: #c5c5d2;
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.12), var(--shadow-input);
}

.chat-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.95rem;
    color: var(--text);
    padding: 0.55rem 0;
    line-height: 1.4;
}

.chat-input::placeholder {
    color: #9ca3af;
}

.send-btn {
    width: 2rem;
    height: 2rem;
    border: none;
    border-radius: 9999px;
    background: var(--text);
    color: #ffffff;
    display: grid;
    place-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.send-btn:hover:not(:disabled) {
    background: #2f2f2f;
}

.send-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* —— Inline panels (date pickers) —— */
.inline-panel {
    background: var(--bg-muted);
    border: 1px solid var(--border);
    border-radius: 1rem;
    padding: 1rem;
}

.inline-panel.hidden {
    display: none;
}

.inline-panel-title {
    margin: 0 0 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.dob-picker-fields {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.dob-picker-fields.range-fields {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.dob-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.dob-field label,
.dob-calendar-label {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-muted);
}

.dob-select,
.dob-calendar-input {
    width: 100%;
    border: 1px solid var(--border-input);
    border-radius: 0.6rem;
    padding: 0.5rem 0.45rem;
    font-size: 0.9rem;
    background: var(--bg);
    color: var(--text);
}

.dob-select:focus,
.dob-calendar-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.15);
}

.dob-picker-calendar-row {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 0.75rem;
}

.panel-btn {
    width: 100%;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 0.75rem;
    padding: 0.7rem 1rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
}

.panel-btn:hover:not(:disabled) {
    background: var(--accent-hover);
}

.panel-btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.panel-btn--danger {
    background: transparent;
    color: #b42318;
    border: 1px solid rgba(180, 35, 24, 0.35);
}

.panel-btn--danger:hover:not(:disabled) {
    background: rgba(180, 35, 24, 0.08);
}

.settings-data-section {
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.settings-section-title {
    margin: 0;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.settings-section-desc {
    margin: 0;
    font-size: 0.78rem;
    line-height: 1.45;
    color: var(--text-muted);
}

.settings-client-count {
    margin: 0;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* —— Share card export —— */
#share-card {
    position: fixed;
    left: -9999px;
    top: 0;
    width: 360px;
    padding: 1.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 1rem;
    color: var(--text);
}

.share-card-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.share-card-mark {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.35rem;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.share-card-body {
    font-size: 0.9rem;
    line-height: 1.55;
    white-space: pre-wrap;
}

.share-card-consultant {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--accent);
}

.share-card-date {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 0.65rem;
}

.share-card-sections {
    font-size: 0.85rem;
    line-height: 1.5;
    white-space: pre-wrap;
    margin-top: 0.75rem;
    border-top: 1px solid var(--border);
    padding-top: 0.75rem;
}

@media (max-width: 900px) {
    .client-sidebar {
        display: none;
    }

    body.sidebar-open-mobile .client-sidebar {
        display: flex;
    }
}

@media (max-width: 640px) {
    .chat-header {
        grid-template-columns: auto 1fr auto;
        padding-left: calc(0.5rem + var(--safe-left));
        padding-right: calc(0.5rem + var(--safe-right));
    }

    .header-hide-mobile {
        display: none !important;
    }

    .header-toolbar-desktop {
        display: none;
    }

    .header-toolbar-mobile {
        display: grid;
    }

    .icon-btn {
        width: var(--touch-min);
        height: var(--touch-min);
    }

    .brand-title {
        font-size: 0.88rem;
    }

    .toolbar-select {
        max-width: none;
        font-size: 0.82rem;
        padding: 0.45rem 0.5rem;
        min-height: var(--touch-min);
    }

    .message-row {
        padding: 1rem 0.65rem;
    }

    .message-row-inner {
        gap: 0.65rem;
    }

    .dob-picker-fields:not(.range-fields) {
        grid-template-columns: 1fr;
    }

    .dob-picker-fields.range-fields {
        grid-template-columns: 1fr;
    }

    .dob-select,
    .dob-calendar-input {
        font-size: 1rem;
        min-height: var(--touch-min);
    }

    .panel-btn {
        min-height: var(--touch-min);
    }

    .composer-area {
        position: sticky;
        bottom: 0;
        z-index: 15;
        padding-bottom: calc(0.85rem + var(--safe-bottom) + var(--keyboard-offset));
    }

    .chat-messages {
        padding-left: var(--safe-left);
        padding-right: var(--safe-right);
    }

    .chat-input {
        font-size: 1rem;
    }

    .send-btn {
        width: var(--touch-min);
        height: var(--touch-min);
    }

    .share-open-btn.visible {
        display: block;
    }

    .share-actions.visible {
        display: none;
    }

    .topic-browser-link:not(.topic-browser-link--button) {
        min-height: var(--touch-min);
        display: inline-flex;
        align-items: center;
    }

    .quick-replies:not(.quick-replies--stacked) {
        flex-wrap: nowrap;
        justify-content: flex-start;
        overflow-x: auto;
        padding-bottom: 0.2rem;
        scrollbar-width: none;
    }

    .quick-replies:not(.quick-replies--stacked)::after {
        opacity: 1;
    }

    .quick-replies:not(.quick-replies--stacked)::-webkit-scrollbar {
        display: none;
    }

    .quick-replies:not(.quick-replies--stacked) .quick-reply-btn {
        flex-shrink: 0;
        min-height: var(--touch-min);
    }

    .session-banner {
        flex-direction: column;
        align-items: stretch;
        text-align: left;
    }

    .session-banner-actions {
        flex-direction: column;
        width: 100%;
    }

    .session-banner-btn {
        width: 100%;
        min-height: var(--touch-min);
        padding: 0.5rem 0.85rem;
        font-size: 0.82rem;
    }

    .modal {
        align-items: flex-end;
        padding: 0;
    }

    .modal-panel {
        width: 100%;
        max-width: none;
        border-radius: 1rem 1rem 0 0;
        border-bottom: none;
        max-height: 90vh;
        overflow-y: auto;
        padding-left: var(--safe-left);
        padding-right: var(--safe-right);
        padding-bottom: var(--safe-bottom);
    }

    .form-input {
        font-size: 1rem;
        min-height: var(--touch-min);
    }
}
