/* === Reset & Base === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg-dark:       #0b141a;
    --bg-panel:      #111b21;
    --bg-sidebar:    #111b21;
    --bg-chat:       #0b141a;
    --bg-input:      #202c33;
    --bg-bubble-out: #005c4b;
    --bg-bubble-in:  #202c33;
    --bg-header:     #202c33;
    --text-primary:  #e9edef;
    --text-secondary:#8696a0;
    --green:         #00a884;
    --green-dark:    #008069;
    --border:        #2a3942;
    --danger:        #f15c6d;
    --radius:        10px;
    --nav-height:    62px;
    --top-height:    56px;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
}

a { color: var(--green); text-decoration: none; }

/* ===================== AUTH ===================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}

.auth-card {
    background: var(--bg-panel);
    border-radius: 16px;
    padding: 36px 32px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.auth-logo { text-align: center; margin-bottom: 28px; }
.auth-logo .logo-icon {
    width: 64px; height: 64px;
    background: var(--green);
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
    margin-bottom: 10px;
}
.auth-logo h1 { font-size: 22px; font-weight: 700; }
.auth-logo p  { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; color: var(--text-secondary); margin-bottom: 6px; }
.form-group input {
    width: 100%;
    padding: 12px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: border-color .2s;
}
.form-group input:focus { border-color: var(--green); }
.form-group input::placeholder { color: var(--text-secondary); }

.btn-primary {
    width: 100%; padding: 13px;
    background: var(--green); color: #fff;
    border: none; border-radius: var(--radius);
    font-size: 15px; font-weight: 600;
    cursor: pointer; transition: background .2s; margin-top: 6px;
}
.btn-primary:hover { background: var(--green-dark); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.auth-footer { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-secondary); }

.alert { padding: 11px 14px; border-radius: var(--radius); font-size: 14px; margin-bottom: 16px; }
.alert-error   { background: rgba(241,92,109,.15); color: var(--danger); border: 1px solid rgba(241,92,109,.3); }
.alert-success { background: rgba(0,168,132,.15); color: var(--green); border: 1px solid rgba(0,168,132,.3); }

.otp-input { text-align: center; letter-spacing: 8px; font-size: 22px; font-weight: 700; }
.otp-hint  { text-align: center; font-size: 13px; color: var(--text-secondary); margin-bottom: 20px; }
.otp-hint span { color: var(--green); }

#countdown { text-align: center; font-size: 13px; color: var(--text-secondary); margin-top: 12px; }
#countdown b { color: var(--green); }

.btn-resend {
    background: none; border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 9px 20px; border-radius: var(--radius);
    font-size: 13px; cursor: not-allowed;
    transition: all .2s; width: 100%;
}
.btn-resend.ready { border-color: var(--green); color: var(--green); cursor: pointer; }
.btn-resend.ready:hover { background: rgba(0,168,132,.1); }

/* ===================== APP SHELL ===================== */
.app {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
}

/* Screen = full area between topbar and bottom nav */
.screen {
    position: absolute;
    inset: 0;
    bottom: var(--nav-height);
    display: flex;
    flex-direction: column;
    background: var(--bg-dark);
    transition: transform .25s ease, opacity .25s ease;
}

.screen.hidden {
    display: none;
}

/* Chat room screen slides over top */
#screenChat {
    z-index: 10;
    bottom: 0; /* covers nav too */
}

/* ===================== TOPBAR ===================== */
.topbar {
    display: flex;
    align-items: center;
    height: var(--top-height);
    padding: 0 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    gap: 12px;
    flex-shrink: 0;
    overflow: hidden;
}

.topbar-title {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}

.topbar-user {
    display: flex; align-items: center; gap: 8px;
}

.topbar-username {
    font-size: 13px;
    color: var(--text-secondary);
    max-width: 100px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.my-avatar-sm {
    width: 36px; height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--green);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 15px;
    cursor: pointer;
    overflow: hidden;
    flex-shrink: 0;
}

.my-avatar-sm img {
    width: 100%; height: 100%; object-fit: cover; display: block;
}

.btn-back {
    background: none; border: none;
    color: var(--text-primary);
    font-size: 22px; cursor: pointer;
    padding: 4px 8px 4px 0;
    line-height: 1;
}

