/* Reset และ Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: #333;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header Styles */
header {
    text-align: center;
    margin-bottom: 30px;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

header h1 {
    font-size: 2.5em;
    margin-bottom: 10px;
    animation: fadeInUp 0.8s ease;
}

header p {
    font-size: 1.1em;
    opacity: 0.9;
    animation: fadeInUp 0.8s ease 0.2s both;
}

/* Main Content */
main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Chat Styles */
.chat-card {
    margin-top: 20px;
}

/* Features Section */
.features {
    display: grid;
    gap: 15px;
    margin-bottom: 30px;
}

.feature {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 15px;
    background: #f8f9fa;
    border-radius: 10px;
    transition: background 0.3s ease;
}

.feature:hover {
    background: #e9ecef;
}

.feature .icon {
    font-size: 1.5em;
    flex-shrink: 0;
}

.feature span:last-child {
    font-weight: 500;
    color: #333;
}

/* Install Button */
.install-btn {
    background: linear-gradient(135deg, #2196F3, #21CBF3);
    color: white;
    border: none;
    padding: 15px 30px;
    border-radius: 50px;
    font-size: 1.1em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

.install-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.4);
}

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

/* Counter Section */
.counter-section {
    text-align: center;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 15px;
    margin-top: 20px;
}

.counter-section h3 {
    margin-bottom: 20px;
    color: #333;
}

.counter-controls {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
}

.counter-controls button {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 50%;
    background: #2196F3;
    color: white;
    font-size: 1.5em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 2px 10px rgba(33, 150, 243, 0.3);
}

.counter-controls button:hover {
    background: #1976D2;
    transform: scale(1.1);
}

.counter-controls button:active {
    transform: scale(0.95);
}

#counter {
    font-size: 2em;
    font-weight: bold;
    color: #2196F3;
    min-width: 80px;
    display: inline-block;
}

/* Status Section */
.status {
    background: rgba(255,255,255,0.1);
    backdrop-filter: blur(10px);
    border-radius: 15px;
    padding: 20px;
    color: white;
    text-align: center;
    margin-top: auto;
}

.status p {
    margin: 5px 0;
    font-weight: 500;
}

#onlineStatus {
    font-size: 1.1em;
}

#installStatus {
    font-size: 0.9em;
    opacity: 0.8;
}

/* Animations */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive Design */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }
    
    header h1 {
        font-size: 2em;
    }
    
    .card {
        padding: 20px;
    }
    
    .counter-controls {
        gap: 15px;
    }
    
    .counter-controls button {
        width: 45px;
        height: 45px;
        font-size: 1.3em;
    }
    
    #counter {
        font-size: 1.8em;
        min-width: 70px;
    }
}

/* PWA Install Banner */
.pwa-install-banner {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: #2196F3;
    color: white;
    padding: 15px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
    display: none;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
}

.pwa-install-banner.show {
    display: flex;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
    .card {
        background: #1e1e1e;
        color: #e0e0e0;
    }
    
    .card h2 {
        color: #64B5F6;
    }
    
    .card p {
        color: #b0b0b0;
    }
    
    .feature {
        background: #2a2a2a;
        color: #e0e0e0;
    }
    
    .feature:hover {
        background: #3a3a3a;
    }
    
    .counter-section {
        background: #2a2a2a;
        color: #e0e0e0;
    }
}

/* Chat Styles */
.chat-card {
    background: white;
    border-radius: 20px;
    padding: 30px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: fadeInUp 0.8s ease 0.4s both;
    transition: transform 0.3s ease;
}

.chat-card:hover {
    transform: translateY(-5px);
}

.chat-card h2 {
    color: #2196F3;
    margin-bottom: 15px;
    font-size: 1.8em;
}

/* Chat Header with User Info */
.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.current-user-info {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #f0f7ff;
    padding: 8px 12px;
    border-radius: 15px;
    border: 1px solid #e3f2fd;
}

.current-user-info #currentUserDisplay {
    font-size: 0.9em;
    color: #1976d2;
    font-weight: 500;
}

.edit-username-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 0.8em;
    transition: background-color 0.2s;
}

.edit-username-btn:hover {
    background: #e3f2fd;
}

/* Login Screen Styles */
.login-card {
    background: white;
    border-radius: 20px;
    padding: 40px 30px;
    box-shadow: 0 15px 35px rgba(0,0,0,0.2);
    animation: fadeInUp 0.8s ease 0.4s both;
    text-align: center;
    max-width: 450px;
    margin: 0 auto;
}

.login-header h2 {
    color: #2196F3;
    margin-bottom: 10px;
    font-size: 2em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.login-header p {
    color: #666;
    margin-bottom: 30px;
    font-size: 1.1em;
}

.login-form {
    margin-bottom: 30px;
}

.password-input-group {
    position: relative;
    margin-bottom: 20px;
}

.password-input-group input {
    width: 100%;
    padding: 15px 50px 15px 20px;
    border: 2px solid #e0e0e0;
    border-radius: 15px;
    font-size: 1.1em;
    transition: border-color 0.3s, box-shadow 0.3s;
    background: #f8f9fa;
}

.password-input-group input:focus {
    outline: none;
    border-color: #2196F3;
    box-shadow: 0 0 0 3px rgba(33, 150, 243, 0.1);
    background: white;
}

.toggle-password-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px;
    border-radius: 5px;
    transition: background-color 0.2s;
}

