*,
*::before,
*::after {
    box-sizing: border-box;
}

.cp-chat-widget {
    max-width: 980px;
    margin: 20px auto;
    border: 1px solid #2b2f45;
    border-radius: 16px;
    overflow: hidden;
    background: linear-gradient(145deg, #0a0f1e 0%, #0e1529 100%);
    font-family: "Vazirmatn", Tahoma, sans-serif;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.45), inset 0 0 0 1px rgba(97, 218, 251, 0.08);
}

.cp-chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: linear-gradient(90deg, rgba(19, 26, 47, 0.95), rgba(12, 18, 35, 0.95));
    border-bottom: 1px solid rgba(97, 218, 251, 0.25);
}

.cp-chat-title-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
}

.cp-header-avatar {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, #00d4ff, #6366f1);
    box-shadow: 0 0 16px rgba(0, 212, 255, 0.35);
    font-size: 18px;
}

.cp-chat-title {
    margin: 0;
    font-size: 16px;
    color: #e0f2fe;
}

.cp-chat-subtitle {
    margin: 2px 0 0 0;
    font-size: 12px;
    color: #93c5fd;
}

.cp-chat-status {
    color: #22c55e;
    font-size: 12px;
    font-weight: 700;
    text-shadow: 0 0 10px rgba(34, 197, 94, 0.5);
}

.cp-chat-body {
    padding: 14px;
    background: transparent;
}

.cp-chat-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 12px;
}

.cp-chat-history-panel {
    border: 1px solid #25304e;
    background: rgba(10, 17, 33, 0.9);
    border-radius: 12px;
    min-height: 420px;
    max-height: 64vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.cp-history-title {
    padding: 10px 12px;
    border-bottom: 1px solid #24324f;
    color: #7dd3fc;
    font-size: 13px;
    font-weight: 700;
}

.cp-chat-history-list {
    overflow-y: auto;
    padding: 8px;
}

.cp-history-item {
    width: 100%;
    border: 1px solid #293658;
    background: rgba(15, 23, 43, 0.9);
    border-radius: 10px;
    color: #cbd5e1;
    text-align: right;
    font-size: 12px;
    padding: 8px;
    margin-bottom: 8px;
    cursor: pointer;
}

.cp-history-item:hover {
    border-color: #38bdf8;
    color: #e0f2fe;
}

.cp-history-empty {
    color: #94a3b8;
    font-size: 12px;
    padding: 8px;
}

.cp-history-meta {
    color: #7dd3fc;
    font-size: 11px;
    margin-bottom: 4px;
}

.cp-history-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cp-chat-main {
    min-width: 0;
}

.cp-chat-messages {
    min-height: 360px;
    max-height: 60vh;
    overflow-y: auto;
    padding: 2px 4px;
    margin-bottom: 12px;
    border: 1px solid #24304b;
    border-radius: 12px;
    background: rgba(6, 10, 22, 0.8);
}

.cp-message {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    margin-bottom: 12px;
}

.cp-message-avatar {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #00d4ff, #6366f1);
    color: #ffffff;
    font-size: 14px;
}

.cp-message-content {
    max-width: 86%;
    border-radius: 14px;
    padding: 10px 12px;
    line-height: 1.75;
    font-size: 14px;
    white-space: pre-wrap;
    word-break: break-word;
}

.cp-assistant {
    justify-content: flex-start;
}

.cp-assistant .cp-message-content {
    background: rgba(15, 25, 48, 0.95);
    border: 1px solid #2c3d66;
    color: #dbeafe;
}

.cp-user {
    justify-content: flex-end;
}

.cp-user .cp-message-avatar {
    order: 2;
    background: linear-gradient(135deg, #7c3aed, #2563eb);
    color: #ffffff;
}

.cp-user .cp-message-content {
    order: 1;
    background: linear-gradient(135deg, #1d4ed8, #4338ca);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.cp-chat-info {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    align-items: center;
    border: 1px solid #2a3a5f;
    background: rgba(10, 17, 33, 0.9);
    border-radius: 12px;
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 12px;
    color: #dbeafe;
}

.cp-timer {
    color: #f43f5e;
    font-weight: 700;
}

.cp-chat-controls {
    display: grid;
    gap: 10px;
}

.cp-model-label {
    color: #93c5fd;
    font-size: 12px;
    font-weight: 700;
}

.cp-model-selector {
    width: 100%;
    border: 1px solid #2d3b5d;
    border-radius: 10px;
    background: rgba(10, 17, 33, 0.92);
    color: #e2e8f0;
    padding: 10px 12px;
    font-size: 14px;
}

.cp-model-selector:focus,
.cp-message-input:focus {
    outline: none;
    border-color: #38bdf8;
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.18);
}

.cp-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.cp-message-input {
    width: 100%;
    min-height: 96px;
    max-height: 260px;
    resize: none;
    border: 1px solid #2d3b5d;
    border-radius: 12px;
    background: rgba(10, 17, 33, 0.92);
    color: #f8fafc;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.6;
}

.cp-send-button {
    min-width: 84px;
    height: 48px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #0891b2, #2563eb);
    color: #ffffff;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s ease, opacity 0.2s ease;
}

.cp-new-chat-button {
    min-width: 84px;
    height: 48px;
    border: 1px solid #2d3b5d;
    border-radius: 10px;
    background: rgba(15, 23, 43, 0.92);
    color: #e2e8f0;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.cp-new-chat-button:hover {
    border-color: #38bdf8;
    color: #7dd3fc;
}

.cp-send-button:hover {
    background: linear-gradient(135deg, #0e7490, #1d4ed8);
}

.cp-send-button:disabled,
.cp-new-chat-button:disabled,
.cp-model-selector:disabled,
.cp-message-input:disabled {
    cursor: not-allowed;
    opacity: 0.65;
}

.cp-thinking-status {
    font-size: 13px;
    color: #67e8f9;
    font-weight: 700;
}

.cp-typing-indicator {
    display: inline-flex;
    gap: 4px;
    align-items: center;
}

.cp-typing-indicator span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #67e8f9;
    animation: cp-typing 1.2s infinite ease-in-out;
}

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

.cp-typing-indicator span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes cp-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
    30% { transform: translateY(-4px); opacity: 1; }
}

@media (max-width: 768px) {
    .cp-chat-widget {
        margin: 10px;
        border-radius: 12px;
    }

    .cp-chat-layout {
        grid-template-columns: 1fr;
    }

    .cp-chat-history-panel {
        min-height: 180px;
        max-height: 220px;
    }

    .cp-chat-body {
        padding: 10px;
    }

    .cp-chat-messages {
        min-height: 280px;
        max-height: 52vh;
    }

    .cp-message-content {
        max-width: 92%;
        font-size: 13px;
    }

    .cp-input-wrapper {
        align-items: stretch;
    }

    .cp-send-button {
        min-width: 72px;
        height: 42px;
    }

    .cp-new-chat-button {
        min-width: 72px;
        height: 42px;
    }
}
