/**
 * ASTRA Claude-Style Layout v1.0
 * Layout: Sidebar (collapsible) | Chat (center) | Preview (right)
 * Palette: #0060ff
 */

/* ============================================
   LAYOUT PRINCIPALE 3 COLONNE
   ============================================ */

html {
    background: #0a0a1a !important;
}

.claude-layout {
    display: grid;
    grid-template-columns: auto 1fr auto;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "header header header"
        "sidebar chat preview";
    height: 100vh;
    background: transparent;
    overflow: hidden;
    position: relative;
    z-index: 1;
}

.claude-layout .header {
    grid-area: header;
    background: rgba(10, 10, 20, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(0, 96, 255, 0.2);
    padding: 12px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    z-index: 100;
}

/* ============================================
   SIDEBAR SINISTRA (Collapsible)
   ============================================ */

.claude-sidebar {
    grid-area: sidebar;
    width: 280px;
    background: rgba(10, 10, 20, 0.80);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-right: 1px solid rgba(0, 96, 255, 0.15);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, transform 0.3s ease;
    overflow: visible;
    position: relative;
    height: 100%;
    min-height: 0;              /* grid item: allow shrink for scroll */
    align-self: stretch;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
    height: 0; /* trick flex scroll */
}

.claude-sidebar.collapsed {
    width: 60px;
}

.claude-sidebar.collapsed .sidebar-content {
    opacity: 0;
    pointer-events: none;
}

.claude-sidebar.collapsed .sidebar-icons {
    opacity: 1;
}

.sidebar-toggle {
    position: absolute;
    right: -14px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: var(--jarvis-primary, #0060ff);
    border: 2px solid #0a0a0f;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: all 0.2s ease;
}

.sidebar-toggle::after {
    content: '\2039';
    color: white;
    font-size: 16px;
    font-weight: bold;
    line-height: 1;
}

.sidebar-toggle:hover {
    background: #4f46e5;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 0 15px rgba(0, 96, 255, 0.5);
}

.claude-sidebar.collapsed .sidebar-toggle::after {
    content: '\203a';
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid rgba(0, 96, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-section {
    padding: 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.sidebar-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 12px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    color: rgba(255, 255, 255, 0.7);
    font-size: 14px;
}

.sidebar-item:hover {
    background: rgba(0, 96, 255, 0.1);
    color: #fff;
}

.sidebar-item.active {
    background: rgba(0, 96, 255, 0.15);
    color: var(--jarvis-primary);
}

.sidebar-item-icon {
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
}

/* Mini metrics in sidebar */
.sidebar-metrics {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
}

.sidebar-metric {
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    padding: 10px;
    text-align: center;
}

.sidebar-metric-value {
    font-size: 18px;
    font-weight: 600;
    color: var(--jarvis-primary);
}

.sidebar-metric-label {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    text-transform: uppercase;
}

/* ============================================
   CHAT AREA CENTRALE
   ============================================ */

.claude-chat {
    grid-area: chat;
    display: flex;
    flex-direction: column;
    background: rgba(13, 13, 18, 0.40);
    min-width: 0;
    min-height: 0;
    height: 100%;
    overflow: hidden;
    position: relative;  /* Per drop overlay */
    z-index: 0;
}

.chat-messages {
    position: relative;
    z-index: 1;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 96, 255, 0.3);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 96, 255, 0.5);
}

/* Message containers */
.message-group {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    overflow: hidden;  /* Previene overflow da contenuto lungo */
}

.message-user {
    display: flex;
    gap: 16px;
    align-items: flex-start;
}

.message-assistant {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    background: rgba(0, 96, 255, 0.03);
    margin: 0 -24px;
    padding: 24px;
    border-top: 1px solid rgba(0, 96, 255, 0.1);
    border-bottom: 1px solid rgba(0, 96, 255, 0.1);
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 14px;
}

.message-user .message-avatar {
    background: linear-gradient(135deg, #9d4edd 0%, #7b2cbf 100%);
    color: white;
}

.message-assistant .message-avatar {
    background: linear-gradient(135deg, var(--jarvis-primary) 0%, var(--jarvis-primary-dark) 100%);
    color: white;
    box-shadow: 0 0 15px rgba(0, 96, 255, 0.3);
}

.message-content {
    flex: 1;
    min-width: 0;
    overflow: hidden;  /* Previene overflow orizzontale */
}

.message-text {
    color: #e5e5e5;
    line-height: 1.7;
    font-size: 15px;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text p {
    margin: 0 0 12px 0;
}

.message-text p:last-child {
    margin-bottom: 0;
}

.message-text code {
    background: rgba(0, 96, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', 'Consolas', monospace;
    font-size: 13px;
    color: var(--jarvis-primary-light);
}

.message-text pre {
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(0, 96, 255, 0.2);
    border-radius: 8px;
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    max-width: 100%;
}

.message-text pre code {
    background: none;
    padding: 0;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.4);
}

.message-provider {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: rgba(0, 96, 255, 0.1);
    border-radius: 4px;
    font-size: 11px;
    color: var(--jarvis-primary);
}

/* ============================================
   INPUT AREA (Bottom)
   ============================================ */

.chat-input-area {
    padding: 16px 24px 24px;
    background: rgba(10, 10, 20, 0.88);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-top: 1px solid rgba(0, 96, 255, 0.1);
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.chat-input-container {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    background: rgba(20, 20, 28, 0.95);
    border: 1px solid rgba(0, 96, 255, 0.2);
    border-radius: 16px;
    padding: 12px 16px;
    transition: all 0.3s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--jarvis-primary);
    box-shadow: 0 0 0 3px rgba(0, 96, 255, 0.1), 0 0 20px rgba(0, 96, 255, 0.15);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 15px;
    line-height: 1.5;
    resize: none;
    max-height: 200px;
    min-height: 24px;
    outline: none;
    font-family: inherit;
}

.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3);
}

.chat-input-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-btn {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-btn:hover {
    background: rgba(0, 96, 255, 0.1);
    color: var(--jarvis-primary);
}

.chat-btn-send {
    background: var(--jarvis-primary);
    color: white;
    box-shadow: 0 0 15px rgba(0, 96, 255, 0.3);
}

.chat-btn-send:hover {
    background: var(--jarvis-primary-light);
    box-shadow: 0 0 20px rgba(0, 96, 255, 0.5);
    transform: scale(1.05);
}

.chat-btn-send:disabled {
    background: rgba(0, 96, 255, 0.3);
    cursor: not-allowed;
    box-shadow: none;
}

/* Voice mic button — recording state */
.chat-btn-mic-active {
    background: #ff3333 !important;
    color: white !important;
    box-shadow: 0 0 15px rgba(255, 51, 51, 0.5);
    animation: mic-pulse 1.5s ease-in-out infinite;
}

@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 10px rgba(255, 51, 51, 0.4); transform: scale(1); }
    50% { box-shadow: 0 0 25px rgba(255, 51, 51, 0.7); transform: scale(1.08); }
}

/* Wake word — passive listening state */
.chat-btn-mic-passive {
    color: rgba(0, 96, 255, 0.7) !important;
    animation: mic-passive-pulse 3s ease-in-out infinite;
}

@keyframes mic-passive-pulse {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 1; }
}