.chat-peer-avatar {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--green-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 16px;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-peer-avatar img {
    width: 100%; height: 100%; object-fit: cover;
}

.chat-peer-info { flex: 1; min-width: 0; }
.chat-peer-name { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-peer-status { font-size: 12px; color: var(--text-secondary); }
.chat-peer-status.online { color: var(--green); }

/* ===================== SEARCH ===================== */
.search-bar { padding: 8px 12px; background: var(--bg-sidebar); flex-shrink: 0; }
.search-bar input {
    width: 100%; padding: 9px 14px;
    background: var(--bg-input); border: none;
    border-radius: 20px; color: var(--text-primary);
    font-size: 14px; outline: none;
}
.search-bar input::placeholder { color: var(--text-secondary); }

/* ===================== CONTACT LIST ===================== */
.contact-list { flex: 1; overflow-y: auto; }
.contact-list::-webkit-scrollbar { width: 3px; }
.contact-list::-webkit-scrollbar-thumb { background: var(--border); }

.list-placeholder { text-align: center; padding: 32px 16px; color: var(--text-secondary); font-size: 14px; }

.contact-item {
    display: flex; align-items: center;
    padding: 12px 16px; gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid rgba(255,255,255,.03);
    transition: background .15s;
}
.contact-item:active { background: var(--bg-input); }

.contact-avatar { position: relative; flex-shrink: 0; }
.avatar-circle {
    width: 50px; height: 50px;
    border-radius: 50%;
    background: var(--green-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 20px; color: #fff;
}

.online-dot {
    position: absolute; bottom: 2px; right: 2px;
    width: 12px; height: 12px;
    border-radius: 50%; background: var(--green);
    border: 2px solid var(--bg-sidebar);
}

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 15px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-last-msg { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.contact-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.contact-time { font-size: 11px; color: var(--text-secondary); }

.unread-badge {
    background: var(--green); color: #fff;
    border-radius: 50%; min-width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700; padding: 0 4px;
}

/* ===================== CHAT MESSAGES ===================== */
.chat-messages {
    flex: 1; overflow-y: auto;
    padding: 12px 16px;
    display: flex; flex-direction: column; gap: 3px;
}
.chat-messages::-webkit-scrollbar { width: 3px; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border); }

.bubble-wrap { display: flex; margin-bottom: 2px; }
.bubble-wrap.out { justify-content: flex-end; }
.bubble-wrap.in  { justify-content: flex-start; }

.bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 14.5px;
    line-height: 1.45;
    word-break: break-word;
}
.bubble-wrap.out .bubble { background: var(--bg-bubble-out); border-top-right-radius: 2px; }
.bubble-wrap.in  .bubble { background: var(--bg-bubble-in);  border-top-left-radius: 2px; }

.bubble .meta {
    display: flex; align-items: center; justify-content: flex-end;
    gap: 3px; margin-top: 3px;
}
.bubble .time { font-size: 11px; color: rgba(255,255,255,.5); }
.bubble .tick { font-size: 13px; color: rgba(255,255,255,.4); }
.bubble .tick.read { color: #53bdeb; }

/* ===================== CHAT INPUT ===================== */
.chat-input-bar {
    display: flex; align-items: flex-end;
    padding: 10px 12px; gap: 10px;
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-input-bar textarea {
    flex: 1;
    background: var(--bg-input); border: none;
    border-radius: 20px;
    padding: 10px 16px;
    color: var(--text-primary);
    font-size: 15px; resize: none;
    max-height: 120px; outline: none;
    font-family: inherit; line-height: 1.4;
}
.chat-input-bar textarea::placeholder { color: var(--text-secondary); }

.btn-attach, .btn-voice {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: none; border: none;
    color: var(--text-secondary);
    font-size: 20px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: color .2s;
    padding: 0;
}
.btn-attach { font-size: 18px; }
.btn-attach:hover, .btn-voice:hover { color: var(--green); }
.btn-voice.recording { color: var(--danger); animation: pulse 1s infinite; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: .4; }
}

/* Bubble gambar */
.bubble-image {
    max-width: 100%; max-height: 260px;
    border-radius: 8px; display: block;
    cursor: pointer;
    margin-bottom: 4px;
}

/* Bubble voice */
.bubble-voice {
    display: flex; align-items: center; gap: 8px;
    padding: 2px 0 4px;
}
.btn-play-voice {
    width: 34px; height: 34px;
    border-radius: 50%; border: none;
    background: rgba(255,255,255,.15);
    color: #fff; font-size: 14px;
    cursor: pointer; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
}
.voice-bar {
    flex: 1; height: 3px;
    background: rgba(255,255,255,.2);
    border-radius: 3px; position: relative; cursor: pointer;
}
.voice-bar-fill {
    height: 100%; background: rgba(255,255,255,.6);
    border-radius: 3px; width: 0%;
    transition: width .1s linear;
}
.voice-duration { font-size: 11px; color: rgba(255,255,255,.6); flex-shrink: 0; }

/* Lightbox foto */
.lightbox {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.92);
    z-index: 300;
    display: flex; align-items: center; justify-content: center;
}
.lightbox.hidden { display: none; }
.lightbox img { max-width: 95vw; max-height: 90vh; border-radius: 8px; }
.lightbox-close {
    position: absolute; top: 16px; right: 20px;
    font-size: 32px; color: #fff; cursor: pointer;
    background: none; border: none; line-height: 1;
}

.btn-send {
    width: 46px; height: 46px;
    border-radius: 50%;
    background: var(--green); border: none;
    color: #fff; font-size: 18px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; flex-shrink: 0;
    transition: background .2s;
}
.btn-send:hover { background: var(--green-dark); }

/* ===================== BOTTOM NAV ===================== */
.bottom-nav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    height: var(--nav-height);
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 20;
}

.nav-item {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 4px;
    background: none; border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 12px;
    transition: color .2s;
    padding-bottom: 4px;
}
.nav-item.active { color: var(--green); }
.nav-icon { font-size: 22px; line-height: 1; }
.nav-label { font-size: 11px; }

/* ===================== FRIENDS ===================== */
.friend-section { flex-shrink: 0; }

.section-label {
    padding: 8px 16px 6px;
    font-size: 12px; font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: .5px;
    display: flex; align-items: center; gap: 8px;
    background: var(--bg-dark);
}

.badge-count {
    background: var(--green); color: #fff;
    border-radius: 20px; font-size: 11px;
    padding: 1px 7px; font-weight: 700;
}
.badge-count.hidden { display: none; }

.friend-item {
    display: flex; align-items: center;
    padding: 10px 16px; gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,.03);
}

