* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
    background: linear-gradient(135deg, #a8e6cf 0%, #88d8a3 100%);
    min-height: 100vh;
    color: #2d5016;
    font-size: 16px;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Login Page Styles */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    background: linear-gradient(135deg, #a8e6cf 0%, #88d8a3 100%);
}

.login-container {
    width: 100%;
    max-width: 380px;
}

.login-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 32px 24px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    border: 1px solid #e8ecef;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-header i {
    font-size: 40px;
    color: #27ae60;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 500;
    color: #2d5016;
    margin-bottom: 8px;
}

.login-header p {
    color: #5a6c57;
    font-size: 15px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.error-message {
    background: #fee;
    color: #c33;
    padding: 12px 16px;
    border-radius: 10px;
    border: 1px solid #fcc;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.input-group {
    position: relative;
    display: flex;
    align-items: center;
}

.input-group i {
    position: absolute;
    left: 16px;
    color: #999;
    z-index: 1;
}

.input-group input {
    width: 100%;
    padding: 14px 16px 14px 44px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 16px;
    transition: border-color 0.2s ease;
    background: #fff;
}

.input-group input:focus {
    outline: none;
    border-color: #27ae60;
    box-shadow: 0 0 0 2px rgba(39, 174, 96, 0.1);
}

.login-btn {
    background: #27ae60;
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.login-btn:hover {
    background: #229954;
}

.login-btn:active {
    background: #1e8449;
}

/* Chat Page Styles */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    max-width: 100%;
    margin: 0;
    background: #ffffff;
}

.chat-header {
    background: #ffffff;
    color: #2c3e50;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #e8ecef;
    position: sticky;
    top: 0;
    z-index: 100;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 500;
    font-size: 16px;
}

.user-info i {
    font-size: 20px;
    color: #27ae60;
}

.header-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clear-btn, .logout-btn {
    background: #f8f9fa;
    border: 1px solid #e8ecef;
    color: #7f8c8d;
    padding: 8px 10px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.clear-btn:hover, .clear-btn:active {
    background: #fee;
    border-color: #fcc;
    color: #c33;
}

.clear-btn:focus {
    outline: 2px solid #c33;
    outline-offset: 2px;
}

.logout-btn:hover, .logout-btn:active {
    background: #e9ecef;
    color: #495057;
}

.logout-btn:focus {
    outline: 2px solid #495057;
    outline-offset: 2px;
}

.chat-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f0f8f0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
    max-width: 70%;
    animation: fadeIn 0.3s ease;
}

.message.own {
    align-self: flex-end;
}

.message.other {
    align-self: flex-start;
}

.message-content {
    padding: 10px 14px;
    border-radius: 16px;
    word-wrap: break-word;
    position: relative;
    font-size: 15px;
    line-height: 1.4;
}

.message.own .message-content {
    background: #27ae60;
    color: white;
    border-bottom-right-radius: 4px;
}

.message.other .message-content {
    background: white;
    color: #2d5016;
    border: 1px solid #d5e8d4;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.chat-notice {
    text-align: center;
    padding: 12px;
    margin: 16px 0;
    background: #e8f4fd;
    color: #1976d2;
    border-radius: 8px;
    font-size: 14px;
    border: 1px solid #bbdefb;
    animation: fadeInOut 3s ease-in-out;
}

.chat-notice i {
    margin-right: 8px;
}

@keyframes fadeInOut {
    0% { opacity: 0; transform: translateY(-10px); }
    15% { opacity: 1; transform: translateY(0); }
    85% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

.message.other .message-time {
    text-align: left;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    margin-top: 8px;
}

.message.other .message-file {
    background: #f8f9fa;
}

.file-icon {
    font-size: 24px;
    opacity: 0.8;
}

.file-info {
    flex: 1;
}

.file-name {
    font-weight: 500;
    font-size: 14px;
}

.file-size {
    font-size: 12px;
    opacity: 0.7;
}

.file-download {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: inherit;
    padding: 6px 8px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.message.other .file-download {
    background: #e9ecef;
    color: #333;
}

.file-download:hover {
    background: rgba(255, 255, 255, 0.3);
}

.message.other .file-download:hover {
    background: #dee2e6;
}

.message-image {
    margin-top: 8px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 300px;
}

.message-image img {
    width: 100%;
    height: auto;
    display: block;
}

.message-video {
    margin-top: 8px;
    border-radius: 12px;
    overflow: hidden;
    max-width: 300px;
}

.message-video video {
    width: 100%;
    height: auto;
    display: block;
}

.chat-input-container {
    background: white;
    border-top: 1px solid #e8ecef;
    padding: 12px 16px 16px 16px;
    position: sticky;
    bottom: 0;
}

.file-preview {
    background: #f8f9fa;
    border: 1px solid #e8ecef;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.upload-progress-container {
    background: #f8f9fa;
    border: 1px solid #e8ecef;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.upload-progress-bar {
    width: 100%;
    height: 6px;
    background: #e9ecef;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 8px;
}

.upload-progress-fill {
    height: 100%;
    background: #27ae60;
    border-radius: 3px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-progress-text {
    font-size: 13px;
    color: #7f8c8d;
    text-align: center;
}

.preview-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.preview-text {
    font-size: 14px;
    color: #666;
}

.remove-file {
    background: none;
    border: none;
    font-size: 18px;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.3s ease;
}

.remove-file:hover {
    background: #e9ecef;
    color: #666;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.attach-btn {
    background: #f8f9fa;
    border: 1px solid #e8ecef;
    color: #7f8c8d;
    padding: 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.attach-btn:hover {
    background: #e9ecef;
    color: #495057;
}

.message-input-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: flex-end;
    background: #f8f9fa;
    border: 1px solid #e8ecef;
    border-radius: 20px;
    overflow: hidden;
}

#messageInput {
    flex: 1;
    border: none;
    background: none;
    padding: 10px 14px;
    font-size: 16px;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 20px;
    max-height: 100px;
    line-height: 1.4;
}

.emoji-btn {
    background: none;
    border: none;
    color: #7f8c8d;
    padding: 10px;
    cursor: pointer;
    transition: color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.emoji-btn:hover {
    color: #495057;
}

.send-btn {
    background: #27ae60;
    border: none;
    color: white;
    padding: 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
}

.send-btn:hover {
    background: #229954;
}

.send-btn:active {
    background: #1e8449;
}

.send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: #bdc3c7;
}

.emoji-picker {
    position: absolute;
    bottom: 100%;
    right: 0;
    background: white;
    border: 1px solid #e8ecef;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    padding: 12px;
    margin-bottom: 8px;
    z-index: 10000;
    max-width: 300px;
}

.emoji-picker.hidden {
    display: none;
}

.emoji-picker.visible {
    display: block;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 6px;
    max-height: 180px;
    overflow-y: auto;
}

.emoji-grid span {
    font-size: 18px;
    cursor: pointer;
    padding: 6px 4px;
    border-radius: 4px;
    text-align: center;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.emoji-grid span:hover {
    background: #f8f9fa;
    transform: scale(1.1);
}

.emoji-grid span:active {
    transform: scale(0.95);
    background: #e9ecef;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Mobile Responsiveness - Enhanced for all devices */
@media screen and (max-width: 768px) {
    body {
        font-size: 16px;
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    .chat-container {
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
    }
    
    .chat-header {
        padding: 12px 16px;
        min-height: 56px;
    }
    
    .user-info {
        font-size: 15px;
    }
    
    .user-info i {
        font-size: 18px;
    }
    
    .header-buttons {
        gap: 6px;
    }
    
    .clear-btn, .logout-btn {
        padding: 8px 10px;
        font-size: 13px;
        min-width: 44px;
        height: 44px;
        border-radius: 8px;
    }
    
    .chat-messages {
        padding: 12px;
        padding-bottom: env(safe-area-inset-bottom, 12px);
    }
    
    .message {
        max-width: 80%;
    }
    
    .message-content {
        padding: 8px 12px;
        font-size: 16px;
    }
    
    .chat-input-container {
        padding: 8px 12px 12px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
    
    .chat-input-wrapper {
        gap: 6px;
    }
    
    .attach-btn, .send-btn {
        min-width: 36px;
        height: 36px;
        padding: 8px;
    }
    
    .message-input-container {
        border-radius: 18px;
    }
    
    #messageInput {
        font-size: 16px;
        padding: 8px 12px;
        min-height: 20px;
    }
    
    .emoji-btn {
        padding: 8px;
    }
    
    .emoji-picker {
        max-width: calc(100vw - 32px);
        right: -12px;
        border-radius: 8px;
    }
    
    .upload-progress-container {
        padding: 8px;
        margin-bottom: 8px;
    }
    
    .upload-progress-text {
        font-size: 12px;
    }
    
    .login-container {
        padding: 0 16px;
    }
    
    .login-card {
        padding: 24px 20px;
        border-radius: 8px;
    }
    
    .login-header h1 {
        font-size: 22px;
    }
    
    .login-header i {
        font-size: 36px;
    }
}

/* Small mobile devices */
@media screen and (max-width: 480px) {
    .login-page {
        padding: 12px;
    }
    
    .login-card {
        padding: 20px 16px;
        margin: 0;
    }
    
    .chat-messages {
        padding: 8px;
    }
    
    .message {
        max-width: 85%;
    }
    
    .message-content {
        font-size: 15px;
        padding: 7px 10px;
    }
    
    .chat-input-container {
        padding: 6px 8px 8px 8px;
    }
    
    .attach-btn, .send-btn {
        min-width: 32px;
        height: 32px;
        padding: 6px;
    }
    
    .emoji-picker {
        max-width: calc(100vw - 24px);
        right: -8px;
    }
    
    .upload-progress-container {
        padding: 6px;
        margin-bottom: 6px;
    }
    
    .upload-progress-bar {
        height: 4px;
    }
    
    .upload-progress-text {
        font-size: 11px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(6, 1fr);
        gap: 6px;
    }
    
    .file-preview {
        padding: 8px;
        margin-bottom: 8px;
    }
}

/* Extra small devices and landscape phones */
@media screen and (max-width: 360px) {
    .message {
        max-width: 90%;
    }
    
    .chat-input-wrapper {
        gap: 4px;
    }
    
    .emoji-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

/* Landscape orientation adjustments */
@media screen and (max-height: 500px) and (orientation: landscape) {
    .chat-header {
        padding: 8px 16px;
        min-height: 48px;
    }
    
    .chat-messages {
        padding: 8px 12px;
    }
    
    .chat-input-container {
        padding: 6px 12px 8px 12px;
    }
    
    .emoji-picker {
        max-height: 150px;
    }
}

/* High DPI displays */
@media screen and (-webkit-min-device-pixel-ratio: 2), 
       screen and (min-resolution: 192dpi) {
    .message-content {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}

/* Scrollbar Styles */
.chat-messages::-webkit-scrollbar,
.emoji-grid::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track,
.emoji-grid::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb,
.emoji-grid::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover,
.emoji-grid::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}
