/**
 * Flora Chat - Public UI
 * "Calm green concierge" — full redesign
 * 2026-05-17 (chat-ui-v5)
 */

:root {
    --page-bg: #d8d1c7;
    --page-bg-deep: #17362d;
    --page-bg-muted: #ebe5db;
    --panel: rgba(247, 241, 232, 0.9);
    --panel-strong: rgba(251, 248, 242, 0.96);
    --panel-border: rgba(58, 53, 43, 0.12);
    --panel-shadow: 0 28px 72px rgba(28, 35, 31, 0.18);
    --shadow-soft: 0 10px 24px rgba(23, 34, 29, 0.08);
    --shadow-tiny: 0 4px 14px rgba(23, 34, 29, 0.06);
    --accent: #2d6b4f;
    --accent-strong: #1d4d39;
    --accent-soft: #def0e4;
    --accent-tint: rgba(45, 107, 79, 0.12);
    --accent-glow: rgba(45, 107, 79, 0.24);
    --text-strong: #18211d;
    --text-body: #47524c;
    --text-muted: #59645e;
    --text-faint: #68736d;
    --text-on-dark: #f7f9f8;
    --incoming-bg: rgba(255, 255, 255, 0.94);
    --incoming-border: rgba(61, 66, 54, 0.08);
    --manager-bg: rgba(243, 248, 255, 0.94);
    --manager-border: rgba(67, 96, 140, 0.14);
    --outgoing-bg-start: #d7f1c9;
    --outgoing-bg-end: #c2e6b3;
    --outgoing-border: rgba(49, 110, 78, 0.12);
    --danger-bg: rgba(254, 240, 238, 0.94);
    --danger-border: rgba(219, 84, 80, 0.16);
    --warn-bg: rgba(255, 248, 229, 0.94);
    --warn-border: rgba(205, 156, 56, 0.18);
    --radius-xl: 32px;
    --radius-lg: 24px;
    --radius-md: 20px;
    --radius-sm: 16px;
    --radius-xs: 12px;
    --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
    --display: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --body-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html {
    height: 100%;
}

body {
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    height: var(--app-height, 100dvh);
    margin: 0;
    font-family: var(--body-font);
    color: var(--text-strong);
    background:
        radial-gradient(circle at 14% 12%, rgba(45, 107, 79, 0.10), transparent 38%),
        radial-gradient(circle at 86% 88%, rgba(45, 107, 79, 0.07), transparent 40%),
        linear-gradient(160deg, #ddd6cc 0%, #ece6db 50%, #d7d0c5 100%);
    overflow: hidden;
    overscroll-behavior: none;
}

img {
    max-width: 100%;
}

button,
input,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

[hidden] {
    display: none !important;
}

/* ============================================================
   SHELL — centered conversation column, optional presence card
   ============================================================ */
.chat-shell {
    position: relative;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    justify-content: center;
    align-items: stretch;
    min-height: 100vh;
    min-height: 100svh;
    min-height: 100dvh;
    height: var(--app-height, 100dvh);
    width: 100%;
    margin: 0;
    padding: 0;
    isolation: isolate;
}

/* ============================================================
   PRESENCE CARD (desktop >= 1180px only)
   ============================================================ */
.chat-presence {
    display: none;
    position: relative;
    z-index: 1;
    align-self: center;
}

.chat-presence-card {
    padding: 36px 30px;
    border-radius: var(--radius-xl);
    background:
        linear-gradient(165deg, var(--accent-strong), var(--accent));
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: var(--panel-shadow);
    color: var(--text-on-dark);
}

.chat-presence-logo {
    width: 72px;
    height: 72px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    border-radius: var(--radius-md);
    background: #ffffff;
    box-shadow: var(--shadow-tiny);
}

.chat-presence-logo img {
    width: 56px;
    height: 56px;
    object-fit: contain;
}

.chat-presence-lead {
    max-width: 22rem;
    margin: 20px 0 0;
    font-size: 1.02rem;
    line-height: 1.65;
    color: rgba(247, 249, 248, 0.88);
}

.chat-presence-points {
    margin-top: 26px;
    display: grid;
    gap: 14px;
}

.presence-point {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    padding: 18px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.presence-point-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    background: rgba(255, 255, 255, 0.14);
}

.presence-point-avatar {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow-tiny);
    flex-shrink: 0;
}

.presence-point-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.presence-point h2 {
    margin: 0;
    font-family: var(--display);
    font-size: 0.98rem;
    line-height: 1.4;
}

.presence-point p {
    margin: 6px 0 0;
    font-size: 0.9rem;
    line-height: 1.6;
    color: rgba(247, 249, 248, 0.78);
}

.presence-point p span {
    display: block;
    margin-top: 4px;
    color: rgba(247, 249, 248, 0.64);
}

.presence-point a {
    color: #ffffff;
    text-decoration: none;
    font-weight: 700;
}

.chat-presence-actions {
    margin-top: 26px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.presence-action {
    min-height: 48px;
    padding: 0 22px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-weight: 700;
    transition: transform 0.22s ease, background 0.22s ease;
}

.presence-action:hover {
    transform: translateY(-1px);
}

.presence-action.primary {
    background: #ffffff;
    color: var(--accent-strong);
    box-shadow: var(--shadow-soft);
}

.presence-action.secondary {
    background: rgba(255, 255, 255, 0.10);
    color: var(--text-on-dark);
    border: 1px solid rgba(255, 255, 255, 0.16);
}

/* ============================================================
   APP — vertical flex: header / messages / composer
   ============================================================ */
.chat-stage {
    position: relative;
    z-index: 1;
    min-width: 0;
    display: flex;
    width: 100%;
    justify-content: center;
}

.chat-app {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-width: 0;
    min-height: 0;
    height: 100vh;
    height: 100svh;
    height: 100dvh;
    height: var(--app-height, 100dvh);
    margin: 0;
    background: var(--page-bg-muted);
    overflow: hidden;
}

.chat-header,
.state-banner,
.chat-main,
.chat-file-preview,
.chat-input-area {
    position: relative;
    z-index: 1;
}

/* ============================================================
   HEADER — slim, sticky
   ============================================================ */
.chat-header {
    position: sticky;
    top: 0;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    padding: calc(10px + env(safe-area-inset-top)) 18px 10px;
    min-height: 64px;
    background: linear-gradient(135deg, var(--accent-strong), var(--accent));
    color: var(--text-on-dark);
    box-shadow: 0 2px 14px rgba(20, 40, 32, 0.16);
}

.chat-header-back,
.chat-header-action {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
    text-decoration: none;
    transition: background 0.2s ease, transform 0.2s ease;
}

.chat-header-back:hover,
.chat-header-action:hover {
    background: rgba(255, 255, 255, 0.16);
    transform: translateY(-1px);
}

.chat-header-back:focus-visible,
.chat-header-action:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.chat-header-avatar {
    width: 44px;
    height: 44px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.16);
    border: 2px solid rgba(255, 255, 255, 0.24);
}

.chat-header-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chat-header-actions {
    display: flex;
}

.chat-header-info {
    min-width: 0;
}

.chat-header-eyebrow {
    margin: 0;
}

.chat-header-title-row {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.chat-header-title {
    min-width: 0;
    font-family: var(--display);
    font-size: 1.06rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-badge {
    padding: 3px 9px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.16);
    color: #d6f5e2;
    font-size: 0.7rem;
    font-weight: 700;
    white-space: nowrap;
}

.chat-header-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 2px;
    min-width: 0;
}

.chat-header-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: rgba(247, 249, 248, 0.9);
    white-space: nowrap;
}

