:root {
    --bg: #0A0A0B;
    --surface: #111113;
    --surface-2: #1A1A1D;
    --border: #2A2A2F;
    --text: #F5F5F7;
    --text-muted: #8E8E93;
    --primary: #0A84FF;
    --primary-press: #0066CC;
    --danger: #FF453A;
    --success: #32D74B;
    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 8px 30px rgba(0,0,0,0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Inter', 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    overflow: hidden;
}

.app {
    display: flex;
    height: 100vh;
    width: 100%;
}

/* ============ AUTH PAGE ============ */
#authPage {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(1200px 600px at 50% -10%, rgba(10,132,255,0.15), transparent), var(--bg);
    padding: 20px;
}

.auth-box {
    background: rgba(17,17,19,0.8);
    backdrop-filter: blur(20px);
    padding: 36px 28px;
    border-radius: 20px;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 32px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, #0A84FF, #5E5CE6);
    border-radius: 12px;
    display: grid;
    place-items: center;
    position: relative;
    overflow: hidden;
}

.logo-icon svg {
    width: 24px;
    height: 24px;
    z-index: 2;
}

.logo-icon::after {
    content: '';
    position: absolute;
    width: 100px;
    height: 100px;
    background: radial-gradient(circle, rgba(255,255,255,0.2), transparent 60%);
    top: -30px;
    left: -30px;
}

.logo h1 {
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-size: 15px;
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(10,132,255,0.15);
}

.btn {
    width: 100%;
    padding: 13px;
    border: none;
    border-radius: var(--radius-sm);
    font-weight: 600;
    cursor: pointer;
    font-size: 15px;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
    margin-bottom: 12px;
}

.btn-primary:active {
    background: var(--primary-press);
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.error {
    color: var(--danger);
    font-size: 12px;
    margin-top: 6px;
    display: none;
}

.toggle-text {
    text-align: center;
    margin-top: 18px;
    font-size: 14px;
    color: var(--text-muted);
}

.toggle-text button {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-weight: 600;
}

/* ============ CHAT PAGE ============ */
#chatPage {
    flex: 1;
    display: none;
    flex-direction: column;
    height: 100%;
}

#chatPage.active {
    display: flex;
}

.chat-layout {
    display: flex;
    height: 100%;
    width: 100%;
}

.sidebar {
    width: 100%;
    max-width: 360px;
    height: 100%;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--surface-2);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sidebar-logo.logo-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
}

.sidebar-logo.logo-icon svg {
    width: 18px;
    height: 18px;
}

.sidebar-logo span {
    font-weight: 700;
    font-size: 18px;
}

.hamburger {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: all 0.2s;
}

.hamburger:active {
    background: var(--surface-2);
    transform: scale(0.95);
}

.hamburger svg {
    width: 18px;
    height: 18px;
}

.tabs {
    display: flex;
    padding: 8px;
    gap: 6px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    border-radius: 8px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
    transition: all 0.2s;
}

.tab.active {
    background: var(--surface);
    color: var(--primary);
}

.search-box {
    padding: 12px;
}

.search-box input {
    width: 100%;
    padding: 11px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 14px;
}

.list-container {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0;
}

.contact-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    gap: 12px;
    align-items: center;
    transition: background 0.2s;
    margin: 0 8px;
    border-radius: var(--radius-sm);
}

.contact-item:hover {
    background: var(--surface-2);
}

.contact-item:active {
    transform: scale(0.99);
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, #5E5CE6, #0A84FF);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.contact-info {
    flex: 1;
    min-width: 0;
}

.contact-name {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-email {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.add-btn {
    padding: 6px 12px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
}

.add-btn:disabled {
    background: var(--surface-2);
    color: var(--text-muted);
}

.empty-state {
    padding: 32px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* ============ PROFILE DRAWER ============ */
.drawer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    max-width: 360px;
    height: 100%;
    background: var(--surface);
    border-right: 1px solid var(--border);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4,0,0.2,1);
    display: flex;
    flex-direction: column;
}

.drawer.open {
    transform: translateX(0);
}

.drawer-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface-2);
}

.drawer-back {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    display: grid;
    place-items: center;
    cursor: pointer;
}

.drawer-title {
    font-weight: 700;
    font-size: 18px;
}

.profile-body {
    padding: 24px 20px;
    overflow-y: auto;
}

.profile-avatar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.profile-avatar {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: linear-gradient(135deg, #5E5CE6, #0A84FF);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 36px;
    position: relative;
    overflow: hidden;
    border: 3px solid var(--border);
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-upload {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: grid;
    place-items: center;
    cursor: pointer;
    border: 2px solid var(--surface);
}

.avatar-upload svg {
    width: 16px;
    height: 16px;
}

#avatarFile {
    display: none;
}

.profile-field {
    margin-bottom: 20px;
}

.profile-field label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.profile-field input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
}

.profile-field input:focus {
    outline: none;
    border-color: var(--primary);
}

.profile-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 24px;
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-danger {
    background: rgba(255,69,58,0.1);
    color: var(--danger);
    border: 1px solid rgba(255,69,58,0.3);
}

/* ============ CHAT MAIN ============ */
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-back-mobile {
    display: none;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    place-items: center;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #5E5CE6, #0A84FF);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: 15px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-meta {
    flex: 1;
}

.chat-name {
    font-weight: 700;
    font-size: 16px;
}

.chat-status {
    font-size: 12px;
    color: var(--success);
    margin-top: 2px;
}

.messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.message {
    display: flex;
    gap: 8px;
    max-width: 75%;
    animation: msgIn 0.2s ease;
}

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

.message.sent {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.message-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 15px;
    word-break: break-word;
    line-height: 1.45;
}

.message.sent .message-bubble {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.message.received .message-bubble {
    background: var(--surface-2);
    color: var(--text);
    border-bottom-left-radius: 6px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
    align-self: flex-end;
    padding: 0 4px;
}

.no-messages {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    font-size: 15px;
    flex-direction: column;
    gap: 12px;
}

.no-messages svg {
    width: 48px;
    height: 48px;
    opacity: 0.3;
}

.input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    background: var(--surface);
}

.input-area input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface-2);
    color: var(--text);
    font-size: 15px;
}

.input-area input:focus {
    outline: none;
    border-color: var(--primary);
}

.input-area button {
    width: 44px;
    height: 44px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.input-area button:active {
    background: var(--primary-press);
    transform: scale(0.95);
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface);
    padding: 28px;
    border-radius: 16px;
    max-width: 360px;
    width: 100%;
    border: 1px solid var(--border);
    animation: modalIn 0.3s cubic-bezier(0.4,0,0.2,1);
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content h3 {
    margin-bottom: 8px;
    font-size: 20px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 20px;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        max-width: 100%;
        position: absolute;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s;
    }

    .sidebar.mobile-open {
        transform: translateX(0);
    }

    .chat-back-mobile {
        display: grid;
    }

    .drawer {
        max-width: 100%;
    }
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 90;
}

.overlay.active {
    display: block;
}

/* Fix input ketutup di mobile */
body {
    height: 100dvh; /* ganti 100vh jadi 100dvh */
}

.input-area {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: none; /* default hide */
}

.input-area.active {
    display: flex; /* munculin kalau udah pilih chat */
}

/* Fix message area biar gak ketiban input */
.messages-area {
    padding-bottom: 80px;
}