/* Плаваючий чат-віджет для зв'язку гостя з адміністратором.
   Кольори узгоджені зі змінними home.css (--accent, --surface тощо). */

.chat-widget-btn {
    position: fixed;
    right: 20px;
    bottom: 20px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: var(--accent, #ff6424);
    color: #fff;
    font-size: 26px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease;
}

.chat-widget-btn:hover {
    transform: scale(1.06);
}

@media (max-width: 860px) {
    .chat-widget-btn {
        bottom: 76px; /* вище stats bar */
    }
}

.chat-widget-btn .chat-widget-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 10px;
    background: #e23b3b;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
}

.chat-widget-panel {
    position: fixed;
    right: 20px;
    bottom: 88px;
    width: 340px;
    max-width: calc(100vw - 32px);
    height: 460px;
    max-height: calc(100vh - 120px);
    background: var(--surface, rgba(19, 19, 22, 0.96));
    backdrop-filter: blur(8px);
    border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    color: var(--text, #f6f6f7);
    font-family: 'Montserrat', system-ui, sans-serif;
}

.chat-widget-panel.open {
    display: flex;
}

.chat-widget-header {
    padding: 14px 16px;
    background: var(--accent, #ff6424);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* Група кнопок праворуч у шапці (очистити + закрити). */
.chat-widget-actions {
    display: flex;
    align-items: center;
    gap: 2px;
}

/* Обидві кнопки шапки — однакові круглі цілі з підсвіткою при наведенні.
   Шапка акцентна, тому підсвітка біла напівпрозора, а не темна. */
.chat-widget-header .chat-widget-close,
.chat-widget-header .chat-widget-clear {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 50%;
    color: #fff;
    line-height: 1;
    cursor: pointer;
    opacity: 0.8;
    transition: opacity 0.15s ease, background-color 0.15s ease, transform 0.1s ease;
}

.chat-widget-header .chat-widget-close {
    font-size: 22px;
}

.chat-widget-header .chat-widget-clear svg {
    width: 16px;
    height: 16px;
}

.chat-widget-header .chat-widget-close:hover,
.chat-widget-header .chat-widget-clear:hover {
    opacity: 1;
    background-color: rgba(255, 255, 255, 0.2);
}

.chat-widget-header .chat-widget-close:active,
.chat-widget-header .chat-widget-clear:active {
    transform: scale(0.92);
}

/* hidden не спрацював би проти display: inline-flex вище. */
.chat-widget-header .chat-widget-clear[hidden] {
    display: none;
}

/* Смужка підтвердження очищення — замість системного window.confirm. */
.chat-widget-confirm {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    background: var(--surface-2, rgba(32, 32, 36, 0.92));
    font-size: 13px;
}

.chat-widget-confirm[hidden] {
    display: none;
}

.chat-widget-confirm > span {
    flex: 1;
    color: var(--muted, #b3b3bd);
}

.chat-widget-confirm-btn {
    border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    border-radius: 8px;
    padding: 5px 10px;
    background: transparent;
    color: var(--text, #f6f6f7);
    font-family: inherit;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.chat-widget-confirm-btn:hover {
    border-color: var(--accent, #ff6424);
}

.chat-widget-confirm-btn.is-danger {
    border-color: transparent;
    background: #e23b3b;
    color: #fff;
}

.chat-widget-confirm-btn.is-danger:hover {
    background: #c93030;
}

/* Вкладки «Адміністратор / АІ-асистент» (лише для авторизованих). */
.chat-widget-tabs {
    display: flex;
    border-bottom: 1px solid var(--line, rgba(255, 255, 255, 0.14));
}

.chat-widget-tab {
    flex: 1;
    padding: 10px 8px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--muted, #b3b3bd);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s ease, border-color 0.15s ease;
}

.chat-widget-tab:hover {
    color: var(--text, #f6f6f7);
}

.chat-widget-tab.active {
    color: var(--accent, #ff6424);
    border-bottom-color: var(--accent, #ff6424);
}

.chat-widget-body {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* display: flex перебиває стандартну поведінку hidden, тому явно ховаємо
   неактивну вкладку (адміністратор ↔ асистент). */
.chat-widget-body[hidden] {
    display: none;
}

.chat-widget-empty {
    margin: auto;
    text-align: center;
    color: var(--muted, #b3b3bd);
    font-size: 13px;
    line-height: 1.5;
}

.chat-msg {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-msg.guest {
    align-self: flex-end;
    background: var(--accent, #ff6424);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg.admin {
    align-self: flex-start;
    background: var(--surface-2, rgba(32, 32, 36, 0.92));
    border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    border-bottom-left-radius: 4px;
}

/* Індикатор генерації відповіді АІ-асистента. */
.chat-msg-typing {
    color: var(--muted, #b3b3bd);
    font-style: italic;
    animation: chat-typing-pulse 1.2s ease-in-out infinite;
}

@keyframes chat-typing-pulse {
    0%, 100% { opacity: 0.45; }
    50% { opacity: 1; }
}

/* Службові повідомлення (адміністратор приєднався тощо). */
.chat-msg.system {
    align-self: center;
    background: none;
    color: var(--muted, rgba(255, 255, 255, 0.55));
    font-size: 12px;
    font-style: italic;
}

/* Блок запиту діалогу — показується замість поля вводу, поки адміністратор
   не підтвердив звернення (або після його завершення). */
.chat-widget-gate {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 14px 12px;
    border-top: 1px solid var(--line, rgba(255, 255, 255, 0.14));
}

.chat-widget-gate[hidden] {
    display: none;
}

.chat-widget-gate-text {
    margin: 0;
    text-align: center;
    color: var(--muted, #b3b3bd);
    font-size: 13px;
    line-height: 1.45;
}

.chat-widget-gate-btn {
    border: none;
    border-radius: 10px;
    padding: 11px 14px;
    background: var(--accent, #ff6424);
    color: #fff;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: filter 0.15s ease, transform 0.1s ease;
}

.chat-widget-gate-btn:hover {
    filter: brightness(1.08);
}

.chat-widget-gate-btn:active {
    transform: scale(0.98);
}

.chat-widget-gate-btn:disabled {
    opacity: 0.6;
    cursor: default;
}

.chat-widget-gate-btn[hidden] {
    display: none;
}

.chat-widget-form {
    display: flex;
    gap: 8px;
    padding: 12px;
    border-top: 1px solid var(--line, rgba(255, 255, 255, 0.14));
}

/* display: flex перебив би стандартну поведінку hidden. */
.chat-widget-form[hidden] {
    display: none;
}

.chat-widget-form textarea {
    flex: 1;
    resize: none;
    height: 40px;
    max-height: 96px;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    background: rgba(0, 0, 0, 0.25);
    color: var(--text, #f6f6f7);
    font-family: inherit;
    font-size: 14px;
}

.chat-widget-form textarea:focus {
    outline: none;
    border-color: var(--accent, #ff6424);
}

.chat-widget-form button {
    border: none;
    background: var(--accent, #ff6424);
    color: #fff;
    border-radius: 10px;
    padding: 0 16px;
    font-weight: 700;
    cursor: pointer;
}

.chat-widget-form button:disabled {
    opacity: 0.5;
    cursor: default;
}

.chat-widget-error {
    color: #ff8a8a;
    font-size: 12px;
    padding: 0 12px 8px;
    display: none;
}

.chat-widget-error.show {
    display: block;
}

/* ── AI booking: slot cards & confirmation card ───────────────────────────── */
.ai-slots {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 4px 0 10px;
}
.ai-slot,
.ai-confirm {
    border: 1px solid var(--line, rgba(255, 255, 255, 0.14));
    background: var(--surface-2, rgba(32, 32, 36, 0.92));
    border-radius: 12px;
    padding: 10px 12px;
    color: var(--text, #f6f6f7);
    font-size: 13px;
}
.ai-slot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}
.ai-slot-main {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}
.ai-slot-main strong {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ai-slot-seats {
    color: var(--muted, #b3b3bd);
    font-size: 12px;
}
.ai-slot-btn,
.ai-confirm-btn {
    border: 0;
    border-radius: 999px;
    padding: 8px 14px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    min-height: 36px;
    flex: none;
}
.ai-slot-btn,
.ai-confirm-btn.is-primary {
    background: var(--accent, #BEF45D);
    color: #131F2C;
}
.ai-confirm-btn {
    background: transparent;
    color: var(--text, #f6f6f7);
    border: 1px solid var(--line, rgba(255, 255, 255, 0.2));
}
.ai-slot-btn:disabled,
.ai-confirm-btn:disabled {
    opacity: 0.55;
    cursor: progress;
}
.ai-slot-tag {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent, #BEF45D);
    flex: none;
}
.ai-slot-tag.is-muted {
    color: var(--muted, #b3b3bd);
}
.ai-confirm {
    margin: 4px 0 10px;
    border-color: var(--accent, #BEF45D);
}
.ai-confirm-title {
    font-weight: 800;
    margin-bottom: 6px;
}
.ai-confirm-row {
    margin: 2px 0;
}
.ai-confirm-actions {
    display: flex;
    gap: 8px;
    margin-top: 10px;
}
.ai-confirm-status:empty {
    display: none;
}
.ai-confirm-status {
    margin-top: 8px;
    font-weight: 700;
}
.ai-confirm-status.is-success { color: var(--accent, #BEF45D); }
.ai-confirm-status.is-error { color: #ff8a80; }
.ai-confirm-status.is-muted { color: var(--muted, #b3b3bd); }

[data-theme="light"] .ai-slot-btn,
[data-theme="light"] .ai-confirm-btn.is-primary {
    color: #FFFFFF;
}