.chat-header-status.online::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 999px;
    background: #74f0a6;
    box-shadow: 0 0 10px rgba(116, 240, 166, 0.65);
    animation: statusPulse 2s ease-in-out infinite;
}

.chat-header-caption {
    min-width: 0;
    font-size: 0.78rem;
    color: rgba(247, 249, 248, 0.76);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header-caption::before {
    content: "·";
    margin-right: 8px;
    color: rgba(247, 249, 248, 0.4);
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============================================================
   STATE BANNERS
   ============================================================ */
.state-banner {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 14px;
    align-items: start;
    padding: 16px 20px;
    border-bottom: 1px solid var(--panel-border);
}

.ban-banner {
    background: var(--danger-bg);
    border-bottom-color: var(--danger-border);
}

.cooldown-banner {
    background: var(--warn-bg);
    border-bottom-color: var(--warn-border);
}

.connection-banner {
    background: rgba(239, 247, 242, 0.98);
    border-bottom-color: rgba(45, 107, 79, 0.16);
}

.connection-banner.is-error {
    background: var(--warn-bg);
    border-bottom-color: var(--warn-border);
}

.connection-banner-icon::before {
    content: "";
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: 2px solid rgba(45, 107, 79, 0.22);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}

.connection-banner.is-error .connection-banner-icon::before {
    content: "!";
    width: auto;
    height: auto;
    border: 0;
    color: #7a5410;
    font-weight: 900;
    animation: none;
}

.connection-banner-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.connection-retry,
.connection-fallback {
    min-height: 42px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.88rem;
    font-weight: 800;
    text-decoration: none;
}

.connection-retry {
    border: 0;
    background: var(--accent-strong);
    color: #ffffff;
    cursor: pointer;
}

.connection-fallback {
    border: 1px solid rgba(45, 107, 79, 0.2);
    background: #ffffff;
    color: var(--accent-strong);
}

.connection-retry:focus-visible,
.connection-fallback:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.state-banner-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
    background: rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-tiny);
}

