/* Ralson Tyres AI assistant (demo) - full-screen chat surface.
   Adapted from the RSO Workplace widget; palette switched to the Ralson
   brand red, payment/sign-in cards removed (informational site). */

.ral-chat-scope,
.ral-chat-launcher,
.ral-chat-overlay {
    --ral-red: #d92b21;
    --ral-red-dark: #a81f17;
    --ral-red-soft: #fbe3e1;
    --ral-ink: #101828;
    --ral-muted: #667085;
    --ral-line: #eaecf0;
    --ral-line-soft: #f2f4f7;
    --ral-surface: #ffffff;
    --ral-canvas: #faf6f6;
    --ral-danger: #b42318;
    --ral-danger-soft: #fef3f2;
    --ral-gold: #b54708;
    --ral-radius: 18px;
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

/* The sprite only supplies <symbol> definitions — it must never occupy space. */
.ral-chat-sprite {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* Sprite icons carry no width/height attributes, so an unsized <svg> would
   stretch to fill its flex parent. This floor keeps any icon added later sane
   even before it gets its own rule. */
.ral-chat-overlay svg,
.ral-chat-launcher svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    fill: currentColor;
}

/* ============================ launcher ============================ */

.ral-chat-launcher {
    position: fixed;
    right: 24px;
    bottom: 96px;
    z-index: 9990;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px 13px 17px;
    background: var(--ral-red);
    color: #fff;
    border: none;
    border-radius: 999px;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.01em;
    curalr: pointer;
    box-shadow: 0 8px 24px rgba(217, 43, 33, 0.28), 0 2px 6px rgba(16, 24, 40, 0.12);
    transition: transform 0.18s ease, background 0.18s ease, box-shadow 0.18s ease;
}

.ral-chat-launcher:hover {
    background: var(--ral-red-dark);
    transform: translateY(-2px);
    box-shadow: 0 12px 30px rgba(217, 43, 33, 0.34), 0 3px 8px rgba(16, 24, 40, 0.14);
}

.ral-chat-launcher:focus-visible {
    outline: 3px solid var(--ral-red-soft);
    outline-offset: 2px;
}

.ral-chat-launcher-icon {
    width: 21px;
    height: 21px;
    fill: currentColor;
    flex-shrink: 0;
}

/* ============================ overlay shell ============================ */

.ral-chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    background: var(--ral-canvas);
    color: var(--ral-ink);
    animation: ralChatIn 0.22s ease both;
}

.ral-chat-overlay[hidden] {
    display: none;
}

@keyframes ralChatIn {
    from { opacity: 0; transform: scale(0.995); }
    to   { opacity: 1; transform: none; }
}

/* Shared centred column. The header, scroll area and footer each span the full
   viewport width so their backgrounds and borders reach edge to edge, while the
   content inside them lines up on one axis. */
