/* ============================================================================
   Threshold AI -- the "how do I get guests to take their shoes off" coach
   getyourcrocsoff.com  ·  Apple Liquid-Glass chat panel

   Uses the existing apple-polish / index.html design tokens:
     --accent #ff6a1f, --accent-press, --accent-soft, --ink / --ink-2..4,
     --bg-soft / --bg-elevated, --radius*, --ease / --ease-spring, --t-*.
   Honors prefers-reduced-motion and [data-theme="dark"].
   ============================================================================ */

:root {
    --tc-z: 2147483000;                      /* above page, below the network-bar chrome */
    --tc-panel-w: 432px;
    --tc-glass: color-mix(in oklab, var(--bg-soft, #fbfbfd) 78%, transparent);
    --tc-glass-strong: color-mix(in oklab, var(--bg-elevated, #f5f5f7) 88%, transparent);
    --tc-hairline: color-mix(in oklab, var(--ink, #1d1d1f) 12%, transparent);
    --tc-bubble-user: color-mix(in oklab, var(--accent, #ff6a1f) 16%, transparent);
    --tc-bubble-ai: color-mix(in oklab, var(--ink, #1d1d1f) 6%, transparent);
    --tc-shadow: 0 30px 80px -28px color-mix(in oklab, var(--ink, #1d1d1f) 60%, transparent);
}
[data-theme="dark"] {
    --tc-glass: color-mix(in oklab, #0a0a0a 72%, transparent);
    --tc-glass-strong: color-mix(in oklab, #161617 86%, transparent);
    --tc-hairline: color-mix(in oklab, #f5f5f7 14%, transparent);
    --tc-bubble-ai: color-mix(in oklab, #f5f5f7 8%, transparent);
    --tc-shadow: 0 30px 90px -24px rgba(0, 0, 0, 0.8);
}

/* ---- Launch capsule (persistent, bottom-right above the network-bar) ------- */
.tc-launch {
    position: fixed;
    right: 22px;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 78px);
    z-index: var(--tc-z);
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 13px 20px 13px 16px;
    border: 1px solid color-mix(in oklab, #fff 26%, transparent);
    border-radius: 999px;
    background: linear-gradient(180deg, var(--accent, #ff6a1f), var(--accent-press, #e85a14));
    color: #fff;
    font: 600 14.5px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", sans-serif;
    letter-spacing: -0.01em;
    cursor: pointer;
    box-shadow: 0 12px 30px -10px color-mix(in oklab, var(--accent, #ff6a1f) 78%, transparent),
                inset 0 1px 0 color-mix(in oklab, #fff 42%, transparent);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    transition: transform var(--t-fast, 0.18s) var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)),
                box-shadow var(--t-fast, 0.18s) var(--ease, ease),
                opacity 0.3s var(--ease, ease);
    will-change: transform;
}
.tc-launch:hover { transform: translateY(-2px) scale(1.02); }
.tc-launch:active { transform: translateY(0) scale(0.98); }
.tc-launch[hidden] { display: none; }
.tc-launch .tc-launch-glyph {
    width: 19px; height: 19px;
    display: inline-flex; align-items: center; justify-content: center;
}
.tc-launch .tc-launch-glyph svg { width: 19px; height: 19px; }
.tc-launch .tc-launch-pulse {
    width: 7px; height: 7px; border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 0 color-mix(in oklab, #fff 80%, transparent);
    animation: tc-pulse 2.4s var(--ease, ease) infinite;
}
@keyframes tc-pulse {
    0% { box-shadow: 0 0 0 0 color-mix(in oklab, #fff 70%, transparent); }
    70% { box-shadow: 0 0 0 9px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

/* ---- Scrim + panel --------------------------------------------------------- */
.tc-scrim {
    position: fixed;
    inset: 0;
    z-index: var(--tc-z);
    background: color-mix(in oklab, var(--ink, #1d1d1f) 38%, transparent);
    -webkit-backdrop-filter: blur(3px);
    backdrop-filter: blur(3px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.32s var(--ease, ease);
}
.tc-scrim.tc-open { opacity: 1; pointer-events: auto; }

.tc-panel {
    position: fixed;
    top: 0;
    right: 0;
    z-index: calc(var(--tc-z) + 1);
    width: min(var(--tc-panel-w), 100vw);
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--tc-glass);
    -webkit-backdrop-filter: blur(40px) saturate(1.8);
    backdrop-filter: blur(40px) saturate(1.8);
    border-left: 1px solid var(--tc-hairline);
    box-shadow: var(--tc-shadow);
    transform: translateX(102%);
    transition: transform 0.42s var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1));
    will-change: transform;
}
.tc-panel.tc-open { transform: translateX(0); }

/* specular top edge */
.tc-panel::before {
    content: "";
    position: absolute;
    inset: 0 0 auto 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, color-mix(in oklab, #fff 55%, transparent), transparent);
    pointer-events: none;
}

/* ---- Header ---------------------------------------------------------------- */
.tc-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px 16px;
    border-bottom: 1px solid var(--tc-hairline);
}
.tc-head-mark {
    width: 38px; height: 38px;
    flex: 0 0 auto;
    border-radius: 12px;
    display: grid; place-items: center;
    color: #fff;
    background: linear-gradient(180deg, var(--accent, #ff6a1f), var(--accent-press, #e85a14));
    box-shadow: inset 0 1px 0 color-mix(in oklab, #fff 45%, transparent);
}
.tc-head-mark svg { width: 21px; height: 21px; }
.tc-head-text { flex: 1 1 auto; min-width: 0; }
.tc-head-text h3 {
    margin: 0;
    font: 650 16px/1.15 -apple-system, BlinkMacSystemFont, "SF Pro Display", sans-serif;
    letter-spacing: -0.02em;
    color: var(--ink, #1d1d1f);
}
.tc-head-text p {
    margin: 3px 0 0;
    font-size: 12.5px;
    color: var(--ink-3, #6e6e73);
    display: flex; align-items: center; gap: 6px;
}
.tc-status-dot {
    width: 7px; height: 7px; border-radius: 50%;
    background: #34c759;
    box-shadow: 0 0 0 0 color-mix(in oklab, #34c759 70%, transparent);
    animation: tc-dot 2.6s var(--ease, ease) infinite;
}
.tc-status-dot.tc-offline { background: var(--ink-4, #86868b); animation: none; }
@keyframes tc-dot {
    0% { box-shadow: 0 0 0 0 color-mix(in oklab, #34c759 60%, transparent); }
    70% { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
.tc-close {
    flex: 0 0 auto;
    width: 34px; height: 34px;
    border: 1px solid var(--tc-hairline);
    border-radius: 10px;
    background: var(--tc-bubble-ai);
    color: var(--ink-2, #424245);
    cursor: pointer;
    display: grid; place-items: center;
    transition: background var(--t-fast, 0.18s) var(--ease, ease), transform var(--t-fast, 0.18s) var(--ease, ease);
}
.tc-close:hover { background: color-mix(in oklab, var(--ink, #1d1d1f) 12%, transparent); transform: scale(1.05); }
.tc-close svg { width: 14px; height: 14px; }

/* ---- Message scroller ------------------------------------------------------ */
.tc-scroll {
    flex: 1 1 auto;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 18px 16px 8px;
    display: flex;
    flex-direction: column;
    gap: 13px;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}
.tc-scroll::-webkit-scrollbar { width: 8px; }
.tc-scroll::-webkit-scrollbar-thumb {
    background: color-mix(in oklab, var(--ink, #1d1d1f) 18%, transparent);
    border-radius: 8px;
}

.tc-msg {
    max-width: 88%;
    padding: 11px 14px;
    border-radius: 16px;
    font: 400 14.5px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    color: var(--ink, #1d1d1f);
    white-space: pre-wrap;
    word-wrap: break-word;
    animation: tc-msg-in 0.34s var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)) both;
}
@keyframes tc-msg-in {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to { opacity: 1; transform: none; }
}
.tc-msg.tc-user {
    align-self: flex-end;
    background: var(--tc-bubble-user);
    border: 1px solid color-mix(in oklab, var(--accent, #ff6a1f) 30%, transparent);
    border-bottom-right-radius: 5px;
}
.tc-msg.tc-ai {
    align-self: flex-start;
    background: var(--tc-bubble-ai);
    border: 1px solid var(--tc-hairline);
    border-bottom-left-radius: 5px;
}
.tc-msg.tc-error {
    align-self: flex-start;
    background: var(--tc-bubble-ai);
    color: var(--ink-2, #424245);
    font-size: 13px;
    border: 1px solid var(--tc-hairline);
}

/* typing shimmer */
.tc-typing { display: inline-flex; gap: 4px; align-items: center; padding: 4px 2px; }
.tc-typing span {
    width: 7px; height: 7px; border-radius: 50%;
    background: var(--accent, #ff6a1f);
    opacity: 0.5;
    animation: tc-typing 1.1s var(--ease, ease) infinite;
}
.tc-typing span:nth-child(2) { animation-delay: 0.15s; }
.tc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes tc-typing {
    0%, 60%, 100% { opacity: 0.35; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-3px); }
}

/* model meta line under an AI bubble */
.tc-meta {
    align-self: flex-start;
    margin: -6px 0 2px 4px;
    font-size: 11px;
    color: var(--ink-4, #86868b);
    display: flex; align-items: center; gap: 6px;
}
.tc-meta .tc-meta-chip {
    padding: 2px 7px;
    border-radius: 999px;
    background: var(--tc-bubble-ai);
    border: 1px solid var(--tc-hairline);
}

/* ---- Action cards (recommend envelope) ------------------------------------- */
.tc-actions {
    align-self: flex-start;
    max-width: 92%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: -2px;
    animation: tc-msg-in 0.4s var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)) both;
}
.tc-chip {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 13px;
    border-radius: 12px;
    border: 1px solid color-mix(in oklab, var(--accent, #ff6a1f) 34%, var(--tc-hairline));
    background: var(--tc-glass-strong);
    -webkit-backdrop-filter: blur(16px) saturate(1.5);
    backdrop-filter: blur(16px) saturate(1.5);
    color: var(--ink, #1d1d1f);
    font: 550 13px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    cursor: pointer;
    transition: transform var(--t-fast, 0.18s) var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)),
                box-shadow var(--t-fast, 0.18s) var(--ease, ease),
                border-color var(--t-fast, 0.18s) var(--ease, ease);
}
.tc-chip:hover {
    transform: translateY(-2px);
    border-color: color-mix(in oklab, var(--accent, #ff6a1f) 60%, transparent);
    box-shadow: 0 12px 24px -14px color-mix(in oklab, var(--accent, #ff6a1f) 70%, transparent);
}
.tc-chip:active { transform: translateY(0) scale(0.97); }
.tc-chip.tc-chip-done {
    border-color: color-mix(in oklab, #34c759 50%, transparent);
    color: #1d8a3f;
}
[data-theme="dark"] .tc-chip.tc-chip-done { color: #5be584; }
.tc-chip .tc-chip-glyph {
    width: 15px; height: 15px; color: var(--accent, #ff6a1f);
    display: inline-flex;
}
.tc-chip .tc-chip-glyph svg { width: 15px; height: 15px; }
.tc-chip.tc-chip-done .tc-chip-glyph { color: #34c759; }

/* ---- Seed prompts ---------------------------------------------------------- */
.tc-seeds {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 16px 10px;
}
.tc-seed {
    padding: 8px 13px;
    border-radius: 999px;
    border: 1px solid var(--tc-hairline);
    background: var(--tc-bubble-ai);
    color: var(--ink-2, #424245);
    font: 500 12.5px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    cursor: pointer;
    transition: transform var(--t-fast, 0.18s) var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)),
                background var(--t-fast, 0.18s) var(--ease, ease),
                color var(--t-fast, 0.18s) var(--ease, ease);
}
.tc-seed:hover {
    transform: translateY(-2px);
    background: var(--accent-soft, rgba(255, 106, 31, 0.1));
    color: var(--accent, #ff6a1f);
    border-color: color-mix(in oklab, var(--accent, #ff6a1f) 40%, transparent);
}

/* ---- Composer -------------------------------------------------------------- */
.tc-composer {
    flex: 0 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 9px;
    padding: 12px 16px calc(env(safe-area-inset-bottom, 0px) + 16px);
    border-top: 1px solid var(--tc-hairline);
    background: var(--tc-glass-strong);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
}
.tc-input {
    flex: 1 1 auto;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    padding: 11px 14px;
    border-radius: 14px;
    border: 1px solid var(--tc-hairline);
    background: var(--tc-glass);
    color: var(--ink, #1d1d1f);
    font: 400 14.5px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", sans-serif;
    outline: none;
    transition: border-color var(--t-fast, 0.18s) var(--ease, ease),
                box-shadow var(--t-fast, 0.18s) var(--ease, ease);
}
.tc-input::placeholder { color: var(--ink-4, #86868b); }
.tc-input:focus {
    border-color: color-mix(in oklab, var(--accent, #ff6a1f) 55%, transparent);
    box-shadow: 0 0 0 4px var(--accent-soft, rgba(255, 106, 31, 0.1));
}
.tc-send {
    flex: 0 0 auto;
    width: 44px; height: 44px;
    border: none;
    border-radius: 13px;
    background: linear-gradient(180deg, var(--accent, #ff6a1f), var(--accent-press, #e85a14));
    color: #fff;
    cursor: pointer;
    display: grid; place-items: center;
    box-shadow: inset 0 1px 0 color-mix(in oklab, #fff 40%, transparent);
    transition: transform var(--t-fast, 0.18s) var(--ease-spring, cubic-bezier(0.32, 0.72, 0, 1)),
                opacity var(--t-fast, 0.18s) var(--ease, ease);
}
.tc-send:hover { transform: scale(1.06); }
.tc-send:active { transform: scale(0.94); }
.tc-send:disabled { opacity: 0.4; cursor: default; transform: none; }
.tc-send svg { width: 19px; height: 19px; }

/* ---- Responsive: centered modal on small screens --------------------------- */
@media (max-width: 560px) {
    .tc-panel {
        width: 100vw;
        height: 100dvh;
        border-left: none;
    }
    .tc-launch { right: 14px; bottom: calc(env(safe-area-inset-bottom, 0px) + 72px); padding: 12px 16px; }
    .tc-launch .tc-launch-label { font-size: 13.5px; }
}

/* ---- Reduced motion -------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .tc-panel, .tc-scrim, .tc-msg, .tc-actions, .tc-chip, .tc-seed, .tc-launch, .tc-send, .tc-close {
        transition: none !important;
        animation: none !important;
    }
    .tc-panel { transform: translateX(0); }
    .tc-panel:not(.tc-open) { transform: translateX(102%); }
    .tc-status-dot, .tc-launch-pulse, .tc-typing span { animation: none !important; }
}
