/**
 * responsive.css — utilitas responsif bersama (mobile & tablet)
 */

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Cegah scroll horizontal tidak sengaja di layar kecil */
@media (max-width: 991px) {
  html,
  body {
    overflow-x: clip;
  }
  .container,
  .content {
    max-width: 100%;
  }
}

/* ─── Navbar publik ─── */
@media (min-width: 992px) {
  .m-nav-hamburger,
  .m-nav-brand {
    display: none !important;
  }

  .navbar.m-topnav .navbar-toggler {
    display: none !important;
  }
}

@media (max-width: 991px) {
  .navbar .navbar-collapse .d-flex,
  .navbar .navbar-collapse #nav-guest,
  .navbar .navbar-collapse #nav-user,
  .navbar .navbar-collapse .nav-account {
    flex-wrap: wrap;
    justify-content: center;
    width: 100%;
    margin-top: 0.75rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border, #e5e7eb);
    gap: 0.5rem !important;
  }
  .navbar .navbar-collapse .nav-account {
    border: none;
    padding: 0;
    justify-content: center;
  }
  .navbar .navbar-collapse .btn-login-nav,
  .navbar .navbar-collapse .btn-register-nav,
  .navbar .navbar-collapse .btn-logout,
  .navbar .navbar-collapse .btn-logout-nav,
  .navbar .navbar-collapse .btn-profile {
    flex: 1 1 calc(50% - 0.35rem);
    justify-content: center;
    min-height: 44px;
  }
  .navbar .navbar-collapse .nav-account__who {
    flex: 1 1 100%;
    justify-content: center;
  }
  .navbar .navbar-nav {
    width: 100%;
    text-align: center;
  }
  .navbar .nav-link {
    padding: 0.65rem 0.75rem;
  }
  .user-greeting,
  .nav-account__who {
    width: 100%;
    text-align: center;
    justify-content: center;
    font-size: 0.82rem;
  }
}

@media (max-width: 576px) {
  .user-greeting--hide-sm {
    display: none !important;
  }
  .navbar .navbar-collapse .btn-login-nav,
  .navbar .navbar-collapse .btn-register-nav,
  .navbar .navbar-collapse .btn-logout,
  .navbar .navbar-collapse .btn-logout-nav,
  .navbar .navbar-collapse .btn-profile {
    flex: 1 1 100%;
  }
  .navbar-brand {
    font-size: 1.1rem !important;
  }
}

/* ─── Page header & stat bar ─── */
@media (max-width: 640px) {
  .stat-bar {
    gap: 0.85rem 1rem;
    justify-content: center;
  }
  .stat-bar__item {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 130px;
  }
}

@media (max-width: 576px) {
  .hero h2 {
    font-size: 1.5rem !important;
    line-height: 1.2;
  }
  .hero p {
    font-size: 0.88rem !important;
  }
  .hero {
    padding: 2rem 0 3.5rem !important;
  }
  .page-header,
  .page-header--compact {
    padding: 1.35rem 0 1.1rem !important;
  }
  .page-header__title {
    font-size: 1.35rem !important;
  }
  .page-header__sub {
    font-size: 0.88rem;
  }
}