.state-banner-title {
    display: block;
    font-family: var(--display);
    font-size: 0.98rem;
    line-height: 1.35;
}

.state-banner-text,
.state-banner-caption {
    margin: 6px 0 0;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-body);
}

.state-banner-caption a {
    color: var(--accent-strong);
    text-decoration: none;
    font-weight: 700;
}

.state-banner-link {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin-top: 8px;
    text-decoration: none;
    font-weight: 800;
    color: var(--accent-strong);
}

/* ============================================================
   MESSAGES — scroll container
   ============================================================ */
.chat-main {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 22px 20px 8px;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(45, 107, 79, 0.26) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(45, 107, 79, 0.22);
    border-radius: 999px;
    border: 2px solid transparent;
    background-clip: padding-box;
}

.chat-date-separator {
    display: flex;
    justify-content: center;
    margin: 10px 0 18px;
}

.chat-date-separator span {
    padding: 6px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(58, 53, 43, 0.08);
    box-shadow: var(--shadow-tiny);
    font: 500 11px/1.2 var(--mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
}

/* ============================================================
   EMPTY STATE — points to composer
   ============================================================ */
.chat-empty-state {
    display: flex;
    flex-shrink: 1;
    flex-direction: column;
    align-items: center;
    text-align: center;
    min-height: 0;
    margin: 24px auto 16px;
    padding: 0 24px;
    max-width: 26rem;
}

.chat-empty-art {
    position: relative;
    width: 84px;
    height: 84px;
    margin-bottom: 18px;
}

.chat-empty-art img {
    position: relative;
    z-index: 1;
    width: 84px;
    height: 84px;
    border-radius: 999px;
    object-fit: cover;
    border: 3px solid #ffffff;
    box-shadow: var(--shadow-soft);
}

.chat-empty-pulse {
    position: absolute;
    inset: -6px;
    border-radius: 999px;
    border: 2px solid var(--accent);
    opacity: 0.35;
    animation: emptyPulse 2.6s ease-out infinite;
}

@keyframes emptyPulse {
    0% { transform: scale(0.92); opacity: 0.4; }
    70% { transform: scale(1.12); opacity: 0; }
    100% { opacity: 0; }
}

.chat-empty-badge {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent-strong);
    font: 600 11px/1.2 var(--mono);
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.chat-empty-state h2 {
    margin: 0;
    font-family: var(--display);
    font-size: 1.3rem;
    line-height: 1.25;
    letter-spacing: -0.02em;
    color: var(--text-strong);
}

.chat-empty-state p {
    margin: 10px 0 0;
    font-size: 0.96rem;
    line-height: 1.6;
    color: var(--text-body);
}

.chat-empty-hint {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-top: 22px;
    padding: 9px 16px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(45, 107, 79, 0.16);
    color: var(--accent-strong);
    font-size: 0.88rem;
    font-weight: 700;
}

.chat-empty-hint svg {
    color: var(--accent);
    animation: hintBounce 1.8s ease-in-out infinite;
}

@keyframes hintBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(4px); }
}

/* Legacy empty-state structure (kept for compatibility, hidden if rendered) */
.chat-empty-topics,
.chat-empty-note {
    display: none;
}

/* ============================================================
   MESSAGE DOM (produced by chat.v4.js — exact hooks)
   ============================================================ */
.chat-message {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 8px;
    animation: messageAppear 0.3s ease-out;
}

.chat-message.customer {
    justify-content: flex-end;
    padding-left: 64px;
}