.toggle-password-btn:hover {
    background: #f0f0f0;
}

.login-btn {
    width: 100%;
    padding: 15px 20px;
    background: linear-gradient(135deg, #2196F3, #1976D2);
    color: white;
    border: none;
    border-radius: 15px;
    font-size: 1.2em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(33, 150, 243, 0.3);
}

.login-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(33, 150, 243, 0.4);
}

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

.login-error {
    background: #ffebee;
    color: #c62828;
    padding: 12px 15px;
    border-radius: 10px;
    margin-top: 15px;
    border-left: 4px solid #c62828;
    font-weight: 500;
}

.login-info {
    background: #f0f7ff;
    padding: 20px;
    border-radius: 15px;
    border: 1px solid #e3f2fd;
}

.login-info p {
    margin: 8px 0;
    color: #1976d2;
    font-size: 0.95em;
}

/* Logout Button */
.logout-btn {
    background: linear-gradient(135deg, #f44336, #c62828);
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 10px;
    font-size: 0.9em;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-left: auto;
}

.logout-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 15px rgba(244, 67, 54, 0.3);
}

.chat-card p {
    margin-bottom: 25px;
    color: #666;
    font-size: 1.1em;
}

.firebase-status {
    margin-bottom: 15px;
    padding: 10px;
    background: #f8f9fa;
    border-radius: 10px;
    text-align: center;
}

.connection-status {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
}

#firebaseStatus {
    font-weight: 600;
    padding: 5px 10px;
    border-radius: 15px;
}

#firebaseStatus.connected {
    background: #d4edda;
    color: #155724;
}

#firebaseStatus.disconnected {
    background: #f8d7da;
    color: #721c24;
}

#firebaseStatus.connecting {
    background: #fff3cd;
    color: #856404;
}

.connect-btn {
    padding: 8px 16px;
    background: #28a745;
    color: white;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9em;
    transition: all 0.3s ease;
}

.connect-btn:hover {
    background: #218838;
    transform: translateY(-1px);
}

.chat-container {
    max-width: 100%;
}

.chat-messages {
    height: 300px;
    overflow-y: auto;
    border: 2px solid #e9ecef;
    border-radius: 15px;
    padding: 15px;
    background: #f8f9fa;
    margin-bottom: 15px;
    scroll-behavior: smooth;
}

.chat-message {
    margin-bottom: 12px;
    padding: 10px 15px;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
    animation: fadeInMessage 0.3s ease;
}

.chat-message.user {
    background: #2196F3;
    color: white;
    margin-left: auto;
    text-align: right;
}

.chat-message.other {
    background: #e9ecef;
    color: #333;
    margin-right: auto;
}

.chat-message.system {
    background: #4CAF50;
    color: white;
    margin: 0 auto;
    text-align: center;
    max-width: 90%;
    font-style: italic;
}

.message-header {
    font-size: 0.8em;
    font-weight: bold;
    margin-bottom: 3px;
    opacity: 0.8;
}

.message-text {
    display: block;
    margin-bottom: 3px;
}

.message-time {
    font-size: 0.7em;
    opacity: 0.6;
    display: block;
}

.chat-input-container {
    margin-bottom: 15px;
}

.user-info {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
}

.chat-input-group {
    display: flex;
    gap: 10px;
}

.chat-input-group input,
.user-info input {
    flex: 1;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    border-radius: 25px;
    font-size: 1em;
    outline: none;
    transition: border-color 0.3s ease;
}

.chat-input-group input:focus,
.user-info input:focus {
    border-color: #2196F3;
}

.chat-input-group button,
.user-info button {
    padding: 12px 20px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 25px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.chat-input-group button:hover,
.user-info button:hover {
    background: #1976D2;
    transform: translateY(-1px);
}

.chat-input-group button:disabled,
.user-info button:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

.chat-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    color: #666;
    padding: 10px 0;
    border-top: 1px solid #e9ecef;
}

.chat-info span {
    transition: color 0.3s ease;
}

/* Performance indicators */
.chat-info span:has-text("🟡") {
    color: #ff9800;
    font-weight: 600;
}

.performance-warning {
    background: #fff3cd;
    border: 1px solid #ffeaa7;
    border-radius: 8px;
    padding: 8px 12px;
    margin: 10px 0;
    color: #856404;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    gap: 8px;
}

.performance-warning.hidden {
    display: none;
}

/* Admin Controls */
.admin-controls {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px solid #e9ecef;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-btn {
    padding: 8px 15px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 500;
    transition: all 0.3s ease;
    flex: 1;
    min-width: 120px;
}

.clear-btn {
    background: #dc3545;
    color: white;
}

.clear-btn:hover {
    background: #c82333;
    transform: translateY(-1px);
}

.refresh-btn {
    background: #6c757d;
    color: white;
}