/* ─── Filter & search panel ─── */
@media (max-width: 576px) {
  .filter-bar {
    padding: 1rem !important;
    margin-top: -2rem !important;
  }
  .filter-card {
    padding: 1rem !important;
  }
  .search-panel {
    padding: 1rem !important;
  }
  .search-panel__grid .search-panel__actions {
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .search-panel__grid .search-panel__actions .btn,
  .search-panel__grid .search-panel__actions button {
    width: 100%;
  }
  .btn-filter,
  .btn-reset {
    width: 100%;
  }
  .filter-actions {
    flex-direction: column !important;
  }
  .filter-actions .btn-filter,
  .filter-actions .btn-reset,
  .filter-actions .btn-rekomendasi {
    flex: none !important;
    width: 100%;
  }
  .results-meta {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.35rem !important;
  }
}

/* ─── Kartu properti & detail ─── */
@media (max-width: 576px) {
  .house-card img,
  .rec-card img {
    height: 170px !important;
  }
  .section-title {
    font-size: 1.1rem !important;
  }
  .hero-stats {
    gap: 0.75rem !important;
  }
  .hero-stat {
    flex: 1 1 calc(50% - 0.5rem);
    min-width: 140px;
  }
  .detail-grid {
    grid-template-columns: 1fr !important;
  }
  .detail-carousel .carousel-item img {
    height: 220px !important;
  }
  .detail-img {
    height: 200px !important;
  }
  .detail-price {
    font-size: 1.35rem !important;
  }
  .modal-body {
    padding: 1.1rem !important;
  }
  .modal-header {
    padding: 1rem 1.1rem !important;
  }
  .modal-dialog {
    margin: 0.65rem !important;
    max-width: calc(100vw - 1.3rem) !important;
  }
}

/* ─── Financial insight banner ─── */
@media (max-width: 576px) {
  .fin-insight {
    padding: 1rem !important;
    flex-direction: column !important;
    align-items: stretch !important;
  }
  .fin-insight--cta {
    gap: 0.75rem !important;
  }
  .fin-insight__cta {
    width: 100%;
    text-align: center;
    white-space: normal !important;
    justify-content: center;
  }
}

/* ─── Footer ─── */
@media (max-width: 576px) {
  .site-footer__grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
    text-align: center;
  }
  .site-footer__tagline {
    max-width: none;
    margin: 0 auto;
  }
  .site-footer__nav {
    align-items: center;
  }
  .site-footer__bottom {
    flex-direction: column;
    text-align: center;
  }
  .site-footer__bottom span:last-child {
    text-align: center;
  }
}

/* ─── Toast & notifikasi ─── */
@media (max-width: 576px) {
  .toast-container {
    left: 1rem !important;
    right: 1rem !important;
    bottom: max(1rem, env(safe-area-inset-bottom, 0px)) !important;
  }
  .toast-container > div {
    max-width: 100%;
  }
}

/* ─── Auth pages ─── */
@media (max-width: 576px) {
  .auth-container {
    padding: 1.25rem 1rem !important;
  }
  .auth-container .card-body {
    padding: 1.35rem !important;
  }
  body.auth-page {
    padding: 0.75rem;
    padding-left: max(0.75rem, env(safe-area-inset-left, 0px));
    padding-right: max(0.75rem, env(safe-area-inset-right, 0px));
    align-items: flex-start;
    padding-top: 1.5rem;
  }
  body.auth-page .auth-container {
    justify-content: flex-start;
    padding-top: 0.5rem;
  }
  .brand h1 {
    font-size: 1.4rem !important;
  }
  .input-group-text {
    min-width: 44px;
    justify-content: center;
  }
}

/* ─── Onboarding ─── */
@media (max-width: 576px) {
  .ob-page {
    padding: 0.75rem 0.65rem 1.5rem !important;
  }
  .ob-top {
    flex-wrap: wrap;
    gap: 0.65rem;
  }
  .ob-progress {
    width: 100%;
    margin-left: 0 !important;
    justify-content: space-between;
  }
  .ob-progress-track {
    flex: 1;
    max-width: none !important;
  }
}

/* ─── Admin panel (dashboard, accounts) ─── */
@media (max-width: 991px) {
  .main .content {
    padding-left: max(1rem, env(safe-area-inset-left, 0px));
    padding-right: max(1rem, env(safe-area-inset-right, 0px));
  }
  .topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
  }
  .topbar-left {
    flex: 1;
    min-width: 0;
  }
  .tab-nav {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    border-radius: var(--radius-lg, 12px);
    scrollbar-width: none;
  }
  .tab-nav::-webkit-scrollbar {
    display: none;
  }
  .tab-btn {
    flex-shrink: 0;
    white-space: nowrap;
  }
  .table-wrap {
    -webkit-overflow-scrolling: touch;
    margin-left: -0.25rem;
    margin-right: -0.25rem;
    padding-bottom: 2px;
  }
  .table-wrap::after {
    content: '';
    display: block;
    height: 1px;
  }
  .rumah-filter-bar {
    padding: 14px !important;
  }
  .rf-grid {
    gap: 10px !important;
  }
  .rf-field {
    flex: 1 1 100% !important;
    max-width: none !important;
  }
  .rf-reset-btn {
    width: 100%;
    justify-content: center;
    min-height: 44px;
  }
  .eval-steps {
    flex-direction: column;
    align-items: stretch;
    gap: 0.35rem;
  }
  .eval-step {
    min-width: 0;
    width: 100%;
  }
  .eval-step-connector {
    display: none;
  }
  .eval-action-grid {
    grid-template-columns: 1fr !important;
  }
  .crm-pipeline-pill {
    font-size: 0.72rem;
    margin-bottom: 4px;
  }
}

