/* Warna diambil dari tema blueprint FreeChat supaya konsisten */
:root {
  --paper: #F4F6F8;
  --panel: #FFFFFF;
  --ink: #141B2E;
  --ink-soft: #4A5468;
  --coral: #EF6F53;
  --mint: #2F9C87;
  --line: #DDE2E8;
  --danger: #D9463C;
}

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

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Segoe UI', Arial, sans-serif;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px -20px rgba(20,27,46,0.15);
}

.auth-box h1 {
  font-size: 22px;
  margin-bottom: 6px;
}

.auth-logo {
  max-width: 64px;
  max-height: 64px;
  display: block;
  margin: 0 auto 14px;
}

.auth-box p.sub {
  color: var(--ink-soft);
  font-size: 13.5px;
  margin-bottom: 24px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
}

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

.btn {
  width: 100%;
  padding: 11px;
  background: var(--coral);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14.5px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 6px;
}

.btn:hover { opacity: 0.92; }

.alert {
  background: rgba(217,70,60,0.1);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

.alert.success {
  background: rgba(47,156,135,0.1);
  color: var(--mint);
}

.switch-link {
  text-align: center;
  margin-top: 18px;
  font-size: 13.5px;
  color: var(--ink-soft);
}

.switch-link a { color: var(--coral); text-decoration: none; font-weight: 600; }

/* Dashboard sederhana (placeholder Fase 1) */
.dash-box { text-align: center; }
.dash-avatar {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 20px;
  margin: 0 auto 14px;
}
.dash-box h2 { font-size: 19px; margin-bottom: 4px; }
.dash-box p.username { color: var(--ink-soft); font-size: 13px; margin-bottom: 22px; }
.logout-link {
  display: inline-block; margin-top: 10px;
  color: var(--ink-soft); font-size: 13px; text-decoration: none;
  border: 1px solid var(--line); padding: 8px 18px; border-radius: 8px;
}
.logout-link:hover { border-color: var(--coral); color: var(--coral); }

/* ================= Halaman Kontak ================= */
body:has(.page-box) { align-items: flex-start; }

.page-box {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  width: 100%;
  max-width: 440px;
  margin: 20px auto;
  overflow: hidden;
}

.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.page-header h1 { font-size: 18px; }

.back-link {
  text-decoration: none;
  color: var(--ink);
  font-size: 18px;
  line-height: 1;
}

.search-form { padding: 14px 20px; }
.search-form input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 13.5px;
}

.contact-list { max-height: 70vh; overflow-y: auto; }

.contact-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  text-decoration: none;
  color: var(--ink);
  border-bottom: 1px solid var(--line);
}
.contact-item:hover { background: var(--paper); }

.contact-avatar, .chat-avatar {
  width: 44px; height: 44px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
  flex-shrink: 0;
}

img.avatar-photo { object-fit: cover; display: block; }

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 14.5px; }
.contact-username { color: var(--ink-soft); font-size: 12.5px; }

.unread-badge {
  background: var(--coral);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 20px;
  height: 20px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 6px;
}

.empty-state {
  padding: 30px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 13.5px;
}

.refresh-location-btn {
  margin-left: auto;
  background: none;
  border: none;
  font-size: 17px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}
.refresh-location-btn:hover { background: var(--paper); }
.refresh-location-btn:active { transform: rotate(90deg); transition: transform 0.3s; }

.last-updated-label {
  text-align: center;
  font-size: 11px;
  color: var(--ink-soft);
  padding: 10px 0 0;
}

.contact-bio {
  font-size: 11.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  margin: 1px 0;
}

/* ================= Halaman Chat ================= */
body:has(.chat-page) { align-items: stretch; padding: 0; }

.chat-page {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  height: 100vh;              /* fallback untuk browser lama */
  height: 100dvh;             /* tinggi layar HP yang sebenarnya keliatan (dynamic viewport height) */
  height: calc(var(--app-vh, 1vh) * 100); /* fallback tambahan lewat JS, lihat script di chat.php */
  background: var(--panel);
}

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

.chat-header-name { font-weight: 700; font-size: 14.5px; }
.chat-header-username { color: var(--ink-soft); font-size: 12px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--paper);
}

.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble-row.theirs { justify-content: flex-start; }

.bubble {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
}
.bubble-row.mine .bubble {
  background: var(--coral);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.bubble-row.theirs .bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
}

.bubble-photo {
  max-width: 100%;
  border-radius: 10px;
  display: block;
  margin-bottom: 4px;
}

.bubble-time {
  font-size: 10.5px;
  opacity: 0.7;
  margin-top: 3px;
  text-align: right;
}

.chat-input-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}

.photo-btn {
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
}

.chat-input-form input[type="text"] {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  font-size: 14px;
}

.send-btn {
  background: var(--coral);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 20px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.photo-preview-name {
  font-size: 11.5px;
  color: var(--ink-soft);
  padding: 0 14px 8px;
}

/* ================= Halaman Profil ================= */
.profile-content { padding: 24px 20px; }

.profile-avatar-wrap { display: flex; justify-content: center; margin-bottom: 16px; }
.profile-avatar {
  width: 84px; height: 84px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 26px;
}

.profile-stats {
  display: flex;
  justify-content: center;
  gap: 36px;
  margin-bottom: 22px;
}
.profile-stats .stat { text-align: center; }
.profile-stats .stat strong { display: block; font-size: 18px; }
.profile-stats .stat span { font-size: 12px; color: var(--ink-soft); }

.field-hint { font-weight: 400; color: var(--ink-soft); }

.color-picker { display: flex; gap: 10px; margin-top: 4px; }
.color-option input { display: none; }
.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  display: block; cursor: pointer;
  border: 2px solid transparent;
}
.color-option input:checked + .color-swatch {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px #fff inset;
}

