/* ============================================
   HouseHunt Pro - Complete Fixed Stylesheet
   Fixes: Footer bg, Header UI, Admin Sidebar,
          Admin Header, Modals, Responsive
   ============================================ */

:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --secondary: #64748b;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --dark: #1e293b;
    --light: #f8fafc;
    --body-font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --heading-font: 'Playfair Display', Georgia, serif;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--body-font);
    color: #334155;
    line-height: 1.6;
    background: #fff;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 { font-family: var(--heading-font); font-weight: 700; }

a { text-decoration: none; color: inherit; }

/* ============================================
   NAVBAR / HEADER FIXES
   ============================================ */
.navbar {
    padding: 0.75rem 0;
    z-index: 1050;
    background: #fff !important;
}

.navbar-brand {
    font-size: 1.5rem;
    margin-right: 0;
}

.brand-icon {
    width: 40px;
    height: 40px;
    background: var(--primary);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.brand-name { font-weight: 800; color: var(--dark); line-height: 1.1; }
.brand-tagline { font-size: 0.65rem; letter-spacing: 2px; text-transform: uppercase; color: var(--primary); margin-top: -2px; }

.nav-link {
    font-weight: 500;
    color: #475569 !important;
    padding: 0.5rem 1rem !important;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.nav-link:hover, .nav-link.active, .nav-link:focus {
    color: var(--primary) !important;
    background: var(--primary-light);
}

/* Navbar toggler fix */
.navbar-toggler {
    padding: 0.4rem 0.6rem;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.navbar-toggler:focus {
    box-shadow: 0 0 0 3px var(--primary-light);
    outline: none;
}

/* Navbar collapse animation fix */
.navbar-collapse { transition: all 0.3s ease; }

/* Ensure dropdowns work properly */
.dropdown-menu {
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 30px rgba(0,0,0,0.1);
    border-radius: 12px;
    padding: 0.5rem;
    z-index: 1060;
}

.dropdown-item {
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    transition: all 0.15s;
}

.dropdown-item:hover, .dropdown-item:focus {
    background: var(--primary-light);
    color: var(--primary-dark);
}

.dropdown-divider { margin: 0.4rem 0; border-color: #e2e8f0; }

/* ============================================
   HERO
   ============================================ */
.hero-section { min-height: 600px; display: flex; align-items: center; }
.hero-bg { z-index: 0; }
.hero-section .container { z-index: 1; position: relative; }
.search-box { max-width: 900px; margin: 0 auto; }

/* ============================================
   PROPERTY CARDS
   ============================================ */
.property-card {
    transition: transform 0.3s, box-shadow 0.3s;
    border-radius: 16px;
    will-change: transform;
    transform: translateZ(0);
    backface-visibility: hidden;
    border: 1px solid #e2e8f0;
    overflow: hidden;
}

.property-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 20px 40px rgba(0,0,0,0.1) !important;
}

.property-image {
    height: 240px;
    object-fit: cover;
    background: #e2e8f0;
    aspect-ratio: 4/3;
    width: 100%;
}

.property-badges { z-index: 2; }
.property-price { z-index: 2; }
.property-features span { font-size: 0.85rem; }

/* Property Type Cards */
.property-type-card {
    border-radius: 16px;
    transition: all 0.3s;
    cursor: pointer;
    border: 1px solid #e2e8f0;
}

.property-type-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 12px 24px rgba(0,0,0,0.1) !important;
}

.property-type-icon {
    width: 60px;
    height: 60px;
    background: var(--primary-light);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    font-weight: 600;
    padding: 0.625rem 1.5rem;
    border-radius: 12px;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-outline-primary {
    border-color: var(--primary);
    color: var(--primary);
}

.btn-outline-primary:hover, .btn-outline-primary:focus {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.btn-light {
    background: #f1f5f9;
    border-color: #e2e8f0;
    color: #475569;
}

.btn-light:hover {
    background: #e2e8f0;
    border-color: #cbd5e1;
}

/* ============================================
   FORMS
   ============================================ */
.form-control, .form-select {
    border-radius: 10px;
    border-color: #e2e8f0;
    padding: 0.625rem 1rem;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
    outline: none;
}

.form-label { font-weight: 500; font-size: 0.9rem; color: #475569; }

/* ============================================
   FOOTER - FIXED WHITE BACKGROUND
   ============================================ */
.site-footer {
    background: #0f172a !important;
    color: #fff;
    position: relative;
    z-index: 1;
}

.site-footer .brand-name { color: #fff !important; }

.footer-desc {
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
    line-height: 1.7;
}

.footer-heading {
    color: #fff;
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.footer-links { list-style: none; padding: 0; margin: 0; }
.footer-links li { margin-bottom: 0.6rem; }

.footer-link {
    color: rgba(255,255,255,0.6) !important;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s;
    display: inline-block;
}

.footer-link:hover, .footer-link:focus {
    color: #fff !important;
    transform: translateX(3px);
}

.footer-contact li {
    color: rgba(255,255,255,0.6);
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.footer-contact i { margin-top: 3px; flex-shrink: 0; }

.footer-divider {
    border-color: rgba(255,255,255,0.1) !important;
    margin: 1.5rem 0;
}

.footer-bottom {
    color: rgba(255,255,255,0.4);
    font-size: 0.85rem;
    padding-bottom: 1.5rem;
}

.social-links .btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-color: rgba(255,255,255,0.3);
    color: rgba(255,255,255,0.7);
    transition: all 0.2s;
}

.social-links .btn:hover {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    transform: translateY(-2px);
}

/* ============================================
   ADMIN LAYOUT - COMPLETE FIX
   ============================================ */
.admin-wrapper {
    display: flex;
    min-height: 100vh;
    position: relative;
    background: #f1f5f9;
}

/* ---- Sidebar Overlay ---- */
.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 1040;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* ---- Admin Sidebar ---- */
.admin-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    z-index: 1045;
    background: #1e293b !important;
    display: flex;
    flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.15) transparent;
}

.admin-sidebar::-webkit-scrollbar { width: 4px; }
.admin-sidebar::-webkit-scrollbar-track { background: transparent; }
.admin-sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
.admin-sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* Sidebar headers */
.sidebar-mobile-header {
    border-bottom: 1px solid rgba(255,255,255,0.1);
    background: #1e293b;
    position: sticky;
    top: 0;
    z-index: 2;
}

.sidebar-desktop-header {
    background: #1e293b;
}

.brand-icon-sm {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.sidebar-close-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    background: rgba(255,255,255,0.1);
    border: none;
    transition: all 0.2s;
}

.sidebar-close-btn:hover {
    background: rgba(255,255,255,0.2);
}

/* Sidebar Navigation */
.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
    overflow-x: hidden;
}

.sidebar-nav .nav-link {
    border-radius: 8px;
    margin: 2px 12px;
    padding: 10px 16px;
    transition: all 0.2s ease;
    color: rgba(255,255,255,0.6) !important;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.9rem;
    text-decoration: none;
}

.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,0.1);
    color: #fff !important;
}

.sidebar-nav .nav-link.active {
    background: var(--primary);
    color: #fff !important;
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}

.sidebar-nav .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 0.95rem;
    flex-shrink: 0;
}

/* Sidebar Footer */
.sidebar-footer {
    margin-top: auto;
    border-top: 1px solid rgba(255,255,255,0.08);
    padding-top: 0.75rem;
}

/* ---- Admin Main ---- */
.admin-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: #f1f5f9;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

/* ---- Admin Topbar ---- */
.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 1035;
    background: #fff;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.75rem 1rem;
    height: auto;
    min-height: var(--topbar-height);
    display: flex;
    align-items: center;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.sidebar-toggle-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
    background: #fff;
    color: #475569;
    transition: all 0.2s;
    flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.admin-page-title {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.admin-search {
    width: 220px;
    padding-left: 2rem;
    font-size: 0.9rem;
}

.admin-search:focus { box-shadow: 0 0 0 3px var(--primary-light); }

.admin-search-icon {
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    pointer-events: none;
}

/* Admin Content */
.admin-content { flex: 1; }

/* Admin Stat Cards */
.admin-stat-card {
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: all 0.2s;
}

.admin-stat-card:hover {
    box-shadow: 0 4px 12px rgba(0,0,0,0.06);
    transform: translateY(-2px);
}

/* Admin Table Cards */
.admin-table-card {
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    overflow: hidden;
}

.admin-table-card .card-header {
    border-bottom: 1px solid #e2e8f0;
}

/* Admin Panel Footer */
.admin-panel-footer {
    background: #fff;
    border-top: 1px solid #e2e8f0;
}

/* ============================================
   MODALS - FIXED SUBMIT BUTTONS
   ============================================ */
.modal { z-index: 1070 !important; }
.modal-backdrop { z-index: 1065 !important; }

.modal-dialog {
    margin: 1.75rem auto;
    max-width: 560px;
}

.modal-dialog.modal-lg { max-width: 800px; }
.modal-dialog.modal-xl { max-width: 1140px; }
.modal-dialog.modal-sm { max-width: 400px; }

.modal-content {
    border: none;
    border-radius: 16px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.15);
    overflow: hidden;
}

.modal-header {
    border-bottom: 1px solid #e2e8f0;
    padding: 1.25rem 1.5rem;
    background: #fff;
}

.modal-title { font-weight: 700; font-size: 1.1rem; }

.modal-body {
    padding: 1.5rem;
    max-height: calc(100vh - 220px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* CRITICAL FIX: Modal footer must be visible */
.modal-footer {
    border-top: 1px solid #e2e8f0;
    padding: 1rem 1.5rem;
    background: #f8fafc;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: flex-end;
    position: relative;
    z-index: 2;
}

.modal-footer .btn {
    min-width: 100px;
    position: relative;
    z-index: 3;
}

/* Ensure modal is scrollable on small screens */
@media (max-height: 700px) {
    .modal-dialog { margin: 0.5rem auto; }
    .modal-body { max-height: calc(100vh - 180px); }
}

/* ============================================
   STATS / CARDS
   ============================================ */
.stat-icon {
    width: 52px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    flex-shrink: 0;
}

.admin-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    transition: all 0.2s;
}

.admin-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.06); }

