/* SLIMHOST Chat - Styles (стиль сайту slimhost.com.ua, тема slimhost-new) */

:root {
    --red: #c84d50;
    --red-dk: #a03d40;
    --red-soft: #fbeeee;
    --bg: #f5f6f8;
    --surface: #fff;
    --surface2: #e2e4e7;
    --border: #dde0e5;
    --border2: #d0d2d6;
    --text: #595959;
    --strong: #333;
    --muted: #6b7079;
    --ok: #2e9e5b;
    --ok-soft: #eaf6ef;
    --shadow: 0 6px 18px rgba(0,0,0,.08);
    --font: 'Open Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    --r: 8px;
    --gutter: max(16px, calc((100% - 860px) / 2));
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    overflow-x: hidden;
    max-width: 100vw;
    -webkit-font-smoothing: antialiased;
}

@media (max-width: 480px) {
    body { font-size: 14px; }
}

/* ---------- Шапка ---------- */

.chat-header {
    background: var(--surface);
    box-shadow: inset 0 4px 0 0 #c9cdd0, 0 1px 0 var(--border);
    padding: 4px 16px 0;
    min-height: 56px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex: 0 0 auto;
    position: relative;
    z-index: 5;
}

.chat-header-brand {
    display: flex;
    align-items: center;
    min-width: 0;
    color: var(--strong);
    text-decoration: none;
}

.chat-header-brand img {
    display: block;
    height: 28px;
    width: auto;
    max-width: 100%;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--strong);
    letter-spacing: .3px;
}

.chat-header-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 0 0 auto;
}

/* Перемикач мови (як .seg на сайті) */
.seg {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px;
    gap: 2px;
}

.seg button {
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text);
    background: transparent;
    border: 0;
    border-radius: 4px;
    padding: 5px 11px;
    cursor: pointer;
    transition: background .15s, color .15s;
}

.seg button:hover {
    background: var(--red-soft);
    color: var(--red-dk);
}

.seg button.on,
.seg button.on:hover {
    background: var(--red);
    color: #fff;
}

.chat-header-close {
    display: none;
    font: inherit;
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 6px;
    padding: 8px 14px;
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
}

.chat-header-close:hover {
    border-color: var(--red);
    color: var(--red);
    background: var(--red-soft);
}

@media (max-width: 480px) {
    .chat-header { padding: 4px 10px 0; }
    .chat-header-brand img { height: 22px; }
    .chat-header-tools { gap: 6px; }
    .seg button { padding: 5px 8px; }
    .chat-header-close { padding: 8px 10px; }
}

/* ---------- Повідомлення ---------- */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px var(--gutter);
    background: var(--bg);
    -webkit-overflow-scrolling: touch;
}

.message {
    margin-bottom: 12px;
    display: flex;
    flex-direction: column;
}

.message.user    { align-items: flex-end; }
.message.manager { align-items: flex-start; }

.message-bubble {
    max-width: 75%;
    padding: 9px 13px;
    border-radius: var(--r);
    word-wrap: break-word;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.message.user .message-bubble {
    background: var(--red);
    color: #fff;
    border-bottom-right-radius: 2px;
}

.message.manager .message-bubble {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-bottom-left-radius: 2px;
    box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.message-text { white-space: pre-wrap; }

.message-sender {
    margin-bottom: 3px;
    font-size: 12px;
    font-weight: 700;
    color: var(--red);
}

.message-time {
    font-size: 11px;
    color: var(--muted);
    margin-top: 3px;
    padding: 0 4px;
}

.message-file img {
    display: block;
    max-width: 220px;
    max-height: 220px;
    border-radius: 6px;
    margin-top: 6px;
    cursor: zoom-in;
    transition: opacity .15s;
}
.message-file img:hover { opacity: .9; }

/* Системні повідомлення та завершення чату */
.system-message {
    text-align: center;
    padding: 8px 0;
    margin: 6px 0;
}

.system-message-text {
    display: inline-block;
    background: var(--ok-soft);
    border-left: 3px solid var(--ok);
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 13px;
    color: #226b40;
    text-align: left;
}

.system-message-time {
    font-size: 11px;
    color: var(--muted);
    margin-top: 4px;
}

/* Очікування спеціаліста */
.wait-box {
    margin: 10px auto 4px;
    max-width: 320px;
    padding: 14px 16px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border2);
    border-radius: 10px;
}
.wait-title { font-weight: 700; font-size: 14px; color: var(--strong); }
.wait-text { margin-top: 4px; font-size: 12.5px; line-height: 1.45; color: var(--muted); }
.wait-box.busy { border-style: solid; border-color: #f0c9ca; background: var(--red-soft); }
.wait-actions { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px 14px; margin-top: 12px; }
.wait-actions .btn-action { display: inline-flex; align-items: center; text-decoration: none; }
.wait-mail { color: var(--red); font-weight: 600; font-size: 13px; text-decoration: none; word-break: break-all; }
.wait-mail:hover { text-decoration: underline; }
.wait-dots { display: flex; justify-content: center; gap: 5px; margin-bottom: 8px; }
.wait-dots i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--red);
    opacity: .25;
    animation: wait-dot 1.2s ease-in-out infinite;
}
.wait-dots i:nth-child(2) { animation-delay: .2s; }
.wait-dots i:nth-child(3) { animation-delay: .4s; }
@keyframes wait-dot { 0%, 80%, 100% { opacity: .25; transform: none; } 40% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .wait-dots i { animation: none; opacity: .6; } }

