/* ==================== */
/* MOBILE FIRST RESPONSIVE DESIGN */
/* ==================== */
:root {
    --primary-gradient: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --primary-color: #4361ee;
    --primary-light: #4361ee20;
    --secondary-color: #3a0ca3;
    --success-color: #06d6a0;
    --warning-color: #ffd166;
    --danger-color: #ef476f;
    --info-color: #118ab2;
    --dark-color: #1a1a2e;
    --darker-color: #0d1117;
    --light-color: #f8f9fa;
    --sidebar-width: 260px;
    --border-radius: 12px;
    --box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Mobile-specific variables */
    --mobile-padding: 15px;
    --mobile-margin: 10px;
    --mobile-font-size: 14px;
    --mobile-header-height: 60px;
}

/* ==================== */
/* BASE STYLES - MOBILE FIRST */
/* ==================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}

html {
    font-size: 16px;
    height: 100%;
    overflow-x: hidden;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    color: #2d3436;
    min-height: 100vh;
    line-height: 1.5;
    overflow-x: hidden;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Prevent scrolling on body when sidebar is open */
body.sidebar-open {
    overflow: hidden;
}

/* ==================== */
/* MOBILE VIEWPORT FIXES */
/* ==================== */
@media screen and (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    body {
        font-size: var(--mobile-font-size);
        position: fixed;
        width: 100vw;
        height: 100vh;
        overflow: hidden;
    }
    
    .app-container {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* ==================== */
/* LOGIN CONTAINER - MOBILE */
/* ==================== */
.login-container {
    background: white;
    width: 90%;
    max-width: 400px;
    margin: 20px auto;
    padding: 30px 25px;
    border-radius: 20px;
    box-shadow: var(--box-shadow);
    position: relative;
    overflow: hidden;
}

@media screen and (max-width: 768px) {
    .login-container {
        width: 95%;
        margin: 10px auto;
        padding: 25px 20px;
        min-height: auto;
    }
    
    .login-container h3 {
        font-size: 1.5rem;
    }
    
    .login-container .form-control {
        padding: 12px;
        font-size: 16px; /* Prevents iOS zoom */
    }
}

/* ==================== */
/* MOBILE MENU TOGGLE */
/* ==================== */
.mobile-menu-toggle {
    display: block;
    position: fixed;
    top: 15px;
    left: 15px;
    z-index: 1100;
    background: var(--primary-gradient);
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 12px;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(67, 97, 238, 0.3);
    cursor: pointer;
    transition: var(--transition);
}

.mobile-menu-toggle:active {
    transform: scale(0.95);
}

/* ==================== */
/* SIDEBAR - MOBILE FRIENDLY */
/* ==================== */
.sidebar {
    position: fixed;
    left: -280px; /* Hidden by default on mobile */
    top: 0;
    width: 280px;
    height: 100vh;
    background: linear-gradient(180deg, var(--darker-color) 0%, #1a1a2e 100%);
    color: white;
    padding: 0;
    overflow-y: auto;
    box-shadow: 5px 0 25px rgba(0, 0, 0, 0.2);
    z-index: 1000;
    transition: var(--transition);
    -webkit-overflow-scrolling: touch;
}

.sidebar.active {
    left: 0;
}

/* Sidebar Backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    backdrop-filter: blur(5px);
}

.sidebar-backdrop.active {
    display: block;
}

/* Close sidebar when clicking backdrop */
.sidebar-backdrop.active ~ .sidebar {
    left: 0;
}

@media screen and (max-width: 992px) {
    .sidebar {
        width: 280px;
        left: -280px;
    }
    
    .sidebar.active {
        left: 0;
    }
}

/* ==================== */
/* MAIN CONTENT - MOBILE FRIENDLY */
/* ==================== */
.main-content {
    margin-left: 0;
    padding: 70px 15px 20px; /* Top padding for mobile menu button */
    min-height: 100vh;
    transition: var(--transition);
    width: 100%;
    overflow-x: hidden;
}

@media screen and (min-width: 993px) {
    .main-content {
        margin-left: var(--sidebar-width);
        padding: 30px;
    }
    
    .mobile-menu-toggle {
        display: none;
    }
    
    .sidebar {
        left: 0;
    }
}

/* ==================== */
/* SECTION STYLES - MOBILE */
/* ==================== */
.section {
    width: 100%;
    overflow-x: hidden;
}

.section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
    color: var(--dark-color);
    font-weight: 700;
    padding-bottom: 10px;
    border-bottom: 3px solid var(--primary-color);
}

@media screen and (max-width: 768px) {
    .section h2 {
        font-size: 1.3rem;
        margin-bottom: 15px;
    }
}

/* ==================== */
/* DASHBOARD - MOBILE OPTIMIZED */
/* ==================== */
/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    margin-bottom: 20px;
}

@media screen and (min-width: 768px) {
    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.03);
    text-align: center;
}