/* ============================================
   GALLERY
   ============================================ */
.carousel-item img {
    transition: transform 0.5s;
    aspect-ratio: 16/9;
    background: #e2e8f0;
    object-fit: cover;
    width: 100%;
}

#propertyCarousel:hover .carousel-item img { transform: scale(1.02); }

/* ============================================
   TABLES
   ============================================ */
.table-responsive {
    border-radius: 0 0 12px 12px;
    background: #fff;
}

.table > :not(caption) > * > * {
    padding: 0.875rem 1rem;
    vertical-align: middle;
}

.table thead th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
}

.table tbody td { font-size: 0.9rem; color: #475569; }

/* ============================================
   BADGES & LABELS
   ============================================ */
.badge {
    font-weight: 600;
    padding: 0.4em 0.75em;
    font-size: 0.75rem;
    border-radius: 6px;
}

/* ============================================
   PAGINATION
   ============================================ */
.pagination .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: 1px solid #e2e8f0;
    color: #475569;
    font-weight: 500;
    padding: 0.5rem 0.875rem;
}

.pagination .page-link:hover, .pagination .page-link:focus {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
    box-shadow: none;
}

.pagination .page-item.active .page-link {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    border-radius: 12px;
    border: none;
    padding: 1rem 1.25rem;
}

