/* =====================================================
   Konektika AI Chat — Widget CSS
   ===================================================== */

:root {
    --kac-primary:   #07213D;
    --kac-accent:    #D4AF37;
    --kac-dark:      #041324;
    --kac-glass:     rgba(255, 255, 255, 0.08);
    --kac-radius:    12px;
    --kac-radius-sm: 6px;
    --kac-shadow:    0 12px 35px rgba(6, 44, 84, 0.25);
    --kac-font:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --kac-user-bg:   var(--kac-primary);
    --kac-bot-bg:    #f3f4f6;
    --kac-bot-text:  #1f2937;
    --kac-win-h:     560px;
}

#kac-chatbot-wrapper {
    font-family: var(--kac-font);
}

/* ── Toggle Button ──────────────────────────── */
#kac-toggle-btn {
    position: fixed !important;
    z-index: 999999 !important;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 20px rgba(7, 33, 61, 0.45);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    outline: none;
    padding: 0;
}

#kac-chatbot-wrapper.kac-position-bottom-right #kac-toggle-btn {
    bottom: 28px !important;
    right: 28px !important;
}

#kac-chatbot-wrapper.kac-position-bottom-left #kac-toggle-btn {
    bottom: 28px !important;
    left: 28px !important;
}

#kac-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 10px 25px rgba(6, 44, 84, 0.5);
}

#kac-toggle-btn:active {
    transform: scale(0.95);
}

.kac-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    color: white;
    transition: opacity 0.2s, transform 0.3s;
}

.kac-btn-icon svg {
    width: 100%;
    height: 100%;
}

.kac-notification-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: var(--kac-accent);
    border-radius: 50%;
    border: 2px solid white;
    display: none;
    animation: kac-pulse 1.5s infinite;
}

@keyframes kac-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50%       { transform: scale(1.3); opacity: 0.7; }
}

/* ── Chat Window ────────────────────────────── */
#kac-chat-window {
    position: fixed !important;
    z-index: 999998 !important;
    width: 370px !important;
    max-width: calc(100vw - 40px) !important; 
    height: min(var(--kac-win-h), calc(100vh - 120px)) !important;
    background: #ffffff;
    border-radius: var(--kac-radius);
    box-shadow: var(--kac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.85) translateY(20px);
    opacity: 0;
    pointer-events: none; /* Disabled when hidden */
    transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.25s ease;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

#kac-chatbot-wrapper.kac-position-bottom-right #kac-chat-window {
    bottom: 100px !important;
    right: 20px !important;
    transform-origin: bottom right;
}

#kac-chatbot-wrapper.kac-position-bottom-left #kac-chat-window {
    bottom: 100px !important;
    left: 20px !important;
    transform-origin: bottom left;
}

#kac-chat-window.kac-open {
    transform: scale(1) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* ── Header ─────────────────────────────────── */
.kac-header {
    background: var(--kac-primary);
    border-bottom: 3px solid var(--kac-accent);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-shrink: 0;
}

.kac-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.kac-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    backdrop-filter: blur(4px);
    border: none;
    background: transparent;
}

.kac-avatar svg {
    width: 26px;
    height: 26px;
}

.kac-header-text h3 {
    margin: 0;
    padding: 0;
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    font-family: var(--kac-font);
    border: none;
}

.kac-status {
    display: flex;
    align-items: center;
    gap: 5px;
    color: rgba(255,255,255,0.85);
    font-size: 11.5px;
    margin-top: 2px;
}

.kac-status-dot {
    width: 7px;
    height: 7px;
    background: #4ade80;
    border-radius: 50%;
    animation: kac-pulse 2s infinite;
}

.kac-header-actions {
    display: flex;
    gap: 4px;
}

.kac-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.85);
    transition: background 0.2s, color 0.2s;
}

.kac-action-btn:hover {
    background: rgba(255,255,255,0.25);
    color: #fff;
}

.kac-action-btn svg {
    width: 15px;
    height: 15px;
}

/* ── Messages ───────────────────────────────── */
.kac-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background:
        radial-gradient(ellipse at 20% 20%, rgba(6, 44, 84, 0.03) 0%, transparent 60%),
        #fafafa;
}

.kac-messages::-webkit-scrollbar {
    width: 4px;
}
.kac-messages::-webkit-scrollbar-track {
    background: transparent;
}
.kac-messages::-webkit-scrollbar-thumb {
    background: rgba(108, 99, 255, 0.25);
    border-radius: 2px;
}

/* Message bubbles */
.kac-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: kac-msg-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

@keyframes kac-msg-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.kac-msg.kac-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.kac-msg.kac-msg-bot {
    align-self: flex-start;
}

.kac-msg-bubble {
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    white-space: pre-wrap;
    width: fit-content;
}

.kac-msg-user .kac-msg-bubble {
    background: var(--kac-primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.kac-msg-bot .kac-msg-bubble {
    background: var(--kac-bot-bg);
    color: var(--kac-bot-text);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0,0,0,0.06);
}

.kac-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    align-self: flex-end;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kac-msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ── Markdown Tables ────────────────────────── */
.kac-md-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
    margin: 6px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(7,33,61,0.12);
}

.kac-md-table thead tr {
    background: #07213D;
    color: #fff;
}

