/* ============================================================================
   JamesPeptides — customer chat widget
   ----------------------------------------------------------------------------
   Shared by the desktop and the mobile storefront. It carries the whole
   conversation: questions answered by James (the LLM), replies typed by an
   operator, and every automated order update — the same single thread the
   Telegram bot used to be.

   Self-contained on purpose: it defines its own tokens with fallbacks so it
   drops onto either page without inheriting or disturbing their styles.
   ========================================================================== */

.jc {
    /* Matches the storefront's planes: the panel is the same step above the page
       as the order column, and the message area sits just below it so the thread
       reads as a surface of its own. */
    --jc-bg:      #14171d;
    --jc-bg-2:    #12151b;
    --jc-raised:  #242932;
    --jc-line:    rgba(255, 255, 255, 0.085);
    --jc-txt:     #e9ecf1;
    --jc-txt-2:   #a6adb9;
    --jc-txt-3:   #767e8b;
    --jc-accent:  #ff4757;
    --jc-ok:      #22c55e;
    --jc-shadow:  0 24px 60px rgba(0, 0, 0, 0.55);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

/* ---- launcher ---- */
.jc-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 140;
    display: flex;
    align-items: center;
    gap: 9px;
    height: 50px;
    padding: 0 20px;
    border: none;
    border-radius: 25px;
    background: var(--jc-accent);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--jc-shadow);
    transition: transform 0.15s cubic-bezier(0.22, 0.61, 0.36, 1), filter 0.15s;
}
.jc-launcher:hover { filter: brightness(1.08); transform: translateY(-1px); }
.jc-launcher[hidden] { display: none; }

/* The count is the whole point of the button now: it says how much is waiting
   before anyone opens anything, so it is a solid chip rather than a dark blob
   on a red field. */
.jc-launcher-badge {
    display: none;
    min-width: 21px;
    height: 21px;
    padding: 0 6px;
    border-radius: 11px;
    background: #ffffff;
    color: var(--jc-accent);
    font-size: 11.5px;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    align-items: center;
    justify-content: center;
}
.jc-launcher-badge.visible { display: inline-flex; }

/* One soft nudge on arrival — enough to be noticed, not enough to nag. */
.jc-launcher.has-unread { animation: jc-nudge 2.4s ease-in-out 1s 2; }
@keyframes jc-nudge {
    0%, 100% { transform: none; }
    6%  { transform: translateY(-3px); }
    12% { transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .jc-launcher.has-unread { animation: none; }
}

/* ---- panel ---- */
.jc-panel {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 150;
    display: none;
    flex-direction: column;
    width: 392px;
    max-width: calc(100vw - 32px);
    height: 620px;
    max-height: calc(100vh - 44px);
    background: var(--jc-bg);
    border: 1px solid var(--jc-line);
    border-radius: 16px;
    box-shadow: var(--jc-shadow);
    overflow: hidden;
}
.jc-panel.open { display: flex; }

.jc-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--jc-line);
    background: #171a21;
}
.jc-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    flex: none;
    border-radius: 50%;
    background: var(--jc-raised);
    color: var(--jc-txt);
    font-size: 14px;
    font-weight: 700;
}
.jc-head-info { flex: 1; min-width: 0; }
.jc-head-name { color: var(--jc-txt); font-size: 14px; font-weight: 650; }
.jc-head-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--jc-txt-3);
    font-size: 11.5px;
}
.jc-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--jc-ok);
    flex: none;
}
.jc-close {
    width: 30px;
    height: 30px;
    flex: none;
    border: none;
    border-radius: 8px;
    background: none;
    color: var(--jc-txt-3);
    font-size: 15px;
    cursor: pointer;
}
.jc-close:hover { background: var(--jc-raised); color: var(--jc-txt); }

/* ---- messages ---- */
.jc-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    background: var(--jc-bg-2);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.jc-msg {
    max-width: 84%;
    padding: 10px 13px;
    border-radius: 14px;
    font-size: 13.5px;
    line-height: 1.55;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}