.friend-item .avatar-circle {
    width: 44px; height: 44px;
    border-radius: 50%; background: var(--green-dark);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 18px; flex-shrink: 0;
    overflow: hidden;
}

.friend-item .avatar-circle img {
    width: 100%; height: 100%; object-fit: cover;
}

.friend-item-info { flex: 1; min-width: 0; }
.friend-item-name { font-size: 14px; font-weight: 500; }
.friend-item-sub  { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.friend-item-sub.text-green { color: var(--green); }

.friend-actions { display: flex; gap: 6px; flex-shrink: 0; }

.btn-friend {
    padding: 6px 12px; border-radius: 20px;
    font-size: 12px; font-weight: 600; border: none; cursor: pointer;
    transition: opacity .2s;
}
.btn-friend:hover { opacity: .8; }
.btn-friend.add    { background: var(--green); color: #fff; }
.btn-friend.accept { background: var(--green); color: #fff; }
.btn-friend.reject { background: var(--bg-input); color: var(--danger); }
.btn-friend.pending { background: var(--bg-input); color: var(--text-secondary); cursor: default; }
.btn-friend.chat   { background: var(--bg-input); color: var(--text-primary); }

/* Nav badge */
.nav-item { position: relative; }
.nav-badge {
    position: absolute; top: 6px; right: calc(50% - 18px);
    background: var(--danger); color: #fff;
    border-radius: 20px; font-size: 10px;
    padding: 1px 5px; font-weight: 700;
    min-width: 16px; text-align: center;
}
.nav-badge.hidden { display: none; }

/* ===================== PROFILE ===================== */
.profile-body {
    display: flex; flex-direction: column;
    align-items: center;
    flex: 1; gap: 10px; padding: 32px 24px;
    overflow-y: auto;
}

.profile-avatar-wrap {
    position: relative;
    margin-bottom: 8px;
}

.profile-avatar {
    width: 96px; height: 96px;
    border-radius: 50%; background: var(--green);
    display: flex; align-items: center; justify-content: center;
    font-size: 38px; font-weight: 700;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%; height: 100%;
    object-fit: cover; border-radius: 50%;
}

.btn-change-avatar {
    position: absolute; bottom: 2px; right: 2px;
    width: 30px; height: 30px;
    background: var(--bg-input);
    border: 2px solid var(--bg-dark);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; cursor: pointer;
    transition: background .2s;
}
.btn-change-avatar:hover { background: var(--green); }

.profile-name { font-size: 20px; font-weight: 700; margin-top: 4px; }

.profile-bio-wrap { text-align: center; margin: 2px 0 4px; }
.profile-bio {
    font-size: 14px; color: var(--text-secondary);
    cursor: pointer; padding: 4px 8px;
    border-radius: 8px; transition: background .2s;
    min-height: 22px;
}
.profile-bio:hover { background: var(--bg-input); }
.bio-hint { font-size: 11px; color: var(--border); }

.profile-info-card {
    width: 100%; max-width: 360px;
    background: var(--bg-input);
    border-radius: 12px;
    padding: 4px 0;
    margin-top: 8px;
}

.profile-info-row {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(255,255,255,.04);
}
.profile-info-row:last-child { border-bottom: none; }

.info-icon { font-size: 20px; flex-shrink: 0; }
.info-label { font-size: 11px; color: var(--text-secondary); }
.info-value { font-size: 14px; color: var(--text-primary); margin-top: 1px; }

/* Toggle switch */
.toggle-switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--border); border-radius: 26px;
    cursor: pointer; transition: background .2s;
}
.toggle-slider::before {
    content: ''; position: absolute;
    width: 20px; height: 20px; border-radius: 50%;
    background: #fff; left: 3px; top: 3px;
    transition: transform .2s;
}
.toggle-switch input:checked + .toggle-slider { background: var(--green); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }

.btn-change-pass {
    width: 100%; padding: 12px 16px;
    background: none; border: none;
    color: var(--text-primary); font-size: 14px;
    text-align: left; cursor: pointer;
    display: flex; align-items: center; gap: 8px;
}

.btn-logout-full {
    margin-top: 24px;
    padding: 12px 32px;
    background: rgba(241,92,109,.15);
    color: var(--danger);
    border: 1px solid rgba(241,92,109,.3);
    border-radius: var(--radius);
    font-size: 14px; font-weight: 600;
    cursor: pointer; text-decoration: none;
    transition: background .2s;
}
.btn-logout-full:hover { background: rgba(241,92,109,.25); text-decoration: none; }

/* ===================== TOAST ===================== */
.toast {
    position: fixed; bottom: calc(var(--nav-height) + 12px);
    left: 50%; transform: translateX(-50%) translateY(20px);
    background: var(--bg-input); color: var(--text-primary);
    padding: 10px 20px; border-radius: 24px;
    font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,.4);
    opacity: 0; transition: all .3s ease;
    z-index: 999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--danger); }

