/* =============================================
   TYPO3 Chatbot Extension — Frontend Widget
   ============================================= */

/* Widget container */
#cb-chatbot { position: fixed; bottom: 24px; right: 24px; z-index: 9999; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; font-size: 14px; }

/* Toggle button */
.cb-toggle { width: 56px; height: 56px; border-radius: 50%; background: linear-gradient(135deg, #4A90D9, #2E6BC4); color: #fff; border: none; cursor: pointer; box-shadow: 0 4px 16px rgba(74,144,217,.5); display: flex; align-items: center; justify-content: center; position: relative; transition: transform .2s, box-shadow .2s; }
.cb-toggle:hover { transform: scale(1.08); box-shadow: 0 6px 20px rgba(74,144,217,.6); }
.cb-badge { position: absolute; top: -4px; right: -4px; background: #e53e3e; color: #fff; border-radius: 50%; width: 18px; height: 18px; font-size: 11px; display: flex; align-items: center; justify-content: center; font-weight: 700; }

/* Chat window */
.cb-window { position: absolute; bottom: 68px; right: 0; width: 360px; max-height: 560px; background: #fff; border-radius: 16px; box-shadow: 0 8px 40px rgba(0,0,0,.18); display: flex; flex-direction: column; overflow: hidden; animation: cbSlide .25s ease; }
@keyframes cbSlide { from { opacity:0; transform:translateY(12px); } to { opacity:1; transform:none; } }
@media (max-width: 420px) { .cb-window { width: 100vw; right: -24px; border-radius: 16px 16px 0 0; max-height: 80vh; } }

/* Header */
.cb-header { background: linear-gradient(135deg, #4A90D9, #2E6BC4); color: #fff; padding: 12px 16px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.cb-header__info { display: flex; align-items: center; gap: 10px; }
.cb-avatar { width: 36px; height: 36px; background: rgba(255,255,255,.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 18px; }
.cb-header__title { font-weight: 700; font-size: 15px; }
.cb-header__status { font-size: 11px; opacity: .85; display: flex; align-items: center; gap: 4px; }
.cb-dot { width: 7px; height: 7px; background: #68d391; border-radius: 50%; display: inline-block; }
.cb-header__actions { display: flex; gap: 4px; }
.cb-btn-icon { background: rgba(255,255,255,.15); border: none; color: #fff; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; }
.cb-btn-icon:hover { background: rgba(255,255,255,.3); }

/* Messages */
.cb-messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; scroll-behavior: smooth; }
.cb-msg { display: flex; max-width: 90%; animation: cbMsg .2s ease; }
@keyframes cbMsg { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:none; } }
.cb-msg--bot { align-self: flex-start; }
.cb-msg--user { align-self: flex-end; }
.cb-msg__bubble { padding: 10px 14px; border-radius: 14px; line-height: 1.5; }
.cb-msg--bot .cb-msg__bubble { background: #f1f5f9; color: #1e293b; border-bottom-left-radius: 4px; }
.cb-msg--user .cb-msg__bubble { background: linear-gradient(135deg, #4A90D9, #2E6BC4); color: #fff; border-bottom-right-radius: 4px; }
.cb-msg__source { font-size: 10px; opacity: .5; margin-top: 3px; padding: 0 14px; }
.cb-msg--user .cb-msg__source { text-align: right; }

/* Feedback buttons */
.cb-msg__feedback { display: flex; gap: 6px; padding: 4px 14px; }
.cb-feedback-btn { background: none; border: 1px solid #e2e8f0; border-radius: 20px; cursor: pointer; padding: 2px 8px; font-size: 12px; color: #64748b; }
.cb-feedback-btn:hover { border-color: #4A90D9; color: #4A90D9; }
.cb-feedback-btn.active { background: #4A90D9; color: #fff; border-color: #4A90D9; }

/* Category chips */
.cb-categories { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 0; }
.cb-chip { border: 1.5px solid #4A90D9; background: transparent; color: #4A90D9; border-radius: 20px; padding: 4px 12px; font-size: 12px; cursor: pointer; transition: all .15s; display: flex; align-items: center; gap: 4px; }
.cb-chip:hover { background: #4A90D9; color: #fff; }
.cb-chip__count { background: rgba(0,0,0,.1); border-radius: 10px; padding: 0 5px; font-size: 10px; }

/* Typing indicator */
.cb-typing .cb-msg__bubble { display: flex; align-items: center; gap: 4px; padding: 14px 18px; }
.cb-typing .cb-dot { width: 6px; height: 6px; background: #94a3b8; border-radius: 50%; animation: cbDot 1.2s infinite; }
.cb-typing .cb-dot:nth-child(2) { animation-delay: .2s; }
.cb-typing .cb-dot:nth-child(3) { animation-delay: .4s; }
@keyframes cbDot { 0%,60%,100% { transform:none; } 30% { transform:translateY(-4px); } }

/* Suggestions */
.cb-suggestions { border-top: 1px solid #f1f5f9; padding: 8px 16px; flex-shrink: 0; }
.cb-suggestions__title { font-size: 11px; color: #94a3b8; margin-bottom: 6px; }
.cb-suggestion-btn { display: block; width: 100%; text-align: left; background: none; border: 1px solid #e2e8f0; border-radius: 8px; padding: 6px 10px; font-size: 12px; cursor: pointer; margin-bottom: 4px; color: #334155; transition: .15s; }
.cb-suggestion-btn:hover { border-color: #4A90D9; background: #f0f7ff; }

/* Contact panel */
.cb-contact-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.cb-contact-header { padding: 12px 16px; border-bottom: 1px solid #e2e8f0; display: flex; align-items: center; gap: 12px; font-weight: 600; }
.cb-contact-body { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }

/* Input area */
.cb-input-area { padding: 10px 12px; border-top: 1px solid #f1f5f9; display: flex; gap: 8px; flex-shrink: 0; }
.cb-input { border: 1.5px solid #e2e8f0; border-radius: 10px; padding: 8px 12px; font-size: 14px; width: 100%; outline: none; transition: border-color .15s; font-family: inherit; background: #fff; }
.cb-input:focus { border-color: #4A90D9; }
.cb-textarea { resize: vertical; min-height: 70px; }
.cb-btn { padding: 8px 16px; border-radius: 10px; border: none; cursor: pointer; font-size: 13px; font-weight: 600; transition: .15s; font-family: inherit; }
.cb-btn--primary { background: linear-gradient(135deg, #4A90D9, #2E6BC4); color: #fff; }
.cb-btn--primary:hover { opacity: .9; }
.cb-btn--send { background: linear-gradient(135deg, #4A90D9, #2E6BC4); color: #fff; padding: 8px 12px; flex-shrink: 0; }
.cb-btn--send:hover { opacity: .9; }
.cb-btn--send:disabled { opacity: .5; cursor: not-allowed; }
.cb-powered { text-align: center; font-size: 10px; color: #cbd5e1; padding: 4px; }
.cb-alert { padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.cb-alert--ok { background: #d1fae5; color: #065f46; }

/* =============================================
   Backend Module Styles
   ============================================= */
.cb-backend { padding: 20px; max-width: 1200px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif; }
.cb-page-title { margin: 0; font-size: 22px; font-weight: 700; color: #1e293b; }
.cb-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 10px; }
.cb-section { margin: 24px 0; }
.cb-section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; color: #334155; border-bottom: 2px solid #e2e8f0; padding-bottom: 8px; }

/* Stats cards */
.cb-stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px,1fr)); gap: 14px; margin-bottom: 24px; }
.cb-stat-card { background: #fff; border-radius: 12px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); border-top: 3px solid #4A90D9; text-align: center; }
.cb-stat-card--blue  { border-top-color: #4A90D9; }
.cb-stat-card--green { border-top-color: #38a169; }
.cb-stat-card--purple{ border-top-color: #805ad5; }
.cb-stat-card--orange{ border-top-color: #dd6b20; }
.cb-stat-card--red   { border-top-color: #e53e3e; }
.cb-stat-card--teal  { border-top-color: #319795; }
.cb-stat-card__value { font-size: 26px; font-weight: 800; color: #1e293b; }
.cb-stat-card__label { font-size: 11px; color: #64748b; margin-top: 4px; }

/* Quick nav */
.cb-quick-nav { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 24px; }
.cb-quick-btn { background: #f1f5f9; border: 1.5px solid #e2e8f0; border-radius: 10px; padding: 10px 18px; text-decoration: none; color: #334155; font-weight: 600; font-size: 13px; transition: .15s; }
.cb-quick-btn:hover { background: #4A90D9; color: #fff; border-color: #4A90D9; text-decoration: none; }

/* Category cards */
.cb-cat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px,1fr)); gap: 12px; }
.cb-cat-card { background: #fff; border-radius: 10px; padding: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.07); border-top: 3px solid #4A90D9; }
.cb-cat-card__title { font-weight: 700; font-size: 14px; color: #1e293b; }
.cb-cat-card__count { font-size: 12px; color: #64748b; margin: 4px 0; }

/* Tables */
.cb-table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 10px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.cb-table th { background: #f8fafc; padding: 10px 12px; text-align: left; font-size: 12px; text-transform: uppercase; color: #64748b; letter-spacing: .04em; border-bottom: 1.5px solid #e2e8f0; }
.cb-table td { padding: 10px 12px; border-bottom: 1px solid #f1f5f9; font-size: 13px; vertical-align: middle; }
.cb-table tr:last-child td { border-bottom: none; }
.cb-table tr:hover td { background: #fafbff; }
.cb-row--hidden td { opacity: .5; }

/* QA table */
.cb-qa-question { font-weight: 600; color: #1e293b; }
.cb-qa-answer-preview { font-size: 11px; color: #94a3b8; margin-top: 2px; }
.cb-keywords { font-size: 11px; color: #64748b; }
.cb-helpful { font-size: 12px; }
.cb-helpful-bar { width: 60px; height: 4px; background: #fee2e2; border-radius: 2px; margin-top: 3px; }
.cb-helpful-bar__fill { height: 100%; background: #38a169; border-radius: 2px; }

/* Log table */
.cb-log-q { max-width: 200px; font-weight: 500; }
.cb-log-a { max-width: 220px; color: #64748b; font-size: 12px; }

/* Badges */
.cb-badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #475569; }
.cb-badge--local    { background: #d1fae5; color: #065f46; }
.cb-badge--openai   { background: #dbeafe; color: #1e40af; }
.cb-badge--deepseek { background: #ede9fe; color: #5b21b6; }
.cb-badge--fallback { background: #fef3c7; color: #92400e; }
.cb-badge--new      { background: #fee2e2; color: #991b1b; }
.cb-badge--ok       { background: #d1fae5; color: #065f46; }
.cb-badge--spam     { background: #f3f4f6; color: #6b7280; }

/* Status badges for contacts */
.cb-status-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 700; }
.cb-status-badge--new         { background: #fee2e2; color: #991b1b; }
.cb-status-badge--in_progress { background: #fef3c7; color: #92400e; }
.cb-status-badge--resolved    { background: #d1fae5; color: #065f46; }
.cb-status-badge--spam        { background: #f3f4f6; color: #6b7280; }

/* Status tabs */
.cb-status-tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.cb-status-tab { padding: 6px 14px; border-radius: 20px; background: #f1f5f9; color: #64748b; text-decoration: none; font-size: 12px; font-weight: 600; transition: .15s; }
.cb-status-tab:hover, .cb-status-tab.active { background: #4A90D9; color: #fff; text-decoration: none; }

/* Color dot */
.cb-color-dot { display: inline-block; width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(0,0,0,.1); }

/* Filter form */
.cb-filter-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; background: #f8fafc; padding: 12px; border-radius: 10px; }
.cb-input--search { min-width: 200px; max-width: 300px; }
.cb-input--date   { width: 140px; }
.cb-input--sm     { width: 80px; }
.cb-select { border: 1.5px solid #e2e8f0; border-radius: 8px; padding: 7px 10px; font-size: 13px; background: #fff; }

/* Buttons (backend) */
.cb-btn--sm      { padding: 4px 10px; font-size: 12px; border-radius: 6px; border: 1px solid #e2e8f0; background: #f8fafc; cursor: pointer; }
.cb-btn--sm:hover { background: #e2e8f0; }
.cb-btn--outline  { background: transparent; border: 1.5px solid #cbd5e1; color: #475569; padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; text-decoration: none; }
.cb-btn--outline:hover { background: #f1f5f9; text-decoration: none; }
.cb-btn--danger   { background: #fee2e2; color: #991b1b; border-color: #fca5a5; }
.cb-btn--danger:hover { background: #fca5a5; }
.cb-actions { white-space: nowrap; display: flex; gap: 4px; }
.cb-link { color: #4A90D9; text-decoration: none; }
.cb-link:hover { text-decoration: underline; }
.cb-empty { padding: 32px; text-align: center; color: #94a3b8; font-size: 14px; background: #f8fafc; border-radius: 10px; }

/* Forms (backend) */
.cb-form { background: #fff; border-radius: 12px; padding: 24px; box-shadow: 0 1px 4px rgba(0,0,0,.07); max-width: 700px; }
.cb-form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: 16px; }
.cb-label { font-size: 13px; font-weight: 600; color: #374151; }
.cb-label small { font-weight: normal; color: #94a3b8; }
.cb-form-actions { display: flex; gap: 10px; margin-top: 20px; align-items: center; }
.cb-form-group { margin-bottom: 8px; }

/* Detail view */
.cb-detail-grid { display: grid; grid-template-columns: 1fr 320px; gap: 20px; }
@media (max-width: 768px) { .cb-detail-grid { grid-template-columns: 1fr; } }
.cb-detail-card { background: #fff; border-radius: 12px; padding: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.07); margin-bottom: 16px; }
.cb-detail-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f5f9; font-size: 13px; }
.cb-detail-row:last-child { border-bottom: none; }
.cb-detail-row label { font-weight: 600; color: #64748b; min-width: 80px; flex-shrink: 0; }
.cb-message-body { white-space: pre-wrap; font-size: 14px; line-height: 1.6; color: #1e293b; margin-top: 8px; }
.cb-info-row { display: flex; gap: 20px; font-size: 13px; color: #64748b; padding: 10px 0; }
.cb-info-row strong { color: #1e293b; }

/* Settings */
.cb-settings-section { background: #fff; border-radius: 12px; padding: 20px 24px; margin-bottom: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.07); }
.cb-settings-section h2 { font-size: 15px; font-weight: 700; margin: 0 0 16px; color: #1e293b; padding-bottom: 10px; border-bottom: 1.5px solid #e2e8f0; }

/* Alert */
.cb-alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.cb-alert--ok      { background: #d1fae5; color: #065f46; }
.cb-alert--error   { background: #fee2e2; color: #991b1b; }
.cb-alert--warning { background: #fef3c7; color: #92400e; }
