/* Global Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #000; /* Consistent dark background */
    color: #fff;
    min-height: 100vh;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    display: flex;
    flex-direction: column;
}

.page {
    display: none;
    flex-direction: column;
    flex-grow: 1;
    min-height: 100vh; /* Ensure page takes full viewport height */
}

.page.active {
    display: flex;
}

/* iOS-like Status Bar */
.status-bar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 44px; /* Approximate height of iOS status bar */
    background: rgba(28, 28, 30, 0.9); /* Dark, slightly transparent */
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 16px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    z-index: 1000;
    box-sizing: border-box;
}

.status-left, .status-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.signal-dots {
    display: flex;
    gap: 2px;
}

.signal-dots .dot {
    width: 4px;
    height: 4px;
    background-color: white;
    border-radius: 50%;
}

.signal-dots .dot.opacity-60 { opacity: 0.6; }
.carrier { font-size: 12px; }
.battery {
    width: 24px;
    height: 11px;
    border: 1px solid white;
    border-radius: 3px;
    position: relative;
    padding: 1px;
}
.battery::after { /* Battery nub */
    content: '';
    position: absolute;
    right: -3px;
    top: 50%;
    transform: translateY(-50%);
    width: 2px;
    height: 4px;
    background-color: white;
    border-radius: 0 1px 1px 0;
}
.battery-level {
    height: 100%;
    background-color: white;
    border-radius: 1px;
    width: 70%; /* Example battery level */
}

/* Common button style */
.btn-primary {
    background: #007AFF;
    color: white;
    border: none;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background: #0056CC;
}

.btn-primary:active {
    transform: translateY(1px);
}

.btn-primary:disabled {
    background: #48484a;
    cursor: not-allowed;
}

/* Auth Page Styles (from auth.html prototype) */
#authPage {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    justify-content: center;
    align-items: center;
    padding: 20px;
    box-sizing: border-box;
}

.auth-container {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 24px;
    padding: 32px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    width: 100%;
    max-width: 380px;
    text-align: center;
    margin-top: 44px; /* Account for status bar */
}