.chat-message.assistant,
.chat-message.manager {
    justify-content: flex-start;
    padding-right: 64px;
}

.chat-message.customer + .chat-message.assistant,
.chat-message.customer + .chat-message.manager,
.chat-message.assistant + .chat-message.customer,
.chat-message.manager + .chat-message.customer {
    margin-top: 18px;
}

.chat-message.assistant + .chat-message.assistant .message-avatar,
.chat-message.manager + .chat-message.manager .message-avatar {
    visibility: hidden;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 999px;
    overflow: hidden;
    box-shadow: var(--shadow-tiny);
    flex-shrink: 0;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.7);
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.message-bubble {
    position: relative;
    max-width: min(80%, 36rem);
    padding: 13px 17px 11px;
    border-radius: var(--radius-lg);
    word-break: break-word;
    overflow-wrap: break-word;
    border: 1px solid var(--incoming-border);
    box-shadow: var(--shadow-tiny);
}

.chat-message.has-actions .message-bubble,
.chat-message.has-attachments .message-bubble {
    max-width: min(84%, 38rem);
}

.chat-message.customer .message-bubble {
    background: linear-gradient(135deg, var(--outgoing-bg-start), var(--outgoing-bg-end));
    border-color: var(--outgoing-border);
    border-bottom-right-radius: var(--radius-xs);
}

.chat-message.assistant .message-bubble {
    background: var(--incoming-bg);
    border-bottom-left-radius: var(--radius-xs);
}

.chat-message.manager .message-bubble {
    background: var(--manager-bg);
    border-color: var(--manager-border);
    border-bottom-left-radius: var(--radius-xs);
}

.message-content {
    font-size: 0.97rem;
    line-height: 1.55;
    color: var(--text-strong);
    white-space: pre-wrap;
}

