
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

button {
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

:root {
    
    --primary-color: #667eea;
    --primary-dark: #5568d3;
    --primary-light: #8693f3;
    --secondary-color: #764ba2;
    
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --bg-chat-user: #667eea;
    --bg-chat-ai: #f1f3f4;
    
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --text-tertiary: #9ca3af;
    --text-on-primary: #ffffff;
    
    --border-color: #e5e7eb;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    
    --header-height: 64px;
    --input-height: auto;
    --sidebar-width: 280px;
    
    --transition-fast: 0.15s ease;
    --transition-base: 0.3s ease;
    --transition-slow: 0.5s ease;
}


body.dark-theme {
    --bg-primary: #1a1a1a;
    --bg-secondary: #2d2d2d;
    --bg-tertiary: #3d3d3d;
    --bg-chat-user: #667eea;
    --bg-chat-ai: #2d2d2d;
    
    --text-primary: #f9fafb;
    --text-secondary: #d1d5db;
    --text-tertiary: #9ca3af;
    
    --border-color: #404040;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    transition: background-color var(--transition-base), color var(--transition-base);
    overflow-x: hidden;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    position: relative;
}

.header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: var(--header-height);
    background-color: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    transition: all var(--transition-base);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    height: 100%;
    padding: 0 12px;
    max-width: 1400px;
    margin: 0 auto;
    gap: 0;
}

.header-content #menuToggle {
    margin-right: 8px;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
    margin-right: auto;
}

.logo-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.logo-icon svg {
    width: 28px;
    height: 28px;
}

.logo-text {
    font-size: 16px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    background-color: transparent;
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

.btn-icon:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.btn-icon:active {
    transform: scale(0.95);
}

.sidebar {
    position: fixed;
    top: var(--header-height);
    left: -100%;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    z-index: 999;
    transition: left var(--transition-base);
    display: flex;
    flex-direction: column;
}

.sidebar.active {
    left: 0;
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.sidebar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 12px;
}

.chat-history {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.history-item {
    padding: 12px;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-tertiary) 100%);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    border: 2px solid transparent;
    box-shadow: var(--shadow-sm);
}

.history-item:hover {
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    border-color: var(--primary-color);
    transform: translateX(4px);
    box-shadow: var(--shadow-md);
}

.history-item.active {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--text-on-primary);
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.history-item-title {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.history-item.active .history-item-title {
    color: var(--text-on-primary);
    font-weight: 700;
}

.history-item-time {
    font-size: 11px;
    color: var(--text-tertiary);
    font-weight: 500;
    opacity: 0.8;
}

.history-item.active .history-item-time {
    color: rgba(255, 255, 255, 0.9);
    opacity: 1;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    background-color: transparent;
    color: var(--text-primary);
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-secondary:hover {
    background-color: var(--bg-secondary);
    border-color: var(--text-tertiary);
}

.main-container {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    min-height: calc(-webkit-fill-available - var(--header-height));
    height: calc(100vh - var(--header-height));
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden;
    padding-bottom: 0;
}

.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 16px 80px 16px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    height: 100%;
}

.welcome-screen.hidden {
    display: none;
}

.welcome-content {
    text-align: center;
    max-width: 800px;
    width: 100%;
    padding: 10px;
}

.welcome-icon {
    margin-bottom: 24px;
    animation: fadeInUp 0.6s ease;
}

.welcome-title {
    font-size: clamp(24px, 6vw, 32px);
    font-weight: 700;
    margin-bottom: 12px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: fadeInUp 0.6s ease 0.1s both;
    word-wrap: break-word;
}

.welcome-subtitle {
    font-size: clamp(14px, 4vw, 18px);
    color: var(--text-secondary);
    margin-bottom: 32px;
    animation: fadeInUp 0.6s ease 0.2s both;
    word-wrap: break-word;
}

.suggestion-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-top: 24px;
}

.suggestion-card {
    padding: 16px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-base);
    text-align: left;
    animation: fadeInUp 0.6s ease both;
    min-height: 120px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.suggestion-card:nth-child(1) { animation-delay: 0.3s; }
