/*
 * The live chat widget's look (tarka-web-design/live-chat).
 *
 * Every colour is a variable. Live chat settings set --lc-accent,
 * --lc-on-accent, --lc-surface, --lc-text and --lc-font on the widget;
 * left empty, they follow the site's own Tailwind tokens (--color-brand,
 * --color-on-brand, --color-ink, --font-sans). A site's stylesheet, or the
 * builder's CSS in Live chat settings, can restyle any .tlc-* class.
 * Everything is scoped under #tarka-live-chat so the site's own styles and
 * ours keep out of each other's way.
 */
#tarka-live-chat {
    --tlc-accent: var(--lc-accent, var(--color-brand, #1f2937));
    --tlc-on-accent: var(--lc-on-accent, var(--color-on-brand, #ffffff));
    --tlc-surface: var(--lc-surface, #ffffff);
    --tlc-text: var(--lc-text, var(--color-ink, #111827));
    --tlc-font: var(--lc-font, var(--font-sans, inherit));
    --tlc-muted: color-mix(in srgb, var(--tlc-text) 64%, var(--tlc-surface));
    --tlc-line: color-mix(in srgb, var(--tlc-text) 14%, var(--tlc-surface));
    --tlc-soft: color-mix(in srgb, var(--tlc-text) 6%, var(--tlc-surface));
    --tlc-radius: 20px;
    --tlc-button-radius: 999px;
    --tlc-bubble-radius: 16px;
    --tlc-bottom: calc(var(--lc-bottom, 20px) + env(safe-area-inset-bottom, 0px));
    --tlc-side: var(--lc-side, 20px);
    --tlc-online: #16a34a;

    position: relative;
    /* Above everything, the site builder's staging pill and bar included: live chat has the priority. */
    z-index: 2147483647;
    font-family: var(--tlc-font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--tlc-text);
}

#tarka-live-chat.tlc-corners-soft { --tlc-radius: 10px; --tlc-button-radius: 10px; --tlc-bubble-radius: 10px; }
#tarka-live-chat.tlc-corners-square { --tlc-radius: 0; --tlc-button-radius: 0; --tlc-bubble-radius: 2px; }

#tarka-live-chat[hidden] { display: none; }
#tarka-live-chat *, #tarka-live-chat *::before, #tarka-live-chat *::after { box-sizing: border-box; }
#tarka-live-chat [hidden] { display: none !important; }

#tarka-live-chat button,
#tarka-live-chat input,
#tarka-live-chat textarea {
    font: inherit;
    color: inherit;
    letter-spacing: normal;
    text-transform: none;
    margin: 0;
}

#tarka-live-chat button { cursor: pointer; }
#tarka-live-chat button:disabled { cursor: default; opacity: 0.6; }

#tarka-live-chat .tlc-icon { width: 22px; height: 22px; flex: none; }

/* ---------------------------------------------------------------- The launcher */

#tarka-live-chat .tlc-launcher {
    position: fixed;
    bottom: var(--tlc-bottom);
    right: var(--tlc-side);
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 0 22px 0 18px;
    border: 0;
    border-radius: var(--tlc-button-radius);
    background: var(--tlc-accent);
    color: var(--tlc-on-accent);
    font-weight: 600;
    font-size: 16px;
    box-shadow: 0 10px 30px -8px rgb(0 0 0 / 0.35), 0 2px 6px rgb(0 0 0 / 0.12);
    transform: translateY(calc(-1 * var(--tlc-lift, 0px)));
    transition: box-shadow 0.2s ease;
}

/* It slides when it steps out of the way, but not into its first place on a page that has just loaded. */
#tarka-live-chat.tlc-settled .tlc-launcher { transition: transform 0.25s ease, box-shadow 0.2s ease; }

#tarka-live-chat.tlc-left .tlc-launcher { right: auto; left: var(--tlc-side); }
#tarka-live-chat .tlc-launcher:hover { box-shadow: 0 14px 34px -8px rgb(0 0 0 / 0.42), 0 2px 6px rgb(0 0 0 / 0.14); }
#tarka-live-chat .tlc-launcher:focus-visible,
#tarka-live-chat .tlc-panel :focus-visible { outline: 3px solid color-mix(in srgb, var(--tlc-accent) 55%, transparent); outline-offset: 2px; }

#tarka-live-chat.tlc-launcher-round .tlc-launcher { width: 60px; height: 60px; padding: 0; justify-content: center; border-radius: 999px; }
#tarka-live-chat.tlc-launcher-round .tlc-launcher .tlc-icon { width: 28px; height: 28px; }
#tarka-live-chat.tlc-launcher-round .tlc-launcher-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

#tarka-live-chat.tlc-launcher-tab .tlc-launcher {
    bottom: 30vh;
    right: 0;
    min-height: 0;
    padding: 16px 12px;
    writing-mode: vertical-rl;
    border-radius: var(--tlc-radius) 0 0 var(--tlc-radius);
}
#tarka-live-chat.tlc-launcher-tab.tlc-left .tlc-launcher { left: 0; right: auto; border-radius: 0 var(--tlc-radius) var(--tlc-radius) 0; }
#tarka-live-chat.tlc-launcher-tab .tlc-launcher .tlc-icon { transform: rotate(90deg); }

#tarka-live-chat .tlc-dot {
    width: 10px;
    height: 10px;
    border-radius: 999px;
    background: var(--tlc-online);
    box-shadow: 0 0 0 2px var(--tlc-accent);
    flex: none;
}
#tarka-live-chat.tlc-launcher-round .tlc-launcher .tlc-dot { position: absolute; top: 6px; right: 6px; }

#tarka-live-chat .tlc-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    border-radius: 999px;
    background: #dc2626;
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 22px;
    text-align: center;
    writing-mode: horizontal-tb;
}

/* A reply that arrived while the panel was shut, beside the launcher. */
#tarka-live-chat .tlc-peek {
    position: fixed;
    bottom: calc(var(--tlc-bottom) + 66px);
    right: var(--tlc-side);
    max-width: min(320px, calc(100vw - 2 * var(--tlc-side)));
    padding: 12px 16px;
    border: 1px solid var(--tlc-line);
    border-radius: var(--tlc-bubble-radius);
    background: var(--tlc-surface);
    color: var(--tlc-text);
    text-align: left;
    box-shadow: 0 12px 30px -10px rgb(0 0 0 / 0.3);
    transform: translateY(calc(-1 * var(--tlc-lift, 0px)));
}
#tarka-live-chat.tlc-left .tlc-peek { right: auto; left: var(--tlc-side); }