.ral-chat-col {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ============================ header ============================ */

.ral-chat-header {
    flex-shrink: 0;
    background: var(--ral-surface);
    border-bottom: 1px solid var(--ral-line);
}

.ral-chat-header-inner {
    width: 100%;
    max-width: 780px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.ral-chat-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.ral-chat-brand-logo {
    width: auto;
    height: 30px;
    flex-shrink: 0;
}

.ral-chat-brand-rule {
    width: 1px;
    height: 30px;
    background: var(--ral-line);
    flex-shrink: 0;
}

.ral-chat-brand-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ral-chat-brand-title {
    font-size: 15px;
    font-weight: 650;
    line-height: 1.2;
    color: var(--ral-ink);
}

.ral-chat-brand-sub {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    line-height: 1.2;
    color: var(--ral-muted);
}

.ral-chat-live {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #17b26a;
    box-shadow: 0 0 0 3px rgba(23, 178, 106, 0.16);
    flex-shrink: 0;
}

.ral-chat-iconbtn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: var(--ral-muted);
    curalr: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.ral-chat-iconbtn svg {
    width: 17px;
    height: 17px;
    fill: currentColor;
}

.ral-chat-iconbtn:hover {
    background: var(--ral-line-soft);
    color: var(--ral-ink);
}

.ral-chat-iconbtn:focus-visible {
    outline: 2px solid var(--ral-red);
    outline-offset: 1px;
}

/* ============================ scroll area ============================ */

.ral-chat-scroll {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    display: flex;
    flex-direction: column;
    padding: 24px 0 12px;
    scrollbar-width: thin;
    scrollbar-color: #cfd6c8 transparent;
}

/* The column has to fill the scroll area's height so the empty state can centre
   itself vertically in it; once messages exist they flow from the top as usual. */
.ral-chat-scroll > .ral-chat-col {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
}

.ral-chat-scroll::-webkit-scrollbar { width: 10px; }
.ral-chat-scroll::-webkit-scrollbar-thumb {
    background: #cfd6c8;
    border-radius: 999px;
    border: 3px solid var(--ral-canvas);
}

.ral-chat-messages {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* ============================ empty state ============================ */

.ral-chat-empty {
    margin: auto 0; /* vertical auto margins centre it in the free space */
    text-align: center;
    padding: 22px 0 30px;
}

.ral-chat-empty[hidden] { display: none; }

.ral-chat-empty-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ral-red);
    color: #fff;
    box-shadow: 0 8px 22px rgba(217, 43, 33, 0.24);
}

.ral-chat-empty-mark svg {
    width: 29px;
    height: 29px;
    fill: currentColor;
}

.ral-chat-empty-title {
    margin: 18px 0 8px;
    font-size: 27px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ral-ink);
}

.ral-chat-empty-sub {
    margin: 0 auto;
    max-width: 470px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--ral-muted);
}

.ral-chat-suggestions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    margin-top: 26px;
    text-align: left;
}

.ral-chat-suggestion {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 15px 16px;
    background: var(--ral-surface);
    border: 1px solid var(--ral-line);
    border-radius: 14px;
    curalr: pointer;
    font-family: inherit;
    text-align: left;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.ral-chat-suggestion:hover {
    border-color: #bcd3ab;
    box-shadow: 0 6px 18px rgba(16, 24, 40, 0.07);
    transform: translateY(-1px);
}

.ral-chat-suggestion:focus-visible {
    outline: 2px solid var(--ral-red);
    outline-offset: 2px;
}

.ral-chat-suggestion-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    flex-shrink: 0;
    border-radius: 10px;
    background: var(--ral-red-soft);
    color: var(--ral-red);
}

.ral-chat-suggestion-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

.ral-chat-suggestion-body {
    min-width: 0;
}

.ral-chat-suggestion-title {
    display: block;
    font-size: 14px;
    font-weight: 620;
    color: var(--ral-ink);
    line-height: 1.3;
}

.ral-chat-suggestion-hint {
    display: block;
    margin-top: 3px;
    font-size: 12.5px;
    color: var(--ral-muted);
    line-height: 1.4;
}

/* ============================ messages ============================ */

.ral-chat-row {
    display: flex;
    align-items: flex-start;
    gap: 11px;
}

.ral-chat-row.user {
    flex-direction: row-reverse;
}

.ral-chat-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    flex-shrink: 0;
    margin-top: 2px;
    border-radius: 50%;
}

.ral-chat-avatar svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.ral-chat-row.assistant .ral-chat-avatar {
    background: var(--ral-red);
    color: #fff;
}

.ral-chat-row.user .ral-chat-avatar {
    background: var(--ral-line);
    color: var(--ral-muted);
}

/* Back-to-back rows from the same side keep the indent but drop the repeat.
   Needs to out-specify the .ral-chat-row.<role> .ral-chat-avatar rules above. */
.ral-chat-row.assistant .ral-chat-avatar.ral-avatar-spacer,
.ral-chat-row.user .ral-chat-avatar.ral-avatar-spacer {
    background: transparent;
    box-shadow: none;
}

