/* =====================================================
   DOPI AI Assistant - Premium UI Styles v2.0
   Floating chat widget + Admin panel
   ===================================================== */

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

/* === Base Container === */
#dopi-root {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 99999;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

/* === Floating Icon Button === */
#dopi-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0070f3, #00b4d8);
    box-shadow: 0 8px 25px rgba(0, 112, 243, 0.45);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    border: none;
    position: relative;
    outline: none;
}

#dopi-fab:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 12px 35px rgba(0, 112, 243, 0.6);
}

#dopi-fab:active {
    transform: scale(0.97);
}

#dopi-fab svg {
    width: 26px;
    height: 26px;
    transition: transform 0.3s ease;
}

#dopi-fab.open svg {
    transform: rotate(90deg);
}

/* Pulse ring animation */
#dopi-fab::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid rgba(0, 112, 243, 0.35);
    animation: dopi-pulse 2.5s ease-in-out infinite;
}

@keyframes dopi-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.15); opacity: 0; }
}

/* Unread badge */
#dopi-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: white;
    font-size: 10px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
}

#dopi-badge.show {
    display: flex;
}

/* === Chat Box === */
#dopi-chatbox {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    height: 540px;
    background: #ffffff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 4px 20px rgba(0,0,0,0.08);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    animation: dopi-box-open 0.35s cubic-bezier(0.34, 1.3, 0.64, 1) forwards;
    border: 1px solid rgba(0,0,0,0.06);
}

@keyframes dopi-box-open {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

#dopi-chatbox.visible {
    display: flex;
}

/* === Header === */
#dopi-header {
    background: linear-gradient(135deg, #0f0f1a 0%, #1a1f3c 100%);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}

.dopi-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0070f3, #00b4d8);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.dopi-avatar svg {
    width: 20px;
    height: 20px;
}

.dopi-header-info {
    flex: 1;
}

.dopi-header-info h4 {
    margin: 0;
    color: #ffffff;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.dopi-header-info p {
    margin: 2px 0 0;
    color: rgba(255,255,255,0.55);
    font-size: 11.5px;
}

.dopi-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
    flex-shrink: 0;
    animation: dopi-blink 2s ease infinite;
}

@keyframes dopi-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

#dopi-close-btn {
    background: rgba(255,255,255,0.1);
    border: none;
    color: rgba(255,255,255,0.7);
    cursor: pointer;
    padding: 5px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

#dopi-close-btn:hover {
    background: rgba(255,255,255,0.2);
    color: white;
}

/* === Messages Area === */
#dopi-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f8fafc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

#dopi-messages::-webkit-scrollbar { width: 4px; }
#dopi-messages::-webkit-scrollbar-track { background: transparent; }
#dopi-messages::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 4px; }

/* Individual message */
.dopi-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 88%;
    animation: dopi-msg-in 0.25s ease-out;
}

@keyframes dopi-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

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

.dopi-msg.ai {
    align-self: flex-start;
}

.dopi-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
}

.dopi-msg.user .dopi-msg-bubble {
    background: linear-gradient(135deg, #0070f3, #0060d0);
    color: #ffffff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,112,243,0.25);
}

.dopi-msg.ai .dopi-msg-bubble {
    background: #ffffff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #f1f5f9;
}

/* Typing indicator */
.dopi-typing-dots {
    display: flex;
    gap: 4px;
    padding: 8px 4px;
}

.dopi-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: dopi-typing 1.2s ease infinite;
}

.dopi-typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.dopi-typing-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dopi-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* Timestamp */
.dopi-msg-time {
    font-size: 10px;
    color: #94a3b8;
    margin-top: 3px;
    text-align: right;
}

.dopi-msg.ai .dopi-msg-time { text-align: left; }

/* === Input Area === */
#dopi-input-wrap {
    padding: 12px 14px;
    background: #ffffff;
    border-top: 1px solid #f1f5f9;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#dopi-input {
    flex: 1;
    border: 1.5px solid #e2e8f0;
    background: #f8fafc;
    padding: 10px 14px;
    border-radius: 22px;
    outline: none;
    font-size: 13.5px;
    color: #1e293b;
    font-family: inherit;
    transition: border-color 0.2s, background 0.2s;
    resize: none;
    max-height: 80px;
    overflow-y: auto;
}