.alert-dismissible .btn-close {
    padding: 1rem;
    border-radius: 0 12px 12px 0;
}

/* ============================================
   TABS
   ============================================ */
.nav-tabs .nav-link {
    border: none;
    border-bottom: 2px solid transparent;
    color: #64748b;
    font-weight: 500;
    padding: 0.75rem 1rem;
    border-radius: 0;
    background: transparent;
}

.nav-tabs .nav-link:hover { color: var(--primary); background: transparent; }
.nav-tabs .nav-link.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: transparent;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================
   RESPONSIVE - LAPTOPS & DESKTOPS
   ============================================ */
@media (min-width: 992px) and (max-width: 1400px) {
    .admin-sidebar { width: 240px; }
    .admin-main { margin-left: 240px; }
    .property-image { height: 220px; }
    .search-box { padding: 2rem !important; }
}

@media (min-width: 1400px) {
    .container { max-width: 1320px; }
    .admin-sidebar { width: 280px; }
    .admin-main { margin-left: 280px; }
}

/* ============================================
   RESPONSIVE - TABLETS
   ============================================ */
@media (max-width: 991px) {
    /* Admin sidebar off-canvas */
    .admin-sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 4px 0 20px rgba(0,0,0,0.2);
    }

    .admin-sidebar.show { transform: translateX(0); }
    .admin-main { margin-left: 0; }

    /* Hero */
    .hero-section { min-height: 500px; }
    .property-image { height: 200px; }

    /* Navbar */
    .navbar-collapse {
        background: #fff;
        padding: 1rem;
        border-radius: 12px;
        margin-top: 0.5rem;
        box-shadow: 0 10px 30px rgba(0,0,0,0.08);
        border: 1px solid #e2e8f0;
    }

    .navbar-nav.mx-auto {
        margin-bottom: 0.5rem;
        border-bottom: 1px solid #e2e8f0;
        padding-bottom: 0.5rem;
    }

    .dropdown-menu {
        box-shadow: none;
        border: 1px solid #e2e8f0;
        margin-top: 0.25rem;
    }
}