.end-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 3px solid var(--red);
    box-shadow: var(--shadow);
    padding: 20px 18px;
    margin: 20px auto;
    max-width: 480px;
    border-radius: var(--r);
    text-align: center;
}

.end-box-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--strong);
    margin-bottom: 8px;
}

.end-box-body {
    color: var(--text);
    margin-bottom: 16px;
}

.end-box-body strong { color: var(--red); }

/* ---------- Картки (форма, офлайн) ---------- */

.greeting-form,
.offline-notice {
    max-width: 500px;
    width: calc(100% - 32px);
    margin: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--r);
    box-shadow: var(--shadow);
}

.greeting-form {
    padding: 22px 22px 20px;
    margin-top: 20px;
    margin-bottom: 20px;
}

.greeting-form h2 {
    text-align: center;
    color: var(--strong);
    margin-bottom: 14px;
    font-size: 21px;
    font-weight: 700;
}

.greeting-form h2::after {
    content: '';
    display: block;
    width: 40px;
    height: 3px;
    background: var(--red);
    border-radius: 2px;
    margin: 8px auto 0;
}

.info-notice {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    background: var(--red-soft);
    padding: 10px 12px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text);
    border-left: 3px solid var(--red);
}

.info-notice::before {
    content: 'i';
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    margin-top: 1px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    font-style: italic;
    line-height: 18px;
    text-align: center;
}

.info-notice strong { color: var(--strong); }

.form-group { margin-bottom: 12px; }

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    font-size: 13px;
    color: var(--strong);
}

.req { color: var(--red); }

.form-group input,
.form-group select {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    font-family: inherit;
    font-size: 15px;
    color: var(--strong);
    background: var(--surface);
    border: 1px solid var(--border2);
    border-radius: 6px;
    transition: border-color .15s, box-shadow .15s;
}

.form-group input::placeholder { color: #9aa0a8; }

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(200,77,80,.15);
}

.captcha-box {
    background: var(--bg);
    border: 1px solid var(--border);
    padding: 12px;
    border-radius: 6px;
    margin: 12px 0;
    text-align: center;
}

.captcha-hint {
    margin-bottom: 4px;
    font-size: 12px;
    color: var(--muted);
}

.captcha-simple { text-align: center; }

#captchaCanvas {
    display: block;
    margin: 6px auto;
    max-width: 100%;
    background: var(--bg);
    border: 1px solid var(--border2);
    border-radius: 6px;
    cursor: pointer;
}

.captcha-refresh {
    display: inline-block;
    font-size: 12px;
    color: var(--muted);
    margin-top: 2px;
    cursor: pointer;
}
.captcha-refresh:hover { color: var(--red); }

.form-group input.captcha-input,
.captcha-input {
    width: 100%;
    max-width: 200px;
    height: 42px;
    padding: 0 8px;
    margin: 8px auto 0;
    font-family: inherit;
    border: 1px solid var(--border2);
    border-radius: 6px;
    font-size: 16px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: 700;
    color: var(--strong);
    background: var(--surface);
}
.captcha-input:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(200,77,80,.15);
}

.captcha-error {
    color: var(--red-dk);
    margin-top: 8px;
    font-weight: 600;
    font-size: 13px;
}

/* ---------- Кнопки ---------- */