.jc-msg a { color: #7ab8ff; }
.jc-msg-in {
    align-self: flex-end;
    background: var(--jc-accent);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.jc-msg-out {
    align-self: flex-start;
    background: var(--jc-bg);
    border: 1px solid var(--jc-line);
    color: var(--jc-txt);
    border-bottom-left-radius: 5px;
}
/* Automated order updates read as notices, not as chatter. */
.jc-msg-system {
    align-self: stretch;
    max-width: 100%;
    background: rgba(255, 71, 87, 0.07);
    border: 1px solid rgba(255, 71, 87, 0.24);
    border-radius: 12px;
    color: var(--jc-txt);
}
.jc-msg-label {
    display: block;
    margin-bottom: 5px;
    color: var(--jc-txt-3);
    font-size: 10.5px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}
.jc-time {
    display: block;
    margin-top: 5px;
    font-size: 10.5px;
    opacity: 0.55;
}

.jc-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 12px 14px;
    background: var(--jc-bg);
    border: 1px solid var(--jc-line);
    border-radius: 14px;
    border-bottom-left-radius: 5px;
}
.jc-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--jc-txt-3);
    animation: jc-bounce 1.2s infinite ease-in-out;
}
.jc-typing span:nth-child(2) { animation-delay: 0.15s; }
.jc-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes jc-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.jc-handoff {
    padding: 9px 13px;
    background: rgba(34, 197, 94, 0.10);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 10px;
    color: var(--jc-ok);
    font-size: 12px;
    text-align: center;
}

/* ---- composer ---- */
.jc-foot {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--jc-line);
    background: var(--jc-bg);
}
.jc-input {
    flex: 1;
    min-width: 0;
    max-height: 120px;
    padding: 10px 13px;
    background: var(--jc-bg-2);
    border: 1px solid var(--jc-line);
    border-radius: 12px;
    color: var(--jc-txt);
    font-family: inherit;
    font-size: 13.5px;
    line-height: 1.45;
    resize: none;
    outline: none;
}
.jc-input:focus { border-color: rgba(255, 255, 255, 0.24); }
.jc-input::placeholder { color: var(--jc-txt-3); }

.jc-send {
    width: 40px;
    height: 40px;
    flex: none;
    border: none;
    border-radius: 12px;
    background: var(--jc-accent);
    color: #fff;
    font-size: 15px;
    cursor: pointer;
    transition: filter 0.12s;
}
.jc-send:hover:not(:disabled) { filter: brightness(1.08); }
.jc-send:disabled { background: var(--jc-raised); color: var(--jc-txt-3); cursor: not-allowed; }

.jc-disclaimer {
    padding: 0 12px 11px;
    background: var(--jc-bg);
    color: var(--jc-txt-3);
    font-size: 10.5px;
    line-height: 1.5;
    text-align: center;
}

/* ---- phones: full-screen sheet ---- */
@media (max-width: 640px) {
    .jc-launcher {
        right: 14px;
        bottom: 14px;
        height: 46px;
        padding: 0 16px;
    }
    .jc-panel {
        right: 0;
        bottom: 0;
        left: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border: none;
        border-radius: 0;
    }
}

/* ---- connect invitation ----
   Shown only while we have no way to reach this customer once they close the
   page. It sits above the composer, not over the thread, so it informs without
   interrupting. */
.jc-connect {
    padding: 12px 14px;
    border-top: 1px solid var(--jc-line);
    background: rgba(255, 71, 87, 0.05);
}
.jc-connect p {
    color: var(--jc-txt-2);
    font-size: 12px;
    line-height: 1.55;
}
.jc-connect button,
.jc-connect .jc-connect-cta {
    display: block;
    width: 100%;
    margin-top: 10px;
    padding: 8px 12px;
    border: 1px solid var(--jc-line);
    border-radius: 9px;
    background: none;
    color: var(--jc-txt);
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.12s, border-color 0.12s;
}
.jc-connect button:hover,
.jc-connect .jc-connect-cta:hover {
    background: var(--jc-accent);
    border-color: var(--jc-accent);
    color: #fff;
}
.jc-connect button:disabled { opacity: 0.6; cursor: default; }
.jc-connect-code {
    margin-top: 9px;
    color: var(--jc-txt-3);
    font-size: 11px;
}
.jc-connect-code b {
    color: var(--jc-txt-2);
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* The greeting reads as a message from James, because that is what it is. */
.jc-welcome { max-width: 100%; }