.auth-header .logo-container {
    width: 80px;
    height: 80px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px auto;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

.auth-header .logo-container i {
    font-size: 32px;
    color: white;
}

.auth-header h1 {
    font-size: 24px;
    font-weight: bold;
    color: white;
    margin-bottom: 8px;
}

.auth-header p {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-form .input-group {
    margin-bottom: 24px;
    text-align: left;
}

.auth-form .input-group label {
    display: block;
    color: white;
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 8px;
}

.auth-form .input-container {
    position: relative;
}

.auth-form input[type="password"],
.auth-form input[type="text"] {
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 12px;
    padding: 12px 40px 12px 16px;
    width: 100%;
    box-sizing: border-box;
    color: #333;
    font-size: 16px;
    transition: all 0.3s ease;
}

.auth-form input[type="password"]::placeholder,
.auth-form input[type="text"]::placeholder {
    color: #888;
}

.auth-form input[type="password"]:focus,
.auth-form input[type="text"]:focus {
    background: white;
    border-color: #007AFF;
    box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.1);
    outline: none;
}

.auth-form .toggle-password {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #555;
    cursor: pointer;
}

.remember-password {
    margin-top: 24px;
    text-align: center;
}

.remember-password label {
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.remember-password input[type="checkbox"] {
    margin-right: 8px;
    accent-color: #007AFF;
}

.auth-footer {
    margin-top: 24px;
    text-align: center;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
}

.auth-footer i {
    margin-right: 4px;
}

/* 认证页面按钮 */
.auth-form button[type="submit"].btn-primary {
    display: block;
    width: 40%; /* Narrower width */
    margin-left: auto;
    margin-right: auto;
    padding: 10px 15px;
    font-size: 16px;
    font-weight: bold;
    color: #fff;
    background-color: #6A5ACD; /* Lighter purple, closer to main theme */
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.auth-form button[type="submit"].btn-primary:hover {
    background-color: #7B68EE; /* Slightly lighter purple on hover */
}

.auth-form button[type="submit"].btn-primary:active {
    transform: scale(0.98);
}

/* Chat Page Styles (from chat.html prototype) */
.message-bubble .nickname {
    display: block;
    font-size: 0.8em;
    color: #aaa; /* Slightly lighter color for nickname */
    margin-bottom: 4px;
}

.message-bubble.sent .nickname {
    text-align: right; /* Align nickname to the right for sent messages */
}

.message-bubble.received .nickname {
    text-align: left; /* Align nickname to the left for received messages */
}
#chatPage {
    background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
    flex-direction: column;
}

.chat-header {
    position: fixed;
    top: 44px; /* Below status bar */
    left: 0;
    right: 0;
    background: rgba(28, 28, 30, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid #3a3a3c;
    padding: 12px 16px;
    z-index: 999;
    box-sizing: border-box;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.avatar {
    width: 36px;
    height: 36px;
    background-color: #4a4a4c;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar i {
    color: white;
    font-size: 16px;
}

.user-details h1 {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.status-indicator.connected { background-color: #34C759; }
.status-indicator.connecting { background-color: #FF9500; animation: pulse 1.5s infinite; }
.status-indicator.disconnected { background-color: #FF3B30; }

#connectionText.connected { color: #34C759; }
#connectionText.connecting { color: #FF9500; }
#connectionText.disconnected { color: #FF3B30; }

.settings-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    padding: 8px;
}

.messages-container {
    flex-grow: 1;
    padding: calc(44px + 60px + 16px) 16px calc(80px + 16px) 16px; /* top: status + header + padding, bottom: inputarea + padding */
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 14px;
    border-radius: 18px;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.4;
    animation: messageSlide 0.3s ease-out;
}

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

.message-bubble.sent {
    align-self: flex-end; /* Changed to flex-end to show on right side */
    background-color: #0B93F6; /* 使用类似iOS的蓝色 */
    color: white;
    border-radius: 18px 18px 4px 18px; /* Adjusted for right side bubble */
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); /* 添加轻微阴影增强立体感 */
}

.message-bubble.received {
    background: #3a3a3c; /* 默认颜色，会被JavaScript根据用户昵称动态覆盖 */
    color: white;
    border-radius: 18px 18px 18px 4px;
    align-self: flex-start;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); /* 添加轻微阴影增强立体感 */
}

.message-bubble .timestamp {
    font-size: 11px;
    color: rgba(255, 255, 255, 0.6);
    display: inline-block;
    margin-left: 5px;
}

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

.message-bubble .nickname {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    color: rgba(255, 255, 255, 0.8);
}

.message-bubble.sent .timestamp {
    color: rgba(255, 255, 255, 0.7); /* 在蓝色背景上提高可见度 */
}

.message-bubble.sent .nickname {
    text-align: left; /* Ensure nickname is also left-aligned */
}

.typing-indicator {
    align-self: flex-start;
    margin-top: 8px;
}

.typing-indicator .message-bubble {
    padding: 10px 14px;
}

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

.typing-dots .dot {
    width: 8px;
    height: 8px;
    background-color: #8e8e93;
    border-radius: 50%;
    animation: typingPulse 1.2s infinite ease-in-out;
}

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

@keyframes typingPulse {
    0%, 100% { opacity: 0.3; transform: scale(0.8); }
    50% { opacity: 1; transform: scale(1); }
}

.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    border-top: 1px solid #3a3a3c;
    padding: 12px 16px env(safe-area-inset-bottom) 16px;
    box-sizing: border-box;
}

.input-area .input-container {
    display: flex;
    align-items: flex-end; /* Align items to bottom for textarea growth */
    gap: 12px;
}

.message-input-wrapper {
    flex-grow: 1;
}

#messageInput {
    width: 100%;
    background: #3a3a3c;
    border: 1px solid #48484a;
    border-radius: 20px;
    padding: 10px 16px;
    color: white;
    font-size: 15px;
    resize: none;
    min-height: 40px; /* Initial height for one line */
    max-height: 100px; /* Max height for ~4-5 lines */
    box-sizing: border-box;
    line-height: 1.4;
    overflow-y: auto; /* Show scrollbar if content exceeds max-height */
}

#messageInput::placeholder { color: #8e8e93; }
#messageInput:focus {
    border-color: #007AFF;
    outline: none;
}

.send-btn {
    background: #007AFF;
    color: white;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0; /* Prevent button from shrinking */
}

.send-btn:disabled {
    background: #48484a;
    color: #8e8e93;
    cursor: not-allowed;
}

.char-count {
    font-size: 10px;
    color: #8e8e93;
    text-align: right;
    margin-top: 4px;
    height: 12px; /* Reserve space */
}

/* Settings Page Styles (from settings.html prototype) */
#settingsPage {
    background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
    flex-direction: column;
}

.settings-header {
    position: fixed;
    top: 44px; /* Below status bar */
    left: 0;
    right: 0;
    background: rgba(28, 28, 30, 0.9);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid #3a3a3c;
    padding: 12px 16px;
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-sizing: border-box;
}

.settings-header .back-btn {
    background: none;
    border: none;
    color: #007AFF;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

.settings-header h1 {
    color: white;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.settings-header .spacer { /* To help center title when back button is present */
    width: 60px; /* Approx width of back button */
}

.settings-content {
    padding: calc(44px + 60px + 16px) 16px 16px 16px;
    flex-grow: 1;
    overflow-y: auto;
}

.settings-group {
    background: #2c2c2e;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden; /* Clip items inside */
}

.settings-group .group-title {
    font-size: 13px;
    color: #8e8e93;
    padding: 16px 16px 8px 16px;
    text-transform: uppercase;
}

.settings-item {
    background: #2c2c2e; /* Match group background, border will separate */
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #3a3a3c; /* Use a slightly darker separator */
    cursor: pointer;
    transition: background-color 0.2s ease;
}

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

.settings-item:active {
    background-color: #3a3a3c;
}

.settings-item-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.settings-item-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
}

.settings-item-icon.icon-notifications { background-color: #007AFF; }
.settings-item-icon.icon-sound { background-color: #34C759; }
.settings-item-icon.icon-theme { background-color: #5856D6; }
.settings-item-icon.icon-password { background-color: #FF9500; }
.settings-item-icon.icon-storage { background-color: #8E8E93; }
.settings-item-icon.icon-info { background-color: #5AC8FA; }

.settings-item-text p {
    margin: 0;
    color: white;
    font-size: 16px;
}

.settings-item-text .description {
    font-size: 12px;
    color: #8e8e93;
}

.settings-item .chevron {
    color: #545458;
    font-size: 14px;
}

.toggle-switch {
    position: relative;
    width: 50px;
    height: 30px;
    background: #3a3a3c;
    border-radius: 15px;
    transition: background-color 0.3s ease;
    cursor: pointer;
}

.toggle-switch.active {
    background: #34C759;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 26px;
    height: 26px;
    background: white;
    border-radius: 50%;
    transition: transform 0.3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch.active::after {
    transform: translateX(20px);
}

.danger-button {
    display: block;
    width: 100%;
    background: #FF3B30;
    color: white;
    border: none;
    padding: 14px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: background-color 0.2s ease;
}

.danger-button:hover {
    background: #D70015;
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #2c2c2e;
    padding: 24px;
    border-radius: 14px;
    width: 90%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 5px 25px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease-out forwards;
}

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

.modal-content h3 {
    font-size: 18px;
    font-weight: 600;
    color: white;
    margin: 0 0 8px 0;
}

.modal-content p {
    font-size: 14px;
    color: #aeaeb2;
    margin-bottom: 20px;
    line-height: 1.5;
}

.modal-buttons {
    display: flex;
    gap: 12px;
}

.modal-buttons button {
    flex-grow: 1;
    padding: 10px;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s ease;
}

.modal-buttons .btn-cancel {
    background: #3a3a3c;
    color: white;
}
.modal-buttons .btn-cancel:hover { background: #48484a; }

.modal-buttons .btn-confirm {
    background: #FF3B30;
    color: white;
}
.modal-buttons .btn-confirm:hover { background: #D70015; }

/* Responsive adjustments for safe areas on iOS */
body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

.status-bar {
    height: calc(20px + env(safe-area-inset-top)); /* Base height + safe area */
    padding-top: env(safe-area-inset-top);
}

.chat-header, .settings-header {
    top: calc(20px + env(safe-area-inset-top));
}

.messages-container {
    padding-top: calc(20px + env(safe-area-inset-top) + 60px + 16px); /* status + header + padding */
    padding-bottom: calc(80px + env(safe-area-inset-bottom) + 16px); /* inputarea + safe area + padding */
}

.input-area {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.settings-content {
    padding-top: calc(20px + env(safe-area-inset-top) + 60px + 16px);
    padding-bottom: calc(16px + env(safe-area-inset-bottom));
}

/* Ensure fixed elements respect safe area for notch */
.status-bar, .chat-header, .settings-header, .input-area, .modal {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

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