.input-hint {
    text-align: center;
    font-size: 11px;
    color: rgba(255, 255, 255, 0.3);
    margin-top: 8px;
}

.input-hint kbd {
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: inherit;
}

/* ============================================
   PREVIEW PANEL DESTRA
   ============================================ */

.claude-preview {
    grid-area: preview;
    width: 0;
    background: rgba(10, 10, 20, 0.80);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-left: 1px solid rgba(0, 96, 255, 0.15);
    transition: width 0.3s ease;
    overflow: hidden;
}

.claude-preview.open {
    width: 320px;
}

.preview-header {
    padding: 16px;
    border-bottom: 1px solid rgba(0, 96, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.preview-title {
    font-size: 14px;
    font-weight: 600;
    color: #fff;
}

.preview-buttons {
    display: flex;
    gap: 4px;
}

.preview-close {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.claude-preview.minimized .preview-content {
    display: none;
}

.claude-preview.minimized {
    width: 320px;
}

.preview-content {
    padding: 16px;
    overflow-y: auto;
    height: calc(100% - 60px);
}

.preview-image {
    width: 100%;
    border-radius: 8px;
    margin-bottom: 12px;
}

.preview-info {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
}

/* ============================================
   TYPING INDICATOR
   ============================================ */

.typing-indicator {
    display: flex;
    gap: 16px;
    align-items: flex-start;
    max-width: 800px;
    margin: 0 auto;
}

.typing-dots {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--jarvis-primary);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ============================================
   WELCOME SCREEN
   ============================================ */

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.welcome-jarvis {
    margin-bottom: 32px;
}

.welcome-title {
    font-size: 32px;
    font-weight: 300;
    color: #fff;
    margin-bottom: 8px;
}

.welcome-title strong {
    font-weight: 600;
    color: var(--jarvis-primary);
}

.welcome-subtitle {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.5);
}

.welcome-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
    max-width: 600px;
    margin-top: 32px;
}

.suggestion-chip {
    padding: 10px 16px;
    background: rgba(0, 96, 255, 0.1);
    border: 1px solid rgba(0, 96, 255, 0.2);
    border-radius: 20px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-chip:hover {
    background: rgba(0, 96, 255, 0.2);
    border-color: var(--jarvis-primary);
    color: #fff;
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 1200px) {
    .claude-preview.open {
        width: 280px;
    }
}

@media (max-width: 992px) {
    .claude-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
        transform: translateX(-100%);
    }

    .claude-sidebar.open {
        transform: translateX(0);
    }

    .claude-preview {
        position: fixed;
        right: 0;
        top: 0;
        height: 100vh;
        z-index: 1000;
    }

    .mobile-overlay {
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s ease;
    }

    .mobile-overlay.active {
        opacity: 1;
        pointer-events: auto;
    }
}

@media (max-width: 576px) {
    .chat-input-area {
        padding: 12px 16px 16px;
    }

    .chat-messages {
        padding: 16px;
    }

    .message-assistant {
        margin: 0 -16px;
        padding: 16px;
    }
}

/* ==================== CONVERSATION HISTORY ==================== */
.conversation-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.conversation-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.conversation-item:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
}