#dopi-input:focus {
    border-color: #0070f3;
    background: #ffffff;
}

#dopi-input::placeholder { color: #94a3b8; }

#dopi-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0070f3, #00b4d8);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(0,112,243,0.3);
}

#dopi-send:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(0,112,243,0.45);
}

#dopi-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#dopi-send svg { width: 17px; height: 17px; }

/* === Powered by footer === */
#dopi-footer {
    text-align: center;
    padding: 5px 0 8px;
    font-size: 10.5px;
    color: #cbd5e1;
    background: #ffffff;
    flex-shrink: 0;
}

/* =====================================================
   DOPI ADMIN PANEL OVERLAY
   ===================================================== */

#dopi-admin-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 100000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    animation: dopi-fade-in 0.2s ease;
}

@keyframes dopi-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

#dopi-admin-overlay.show { display: flex; }

#dopi-admin-panel {
    background: #ffffff;
    border-radius: 18px;
    width: 780px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 25px 80px rgba(0,0,0,0.25);
    animation: dopi-panel-in 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
}

@keyframes dopi-panel-in {
    from { transform: scale(0.9) translateY(20px); opacity: 0; }
    to   { transform: scale(1) translateY(0); opacity: 1; }
}

#dopi-admin-panel::-webkit-scrollbar { width: 5px; }
#dopi-admin-panel::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 4px; }

