/* chatbot.css - Chat interface */

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    flex: 1;
}
.chat-welcome h3 {
    font-size: 20px;
    font-weight: 600;
    margin-top: 16px;
    color: var(--text);
}
.chat-welcome p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 8px;
    max-width: 400px;
}

.chat-message {
    max-width: 75%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message-ai {
    align-self: flex-start;
    background: var(--bg-secondary);
    color: var(--text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--border);
}

.message-error { opacity: 0.8; }

.message-system {
    align-self: center !important;
    max-width: 90% !important;
    background: var(--bg-tertiary) !important;
    border: 1px dashed var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 14px;
    text-align: center;
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 12px auto;
}
.message-system .message-content { font-size: 0.8rem; }

.message-content {
    overflow-wrap: break-word;
}
.message-content code {
    background: var(--bg-tertiary);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 13px;
    font-family: 'SF Mono', Monaco, Consolas, monospace;
}
.message-content pre {
    background: var(--bg-tertiary);
    padding: 12px;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 8px 0;
}
.message-content pre code { background: none; padding: 0; }
.message-content strong { font-weight: 600; }
.message-content a { color: var(--primary); }
.message-user .message-content code {
    background: rgba(255,255,255,0.2);
    color: white;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 4px;
    gap: 8px;
}
.message-user .message-footer {
    flex-direction: row-reverse;
}
.message-time {
    display: block;
    font-size: 11px;
    opacity: 0.6;
}
.msg-copy-btn {
    background: none;
    border: none;
    padding: 2px 4px;
    cursor: pointer;
    opacity: 0.45;
    transition: opacity 0.2s;
    color: var(--text-tertiary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.msg-copy-btn:hover {
    opacity: 1;
    background: var(--bg-secondary);
}
.msg-copy-btn:active {
    opacity: 1;
}

/* Typing indicator */
.chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 20px 8px;
}

/* Input area */
.chat-input-container {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px 20px;
    border-top: 1px solid var(--border);
    background: var(--bg);
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 8px 16px;
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg-secondary);
    resize: none;
    height: 36px;
    max-height: 150px;
    outline: none;
    transition: border-color var(--transition);
    line-height: 1.5;
    box-sizing: border-box;
}
.chat-input:focus { border-color: var(--primary); }
.chat-input::placeholder { color: var(--text-tertiary); }

.btn-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.btn-send:hover:not(:disabled) { background: var(--primary-hover); transform: scale(1.05); }
.btn-send:disabled { opacity: 0.4; cursor: not-allowed; }

/* Mic button */
.btn-mic {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.btn-mic:active {
    transform: scale(0.95);
}
.btn-mic.recording {
    background: #C0604A;
    color: white;
    border-color: #C0604A;
    animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* Attach button */
.btn-attach {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition);
    flex-shrink: 0;
}
.btn-attach:active {
    transform: scale(0.95);
    color: var(--primary);
}

/* Chat file preview row */
.chat-file-preview {
    padding: 8px 16px 0;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.chat-file-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 72px;
    min-width: 72px;
    padding: 8px 4px 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 10px;
}
.chat-file-card .chat-file-thumb {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    object-fit: cover;
}
.chat-file-icon-thumb {
    width: 44px;
    height: 44px;
    border-radius: 6px;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}
.chat-file-card-name {
    display: block;
    width: 100%;
    font-size: 10px;
    font-weight: 500;
    text-align: center;
    color: var(--text-secondary);
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.chat-file-card-remove {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border: 2px solid var(--bg);
    border-radius: 50%;
    background: var(--text-tertiary);
    color: white;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
}

/* File attachments in chat messages */
.message-files {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
    justify-content: flex-end;
}
.message-file-card {
    width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255,255,255,0.15);
    border-radius: 8px;
    padding: 4px;
    overflow: hidden;
}
.message-file-img {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    object-fit: cover;
}
.message-file-icon {
    width: 56px;
    height: 56px;
    border-radius: 6px;
    background: rgba(255,255,255,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.message-file-label {
    display: block;
    width: 100%;
    font-size: 9px;
    text-align: center;
    color: rgba(255,255,255,0.85);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* TTS button in header */
.btn-tts {
    color: var(--text-secondary);
    transition: all var(--transition);
}
.btn-tts.tts-active {
    color: var(--primary);
}

/* Automation confirm card in chat (pre-creation) */
.chat-automation-confirm {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.chat-automation-confirm-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #2D5BE315;
    border: 1px solid #2D5BE340;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text);
}
.chat-automation-confirm-inner .btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.chat-automation-confirm-inner .btn-sm:hover {
    background: var(--primary-hover);
}
.chat-automation-confirm-inner .btn-sm:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Automation created banner in chat (post-creation) */
.chat-automation-created {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.chat-automation-created-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: #4A8C6F15;
    border: 1px solid #4A8C6F40;
    border-radius: 12px;
    font-size: 13px;
    color: var(--text);
}
.chat-automation-created-inner .btn-sm {
    padding: 6px 14px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    background: var(--primary);
    color: white;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}
.chat-automation-created-inner .btn-sm:hover {
    background: var(--primary-hover);
}

@media (max-width: 768px) {
    .chat-message { max-width: 85%; }
    .chat-messages { padding: 12px; gap: 12px; }
    .chat-input-container {
        padding: 8px 12px calc(12px + 60px + var(--safe-bottom));
        gap: 10px;
    }
    .btn-send {
        width: 44px;
        height: 44px;
        min-width: 44px;
    }
    .btn-mic, .btn-attach {
        width: 44px;
        height: 44px;
    }
    .chat-input {
        height: 38px;
    }
}

/* Appointment link form */
.chat-appointment-form {
    display: flex;
    justify-content: flex-start;
    padding: 4px 0;
    max-width: 75%;
}
.chat-appointment-form-inner {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    width: 100%;
}
.appointment-form-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
}
.appointment-form-fields {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.appointment-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.appointment-field label {
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
}
.appointment-field input,
.appointment-field textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
    outline: none;
    transition: border-color var(--transition);
    box-sizing: border-box;
}
.appointment-field input:focus,
.appointment-field textarea:focus {
    border-color: var(--primary);
}
.appointment-field textarea {
    resize: none;
}
.appointment-field-row {
    display: flex;
    gap: 10px;
}
.appointment-field-row .appointment-field {
    flex: 1;
}
.chat-appointment-form-inner .btn-sm {
    align-self: flex-end;
    padding: 8px 20px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}
.chat-appointment-form-inner .btn-sm:hover {
    background: var(--primary-hover);
}

/* Appointment link result */
.chat-appointment-result {
    display: flex;
    justify-content: flex-start;
    padding: 4px 0;
    max-width: 75%;
}
.chat-appointment-result-inner {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: #4A8C6F10;
    border: 1px solid #4A8C6F30;
    border-radius: var(--radius-lg);
    border-bottom-left-radius: 4px;
    font-size: 13px;
    color: var(--text);
}
.chat-appointment-result-inner > svg {
    flex-shrink: 0;
}
.appointment-result-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.appointment-link-preview {
    font-size: 11px;
    color: var(--primary);
    word-break: break-all;
    text-decoration: none;
    opacity: 0.8;
}
.appointment-link-preview:hover {
    opacity: 1;
    text-decoration: underline;
}
.appointment-result-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}
.appointment-copy-btn {
    padding: 7px 16px;
    font-size: 12px;
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
}
.appointment-copy-btn:hover {
    background: var(--primary-hover);
}
.appointment-open-btn {
    padding: 7px 16px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    color: var(--text);
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.appointment-open-btn:hover {
    background: var(--bg-secondary);
}

@media (max-width: 768px) {
    .chat-appointment-form,
    .chat-appointment-result {
        max-width: 90%;
    }
}

/* Save to archive bar */
.chat-save-bar {
    display: flex;
    justify-content: center;
    padding: 8px 0 4px;
}
.chat-save-bar .btn {
    opacity: 0.7;
    font-size: 12px;
}
.chat-save-bar .btn:hover {
    opacity: 1;
}