.btn-primary,
.btn-action {
    font-family: inherit;
    height: 42px;
    padding: 0 20px;
    background: var(--red);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s; /* як .btn на сайті */
}

.btn-primary {
    width: 100%;
    margin-top: 6px;
}

.btn-primary:hover,
.btn-action:hover { background: var(--red-dk); }

.btn-primary:disabled {
    background: var(--surface2);
    color: var(--muted);
    cursor: not-allowed;
}

/* ---------- Офлайн / перевірка ---------- */

.offline-notice {
    padding: 32px 24px;
    text-align: center;
}

.offline-notice h2 {
    color: var(--strong);
    margin-bottom: 14px;
    font-size: 21px;
    word-wrap: break-word;
}

.offline-notice p {
    color: var(--text);
    line-height: 1.6;
    margin-bottom: 14px;
}

.offline-notice .email {
    background: var(--red-soft);
    border: 1px dashed var(--red);
    padding: 14px;
    border-radius: 6px;
    margin: 16px 0 0;
    font-size: 17px;
    font-weight: 700;
    color: var(--red);
    word-break: break-all;
    overflow-wrap: break-word;
}

.loading-check {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    color: var(--muted);
    margin: auto;
}

.loading-check h3 {
    font-size: 15px;
    font-weight: 600;
}

.spinner {
    width: 20px;
    height: 20px;
    border: 3px solid var(--border);
    border-top-color: var(--red);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Поле вводу ---------- */

.chat-input-area {
    background: var(--surface);
    padding: 10px var(--gutter) 12px;
    display: none;
    align-items: flex-end;
    gap: 10px;
    border-top: 1px solid var(--border);
    flex: 0 0 auto;
}

.chat-input-area.active { display: flex; }

.chat-input-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.file-attach-btn {
    align-self: flex-start;
    background: var(--surface);
    border: 1px dashed var(--border2);
    border-radius: 6px;
    padding: 6px 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.3;
    transition: all .15s;
}

.file-attach-btn svg { flex: 0 0 auto; }

.file-attach-btn:hover {
    background: var(--red-soft);
    border-color: var(--red);
    color: var(--red);
}

.file-attach-hint {
    display: block;
    font-size: 10.5px;
    font-weight: 400;
    color: #9aa0a8;
}

.file-preview {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.file-preview img {
    max-height: 48px;
    border-radius: 4px;
}

.file-preview span {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-remove {
    background: var(--surface);
    color: var(--muted);
    border: 1px solid var(--border2);
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
    margin-left: auto;
}
.file-remove:hover { color: var(--red); border-color: var(--red); }

.chat-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border2);
    border-radius: 6px;
    font-size: 15px;
    line-height: 1.4;
    resize: none;
    overflow-y: hidden; /* смуга прокрутки лише коли текст вже не влазить (див. chat.html) */
    font-family: inherit;
    color: var(--strong);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
}

.chat-input:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(200,77,80,.15);
}

.chat-send {
    height: 42px;
    padding: 0 22px;
    font-family: inherit;
    font-size: 14px;
    background: var(--red);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-weight: 700;
    cursor: pointer;
    transition: background .2s;
}

.chat-send:hover { background: var(--red-dk); }

.chat-send:disabled {
    background: var(--surface2);
    color: var(--muted);
    cursor: not-allowed;
}

.hidden { display: none !important; }

.message.failed .message-bubble { opacity: .55; }
.message.failed .message-time { color: var(--red-dk); }

.message-text a { color: inherit; text-decoration: underline; word-break: break-all; }
.message.manager .message-text a { color: var(--red); }

/* картинку перетягують у вікно */
body.drag-over::after {
    content: attr(data-drop);
    position: fixed;
    inset: 8px;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px dashed var(--red);
    border-radius: 12px;
    background: rgba(255, 255, 255, .88);
    color: var(--red);
    font-weight: 700;
    font-size: 15px;
    pointer-events: none;
}

.chat-error {
    margin: 0 12px 8px;
    padding: 8px 12px;
    background: var(--red-soft);
    color: var(--red-dk);
    border-radius: 6px;
    font-size: 13px;
    cursor: pointer;
}

.form-error {
    background: var(--red-soft);
    color: var(--red-dk);
    border-radius: 6px;
    padding: 8px 12px;
    margin: 4px 0 12px;
    font-size: 13px;
}