.refresh-btn:hover {
    background: #5a6268;
    transform: translateY(-1px);
}

.notification-btn {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
}

.notification-btn:hover {
    background: linear-gradient(135deg, #218838, #1ea086);
    transform: translateY(-1px);
}

.notification-btn.enabled {
    background: linear-gradient(135deg, #007bff, #0056b3);
}

.notification-btn.enabled:hover {
    background: linear-gradient(135deg, #0056b3, #004085);
}

.notification-btn.disabled {
    background: linear-gradient(135deg, #dc3545, #c82333);
}

.notification-btn.disabled:hover {
    background: linear-gradient(135deg, #c82333, #a02030);
}

/* Emergency Button Styles */
.emergency-btn {
    background: linear-gradient(135deg, #ff6b6b, #ffa726);
    color: white;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.emergency-btn:hover {
    background: linear-gradient(135deg, #ff5252, #ff9800);
    transform: translateY(-1px);
}

.emergency-btn.enabled {
    background: linear-gradient(135deg, #f44336, #e91e63);
    border-color: #fff;
    animation: emergencyPulse 2s infinite;
}

.emergency-btn.enabled:hover {
    background: linear-gradient(135deg, #d32f2f, #c2185b);
}

.emergency-btn.disabled {
    background: linear-gradient(135deg, #9e9e9e, #757575);
    color: #ffffff;
}

.emergency-btn.disabled:hover {
    background: linear-gradient(135deg, #757575, #616161);
}

@keyframes emergencyPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(244, 67, 54, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(244, 67, 54, 0);
    }
}

/* Emergency Banner */
.emergency-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(135deg, #f44336, #e91e63);
    color: white;
    z-index: 10000;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(244, 67, 54, 0.4);
    animation: emergencySlideDown 0.5s ease;
}

.emergency-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 600px;
    margin: 0 auto;
    gap: 15px;
}

.emergency-icon {
    font-size: 1.5em;
    animation: emergencyBlink 1s infinite;
}

.emergency-text {
    flex: 1;
    font-weight: 500;
}

.emergency-close {
    background: none;
    border: none;
    color: white;
    font-size: 1.2em;
    cursor: pointer;
    padding: 5px;
    border-radius: 50%;
    transition: background 0.3s ease;
}

.emergency-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

@keyframes emergencySlideDown {
    from {
        transform: translateY(-100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes emergencyBlink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0.3; }
}

/* Emergency Mode Body */
body.emergency-mode {
    filter: hue-rotate(15deg) saturate(1.2);
}

body.emergency-mode .container {
    border: 3px solid #f44336;
    box-shadow: 0 0 30px rgba(244, 67, 54, 0.3);
}

/* Emergency Message Highlight */
.emergency-highlight {
    background: linear-gradient(135deg, #fff3e0, #ffecb3) !important;
    border-left: 4px solid #f44336 !important;
    animation: emergencyHighlight 2s ease-in-out infinite alternate;
}

@keyframes emergencyHighlight {
    from {
        box-shadow: 0 0 5px rgba(244, 67, 54, 0.3);
    }
    to {
        box-shadow: 0 0 20px rgba(244, 67, 54, 0.6);
    }
}

/* Chat Animations */
@keyframes fadeInMessage {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Online Status Indicator */
.user-status {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4CAF50;
    margin-right: 5px;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Chat Responsive Design */
@media (max-width: 480px) {
    .login-card {
        padding: 30px 20px;
        margin: 10px;
    }
    
    .login-header h2 {
        font-size: 1.5em;
    }
    
    .password-input-group input {
        padding: 12px 45px 12px 15px;
        font-size: 1em;
    }
    
    .login-btn {
        padding: 12px 15px;
        font-size: 1.1em;
    }
    
    .chat-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    .chat-header h2 {
        font-size: 1.5em;
    }
    
    .logout-btn {
        align-self: stretch;
        margin-left: 0;
        margin-top: 10px;
    }
    
    .current-user-info {
        align-self: stretch;
        justify-content: center;
    }
    
    .chat-messages {
        height: 250px;
        padding: 10px;
    }
    
    .chat-message {
        max-width: 90%;
        padding: 8px 12px;
    }
    
    .chat-input-group,
    .user-info {
        flex-direction: column;
    }
    
    .chat-input-group input,
    .user-info input {
        margin-bottom: 8px;
    }
    
    .chat-info {
        flex-direction: column;
        gap: 5px;
        text-align: center;
    }
}

/* Chat Dark Mode */
@media (prefers-color-scheme: dark) {
    .chat-messages {
        background: #2a2a2a;
        border-color: #444;
        color: #e0e0e0;
    }
    
    .chat-message.other {
        background: #444;
        color: #e0e0e0;
    }
    
    .chat-input-group input,
    .user-info input {
        background: #333;
        color: #e0e0e0;
        border-color: #555;
    }
    
    .chat-input-group input:focus,
    .user-info input:focus {
        border-color: #64B5F6;
    }
    
    .chat-info {
        color: #b0b0b0;
        border-color: #444;
    }
}