/* ---------------------------------------------------------------- The panel */

#tarka-live-chat .tlc-panel {
    position: fixed;
    bottom: calc(var(--tlc-bottom) + 70px);
    right: var(--tlc-side);
    display: flex;
    flex-direction: column;
    width: min(390px, calc(100vw - 2 * var(--tlc-side)));
    height: min(640px, calc(100dvh - var(--tlc-bottom) - 100px));
    overflow: hidden;
    border: 1px solid var(--tlc-line);
    border-radius: var(--tlc-radius);
    background: var(--tlc-surface);
    color: var(--tlc-text);
    box-shadow: 0 30px 60px -20px rgb(0 0 0 / 0.4), 0 4px 14px rgb(0 0 0 / 0.1);
    transform: translateY(calc(-1 * var(--tlc-lift, 0px)));
}
#tarka-live-chat.tlc-left .tlc-panel { right: auto; left: var(--tlc-side); }
#tarka-live-chat.tlc-launcher-tab .tlc-panel { bottom: max(16px, calc(30vh - 120px)); right: 56px; }
#tarka-live-chat.tlc-launcher-tab.tlc-left .tlc-panel { right: auto; left: 56px; }

#tarka-live-chat .tlc-head {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 16px 14px 16px 20px;
    background: var(--tlc-accent);
    color: var(--tlc-on-accent);
}
#tarka-live-chat .tlc-head-words { flex: 1; min-width: 0; }
#tarka-live-chat .tlc-title { margin: 0; font-size: 17px; font-weight: 700; line-height: 1.3; }
#tarka-live-chat .tlc-status { margin: 2px 0 0; font-size: 13px; line-height: 1.4; opacity: 0.9; }
#tarka-live-chat .tlc-head-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    flex: none;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: inherit;
}
#tarka-live-chat .tlc-head-button:hover { background: color-mix(in srgb, var(--tlc-on-accent) 16%, transparent); }
#tarka-live-chat .tlc-back { margin-left: -10px; }

#tarka-live-chat .tlc-body { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }

#tarka-live-chat .tlc-home,
#tarka-live-chat .tlc-form { padding: 20px; }
#tarka-live-chat .tlc-heading { margin: 0 0 6px; font-size: 20px; font-weight: 700; line-height: 1.25; }
#tarka-live-chat .tlc-intro { margin: 0 0 16px; color: var(--tlc-muted); }
#tarka-live-chat .tlc-choices { display: grid; gap: 10px; }
#tarka-live-chat .tlc-choice {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 16px 18px;
    border: 1px solid var(--tlc-line);
    border-radius: calc(var(--tlc-radius) * 0.7);
    background: var(--tlc-soft);
    font-weight: 600;
    text-align: left;
}
#tarka-live-chat .tlc-choice span:not(.tlc-dot) { flex: 1; }
#tarka-live-chat .tlc-choice:hover { border-color: var(--tlc-accent); }
#tarka-live-chat .tlc-choice-chat { background: var(--tlc-accent); border-color: var(--tlc-accent); color: var(--tlc-on-accent); }