.suggestion-card:nth-child(2) { animation-delay: 0.4s; }
.suggestion-card:nth-child(3) { animation-delay: 0.5s; }
.suggestion-card:nth-child(4) { animation-delay: 0.6s; }

.suggestion-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.suggestion-icon {
    font-size: 32px;
    margin-bottom: 12px;
}

.suggestion-card h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.suggestion-card p {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.chat-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px 12px 80px 12px;
    display: none;
    -webkit-overflow-scrolling: touch;
    height: 100%;
}

.chat-container.active {
    display: block;
}

.messages {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* Message Styles */
.message {
    display: flex;
    gap: 12px;
    animation: fadeInUp 0.3s ease;
}

.message.user {
    flex-direction: row-reverse;
}

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

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--text-on-primary);
}

.message.ai .message-avatar {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.message-content {
    flex: 1;
    max-width: 75%;
}

.message.user .message-content {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

.message-bubble {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    word-wrap: break-word;
    line-height: 1.6;
}

.message-bubble strong {
    font-weight: 700;
    color: inherit;
}

.message-bubble em {
    font-style: italic;
}

.message-bubble code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    font-size: 0.9em;
}

.message-bubble ul {
    margin: 8px 0;
    padding-left: 0;
    list-style: none;
}

.message-bubble li {
    margin: 4px 0;
    padding-left: 20px;
    position: relative;
}

.message-bubble li::before {
    content: '•';
    position: absolute;
    left: 0;
    font-weight: bold;
    color: var(--primary-color);
}

.message-bubble .numbered-item {
    margin: 6px 0;
    display: flex;
    gap: 8px;
}

.message-bubble .numbered-item .number {
    font-weight: 700;
    color: var(--primary-color);
    min-width: 24px;
}

.message.user .message-bubble code {
    background-color: rgba(255, 255, 255, 0.2);
}

.message.user .message-bubble li::before {
    color: rgba(255, 255, 255, 0.9);
}

.message.user .message-bubble .numbered-item .number {
    color: rgba(255, 255, 255, 0.9);
}

.message.user .message-bubble {
    background-color: var(--bg-chat-user);
    color: var(--text-on-primary);
    border-bottom-right-radius: 4px;
}

.message.ai .message-bubble {
    background-color: var(--bg-chat-ai);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 12px;
    color: var(--text-tertiary);
    margin-top: 4px;
    padding: 0 4px;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--text-tertiary);
    animation: typing 1.4s infinite;
}

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

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

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

.input-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    padding: 12px;
    background-color: var(--bg-primary);
    border-top: 1px solid var(--border-color);
    z-index: 100;
    flex-shrink: 0;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 8px;
    transition: all var(--transition-fast);
}

.input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background-color: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 15px;
    resize: none;
    outline: none;
    min-height: 24px;
    max-height: 120px;
    padding: 8px;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: var(--text-tertiary);
}

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: var(--text-on-primary);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.btn-send:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn-send:active {
    transform: translateY(0);
}

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

.input-footer {
    max-width: 800px;
    margin: 8px auto 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    color: var(--text-tertiary);
    padding: 0 4px;
}

.char-count {
    font-weight: 500;
}

.input-hint {
    text-align: right;
}

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

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}


::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--text-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

html {
    height: 100%;
    height: -webkit-fill-available;
}

@media screen and (max-width: 767px) {
    input[type="text"],
    input[type="email"],
    input[type="password"],
    textarea {
        font-size: 16px !important;
    }
    
    .btn-icon {
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        height: 44px;
    }
    
    .btn-send {
        min-width: 44px;
        min-height: 44px;
    }
    
    .chat-input {
        font-size: 16px;
        line-height: 1.5;
        -webkit-appearance: none;
    }
    
    .sidebar {
        width: 85%;
        max-width: 320px;
    }
}

