/* General Body Styles */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #000; /* Default to dark theme based on settings prototype */
    color: #fff;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    overflow: hidden; /* Prevent scrollbars from base layout */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* Light Mode Styles */
body.light-mode {
    background-color: #f2f2f7;
    color: #000;
}

/* Page Containers */
.page {
    display: none; /* Hidden by default */
    width: 100%;
    max-width: 480px; /* Max width for mobile-like view */
    height: 100vh; /* Full viewport height */
    max-height: 100vh; /* Ensure it doesn't exceed viewport */
    background: linear-gradient(180deg, #1c1c1e 0%, #2c2c2e 100%);
    flex-direction: column;
    overflow: hidden; /* Prevent internal scrolling from breaking layout */
    position: relative; /* For absolute positioning of children like headers/footers */
    transition: background 0.3s ease;
}

body.light-mode .page {
    background: linear-gradient(180deg, #f2f2f7 0%, #ffffff 100%);
}

.page.active {
    display: flex; /* Show active page */
}

/* Header Styles (Common for Chat & Settings) */
.header {
    background: rgba(28, 28, 30, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 12px 16px;
    padding-top: calc(12px + env(safe-area-inset-top)); /* Adjust for notch */
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #3a3a3c;
    position: fixed; /* Stick to top */
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    max-width: 480px; /* Match page max-width */
    margin: 0 auto; /* Center if viewport is wider */
    transition: background 0.3s ease, border-color 0.3s ease;
}

body.light-mode .header {
    background: rgba(242, 242, 247, 0.85);
    border-bottom: 1px solid #c6c6c8;
}

.header h1 {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    text-align: center;
    flex-grow: 1;
    transition: color 0.3s ease;
}

body.light-mode .header h1 {
    color: #000;
}

.header .back-button,
.header .settings-button {
    background: none;
    border: none;
    color: #007aff; /* iOS blue */
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
}

.header .back-button i,
.header .settings-button i {
    font-size: 20px;
}

/* Auth Page Styles */
#authPage {
    background: linear-gradient(180deg, #2c2c2e 0%, #1c1c1e 100%);
    justify-content: center;
    transition: background 0.3s ease;
}

body.light-mode #authPage {
    background: linear-gradient(180deg, #ffffff 0%, #f2f2f7 100%);
}

.auth-container {
    background-color: #1c1c1e;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    text-align: center;
    width: 90%;
    max-width: 360px;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

body.light-mode .auth-container {
    background-color: #ffffff;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
}

.auth-container h1 {
    color: #fff;
    margin-bottom: 10px;
    font-size: 28px;
    font-weight: 600;
    transition: color 0.3s ease;
}

body.light-mode .auth-container h1 {
    color: #000;
}

.auth-container p {
    color: #8e8e93; /* iOS secondary label color */
    margin-bottom: 25px;
    font-size: 15px;
    transition: color 0.3s ease;
}

body.light-mode .auth-container p {
    color: #6d6d70;
}

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

.input-group input[type="password"],
.input-group input[type="text"] {
    width: calc(100% - 20px); /* Account for padding */
    padding: 12px 10px;
    padding-right: 40px; /* Space for toggle icon */
    background-color: #2c2c2e;
    border: 1px solid #3a3a3c;
    border-radius: 8px;
    color: #fff;
    font-size: 16px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body.light-mode .input-group input[type="password"],
body.light-mode .input-group input[type="text"] {
    background-color: #f2f2f7;
    border: 1px solid #c6c6c8;
    color: #000;
}

.input-group input[type="password"]::placeholder,
.input-group input[type="text"]::placeholder {
    color: #8e8e93;
    transition: color 0.3s ease;
}

body.light-mode .input-group input[type="password"]::placeholder,
body.light-mode .input-group input[type="text"]::placeholder {
    color: #6d6d70;
}

.toggle-password {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #8e8e93;
    cursor: pointer;
    font-size: 18px;
    transition: color 0.3s ease;
}

body.light-mode .toggle-password {
    color: #6d6d70;
}

.remember-password {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: 25px;
    font-size: 14px;
    color: #8e8e93;
    transition: color 0.3s ease;
}

body.light-mode .remember-password {
    color: #6d6d70;
}

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

.auth-button, .btn-primary {
    display: block; /* Ensure it takes up full width before centering */
    width: 60%; /* Or a specific width if preferred */
    margin-left: auto;
    margin-right: auto;
    padding: 14px;
    background-color: #3a3a3c; /* Darker color, consistent with other UI elements */
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 17px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
    text-align: center; /* Center text and icon inside button */
}

body.light-mode .auth-button, 
body.light-mode .btn-primary {
    background-color: #007aff;
    color: white;
}

.auth-button:hover, .btn-primary:hover {
    background-color: #4a4a4c; /* Slightly lighter on hover */
}

body.light-mode .auth-button:hover, 
body.light-mode .btn-primary:hover {
    background-color: #0056cc;
}

/* Chat Page Styles */
.messages-container {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    padding-top: calc(60px + env(safe-area-inset-top) + 15px); /* Header height + safe area + padding */
    padding-bottom: calc(70px + env(safe-area-inset-bottom) + 15px); /* Input area height + safe area + padding */
    display: flex;
    flex-direction: column;
}

.message-bubble {
    max-width: 75%;
    padding: 10px 15px;
    border-radius: 18px;
    margin-bottom: 10px;
    line-height: 1.4;
    font-size: 16px;
    position: relative;
    display: flex; /* Use flexbox for internal alignment */
    flex-direction: column; /* Stack nickname, content, timestamp vertically */
    transition: background-color 0.3s ease, color 0.3s ease;
}

.message-bubble p {
    margin: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-bubble .timestamp {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.6);
    margin-top: 5px;
    align-self: flex-end; /* Align timestamp to the right */
    transition: color 0.3s ease;
}

body.light-mode .message-bubble .timestamp {
    color: rgba(0, 0, 0, 0.6);
}

.message-bubble.sent {
    background-color: #007aff;
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 5px;
}

body.light-mode .message-bubble.sent {
    background-color: #007aff;
    color: white;
}

.message-bubble.received {
    background-color: #3a3a3c;
    color: #fff;
    align-self: flex-start;
    border-bottom-left-radius: 5px;
}

body.light-mode .message-bubble.received {
    background-color: #e5e5ea;
    color: #000;
}

.message-bubble .nickname {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 3px;
    opacity: 0.8;
}

.message-bubble.sent .nickname {
    text-align: right;
    color: rgba(255, 255, 255, 0.9);
}

body.light-mode .message-bubble.sent .nickname {
    color: rgba(255, 255, 255, 0.9);
}

.message-bubble.received .nickname {
    text-align: left;
    /* Color will be set dynamically based on nickname */
}

body.light-mode .message-bubble.received .nickname {
    /* Color will be set dynamically based on nickname */
}

/* Input Area */
.input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(28, 28, 30, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    padding: 10px 15px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
    border-top: 1px solid #3a3a3c;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    max-width: 480px;
    margin: 0 auto;
    z-index: 50;
    transition: background 0.3s ease, border-color 0.3s ease;
}

body.light-mode .input-area {
    background: rgba(242, 242, 247, 0.95);
    border-top: 1px solid #c6c6c8;
}

.input-area textarea {
    flex-grow: 1;
    min-height: 40px;
    padding: 10px 15px;
    background-color: #2c2c2e;
    border: 1px solid #3a3a3c;
    border-radius: 20px;
    color: #fff;
    font-size: 16px;
    resize: none;
    max-height: 100px; /* Limit height */
    overflow-y: auto;
    line-height: 1.4;
    margin-right: 10px;
    transition: background-color 0.3s ease, border-color 0.3s ease, color 0.3s ease;
}

body.light-mode .input-area textarea {
    background-color: #ffffff;
    border: 1px solid #c6c6c8;
    color: #000;
}

.input-area textarea::placeholder {
    color: #8e8e93;
    transition: color 0.3s ease;
}

body.light-mode .input-area textarea::placeholder {
    color: #6d6d70;
}

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

.input-area .send-button:hover {
    background-color: #0056cc;
}

.input-area .send-button:disabled {
    background-color: #48484a;
    cursor: not-allowed;
}

body.light-mode .input-area .send-button:disabled {
    background-color: #c6c6c8;
}

.char-count {
    position: absolute;
    bottom: calc(100% + 5px); /* Position above the textarea */
    right: 65px; /* Align with send button */
    font-size: 12px;
    color: #8e8e93;
    background-color: rgba(44, 44, 46, 0.9);
    padding: 2px 6px;
    border-radius: 4px;
}

/* Status Indicator in Chat Header */
.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 8px;
    display: inline-block;
}
.status-indicator.connected {
    background-color: #34c759; /* Green */
}
.status-indicator.disconnected {
    background-color: #ff3b30; /* Red */
}
.status-indicator.connecting {
    background-color: #ffcc00; /* Yellow */
    animation: pulse 1.5s infinite;
}

#connectionText.connected { color: #34c759; }
#connectionText.disconnected { color: #ff3b30; }
#connectionText.connecting { color: #ffcc00; }

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

/* Settings Page Specific Styles */
#settingsPage .page-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 15px;
    padding-top: calc(60px + env(safe-area-inset-top) + 15px);
    padding-bottom: calc(15px + env(safe-area-inset-bottom));
}

.settings-group {
    background-color: #1c1c1e;
    border-radius: 12px;
    margin-bottom: 20px;
    overflow: hidden;
    transition: background-color 0.3s ease;
}

body.light-mode .settings-group {
    background-color: #ffffff;
}

.settings-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px 20px;
    border-bottom: 1px solid #2c2c2e;
    transition: background-color 0.2s ease, border-color 0.3s ease;
}

body.light-mode .settings-item {
    border-bottom: 1px solid #f2f2f7;
}

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

.settings-item.clickable {
    cursor: pointer;
}

.settings-item.clickable:hover {
    background-color: #2c2c2e;
}

body.light-mode .settings-item.clickable:hover {
    background-color: #f2f2f7;
}

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

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

.item-icon.bg-blue { background-color: #007aff; }
.item-icon.bg-green { background-color: #34c759; }
.item-icon.bg-purple { background-color: #af52de; }
.item-icon.bg-orange { background-color: #ff9500; }
.item-icon.bg-red { background-color: #ff3b30; }

.item-text .title {
    color: #fff;
    font-size: 16px;
    font-weight: 500;
    margin: 0 0 2px 0;
    transition: color 0.3s ease;
}

body.light-mode .item-text .title {
    color: #000;
}

.item-text .subtitle {
    color: #8e8e93;
    font-size: 14px;
    margin: 0;
    transition: color 0.3s ease;
}

body.light-mode .item-text .subtitle {
    color: #6d6d70;
}

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

body.light-mode .toggle-switch {
    background-color: #c6c6c8;
}

.toggle-switch::before {
    content: '';
    position: absolute;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: #fff;
    top: 2px;
    left: 2px;
    transition: transform 0.3s ease;
}

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

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

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
}

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

.status-indicator.connected {
    background-color: #34c759;
}

.status-indicator.disconnected {
    background-color: #ff3b30;
}

.connection-status .connected {
    color: #34c759;
}

.connection-status .disconnected {
    color: #ff3b30;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    transition: background-color 0.3s ease;
}

body.light-mode .modal {
    background-color: rgba(0, 0, 0, 0.3);
}

.modal-content {
    background-color: #1c1c1e;
    border-radius: 12px;
    padding: 20px;
    max-width: 320px;
    width: 90%;
    text-align: center;
    transition: background-color 0.3s ease;
}

body.light-mode .modal-content {
    background-color: #ffffff;
}

.modal-title {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 10px;
    transition: color 0.3s ease;
}

body.light-mode .modal-title {
    color: #000;
}

.modal-message {
    color: #8e8e93;
    font-size: 14px;
    line-height: 1.4;
    margin-bottom: 20px;
    transition: color 0.3s ease;
}

body.light-mode .modal-message {
    color: #6d6d70;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.modal-actions button.btn-primary {
    background-color: #007aff;
    color: white;
}
.modal-actions button.btn-primary:hover { background-color: #005bb5; }

.modal-actions button.btn-secondary {
    background-color: #3a3a3c;
    color: white;
}

body.light-mode .modal-actions button.btn-secondary {
    background-color: #f2f2f7;
    color: #000;
}

.modal-actions button.btn-secondary:hover { background-color: #48484a; }

body.light-mode .modal-actions button.btn-secondary:hover {
    background-color: #e5e5ea;
}

.modal-actions button.btn-danger {
    background-color: #ff3b30;
    color: white;
}
.modal-actions button.btn-danger:hover { background-color: #d70015; }

/* User Profile Section */
.user-profile {
    text-align: center;
    padding: 20px;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 15px;
    font-size: 32px;
    color: white;
}

.user-profile h2 {
    color: #fff;
    font-size: 20px;
    font-weight: 600;
    margin: 0 0 5px 0;
    transition: color 0.3s ease;
}

body.light-mode .user-profile h2 {
    color: #000;
}

.user-profile p {
    color: #8e8e93;
    font-size: 14px;
    margin: 0;
    transition: color 0.3s ease;
}

body.light-mode .user-profile p {
    color: #6d6d70;
}

/* General Modal Styles */
#confirmClearModal {
    display: none; /* Hidden by default */
    position: fixed;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000; /* High z-index to appear on top */
    justify-content: center;
    align-items: center;
}

#confirmClearModal.active {
    display: flex; /* Show when active */
}
.modal {
    display: none; /* Hidden by default */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.6); /* Darker semi-transparent background */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #2c2c2e; /* Dark modal content background */
    margin: auto;
    padding: 25px;
    border-radius: 14px;
    width: 85%;
    max-width: 320px;
    text-align: center;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: modalSlideUp 0.3s ease-out;
}

.modal-icon-container {
    font-size: 36px;
    margin-bottom: 15px;
}

.modal-icon-container.info { color: #007aff; } /* Blue for info */
.modal-icon-container.success { color: #34c759; } /* Green for success */
.modal-icon-container.warning { color: #ffcc00; } /* Yellow for warning */
.modal-icon-container.error { color: #ff3b30; } /* Red for error/danger */

.modal-content h3 {
    color: #fff;
    font-size: 18px;
    font-weight: 600;
    margin-top: 0;
    margin-bottom: 10px;
}

.modal-content p {
    color: #e5e5ea; /* Lighter gray for modal text */
    font-size: 14px;
    line-height: 1.5;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    justify-content: space-between; /* For two buttons */
    gap: 10px; /* Space between buttons */
}

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

.modal-actions button.btn-primary {
    background-color: #007aff;
    color: white;
}
.modal-actions button.btn-primary:hover { background-color: #005bb5; }

.modal-actions button.btn-secondary {
    background-color: #3a3a3c;
    color: white;
}
.modal-actions button.btn-secondary:hover { background-color: #48484a; }

.modal-actions button.btn-danger {
    background-color: #ff3b30;
    color: white;
}
.modal-actions button.btn-danger:hover { background-color: #d70015; }

/* If only one button in modal, make it full width */
.modal-actions button:only-child {
    width: 100%;
    flex-grow: 0; /* Don't grow if it's the only child */
}

@keyframes modalSlideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Dark Mode Active State (can be toggled via JS) */
body.dark-mode-active {
    /* Styles here are already dark by default, this class is for explicit toggling if needed */
    /* Or, if you had a light default, this is where dark styles would go. */
    /* For this project, it's more of a placeholder or for future light mode addition */
}

/* Utility for visually hidden but accessible elements */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}