.dopi-ap-header {
    background: linear-gradient(135deg, #0f0f1a, #1a1f3c);
    padding: 22px 26px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 18px 18px 0 0;
}

.dopi-ap-header h2 {
    margin: 0;
    color: white;
    font-size: 18px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 10px;
}

.dopi-ap-close {
    background: rgba(255,255,255,0.1);
    border: none;
    color: rgba(255,255,255,0.75);
    cursor: pointer;
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    font-size: 18px;
}

.dopi-ap-close:hover { background: rgba(255,255,255,0.2); color: white; }

.dopi-ap-tabs {
    display: flex;
    gap: 2px;
    padding: 16px 20px 0;
    border-bottom: 1px solid #f1f5f9;
    background: #fafbfc;
}

.dopi-ap-tab {
    padding: 9px 16px;
    border: none;
    background: none;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: #64748b;
    border-radius: 8px 8px 0 0;
    transition: all 0.2s;
    font-family: inherit;
    border-bottom: 2px solid transparent;
}

.dopi-ap-tab:hover { background: #f1f5f9; color: #374151; }
.dopi-ap-tab.active { color: #0070f3; border-bottom-color: #0070f3; background: white; font-weight: 600; }

.dopi-ap-content { padding: 22px; }

.dopi-ap-section { display: none; }
.dopi-ap-section.active { display: block; }

/* Form elements */
.dopi-form-group {
    margin-bottom: 18px;
}

.dopi-form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.dopi-form-group .dopi-hint {
    font-size: 11.5px;
    color: #94a3b8;
    margin-top: 4px;
}

.dopi-input, .dopi-select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 13.5px;
    font-family: inherit;
    color: #1e293b;
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.dopi-input:focus, .dopi-select:focus { border-color: #0070f3; }
.dopi-input.password { font-family: monospace; letter-spacing: 2px; }

.dopi-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 10px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.dopi-btn-primary {
    background: linear-gradient(135deg, #0070f3, #0060d0);
    color: white;
    box-shadow: 0 2px 8px rgba(0,112,243,0.3);
}

.dopi-btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(0,112,243,0.4); }

.dopi-btn-danger { background: #ef4444; color: white; }
.dopi-btn-danger:hover { background: #dc2626; }

.dopi-btn-secondary { background: #f1f5f9; color: #374151; }
.dopi-btn-secondary:hover { background: #e2e8f0; }

/* KB file list */
.dopi-kb-list {
    margin-top: 16px;
}

.dopi-kb-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: #f8fafc;
    border: 1px solid #f1f5f9;
    border-radius: 10px;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.dopi-kb-item:hover { background: #f1f5f9; }

.dopi-kb-item-info strong { font-size: 13.5px; color: #1e293b; }
.dopi-kb-item-info span { font-size: 11.5px; color: #94a3b8; margin-top: 2px; display: block; }

/* Log viewer */
.dopi-log-area {
    background: #0f172a;
    color: #94a3b8;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    padding: 14px;
    border-radius: 10px;
    max-height: 320px;
    overflow-y: auto;
    line-height: 1.7;
    white-space: pre-wrap;
    word-break: break-all;
}

.dopi-log-area::-webkit-scrollbar { width: 4px; }
.dopi-log-area::-webkit-scrollbar-thumb { background: #334155; border-radius: 4px; }

/* Toast notification */
.dopi-toast {
    position: fixed;
    bottom: 100px;
    right: 28px;
    background: #1e293b;
    color: white;
    padding: 12px 18px;
    border-radius: 10px;
    font-size: 13px;
    z-index: 100001;
    box-shadow: 0 4px 20px rgba(0,0,0,0.2);
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.34, 1.2, 0.64, 1);
    max-width: 280px;
}

.dopi-toast.show { transform: translateX(0); }
.dopi-toast.success { border-left: 4px solid #22c55e; }
.dopi-toast.error { border-left: 4px solid #ef4444; }

/* Alert boxes */
.dopi-alert {
    padding: 12px 14px;
    border-radius: 10px;
    font-size: 13px;
    margin-bottom: 14px;
}

.dopi-alert.info { background: #eff6ff; color: #1d4ed8; border: 1px solid #bfdbfe; }
.dopi-alert.warning { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }

/* Upload zone */
.dopi-upload-zone {
    border: 2px dashed #d1d5db;
    border-radius: 12px;
    padding: 24px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: #fafbfc;
}

.dopi-upload-zone:hover, .dopi-upload-zone.drag-over {
    border-color: #0070f3;
    background: #eff6ff;
}

.dopi-upload-zone p { margin: 8px 0 0; color: #64748b; font-size: 13px; }

/* Two-column grid */
.dopi-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

/* Divider */
.dopi-divider {
    border: none;
    border-top: 1px solid #f1f5f9;
    margin: 18px 0;
}

/* === Responsive === */
@media (max-width: 520px) {
    #dopi-root { bottom: 16px; right: 16px; }
    #dopi-chatbox { width: calc(100vw - 32px); height: calc(100vh - 100px); bottom: 72px; right: 0; }
    #dopi-admin-panel { border-radius: 12px; }
    .dopi-grid-2 { grid-template-columns: 1fr; }
}

/* === Admin icon in top panel === */
.dopi-admin-trigger {
    cursor: pointer;
    opacity: 0.85;
    transition: opacity 0.2s;
    position: relative;
}

.dopi-admin-trigger:hover { opacity: 1; }

/* Tooltip for non-admin */
.dopi-no-permission-tip {
    position: absolute;
    top: 40px;
    right: 0;
    background: #1e293b;
    color: white;
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 9999;
}

/* === DOPI Top Panel Button (Admin only) === */
.dopi-panel-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.dopi-panel-btn a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 0;
    line-height: 1;
}

.dopi-logo-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 8px; /* Even smaller font */
    font-weight: 800;
    letter-spacing: 0.2px;
    color: #ffffff;
    background: linear-gradient(135deg, #0070f3, #00b4d8);
    border-radius: 4px;
    padding: 2px 4px; /* Reduced padding */
    min-width: 22px; /* Reduced width */
    height: 16px; /* Matched the typical bell icon height */
    box-shadow: 0 1px 4px rgba(0, 112, 243, 0.45);
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    position: relative;
    overflow: hidden;
    cursor: pointer;
    margin-top: 5px; /* Vertical align with sibling icons in cpanel */
}

.dopi-logo-icon::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.2), transparent);
    border-radius: inherit;
}

.dopi-logo-icon::after {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 4px; /* match border-radius */
    border: 1px solid rgba(0, 180, 216, 0.5);
    animation: dopi-top-pulse 2.5s ease-in-out infinite;
}

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

.dopi-panel-btn a:hover .dopi-logo-icon {
    transform: scale(1.1) translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 112, 243, 0.65);
    background: linear-gradient(135deg, #0080ff, #00c8ef);
}

.dopi-panel-btn a:active .dopi-logo-icon {
    transform: scale(0.96);
}