@supports (padding: max(0px)) {
    .header {
        padding-left: max(12px, env(safe-area-inset-left));
        padding-right: max(12px, env(safe-area-inset-right));
    }
    
    .input-container {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

@media (min-width: 576px) {
    .suggestion-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .message-content {
        max-width: 70%;
    }
}

@media (min-width: 768px) {
    .header-content {
        padding: 0 24px;
        gap: 12px;
    }
    
    .logo-container {
        gap: 12px;
    }
    
    .logo-icon svg {
        width: 32px;
        height: 32px;
    }
    
    .logo-text {
        font-size: 20px;
    }
    
    .header-actions {
        gap: 8px;
    }
    
    .btn-icon {
        width: 40px;
        height: 40px;
    }
    
    .btn-icon svg {
        width: 20px;
        height: 20px;
    }
    
    .welcome-title {
        font-size: 40px;
    }
    
    .welcome-subtitle {
        font-size: 20px;
    }
    
    .suggestion-cards {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .chat-container {
        padding: 32px 24px 100px 24px;
    }
    
    .input-container {
        padding: 20px 24px;
    }
    
    .message-content {
        max-width: 65%;
    }
}
@media (min-width: 1024px) {
    .header-content {
        padding: 0 32px;
    }
    
    .main-container {
        margin-left: 0;
        transition: margin-left var(--transition-base);
    }
    
    .main-container.sidebar-open {
        margin-left: var(--sidebar-width);
    }
    
    .sidebar {
        left: -100%;
    }
    
    .sidebar.active {
        left: 0;
    }
    
    .suggestion-cards {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .chat-container {
        padding: 40px 32px 100px 32px;
    }
    
    .input-container {
        padding: 24px 32px;
    }
    
    .main-container.sidebar-open .input-container {
        left: var(--sidebar-width);
        width: calc(100% - var(--sidebar-width));
    }
    
    .message-content {
        max-width: 60%;
    }
    
    .message-bubble {
        padding: 14px 18px;
    }
}

@media (min-width: 1440px) {
    .welcome-title {
        font-size: 48px;
    }
    
    .welcome-subtitle {
        font-size: 22px;
    }
    
    .message-content {
        max-width: 55%;
    }
}

.attachment-preview-container {
    display: flex;
    gap: 8px;
    padding: 8px;
    flex-wrap: wrap;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    margin-bottom: 8px;
}

.attachment-preview {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 4px;
    padding: 8px;
    border: 2px solid var(--border-color);
}

.attachment-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    position: absolute;
    top: 0;
    left: 0;
}

.attachment-preview .file-icon {
    font-size: 32px;
}

.attachment-preview .file-name {
    font-size: 10px;
    color: var(--text-secondary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    z-index: 1;
}

.remove-attachment {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background-color: #ef4444;
    color: white;
    border: 2px solid var(--bg-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    transition: all var(--transition-fast);
    z-index: 2;
}

.remove-attachment:hover {
    background-color: #dc2626;
    transform: scale(1.1);
}


.message-attachments {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.message-attachment {
    border-radius: var(--radius-sm);
    overflow: hidden;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
}

.message-attachment img {
    max-width: 300px;
    max-height: 300px;
    width: 100%;
    height: auto;
    display: block;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.message-attachment img:hover {
    opacity: 0.9;
    transform: scale(1.02);
}

.message.user .message-attachment {
    border-color: rgba(255, 255, 255, 0.3);
}

.file-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    min-width: 200px;
}

.file-info .file-icon {
    font-size: 24px;
}

.file-info .file-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.file-info .file-size {
    font-size: 12px;
    color: var(--text-tertiary);
}

.message.user .file-info .file-name {
    color: var(--text-on-primary);
}

.message.user .file-info .file-size {
    color: rgba(255, 255, 255, 0.7);
}

.image-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.9);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
    animation: fadeIn 0.2s ease;
    padding: 20px;
}

.image-modal img {
    max-width: 90%;
    max-height: 90%;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-xl);
    cursor: default;
}

.hidden {
    display: none !important;
}

.fade-in {
    animation: fadeIn 0.3s ease;
}

.no-scroll {
    overflow: hidden;
}

@media print {
    .header,
    .sidebar,
    .input-container {
        display: none;
    }
    
    .main-container {
        margin-top: 0;
        height: auto;
    }
    
    .chat-container {
        display: block;
    }
    
    .message {
        page-break-inside: avoid;
    }
}