.conversation-item.active {
    background: rgba(0, 96, 255, 0.2);
    border-color: var(--jarvis-primary);
}

.conversation-item .conv-info {
    flex: 1;
    min-width: 0;
}

.conversation-item .conv-title {
    font-size: 13px;
    font-weight: 500;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conversation-item .conv-date {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 2px;
}

.conversation-item .conv-delete {
    opacity: 0;
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: opacity 0.2s;
    font-size: 12px;
}

.conversation-item:hover .conv-delete {
    opacity: 1;
}

.conversation-item .conv-delete:hover {
    background: rgba(239, 68, 68, 0.2);
}

/* New Chat Button */
#new-chat-btn:hover {
    background: #4f46e5 !important;
    transform: scale(1.05);
}

#new-chat-btn:active {
    transform: scale(0.95);
}

/* ==================== DRAG & DROP ==================== */
.drop-overlay {
    display: none;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 96, 255, 0.15);
    border: 3px dashed var(--jarvis-primary, #0060ff);
    border-radius: 12px;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.drop-overlay.active {
    display: flex;
}

.drop-content {
    text-align: center;
    padding: 40px;
    background: rgba(15, 15, 25, 0.95);
    border-radius: 16px;
    border: 1px solid var(--jarvis-primary, #0060ff);
}

.drop-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.drop-text {
    font-size: 20px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 8px;
}

.drop-hint {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
}

/* File preview nella chat input area — compact list, NOT grid */
.file-preview-container {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px 8px 0 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    margin-bottom: 8px;
    max-height: 120px;
    overflow-y: auto;
}

.file-preview-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: rgba(0, 96, 255, 0.2);
    border-radius: 6px;
    font-size: 13px;
    color: #fff;
    border: 1px solid rgba(0, 96, 255, 0.3);
    flex-shrink: 0;
}

.file-preview-item img {
    width: 40px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
}

.file-preview-item .file-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    font-size: 20px;
}

.file-preview-item .file-info {
    max-width: 150px;
}

.file-preview-item .file-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-item .file-size {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.5);
}

.file-preview-item .file-remove {
    background: none;
    border: none;
    color: #ef4444;
    cursor: pointer;
    padding: 4px;
    font-size: 18px;
    opacity: 0.7;
    line-height: 1;
}

.file-preview-item .file-remove:hover {
    opacity: 1;
}
