/* ==========================================================================
   1. General Core & Variables Setup
   ========================================================================== */
:root {
    --primary-color: #38bdf8;
    --primary-hover: #0284c7;
    --bg-dark: #0f172a;
    --card-bg: #1e293b;
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --success: #22c55e;
    --danger: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Sukhumvit Set', 'Sarabun', system-ui, -apple-system, sans-serif;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    line-height: 1.6;
    display: block;
}

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

/* ==========================================================================
   2. Base UI Components & Layout
   ========================================================================== */
.public-nav {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 32px;
    background: #1e293b;
    border-bottom: 1px solid var(--border-color);
}

.glass-nav {
    background: rgba(15, 23, 42, 0.75) !important;
    backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary-color);
    color: #0f172a;
}

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

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

.btn-sm {
    padding: 6px 12px;
    font-size: 13px;
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    background: #0f172a;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary-color);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.badge-sale {
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
}

.badge-rent {
    background: rgba(56, 189, 248, 0.15);
    color: #38bdf8;
}

/* ==========================================================================
   3. Index Page & Card Grid
   ========================================================================== */
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.prop-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

.prop-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease;
}

.prop-card:hover {
    transform: translateY(-4px);
}

.prop-gallery-container {
    position: relative;
    height: 220px;
    background: #090d16;
}

.gallery-grid {
    display: grid;
    height: 100%;
    gap: 2px;
}

.gallery-grid.count-1 { grid-template-columns: 1fr; }
.gallery-grid.count-2 { grid-template-columns: 1fr 1fr; }
.gallery-grid.count-3 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.gallery-grid.count-3 .gallery-item:first-child { grid-row: span 2; }
.gallery-grid.count-4 { grid-template-columns: 2fr 1fr; grid-template-rows: 1fr 1fr; }
.gallery-grid.count-4 .gallery-item:first-child { grid-row: span 2; }

.gallery-item {
    overflow: hidden;
    position: relative;
}

.gallery-item img, .prop-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    cursor: pointer;
}

.img-badge {
    position: absolute;
    bottom: 10px;
    right: 10px;
    background: rgba(15, 23, 42, 0.75);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
}

.prop-content {
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex-grow: 1;
}

.prop-price {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
}

.prop-description {
    font-size: 13px;
    color: var(--text-muted);
    background: rgba(15, 23, 42, 0.5);
    padding: 10px;
    border-radius: 8px;
    margin-top: 8px;
}

/* ==========================================================================
   4. Admin Layout Component
   ========================================================================== */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: 260px;
    background: #1e293b;
    border-right: 1px solid var(--border-color);
    padding: 24px;
}

.brand {
    font-size: 20px;
    font-weight: 700;
    color: var(--primary-color);
    margin-bottom: 32px;
}

.sidebar-menu {
    list-style: none;
}

.sidebar-menu li a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 8px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.sidebar-menu li a.active, .sidebar-menu li a:hover {
    background: rgba(56, 189, 248, 0.1);
    color: var(--primary-color);
}

.main-content {
    flex-grow: 1;
    padding: 32px;
    background: var(--bg-dark);
}

.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary-color);
    color: #0f172a;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 32px;
}

.stat-card .title {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
}

.table-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 24px;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 14px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    color: var(--text-muted);
    font-weight: 600;
    font-size: 13px;
}

.form-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 32px;
    max-width: 800px;
    margin: 0 auto;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 14px;
    color: var(--text-muted);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

/* Modal Lightbox */
.lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 9999;
    align-items: center;
    justify-content: center;
}

.lightbox-content {
    max-width: 90%;
    max-height: 85vh;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #fff;
    font-size: 36px;
    cursor: pointer;
}

/* ==========================================================================
   5. Grand Detail Page Styling & Responsive Gallery
   ========================================================================== */
.grand-hero {
    height: 480px;
    background-size: cover;
    background-position: center;
    display: flex;
    align-items: flex-end;
    padding: 60px 20px 100px;
    text-align: center;
    justify-content: center;
    position: relative;
}

.hero-content {
    max-width: 900px;
    animation: fadeInUp 0.8s ease;
}

.grand-title {
    font-size: 42px;
    font-weight: 800;
    margin: 16px 0 8px;
    color: #ffffff;
    text-shadow: 0 4px 20px rgba(0,0,0,0.6);
}

.grand-location {
    font-size: 18px;
    color: #cbd5e1;
    margin-bottom: 16px;
}

.grand-price {
    font-size: 38px;
    font-weight: 800;
    color: #38bdf8;
    text-shadow: 0 2px 10px rgba(56, 189, 248, 0.3);
}

.vip-stats-bar {
    background: rgba(30, 41, 59, 0.9);
    backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 16px;
    padding: 24px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 20px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5);
    margin-bottom: 40px;
}

.vip-stat-item {
    display: flex;
    align-items: center;
    gap: 16px;
}

.vip-stat-item .icon {
    font-size: 28px;
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.1);
    padding: 14px;
    border-radius: 12px;
}

.vip-stat-item .val {
    display: block;
    font-size: 20px;
    font-weight: 700;
    color: #fff;
}

.vip-stat-item .lbl {
    font-size: 13px;
    color: #94a3b8;
}

.section-title {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 20px;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 10px;
}

.gallery-section {
    margin-bottom: 40px;
}

.detail-gallery-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.detail-gallery-item {
    position: relative;
    border-radius: 12px;
    overflow: hidden;
    height: 180px;
    cursor: pointer;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.3);
}

.detail-gallery-item.feature-photo {
    grid-column: span 2;
    grid-row: span 2;
    height: 376px;
}

.detail-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.detail-gallery-item:hover img {
    transform: scale(1.06);
}

.photo-overlay {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    color: #fff;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.detail-gallery-item:hover .photo-overlay {
    opacity: 1;
}

.detail-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 32px;
}

.detail-main-card {
    background: #1e293b;
    border-radius: 16px;
    padding: 32px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.description-text {
    line-height: 1.8;
    color: #cbd5e1;
    font-size: 16px;
}

.agent-card {
    background: #1e293b;
    border-radius: 16px;
    padding: 32px;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.05);
    height: fit-content;
}

.agent-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(56, 189, 248, 0.1);
    color: #38bdf8;
    font-size: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 36px;
    width: 100%;
    max-width: 400px;
}

/* Mobile Responsive Adjustments */
@media (max-width: 902px) {
    .app-container { flex-direction: column; }
    .sidebar { width: 100%; }
    .grand-title { font-size: 28px; }
    .grand-price { font-size: 30px; }
    .detail-layout { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    
    .detail-gallery-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .detail-gallery-item.feature-photo {
        grid-column: span 2;
        height: 240px;
    }
    
    .detail-gallery-item {
        height: 140px;
    }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}