#tarka-live-chat .tlc-field { margin: 0 0 12px; }
#tarka-live-chat .tlc-field label { display: block; margin: 0 0 4px; font-size: 13px; font-weight: 600; }
#tarka-live-chat .tlc-field input,
#tarka-live-chat .tlc-field textarea,
#tarka-live-chat .tlc-compose textarea {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--tlc-line);
    border-radius: calc(var(--tlc-radius) * 0.5);
    background: var(--tlc-surface);
    font-size: 16px;
    line-height: 1.4;
    resize: vertical;
}
#tarka-live-chat .tlc-field input:focus,
#tarka-live-chat .tlc-field textarea:focus,
#tarka-live-chat .tlc-compose textarea:focus { outline: none; border-color: var(--tlc-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--tlc-accent) 25%, transparent); }

#tarka-live-chat .tlc-submit {
    width: 100%;
    min-height: 48px;
    margin-top: 4px;
    border: 0;
    border-radius: var(--tlc-button-radius);
    background: var(--tlc-accent);
    color: var(--tlc-on-accent);
    font-weight: 700;
}
#tarka-live-chat .tlc-small { margin: 10px 0 0; font-size: 12px; color: var(--tlc-muted); text-align: center; }
#tarka-live-chat .tlc-error { margin: 0 0 10px; color: #b91c1c; font-size: 14px; }
#tarka-live-chat .tlc-hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* ---------------------------------------------------------------- The conversation */

#tarka-live-chat .tlc-thread { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#tarka-live-chat .tlc-messages { flex: 1; min-height: 0; overflow-y: auto; padding: 18px 16px 8px; display: flex; flex-direction: column; gap: 8px; }
#tarka-live-chat .tlc-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: var(--tlc-bubble-radius);
    white-space: pre-line;
    overflow-wrap: anywhere;
}
#tarka-live-chat .tlc-bubble a { color: inherit; text-decoration: underline; }
#tarka-live-chat .tlc-from-admin { align-self: flex-start; background: var(--tlc-soft); border-bottom-left-radius: 4px; }
#tarka-live-chat .tlc-form > .tlc-from-admin { margin: 0 0 16px; }
#tarka-live-chat .tlc-from-visitor { align-self: flex-end; background: var(--tlc-accent); color: var(--tlc-on-accent); border-bottom-right-radius: 4px; }
#tarka-live-chat .tlc-author { display: block; font-size: 12px; font-weight: 700; color: var(--tlc-muted); }
#tarka-live-chat .tlc-note { align-self: center; max-width: 92%; margin: 4px 0; font-size: 13px; color: var(--tlc-muted); text-align: center; }

#tarka-live-chat .tlc-compose { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--tlc-line); }
#tarka-live-chat .tlc-compose textarea { flex: 1; min-height: 44px; max-height: 140px; resize: none; }
#tarka-live-chat .tlc-send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex: none;
    border: 0;
    border-radius: var(--tlc-button-radius);
    background: var(--tlc-accent);
    color: var(--tlc-on-accent);
}
#tarka-live-chat .tlc-thread-foot { padding: 0 16px 10px; text-align: center; }
#tarka-live-chat .tlc-link { padding: 4px; border: 0; background: none; font-size: 13px; color: var(--tlc-muted); text-decoration: underline; }

/* ---------------------------------------------------------------- Phones */

@media (max-width: 639px) {
    #tarka-live-chat .tlc-launcher { min-height: 50px; padding: 0 18px 0 14px; font-size: 15px; }

    /* Open, the panel is a sheet across the bottom of the screen, and the launcher steps aside. */
    #tarka-live-chat .tlc-panel,
    #tarka-live-chat.tlc-left .tlc-panel,
    #tarka-live-chat.tlc-launcher-tab .tlc-panel {
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: min(100dvh, 720px);
        max-height: 100dvh;
        border-radius: var(--tlc-radius) var(--tlc-radius) 0 0;
        border-width: 1px 0 0;
        transform: none;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    #tarka-live-chat.tlc-is-open .tlc-launcher { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    #tarka-live-chat .tlc-launcher,
    #tarka-live-chat .tlc-panel { transition: none; }
}

@media print {
    #tarka-live-chat { display: none !important; }
}
