/* ============================================================
   ChatBot Widget - Styly
   ============================================================ */

:root {
    --chat-primary: #2563eb;
    --chat-primary-hover: #1d4ed8;
    --chat-bg: #ffffff;
    --chat-header-text: #ffffff;
    --chat-user-msg: #2563eb;
    --chat-user-text: #ffffff;
    --chat-bot-msg: #f1f5f9;
    --chat-bot-text: #1e293b;
    --chat-input-border: #e2e8f0;
    --chat-input-bg: #ffffff;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --chat-radius: 16px;
    --chat-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --chat-error-bg: #fef2f2;
    --chat-error-text: #dc2626;
    --chat-chip-bg: #eef2ff;
    --chat-chip-text: #3b5bdb;
    --chat-chip-border: #c7d2fe;
    --chat-glass-bg: rgba(255, 255, 255, 0.85);
}

/* ============================================================
   Dark mode
   ============================================================ */
.chat-dark {
    --chat-bg: #1e1e2e;
    --chat-user-msg: #1e40af;
    --chat-bot-msg: #2a2a3e;
    --chat-bot-text: #e2e8f0;
    --chat-input-border: #3a3a50;
    --chat-input-bg: #2a2a3e;
    --chat-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    --chat-error-bg: #3b1f1f;
    --chat-error-text: #f87171;
    --chat-chip-bg: #2a2a4e;
    --chat-chip-text: #93a3ff;
    --chat-chip-border: #3a3a5e;
    --chat-glass-bg: rgba(30, 30, 46, 0.85);
}

/* Dark mode se ridi pouze tridou .chat-dark (JS detekuje system preference) */

/* Popisek nad bublinou */
.chat-tooltip {
    position: fixed;
    bottom: 132px;
    right: 16px;
    background: var(--chat-bg);
    color: var(--chat-bot-text);
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: var(--chat-shadow);
    font-family: var(--chat-font);
    font-size: 13px;
    line-height: 1.4;
    z-index: 99999;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-tooltip::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 26px;
    width: 12px;
    height: 12px;
    background: var(--chat-bg);
    transform: rotate(45deg);
    box-shadow: 3px 3px 6px rgba(0, 0, 0, 0.06);
}

.chat-tooltip.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateY(10px);
    animation: none;
}

.chat-tooltip:not(.hidden) {
    animation: chatTooltipBounce 2s ease-in-out infinite;
}

@keyframes chatTooltipBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-4px);
    }
}

/* Plovouci bublina */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 100px;
    height: 100px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: var(--chat-header-text);
    border: none;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    transition: transform 0.2s ease, background 0.2s ease;
}

.chat-bubble:hover {
    transform: scale(1.08);
    background: var(--chat-primary-hover);
}

.chat-bubble svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-bubble img {
    width: 90px;
    height: 90px;
    border-radius: 50%;
    object-fit: cover;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.chat-bubble .chat-icon-close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.chat-bubble.open .chat-icon-open {
    opacity: 0;
    transform: scale(0.5);
    pointer-events: none;
}

.chat-bubble.open .chat-icon-close {
    opacity: 1;
    transform: rotate(0deg);
}

/* Chat okno — glassmorphism */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--chat-glass-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: flex;
    flex-direction: column;
    z-index: 99998;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-family: var(--chat-font);
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Hlavicka */
.chat-header {
    background: var(--chat-primary);
    color: var(--chat-header-text);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-avatar svg {
    width: 20px;
    height: 20px;
    fill: white;
}

.chat-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff !important;
}

.chat-header-info p {
    margin: 2px 0 0;
    font-size: 12px;
    opacity: 0.85;
}

/* Dark mode toggle */
.chat-dark-toggle {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    margin-left: auto;
    opacity: 0.7;
    transition: opacity 0.2s;
    color: white;
    display: flex;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}

.chat-dark-toggle:hover {
    opacity: 1;
}

.chat-dark-toggle svg {
    fill: white;
}

.chat-lang-switch {
    background: transparent;
    border: 1.5px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    font-family: var(--chat-font);
    color: rgba(255, 255, 255, 0.85);
    letter-spacing: 0.5px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.2s ease, border-color 0.2s ease, color 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-lang-switch:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.8);
    color: #ffffff;
}