.profile-view { text-align: center; }
.profile-view h2 { font-size: 19px; margin-bottom: 2px; }
.profile-view .username { color: var(--ink-soft); font-size: 13px; margin-bottom: 12px; }
.profile-view .bio { font-size: 14px; color: var(--ink); line-height: 1.5; }

.avatar-edit-wrap {
  position: relative;
  display: inline-block;
  cursor: pointer;
}
.avatar-edit-badge {
  position: absolute;
  bottom: -2px; right: -2px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
}
.avatar-preview-hint {
  text-align: center;
  font-size: 11.5px;
  color: var(--ink-soft);
  margin: 8px 0 6px;
  min-height: 14px;
}

.password-section {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}
.password-section h3 { font-size: 15px; margin-bottom: 14px; }

.gender-picker { display: flex; gap: 10px; flex-wrap: wrap; }
.gender-option {
  display: flex; align-items: center; gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
}
.gender-option input { accent-color: var(--coral); }
.gender-option:has(input:checked) { border-color: var(--coral); background: rgba(239,111,83,0.06); }

.gender-badge {
  display: inline-block;
  font-size: 14px;
  font-weight: 700;
  margin-left: 2px;
}
.gender-badge.male { color: #3B82C4; }
.gender-badge.female { color: #E05A8A; }

/* Badge notifikasi angka merah di ikon nav (Chat) */
.nav-icon-wrap { position: relative; display: inline-block; }
.nav-badge {
  position: absolute;
  top: -6px; right: -9px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: 999px;
  min-width: 16px;
  height: 16px;
  display: flex; align-items: center; justify-content: center;
  padding: 0 4px;
  border: 1.5px solid #fff;
}

/* ================= Navigasi (bottom bar mobile / sidebar desktop) ================= */

/* Halaman yang punya nav butuh ruang kosong biar konten nggak ketutupan */
body.has-app-nav { padding-bottom: 76px; }

.app-navbar-mobile {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  align-items: center;
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 8px 0 10px;
  z-index: 100;
}

.app-navbar-mobile a {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-decoration: none;
  color: var(--ink-soft);
  font-size: 21px;
  padding: 4px 18px;
}

.app-navbar-mobile a.active { color: var(--coral); }
.app-navbar-mobile .nav-label { font-size: 10px; font-weight: 600; }

.app-sidebar-desktop {
  display: none; /* baru ditampilkan lewat media query di bawah, khusus desktop */
}

/* ---- Desktop: sembunyikan bottom bar, tampilkan sidebar kiri ---- */
@media (min-width: 761px) {
  .app-navbar-mobile { display: none; }

  body.has-app-nav {
    padding-bottom: 0;
    padding-left: 84px;
  }

  .app-sidebar-desktop {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 26px;
    position: fixed;
    left: 0; top: 0; bottom: 0;
    width: 84px;
    background: #fff;
    border-right: 1px solid var(--line);
    padding-top: 32px;
    z-index: 100;
  }

  .app-sidebar-desktop a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    text-decoration: none;
    color: var(--ink-soft);
    font-size: 22px;
  }

  .app-sidebar-desktop a.active { color: var(--coral); }
  .app-sidebar-desktop .nav-label { font-size: 9.5px; font-weight: 600; }
}

/* ================= Story Bar (Momen) — di atas halaman Chat ================= */
.story-bar {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--line);
}

.story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  flex-shrink: 0;
  width: 58px;
}

.story-ring {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  padding: 2.5px;
}
.story-ring.has-moment { background: var(--ring-color, var(--coral)); }
.story-ring.add-new { background: var(--line); }

.story-avatar {
  width: 100%; height: 100%;
  border-radius: 50%;
  background: var(--panel);
  border: 2px solid #fff;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px;
}
.story-avatar.add-icon {
  background: var(--paper);
  color: var(--ink-soft);
  font-size: 22px;
  border-color: var(--paper);
}

.story-label {
  font-size: 10.5px;
  color: var(--ink-soft);
  max-width: 58px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ================= Halaman Tambah Momen ================= */
.upload-momen-box { padding: 20px; }

.upload-drop-zone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  cursor: pointer;
  overflow: hidden;
  margin-bottom: 16px;
  background: var(--paper);
}
.upload-drop-zone img,
.upload-drop-zone video {
  width: 100%; height: 100%;
  max-height: 280px;
  object-fit: cover;
}
#dropZoneText { color: var(--ink-soft); font-size: 13.5px; text-align: center; padding: 0 20px; }

/* ================= Story Viewer Full-Screen ================= */
.story-viewer {
  position: fixed;
  inset: 0;
  background: #000;
  display: flex;
  flex-direction: column;
}

.story-progress-row {
  display: flex;
  gap: 4px;
  padding: 10px 10px 0;
}
.story-progress-bar {
  flex: 1;
  height: 3px;
  background: rgba(255,255,255,0.3);
  border-radius: 3px;
  overflow: hidden;
}
.story-progress-fill { height: 100%; width: 0%; background: #fff; }

.story-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  color: #fff;
}
.story-header-name { font-weight: 600; font-size: 13.5px; flex: 1; }
.story-time-left { font-size: 11.5px; opacity: 0.75; margin-right: 6px; }
.story-close-btn, .story-delete-btn {
  color: #fff;
  font-size: 18px;
  text-decoration: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
}

.story-media-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.story-media { max-width: 100%; max-height: 100%; object-fit: contain; }

.story-tap-zone {
  position: absolute;
  top: 60px; bottom: 0;
  width: 35%;
}
.story-tap-left { left: 0; }
.story-tap-right { right: 0; }
