/* ===== TOOLSNOVA AI ASSISTANT - COMPLETE FIXED CSS ===== */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Inter', sans-serif;
    background: #f8fafc;
    color: #0f172a;
    min-height: 100dvh;
    overflow-x: hidden;
    overflow-y: auto;
    transition: background 0.2s ease, color 0.2s ease;
    position: relative;
}

/* Dark Mode */
body.dark-mode {
    background: #0f172a;
    color: #e2e8f0;
}

.app {
    display: flex;
    min-height: 100dvh;
    width: 100%;
    position: relative;
    overflow: hidden;
}

/* ========= SIDEBAR ========= */
.sidebar {
    width: 280px;
    background: #ffffff;
    border-right: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1), width 0.2s ease;
    flex-shrink: 0;
    z-index: 100;
    overflow-y: auto;
}

body.dark-mode .sidebar {
    background: #1e293b;
    border-right-color: #334155;
}

/* Desktop collapsed state */
.sidebar.collapsed {
    width: 72px;
}

.sidebar.collapsed .sidebar-logo span,
.sidebar.collapsed .nav-links a span,
.sidebar.collapsed .history-item .history-content,
.sidebar.collapsed .chat-actions,
.sidebar.collapsed .sidebar-footer .user-info span,
.sidebar.collapsed .sidebar-footer .auth-btn span {
    display: none;
}

.sidebar.collapsed .history-item {
    justify-content: center;
    padding: 10px;
}

.sidebar.collapsed .history-item i {
    margin-right: 0;
}

.sidebar.collapsed .sidebar-logo {
    justify-content: center;
}

.sidebar.collapsed .nav-links a {
    justify-content: center;
}

/* Mobile sidebar */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        box-shadow: none;
        z-index: 1050;
        transition: transform 0.3s cubic-bezier(0.2, 0.9, 0.4, 1.1);
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 20px rgba(0,0,0,0.15);
    }
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid #e2e8f0;
    font-weight: 700;
    font-size: 1.25rem;
}

body.dark-mode .sidebar-logo {
    border-bottom-color: #334155;
}

.sidebar-logo i {
    font-size: 1.6rem;
    color: #3b82f6;
}

.nav-links {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 12px;
    text-decoration: none;
    color: #334155;
    font-weight: 500;
    transition: all 0.2s;
    cursor: pointer;
}

body.dark-mode .nav-links a {
    color: #cbd5e1;
}

.nav-links a:hover {
    background: #f1f5f9;
}

body.dark-mode .nav-links a:hover {
    background: #334155;
}

.chat-history-section {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
}

.history-header {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: #64748b;
    margin-bottom: 12px;
    padding-left: 8px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    margin-bottom: 4px;
    cursor: pointer;
    transition: background 0.15s;
}

.history-item:hover {
    background: #f1f5f9;
}

body.dark-mode .history-item:hover {
    background: #334155;
}

.history-item.active {
    background: #eef2ff;
}

body.dark-mode .history-item.active {
    background: #2d3a5e;
}

.history-content {
    flex: 1;
    overflow: hidden;
}

.history-title {
    font-size: 0.85rem;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 0.7rem;
    color: #64748b;
}

.chat-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.history-item:hover .chat-actions {
    opacity: 1;
}

.chat-action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.75rem;
    padding: 4px;
    border-radius: 6px;
    color: #5b6e8c;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid #e2e8f0;
    margin-top: auto;
}

body.dark-mode .sidebar-footer {
    border-top-color: #334155;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.auth-btn, .logout-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 12px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
}

.logout-btn {
    color: #dc2626;
}

/* ========= MAIN CHAT AREA ========= */
.main-chat {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
    min-width: 0;
}

body.dark-mode .main-chat {
    background: #0f172a;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-bottom: 1px solid #e2e8f0;
    background: inherit;
    gap: 16px;
    flex-shrink: 0;
    z-index: 10;
}

body.dark-mode .chat-header {
    border-bottom-color: #334155;
}

.mobile-menu-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: #334155;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.mobile-menu-btn:hover {
    background: #f1f5f9;
}