.kac-md-table thead th {
    padding: 7px 10px;
    text-align: left;
    font-weight: 600;
    font-size: 11.5px;
    border-right: 1px solid rgba(255,255,255,0.15);
    white-space: nowrap;
}

.kac-md-table thead th:last-child {
    border-right: none;
}

.kac-md-table tbody tr {
    background: #fff;
    transition: background 0.15s;
}

.kac-md-table tbody tr:nth-child(even) {
    background: #f0f4fa;
}

.kac-md-table tbody tr:hover {
    background: #e8f0fb;
}

.kac-md-table td {
    padding: 6px 10px;
    border-right: 1px solid #e5e7eb;
    border-bottom: 1px solid #e5e7eb;
    vertical-align: top;
    line-height: 1.4;
}

.kac-md-table td:last-child {
    border-right: none;
}

.kac-md-table tbody tr:last-child td {
    border-bottom: none;
}

/* Make bot bubble fit table width */
.kac-msg-bot .kac-msg-bubble {
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.kac-msg-time {
    font-size: 10px;
    color: #9ca3af;
    margin-top: 4px;
    display: block;
    text-align: right;
}

.kac-msg-bot .kac-msg-time {
    text-align: left;
}

/* ── Typing Indicator ───────────────────────── */
.kac-typing {
    padding: 8px 18px;
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fafafa;
    border-top: 1px solid rgba(0,0,0,0.04);
    flex-shrink: 0;
}

.kac-typing small {
    font-size: 11.5px;
    color: #9ca3af;
}

.kac-typing-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    background: #e5e7eb;
    border-radius: 20px;
    padding: 8px 12px;
}

.kac-typing-bubble span {
    width: 6px;
    height: 6px;
    background: #9ca3af;
    border-radius: 50%;
    animation: kac-bounce 1.2s ease-in-out infinite;
}
.kac-typing-bubble span:nth-child(2) { animation-delay: 0.15s; }
.kac-typing-bubble span:nth-child(3) { animation-delay: 0.30s; }

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

/* ── Input Area ─────────────────────────────── */
.kac-input-area {
    border-top: 1px solid rgba(0,0,0,0.07);
    padding: 12px 14px 10px;
    background: #fff;
    flex-shrink: 0;
}

.kac-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: #f3f4f6;
    border-radius: 14px;
    padding: 6px 6px 6px 12px;
    border: 1.5px solid transparent;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.kac-input-wrapper:focus-within {
    border-color: var(--kac-primary);
    box-shadow: 0 0 0 3px rgba(6, 44, 84, 0.1);
    background: #fff;
}

#kac-message-input {
    flex: 1;
    border: none;
    background: transparent;
    outline: none;
    resize: none;
    font-size: 13.5px;
    font-family: var(--kac-font);
    color: #1f2937;
    line-height: 1.5;
    max-height: 120px;
    scrollbar-width: none;
    padding: 4px 0;
}

#kac-message-input::placeholder {
    color: #9ca3af;
}

#kac-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: var(--kac-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.2s, opacity 0.2s;
}

#kac-send-btn:hover {
    transform: scale(1.08);
}

#kac-send-btn:active {
    transform: scale(0.94);
}

#kac-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#kac-send-btn svg {
    width: 16px;
    height: 16px;
}

.kac-footer-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 8px;
    padding: 0 2px;
}

.kac-powered {
    font-size: 10px;
    color: #d1d5db;
}

.kac-powered strong {
    color: var(--kac-primary);
}

.kac-char-count {
    font-size: 10px;
    color: #d1d5db;
}

/* ── Welcome Message ───────────────────────── */
.kac-welcome {
    text-align: center;
    padding: 20px;
}

.kac-welcome-icon {
    font-size: 36px;
    margin-bottom: 8px;
}

.kac-welcome h4 {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
    margin: 0 0 4px;
}

.kac-welcome p {
    font-size: 12.5px;
    color: #6b7280;
    margin: 0;
}

/* ── Suggestion Chips ──────────────────────── */
.kac-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 12px;
    flex-shrink: 0;
}

.kac-chip {
    font-size: 12px;
    color: var(--kac-primary);
    border: 1.5px solid rgba(6, 44, 84, 0.25);
    background: rgba(6, 44, 84, 0.05);
    border-radius: 20px;
    padding: 5px 12px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    font-family: var(--kac-font);
}

.kac-chip:hover {
    background: rgba(6, 44, 84, 0.12);
    border-color: var(--kac-primary);
}

/* ── Error Toast ───────────────────────────── */
.kac-error-msg .kac-msg-bubble {
    background: #fef2f2;
    color: #dc2626;
    border: 1px solid #fecaca;
}

/* ── Responsive ────────────────────────────── */
@media (max-width: 420px) {
    #kac-chat-window {
        width: calc(100vw - 24px);
        height: calc(100vh - 100px);
        bottom: 80px;
        right: 0 !important;
        left: 0 !important;
        margin: 0 12px;
    }

    #kac-chatbot-wrapper.kac-position-bottom-left #kac-chat-window,
    #kac-chatbot-wrapper.kac-position-bottom-right #kac-chat-window {
        right: auto;
        left: 12px;
    }
}

/* Google Fonts import */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');