.message-content p {
    margin: 0 0 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content a {
    color: var(--accent-strong);
    text-decoration-color: rgba(29, 77, 57, 0.32);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 0.16em;
    font-weight: 700;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 6px;
    margin-top: 7px;
}

.message-time,
.message-role {
    font: 500 11px/1.2 var(--mono);
    letter-spacing: 0.03em;
}

.message-time {
    color: var(--text-muted);
}

.message-role {
    color: var(--accent-strong);
}

.typing-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: rgba(45, 107, 79, 0.5);
    animation: typing 1.2s infinite ease-in-out;
}

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

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

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.99);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes typing {
    0%, 80%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    40% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

/* ============================================================
   PRODUCT / SEARCH ACTION CARDS
   ============================================================ */
.product-card {
    overflow: hidden;
    margin-top: 12px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(58, 53, 43, 0.08);
    box-shadow: var(--shadow-soft);
}

.product-card-image {
    width: 100%;
    height: 192px;
    object-fit: cover;
    background: #eff2ef;
    display: block;
}

.product-card-body {
    padding: 16px;
}

.product-card-name {
    margin: 0;
    font-family: var(--display);
    font-size: 1rem;
    line-height: 1.35;
}

.product-card-price {
    margin: 10px 0 0;
    font-size: 1.28rem;
    font-weight: 800;
    color: var(--accent-strong);
    letter-spacing: -0.02em;
}

.product-card-stock {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    margin: 12px 0 0;
    padding: 0 12px;
    border-radius: 999px;
    background: var(--accent-tint);
    color: var(--accent-strong);
    font-size: 0.82rem;
    font-weight: 700;
}

.product-card-stock.preorder {
    background: rgba(240, 173, 78, 0.12);
    color: #8f5e0c;
}

.product-card-stock.out-of-stock {
    background: rgba(220, 80, 76, 0.12);
    color: #b3322e;
}

.product-card-actions {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    margin-top: 14px;
}

.btn-add-to-cart,
.btn-view-product,
.btn-catalog-link,
.pwa-banner-install,
.pwa-banner-dismiss {
    min-height: 46px;
    padding: 0 18px;
    border-radius: var(--radius-sm);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 0.92rem;
    font-weight: 800;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.btn-add-to-cart,
.btn-catalog-link,
.pwa-banner-install {
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #ffffff;
    box-shadow: 0 12px 24px rgba(29, 77, 57, 0.22);
}

.btn-view-product,
.pwa-banner-dismiss {
    background: #ffffff;
    color: var(--accent-strong);
    border: 1px solid rgba(45, 107, 79, 0.16);
}

.btn-add-to-cart:hover,
.btn-view-product:hover,
.btn-catalog-link:hover,
.pwa-banner-install:hover,
.pwa-banner-dismiss:hover {
    transform: translateY(-1px);
}

.btn-add-to-cart:focus-visible,
.btn-view-product:focus-visible,
.btn-catalog-link:focus-visible,
.pwa-banner-install:focus-visible,
.pwa-banner-dismiss:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-add-to-cart:disabled {
    background: linear-gradient(135deg, #c7ccc9, #b4bbb7);
    box-shadow: none;
    cursor: not-allowed;
}

.search-results {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.search-result-item {
    position: relative;
    display: grid;
    grid-template-columns: 80px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(58, 53, 43, 0.08);
    box-shadow: var(--shadow-tiny);
    text-decoration: none;
    color: inherit;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.search-result-item::after {
    content: "↗";
    position: absolute;
    top: 12px;
    right: 14px;
    color: rgba(29, 77, 57, 0.42);
    font-size: 0.95rem;
    font-weight: 700;
}

.search-result-item:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-soft);
    border-color: rgba(45, 107, 79, 0.16);
}

.search-result-image {
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    display: block;
    background: #eff2ef;
}

.search-result-info {
    min-width: 0;
    padding-right: 20px;
}

.search-result-name {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.4;
    color: var(--text-strong);
}

.search-result-price {
    margin: 10px 0 0;
    color: var(--accent-strong);
    font-size: 1rem;
    font-weight: 800;
}

.search-fallback {
    margin-top: 12px;
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--warn-bg);
    border: 1px solid var(--warn-border);
    text-align: center;
}

.search-fallback-text {
    margin: 0 0 12px;
    font-size: 0.92rem;
    line-height: 1.6;
    color: #735319;
}

/* ============================================================
   QUICK REPLIES
   ============================================================ */
.quick-replies {
    display: flex;
    gap: 10px;
    padding: 0 20px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-behavior: smooth;
    scrollbar-width: none;
}

.quick-replies::-webkit-scrollbar {
    display: none;
}

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

.quick-reply-btn {
    flex: 0 0 auto;
    min-height: 44px;
    padding: 0 16px;
    border-radius: 999px;
    border: 1px solid rgba(45, 107, 79, 0.16);
    background: #ffffff;
    color: var(--accent-strong);
    box-shadow: var(--shadow-tiny);
    font-size: 0.86rem;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, border-color 0.2s ease;
}

.quick-reply-btn:hover {
    transform: translateY(-1px);
    background: var(--accent-soft);
    border-color: rgba(45, 107, 79, 0.28);
}

.quick-reply-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ============================================================
   FILE PREVIEW
   ============================================================ */
.chat-file-preview {
    margin: 0 20px 0;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1px solid rgba(45, 107, 79, 0.16);
    box-shadow: var(--shadow-soft);
    overflow: hidden;
}

.file-preview-content {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
}

.file-preview-image {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-sm);
    background: #eef3ef center/cover no-repeat;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-preview-image.document {
    background-color: var(--accent-soft);
    color: var(--accent-strong);
    font-size: 1.5rem;
}

.file-preview-image.video {
    position: relative;
    font-size: 1.35rem;
}

.file-preview-name,
.file-preview-size {
    display: block;
}

.file-preview-info,
.attachment-document-info {
    min-width: 0;
}

.file-preview-name {
    font-size: 0.92rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    margin-top: 4px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.file-preview-remove {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(24, 33, 29, 0.06);
    color: var(--text-body);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.file-preview-remove:hover {
    background: rgba(220, 80, 76, 0.12);
    color: #b3322e;
}

.file-preview-remove:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.file-upload-progress {
    display: none;
    height: 4px;
    background: rgba(24, 33, 29, 0.06);
}

.file-upload-progress.active {
    display: block;
}

.file-upload-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    transition: width 0.2s ease;
}

/* ============================================================
   COMPOSER (hero) — sticky bottom, keyboard-safe
   ============================================================ */
.chat-input-area {
    position: sticky;
    bottom: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 10px;
    align-items: end;
    padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    background: var(--page-bg-muted);
    border-top: 1px solid var(--panel-border);
}

.chat-attach-btn,
.chat-send-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}

.chat-attach-btn {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1px solid rgba(45, 107, 79, 0.18);
    color: var(--accent);
    box-shadow: var(--shadow-tiny);
}

.chat-attach-btn:hover {
    transform: translateY(-1px);
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.chat-attach-btn:focus-visible,
.chat-send-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.chat-attach-btn:disabled,
.chat-input:disabled {
    opacity: 0.62;
    cursor: wait;
}

.chat-input-wrapper:has(.chat-input:disabled) {
    background: rgba(255, 255, 255, 0.72);
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    min-height: 56px;
    padding: 11px 18px;
    border-radius: var(--radius-md);
    background: #ffffff;
    border: 1.5px solid var(--accent-soft);
    box-shadow: var(--shadow-tiny);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-tint), var(--shadow-tiny);
}

.chat-input {
    width: 100%;
    min-height: 40px;
    max-height: 144px;
    padding: 0;
    border: none;
    outline: none;
    resize: none;
    overflow-y: auto;
    scrollbar-width: none;
    background: transparent;
    color: var(--text-strong);
    font-size: 16px;
    line-height: 1.5;
}

.chat-input::-webkit-scrollbar {
    width: 0;
    height: 0;
}

.chat-input::placeholder {
    color: var(--text-faint);
}

.chat-send-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #ffffff;
    box-shadow: 0 14px 26px rgba(29, 77, 57, 0.24);
}

