/* === Base & Variables === */
:root {
    --bg: #0a0a0f;
    --surface: #12121a;
    --sidebar: #0e0e16;
    --accent: #00d4aa;
    --accent-hover: #00f0c0;
    --purple: #7c5cfc;
    --text: #e0e0e0;
    --text-muted: #888;
    --danger: #ff4757;
    --warning: #ffa502;
    --border: #1e1e2e;
    --input-bg: #1a1a28;
    --msg-self: #1a2a3a;
    --msg-other: #161622;
    --radius: 8px;
    --radius-lg: 12px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    overflow: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Buttons === */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 14px;
    font-family: var(--font);
    transition: all 0.2s;
    color: var(--text);
    background: var(--input-bg);
}
.btn:hover { filter: brightness(1.2); }
.btn-primary { background: var(--accent); color: #000; font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-accent { background: var(--accent); color: #000; font-weight: 600; }
.btn-accent:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger { background: transparent; color: var(--danger); }
.btn-danger:hover { background: rgba(255, 71, 87, 0.15); }
.btn-full { width: 100%; }
.btn-sm { padding: 4px 10px; font-size: 13px; }
.btn-xs { padding: 2px 6px; font-size: 11px; background: transparent; }
.btn-send { padding: 8px 14px; font-size: 18px; min-width: 44px; }
.btn-attach { font-size: 18px; padding: 6px 10px; background: transparent; }

/* === Auth Page === */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 40px 30px;
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: 0 0 60px rgba(0, 212, 170, 0.08);
    margin: 20px;
}

.auth-logo {
    text-align: center;
    margin-bottom: 30px;
}
.lock-icon { font-size: 48px; margin-bottom: 10px; }
.auth-logo h1 {
    font-size: 28px;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}
.auth-subtitle { color: var(--text-muted); margin-top: 6px; font-size: 14px; }

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}
.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 15px;
    cursor: pointer;
    font-family: var(--font);
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
}
.auth-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.auth-form { display: none; }
.auth-form.active { display: block; }

.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--text-muted);
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="number"],
.form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    transition: border-color 0.2s;
}
.form-group input:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.form-group input[type="checkbox"] { margin-right: 6px; }

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 12px;
    text-align: center;
    min-height: 20px;
}
.guest-notice {
    color: var(--warning);
    font-size: 13px;
    margin-bottom: 16px;
    text-align: center;
    line-height: 1.5;
}

/* === App Layout === */
.app-page { overflow: hidden; }
.app-container {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* Sidebar */
.sidebar {
    width: 300px;
    min-width: 300px;
    background: var(--sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.user-info { display: flex; align-items: center; gap: 10px; }
.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #000;
    font-size: 16px;
}
.user-name { font-weight: 500; font-size: 15px; }

.guest-badge {
    font-size: 10px;
    background: var(--warning);
    color: #000;
    padding: 1px 6px;
    border-radius: 10px;
    font-weight: 600;
    vertical-align: middle;
}
.guest-warning {
    background: rgba(255, 165, 2, 0.1);
    color: var(--warning);
    font-size: 12px;
    padding: 8px 16px;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.sidebar-actions {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.room-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}
.room-list-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}

.room-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 2px;
}
.room-item:hover { background: rgba(255,255,255,0.05); }
.room-item.active { background: rgba(0, 212, 170, 0.12); border-left: 3px solid var(--accent); }
.room-item-name { font-size: 14px; font-weight: 500; }
.room-item-meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 100;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 20px;
    padding: 6px 10px;
    border-radius: var(--radius);
    cursor: pointer;
}

/* Chat Main */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
}
.placeholder-icon { font-size: 64px; margin-bottom: 16px; opacity: 0.5; }
.chat-placeholder h2 { font-size: 22px; margin-bottom: 8px; color: var(--text); }
.chat-placeholder p { font-size: 14px; }

.chat-active { display: flex; flex-direction: column; height: 100vh; }

.chat-header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 12px;
}
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-info h3 { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-count { font-size: 12px; color: var(--text-muted); }
.chat-header-actions { display: flex; gap: 6px; }
.back-btn { display: none; }

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    position: relative;
    padding: 16px;
}
.messages-list { display: flex; flex-direction: column; gap: 4px; }

