/* ============================================================
   Stepcraft Live Chat Widget
   ============================================================ */

:root {
    --sc-primary:   #fc8400;
    --sc-primary-d: #e07600;
    --sc-dark:      #1a1a2e;
    --sc-white:     #ffffff;
    --sc-gray:      #f5f5f5;
    --sc-border:    #e5e5e5;
    --sc-radius:    16px;
    --sc-shadow:    0 8px 40px rgba(0,0,0,0.18);
    --sc-font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* Widget wrapper */
.sc-chat-widget {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    font-family: var(--sc-font);
}

/* ── Toggle button ─────────────────────────────────────────── */
.sc-chat-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--sc-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(252,132,0,.45);
    transition: transform .2s, background .2s;
    position: relative;
}

.sc-chat-toggle:hover {
    background: var(--sc-primary-d);
    transform: scale(1.08);
}

.sc-chat-toggle svg {
    width: 26px;
    height: 26px;
    color: var(--sc-white);
    transition: opacity .2s, transform .2s;
    position: absolute;
}

.sc-icon-chat  { opacity: 1;  transform: scale(1); }
.sc-icon-close { opacity: 0;  transform: scale(.6); }
.sc-chat-widget.is-open .sc-icon-chat  { opacity: 0;  transform: scale(.6); }
.sc-chat-widget.is-open .sc-icon-close { opacity: 1;  transform: scale(1); }

/* Badge */
.sc-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    border: 2px solid #fff;
    animation: sc-pop .3s ease;
}

/* Ukryj [hidden] zawsze — nawet gdy CSS ustawia display */
[hidden] { display: none !important; }

@keyframes sc-pop {
    0%   { transform: scale(.5); }
    70%  { transform: scale(1.2); }
    100% { transform: scale(1); }
}

/* ── Okno czatu ────────────────────────────────────────────── */
.sc-chat-box {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 360px;
    max-height: 580px;
    background: var(--sc-white);
    border-radius: var(--sc-radius);
    box-shadow: var(--sc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: sc-open .25s cubic-bezier(.34,1.56,.64,1);
}

@keyframes sc-open {
    from { opacity: 0; transform: scale(.85) translateY(12px); }
    to   { opacity: 1; transform: scale(1)   translateY(0); }
}

/* Nagłówek */
.sc-chat-header {
    background: var(--sc-primary);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.sc-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--sc-white);
}

.sc-chat-header-info strong {
    display: block;
    font-size: 15px;
    line-height: 1.2;
}

.sc-chat-header-info small {
    font-size: 12px;
    opacity: .85;
}

.sc-chat-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #4caf50;
    box-shadow: 0 0 0 3px rgba(76,175,80,.35);
    flex-shrink: 0;
    transition: background .4s, box-shadow .4s;
}

/* ── Formularz ─────────────────────────────────────────────── */
.sc-name-step {
    padding: 20px 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    flex: 1;
}

.sc-form-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    line-height: 1.4;
}

.sc-form-label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 13px;
    color: #555;
    font-weight: 500;
}

.sc-form-label input,
.sc-form-label textarea {
    padding: 9px 13px;
    border: 1.5px solid var(--sc-border);
    border-radius: 10px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color .2s;
    color: #111;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}

.sc-form-label textarea {
    resize: vertical;
    min-height: 72px;
}

.sc-form-label input:focus,
.sc-form-label textarea:focus {
    border-color: var(--sc-primary);
}

.sc-required { color: #e53935; font-size: 12px; }
.sc-optional  { color: #aaa;    font-size: 11px; font-weight: 400; }

.sc-form-error {
    background: #fdecea;
    border: 1px solid #f5c6c6;
    color: #c0392b;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
}

.sc-btn-primary {
    background: var(--sc-primary);
    color: var(--sc-white);
    border: none;
    border-radius: 10px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background .2s;
    margin-top: 4px;
}

.sc-btn-primary:hover  { background: var(--sc-primary-d); }
.sc-btn-primary:disabled { background: #ccc; cursor: not-allowed; }

/* Offline tytuł */
.sc-offline-title {
    color: #555;
}

.sc-offline-title small {
    font-size: 12px;
    font-weight: 400;
    color: #888;
}

/* Potwierdzenie offline */
.sc-offline-thanks {
    text-align: center;
    padding: 40px 20px;
    justify-content: center;
    align-items: center;
}

.sc-thanks-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.sc-offline-thanks p {
    margin: 6px 0;
    font-size: 14px;
    color: #555;
}

/* ── Lista wiadomości ──────────────────────────────────────── */
.sc-messages-wrap {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fafafa;
}

.sc-messages-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sc-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
}

.sc-msg-admin   { align-self: flex-start; align-items: flex-start; }
.sc-msg-visitor { align-self: flex-end;   align-items: flex-end; }

.sc-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.sc-msg-admin .sc-msg-bubble {
    background: var(--sc-white);
    color: #222;
    border: 1px solid var(--sc-border);
    border-bottom-left-radius: 4px;
}

.sc-msg-visitor .sc-msg-bubble {
    background: var(--sc-primary);
    color: var(--sc-white);
    border-bottom-right-radius: 4px;
}

.sc-msg-time {
    font-size: 10px;
    color: #aaa;
    margin-top: 3px;
    padding: 0 4px;
}

/* ── Typing indicator — TYLKO gdy aktywny ─────────────────── */
.sc-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 10px 14px;
    background: var(--sc-white);
    border: 1px solid var(--sc-border);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

/* Domyślnie ukryty przez klasę (nie [hidden]) */
.sc-typing--hidden {
    display: none !important;
}

.sc-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--sc-primary);
    animation: sc-bounce 1.2s infinite ease-in-out;
}

.sc-typing span:nth-child(2) { animation-delay: .2s; }
.sc-typing span:nth-child(3) { animation-delay: .4s; }

@keyframes sc-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40%            { transform: translateY(-6px); }
}

/* ── Pole wpisywania ───────────────────────────────────────── */
.sc-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--sc-border);
    background: var(--sc-white);
    flex-shrink: 0;
}

.sc-input-wrap textarea {
    flex: 1;
    border: 1px solid var(--sc-border);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color .2s;
    line-height: 1.4;
}

.sc-input-wrap textarea:focus {
    border-color: var(--sc-primary);
}

.sc-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--sc-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--sc-white);
    flex-shrink: 0;
    transition: background .2s, transform .15s;
}

.sc-send-btn:hover     { background: var(--sc-primary-d); transform: scale(1.08); }
.sc-send-btn:disabled  { background: #ccc; cursor: not-allowed; transform: none; }

/* Mobile */
@media (max-width: 420px) {
    .sc-chat-widget { bottom: 16px; right: 16px; }
    .sc-chat-box    { width: calc(100vw - 32px); right: 0; }
}