.chat-send-btn:hover {
    transform: translateY(-1px);
}

.chat-input-area.has-value .chat-send-btn {
    transform: translateY(-1px);
}

.chat-send-btn:disabled,
.chat-input-area.is-busy .chat-send-btn {
    background: linear-gradient(135deg, #cfd5d1, #bfc6c2);
    box-shadow: none;
    cursor: not-allowed;
    transform: none;
}

.chat-input-area.is-busy .chat-attach-btn {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-attach-btn svg {
    width: 22px;
    height: 22px;
}

.chat-send-btn svg {
    width: 23px;
    height: 23px;
    transform: translateX(1px);
}

/* ============================================================
   ATTACHMENTS IN MESSAGES
   ============================================================ */
.message-attachments {
    display: grid;
    gap: 8px;
    margin-bottom: 8px;
}

.message-attachment {
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.attachment-image,
.attachment-video {
    display: block;
    width: 100%;
    max-width: 100%;
    max-height: 320px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: #0a0a0a;
}

.attachment-image {
    cursor: pointer;
}

.attachment-document {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 12px;
    border-radius: var(--radius-sm);
    background: rgba(24, 33, 29, 0.05);
    text-decoration: none;
}

.attachment-document-icon {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-xs);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #ffffff;
    font-size: 1.05rem;
}

.attachment-document-icon.pdf {
    background: #cc4b49;
}

.attachment-document-icon.doc {
    background: #3e6fcb;
}

.attachment-document-icon.xls {
    background: #278a4b;
}

.attachment-document-name {
    font-size: 0.9rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-document-size {
    margin-top: 4px;
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* ============================================================
   LIGHTBOX
   ============================================================ */
.chat-lightbox {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(9, 14, 12, 0.92);
    backdrop-filter: blur(14px);
    z-index: 3000;
}

.lightbox-close {
    position: absolute;
    top: calc(16px + env(safe-area-inset-top));
    right: 16px;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.14);
    color: #ffffff;
    cursor: pointer;
}

.lightbox-close:focus-visible {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.lightbox-image {
    max-width: min(94vw, 1180px);
    max-height: min(88vh, 960px);
    object-fit: contain;
    border-radius: var(--radius-md);
    box-shadow: 0 22px 80px rgba(0, 0, 0, 0.4);
}

/* ============================================================
   PWA INSTALL BANNER
   ============================================================ */
.pwa-install-banner {
    position: fixed;
    right: 20px;
    bottom: calc(112px + env(safe-area-inset-bottom));
    width: min(360px, calc(100vw - 40px));
    display: none;
    padding: 16px;
    border-radius: var(--radius-lg);
    background: var(--panel-strong);
    border: 1px solid rgba(58, 53, 43, 0.1);
    box-shadow: var(--panel-shadow);
    backdrop-filter: blur(16px);
    z-index: 2500;
}

.pwa-install-banner.show {
    display: block;
    animation: bannerSlideIn 0.28s ease-out;
}

@keyframes bannerSlideIn {
    from {
        opacity: 0;
        transform: translateY(12px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.pwa-banner-content {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
}

.pwa-banner-icon {
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), var(--accent-strong));
    color: #ffffff;
    font-size: 1.35rem;
}

.pwa-banner-title {
    margin: 0;
    font-family: var(--display);
    font-size: 0.95rem;
    font-weight: 800;
}

.pwa-banner-desc {
    margin: 4px 0 0;
    font-size: 0.84rem;
    line-height: 1.55;
    color: var(--text-body);
}

.pwa-banner-actions {
    display: flex;
    gap: 10px;
    margin-top: 14px;
}

.loading-spinner {
    width: 18px;
    height: 18px;
    display: inline-block;
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.28);
    border-top-color: #ffffff;
    animation: spin 0.7s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================================
   RICH MESSAGE CONTENT
   ============================================================ */
.message-content .chat-heading {
    margin: 12px 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(45, 107, 79, 0.14);
    color: var(--accent-strong);
    font-family: var(--display);
    font-size: 1.02em;
    font-weight: 800;
}

.message-content .chat-heading:first-child {
    margin-top: 0;
}

.message-content .chat-subheading {
    margin: 10px 0 6px;
    color: var(--accent);
    font-size: 0.98em;
    font-weight: 800;
}

.message-content .chat-divider {
    margin: 12px 0;
    border: 0;
    border-top: 1px solid rgba(24, 33, 29, 0.08);
}

.message-content strong {
    font-weight: 800;
    color: var(--accent-strong);
}

.message-content em {
    font-style: italic;
}

.message-content .chat-table-wrapper {
    position: relative;
    margin: 10px 0;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    overflow-y: hidden;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(58, 53, 43, 0.08);
    box-shadow: var(--shadow-tiny);
    -webkit-overflow-scrolling: touch;
}

.message-content .chat-table-wrapper::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 26px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.95));
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.message-content .chat-table-wrapper.scrolled-end::after {
    opacity: 0;
}

.message-content .chat-table {
    width: 100%;
    min-width: 420px;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.message-content .chat-table th,
.message-content .chat-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid rgba(24, 33, 29, 0.06);
}

.message-content .chat-table th {
    background: var(--accent-tint);
    color: var(--accent-strong);
    font-size: 0.78rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.message-content .chat-table tr:nth-child(even) {
    background: rgba(24, 33, 29, 0.025);
}

.message-content .chat-table tr:last-child td {
    border-bottom: none;
}

/* ============================================================
   DESKTOP — centered shell with presence card (>= 1180px)
   ============================================================ */
@media (min-width: 1180px) {
    .chat-shell {
        grid-template-columns: minmax(300px, 340px) minmax(0, 760px);
        gap: 28px;
        padding: 32px;
        align-items: center;
        min-height: 0;
    }

    .chat-presence {
        display: block;
    }

    .chat-stage {
        align-items: stretch;
        height: min(calc(var(--app-height, 100dvh) - 64px), 920px);
        min-height: 0;
    }

    .chat-app {
        height: 100%;
        max-width: 760px;
        border-radius: var(--radius-xl);
        border: 1px solid rgba(255, 255, 255, 0.5);
        box-shadow: var(--panel-shadow);
    }

    .chat-header {
        border-top-left-radius: var(--radius-xl);
        border-top-right-radius: var(--radius-xl);
    }
}

/* ============================================================
   TABLET / NARROW DESKTOP (< 1180px) — full-width column
   ============================================================ */
@media (min-width: 769px) and (max-width: 1179px) {
    .chat-shell {
        padding: 0;
    }

    .chat-app {
        width: min(100%, 820px);
    }
}

/* ============================================================
   MOBILE (<= 768px) — fullscreen, safe-area
   ============================================================ */
@media (max-width: 768px) {
    body {
        background: linear-gradient(180deg, #e9e2d8 0%, #efe8dd 100%);
    }

    .chat-shell {
        padding: 0;
    }

    .chat-app {
        width: 100%;
        height: 100vh;
        height: 100svh;
        height: 100dvh;
        height: var(--app-height, 100dvh);
        border-radius: 0;
        border: none;
        box-shadow: none;
    }

    .chat-header {
        padding: calc(8px + env(safe-area-inset-top)) 14px 8px;
        gap: 10px;
        min-height: 60px;
        grid-template-columns: auto auto minmax(0, 1fr) auto;
    }

    .chat-header-back,
    .chat-header-action {
        width: 44px;
        height: 44px;
    }

    .chat-header-avatar {
        width: 42px;
        height: 42px;
    }

    .chat-header-caption {
        display: none;
    }

    .state-banner {
        padding: 14px;
    }

    .chat-messages {
        padding: 18px 14px 6px;
    }

    .chat-empty-state {
        margin: 18px auto 12px;
        padding: 0 20px;
    }

    .chat-empty-state h2 {
        font-size: 1.18rem;
    }

    .chat-message.customer {
        padding-left: 40px;
    }

    .chat-message.assistant,
    .chat-message.manager {
        padding-right: 40px;
    }

    .message-avatar {
        width: 32px;
        height: 32px;
    }

    .message-bubble {
        max-width: min(88%, 30rem);
        padding: 12px 15px 10px;
    }

    .chat-message.has-actions .message-bubble,
    .chat-message.has-attachments .message-bubble {
        max-width: min(92%, 32rem);
    }

    .product-card-image {
        height: 164px;
    }

    .search-result-item {
        grid-template-columns: 72px minmax(0, 1fr);
    }

    .search-result-image {
        width: 72px;
        height: 72px;
    }

    .quick-replies {
        gap: 8px;
        padding: 0 14px 10px;
    }

    .chat-file-preview {
        margin: 0 14px 0;
    }

    .chat-input-area {
        gap: 8px;
        padding: 12px 14px calc(12px + env(safe-area-inset-bottom));
    }

    .chat-attach-btn {
        width: 48px;
        height: 48px;
    }

    .chat-send-btn {
        width: 52px;
        height: 52px;
    }

    .chat-input-wrapper {
        min-height: 56px;
        padding: 11px 16px;
    }

    .pwa-install-banner {
        left: 14px;
        right: 14px;
        width: auto;
        bottom: calc(108px + env(safe-area-inset-bottom));
    }
}

/* Keep the desktop presence panel inside common 1366×768 laptop screens. */
@media (min-width: 1180px) and (max-height: 820px) {
    .chat-shell {
        gap: 20px;
        padding: 16px;
    }

    .chat-stage {
        height: calc(var(--app-height, 100dvh) - 32px);
    }

    .chat-presence-card {
        padding: 24px;
    }

    .chat-presence-logo {
        width: 58px;
        height: 58px;
    }

    .chat-presence-logo img {
        width: 46px;
        height: 46px;
    }

    .chat-presence-lead {
        margin-top: 14px;
        font-size: 0.94rem;
        line-height: 1.5;
    }

    .chat-presence-points {
        margin-top: 18px;
        gap: 10px;
    }

    .presence-point {
        gap: 12px;
        padding: 13px;
    }

    .presence-point p {
        margin-top: 4px;
        font-size: 0.84rem;
        line-height: 1.45;
    }

    .chat-presence-actions {
        margin-top: 18px;
        gap: 8px;
    }

    .presence-action {
        min-height: 44px;
        padding: 0 18px;
        font-size: 0.9rem;
    }
}

/* Short phones, landscape and keyboard-open visual viewports. */
@media (max-height: 620px) {
    .chat-empty-state {
        display: none !important;
    }

    .chat-header {
        min-height: 56px;
        padding-top: calc(6px + env(safe-area-inset-top));
        padding-bottom: 6px;
    }

    .chat-messages {
        padding-top: 12px;
    }

    .state-banner {
        gap: 10px;
        padding: 10px 14px;
    }

    .state-banner-icon {
        width: 36px;
        height: 36px;
        border-radius: var(--radius-xs);
    }

    .state-banner-text,
    .state-banner-caption {
        margin-top: 3px;
        font-size: 0.84rem;
        line-height: 1.4;
    }

    .chat-input-area {
        padding-top: 8px;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
    }

    .chat-attach-btn {
        width: 44px;
        height: 44px;
    }

    .chat-send-btn {
        width: 48px;
        height: 48px;
    }

    .chat-input-wrapper {
        min-height: 52px;
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .pwa-install-banner {
        bottom: calc(84px + env(safe-area-inset-bottom));
        max-height: calc(var(--app-height, 100dvh) - 100px);
        overflow-y: auto;
    }
}

@media (max-width: 420px) {
    .chat-header-title {
        font-size: 1rem;
    }

    .message-content {
        font-size: 0.95rem;
    }

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

    .file-preview-content {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 10px;
        padding: 12px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition: none !important;
        scroll-behavior: auto !important;
    }
}