@media (max-width: 768px) {
    .mobile-menu-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

.current-title {
    flex: 1;
    font-weight: 600;
    font-size: 1.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.header-actions {
    display: flex;
    gap: 12px;
    flex-shrink: 0;
}

.icon-btn {
    background: transparent;
    border: none;
    font-size: 1.2rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    color: #475569;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: #f1f5f9;
}

body.dark-mode .icon-btn:hover {
    background: #334155;
}

/* ========= MESSAGES CONTAINER ========= */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 24px 20px;
    padding-bottom: 120px;
    scroll-behavior: smooth;
    background: #f9fafb;
}

body.dark-mode .messages-container {
    background: #0f172a;
}

.messages-wrapper {
    max-width: 900px;
    margin: 0 auto;
    width: 100%;
}

.welcome-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 20px;
    height: 100%;
    min-height: 400px;
}

.welcome-icon {
    font-size: 4.5rem;
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    margin-bottom: 24px;
}

.welcome-screen h2 {
    font-size: 1.8rem;
    margin-bottom: 12px;
    color: #0f172a;
}

body.dark-mode .welcome-screen h2 {
    color: #e2e8f0;
}

.welcome-screen p {
    color: #64748b;
    font-size: 1rem;
    max-width: 500px;
    line-height: 1.6;
}

