/* ============================================================
   Khatri Enterprise - Property Management System
   Main Stylesheet - Mobile Responsive v11 (Unified & Layer Fixed)
   ============================================================ */

:root {
    --primary:       #1a3c5e;
    --primary-light: #2557a7;
    --accent:        #c9a84c;
    --accent-light:  #f0c96a;
    --sidebar-bg:    #0f2339;
    --sidebar-w:     260px;
    --topbar-h:      60px;
    --bg:            #f4f6f9;
    --card-bg:       #ffffff;
    --text:          #2d3748;
    --text-muted:    #718096;
    --border:        #e2e8f0;
    --success:       #38a169;
    --danger:        #e53e3e;
    --warning:       #d69e2e;
    --info:          #3182ce;
    --shadow:        0 2px 12px rgba(0,0,0,0.08);
    --shadow-lg:     0 8px 30px rgba(0,0,0,0.12);
    --radius:        10px;
    --radius-lg:     14px;
    --font-body:     'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display:  'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Global Typography Override */
*, body, h1, h2, h3, h4, h5, h6, p, span, a, button, input, select, textarea, .table, .card {
    font-family: var(--font-body) !important;
}

body {
    background: var(--bg);
    color: var(--text);
    margin: 0;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    letter-spacing: -0.01em;
}

/* ════════════════════════════════════════
   SIDEBAR & OVERLAY ENGINE
════════════════════════════════════════ */
.sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: var(--sidebar-w) !important;
    height: 100vh !important;
    background: var(--sidebar-bg) !important;
    display: flex;
    flex-direction: column;
    z-index: 1030 !important; /* Kept below Bootstrap Modal z-index 1050 */
    transition: transform .28s cubic-bezier(.4,0,.2,1) !important;
    overflow-y: auto !important;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 18px 16px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.brand-logo {
    width: 42px; height: 42px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; color: var(--sidebar-bg);
    flex-shrink: 0;
}

.brand-text h6 {
    margin: 0;
    font-size: 13px;
    color: #fff;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

.brand-text small {
    font-size: 10px;
    color: var(--accent);
    letter-spacing: .5px;
    text-transform: uppercase;
}

.sidebar-nav { flex: 1; padding: 8px 0; }
.sidebar-nav .nav-section { margin-bottom: 5px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 13.5px;
    font-weight: 400;
    transition: all .2s;
    border-left: 3px solid transparent;
    -webkit-tap-highlight-color: transparent;
}

.nav-item i { font-size: 16px; width: 20px; flex-shrink: 0; }

.nav-item:hover,
.nav-item:active {
    color: #fff;
    background: rgba(255,255,255,0.07);
    border-left-color: rgba(201,168,76,.5);
}

.nav-item.active {
    color: var(--accent-light);
    background: rgba(201,168,76,0.12);
    border-left-color: var(--accent);
    font-weight: 600;
}

/* Sidebar Dropdown Controls */
.sidebar-nav .nav-label-btn {
    display: flex; align-items: center; justify-content: space-between;
    width: 100%; padding: 12px 15px; border: none; background: transparent;
    color: #a3b8cc; text-align: left; font-size: 0.85rem; font-weight: 600;
    text-transform: uppercase; letter-spacing: 0.05em; transition: all 0.2s ease;
    cursor: pointer;
}
.sidebar-nav .nav-label-btn:hover { color: #ffffff; background: rgba(255,255,255,0.05); }
.sidebar-nav .nav-label-btn.menu-open-active { color: #ffffff; }
.sidebar-nav .dropdown-arrow { transition: transform 0.2s ease; font-size: 0.75rem; }
.sidebar-nav .nav-label-btn.menu-open-active .dropdown-arrow { transform: rotate(90deg); }

.sidebar-nav .custom-dropdown { 
    display: none; 
    background: rgba(0, 0, 0, 0.2); 
    border-radius: 6px; 
    margin: 0 8px; 
    padding: 4px 0;
}
.sidebar-nav .custom-dropdown.show { display: block; }
.sidebar-nav .custom-dropdown .nav-item { 
    padding-left: 40px; 
    height: 38px; 
    display: flex; 
    align-items: center; 
    font-size: 0.85rem;
}

.sidebar-footer {
    padding: 14px 16px;
    border-top: 1px solid rgba(255,255,255,0.08);
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
}

.user-avatar {
    width: 34px; height: 34px;
    background: linear-gradient(135deg, var(--accent), var(--primary-light));
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700; color: #fff;
    flex-shrink: 0;
}

.user-name {
    font-size: 12.5px; font-weight: 500; color: #fff;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-role {
    font-size: 11px; color: rgba(255,255,255,0.4); text-transform: capitalize;
}

.btn-logout {
    color: rgba(255,255,255,0.4);
    font-size: 18px;
    transition: color .2s;
    flex-shrink: 0;
    text-decoration: none;
}
.btn-logout:hover { color: var(--danger); }

/* Sidebar Overlay Shade */
.sb-overlay, .sidebar-overlay {
    position: fixed !important;
    top: 0 !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
    background: rgba(0,0,0,0.5) !important;
    z-index: 1020 !important;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
    backdrop-filter: blur(2px);
}
.sb-overlay.sb-show, .sidebar-overlay.show { opacity: 1 !important; visibility: visible !important; display: block !important; }

/* ════════════════════════════════════════
   MAIN CONTENT & TOPBAR
════════════════════════════════════════ */
.main-content {
    margin-left: var(--sidebar-w);
    min-height: 100vh;
    transition: margin-left .28s cubic-bezier(.4,0,.2,1);
}

.top-navbar {
    position: sticky;
    top: 0;
    height: var(--topbar-h);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    z-index: 1000;
    box-shadow: 0 1px 4px rgba(0,0,0,0.05);
}

.sidebar-toggle {
    background: none; border: none;
    font-size: 22px; color: var(--text-muted);
    cursor: pointer; padding: 6px;
    border-radius: 8px;
    transition: background .2s;
    flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--bg); }

.page-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--primary);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.search-box {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 12px;
}

.search-box i { color: var(--text-muted); font-size: 13px; }
.search-box input {
    border: none; background: none; outline: none;
    font-size: 13px; width: 160px;
    color: var(--text);
}

.content-wrapper { padding: 20px; }

/* ════════════════════════════════════════
   COMPONENTS (CARDS, TABLES, BUTTONS, FORMS)
════════════════════════════════════════ */
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 18px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    transition: transform .2s, box-shadow .2s;
    height: 100%;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-card .stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
    margin-bottom: 12px;
}

.stat-card .stat-value {
    font-size: 26px;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-card .stat-label { font-size: 12px; color: var(--text-muted); }

.stat-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-icon.orange { background: #ffedd5; color: #ea580c; }
.stat-icon.gold   { background: #fef9c3; color: #ca8a04; }
.stat-icon.purple { background: #f3e8ff; color: #9333ea; }
.stat-icon.red    { background: #fee2e2; color: #dc2626; }

.card {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

.card-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 14px 16px;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    font-weight: 600;
    font-size: 14px;
    color: var(--primary);
}

.table { font-size: 13px; }
.table th {
    background: var(--bg);
    color: var(--text-muted);
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    padding: 10px 12px;
}

.table td { vertical-align: middle; padding: 10px 12px; }
.table tbody tr:hover { background: rgba(26,60,94,0.025); }

.btn {
    font-size: 13px;
    border-radius: 8px;
    font-weight: 500;
    touch-action: manipulation;
}

.btn-primary  { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-light); border-color: var(--primary-light); }

.btn-gold { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-gold:hover { background: #b8943c; border-color: #b8943c; color: #fff; }

.form-control, .form-select {
    border-color: var(--border);
    border-radius: 8px;
    font-size: 14px;
    transition: border-color .2s, box-shadow .2s;
    min-height: 42px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(37,87,167,0.12);
}

/* ════════════════════════════════════════
   MOBILE BOTTOM NAVIGATION
════════════════════════════════════════ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: rgba(255, 255, 255, 0.95) !important;
    backdrop-filter: blur(15px) !important;
    -webkit-backdrop-filter: blur(15px) !important;
    border-top: 1px solid rgba(0, 0, 0, 0.08) !important;
    z-index: 1025 !important;
    padding: 6px 0 env(safe-area-inset-bottom, 6px);
    box-shadow: 0 -4px 20px rgba(0,0,0,0.06);
}

.mobile-bottom-nav .nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    width: 100%;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 4px 2px;
    color: #8e8e93;
    text-decoration: none !important;
    font-size: 9px;
    font-weight: 500;
    transition: all .2s ease;
    flex: 1;
    text-align: center;
    position: relative;
}

.mobile-nav-item i { font-size: 18px; transition: transform 0.15s ease, color 0.15s ease; }

.mobile-nav-item.active {
    color: var(--primary-light) !important;
    font-weight: 700;
}

.mobile-nav-item.active i {
    transform: translateY(-2px) scale(1.05);
    color: var(--primary-light) !important;
}

.mobile-nav-item.active::after {
    content: '';
    position: absolute;
    bottom: -2px;
    width: 4px;
    height: 4px;
    background-color: var(--primary-light);
    border-radius: 50%;
}

/* ════════════════════════════════════════
   RESPONSIVE BREAKPOINTS
════════════════════════════════════════ */

/* Desktop State Switching */
@media (min-width: 769px) {
    #sidebar { transform: translateX(0) !important; }
    #sidebar.sb-collapsed, #sidebar.collapsed { transform: translateX(-100%) !important; }

    #mainContent { margin-left: var(--sidebar-w) !important; }
    #mainContent.sb-expanded, #mainContent.expanded { margin-left: 0 !important; }

    .sb-overlay, .sidebar-overlay { display: none !important; }
}

/* Mobile State Switching (<=768px) */
@media (max-width: 768px) {
    body { padding-bottom: 78px !important; }

    #sidebar { transform: translateX(-100%) !important; }
    #sidebar.sb-open, #sidebar.open { transform: translateX(0) !important; box-shadow: 4px 0 30px rgba(0,0,0,0.3); }

    .main-content { margin-left: 0 !important; }
    .content-wrapper { padding: 12px; padding-bottom: 80px; }

    .search-box { display: none; }
    .mobile-bottom-nav { display: block; }

    .modal-dialog { margin: 8px; }
    .form-control, .form-select { font-size: 16px !important; } /* Prevents iOS auto-zoom */
}

/* Print Styles */
@media print {
    .sidebar, .top-navbar, .no-print, .mobile-bottom-nav, .sb-overlay, .sidebar-overlay { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .content-wrapper { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    body { font-size: 11px; padding-bottom: 0 !important; }
}