/* =========================================
   1. ROOT VARIABLES & RESETS
========================================= */
:root {
    --primary: #1a73e8;
    --primary-hover: #1557b0;
    --primary-light: #e3f2fd;
    --success: #2e7d32;
    --danger: #d32f2f;
    --warning: #f59e0b; /* Premium/Gold */
    --bg-color: #f4f7f6;
    --text-main: #333;
    --text-muted: #666;
    --border-color: #eee;
    --card-bg: #ffffff;
    --transition: 0.2s ease-in-out;
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    line-height: 1.6;
    overflow-x: hidden; 
    display: flex;
    flex-direction: column;
    min-height: 100vh; /* Ensures footer stays at bottom */
}

/* =========================================
   2. HEADER & NAVIGATION
========================================= */
.site-header {
    background: white;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.nav-container {
    max-width: 1240px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px; 
}

.nav-brand-group, .nav-user-group {
    display: flex;
    align-items: center;
    gap: 15px;
    flex-wrap: wrap; /* Allows links to wrap safely on small screens */
}

.nav-brand {
    font-weight: 800;
    text-decoration: none;
    color: var(--primary);
    font-size: 1.4rem;
    letter-spacing: -0.5px;
}

.nav-link {
    text-decoration: none;
    color: #555;
    font-size: 0.95rem;
    font-weight: 500;
    transition: var(--transition);
}

.nav-link:hover { color: var(--primary); }
.nav-highlight { color: var(--success); font-weight: bold; }
.nav-danger { color: var(--danger); }
.nav-divider { color: #ccc; user-select: none; }

/* =========================================
   3. HERO SECTION
========================================= */
.hero-section {
    background: linear-gradient(135deg, #64748b 0%, #475569 100%);
    padding: 80px 20px;
    text-align: center;
    border-radius: 0 0 25px 25px;
    margin-top: -20px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    color: white;
}

.hero-title { 
    font-size: 3.2rem;
    font-weight: 800; 
    margin-bottom: 15px; 
    letter-spacing: -1.5px;
    color: #fff;
}

.hero-subtitle { 
    font-size: 1.25rem; 
    color: rgba(255,255,255,0.9); 
    margin-bottom: 40px;
    font-weight: 400; 
}

.search-tabs { display: flex; justify-content: center; gap: 5px; margin-bottom: -1px; max-width: 800px; margin: 0 auto; }
.search-tab { 
    padding: 12px 24px; 
    background: rgba(255,255,255,0.15); 
    border: none; 
    color: white;
    border-radius: 12px 12px 0 0; 
    cursor: pointer; 
    font-weight: 600; 
    font-family: inherit;
    transition: var(--transition);
}
.search-tab.active { background: #fff; color: #1e293b; }

.hero-search-form {
    max-width: 850px; 
    margin: 0 auto; 
    display: flex; 
    gap: 10px;
    background: #fff; 
    padding: 12px; 
    border-radius: 16px;
    box-shadow: 0 10px 25px -5px rgba(0,0,0,0.1);
}

.hero-input { 
    flex: 1;
    padding: 16px 20px; 
    border: 1px solid #e2e8f0; 
    border-radius: 10px; 
    font-size: 1.1rem; 
    outline: none; 
    color: #334155;
    min-width: 150px; /* Prevents squashing on tablets */
}

.hero-btn { 
    background: var(--primary); 
    color: white; 
    border: none; 
    padding: 0 35px; 
    border-radius: 10px; 
    font-weight: 700;
    font-size: 1.1rem; 
    cursor: pointer; 
    transition: var(--transition); 
}
.hero-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* =========================================
   4. HOMEPAGE COMPONENTS
========================================= */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
    margin-bottom: 60px;
}

.cat-card {
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 15px;
    padding: 25px 15px;
    text-align: center;
    text-decoration: none;
    color: #334155;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.cat-card:hover {
    transform: translateY(-5px);
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    color: var(--primary);
}

.cat-icon { font-size: 2.5rem; }
.cat-name { font-weight: 700; font-size: 0.95rem; }

.featured-biz-wrap { 
    background: #f8fafc; 
    padding: 40px 20px; 
    border-radius: 20px;
    border: 1px solid var(--border-color); 
    margin: 60px 0; 
}

.biz-home-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px; 
}

.biz-home-card { 
    background: white; 
    border: 1px solid var(--border-color); 
    border-radius: 12px; 
    padding: 20px; 
    display: flex;
    gap: 15px; 
    text-decoration: none; 
    color: inherit; 
    transition: var(--transition);
}

.biz-home-card:hover { border-color: var(--primary); transform: translateY(-3px); box-shadow: var(--shadow-md); }

.biz-home-icon { 
    width: 60px; height: 60px; border-radius: 8px; background: #f1f5f9; 
    display: flex; align-items: center; justify-content: center;
    font-size: 1.5rem; 
    overflow: hidden; flex-shrink: 0; 
}
.biz-home-icon img { width: 100%; height: 100%; object-fit: cover; }

/* =========================================
   5. GLOBAL LAYOUT & CONTAINERS
========================================= */
.main-content-wrapper { flex: 1; }

.container, .layout-sidebar, .dashboard-layout {
    max-width: 1240px; 
    margin: 2.5rem auto;
    padding: 0 20px;
    width: 100%;
}

.section-title { font-size: 2rem; font-weight: 800; color: #1e293b; margin-bottom: 1.5rem; }

.card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05);
}

.card-narrow { max-width: 500px; margin: 0 auto; }

/* Sidebar & Dashboard Layout Logic */
.layout-sidebar, .dashboard-layout { 
    display: flex; 
    gap: 30px; 
    align-items: flex-start;
}

.sidebar, .dashboard-sidebar { 
    width: 280px; 
    flex-shrink: 0; 
}

.main-content, .dashboard-content { 
    flex: 1;
    min-width: 0; 
}

/* Typography Helpers */
h1, h2, h3 { color: var(--primary); margin-bottom: 15px; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); font-size: 0.9rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 24px;
    border-radius: 8px;
    font-weight: 700;
    text-decoration: none;
    text-align: center;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    width: 100%;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; padding: 10px 20px; font-size: 0.9rem;}

