/* Page Container */
#calcai-page {
    max-width: 1200px;
    margin: 0 auto;
    padding: 30px 20px;
}

/* Chat Window */
#calcai-window {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 900px;
    height: 80vh;
    margin: 40px auto;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 18px;
    box-shadow: 0 12px 35px rgba(0,0,0,.12);
    overflow: hidden;
}

/* Header */
#calcai-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: #007bff;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
    min-height: 70px;
}

#calcai-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

#calcai-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    background: #2563eb;
    color: #fff;
    border-radius: 50%;
    font-weight: 700;
    font-size: 14px;
    flex-shrink: 0;
}

#calcai-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
}

#calcai-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

#calcai-actions button {
    background: transparent;
    border: none;
    padding: 6px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #64748b;
    border-radius: 6px;
    transition: background 0.2s;
    white-space: nowrap;
}

#calcai-actions button:hover {
    background: #e2e8f0;
}

#calcai-new-btn {
    font-weight: 500;
    color: #2563eb !important;
}

#calcai-history-btn {
    font-size: 18px !important;
    padding: 6px 8px !important;
}

#calcai-close {
    font-weight: 600;
    font-size: 16px !important;
    color: #94a3b8 !important;
    padding: 6px 10px !important;
}

/* History Panel */
#calcai-history-panel {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    width: 300px;
    height: 100%;
    background: #fff;
    border-left: 1px solid #e5e7eb;
    z-index: 10;
    flex-direction: column;
    box-shadow: -4px 0 12px rgba(0,0,0,0.08);
}

#calcai-history-panel.active {
    display: flex;
}

#calcai-history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    flex-shrink: 0;
}

#calcai-history-header strong {
    font-size: 15px;
    color: #1e293b;
}

#calcai-history-close {
    background: transparent;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #94a3b8;
    padding: 0 4px;
    line-height: 1;
}

#calcai-history-close:hover {
    color: #475569;
}

#calcai-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px 16px;
}

/* History Items */
.calcai-history-item {
    padding: 12px 14px;
    margin-bottom: 6px;
    background: #f8fafc;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    border: 1px solid transparent;
}

.calcai-history-item:hover {
    background: #f1f5f9;
    border-color: #e2e8f0;
}

.calcai-history-item.active {
    background: #eff6ff;
    border-color: #2563eb;
}

.calcai-history-title {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calcai-history-date {
    display: block;
    font-size: 11px;
    color: #94a3b8;
    margin-top: 4px;
}

/* Messages */
#calcai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px 24px;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.calcai-message {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.7;
    word-wrap: break-word;
    animation: calcai-fadeIn 0.3s ease;
}

@keyframes calcai-fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.calcai-user {
    align-self: flex-end;
    background: #2563eb;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.calcai-bot {
    align-self: flex-start;
    background: #f1f5f9;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    max-width: 90%;
}

.calcai-disclaimer-note {
    margin-top: 14px;
    padding: 10px 14px;
    background: #fef9c3;
    border-radius: 8px;
    font-size: 12px;
    color: #854d0e;
    border-left: 3px solid #eab308;
    line-height: 1.5;
}

/* Tables in messages */
.calcai-table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 13px;
}

.calcai-table th {
    background: #f1f5f9;
    font-weight: 600;
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
    text-align: left;
}

.calcai-table td {
    padding: 8px 12px;
    border: 1px solid #e2e8f0;
}

.calcai-table tr:nth-child(even) {
    background: #f8fafc;
}

/* Typing indicator */
#calcai-typing .calcai-thinking {
    display: flex;
    align-items: center;
    gap: 12px;
}

#calcai-typing .calcai-thinking-label {
    font-size: 13px;
    color: #64748b;
}

.calcai-wave {
    display: flex;
    gap: 4px;
    align-items: center;
}

.calcai-wave span {
    width: 6px;
    height: 6px;
    background: #94a3b8;
    border-radius: 50%;
    animation: calcai-wave 1.2s ease-in-out infinite;
}

.calcai-wave span:nth-child(2) {
    animation-delay: 0.15s;
}

.calcai-wave span:nth-child(3) {
    animation-delay: 0.3s;
}

.calcai-wave span:nth-child(4) {
    animation-delay: 0.45s;
}

.calcai-wave span:nth-child(5) {
    animation-delay: 0.6s;
}

@keyframes calcai-wave {
    0%, 60%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    30% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Footer / Input */
#calcai-footer {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 20px 16px;
    background: #f8fafc;
    border-top: 1px solid #e5e7eb;
    flex-shrink: 0;
}

#calcai-input {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 44px;
    max-height: 120px;
    line-height: 1.5;
}

#calcai-input:focus {
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}

#calcai-input::placeholder {
    color: #94a3b8;
}

#calcai-send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    background: #2563eb;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    color: #fff;
    transition: background 0.2s, transform 0.1s;
    flex-shrink: 0;
}

#calcai-send:hover {
    background: #1d4ed8;
}

#calcai-send:active {
    transform: scale(0.95);
}

#calcai-send svg {
    width: 20px;
    height: 20px;
}

#calcai-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 768px) {
    #calcai-page {
        padding: 15px 10px;
    }

    #calcai-window {
        height: 90vh;
        margin: 10px auto;
        border-radius: 12px;
    }

    #calcai-header {
        padding: 12px 16px;
        min-height: 60px;
    }

    #calcai-title h3 {
        font-size: 14px;
    }

    #calcai-actions button {
        font-size: 12px;
        padding: 4px 8px;
    }

    #calcai-messages {
        padding: 16px;
    }

    .calcai-message {
        max-width: 92%;
        font-size: 13px;
        padding: 12px 14px;
    }

    #calcai-footer {
        padding: 10px 16px 12px;
        gap: 8px;
    }

    #calcai-history-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid #e5e7eb;
    }
}

@media (max-width: 480px) {
    #calcai-window {
        height: 95vh;
        border-radius: 8px;
        margin: 5px auto;
    }

    #calcai-title h3 {
        font-size: 13px;
    }

    #calcai-actions button {
        font-size: 11px;
        padding: 4px 6px;
    }

    #calcai-avatar {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    #calcai-input {
        font-size: 13px;
        padding: 8px 12px;
        min-height: 38px;
    }

    #calcai-send {
        width: 38px;
        height: 38px;
    }

    #calcai-send svg {
        width: 17px;
        height: 17px;
    }

    .calcai-message {
        max-width: 95%;
        font-size: 12px;
        padding: 10px 12px;
    }

    .calcai-disclaimer-note {
        font-size: 11px;
        padding: 8px 10px;
    }
}