.ral-chat-msg {
    max-width: 100%;
    padding: 12px 16px;
    border-radius: var(--ral-radius);
    font-size: 15px;
    line-height: 1.62;
    white-space: pre-wrap;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.ral-chat-row.assistant .ral-chat-msg {
    background: var(--ral-surface);
    border: 1px solid var(--ral-line);
    border-top-left-radius: 6px;
    color: var(--ral-ink);
    box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

/* The user's own words are short — a narrower bubble reads better and makes the
   two sides visually distinct. Assistant replies keep the full column. */
.ral-chat-row.user .ral-chat-msg {
    max-width: 78%;
    background: var(--ral-red);
    border-top-right-radius: 6px;
    color: #fff;
}

.ral-chat-msg strong { font-weight: 650; }

.ral-chat-row.assistant .ral-chat-msg a {
    color: var(--ral-red);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ral-chat-row.user .ral-chat-msg a {
    color: #fff;
    text-decoration: underline;
}

.ral-chat-msg code {
    background: var(--ral-line-soft);
    border-radius: 5px;
    padding: 1px 5px;
    font-size: 13px;
}

.ral-chat-row.user .ral-chat-msg code {
    background: rgba(255, 255, 255, 0.18);
}

/* status row (tool activity / typing) */

.ral-chat-status {
    display: flex;
    align-items: center;
    gap: 11px;
}

.ral-chat-status-bubble {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 11px 16px;
    background: var(--ral-surface);
    border: 1px solid var(--ral-line);
    border-radius: var(--ral-radius);
    border-top-left-radius: 6px;
    font-size: 13.5px;
    color: var(--ral-muted);
}

.ral-dots {
    display: inline-flex;
    gap: 4px;
}

.ral-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--ral-red);
    opacity: 0.3;
    animation: ralBlink 1.2s infinite both;
}

.ral-dots span:nth-child(2) { animation-delay: 0.18s; }
.ral-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes ralBlink {
    0%, 80%, 100% { opacity: 0.25; }
    40% { opacity: 1; }
}

/* error bubble */

.ral-chat-error {
    align-self: center;
    max-width: 460px;
    background: var(--ral-danger-soft);
    border: 1px solid #fecdca;
    color: var(--ral-danger);
    font-size: 13px;
    text-align: center;
    padding: 10px 16px;
    border-radius: 12px;
}

/* ============================ rich cards ============================ */

.ral-chat-card {
    min-width: 0;
    max-width: 420px;
    background: var(--ral-surface);
    border: 1px solid var(--ral-line);
    border-radius: 16px;
    padding: 0;
    overflow: hidden;
    font-size: 14px;
    box-shadow: 0 2px 8px rgba(16, 24, 40, 0.05);
}

.ral-card-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--ral-red-soft);
    color: var(--ral-red-dark);
    font-weight: 650;
    font-size: 13.5px;
}

.ral-card-head svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
    flex-shrink: 0;
}

.ral-card-body {
    padding: 14px 16px 16px;
}

.ral-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 14px;
    color: var(--ral-muted);
    font-size: 13px;
}

/* resource_type arrives as a raw slug ("room", "desk") from the tool payload. */
.ral-card-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    text-transform: capitalize;
}

.ral-card-meta svg {
    width: 13px;
    height: 13px;
    fill: currentColor;
    opacity: 0.7;
}

.ral-card-total {
    margin-top: 10px;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--ral-red);
}

.ral-card-text {
    margin-top: 8px;
    color: var(--ral-ink);
    line-height: 1.55;
}

/* payment card */

.ral-chat-card.ral-card-payment .ral-card-head {
    background: #fef6ee;
    color: var(--ral-gold);
}

.ral-chat-card.ral-card-confirmed .ral-card-head {
    background: #ecfdf3;
    color: #027a48;
}

.ral-chat-card.ral-signedin .ral-card-head {
    background: #ecfdf3;
    color: #027a48;
}

/* ============================ footer / input ============================ */

.ral-chat-footer {
    flex-shrink: 0;
    background: linear-gradient(to top, var(--ral-canvas) 62%, rgba(247, 249, 245, 0));
    padding: 12px 0 calc(14px + env(safe-area-inset-bottom));
}

.ral-chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.ral-chat-chips:empty { display: none; }

