/**
 * ChatSupportBot Widget Styles
 * Standalone CSS for the embeddable chat widget.
 */

/* CSS Variables - configurable via data attributes */
:root {
    --csb-primary: #2563eb;
    --csb-primary-dark: #1d4ed8;
    --csb-primary-light: #eff6ff;
    --csb-text-primary: #1e293b;
    --csb-text-secondary: #64748b;
    --csb-text-muted: #94a3b8;
    --csb-bg-primary: #ffffff;
    --csb-bg-secondary: #f8fafc;
    --csb-border-light: #e2e8f0;
    --csb-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --csb-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --csb-radius-sm: 8px;
    --csb-radius-md: 12px;
    --csb-radius-lg: 16px;
    --csb-radius-full: 50%;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--csb-text-primary);
    background: var(--csb-bg-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Header */
.widget-header {
    background: var(--csb-primary);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.widget-header-icon {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: var(--csb-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.widget-header-icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
}

.widget-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--csb-radius-full);
}

.widget-header-info {
    flex: 1;
    min-width: 0;
}

.widget-header-title {
    font-weight: 600;
    font-size: 16px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.widget-header-status {
    font-size: 13px;
    opacity: 0.9;
}

/* Header Menu */
.widget-header-menu {
    position: relative;
    margin-left: auto;
}

.widget-menu-button {
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    border-radius: var(--csb-radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    transition: background 0.2s;
}

.widget-menu-button:hover {
    background: rgba(255, 255, 255, 0.25);
}

.widget-menu-button svg {
    width: 18px;
    height: 18px;
}

.widget-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: white;
    border-radius: var(--csb-radius-sm);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    min-width: 160px;
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 0.2s ease;
}

.widget-menu-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.widget-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px 14px;
    border: none;
    background: none;
    font-size: 14px;
    color: var(--csb-text-primary);
    cursor: pointer;
    text-align: left;
    transition: background 0.15s;
}

.widget-menu-item:hover {
    background: var(--csb-bg-secondary);
}

.widget-menu-item:first-child {
    border-radius: var(--csb-radius-sm) var(--csb-radius-sm) 0 0;
}

.widget-menu-item:last-child {
    border-radius: 0 0 var(--csb-radius-sm) var(--csb-radius-sm);
}

.widget-menu-item:only-child {
    border-radius: var(--csb-radius-sm);
}

.widget-menu-item svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* Messages Area */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--csb-bg-primary);
}

.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--csb-radius-lg);
    font-size: 14px;
    line-height: 1.5;
    animation: messageSlideIn 0.3s ease;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* AI messages with complex content get more width */
.message-ai:has(table),
.message-ai:has(pre),
.message-ai.has-table {
    max-width: 95%;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

.message-welcome {
    background: transparent;
    color: var(--csb-text-secondary);
    align-self: center;
    text-align: center;
    font-size: 13px;
    padding: 8px;
    max-width: 100%;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: var(--csb-bg-secondary);
    border-radius: var(--csb-radius-lg);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--csb-border-light);
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--csb-text-muted);
    border-radius: var(--csb-radius-full);
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: translateY(0);
    }
    40% {
        transform: translateY(-8px);
    }
}

/* Input Area */
.input-container {
    border-top: 1px solid var(--csb-border-light);
    padding: 12px 16px;
    background: var(--csb-bg-primary);
    flex-shrink: 0;
}

.input-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.input-field {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--csb-border-light);
    border-radius: 24px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: var(--csb-bg-primary);
    color: var(--csb-text-primary);
}

.input-field::placeholder {
    color: var(--csb-text-muted);
}

.input-field:focus {
    border-color: var(--csb-primary);
    box-shadow: 0 0 0 3px var(--csb-primary-light);
}

.send-button {
    width: 44px;
    height: 44px;
    background: var(--csb-primary);
    border: none;
    border-radius: var(--csb-radius-full);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-button:hover {
    background: var(--csb-primary-dark);
}

.send-button:active {
    transform: scale(0.95);
}

.send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.send-button svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Branding Footer */
.branding {
    text-align: center;
    padding: 8px;
    font-size: 11px;
    color: var(--csb-text-muted);
    border-top: 1px solid var(--csb-border-light);
    background: var(--csb-bg-primary);
    flex-shrink: 0;
}

.branding a {
    color: var(--csb-text-muted);
    text-decoration: none;
    transition: color 0.2s;
}

.branding a:hover {
    color: var(--csb-primary);
}

/* Custom Scrollbar */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-track {
    background: transparent;
}

.messages-container::-webkit-scrollbar-thumb {
    background: var(--csb-border-light);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--csb-text-muted);
}

