/* ════════════════════════════════════════════════════════════════════════════
   UNIVERSAL CHAT PANEL STYLES
   Self-contained, uses CSS variables from main site stylesheet
   ════════════════════════════════════════════════════════════════════════════ */

/* ─── Tab Button (Fixed Left, Rotated) ──────────────────────────────── */

.uc-tab-btn {
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent, #2563eb);
    color: #ffffff;
    border: none;
    border-radius: 0 12px 12px 0;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 10000;
    box-shadow: 2px 2px 10px rgba(37, 99, 235, 0.35);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.uc-tab-btn:hover {
    background: var(--accent-hover, #1d4ed8);
    box-shadow: 2px 4px 14px rgba(37, 99, 235, 0.45);
}

.uc-tab-btn:active {
    transform: translateY(-50%) scale(0.95);
}

/* ─── Mobile Tab Button (Fixed Bottom Right) ───────────────────────── */

.uc-mobile-tab-btn {
    display: none;
    position: fixed;
    left: 0;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent, #2563eb);
    color: #ffffff;
    border: none;
    border-radius: 0 12px 12px 0;
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    z-index: 10000;
    box-shadow: 2px 2px 10px rgba(37, 99, 235, 0.35);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    white-space: nowrap;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.2s ease;
}

.uc-mobile-tab-btn:hover {
    background: var(--accent-hover, #1d4ed8);
    box-shadow: 2px 4px 14px rgba(37, 99, 235, 0.45);
}

.uc-mobile-tab-btn:active {
    transform: translateY(-50%) scale(0.95);
}

.uc-mobile-tab-btn__icon {
    font-size: 1rem;
    line-height: 1;
}

.uc-mobile-tab-btn__label {
    line-height: 1;
}

/* ─── Backdrop (Overlay) ────────────────────────────────────────────── */

.uc-backdrop {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 10001;
    cursor: pointer;
}

.uc-backdrop.is-open {
    display: block;
}

/* ─── Panel Container ───────────────────────────────────────────────── */

.uc-panel {
    position: fixed;
    top: 60px;
    left: 0;
    height: calc(100% - 60px);
    width: 340px;
    max-width: 92vw;
    background: var(--bg-card, #e8f0ff);
    border-right: 1px solid var(--glass-border, #d1d5db);
    box-shadow: 4px 0 32px rgba(37, 99, 235, 0.15);
    z-index: 10002;
    display: flex;
    flex-direction: column;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.uc-panel.is-open {
    transform: translateX(0);
}

/* ─── Panel Header ──────────────────────────────────────────────────── */

.uc-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--glass-border, #d1d5db);
    background: var(--bg-surface, var(--bg-card, #f0f7ff));
    flex-shrink: 0;
}

.uc-panel__title {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-1, #0f172a);
}

.uc-panel__close {
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-1, #0f172a);
    padding: 0.25rem 0.5rem;
    border-radius: 8px;
    transition: background 0.2s ease;
    line-height: 1;
}

.uc-panel__close:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* ─── Messages Container ────────────────────────────────────────────── */

.uc-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    scroll-behavior: smooth;
}

/* Custom scrollbar for messages */
.uc-panel__messages::-webkit-scrollbar {
    width: 6px;
}

.uc-panel__messages::-webkit-scrollbar-track {
    background: transparent;
}

.uc-panel__messages::-webkit-scrollbar-thumb {
    background: var(--accent, #2563eb);
    border-radius: 3px;
}

.uc-panel__messages::-webkit-scrollbar-thumb:hover {
    background: var(--accent-hover, #1d4ed8);
}

/* ─── Message Styles ────────────────────────────────────────────────── */

.uc-msg {
    max-width: 92%;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.55;
    word-wrap: break-word;
    animation: slideIn 0.2s ease;
}

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

.uc-msg p {
    margin: 0;
}

.uc-msg p + p {
    margin-top: 0.5rem;
}

/* User messages (right, blue) */
.uc-msg--user {
    align-self: flex-end;
    background: var(--accent, #2563eb);
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

/* AI messages (left, glass effect) */
.uc-msg--ai {
    align-self: flex-start;
    background: var(--glass-fill, #ffffff);
    border: 1px solid var(--glass-border, #d1d5db);
    color: var(--text-1, #0f172a);
    border-bottom-left-radius: 3px;
}

/* Typing indicator */
.uc-msg--ai.uc-msg--typing {
    padding: 0.65rem 1rem;
}

.uc-msg--ai.uc-msg--typing p {
    animation: typing 1.4s infinite;
    font-style: italic;
    opacity: 0.7;
}

@keyframes typing {
    0%, 60%, 100% {
        content: "…";
    }
    20% {
        content: "…";
    }
}

/* Error messages */
.uc-msg--error {
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.35);
    color: #dc2626;
    align-self: flex-start;
}

/* ─── Input Area ────────────────────────────────────────────────────── */

.uc-panel__input-area {
    padding: 0.75rem 1.25rem 1rem 1.25rem;
    border-top: 1px solid var(--glass-border, #d1d5db);
    background: var(--bg-surface, var(--bg-card, #f0f7ff));
    flex-shrink: 0;
}

.uc-form {
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}

.uc-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--glass-border, #d1d5db);
    border-radius: 12px;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-family: inherit;
    background: var(--bg-base, #ffffff);
    color: var(--text-1, #0f172a);
    outline: none;
    transition: border-color 0.2s ease;
    max-height: 120px;
}

.uc-input:focus {
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.uc-input::placeholder {
    color: var(--text-muted, #9ca3af);
}

.uc-send-btn {
    background: var(--accent, #2563eb);
    color: #ffffff;
    border: none;
    border-radius: 12px;
    padding: 0.6rem 1rem;
    font-size: 1rem;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s ease;
    line-height: 1;
}

.uc-send-btn:hover:not(:disabled) {
    background: var(--accent-hover, #1d4ed8);
    transform: scale(1.05);
}

.uc-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

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

.uc-rate-note {
    font-size: 0.72rem;
    color: var(--text-muted, #6b7280);
    margin: 0.4rem 0 0 0;
    text-align: center;
}

/* ─── Dark Mode Support ────────────────────────────────────────────── */

[data-theme="dark"] .uc-panel {
    background: var(--bg-card, #0f1629);
}

[data-theme="dark"] .uc-panel__header {
    background: var(--bg-surface, #1a202c);
    border-bottom-color: #334155;
}

[data-theme="dark"] .uc-panel__title {
    color: #e2e8f0;
}

[data-theme="dark"] .uc-panel__close {
    color: #e2e8f0;
}

[data-theme="dark"] .uc-panel__close:hover {
    background: rgba(255, 255, 255, 0.1);
}

[data-theme="dark"] .uc-msg--ai {
    background: #1e293b;
    border-color: #334155;
    color: #cbd5e1;
}

[data-theme="dark"] .uc-msg--error {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
}

[data-theme="dark"] .uc-input {
    background: #1a202c;
    color: #e2e8f0;
    border-color: #334155;
}

[data-theme="dark"] .uc-input::placeholder {
    color: #6b7280;
}

[data-theme="dark"] .uc-input:focus {
    border-color: var(--accent, #2563eb);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

[data-theme="dark"] .uc-panel__input-area {
    background: var(--bg-surface, #1a202c);
    border-top-color: #334155;
}

[data-theme="dark"] .uc-rate-note {
    color: #6b7280;
}

/* ─── Responsive Design ────────────────────────────────────────────── */

/* Desktop */
@media (min-width: 769px) {
    .uc-panel {
        top: 60px;
        height: calc(100% - 60px);
    }
}

/* Tablet and larger */
@media (max-width: 768px) {
    .uc-panel {
        top: 56px;
        height: calc(100% - 56px);
    }
}

@media (max-width: 480px) {
    .uc-panel {
        width: 100%;
        max-width: 100vw;
        top: 56px;
        height: calc(100% - 56px);
    }

    .uc-backdrop {
        top: 56px;
    }

    .uc-tab-btn {
        display: none;
    }

    .uc-mobile-tab-btn {
        display: flex;
    }

    .uc-panel.is-open {
        z-index: 10002;
    }
}

/* Prevent scrolling when panel is open (on mobile) */
html.uc-open-mobile {
    overflow: hidden;
}