.stat-card h3 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 5px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.stat-card p {
    color: #6c757d;
    font-size: 0.9rem;
    margin-bottom: 0;
}

.stat-card i {
    display: none; /* Hide icons on mobile to save space */
}

@media screen and (min-width: 768px) {
    .stat-card {
        text-align: left;
        padding: 25px;
    }
    
    .stat-card h3 {
        font-size: 2.2rem;
    }
    
    .stat-card i {
        display: block;
        position: absolute;
        bottom: 20px;
        right: 20px;
        opacity: 0.1;
        font-size: 3rem;
        color: var(--primary-color);
    }
}

/* Quick Actions */
.quick-actions-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-top: 15px;
}

@media screen and (min-width: 768px) {
    .quick-actions-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 15px;
    }
}

@media screen and (min-width: 992px) {
    .quick-actions-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

.quick-action-btn {
    background: white;
    border: none;
    border-radius: 12px;
    padding: 15px 10px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: auto;
    min-height: 90px;
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.quick-action-btn:active {
    transform: scale(0.98);
}

.quick-action-btn i {
    font-size: 1.5rem;
    margin-bottom: 8px;
    background: linear-gradient(135deg, currentColor 0%, rgba(255, 255, 255, 0.3) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.quick-action-btn span {
    font-weight: 600;
    font-size: 0.8rem;
    color: var(--dark-color);
    line-height: 1.3;
}

/* ==================== */
/* TABLES - MOBILE FRIENDLY */
/* ==================== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--border-radius);
    background: white;
    box-shadow: var(--box-shadow);
    margin-bottom: 20px;
}

.table-responsive table {
    min-width: 700px; /* Minimum width for horizontal scrolling */
    width: 100%;
    border-collapse: collapse;
}

/* Mobile table view - card layout */
.mobile-table-view {
    display: none;
}

@media screen and (max-width: 768px) {
    .desktop-table-view {
        display: none;
    }
    
    .mobile-table-view {
        display: block;
    }
    
    .tenant-mobile-card {
        background: white;
        border-radius: 12px;
        padding: 15px;
        margin-bottom: 15px;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
        border: 1px solid #f1f3f4;
    }
    
    .tenant-mobile-header {
        display: flex;
        align-items: center;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid #f1f3f4;
    }
    
    .tenant-mobile-avatar {
        width: 45px;
        height: 45px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-weight: 700;
        font-size: 1.1rem;
        margin-right: 12px;
        flex-shrink: 0;
    }
    
    .tenant-mobile-info h6 {
        margin: 0;
        font-weight: 600;
        font-size: 1rem;
        color: var(--dark-color);
    }
    
    .tenant-mobile-info small {
        color: #6c757d;
        font-size: 0.85rem;
    }
    
    .tenant-mobile-details {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 15px;
    }
    
    .tenant-mobile-detail {
        background: #f8fafc;
        padding: 10px;
        border-radius: 8px;
        text-align: center;
    }
    
    .tenant-mobile-detail .label {
        font-size: 0.75rem;
        color: #6c757d;
        margin-bottom: 3px;
        display: block;
    }
    
    .tenant-mobile-detail .value {
        font-weight: 600;
        color: var(--dark-color);
        font-size: 0.9rem;
    }
    
    .tenant-mobile-actions {
        display: flex;
        gap: 10px;
        margin-top: 15px;
    }
    
    .tenant-mobile-actions .btn {
        flex: 1;
        padding: 8px 12px;
        font-size: 0.85rem;
    }
}

/* Desktop table styles */
.table {
    width: 100%;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

.table thead th {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border: none;
    padding: 15px;
    font-weight: 600;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: none;
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

.table tbody td {
    padding: 12px 15px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f3f4;
    font-size: 0.9rem;
    color: #495057;
}

/* ==================== */
/* FORMS - MOBILE FRIENDLY */
/* ==================== */
.form-control, .form-select {
    border-radius: 10px;
    padding: 12px 15px;
    border: 2px solid #e9ecef;
    transition: var(--transition);
    font-size: 16px; /* Prevents iOS zoom */
    width: 100%;
    min-height: 48px;
}

/* iOS specific fixes */
@supports (-webkit-touch-callout: none) {
    .form-control, .form-select {
        font-size: 16px;
    }
    
    input, select, textarea {
        font-size: 16px;
    }
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-light);
    outline: none;
}

.form-label {
    font-weight: 600;
    color: var(--dark-color);
    margin-bottom: 8px;
    font-size: 0.95rem;
    display: block;
}

/* ==================== */
/* BUTTONS - MOBILE OPTIMIZED */
/* ==================== */
.btn {
    border-radius: 10px;
    padding: 12px 20px;
    font-weight: 600;
    font-size: 0.95rem;
    transition: var(--transition);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-align: center;
    cursor: pointer;
    min-height: 48px;
    width: 100%;
    margin-bottom: 10px;
    -webkit-appearance: none;
}

.btn:active {
    transform: scale(0.98);
}

/* Button variants */
.btn-primary {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
}

.btn-outline-primary {
    color: var(--primary-color);
    border: 2px solid var(--primary-color);
    background: transparent;
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
    min-height: 40px;
}

@media screen and (min-width: 768px) {
    .btn {
        width: auto;
        margin-bottom: 0;
    }
}

/* ==================== */
/* MODALS - MOBILE FRIENDLY */
/* ==================== */
.modal {
    padding: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-dialog {
    margin: 0;
    width: 100%;
    max-width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    width: 95%;
    margin: 20px auto;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    max-height: 90vh;
    overflow-y: auto;
}

@media screen and (min-width: 768px) {
    .modal-dialog {
        margin: 1.75rem auto;
        max-width: 500px;
        height: auto;
    }
    
    .modal-dialog.modal-lg {
        max-width: 800px;
    }
    
    .modal-dialog.modal-xl {
        max-width: 1140px;
    }
    
    .modal-content {
        width: 100%;
        margin: 0;
    }
}

.modal-header {
    padding: 20px;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    color: white;
    border-bottom: none;
    position: sticky;
    top: 0;
    z-index: 1055;
}

.modal-body {
    padding: 20px;
    max-height: calc(90vh - 140px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-footer {
    padding: 20px;
    border-top: 1px solid #f1f3f4;
    position: sticky;
    bottom: 0;
    background: white;
    z-index: 1055;
}

/* ==================== */
/* CARDS - MOBILE FRIENDLY */
/* ==================== */
.card {
    border: none;
    border-radius: var(--border-radius);
    box-shadow: var(--box-shadow);
    margin-bottom: 20px;
    background: white;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.03);
    width: 100%;
}

.card-header {
    background: white;
    border-bottom: 1px solid #f1f3f4;
    padding: 20px;
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--dark-color);
}

.card-body {
    padding: 20px;
}

/* ==================== */
/* NAVIGATION - MOBILE FRIENDLY */
/* ==================== */
.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.8);
    padding: 15px 20px;
    margin: 5px 0;
    border-radius: 12px;
    transition: var(--transition);
    border: none;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    width: 100%;
}

.sidebar .nav-link i {
    width: 24px;
    text-align: center;
    margin-right: 12px;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.sidebar .badge {
    font-size: 0.75rem;
    padding: 4px 8px;
    min-width: 26px;
    margin-left: auto;
}

/* ==================== */
/* UTILITY CLASSES FOR MOBILE */
/* ==================== */
.hide-on-mobile {
    display: none !important;
}

.show-on-mobile {
    display: block !important;
}

@media screen and (min-width: 768px) {
    .hide-on-mobile {
        display: block !important;
    }
    
    .show-on-mobile {
        display: none !important;
    }
}

/* Safe area padding for iPhone X and newer */
.safe-area-top {
    padding-top: env(safe-area-inset-top);
}

.safe-area-bottom {
    padding-bottom: env(safe-area-inset-bottom);
}

/* ==================== */
/* SCROLLBAR STYLES */
/* ==================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 3px;
}

/* ==================== */
/* LOADING STATES */
/* ==================== */
.data-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
    display: none;
    backdrop-filter: blur(5px);
}

.data-loader.show {
    display: flex;
}

/* ==================== */
/* TOAST NOTIFICATIONS - MOBILE */
/* ==================== */
.toast-container {
    position: fixed;
    top: 70px;
    right: 15px;
    z-index: 9999;
    width: 90%;
    max-width: 350px;
}

@media screen and (min-width: 768px) {
    .toast-container {
        width: auto;
        max-width: none;
    }
}

.toast {
    width: 100%;
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    background: white;
    border-left: 4px solid var(--primary-color);
    margin-bottom: 10px;
}

/* ==================== */
/* PAGINATION - MOBILE */
/* ==================== */
.pagination {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    justify-content: center;
    margin-top: 20px;
}

.page-link {
    padding: 8px 12px;
    font-size: 0.9rem;
    min-width: 40px;
    text-align: center;
}

/* ==================== */
/* SEARCH BOX - MOBILE */
/* ==================== */
.search-box {
    width: 100%;
    padding: 12px 15px;
    border-radius: 10px;
    border: 2px solid #e9ecef;
    font-size: 16px;
    margin-bottom: 10px;
}

@media screen and (min-width: 768px) {
    .search-box {
        width: auto;
        margin-bottom: 0;
    }
}

/* ==================== */
/* FIX FOR IOS ZOOM ON INPUT FOCUS */
/* ==================== */
@supports (-webkit-overflow-scrolling: touch) {
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* ==================== */
/* PREVENT TEXT SELECTION ON MOBILE */
/* ==================== */
.no-select {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* ==================== */
/* IMAGE RESPONSIVENESS */
/* ==================== */
img {
    max-width: 100%;
    height: auto;
}

/* ==================== */
/* FLEX UTILITIES FOR MOBILE */
/* ==================== */
.flex-mobile-column {
    display: flex;
    flex-direction: column;
}

@media screen and (min-width: 768px) {
    .flex-mobile-column {
        flex-direction: row;
    }
}

/* ==================== */
/* GRID UTILITIES FOR MOBILE */
/* ==================== */
.grid-mobile-1 {
    display: grid;
    grid-template-columns: 1fr;
    gap: 15px;
}

.grid-mobile-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
}

@media screen and (min-width: 768px) {
    .grid-mobile-1 {
        grid-template-columns: repeat(1, 1fr);
        gap: 20px;
    }
    
    .grid-mobile-2 {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

/* ==================== */
/* FIX FOR MODAL BACKDROP ON MOBILE */
/* ==================== */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 1040;
}

/* ==================== */
/* TAP HIGHLIGHT COLOR */
/* ==================== */
* {
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}

/* ==================== */
/* ANIMATIONS FOR MOBILE */
/* ==================== */
@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideInLeft {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.mobile-slide-up {
    animation: slideInUp 0.3s ease-out;
}

.mobile-slide-left {
    animation: slideInLeft 0.3s ease-out;
}

/* ==================== */
/* FIX FOR IOS BOTTOM BAR */
/* ==================== */
.ios-bottom-fix {
    padding-bottom: constant(safe-area-inset-bottom);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ==================== */
/* FULLSCREEN MODAL FOR MOBILE */
/* ==================== */
.fullscreen-modal .modal-dialog {
    max-width: 100%;
    margin: 0;
}

.fullscreen-modal .modal-content {
    border-radius: 0;
    min-height: 100vh;
    max-height: 100vh;
}

/* ==================== */
/* FIX FOR IOS INPUT SHADOW */
/* ==================== */
input, textarea, select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* ==================== */
/* CUSTOM SCROLLBAR FOR MOBILE */
/* ==================== */
.scrollbar-thin {
    scrollbar-width: thin;
    scrollbar-color: var(--primary-color) #f1f1f1;
}

.scrollbar-thin::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}

.scrollbar-thin::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 2px;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    border-radius: 2px;
}

/* ==================== */
/* HOVER EFFECTS ONLY ON DESKTOP */
/* ==================== */
@media (hover: hover) and (pointer: fine) {
    .btn:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 20px rgba(67, 97, 238, 0.3);
    }
    
    .quick-action-btn:hover {
        transform: translateY(-5px);
        box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    }
}

/* ==================== */
/* FIX FOR VIEWPORT HEIGHT ON MOBILE */
/* ==================== */
.full-vh {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
}