/* ============================================
   RESPONSIVE - PHONES
   ============================================ */
@media (max-width: 767px) {
    .hero-section { min-height: 400px; }
    .search-box { padding: 1rem !important; }
    .display-3 { font-size: 2rem; }
    .property-image { height: 180px; }

    /* Admin topbar */
    .admin-topbar {
        padding: 0.5rem 0.75rem;
        min-height: 56px;
    }

    .admin-topbar .btn-sm {
        padding: 0.35rem 0.5rem;
    }

    .admin-page-title {
        font-size: 1rem;
        max-width: 150px;
    }

    /* Stats cards - 2 per row already set by col-6 */
    .stat-icon {
        width: 44px;
        height: 44px;
    }

    .stat-icon i { font-size: 1rem; }

    /* Admin sidebar on phone */
    .admin-sidebar {
        width: 260px;
    }

    /* Footer */
    .site-footer { text-align: center; }
    .site-footer .social-links { justify-content: center; }
    .footer-contact li { justify-content: center; }

    /* Modals */
    .modal-dialog {
        margin: 0.5rem;
        max-width: 100%;
    }

    .modal-body {
        padding: 1rem;
        max-height: calc(100vh - 160px);
    }

    .modal-footer {
        padding: 0.75rem 1rem;
        flex-direction: column-reverse;
    }

    .modal-footer .btn {
        width: 100%;
        min-width: auto;
    }

    /* Tables */
    .table-responsive {
        border-radius: 0 0 8px 8px;
        font-size: 0.85rem;
    }

    .table > :not(caption) > * > * {
        padding: 0.625rem 0.75rem;
    }

    /* Cards */
    .admin-card { margin-bottom: 1rem; }
}

@media (max-width: 575px) {
    .brand-name { font-size: 1.1rem; }
    .brand-tagline { font-size: 0.55rem; }
    .brand-icon { width: 34px; height: 34px; font-size: 0.85rem; }

    .btn { padding: 0.5rem 1rem; font-size: 0.9rem; }

    .admin-topbar .admin-brand span { font-size: 0.95rem; }

    /* Smaller stat cards */
    .admin-stat-card .card-body {
        padding: 0.875rem !important;
    }

    .admin-stat-card .h4 {
        font-size: 1.1rem;
    }

    /* Table cards */
    .admin-table-card .card-header {
        padding: 0.75rem !important;
    }

    .admin-table-card .card-header h5 {
        font-size: 0.95rem;
    }

    .admin-table-card .btn-sm {
        padding: 0.25rem 0.5rem;
        font-size: 0.75rem;
    }
}

/* ============================================
   PRINT
   ============================================ */
@media print {
    .navbar, .site-footer, .admin-sidebar, .admin-topbar, .btn, .sidebar-toggle-btn, .sidebar-overlay, .sidebar-mobile-header {
        display: none !important;
    }
    .admin-main { margin-left: 0 !important; }
    body { background: #fff; color: #000; }
    a { text-decoration: none; color: #000; }
    .modal { position: static; display: block !important; opacity: 1 !important; }
    .modal-dialog { margin: 0; max-width: 100%; }
    .modal-content { border: 1px solid #ddd; box-shadow: none; }
}

/* ============================================
   IMAGE STABILITY
   ============================================ */
img { max-width: 100%; height: auto; display: block; }
img[src=""] { visibility: hidden; }

/* ============================================
   UTILITIES
   ============================================ */
.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.text-truncate-3 {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.shadow-hover { transition: box-shadow 0.2s; }
.shadow-hover:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.08) !important; }

.cursor-pointer { cursor: pointer; }

.min-w-0 { min-width: 0; }

/* Animation for page load */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.4s ease-out; }

/* Prevent body scroll when sidebar is open */
body.sidebar-open { overflow: hidden; }