.message {
    max-width: 75%;
    padding: 8px 14px;
    border-radius: var(--radius-lg);
    animation: fadeIn 0.2s ease;
    position: relative;
}
.message.self {
    align-self: flex-end;
    background: var(--msg-self);
    border-bottom-right-radius: 4px;
}
.message.other {
    align-self: flex-start;
    background: var(--msg-other);
    border-bottom-left-radius: 4px;
}
.message-sender {
    font-size: 12px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 3px;
}
.message-text {
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    white-space: pre-wrap;
}
.message-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}
.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: rgba(255,255,255,0.05);
    border-radius: var(--radius);
    margin-top: 6px;
    cursor: pointer;
    transition: background 0.2s;
}
.message-file:hover { background: rgba(255,255,255,0.1); }
.message-file-icon { font-size: 24px; }
.message-file-info { flex: 1; min-width: 0; }
.message-file-name { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.message-file-size { font-size: 11px; color: var(--text-muted); }

.system-message {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 8px;
    max-width: 100%;
}

.new-msg-indicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--accent);
    color: #000;
    border: none;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    box-shadow: 0 2px 12px rgba(0,0,0,0.3);
}

/* Chat Input */
.chat-input-area {
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
}
#messageInput {
    flex: 1;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 14px;
    color: var(--text);
    font-size: 14px;
    font-family: var(--font);
    resize: none;
    max-height: 120px;
    line-height: 1.4;
}
#messageInput:focus { outline: none; border-color: var(--accent); }

.file-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    background: rgba(0,212,170,0.1);
    padding: 4px 10px;
    border-radius: var(--radius);
    font-size: 12px;
    max-width: 200px;
}
.file-preview span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.upload-progress {
    height: 3px;
    background: var(--border);
}
.upload-progress-bar {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

/* === Modals === */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    align-items: center;
    justify-content: center;
}
.modal.active { display: flex; }
.modal-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(4px);
}
.modal-content {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    width: 90%;
    max-width: 440px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 0 40px rgba(0,0,0,0.5);
    animation: modalIn 0.2s ease;
}
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text); }

.password-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--input-bg);
    padding: 12px 16px;
    border-radius: var(--radius);
    margin: 12px 0;
}
.password-display code {
    flex: 1;
    font-size: 20px;
    letter-spacing: 2px;
    color: var(--accent);
    font-weight: 600;
}

.text-muted { color: var(--text-muted); font-size: 13px; }
.text-warning { color: var(--warning); font-size: 13px; margin-top: 8px; }

hr { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.search-results { max-height: 200px; overflow-y: auto; }
.search-result-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}
.search-result-item:hover { background: rgba(255,255,255,0.05); }
.search-result-name { font-size: 14px; }
.search-result-meta { font-size: 12px; color: var(--text-muted); }

.members-list { display: flex; flex-direction: column; gap: 6px; }
.member-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: var(--radius);
    background: var(--input-bg);
}
.member-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent), var(--purple));
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    color: #000;
    font-size: 14px;
}
.member-name { font-size: 14px; }

/* Date divider */
.date-divider {
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
    padding: 12px 0 4px;
    position: relative;
}
.date-divider::before,
.date-divider::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 60px);
    height: 1px;
    background: var(--border);
}
.date-divider::before { left: 0; }
.date-divider::after { right: 0; }

/* === Animations === */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

/* === Responsive === */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -300px;
        top: 0;
        z-index: 50;
        transition: left 0.3s;
    }
    .sidebar.open { left: 0; }
    .sidebar-toggle { display: block; }
    .back-btn { display: block; }
    .chat-header { padding-left: 12px; }
    .message { max-width: 90%; }
    .auth-container { padding: 30px 20px; }
}

/* Image preview in messages */
.message-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--radius);
    margin-top: 6px;
    cursor: pointer;
}

/* Image lightbox */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 300;
    background: rgba(0,0,0,0.9);
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.lightbox.active { display: flex; }
.lightbox img {
    max-width: 95%;
    max-height: 95vh;
    object-fit: contain;
}