/* Alerts */
.alert { padding: 15px; border-radius: 8px; margin-bottom: 20px; font-weight: 600; border: 1px solid transparent; }
.alert-error { background: #fef2f2; color: #c62828; border-color: #fecaca; border-left: 5px solid #c62828; }
.alert-success { background: #f0fdf4; color: var(--success); border-color: #bbf7d0; border-left: 5px solid var(--success); }

/* =========================================
   6. MARKETPLACE (Listing Grids)
========================================= */
.ad-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 25px; 
}

.ad-card-container, .ad-card {
    background: #fff; border-radius: 12px; overflow: hidden; border: 1px solid var(--border-color); 
    transition: var(--transition);
    display: flex; flex-direction: column; text-decoration: none; color: inherit;
}
.ad-card-container:hover, .ad-card:hover { transform: translateY(-5px); box-shadow: var(--shadow-md); }

.ad-img-box, .ad-img-wrapper { width: 100%; height: 220px; overflow: hidden; background: #f8fafc; position: relative; }
.ad-img-box img, .ad-img-wrapper img { width: 100%; height: 100%; object-fit: cover; }

.ad-content, .ad-details { padding: 15px; flex-grow: 1; display: flex; flex-direction: column; gap: 8px; }
.ad-title-link, .ad-title { text-decoration: none; color: #1e293b; font-weight: 700; font-size: 1.15rem; line-height: 1.4; }
.ad-price-tag, .ad-price { color: #059669; font-weight: 800; font-size: 1.3rem; margin-bottom: 5px; }
.ad-footer, .ad-meta { margin-top: auto; padding-top: 12px; border-top: 1px solid #f1f5f9; font-size: 0.85rem; color: var(--text-muted); }

/* =========================================
   7. DIRECTORY & LOCAL BUSINESSES
========================================= */
.directory-grid { display: flex; flex-direction: column; gap: 20px; }

.biz-card { 
    background: #fff; border-radius: 16px; border: 1px solid var(--border-color); 
    padding: 25px; display: flex; gap: 25px;
    transition: var(--transition); position: relative;
}
.biz-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); }
.biz-card.premium { border-left: 6px solid var(--warning); background: #fffbeb; } 

.biz-logo-placeholder {
    width: 110px; height: 110px; background: #f1f5f9; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.5rem; color: #94a3b8; flex-shrink: 0; overflow: hidden;
}
.biz-logo-placeholder img { width: 100%; height: 100%; object-fit: cover; }

.biz-content { flex: 1; }
.biz-title { margin: 0 0 5px 0; font-size: 1.4rem; color: #1e293b; font-weight: 800; }
.biz-cat { font-size: 0.85rem; color: #64748b; text-transform: uppercase; font-weight: 700; margin-bottom: 12px; display: block; }
.biz-desc { color: #475569; font-size: 1rem; line-height: 1.6; margin-bottom: 20px; }

.btn-outline { 
    border: 1px solid #cbd5e1; background: #fff; padding: 10px 18px;
    border-radius: 8px; text-decoration: none; color: #1e293b; 
    font-weight: 700; font-size: 0.9rem; transition: var(--transition); 
}
.btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }

.premium-badge { 
    position: absolute; top: 15px; right: 15px; background: var(--warning); 
    color: white; padding: 5px 12px;
    border-radius: 20px; font-size: 0.75rem; font-weight: 800; 
}

/* Business Profile Specifics */
.biz-profile-layout { display: grid; grid-template-columns: 1fr 350px; gap: 30px; margin-top: 20px; align-items: start; }
.biz-header { background: #fff; border: 1px solid var(--border-color); border-radius: 16px; padding: 30px; display: flex; gap: 30px; align-items: center; margin-bottom: 30px; position: relative; }
.biz-header.premium { border-top: 6px solid var(--warning); background: #fffbeb; }
.biz-hero-logo { width: 140px; height: 140px; background: white; border-radius: 12px; display: flex; align-items: center; justify-content: center; border: 1px solid var(--border-color); overflow: hidden; flex-shrink: 0; }
.biz-hero-logo img { width: 100%; height: 100%; object-fit: contain; }

.action-btn { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; padding: 18px; border-radius: 10px; font-size: 1.1rem; font-weight: bold; text-decoration: none; margin-bottom: 12px; transition: var(--transition); cursor: pointer; border: none;}
.btn-call { background: #059669; color: white; }
.btn-web { background: white; color: #1e40af; border: 2px solid #1e40af; }
.btn-email { background: #f8fafc; color: #475569; border: 1px solid #cbd5e1; }

/* =========================================
   8. DASHBOARD, MESSAGES & TABLES
========================================= */
.dashboard-nav { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.dashboard-nav a { display: block; padding: 12px 16px; text-decoration: none; color: var(--text-main); border-radius: 8px; font-weight: 500; transition: var(--transition); }
.dashboard-nav a:hover, .dashboard-nav a.active { background: var(--primary-light); color: var(--primary); font-weight: 700; }

/* Data Tables */
.table-responsive { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; margin-top: 20px; background: white; }
.data-table th { text-align: left; padding: 15px; background: #f8fafc; border-bottom: 2px solid var(--border-color); color: var(--text-muted); }
.data-table td { padding: 15px; border-bottom: 1px solid var(--border-color); }

/* Messaging Interface */
.messages-layout { display: grid; grid-template-columns: 320px 1fr; height: 75vh; border: 1px solid var(--border-color); border-radius: 12px; background: white; overflow: hidden; }
.messages-list { border-right: 1px solid var(--border-color); overflow-y: auto; }
.message-thread { padding: 20px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: var(--transition); }
.message-thread.active { background: var(--primary-light); border-left: 4px solid var(--primary); }
.chat-history { flex: 1; padding: 25px; overflow-y: auto; display: flex; flex-direction: column; gap: 15px; background: #fafafa; }
.chat-bubble { max-width: 70%; padding: 12px 18px; border-radius: 20px; font-size: 0.95rem; }
.chat-received { background: #e2e8f0; align-self: flex-start; border-bottom-left-radius: 4px; }
.chat-sent { background: var(--primary); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }

/* Forms & Autocomplete */
.form-group { margin-bottom: 25px; }
.form-label { display: block; font-weight: 600; margin-bottom: 10px; color: #475569; }
.form-input { width: 100%; padding: 14px; border: 1px solid #cbd5e1; border-radius: 10px; font-size: 1rem; transition: var(--transition); outline: none; background: white; }
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light); }

/* Missing Form Grid Classes Added */
.grid-uneven { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
.grid-2-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.autocomplete-items {
    position: absolute;
    border: 1px solid var(--border-color); border-top: none; 
    z-index: 100; top: 100%; left: 0; right: 0; background-color: #fff; 
    max-height: 250px; overflow-y: auto;
    border-radius: 0 0 12px 12px; box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1);
}
.autocomplete-items div { padding: 12px; cursor: pointer; border-bottom: 1px solid #f1f5f9; }
.autocomplete-items div:hover { background-color: #f8fafc; color: var(--primary); }

/* =========================================
   9. MOBILE RESPONSIVE
========================================= */
@media (max-width: 992px) {
    /* Stack sidebars and flex layouts safely */
    .dashboard-layout, .layout-sidebar { 
        flex-direction: column;
    }
    
    /* Grid-specific reset for profile layout */
    .biz-profile-layout {
        grid-template-columns: 1fr;
    }
    
    .sidebar, .dashboard-sidebar { 
        width: 100%; 
        margin-bottom: 20px;
    }

    /* Force the main content to take full width when stacked */
    .main-content, .dashboard-content {
        width: 100%;
        min-width: 100%;
    }

    /* Stack form grids safely on tablets and below */
    .grid-uneven, .grid-2-col { 
        grid-template-columns: 1fr; 
    }
}

@media (max-width: 768px) {
    .nav-container { flex-direction: column; text-align: center; gap: 20px; }
    .nav-brand-group, .nav-user-group { justify-content: center; width: 100%; }
    
    .hero-title { font-size: 2.4rem; }
    .hero-search-form { flex-direction: column; padding: 15px; }
    .hero-btn { padding: 18px; width: 100%; }

    /* Turn Table into Card Stack safely across the site */
    .data-table thead { display: none; }
    .data-table tr { 
        display: block; margin-bottom: 20px;
        border: 1px solid var(--border-color); border-radius: 12px; padding: 10px;
        box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    }
    .data-table td { 
        display: flex; justify-content: space-between; align-items: center; 
        text-align: right; border-bottom: 1px solid #f9f9f9; padding: 10px 5px;
    }
    .data-table td:last-child { border-bottom: none; }
    .data-table td::before {
        content: attr(data-label); font-weight: bold; text-align: left;
        color: var(--text-muted); flex: 1; text-transform: uppercase; font-size: 0.8rem;
    }

    /* Force mobile buttons to stretch inside the card stack */
    .data-table td[data-label="Actions"] {
        flex-direction: column;
        gap: 10px;
    }
    .data-table td[data-label="Actions"] form,
    .data-table td[data-label="Actions"] .btn {
        width: 100%;
        margin: 0;
    }

    .messages-layout { grid-template-columns: 1fr; }
    .hide-on-mobile { display: none; }
    
    .biz-card { flex-direction: column; align-items: center; text-align: center; }
    .biz-logo-placeholder { width: 100px; height: 100px; }
    .biz-home-card { flex-direction: column; align-items: center; text-align: center; }
    .biz-header { flex-direction: column; text-align: center; gap: 15px;}
}

@media (max-width: 480px) {
    .container { 
        padding: 0 15px; 
    }
    
    /* Keep the nice rounded corners and shadow on mobile cards */
    .card { 
        padding: 20px; 
        border-radius: 12px; 
        margin-bottom: 20px;
    }
    
    .hero-section { 
        padding: 50px 15px; 
        border-radius: 0 0 20px 20px; 
    }
    
    .ad-grid { 
        grid-template-columns: 1fr; 
    } 
}