/* Close button na mobilu */
.chat-close-mobile {
    display: none;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 4px;
    color: white;
    min-width: 44px;
    min-height: 44px;
    align-items: center;
    justify-content: center;
}

.chat-close-mobile svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Oblast zprav */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 340px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

/* Jednotlive zpravy */
.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: chatFadeIn 0.2s ease;
}

@keyframes chatFadeIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.user {
    background: var(--chat-user-msg);
    color: var(--chat-user-text);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-msg.bot {
    background: var(--chat-bot-msg);
    color: var(--chat-bot-text);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-msg.bot p {
    margin: 0 0 8px;
}

.chat-msg.bot p:last-child {
    margin-bottom: 0;
}

.chat-msg.bot ul,
.chat-msg.bot ol {
    margin: 4px 0;
    padding-left: 20px;
}

.chat-msg.bot li {
    margin-bottom: 2px;
}

.chat-msg.bot strong {
    font-weight: 600;
}

.chat-msg.error {
    background: var(--chat-error-bg);
    color: var(--chat-error-text);
    align-self: center;
    font-size: 13px;
    text-align: center;
}

/* Indikator psani */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--chat-bot-msg);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
    animation: chatFadeIn 0.2s ease;
}

.chat-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: chatBounce 1.4s ease-in-out infinite;
}

.chat-typing span:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-6px);
    }
}

/* ============================================================
   Tlacitka vyberu (jazyk, menu)
   ============================================================ */

.chat-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    animation: chatFadeIn 0.2s ease;
    align-self: flex-start;
    max-width: 100%;
}

.chat-buttons.lang-select {
    justify-content: center;
    align-self: stretch;
    gap: 12px;
}

.chat-buttons.lang-select .chat-btn {
    flex: 1;
    padding: 14px 16px;
    font-size: 15px;
    font-weight: 600;
    min-width: 0;
}

.chat-btn {
    background: var(--chat-bg);
    color: var(--chat-primary);
    border: 2px solid var(--chat-primary);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease, transform 0.1s ease;
    text-align: left;
    line-height: 1.3;
    min-height: 44px;
    animation: chatStaggerIn 0.3s ease both;
}

@keyframes chatStaggerIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-btn:hover {
    background: var(--chat-primary);
    color: var(--chat-header-text);
}

.chat-btn:active {
    transform: scale(0.97);
}

.chat-buttons.menu-select {
    flex-direction: column;
    align-self: stretch;
}

.chat-buttons.menu-select .chat-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-btn-icon {
    font-size: 16px;
    flex-shrink: 0;
    width: 22px;
    text-align: center;
}

/* WhatsApp tlacitko */
.chat-btn.chat-btn-whatsapp {
    background: #25D366;
    color: #ffffff;
    border-color: #25D366;
}

.chat-btn.chat-btn-whatsapp .chat-btn-icon svg {
    fill: #ffffff;
}

.chat-btn.chat-btn-whatsapp:hover {
    background: #1da851;
    border-color: #1da851;
    color: #ffffff;
}

/* ============================================================
   Quick reply chipy
   ============================================================ */

.chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-self: flex-start;
    animation: chatFadeIn 0.3s ease;
}

.chat-chip {
    background: var(--chat-chip-bg);
    color: var(--chat-chip-text);
    border: 1px solid var(--chat-chip-border);
    border-radius: 16px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.chat-chip:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

.chat-chip:active {
    transform: scale(0.95);
}

/* ============================================================
   Lead formular
   ============================================================ */

.chat-lead-form {
    background: var(--chat-bot-msg);
    border-radius: 12px;
    padding: 14px;
    animation: chatFadeIn 0.3s ease;
    align-self: stretch;
}

.chat-lead-title {
    font-weight: 600;
    font-size: 14px;
    margin-bottom: 10px;
    color: var(--chat-bot-text);
}

.chat-lead-input {
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--chat-input-border);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--chat-font);
    margin-bottom: 8px;
    background: var(--chat-input-bg);
    color: var(--chat-bot-text);
    outline: none;
    transition: border-color 0.2s;
    min-height: 44px;
}

