@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
        'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    height: 100vh;
    background-color: #f0f0f0;
}

/* Login Screen Styles */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    background: linear-gradient(135deg, #FB651E 0%, #FF8C42 100%);
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 48px;
    text-align: center;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
    max-width: 400px;
    width: 100%;
}

.login-card h1 {
    font-size: 32px;
    font-weight: 700;
    color: #1f2937;
    margin-bottom: 16px;
}

.login-card p {
    color: #6b7280;
    font-size: 16px;
    margin-bottom: 32px;
}

.login-button {
    background: #FB651E;
    color: white;
    border: none;
    padding: 16px 32px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
}

.login-button:hover {
    background: #e55a1a;
    transform: translateY(-2px);
}

/* Chat Screen Styles */
.chat-container {
    display: flex;
    height: 100vh;
    background-color: white;
}

.sidebar {
    width: 256px;
    background-color: #E8EAED;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid #d1d5db;
    font-size: 18px;
    font-weight: 600;
    color: #1f2937;
}

.new-chat-button {
    margin: 16px;
    background-color: #FB651E;
    color: white;
    padding: 8px 16px;
    border-radius: 10px;
    border: none;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    transition: all 0.2s;
}

.new-chat-button:hover {
    background-color: #e55a1a;
}

.new-chat-button span {
    margin-right: 8px;
}

.chat-list {
    flex: 1;
    padding: 0 16px;
    overflow-y: auto;
    max-height: calc(100vh - 200px); /* Account for header and user profile */
}

.chat-item {
    padding: 8px 12px;
    color: #374151;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 14px;
    transition: all 0.2s;
}

.chat-item:hover {
    background-color: #d1d5db;
}

/* Conversation list styles */
.conversation-item {
    padding: 8px 12px;
    color: #374151;
    cursor: pointer;
    border-radius: 6px;
    margin-bottom: 4px;
    font-size: 14px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
    -webkit-tap-highlight-color: transparent;
}

.conversation-item:hover {
    background-color: #d1d5db;
}

.conversation-item.active {
    background-color: #FB651E;
    color: white;
}

.conversation-item.active:hover {
    background-color: #e55a1a;
}

.conversation-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    margin-right: 8px;
}

.menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0;
    border-radius: 4px;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s;
    flex-shrink: 0;
    width: 24px;
    height: 24px;
}

.menu-icon {
    font-size: 18px;
    line-height: 1;
}

.conversation-item:hover .menu-btn {
    opacity: 0.7;
    visibility: visible;
}

.conversation-item:hover .menu-btn:hover {
    opacity: 1;
}

.no-conversations {
    padding: 16px 12px;
    color: #6b7280;
    font-size: 14px;
    text-align: center;
    font-style: italic;
}

.user-profile {
    padding: 16px;
    border-top: 1px solid #d1d5db;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.user-info {
    display: flex;
    align-items: center;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background-color: #FB651E;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
}

.user-name {
    margin-left: 8px;
    font-size: 14px;
    color: #374151;
}