.ral-chat-chip {
    border: 1px solid var(--ral-line);
    background: var(--ral-surface);
    color: var(--ral-red-dark);
    border-radius: 999px;
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 15px;
    curalr: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.ral-chat-chip:hover {
    background: var(--ral-red-soft);
    border-color: #bcd3ab;
}

.ral-chat-inputwrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ral-surface);
    border: 1px solid var(--ral-line);
    border-radius: 22px;
    padding: 7px 7px 7px 16px;
    box-shadow: 0 2px 10px rgba(16, 24, 40, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.ral-chat-inputwrap:focus-within {
    border-color: var(--ral-red);
    box-shadow: 0 0 0 3px rgba(217, 43, 33, 0.1);
}

.ral-chat-input {
    flex: 1;
    border: none;
    outline: none;
    resize: none;
    padding: 9px 0;
    font-family: inherit;
    font-size: 16px; /* 16px keeps iOS from zooming on focus */
    line-height: 1.45;
    max-height: 132px;
    background: transparent;
    color: var(--ral-ink);
}

.ral-chat-input::placeholder { color: #98a2b3; }

.ral-chat-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--ral-red);
    color: #fff;
    curalr: pointer;
    flex-shrink: 0;
    transition: background 0.15s ease, opacity 0.15s ease;
}

.ral-chat-send svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}

.ral-chat-send:hover:not(:disabled) { background: var(--ral-red-dark); }

.ral-chat-send:disabled {
    background: var(--ral-line);
    color: #98a2b3;
    curalr: default;
}

.ral-chat-disclaimer {
    margin: 9px 0 0;
    text-align: center;
    font-size: 11.5px;
    color: #98a2b3;
}

/* body lock while open */

body.ral-chat-open {
    overflow: hidden;
}

/* ============================ responsive ============================ */

@media (max-width: 640px) {
    .ral-chat-launcher {
        right: 16px;
        bottom: 84px;
        padding: 13px 15px;
    }

    .ral-chat-launcher-text { display: none; }

    .ral-chat-col,
    .ral-chat-header-inner { padding-left: 14px; padding-right: 14px; }

    .ral-chat-scroll { padding-top: 20px; }

    .ral-chat-brand-logo { height: 26px; }
    .ral-chat-brand-sub { display: none; }

    .ral-chat-empty-title { font-size: 22px; }
    .ral-chat-empty-sub { font-size: 13.5px; }

    /* Two columns of cards get too cramped to read below ~640px. */
    .ral-chat-suggestions { grid-template-columns: 1fr; gap: 10px; }

    .ral-chat-msg { font-size: 14.5px; padding: 11px 14px; }

    .ral-chat-avatar { width: 28px; height: 28px; }
    .ral-chat-avatar svg { width: 14px; height: 14px; }
}

@media (prefers-reduced-motion: reduce) {
    .ral-chat-overlay,
    .ral-chat-launcher,
    .ral-chat-suggestion,
    .ral-dots span {
        animation: none;
        transition: none;
    }
}

/* ============================ product cards ============================ */

.ral-card-products {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ral-card-product {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 10px 14px;
    border: 1px solid var(--ral-line);
    border-radius: 12px;
    background: var(--ral-surface);
    text-decoration: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

a.ral-card-product:hover {
    border-color: var(--ral-red);
    box-shadow: 0 4px 14px rgba(217, 43, 33, 0.12);
    transform: translateY(-1px);
}

.ral-card-product-name {
    font-weight: 700;
    font-size: 14px;
    color: var(--ral-ink);
}

.ral-card-product-detail {
    font-size: 12.5px;
    color: var(--ral-muted);
}

/* ============================ review fixes ============================ */

/* Hide the textarea scrollbar chrome (Windows arrows) — the input auto-grows. */
.ral-chat-input {
    overflow-y: auto;
    scrollbar-width: none;
}

.ral-chat-input::-webkit-scrollbar {
    display: none;
}

@media (max-width: 480px) {
    .ral-chat-input::placeholder {
        font-size: 13px;
    }
}

/* "New chat" header button shares the icon-button style with the close X. */
.ral-chat-iconbtn + .ral-chat-iconbtn {
    margin-left: 6px;
}

.ral-chat-header-actions {
    display: flex;
    align-items: center;
}