.chat-lead-input:focus {
    border-color: var(--chat-primary);
}

.chat-lead-error {
    color: var(--chat-error-text);
    font-size: 12px;
    min-height: 16px;
    margin-bottom: 4px;
}

.chat-lead-actions {
    display: flex;
    gap: 8px;
}

.chat-lead-submit {
    flex: 1;
    background: var(--chat-primary);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
}

.chat-lead-submit:hover {
    background: var(--chat-primary-hover);
}

.chat-lead-cancel {
    background: transparent;
    color: var(--chat-bot-text);
    border: 1px solid var(--chat-input-border);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: var(--chat-font);
    cursor: pointer;
    transition: background 0.2s;
    min-height: 44px;
}

.chat-lead-cancel:hover {
    background: var(--chat-bot-msg);
}

/* ============================================================
   Hodnoceni odpovedi
   ============================================================ */

.chat-rating {
    display: flex;
    gap: 4px;
    align-self: flex-start;
    animation: chatFadeIn 0.2s ease;
}

.chat-rating-btn {
    background: transparent;
    border: 1px solid var(--chat-input-border);
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, background 0.2s;
    display: flex;
    align-items: center;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}

.chat-rating-btn svg {
    fill: var(--chat-bot-text);
}

.chat-rating-btn:hover {
    opacity: 1;
    background: var(--chat-bot-msg);
}

.chat-rating-btn:disabled {
    cursor: default;
}

.chat-rating-btn.chat-rating-active {
    opacity: 1;
    background: var(--chat-primary);
    border-color: var(--chat-primary);
}

.chat-rating-btn.chat-rating-active svg {
    fill: white;
}

/* Vstupni pole */
.chat-input-area {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: 1px solid var(--chat-input-border);
    gap: 8px;
    flex-shrink: 0;
}

.chat-input-area.hidden {
    display: none;
}

.chat-input-area textarea {
    flex: 1;
    border: 1px solid var(--chat-input-border);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 14px;
    font-family: var(--chat-font);
    resize: none;
    outline: none;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color 0.2s ease;
    background: var(--chat-input-bg);
    color: var(--chat-bot-text);
}

.chat-input-area textarea:focus {
    border-color: var(--chat-primary);
}

.chat-input-area textarea::placeholder {
    color: #94a3b8;
}

.chat-input-area button {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--chat-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.chat-input-area button:hover {
    background: var(--chat-primary-hover);
}

.chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-input-area button svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Tlacitko zpet do menu */
.chat-back-btn {
    background: none;
    color: var(--chat-primary);
    border: 1px solid var(--chat-input-border);
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    font-family: var(--chat-font);
    cursor: pointer;
    align-self: center;
    margin-top: 4px;
    transition: background 0.2s ease, border-color 0.2s ease;
    animation: chatFadeIn 0.2s ease;
    min-height: 44px;
    display: flex;
    align-items: center;
}

.chat-back-btn:hover {
    background: var(--chat-bot-msg);
    border-color: var(--chat-primary);
}

/* ============================================================
   Kalendar — vyber terminu
   ============================================================ */

.chat-calendar {
    background: var(--chat-bot-msg);
    border-radius: 12px;
    padding: 14px;
    animation: chatFadeIn 0.3s ease;
    align-self: stretch;
}

.chat-cal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.chat-cal-title {
    font-weight: 600;
    font-size: 14px;
    color: var(--chat-bot-text);
}

.chat-cal-nav {
    background: transparent;
    border: 1px solid var(--chat-input-border);
    border-radius: 6px;
    width: 32px;
    height: 32px;
    font-size: 18px;
    cursor: pointer;
    color: var(--chat-bot-text);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.chat-cal-nav:hover {
    background: var(--chat-chip-bg);
}

.chat-cal-days {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    margin-bottom: 4px;
}

.chat-cal-days span {
    text-align: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--chat-bot-text);
    opacity: 0.6;
    padding: 4px 0;
}

.chat-cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.chat-cal-empty {
    padding: 6px;
}

.chat-cal-day {
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-input-border);
    border-radius: 6px;
    padding: 6px 2px;
    font-size: 13px;
    font-family: var(--chat-font);
    cursor: pointer;
    color: var(--chat-bot-text);
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
    min-height: 32px;
}