@media (max-width: 576px) {
  .admin-form-modal .modal-dialog,
  .modal-dialog {
    margin: 0.5rem auto !important;
    max-width: calc(100vw - 1rem) !important;
  }
  .admin-form-modal .modal-header,
  .admin-form-modal .modal-body,
  .admin-form-modal .modal-footer {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
  }
  .admin-form-modal .form-section {
    padding: 0.9rem !important;
  }
  .modal-footer {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
    gap: 0.5rem !important;
  }
  .modal-footer .btn-save,
  .modal-footer .btn-cancel,
  .modal-footer .btn-add,
  .modal-footer .page-btn,
  .modal-footer > button {
    width: 100% !important;
    margin: 0 !important;
    justify-content: center;
    min-height: 44px;
  }
  .section-header .btn-add,
  .section-header .btn-export {
    width: 100%;
    justify-content: center;
  }
  .crud-toolbar .page-btn {
    min-height: 40px;
  }
  .match-card .page-btn {
    width: 100% !important;
  }
  .pros-rp {
    padding: 0.55rem 0.75rem !important;
  }
  .pros-status-preview {
    font-size: 0.72rem;
  }
  .kpi-card,
  .kpi-card-clean,
  .stat-card {
    padding: 0.85rem 0.95rem !important;
  }
  .chart-canvas-wrap {
    height: 165px !important;
  }
  .pagination-wrap,
  #prospek-pagination,
  #users-pagination,
  #rumah-pagination {
    gap: 0.35rem;
  }
  .page-content {
    padding-top: 1.15rem !important;
    padding-bottom: 2rem !important;
  }
  .empty-state {
    padding: 2.5rem 1rem !important;
  }
  .btn-icon-sm {
    width: 40px;
    height: 40px;
  }
  .btn-icon {
    width: 40px !important;
    height: 40px !important;
    flex-shrink: 0;
  }
}