.logout-button {
    background: none;
    border: 1px solid #d1d5db;
    color: #374151;
    padding: 4px 8px;
    border-radius: 6px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.logout-button:hover {
    background-color: #f3f4f6;
}

.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.header {
    background-color: #FB651E;
    color: white;
    padding: 16px;
    font-size: 20px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 56px;
    /* Ensure header content doesn't overflow */
    overflow: hidden;
}

.messages-area {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background-color: #F2F4F8;
}

.welcome-message {
    text-align: center;
    padding-top: 48px;
    padding-bottom: 48px;
}

.welcome-message h2 {
    font-size: 24px;
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 16px;
}

.welcome-message p {
    color: #6b7280;
    font-size: 16px;
}

.messages-container {
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-width: none;
    margin: 0 20px;
    width: calc(100% - 40px);
}

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-assistant {
    display: flex;
    justify-content: flex-start;
}

.message-bubble-user {
    background-color: rgba(251, 101, 30, 0.2); /* 20% of header color #FB651E */
    color: #1f2937;
    padding: 12px 16px;
    border-radius: 10px;
    max-width: 80%;
}

.message-bubble-assistant {
    background-color: #D1D5DB;
    color: #1f2937;
    padding: 12px 16px;
    border-radius: 10px;
    max-width: 80%;
}

/* Markdown content styling */
.message-bubble-assistant h1,
.message-bubble-assistant h2,
.message-bubble-assistant h3,
.message-bubble-assistant h4,
.message-bubble-assistant h5,
.message-bubble-assistant h6 {
    margin: 12px 0 8px 0;
    font-weight: bold;
}

.message-bubble-assistant h1 { font-size: 1.5em; }
.message-bubble-assistant h2 { font-size: 1.3em; }
.message-bubble-assistant h3 { font-size: 1.1em; }

.message-bubble-assistant p {
    margin: 8px 0;
    line-height: 1.4;
}

.message-bubble-assistant ul,
.message-bubble-assistant ol {
    margin: 8px 0;
    padding-left: 20px;
}

.message-bubble-assistant li {
    margin: 4px 0;
}

.message-bubble-assistant blockquote {
    border-left: 3px solid #999;
    margin: 8px 0;
    padding-left: 12px;
    color: #555;
    font-style: italic;
}

.message-bubble-assistant code {
    background-color: #1f2937;
    color: #e5e7eb;
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Fira Code', monospace;
    font-size: 0.9em;
    font-weight: 400;
}

.message-bubble-assistant pre {
    background-color: #0d1117;
    border: 1px solid #30363d;
    padding: 16px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    max-width: 100%;
    width: 100%;
    box-sizing: border-box;
}

.message-bubble-assistant pre code {
    background: none;
    padding: 0;
    border-radius: 0;
    font-size: 0.85em;
    line-height: 1.6;
    white-space: pre;
    display: block;
    /* Remove color: inherit to let highlight.js apply its own colors */
}

/* Ensure code blocks are responsive and scrollable */
.message-bubble-assistant pre code.hljs {
    background: transparent !important;
    padding: 0 !important;
    /* Let highlight.js handle all colors - don't override them */
}

/* Mobile responsiveness for code blocks */
@media (max-width: 768px) {
    .message-bubble-assistant pre {
        padding: 12px;
        margin: 8px 0;
        font-size: 0.8em;
    }
    
    .message-bubble-assistant pre code {
        font-size: 0.8em;
    }
}

.message-bubble-assistant table {
    border-collapse: collapse;
    margin: 8px 0;
    width: 100%;
}

.message-bubble-assistant th,
.message-bubble-assistant td {
    border: 1px solid #999;
    padding: 6px 8px;
    text-align: left;
}

.message-bubble-assistant th {
    background-color: rgba(0, 0, 0, 0.1);
    font-weight: bold;
}


.message-bubble-assistant del {
    opacity: 0.7;
}

.message-bubble-assistant a {
    color: #0066cc;
    text-decoration: underline;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background-color: #6b7280;
    border-radius: 50%;
    animation: bounce 1s infinite;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.1s;
}

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

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.8);
    }
    40% {
        transform: scale(1.2);
    }
}

.input-area {
    border-top: 1px solid #e5e7eb;
    padding: 16px;
    background-color: white;
}

.input-container {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: none;
    margin: 0 20px;
    width: calc(100% - 40px);
}

#message-input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 10px;
    padding: 14px 18px;
    font-size: 14px;
    outline: none;
    font-family: inherit;
    resize: none;
    min-height: 44px;
    max-height: 300px;
    overflow-y: auto;
}

#message-input:focus {
    border-color: #FB651E;
}

.send-button {
    background-color: #FB651E;
    color: white;
    padding: 12px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    transition: all 0.2s;
}

.send-button:hover {
    background-color: #e55a1a;
}

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

.send-button:disabled:hover {
    background-color: #FB651E;
}

.plus-button {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    background: #ffffff;
    color: #111827;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color 0.2s, background-color 0.2s;
}

.plus-button:hover {
    border-color: #FB651E;
    background-color: #fff7ed;
}

.plus-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.file-input-hidden {
    position: fixed;
    left: -9999px;
    width: 1px;
    height: 1px;
    opacity: 0;
    pointer-events: none;
}

.attachment-strip {
    margin: 10px 20px 0 20px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.attachment-thumb {
    width: 96px;
    height: 96px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    background: #f9fafb;
    overflow: hidden;
    position: relative;
    cursor: pointer;
}

.attachment-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.attachment-thumb .attachment-status {
    position: absolute;
    left: 6px;
    bottom: 6px;
    background: rgba(17, 24, 39, 0.75);
    color: #fff;
    font-size: 12px;
    padding: 2px 6px;
    border-radius: 8px;
}

.attachment-thumb .attachment-remove {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: none;
    background: rgba(17, 24, 39, 0.75);
    color: #fff;
    cursor: pointer;
    line-height: 22px;
    text-align: center;
    padding: 0;
}

.messages-area {
    position: relative;
}

.drop-overlay {
    display: none;
    position: absolute;
    inset: 0;
    background: rgba(251, 101, 30, 0.08);
    border: 2px dashed rgba(251, 101, 30, 0.6);
    color: #111827;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    z-index: 10;
    pointer-events: none;
}

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

.image-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
}

.image-modal[aria-hidden="false"] {
    display: block;
}

.image-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
}

.image-modal-content {
    position: absolute;
    inset: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#image-modal-img {
    max-width: 100%;
    max-height: 100%;
    border-radius: 12px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4);
    background: #111827;
}