.chat-cal-day:hover:not(:disabled) {
    background: var(--chat-chip-bg);
    border-color: var(--chat-primary);
}

.chat-cal-day.chat-cal-past {
    opacity: 0.3;
    cursor: not-allowed;
}

.chat-cal-day.chat-cal-office {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.08);
}

.chat-cal-day.chat-cal-selected {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

.chat-cal-note {
    font-size: 11px;
    color: var(--chat-bot-text);
    opacity: 0.7;
    margin-top: 8px;
    text-align: center;
    line-height: 1.4;
}

.chat-cal-time-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--chat-input-border);
}

.chat-cal-time-section.hidden,
.chat-cal-form-section.hidden {
    display: none;
}

.chat-cal-time-label,
.chat-cal-form-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--chat-bot-text);
    margin-bottom: 8px;
}

.chat-cal-times {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    max-height: 140px;
    overflow-y: auto;
}

.chat-cal-time-btn {
    background: var(--chat-input-bg);
    border: 1px solid var(--chat-input-border);
    border-radius: 6px;
    padding: 5px 10px;
    font-size: 12px;
    font-family: var(--chat-font);
    cursor: pointer;
    color: var(--chat-bot-text);
    transition: background 0.15s, border-color 0.15s;
}

.chat-cal-time-btn:hover {
    background: var(--chat-chip-bg);
    border-color: var(--chat-primary);
}

.chat-cal-time-btn.chat-cal-time-office {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.08);
}

.chat-cal-time-btn.chat-cal-time-selected {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

.chat-cal-time-warning {
    margin-top: 6px;
    padding: 6px 10px;
    background: #fef3c7;
    color: #92400e;
    border-radius: 6px;
    font-size: 12px;
    line-height: 1.4;
}

.chat-dark .chat-cal-time-warning {
    background: #451a03;
    color: #fbbf24;
}

.chat-cal-time-warning.hidden {
    display: none;
}

.chat-cal-form-section {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--chat-input-border);
}

/* ============================================================
   Mobilni responsivita
   ============================================================ */
/* Focus-visible pro pristupnost */
.chat-btn:focus-visible,
.chat-chip:focus-visible,
.chat-bubble:focus-visible,
.chat-rating-btn:focus-visible,
.chat-back-btn:focus-visible,
.chat-lead-submit:focus-visible,
.chat-lead-cancel:focus-visible,
.chat-dark-toggle:focus-visible,
.chat-lang-switch:focus-visible,
.chat-close-mobile:focus-visible,
.chat-input-area button:focus-visible {
    outline: 2px solid var(--chat-primary);
    outline-offset: 2px;
}

.chat-lead-input:focus-visible,
.chat-input-area textarea:focus-visible {
    outline: none;
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

/* Offline banner */
.chat-offline-banner {
    background: #fef3c7;
    color: #92400e;
    padding: 8px 14px;
    font-size: 12px;
    text-align: center;
    flex-shrink: 0;
    display: none;
}

.chat-offline-banner.visible {
    display: block;
}

.chat-dark .chat-offline-banner {
    background: #451a03;
    color: #fbbf24;
}

@media (max-width: 480px) {
    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-height: 100%;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
        padding-bottom: env(safe-area-inset-bottom, 0);
    }

    .chat-window.open {
        transform: translateY(0) scale(1);
    }

    .chat-messages {
        max-height: none;
        flex: 1;
    }

    .chat-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0));
    }

    /* Prevent iOS zoom on textarea focus (font < 16px triggers zoom) */
    .chat-input-area textarea {
        font-size: 16px;
    }

    .chat-lead-input {
        font-size: 16px;
    }

    .chat-bubble {
        bottom: 16px;
        right: 16px;
    }

    .chat-tooltip {
        bottom: 124px;
        right: 8px;
        font-size: 12px;
    }

    .chat-close-mobile {
        display: flex;
    }
}