/* ─── Admin mobile: anti-overflow & rapikan dashboard ─── */
@media (max-width: 991px) {
  /* Jaring pengaman: tidak ada elemen yang boleh melebihi lebar layar */
  .main,
  .main .content,
  .tab-pane,
  .section-card,
  .section-card--chart,
  .table-wrap {
    max-width: 100%;
  }
  .content .row {
    --bs-gutter-x: 0.75rem;
    margin-left: 0;
    margin-right: 0;
  }

  /* Tab "Periode": geser horizontal (chip bar) supaya tidak terpotong/membungkus berantakan */
  .dash-toolbar .filter-group {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    justify-content: flex-start;
  }
  .dash-toolbar .filter-group::-webkit-scrollbar {
    display: none;
  }
  .dash-toolbar .filter-group .filter-btn {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  /* Teks panjang membungkus, bukan terpotong */
  .insight-item-text,
  .section-title,
  .kpi-label,
  .top-table-sub {
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .top-table-name {
    max-width: 150px;
  }

  /* Tabel di dalam kartu boleh digeser horizontal tanpa melebarkan halaman */
  .table-wrap {
    overflow-x: auto;
  }
}

@media (max-width: 576px) {
  /* KPI: 2 kolom rapi, nilai tidak meluap */
  .kpi-card-clean {
    gap: 0.7rem !important;
    padding: 0.85rem 0.9rem !important;
  }
  .kpi-card-clean .kpi-value {
    font-size: 1.15rem !important;
    line-height: 1.15;
  }
  .kpi-card-clean .kpi-icon {
    width: 38px !important;
    height: 38px !important;
    font-size: 0.95rem !important;
  }
  .kpi-label {
    font-size: 0.72rem !important;
  }
  /* Quick stats (hari ini · bulan ini · tahun ini) tetap dalam satu area */
  .dash-quick-stats {
    justify-content: flex-start;
    font-size: 0.74rem;
  }
}

/* Tombol "Tambah Rumah" jadi ikon + bulat saja (mobile) */
@media (max-width: 991px) {
  .btn-add--rumah {
    width: 44px !important;
    height: 44px;
    min-width: 44px;
    padding: 0 !important;
    border-radius: 50%;
    justify-content: center;
    flex-shrink: 0;
    gap: 0;
  }
  .btn-add--rumah .btn-add__label {
    display: none;
  }
  /* Kolom pencarian melebar penuh, tombol + merapat ke kanan */
  .btn-add--rumah {
    margin-left: auto;
  }
  .section-header .d-flex:has(.btn-add--rumah) {
    width: 100%;
  }
  .section-header .d-flex:has(.btn-add--rumah) > div:first-child {
    flex: 1 1 auto;
    min-width: 0;
  }
  .section-header .d-flex:has(.btn-add--rumah) .search-input {
    width: 100% !important;
    max-width: none !important;
  }
}

/* Rekap Penjualan: tombol Unduh & Tambah sebaris kiri-kanan (mobile) */
@media (max-width: 991px) {
  .penjualan-actions {
    width: 100%;
  }
  .penjualan-actions .btn-export,
  .penjualan-actions .btn-add {
    flex: 1 1 0;
    width: auto !important;
    justify-content: center;
    min-height: 44px;
  }
}

/* Data Pembeli: pencarian penuh, filter rapi, reset disembunyikan (mobile) */
@media (max-width: 991px) {
  .users-toolbar {
    width: 100%;
    gap: 0.5rem !important;
  }
  .users-toolbar__search {
    flex: 1 1 100%;
    width: 100%;
    min-width: 0;
  }
  .users-toolbar__search .search-input {
    width: 100% !important;
  }
  .users-toolbar__filter {
    flex: 1 1 100%;
    width: 100% !important;
    min-height: 44px;
  }
  .users-toolbar__reset {
    display: none !important;
  }
}

/* Sembunyikan refresh & ringkasan cepat di toolbar dashboard (mobile) */
@media (max-width: 991px) {
  .dash-toolbar .btn-icon,
  .dash-toolbar .dash-quick-stats {
    display: none !important;
  }
  .dash-toolbar {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center !important;
    column-gap: 0.5rem;
    row-gap: 0.6rem;
  }
  .dash-toolbar__label {
    width: 100%;
  }
  .dash-toolbar .filter-group,
  .dash-toolbar #dash-custom-date-wrap {
    width: 100%;
  }
}

/* ─── Drawer menu mobile: rapikan jarak & teks ─── */
@media (max-width: 991px) {
  .sidebar.open .sidebar-nav {
    gap: 0.2rem;
    padding: 0.25rem 0;
    flex: 0 0 auto;
  }
  .sidebar.open .sidebar-link {
    min-height: 46px;
    padding: 0.6rem 0.85rem;
    margin: 1px 12px;
    gap: 0.8rem;
    font-size: 0.92rem;
    line-height: 1.2;
  }
  .sidebar.open .sidebar-link__icon {
    font-size: 1.1rem;
    width: 22px;
    flex-shrink: 0;
  }
  .sidebar.open .sidebar-link__text {
    line-height: 1.2;
  }
  .sidebar.open .sidebar-section {
    padding: 0.5rem 1.25rem 0.3rem;
  }
}

/* ─── Touch target minimum ─── */
@media (max-width: 991px) {
  .navbar-toggler {
    min-width: 44px;
    min-height: 44px;
  }
  .sidebar-toggle {
    min-width: 44px;
    min-height: 44px;
  }
  .sidebar-link {
    min-width: 44px;
    min-height: 44px;
  }
}