/* ===== MESSAGE STYLES ===== */
.message {
    display: flex;
    gap: 14px;
    margin-bottom: 28px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.message-avatar.ai {
    background: linear-gradient(135deg, #3b82f6, #8b5cf6);
    color: white;
}

.message-avatar.user {
    background: #10b981;
    color: white;
}

.message-content {
    flex: 1;
    max-width: 75%;
    display: flex;
    flex-direction: column;
}

.message.user .message-content {
    align-items: flex-end;
}

.message-bubble {
    padding: 12px 18px;
    border-radius: 20px;
    line-height: 1.6;
    font-size: 0.95rem;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.message:not(.user) .message-bubble {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    color: #1f2937;
}

body.dark-mode .message:not(.user) .message-bubble {
    background: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}

.message.user .message-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
}

.message-time {
    font-size: 0.7rem;
    color: #9ca3af;
    margin-top: 6px;
    padding: 0 8px;
}

/* ===== CODE BLOCKS ===== */
.code-block-wrapper {
    position: relative;
    margin: 12px 0;
    background: #1e293b;
    border-radius: 12px;
    overflow: hidden;
}

.code-block-wrapper pre {
    margin: 0;
    padding: 16px;
    overflow-x: auto;
    color: #e2e8f0;
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
}

.copy-code-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: #334155;
    border: none;
    padding: 6px 12px;
    border-radius: 8px;
    color: white;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-code-btn:hover {
    background: #475569;
}

/* ===== TABLES ===== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    background: #ffffff;
    border-radius: 8px;
    overflow: hidden;
}

body.dark-mode .data-table {
    background: #1e293b;
}

.data-table th,
.data-table td {
    border: 1px solid #e2e8f0;
    padding: 10px 12px;
    text-align: left;
}

body.dark-mode .data-table th,
body.dark-mode .data-table td {
    border-color: #334155;
}

.data-table th {
    background: #f8fafc;
    font-weight: 600;
}

body.dark-mode .data-table th {
    background: #0f172a;
}

/* ===== LISTS ===== */
.message-bubble ul, 
.message-bubble ol {
    margin: 8px 0;
    padding-left: 24px;
}

.message-bubble li {
    margin: 4px 0;
    line-height: 1.6;
}

/* ===== FILE ATTACHMENTS ===== */
.file-attachment {
    background: #f1f5f9;
    padding: 8px 12px;
    border-radius: 12px;
    margin-bottom: 10px;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
}

body.dark-mode .file-attachment {
    background: #334155;
    border-color: #475569;
}

.file-attachment i {
    color: #3b82f6;
}

/* ===== FILE PREVIEW ===== */
.file-preview-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 12px;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

.file-preview {
    background: #f1f5f9;
    border-radius: 12px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    border: 1px solid #e2e8f0;
}

body.dark-mode .file-preview {
    background: #334155;
    border-color: #475569;
}

.file-preview-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.remove-file {
    background: none;
    border: none;
    cursor: pointer;
    color: #ef4444;
    font-size: 0.9rem;
    padding: 4px;
    border-radius: 6px;
    transition: background 0.2s;
}

.remove-file:hover {
    background: rgba(239, 68, 68, 0.1);
}

/* ===== INPUT AREA ===== */
.input-area {
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
    border-top: 1px solid #e2e8f0;
    background: #ffffff;
    flex-shrink: 0;
    position: sticky;
    bottom: 0;
    z-index: 5;
}

body.dark-mode .input-area {
    background: #0f172a;
    border-top-color: #334155;
}

.input-wrapper {
    max-width: 900px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 28px;
    border: 1px solid #e2e8f0;
    padding: 8px 16px;
    display: flex;
    align-items: flex-end;
    gap: 12px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

body.dark-mode .input-wrapper {
    background: #1e293b;
    border-color: #334155;
}

.input-wrapper textarea {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-family: inherit;
    font-size: 0.95rem;
    padding: 10px 0;
    outline: none;
    max-height: 120px;
    color: inherit;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: #94a3b8;
}

.send-btn {
    background: #3b82f6;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
    margin-bottom: 4px;
}

.send-btn:hover {
    background: #2563eb;
    transform: scale(1.05);
}

.send-btn i {
    color: white;
    font-size: 1rem;
}

.send-btn:disabled {
    background: #94a3b8;
    cursor: not-allowed;
    transform: none;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
    display: flex;
    gap: 6px;
    padding: 12px 18px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #94a3b8;
    border-radius: 50%;
    animation: typingPulse 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingPulse {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===== MOBILE OVERLAY ===== */
.mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    display: none;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* ===== SCROLLBAR STYLES ===== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

body.dark-mode ::-webkit-scrollbar-track {
    background: #1e293b;
}

body.dark-mode ::-webkit-scrollbar-thumb {
    background: #475569;
}

/* ===== RESPONSIVE DESIGN ===== */
@media (max-width: 768px) {
    .messages-container {
        padding: 16px 12px;
        padding-bottom: 140px;
    }
    
    .message-content {
        max-width: 85%;
    }
    
    .message-bubble {
        padding: 10px 14px;
        font-size: 0.9rem;
    }
    
    .message-avatar {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .welcome-screen h2 {
        font-size: 1.4rem;
    }
    
    .welcome-screen p {
        font-size: 0.9rem;
    }
    
    .input-area {
        padding: 12px 16px 16px;
    }
    
    .input-wrapper {
        padding: 6px 12px;
    }
    
    .input-wrapper textarea {
        font-size: 0.9rem;
        max-height: 100px;
    }
    
    .send-btn {
        width: 32px;
        height: 32px;
    }
    
    .send-btn i {
        font-size: 0.9rem;
    }
    
    .code-block-wrapper pre {
        font-size: 0.75rem;
        padding: 12px;
    }
    
    .chat-header {
        padding: 10px 16px;
    }
    
    .current-title {
        font-size: 1rem;
    }
    
    .icon-btn {
        padding: 6px;
        font-size: 1.1rem;
    }
}

@media (max-width: 480px) {
    .message-content {
        max-width: 90%;
    }
    
    .message-bubble {
        padding: 8px 12px;
        font-size: 0.85rem;
    }
    
    .file-preview {
        font-size: 0.75rem;
    }
    
    .input-area {
        padding: 10px 12px 14px;
    }
    
    .messages-container {
        padding-bottom: 70px;
    }
}

/* ===== iOS SAFARI FIX ===== */
@supports (-webkit-touch-callout: none) {
    .app {
        min-height: -webkit-fill-available;
    }
    
    body {
        min-height: -webkit-fill-available;
    }
}

/* ===== UTILITY CLASSES ===== */
.text-center {
    text-align: center;
}

.mt-2 {
    margin-top: 8px;
}

.mb-2 {
    margin-bottom: 8px;
}

/* ===== SAFE AREA SUPPORT ===== */
@supports (padding: max(0px)) {
    .input-area {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
    
    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }
}

/* ===== DYNAMIC VIEWPORT SUPPORT ===== */
@supports (height: 100dvh) {
    body,
    .app {
        min-height: 100dvh;
    }
}