/* ===================== MODAL CROP ===================== */
.crop-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.85);
    z-index: 200;
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.crop-overlay.hidden { display: none; }

.crop-modal {
    background: var(--bg-panel);
    border-radius: 16px;
    width: 100%; max-width: 380px;
    overflow: hidden;
    display: flex; flex-direction: column;
}

.crop-header {
    padding: 14px 18px;
    font-size: 15px; font-weight: 600;
    border-bottom: 1px solid var(--border);
}

.crop-canvas-wrap {
    width: 100%;
    height: 320px;
    background: #000;
    overflow: hidden;
}

.crop-canvas-wrap img {
    display: block;
    max-width: 100%;
}

.crop-actions {
    display: flex; gap: 10px;
    padding: 14px 16px;
    border-top: 1px solid var(--border);
}

.btn-crop-cancel {
    flex: 1; padding: 11px;
    background: var(--bg-input); border: none;
    color: var(--text-secondary);
    border-radius: var(--radius); font-size: 14px;
    cursor: pointer;
}

.btn-crop-save {
    flex: 1; padding: 11px;
    background: var(--green); border: none;
    color: #fff; border-radius: var(--radius);
    font-size: 14px; font-weight: 600; cursor: pointer;
}
.btn-crop-save:disabled { opacity: .6; cursor: not-allowed; }

/* ===================== SPINNER ===================== */
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid rgba(255,255,255,.2);
    border-top-color: #fff; border-radius: 50%;
    animation: spin .7s linear infinite;
    vertical-align: middle; margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Desktop: sidebar layout */
@media (min-width: 768px) {
    .app { flex-direction: row; }

    .bottom-nav {
        position: relative;
        width: 64px; height: 100%;
        flex-direction: column;
        border-top: none; border-right: 1px solid var(--border);
        order: -1;
    }

    .screen { bottom: 0; position: relative; flex: 1; height: 100%; }
    #screenChat { position: absolute; left: 64px; right: 0; top: 0; bottom: 0; }

    .toast { bottom: 16px; }
}