.image-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(17, 24, 39, 0.85);
    color: #fff;
    font-size: 26px;
    cursor: pointer;
}

/* Hamburger Menu Styles */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    flex-direction: column;
    gap: 3px;
    padding: 8px;
    border-radius: 4px;
    transition: all 0.2s;
}

.sidebar-toggle:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.hamburger-line {
    width: 20px;
    height: 2px;
    background-color: white;
    border-radius: 1px;
    transition: all 0.3s ease;
}

.sidebar-toggle.active .hamburger-line:nth-child(1) {
    transform: rotate(45deg) translate(4px, 4px);
}

.sidebar-toggle.active .hamburger-line:nth-child(2) {
    opacity: 0;
}

.sidebar-toggle.active .hamburger-line:nth-child(3) {
    transform: rotate(-45deg) translate(4px, -4px);
}

/* Mobile Responsive Design */
@media (max-width: 768px) {
    .chat-container {
        position: relative;
        overflow: hidden;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height */
        height: -webkit-fill-available; /* iOS Safari fallback */
    }
    
    .header {
        padding: 12px 16px;
        font-size: 18px;
        min-height: 48px;
        /* Better text positioning on mobile */
        line-height: 1.2;
    }
    
    .header .sidebar-toggle {
        flex-shrink: 0;
        margin-right: 8px;
    }
    
    .header-title {
        flex: 1;
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        padding: 0 8px;
        font-weight: 600;
    }
    
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        opacity: 0;
        visibility: hidden;
        transition: all 0.3s ease;
    }
    
    .sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .main-area {
        width: 100%;
        margin-left: 0;
    }
    
    .sidebar-toggle {
        display: flex;
    }
    
    .login-card {
        margin: 20px;
        padding: 32px;
    }
    
    .login-card h1 {
        font-size: 24px;
    }
    
    .messages-area {
        padding: 16px 12px;
        /* Add bottom padding to prevent last message from being hidden behind input */
        padding-bottom: 24px;
    }
    
    .input-area {
        padding: 16px 12px;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        position: sticky;
        bottom: 0;
        background-color: white;
        border-top: 1px solid #e5e7eb;
        /* Ensure input area stays above other content */
        z-index: 10;
    }
    
    .message-bubble-user,
    .message-bubble-assistant {
        max-width: calc(100vw - 80px);
        word-wrap: break-word;
        line-height: 1.4;
    }
    
    .input-container {
        gap: 12px;
        /* Ensure container doesn't exceed viewport width */
        max-width: calc(100vw - 24px);
        margin: 0 auto;
    }
    
    #message-input {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 14px 16px;
        border-radius: 12px;
        /* Better mobile touch target */
        min-height: 44px;
    }
    
    .send-button {
        width: 44px;
        height: 44px;
        padding: 10px;
    }
    
}

/* Context menu for mobile */
.context-menu {
    position: fixed;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    min-width: 120px;
    display: none;
}

.context-menu.show {
    display: block;
}

.context-menu-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f3f4f6;
    color: #374151;
    font-size: 14px;
    transition: background-color 0.2s;
}

.context-menu-item:last-child {
    border-bottom: none;
}

.context-menu-item:hover {
    background-color: #f9fafb;
}

.context-menu-item.delete {
    color: #dc2626;
}

.context-menu-item.delete:hover {
    background-color: #fef2f2;
}

/* Hide menu buttons on touch devices to prevent conflicts with long press */
.touch-device .menu-btn {
    display: none !important;
}

/* Inline conversation rename input */
.conversation-name-edit {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    padding: 6px 0;
    font-size: 14px;
    font-family: inherit;
    background-color: #ffffff;
}

/* Ensure viewport height is respected */
html, body {
    height: 100%;
    overflow: hidden;
}

.chat-container {
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile browsers */
    max-height: 100vh;
    max-height: 100dvh;
}

.messages-area {
    height: 0; /* This allows flex: 1 to work properly */
    min-height: 0;
}

/* iOS Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .chat-container {
        height: -webkit-fill-available;
        min-height: -webkit-fill-available;
    }
    
    .input-area {
        position: sticky;
        bottom: 0;
        background-color: white;
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
    
    /* Fix for iOS viewport issues */
    .messages-area {
        padding-bottom: 32px;
    }
}

/* Persistence status icons */
.persistence-icon {
    font-size: 12px;
    margin-left: 8px;
    opacity: 0.7;
    color: #6b7280;
    display: inline-block;
}

.persistence-icon.spinning {
    animation: spin 1s linear infinite;
}

.persistence-icon.success {
    color: #6b7280; /* Grey checkmark as requested */
}

.persistence-icon.failed {
    color: #6b7280; /* Grey triangle as requested */
}

@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}