/* Utility Classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===========================================
   Markdown Styling for AI Messages
   =========================================== */

.message-ai h1,
.message-ai h2,
.message-ai h3,
.message-ai h4,
.message-ai h5,
.message-ai h6 {
    margin-top: 0.75em;
    margin-bottom: 0.5em;
    font-weight: 600;
    line-height: 1.3;
    color: var(--csb-text-primary);
}

.message-ai h1 { font-size: 1.25rem; }
.message-ai h2 { font-size: 1.125rem; }
.message-ai h3 { font-size: 1rem; }
.message-ai h4,
.message-ai h5,
.message-ai h6 { font-size: 0.9375rem; }

.message-ai p {
    margin-top: 0;
    margin-bottom: 0.75em;
}

.message-ai p:last-child {
    margin-bottom: 0;
}

.message-ai ul,
.message-ai ol {
    margin-top: 0.5em;
    margin-bottom: 0.75em;
    padding-left: 1.5em;
}

.message-ai li {
    margin-bottom: 0.25em;
}

.message-ai li:last-child {
    margin-bottom: 0;
}

.message-ai strong {
    font-weight: 600;
}

.message-ai em {
    font-style: italic;
}

.message-ai a {
    color: var(--csb-primary);
    text-decoration: none;
}

.message-ai a:hover {
    text-decoration: underline;
}

.message-ai code {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 0.125em 0.375em;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.875em;
}

.message-ai pre {
    background-color: rgba(0, 0, 0, 0.06);
    padding: 0.75em 1em;
    border-radius: var(--csb-radius-sm);
    overflow-x: auto;
    margin: 0.75em 0;
    font-size: 0.8125rem;
}

.message-ai pre code {
    background-color: transparent;
    padding: 0;
    font-size: inherit;
}

.message-ai blockquote {
    border-left: 3px solid var(--csb-primary);
    padding-left: 1em;
    margin: 0.75em 0;
    color: var(--csb-text-secondary);
    font-style: italic;
}

/* Table container styling */
.message-ai table {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-collapse: collapse;
    margin: 0.75em 0;
    font-size: 0.75rem;
    border: 1px solid var(--csb-border-light);
    border-radius: var(--csb-radius-sm);
}

.message-ai thead {
    display: table;
    width: 100%;
    table-layout: auto;
}

.message-ai tbody {
    display: table;
    width: 100%;
    table-layout: auto;
}

.message-ai tr {
    display: table-row;
}

.message-ai th,
.message-ai td {
    display: table-cell;
    border: 1px solid var(--csb-border-light);
    padding: 0.35em 0.5em;
    text-align: left;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
    vertical-align: top;
    min-width: 60px;
    max-width: 180px;
}

.message-ai th {
    background-color: var(--csb-bg-secondary);
    font-weight: 600;
    white-space: nowrap;
}

/* Make table cells more readable */
.message-ai td strong {
    display: block;
    margin-bottom: 0.15em;
}

.message-ai hr {
    border: none;
    border-top: 1px solid var(--csb-border-light);
    margin: 1em 0;
}

/* First and last element spacing cleanup */
.message-ai > *:first-child {
    margin-top: 0;
}

.message-ai > *:last-child {
    margin-bottom: 0;
}

/* Feedback Buttons */
.feedback-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    transition: opacity 0.3s ease;
}

.feedback-button {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    background: transparent;
    border: 1px solid var(--csb-border-light);
    border-radius: var(--csb-radius-sm);
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--csb-text-secondary);
}

.feedback-button:hover:not(:disabled) {
    background: var(--csb-bg-secondary);
    border-color: var(--csb-primary);
    color: var(--csb-primary);
}

.feedback-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.feedback-button svg {
    width: 16px;
    height: 16px;
}

.feedback-thanks {
    font-size: 13px;
    color: var(--csb-text-secondary);
    font-style: italic;
}