.form-group .is-invalid {
    border-color: var(--red);
    background: #fff8f8;
}

.error {
    background: var(--red-soft);
    color: var(--red-dk);
    padding: 10px 15px;
    border-radius: 6px;
    margin: 10px 20px;
}

/* ---------- Перегляд зображення ---------- */

.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .88);
    z-index: 10000;
    display: none;
    flex-direction: column;
}
.lightbox.open { display: flex; }
.lightbox-bar {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    flex: 0 0 auto;
}
.lightbox-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 6px;
    padding: 8px 14px;
    font-size: 14px;
    font-family: inherit;
    text-decoration: none;
    cursor: pointer;
    line-height: 1;
}
.lightbox-btn:hover { background: rgba(255, 255, 255, .25); }
.lightbox-stage {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 0 14px 14px;
    cursor: zoom-out;
}
.lightbox-stage img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
    cursor: zoom-in;
    box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.lightbox-stage img.zoomed {
    max-width: none;
    max-height: none;
    cursor: zoom-out;
    margin: auto;
}

/* ---------- Мобільна адаптація ---------- */

@media (max-width: 768px) {
    .message-bubble { max-width: 85%; }
    .chat-messages { padding-top: 14px; padding-bottom: 14px; }
}

@media (max-width: 480px) {
    .greeting-form { padding: 18px 14px 16px; width: calc(100% - 20px); margin-top: 10px; }
    .greeting-form h2 { font-size: 19px; }
    .offline-notice { padding: 24px 14px; width: calc(100% - 20px); }
    .offline-notice h2 { font-size: 18px; }
    .offline-notice .email { font-size: 15px; padding: 12px; }
    .message-bubble { max-width: 92%; }
    .chat-input-area { gap: 8px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .chat-input { font-size: 16px; } /* без зуму на iOS */
    .form-group input, .form-group select { font-size: 16px; }
    .chat-send { padding: 0 14px; }
    .file-attach-hint { display: none; }
}

/* ---------- Вбудоване вікно на сайті (chat-widget.js, ?embed=1) ---------- */

html.embed .chat-header { display: none; }
html.embed body { background: var(--bg); }
html.embed .greeting-form {
    width: 100%;
    max-width: none;
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    padding: 14px 14px 16px;
    background: transparent;
}
html.embed .greeting-form h2 { display: none; }
html.embed .info-notice { margin-bottom: 10px; padding: 8px 10px; font-size: 12.5px; }
html.embed .form-group { margin-bottom: 8px; }
html.embed .form-group label { margin-bottom: 3px; }
html.embed .form-group input,
html.embed .form-group select { height: 40px; font-size: 14.5px; }
html.embed .captcha-box { margin: 10px 0 8px; padding: 8px; }
html.embed .captcha-box:has(#turnstileWidget) { padding: 0; border: 0; background: none; }
html.embed #turnstileWidget { min-height: 65px; } /* місце під Turnstile, щоб форма не стрибала */
html.embed, html.embed body { overscroll-behavior: contain; }
/* у вікні картинка і поле в один рядок — так форма влазить без прокрутки */
html.embed .captcha-simple {
    display: grid;
    grid-template-columns: auto 1fr;
    grid-template-areas: "hint hint" "img inp" "img ref" "err err";
    column-gap: 10px;
    align-items: center;
}
html.embed .captcha-hint { grid-area: hint; margin-bottom: 6px; }
html.embed #captchaCanvas { grid-area: img; margin: 0; width: 140px; height: 42px; }
html.embed .captcha-refresh { grid-area: ref; margin: 2px 0 0; }
html.embed .captcha-input { grid-area: inp; margin: 0; height: 34px; max-width: none; }
html.embed .captcha-simple .captcha-error { grid-area: err; margin-top: 6px; }
html.embed .btn-primary { margin-top: 2px; }
html.embed .offline-notice { width: calc(100% - 24px); margin: auto; }
html.embed .chat-messages { padding: 14px 12px; }
html.embed .message-bubble { max-width: 88%; }
html.embed .chat-input-area { padding: 10px 12px 12px; gap: 8px; }
html.embed .file-attach-hint { display: none; }
html.embed .chat-send { padding: 0 14px; }
html.embed .end-box { margin: 14px 0; }
@media (max-width: 480px) {
    html.embed .form-group input,
    html.embed .form-group select { font-size: 16px; } /* без зуму на iOS */
}
